Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] GaussDB for NoSQL #453

Draft
wants to merge 31 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions openstack/gaussdbnosql/v3/ListDatastores.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package v3

import (
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

func ListDatastores(client *golangsdk.ServiceClient, datastoreName string) ([]string, error) {
Aloento marked this conversation as resolved.
Show resolved Hide resolved
// GET https://{Endpoint}/v3/{project_id}/datastores/{datastore_name}/versions
raw, err := client.Get(client.ServiceURL("datastores", datastoreName, "versions"), nil, nil)
if err != nil {
return nil, err
}

var res []string
err = extract.IntoSlicePtr(raw.Body, &res, "versions")
return res, err
}
67 changes: 67 additions & 0 deletions openstack/gaussdbnosql/v3/ListFlavors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package v3

import (
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

type ListFlavorsOpts struct {
// Region where the instance is deployed.
// Valid value:
// The value cannot be empty. For details about how to obtain this parameter value, see Regions and Endpoints.
Region string `q:"region"`
// engine_name No Database type
// If the value is cassandra, the GaussDB(for Cassandra) DB instance specifications are queried,
// If this parameter is not transferred, the default value is cassandra.
EngineName string `q:"engine_name,omitempty"`
}

func ListFlavors(client *golangsdk.ServiceClient, opts ListFlavorsOpts) (*ListFlavorsResponse, error) {
q, err := golangsdk.BuildQueryString(opts)
if err != nil {
return nil, err
}

// GET https://{Endpoint}/v3/{project_id}/flavors
raw, err := client.Get(client.ServiceURL("flavors")+q.String(), nil, nil)
if err != nil {
return nil, err
}

var res ListFlavorsResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type ListFlavorsResponse struct {
// Total number of records
TotalCount int32 `json:"total_count"`
// Instance specifications.
Flavors []ListFlavorsResult `json:"flavors"`
}

type ListFlavorsResult struct {
// Engine name
EngineName string `json:"engine_name"`
// Engine version
EngineVersion string `json:"engine_version"`
// Number of vCPUs
Vcpus string `json:"vcpus"`
// Memory size in megabytes (MB)
Ram string `json:"ram"`
// Resource specification code
// Example: geminidb.cassandra.8xlarge.4
// NOTE
// geminidb.cassandra indicates GaussDB(for Cassandra).
// 8xlarge.4 indicates the single-node specifications.
SpecCode string `json:"spec_code"`
// ID of the AZ that supports this specification
// NOTE
// This field is discarded and cannot be used.
AvailabilityZone []string `json:"availability_zone"`
// Status of specifications in an AZ. The value can be:
// normal: indicates that the specifications are on sale.
// unsupported: not supported.
// sellout: indicates that the instance specifications are sold out.
AzStatus string `json:"az_status"`
}
63 changes: 63 additions & 0 deletions openstack/gaussdbnosql/v3/ListSlowLogs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package v3

import (
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

type ListSlowLogsOpts struct {
// Instance ID
InstanceId string `q:"instance_id"`
// Start time in the "yyyy-mm-ddThh:mm:ssZ" format.
StartDate string `q:"start_date"`
// End time in the "yyyy-mm-ddThh:mm:ssZ" format.
EndDate string `q:"end_date"`
// Node ID. If this parameter is left blank, all nodes of the instance are queried.
NodeId string `q:"node_id,omitempty"`
// Statement type. If this parameter is left empty, all statement types are queried.
// You can also specify the following log type:
// SELECT
Type string `q:"type,omitempty"`
// Index offset. Its value range is [0, 1999].
// If offset is set to N, the resource query starts from the N+1 piece of data. The value is 0 by default,
// indicating that the query starts from the first piece of data. The value must be a positive number.
Offset int32 `q:"offset,omitempty"`
// Number of records to be queried. The value ranges from 1 (inclusive) to 100 (inclusive).
// The sum of values of limit and offset must be less than or equal to 2000.
Limit int32 `q:"limit,omitempty"`
}

func ListSlowLogs(client *golangsdk.ServiceClient, opts ListSlowLogsOpts) (*ListSlowLogsResponse, error) {
q, err := golangsdk.BuildQueryString(opts)
if err != nil {
return nil, err
}

// GET https://{Endpoint}/v3/{project_id}/instances/{instance_id}/slowlog
raw, err := client.Get(client.ServiceURL("instances", opts.InstanceId, "slowlog")+q.String(), nil, nil)
if err != nil {
return nil, err
}

var res ListSlowLogsResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type ListSlowLogsResponse struct {
SlowLogList []SlowlogResult `json:"slow_log_listq"`
TotalRecord int32 `json:"total_recordq"`
}

type SlowlogResult struct {
// Execution time
Time string `json:"time"`
// Database which slow logs belong to
Database string `json:"database"`
// Execution syntax
QuerySample string `json:"query_sample"`
// Statement type
Type string `json:"type"`
// Time in the UTC format
StartTime string `json:"start_time"`
}
46 changes: 46 additions & 0 deletions openstack/gaussdbnosql/v3/backup/SetBackupPolicy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package backup

import (
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
)

type SetBackupPolicyOpts struct {
InstanceId string
// Backup policy object, which includes the backup retention period (days) and start time.
BackupPolicy BackupPolicy `json:"backup_policy"`
}

type BackupPolicy struct {
// Backup retention days. Value range: 0-35. The value 0 indicates that the automated backup policy is disabled.
KeepDays int32 `json:"keep_days"`
// Backup time window. Automated backups will be triggered during the backup time window.
// This parameter is mandatory if the automated backup policy is enabled.
// This parameter is not transferred if the automated backup policy is disabled.
// The value must be a valid value in the "hh:mm-HH:MM" format. The current time is in the UTC format.
// The HH value must be 1 greater than the hh value.
// The values of mm and MM must be the same and must be set to any of the following: 00, 15, 30, and 45.
// If this parameter is not transferred, the default backup time window is from 00:00 to 01:00.
// Example value: 23:00-00:00
StartTime string `json:"start_time,omitempty"`
// Backup cycle configuration. Data will be automatically backed up on the selected days every week.
// Value range: The value is a number separated by DBS case commas (,). The number indicates the week.
// The restrictions on the backup retention period are as follows:
// This parameter is not transferred if its value is set to 0.
// If you set the retention period to 1 to 6 days, data is automatically backed up each day of the week.
// Set the parameter value to 1,2,3,4,5,6,7.
// If you set the retention period to 7 to 732 days, select at least one day of the week for the backup cycle.
// Example value: 1,2,3,4
Period string `json:"period,omitempty"`
}

func SetBackupPolicy(client *golangsdk.ServiceClient, opts SetBackupPolicyOpts) (err error) {
b, err := build.RequestBody(opts, "")
if err != nil {
return
}

// PUT https://{Endpoint}/v3/{project_id}/instances/{instance_id}/backups/policy
_, err = client.Put(client.ServiceURL("instances", opts.InstanceId, "backups", "policy"), b, nil, nil)
return
}
27 changes: 27 additions & 0 deletions openstack/gaussdbnosql/v3/backup/ShowBackupPolicy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package backup

import (
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

func ShowBackupPolicy(client *golangsdk.ServiceClient, instanceId string) (*ShowBackupPolicyResult, error) {
// GET https://{Endpoint}/v3/{project_id}/instances/{instance_id}/backups/policy
raw, err := client.Get(client.ServiceURL("instances", instanceId, "backups", "policy"), nil, nil)
if err != nil {
return nil, err
}

var res ShowBackupPolicyResult
err = extract.IntoStructPtr(raw.Body, &res, "backup_policy")
return &res, err
}

type ShowBackupPolicyResult struct {
// Backup retention days
KeepDays int32 `json:"keep_days"`
// Backup time window. Automated backups will be triggered during the backup time window.
StartTime string `json:"start_time"`
// Backup cycle configuration. Data will be automatically backed up on the selected days every week.
Period string `json:"period"`
}
143 changes: 143 additions & 0 deletions openstack/gaussdbnosql/v3/instance/CreateInstance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package instance

import (
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

type CreateInstanceOpts struct {
// Instance name, which can be the same as an existing instance name.
// Value range:
// The value must be 4 to 64 characters in length and start with a letter (from A to Z or from a to z).
// It is case-sensitive and can contain only letters, digits (from 0 to 9), hyphens (-), and underscores (_).
Name string `json:"name"`
// Database information.
Datastore Datastore `json:"datastore"`
// Region ID
// The value cannot be empty.
Region string `json:"region"`
// AZ ID
// For details about the value, see az_status returned in 5.3 Querying All Instance Specifications.
// Separate multiple AZs by commas (,).
AvailabilityZone string `json:"availability_zone"`
// VPC ID. To obtain this parameter value, use either of the following methods:
// Method 1: Log in to VPC console and view the VPC ID on the VPC details page.
// Method 2: See the "Querying VPCs" section in the Virtual Private Cloud API Reference.
VpcId string `json:"vpc_id"`
// Network ID of the subnet. To obtain this parameter value, use either of the following methods:
// Method 1: Log in to VPC console and click the target subnet on the Subnets page. You can view the subnet ID on the displayed page.
// Method 2: See the "Querying Subnets" section in the Virtual Private Cloud API Reference.
SubnetId string `json:"subnet_id"`
// Security group ID. To obtain the security group ID, perform either of the following methods:
// Method 1: Log in to VPC console. Choose Access Control > Security Groups in the navigation pane on the left.
// On the displayed page, click the target security group. You can view the security group ID on the displayed page.
// Method 2: See the "Querying Security Groups" section in the Virtual Private Cloud API Reference.
SecurityGroupId string `json:"security_group_id"`
// Database password
// The value must be 8 to 32 characters in length and contain uppercase letters (A to Z),
// lowercase letters (a to z), digits (0 to 9), and special characters, such as ~!@#%^*-_=+?
// You are advised to enter a strong password to improve security, preventing security risks such as brute force cracking.
Password string `json:"password"`
// Instance type
// GaussDB(for Cassandra) supports the cluster type. The value is "Cluster".
Mode string `json:"mode"`
// Instance specifications
Flavor []InstanceFlavor `json:"flavor"`
// Parameter template ID
ConfigurationId string `json:"configuration_id,omitempty"`
// Advanced backup policy.
BackupStrategy BackupStrategy `json:"backup_strategy,omitempty"`
// Specifies whether to enable or disable SSL.
// Valid value:
// The value "0" indicates that SSL is disabled by default.
// The value "1" indicates that SSL is enabled by default.
// If this parameter is not transferred, SSL is disabled by default.
SslOption string `json:"ssl_option,omitempty"`
}

func CreateInstance(client *golangsdk.ServiceClient, opts CreateInstanceOpts) (*CreateInstanceResponse, error) {
b, err := build.RequestBody(opts, "")
if err != nil {
return nil, err
}

// POST https://{Endpoint}/v3/{project_id}/instances
raw, err := client.Post(client.ServiceURL("instances"), b, nil, nil)
if err != nil {
return nil, err
}

var res CreateInstanceResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type CreateInstanceResponse struct {
// Instance ID
Id string `json:"id"`
// Database information, which is the same as the request parameter.
Datastore Datastore `json:"datastore"`
// Instance name, which is the same as the request parameter.
Name string `json:"name"`
// Creation time, which is in the yyyy-mm-dd hh:mm:ss format.
Created string `json:"created"`
// Instance status. The value is creating.
Status string `json:"status"`
// Region ID, which is the same as the request parameter.
Region string `json:"region"`
// AZ ID, which is the same as the request parameter.
AvailabilityZone string `json:"availability_zone"`
// VPC ID, which is the same as the request parameter.
VpcId string `json:"vpc_id"`
// Network ID of the subnet, which is the same as the request parameter.
SubnetId string `json:"subnet_id"`
// Security group ID, which is the same as the request parameter.
SecurityGroupId string `json:"security_group_id"`
// Instance type, which is the same as the request parameter.
Mode string `json:"mode"`
// Instance specification, which is the same as the request parameter.
Flavor []InstanceFlavor `json:"flavor"`
// Advanced backup policy, which is the same as the request parameter.
BackupStrategy BackupStrategy `json:"backup_strategy"`
// Indicates whether to enable SSL, which functions the same as the request parameter.
SslOption string `json:"ssl_option"`
// ID of the job for creating an instance.
JobId string `json:"job_id"`
}

type Datastore struct {
// Database type
// GaussDB(for Cassandra) instances are supported.
// The value "cassandra" indicates that a GaussDB(for Cassandra) DB instance is created.
Type string `json:"type"`
// Database version
// The value "3.11" indicates that the GaussDB(for Cassandra) 3.11 is supported.
Version string `json:"version"`
// Storage engine
// The value "rocksDB" indicates that the GaussDB(for Cassandra) instance supports the RocksDB storage engine.
StorageEngine string `json:"storage_engine"`
}

type InstanceFlavor struct {
// Node quantity
// The number of GaussDB(for Cassandra) instance nodes ranges from 3 to 200.
Num string `json:"num"`
// Disk type
// Valid value: ULTRAHIGH, which indicates the SSD disk.
Storage string `json:"storage"`
// Storage space. The value must be an integer, in GB.
Size string `json:"size"`
// Resource specification code
SpecCode string `json:"spec_code"`
}

type BackupStrategy struct {
// Backup time window Automated backups will be triggered during the backup time window.
// The value cannot be empty. It must be a valid value in the "hh:mm-HH:MM" format.
// The current time is in the UTC format.
StartTime string `json:"start_time"`
// Number of days to retain the generated backup files.
// Value range: 0-35.
KeepDays string `json:"keep_days,omitempty"`
}
26 changes: 26 additions & 0 deletions openstack/gaussdbnosql/v3/instance/DeleteInstance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package instance

import (
"net/http"

golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

func DeleteInstance(client *golangsdk.ServiceClient, instanceId string) (string, error) {
// DELETE https://{Endpoint}/v3/{project_id}/instances/{instance_id}
raw, err := client.Delete(client.ServiceURL("instances", instanceId), nil)
return extraJob(err, raw)
}

func extraJob(err error, raw *http.Response) (string, error) {
Aloento marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return "", err
}

var res struct {
JobId string `json:"job_id"`
}
err = extract.Into(raw.Body, &res)
return res.JobId, err
}
Loading