Skip to content

Commit

Permalink
Add features in bcm, et and gaiadb
Browse files Browse the repository at this point in the history
  • Loading branch information
duanliguo committed Jul 15, 2024
1 parent f063385 commit 5937ab3
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 44 deletions.
2 changes: 1 addition & 1 deletion bce/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

// Constants and default values for the package bce
const (
SDK_VERSION = "0.9.184"
SDK_VERSION = "0.9.133"
URI_PREFIX = "/" // now support uri without prefix "v1" so just set root path
DEFAULT_DOMAIN = "baidubce.com"
DEFAULT_PROTOCOL = "http"
Expand Down
1 change: 1 addition & 0 deletions doc/GAIADB.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ args := &gaiadb.CreateClusterArgs{
VpcId: "vpc-it3v6qt3jhvj",
InstanceAmount: 2,
ProxyAmount: 2,
ComputeTplId: "p80f-xxxyyy",
},
}
result, err := GAIADB_CLIENT.CreateCluster(args)
Expand Down
7 changes: 7 additions & 0 deletions examples/etGateway/examples_create_et_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package etgatewayexamples

import (
"fmt"
"github.com/baidubce/bce-sdk-go/model"
"github.com/baidubce/bce-sdk-go/services/etGateway"
"github.com/baidubce/bce-sdk-go/util"
)
Expand All @@ -28,6 +29,12 @@ func CreateEtGateway() {
ChannelId: "sdxs",
LocalCidrs: []string{"10.240.0.0/16", "192.168.3.0/24"},
ClientToken: getClientToken(),
Tags: []model.TagModel{
{
TagKey: "tagKey",
TagValue: "tagValue",
},
},
}
result, err := client.CreateEtGateway(args)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions examples/lbdc/example_create_lbdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package lbdcexamples

import (
"fmt"
"github.com/baidubce/bce-sdk-go/model"

"github.com/baidubce/bce-sdk-go/services/lbdc"
)
Expand All @@ -34,6 +35,12 @@ func CreateLbdc() {
ReservationLength: 1,
},
},
Tags: []model.TagModel{
{
TagKey: "tagKey",
TagValue: "tagValue",
},
},
}
res, err := client.CreateLbdc(args) // 创建lbdc
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions examples/vpc/ipv6gateway/example_create_ipv6gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ipv6gateway

import (
"fmt"
"github.com/baidubce/bce-sdk-go/model"

"github.com/baidubce/bce-sdk-go/services/vpc"
)
Expand All @@ -24,6 +25,12 @@ func CreateIPv6Gateway() {
Billing: &vpc.Billing{
PaymentTiming: vpc.PAYMENT_TIMING_POSTPAID,
},
Tags: []model.TagModel{
{
TagKey: "tagKey",
TagValue: "tagValue",
},
},
}
result, err := ipv6gatewayClient.CreateIPv6Gateway(args)
if err != nil {
Expand Down
45 changes: 45 additions & 0 deletions services/bcm/bcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const (
MultiMetricAllDataPath = "/csm/api/v2/data/metricAllData"
MultiMetricAllDataBatchPath = "/csm/api/v2/data/metricAllData/batch"
GetMetricDimensionTopPath = "/csm/api/v2/dimensions/top"
GetMetricDimensionTopDataPath = "/csm/api/v2/dimensions/top/data"

Average = "average"
Maximum = "maximum"
Expand Down Expand Up @@ -4240,6 +4241,50 @@ func (c *Client) GetMetricDimensionTop(req *model.TsdbDimensionTopQuery) (*model
return result, err
}

func (c *Client) GetMetricDimensionTopData(req *model.TsdbDimensionTopQuery) ([]*model.TsdbQueryMetaData, error) {
if req == nil {
return nil, errors.New("req should not be empty")
}
if len(req.UserID) <= 0 {
return nil, errors.New("userId should not be empty")
}
if len(req.Scope) <= 0 {
return nil, errors.New("scope should not be empty")
}
if len(req.MetricName) <= 0 {
return nil, errors.New("metricName should not be empty")
}
if len(req.Dimensions) <= 0 {
return nil, errors.New("dimensions should not be empty")
}
if len(req.Labels) <= 0 {
return nil, errors.New("labels should not be empty")
}
if len(req.StartTime) <= 0 {
return nil, errors.New("startTime should not be empty")
}
if len(req.EndTime) <= 0 {
return nil, errors.New("endTime should not be empty")
}
if len(req.Order) == 0 {
req.Order = "top"
}
if req.TopNum <= 0 {
req.TopNum = 10
}
if req.Cycle <= 0 {
req.Cycle = 60
}
var result []*model.TsdbQueryMetaData
err := bce.NewRequestBuilder(c).
WithURL(GetMetricDimensionTopDataPath).
WithBody(req).
WithMethod(http.POST).
WithResult(&result).
Do()
return result, err
}

// 判断传入字符串是否为utc时间,格式为:2023-12-12T00:00:00Z
func isUtcTime(str string) bool {
_, err := time.Parse(time.RFC3339, str)
Expand Down
24 changes: 24 additions & 0 deletions services/bcm/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3267,3 +3267,27 @@ func TestGetMetricDimensionTop(t *testing.T) {
content, _ := json.Marshal(response)
fmt.Println(string(content))
}

func TestGetMetricDimensionTopData(t *testing.T) {
req := &model.TsdbDimensionTopQuery{
UserID: bcmConf.UserId,
Region: "bj",
Scope: "BCE_PFS",
Dimensions: map[string]string{
"InstanceId": "pfs-1******7",
},
MetricName: "WriteIO",
Statistics: "average",
StartTime: "2024-07-10T07:10:01Z",
EndTime: "2024-07-10T07:20:01Z",
Labels: []string{
"FilesetId",
},
}
response, err := bcmClient.GetMetricDimensionTopData(req)
if err != nil {
t.Errorf("Get metric dimensions top and data error with %v\n", err)
}
content, _ := json.Marshal(response)
fmt.Println(string(content))
}
11 changes: 11 additions & 0 deletions services/bcm/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ type TsdbDimensionTopQuery struct {
Order string `json:"order,omitempty"`
TopNum int `json:"topNum,omitempty"`
Labels []string `json:"labels,omitempty"`
Cycle int `json:"cycle,omitempty"`
}

type TsdbDimensionTopResult struct {
Expand All @@ -473,3 +474,13 @@ type TopData struct {
Order int `json:"order,omitempty"`
Dimensions []Dimension `json:"dimensions,omitempty"`
}

type TsdbQueryMetaData struct {
RequestId string `json:"requestId,omitempty"`
UserId string `json:"userId,omitempty"`
ServiceName string `json:"serviceName,omitempty"`
MetricName string `json:"metricName,omitempty"`
Statistics []string `json:"statistics,omitempty"`
ResourceID string `json:"resourceId,omitempty"`
DataPoints []*DataPoints `json:"dataPoints,omitempty"`
}
7 changes: 7 additions & 0 deletions services/etGateway/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package etGateway
import (
"encoding/json"
"fmt"
"github.com/baidubce/bce-sdk-go/model"
"github.com/baidubce/bce-sdk-go/util"
"github.com/baidubce/bce-sdk-go/util/log"
"os"
Expand Down Expand Up @@ -83,6 +84,12 @@ func TestClient_CreateEtGateway(t *testing.T) {
VpcId: "vpc-2pa2x0bjt26i",
Speed: 100,
ClientToken: getClientToken(),
Tags: []model.TagModel{
{
TagKey: "tagKey",
TagValue: "tagValue",
},
},
}
result, err := EtGateway_CLIENT.CreateEtGateway(args)
ExpectEqual(t.Errorf, nil, err)
Expand Down
52 changes: 28 additions & 24 deletions services/etGateway/model.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package etGateway

import "github.com/baidubce/bce-sdk-go/model"

type (
HealthCheckType string
)
Expand All @@ -9,14 +11,15 @@ const (
)

type CreateEtGatewayArgs struct {
Name string `json:"name"`
VpcId string `json:"vpcId"`
Speed int `json:"speed"`
Description string `json:"description"`
EtId string `json:"etId"`
ChannelId string `json:"channelId"`
LocalCidrs []string `json:"localCidrs"`
ClientToken string `json:"clientToken,omitempty"`
Name string `json:"name"`
VpcId string `json:"vpcId"`
Speed int `json:"speed"`
Description string `json:"description"`
EtId string `json:"etId"`
ChannelId string `json:"channelId"`
LocalCidrs []string `json:"localCidrs"`
ClientToken string `json:"clientToken,omitempty"`
Tags []model.TagModel `json:"tags,omitempty"`
}

type CreateEtGatewayResult struct {
Expand Down Expand Up @@ -53,22 +56,23 @@ type EtGateway struct {
}

type EtGatewayDetail struct {
EtGatewayId string `json:"etGatewayId"`
Name string `json:"name"`
Status string `json:"status"`
Speed int `json:"speed"`
CreateTime string `json:"createTime"`
Description string `json:"description"`
VpcId string `json:"vpcId"`
EtId string `json:"etId"`
ChannelId string `json:"channelId"`
LocalCidrs []string `json:"localCidrs"`
HealthCheckSourceIp string `json:"healthCheckSourceIp"`
HealthCheckDestIp string `json:"healthCheckDestIp"`
HealthCheckType string `json:"healthCheckType"`
HealthCheckInterval int `json:"healthCheckInterval"`
HealthThreshold int `json:"healthThreshold"`
UnhealthThreshold int `json:"unhealthThreshold"`
EtGatewayId string `json:"etGatewayId"`
Name string `json:"name"`
Status string `json:"status"`
Speed int `json:"speed"`
CreateTime string `json:"createTime"`
Description string `json:"description"`
VpcId string `json:"vpcId"`
EtId string `json:"etId"`
ChannelId string `json:"channelId"`
LocalCidrs []string `json:"localCidrs"`
HealthCheckSourceIp string `json:"healthCheckSourceIp"`
HealthCheckDestIp string `json:"healthCheckDestIp"`
HealthCheckType string `json:"healthCheckType"`
HealthCheckInterval int `json:"healthCheckInterval"`
HealthThreshold int `json:"healthThreshold"`
UnhealthThreshold int `json:"unhealthThreshold"`
Tags []model.TagModel `json:"tags,omitempty"`
}

// 参数localCidrs只有在专线网关处于running状态时允许更新。
Expand Down
5 changes: 3 additions & 2 deletions services/gaiadb/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,14 @@ func TestClient_CreateGaiadb(t *testing.T) {
ProductType: "postpay",
InstanceParam: InstanceParam{
ReleaseVersion: "8.0",
SubnetId: "sbn-na4tmg4v11hs",
SubnetId: "sbn-dqafncqsy3y4",
AllocatedCpuInCore: 2,
AllocatedMemoryInMB: 8192,
AllocatedStorageInGB: 5120,
VpcId: "vpc-it3v6qt3jhvj",
VpcId: "vpc-70pxg3pmv8rv",
InstanceAmount: 2,
ProxyAmount: 2,
ComputeTplId: "p80f1db2-a21c-4bc5-ba6b-62afafdb8080",
},
}
result, err := GAIADB_CLIENT.CreateCluster(args)
Expand Down
1 change: 1 addition & 0 deletions services/gaiadb/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type InstanceParam struct {
SnapshotId string `json:"snapshotId,omitempty"`
Pit string `json:"pit,omitempty"`
LowerCaseTableNames string `json:"lowercaseTableNames,omitempty"`
ComputeTplId string `json:"computeTplId,omitempty"`
}
type CreateResult struct {
OrderId string `json:"orderId"`
Expand Down
7 changes: 7 additions & 0 deletions services/lbdc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lbdc

import (
"encoding/json"
"github.com/baidubce/bce-sdk-go/model"
"github.com/baidubce/bce-sdk-go/util"
"github.com/baidubce/bce-sdk-go/util/log"
"os"
Expand Down Expand Up @@ -98,6 +99,12 @@ func TestClient_CreateLbdc(t *testing.T) {
RenewReservation: &Reservation{
ReservationLength: 1,
},
Tags: []model.TagModel{
{
TagKey: "tagKey",
TagValue: "tagValue",
},
},
}
res, err := LDBC_CLIENT.CreateLbdc(args)
ExpectEqual(t.Errorf, nil, err)
Expand Down
28 changes: 16 additions & 12 deletions services/lbdc/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package lbdc

import "github.com/baidubce/bce-sdk-go/model"

type Reservation struct {
ReservationLength int `json:"reservationLength"`
}
Expand Down Expand Up @@ -46,13 +48,14 @@ type Cluster struct {

// CreateLbdcArgs defines the structure of input parameters for the CreateLbdc api
type CreateLbdcArgs struct {
ClientToken string `json:"-"`
Name string `json:"name"`
Type string `json:"type"`
CcuCount int `json:"ccuCount"`
Description *string `json:"desc,omitempty"`
Billing *Billing `json:"billing"`
RenewReservation *Reservation `json:"renewReservation"`
ClientToken string `json:"-"`
Name string `json:"name"`
Type string `json:"type"`
CcuCount int `json:"ccuCount"`
Description *string `json:"desc,omitempty"`
Billing *Billing `json:"billing"`
RenewReservation *Reservation `json:"renewReservation"`
Tags []model.TagModel `json:"tags,omitempty"`
}

// CreateLbdcResult defines the structure of output parameters for the CreateLbdc api
Expand Down Expand Up @@ -107,11 +110,12 @@ type GetLbdcDetailResult struct {
NetworkOutBps int64 `json:"networkOutBps"`

// 7layer
HttpsQps *int64 `json:"httpsQps,omitempty"`
HttpQps *int64 `json:"httpQps,omitempty"`
HttpNewConnectCps *int64 `json:"httpNewConnectCps,omitempty"`
HttpsNewConnectCps *int64 `json:"httpsNewConnectCps,omitempty"`
SslNewConnectCps *int64 `json:"sslNewConnectCps,omitempty"`
HttpsQps *int64 `json:"httpsQps,omitempty"`
HttpQps *int64 `json:"httpQps,omitempty"`
HttpNewConnectCps *int64 `json:"httpNewConnectCps,omitempty"`
HttpsNewConnectCps *int64 `json:"httpsNewConnectCps,omitempty"`
SslNewConnectCps *int64 `json:"sslNewConnectCps,omitempty"`
Tags []model.TagModel `json:"tags,omitempty"`
}

// UpdateLbdcArgs defines the structure of input parameters for the UpdateLbdc api
Expand Down
11 changes: 6 additions & 5 deletions services/vpc/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,11 +861,12 @@ type GetProbeDetailResult struct {

// CreateIPv6GatewayArgs defines the structure of the input parameters for the CreateIPv6Gateway api
type CreateIPv6GatewayArgs struct {
ClientToken string `json:"-"`
Name string `json:"name"`
VpcId string `json:"vpcId"`
BandwidthInMbps int `json:"bandwidthInMbps"`
Billing *Billing `json:"billing"`
ClientToken string `json:"-"`
Name string `json:"name"`
VpcId string `json:"vpcId"`
BandwidthInMbps int `json:"bandwidthInMbps"`
Billing *Billing `json:"billing"`
Tags []model.TagModel `json:"tags,omitempty"`
}

// CreateIPv6GatewayResult defines the structure of the output parameters for the CreateIPv6Gateway api
Expand Down

0 comments on commit 5937ab3

Please sign in to comment.