-
Notifications
You must be signed in to change notification settings - Fork 71
/
ddcrds.go
1586 lines (1469 loc) · 47.8 KB
/
ddcrds.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package ddcrds
import (
"encoding/json"
"fmt"
"strconv"
"strings"
"github.com/baidubce/bce-sdk-go/services/ddc/ddc_util"
"github.com/baidubce/bce-sdk-go/services/rds"
)
// Int int point helper
func Int(value string) *int {
if len(value) < 1 {
return nil
}
intPtr, err := strconv.Atoi(value)
if err != nil {
panic("please pass valid int value ")
}
return &intPtr
}
func Json(v interface{}) string {
jsonStr, err := json.Marshal(v)
if err != nil {
panic("convert to json faild")
}
return string(jsonStr)
}
func isDDC(productType string) bool {
return productType == "ddc" || productType == "DDC"
}
// 根据实例ID判断产品类型是否为DDC
func isDDCId(instanceId string) bool {
if strings.HasPrefix(instanceId, "rds") {
return false
}
return true
}
func getDDCAndRDSIds(instanceIds string) (string, string) {
instanceIdArr := strings.Split(instanceIds, ",")
ddcIds, rdsIds := "", ""
if len(instanceIdArr) > 0 {
for _, id := range instanceIdArr {
if isDDCId(id) {
ddcIds += id + ","
} else {
rdsIds += id + ","
}
}
}
if strings.HasSuffix(ddcIds, ",") {
ddcIds = ddcIds[:len(ddcIds)-1]
}
if strings.HasSuffix(rdsIds, ",") {
rdsIds = rdsIds[:len(rdsIds)-1]
}
return ddcIds, rdsIds
}
// CreateInstance - create a Instance with the specific parameters
//
// PARAMS:
// - args: the arguments to create a instance
// RETURNS:
// - *InstanceIds: the result of create RDS, contains new RDS's instanceIds
// - error: nil if success otherwise the specific error
func (c *Client) CreateRds(args *CreateRdsArgs, productType string) (*CreateResult, error) {
if args == nil {
return nil, fmt.Errorf("unset args")
}
// 限制InstanceName
if strings.Contains(args.InstanceName, ".") {
return nil, fmt.Errorf("invalid InstanceName:. not support")
}
var result *CreateResult
var err error
if isDDC(productType) {
result, err = c.ddcClient.CreateRds(args)
} else {
rdsArgs := &rds.CreateRdsArgs{}
// copy 请求参数
err = ddc_util.SimpleCopyProperties(rdsArgs, args)
if err != nil {
return nil, err
}
var rdsRes *rds.CreateResult
rdsRes, err = c.rdsClient.CreateRds(rdsArgs)
if rdsRes != nil {
result = &CreateResult{InstanceIds: rdsRes.InstanceIds}
}
}
return result, err
}
// CreateReadReplica - create a readReplica RDS with the specific parameters
//
// PARAMS:
// - args: the arguments to create a readReplica rds
// RETURNS:
// - *InstanceIds: the result of create a readReplica RDS, contains the readReplica RDS's instanceIds
// - error: nil if success otherwise the specific error
func (c *Client) CreateReadReplica(args *CreateReadReplicaArgs) (*CreateResult, error) {
if args == nil {
return nil, fmt.Errorf("unset args")
}
if len(args.SourceInstanceId) < 1 {
return nil, fmt.Errorf("unset SourceInstanceId")
}
// 默认创建1个只读实例
if args.PurchaseCount < 1 {
args.PurchaseCount = 1
}
var result *CreateResult
var err error
if isDDCId(args.SourceInstanceId) {
result, err = c.ddcClient.CreateReadReplica(args)
} else {
rdsArgs := &rds.CreateReadReplicaArgs{}
// copy 请求参数
err = ddc_util.SimpleCopyProperties(rdsArgs, args)
if err != nil {
return nil, err
}
var rdsRes *rds.CreateResult
rdsRes, err = c.rdsClient.CreateReadReplica(rdsArgs)
if rdsRes != nil {
result = &CreateResult{InstanceIds: rdsRes.InstanceIds}
}
}
return result, err
}
// CreateHotBackup - create a hotBackup ddc with the specific parameters
//
// PARAMS:
// - args: the arguments to create a hotBackup ddc
// RETURNS:
// - *InstanceIds: the result of create a hotBackup ddc, contains the hotBackup DDC's instanceIds
// - error: nil if success otherwise the specific error
func (c *Client) CreateHotBackup(args *CreateHotBackupArgs) (*CreateResult, error) {
if args == nil {
return nil, fmt.Errorf("unset args")
}
if len(args.SourceInstanceId) < 1 {
return nil, fmt.Errorf("unset SourceInstanceId")
}
// 默认创建1个热备实例
if args.PurchaseCount < 1 {
args.PurchaseCount = 1
}
var result *CreateResult
var err error
if isDDCId(args.SourceInstanceId) {
result, err = c.ddcClient.CreateHotBackup(args)
}
return result, err
}
// UpdateRoGroup - update a roGroup
//
// PARAMS:
// - body: http request body
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) UpdateRoGroup(roGroupId string, args *UpdateRoGroupArgs, productType string) error {
if isDDC(productType) {
return c.ddcClient.UpdateRoGroup(roGroupId, args)
}
return RDSNotSupportError()
}
// UpdateRoGroupReplicaWeight- update repica weight in roGroup
//
// PARAMS:
// - body: http request body
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) UpdateRoGroupReplicaWeight(roGroupId string, args *UpdateRoGroupWeightArgs, productType string) error {
if isDDC(productType) {
return c.ddcClient.UpdateRoGroupReplicaWeight(roGroupId, args)
}
return RDSNotSupportError()
}
// ReBalanceRoGroup- Initiate a rebalance for foGroup
//
// PARAMS:
// - body: http request body
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) ReBalanceRoGroup(roGroupId, productType string) error {
if len(roGroupId) < 1 {
return fmt.Errorf("unset roGroupId")
}
if isDDC(productType) {
return c.ddcClient.ReBalanceRoGroup(roGroupId)
}
return RDSNotSupportError()
}
// CreateRdsProxy - create a proxy RDS with the specific parameters
//
// PARAMS:
// - args: the arguments to create a readReplica rds
// RETURNS:
// - *InstanceIds: the result of create a readReplica RDS, contains the readReplica RDS's instanceIds
// - error: nil if success otherwise the specific error
func (c *Client) CreateRdsProxy(args *CreateRdsProxyArgs) (*CreateResult, error) {
if args == nil {
return nil, fmt.Errorf("unset args")
}
if len(args.SourceInstanceId) < 1 {
return nil, fmt.Errorf("unset SourceInstanceId")
}
if isDDCId(args.SourceInstanceId) {
return nil, DDCNotSupportError()
}
// copy请求参数
rdsArgs := &rds.CreateRdsProxyArgs{}
err := ddc_util.SimpleCopyProperties(rdsArgs, args)
if err != nil {
return nil, err
}
// copy返回结果
rdsRes, err := c.rdsClient.CreateRdsProxy(rdsArgs)
if err != nil {
return nil, err
}
result := &CreateResult{InstanceIds: rdsRes.InstanceIds}
return result, err
}
func (c *Client) listRdsInstance(marker *ListRdsArgs) (*ListRdsResult, error) {
rdsArgs := &rds.ListRdsArgs{}
// copy请求参数
err := ddc_util.SimpleCopyProperties(rdsArgs, marker)
if err != nil {
return nil, err
}
var rdsRes *rds.ListRdsResult
rdsRes, err = c.rdsClient.ListRds(rdsArgs)
// copy返回结果
result := &ListRdsResult{}
if rdsRes != nil {
err = ddc_util.SimpleCopyProperties(result, rdsRes)
}
if result.Instances != nil &&
len(result.Instances) > 0 {
for i := range result.Instances {
err = convertRdsInstance(&result.Instances[i])
}
}
return result, err
}
// ListPage - list all instances with page
// RETURNS:
// - *ListRdsResult: the result of list instances with page
// - error: nil if success otherwise the specific error
func (c *Client) ListPage(args *ListPageArgs) (*ListPageResult, error) {
result, err := c.ddcClient.ListPage(args)
return result, err
}
// ListRds - list all instances
// RETURNS:
// - *ListRdsResult: the result of list instances with marker
// - error: nil if success otherwise the specific error
func (c *Client) ListRds(marker *ListRdsArgs) (*ListRdsResult, error) {
var result *ListRdsResult
var err error
// 先获取DDC列表
if len(marker.Marker) < 1 || marker.Marker == "-1" || isDDCId(marker.Marker) {
result, err = c.ddcClient.ListRds(marker)
if err != nil {
return nil, err
}
// 数量不够时获取RDS列表
if len(result.Instances) < marker.MaxKeys {
// 修改marker
marker.MaxKeys = marker.MaxKeys - len(result.Instances)
rdsResult, err := c.listRdsInstance(marker)
if err != nil {
return nil, err
}
// 合并结果到result
if rdsResult != nil && len(rdsResult.Instances) > 0 {
result.Instances = append(result.Instances, rdsResult.Instances...)
result.Marker = rdsResult.Marker
result.IsTruncated = rdsResult.IsTruncated
result.NextMarker = rdsResult.NextMarker
}
} else if !result.IsTruncated {
// 使用IsTruncated判断DDC实例是否已查询完
marker.MaxKeys = 1
rdsResult, err := c.listRdsInstance(marker)
if err != nil {
return nil, err
}
if rdsResult != nil && len(rdsResult.Instances) > 0 {
result.NextMarker = rdsResult.Instances[0].InstanceId
result.IsTruncated = true
}
}
return result, err
}
// marker 到达rds时,直接取rds列表
result, err = c.listRdsInstance(marker)
return result, err
}
// GetDetail - get a specific ddc Instance's detail
//
// PARAMS:
// - instanceId: the specific ddc Instance's ID
// RETURNS:
// - *Instance: the specific ddc Instance's detail
// - error: nil if success otherwise the specific error
func (c *Client) GetDetail(instanceId string) (*Instance, error) {
var result *Instance
var err error
if isDDCId(instanceId) {
result, err = c.ddcClient.GetDetail(instanceId)
} else {
rdsRes, err1 := c.rdsClient.GetDetail(instanceId)
if err1 != nil {
return nil, err
}
// copy返回结果
if rdsRes != nil {
result = &Instance{}
err = ddc_util.SimpleCopyProperties(result, rdsRes)
if err != nil {
return nil, err
}
err = convertRdsInstance(result)
}
}
return result, err
}
// 修改RDS中参数类型无法匹配的字段
func convertRdsInstance(result *Instance) error {
// rds公网访问
// Closed 未开放外网权限
// Creating 公网开通中,成功后状态为Available
// Available 已开通公网
result.PubliclyAccessible = result.PublicAccessStatus == "Available"
days := result.BackupPolicy.ExpireInDaysStr
var err error
if len(days) > 0 {
result.BackupPolicy.ExpireInDaysInt, err = strconv.Atoi(days)
}
return err
}
// DeleteRds - delete instances
//
// PARAMS:
// - instanceIds: id of the instance
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) DeleteRds(instanceIds string) error {
var err error
ddcIds, rdsIds := getDDCAndRDSIds(instanceIds)
if len(ddcIds) > 0 {
err = c.ddcClient.DeleteRds(ddcIds)
}
if err != nil {
return err
}
if len(rdsIds) > 0 {
err = c.rdsClient.DeleteRds(rdsIds)
}
return err
}
// ResizeRds - resize an RDS with the specific parameters
//
// PARAMS:
// - instanceId: the specific instanceId
// - args: the arguments to resize an RDS
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) ResizeRds(instanceId string, args *ResizeRdsArgs) (*OrderIdResponse, error) {
if isDDCId(instanceId) {
return c.ddcClient.ResizeRds(instanceId, args)
}
// copy请求参数
resReq := &rds.ResizeRdsArgs{}
err := ddc_util.SimpleCopyProperties(resReq, args)
if err != nil {
return nil, err
}
err = c.rdsClient.ResizeRds(instanceId, resReq)
return nil, err
}
// CreateAccount - create a account with the specific parameters
//
// PARAMS:
// - instanceId: the specific instanceId
// - args: the arguments to create a account
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) CreateAccount(instanceId string, args *CreateAccountArgs) error {
var err error
if isDDCId(instanceId) {
err = c.ddcClient.CreateAccount(instanceId, args)
} else {
rdsArgs := &rds.CreateAccountArgs{}
// copy请求参数
err = ddc_util.SimpleCopyProperties(rdsArgs, args)
if err != nil {
return err
}
err = c.rdsClient.CreateAccount(instanceId, rdsArgs)
}
return err
}
// ListAccount - list all account of a RDS instance with the specific parameters
//
// PARAMS:
// - instanceId: the specific rds Instance's ID
// RETURNS:
// - *ListAccountResult: the result of list all account, contains all accounts' meta
// - error: nil if success otherwise the specific error
func (c *Client) ListAccount(instanceId string) (*ListAccountResult, error) {
var result *ListAccountResult
var err error
if isDDCId(instanceId) {
result, err = c.ddcClient.ListAccount(instanceId)
} else {
var rdsRes *rds.ListAccountResult
rdsRes, err = c.rdsClient.ListAccount(instanceId)
// copy返回结果
if rdsRes != nil {
result = &ListAccountResult{}
err = ddc_util.SimpleCopyProperties(result, rdsRes)
}
}
return result, err
}
// GetAccount - get an account of a RDS instance with the specific parameters
//
// PARAMS:
// - instanceId: the specific rds Instance's ID
// - accountName: the specific account's name
// RETURNS:
// - *Account: the account's meta
// - error: nil if success otherwise the specific error
func (c *Client) GetAccount(instanceId, accountName string) (*Account, error) {
var result *Account
var err error
if isDDCId(instanceId) {
result, err = c.ddcClient.GetAccount(instanceId, accountName)
} else {
var rdsRes *rds.Account
rdsRes, err = c.rdsClient.GetAccount(instanceId, accountName)
// copy返回结果
if rdsRes != nil {
result = &Account{}
err = ddc_util.SimpleCopyProperties(result, rdsRes)
}
}
return result, err
}
// DeleteAccount - delete an account of a RDS instance
//
// PARAMS:
// - instanceIds: the specific instanceIds
// - accountName: the specific account's name
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) DeleteAccount(instanceId, accountName string) error {
var err error
if isDDCId(instanceId) {
err = c.ddcClient.DeleteAccount(instanceId, accountName)
} else {
err = c.rdsClient.DeleteAccount(instanceId, accountName)
}
return err
}
// RebootInstance - reboot a specified instance
//
// PARAMS:
// - cli: the client agent which can perform sending request
// - instanceId: id of the instance to be rebooted
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) RebootInstance(instanceId string) error {
if isDDCId(instanceId) {
args := &RebootArgs{IsRebootNow: true}
_, err := c.ddcClient.RebootInstanceWithArgs(instanceId, args)
return err
}
err := c.rdsClient.RebootInstance(instanceId)
return err
}
// RebootInstance - reboot a specified instance
//
// PARAMS:
// - cli: the client agent which can perform sending request
// - instanceId: id of the instance to be rebooted
// - args: reboot args
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) RebootInstanceWithArgs(instanceId string, args *RebootArgs) (*MaintainTaskIdResult, error) {
if isDDCId(instanceId) {
return c.ddcClient.RebootInstanceWithArgs(instanceId, args)
}
return nil, RDSNotSupportError()
}
// UpdateInstanceName - update name of a specified instance
//
// PARAMS:
// - cli: the client agent which can perform sending request
// - instanceId: id of the instance
// - args: the arguments to update instanceName
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) UpdateInstanceName(instanceId string, args *UpdateInstanceNameArgs) error {
var err error
if isDDCId(instanceId) {
err = c.ddcClient.UpdateInstanceName(instanceId, args)
} else {
rdsArgs := &rds.UpdateInstanceNameArgs{
InstanceName: args.InstanceName,
}
err = c.rdsClient.UpdateInstanceName(instanceId, rdsArgs)
}
return err
}
// UpdateSyncMode - update sync mode of a specified instance
//
// PARAMS:
// - cli: the client agent which can perform sending request
// - instanceId: id of the instance
// - args: the arguments to update syncMode
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) ModifySyncMode(instanceId string, args *ModifySyncModeArgs) error {
if args == nil {
return fmt.Errorf("unset args")
}
if isDDCId(instanceId) {
return c.ddcClient.ModifySyncMode(instanceId, args)
}
rdsArgs := &rds.ModifySyncModeArgs{SyncMode: args.SyncMode}
err := c.rdsClient.ModifySyncMode(instanceId, rdsArgs)
return err
}
// ModifyEndpoint - modify the prefix of endpoint
//
// PARAMS:
// - cli: the client agent which can perform sending request
// - instanceId: id of the instance
// - args: the arguments to modify endpoint
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) ModifyEndpoint(instanceId string, args *ModifyEndpointArgs) error {
if isDDCId(instanceId) {
return DDCNotSupportError()
}
rdsArgs := &rds.ModifyEndpointArgs{Address: args.Address}
err := c.rdsClient.ModifyEndpoint(instanceId, rdsArgs)
return err
}
// ModifyPublicAccess - modify public access
//
// PARAMS:
// - cli: the client agent which can perform sending request
// - instanceId: id of the instance
// - args: the arguments to modify public access
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) ModifyPublicAccess(instanceId string, args *ModifyPublicAccessArgs) error {
if isDDCId(instanceId) {
return DDCNotSupportError()
}
rdsArgs := &rds.ModifyPublicAccessArgs{PublicAccess: args.PublicAccess}
err := c.rdsClient.ModifyPublicAccess(instanceId, rdsArgs)
return err
}
// GetBackupList - get backup list of the instance
//
// PARAMS:
// - cli: the client agent which can perform sending request
// - instanceId: id of the instance
// RETURNS:
// - *GetBackupListResult: result of the backup list
// - error: nil if success otherwise the specific error
func (c *Client) GetBackupList(instanceId string, args *GetBackupListArgs) (*GetBackupListResult, error) {
var result *GetBackupListResult
var err error
if isDDCId(instanceId) {
result, err = c.ddcClient.GetBackupList(instanceId, args)
} else {
rdsArgs := &rds.GetBackupListArgs{}
// copy请求参数
err = ddc_util.SimpleCopyProperties(rdsArgs, args)
if err != nil {
return nil, err
}
var rdsRes *rds.GetBackupListResult
rdsRes, err = c.rdsClient.GetBackupList(instanceId, rdsArgs)
// 转换返回结果
if rdsRes != nil {
result = &GetBackupListResult{}
err = ddc_util.SimpleCopyProperties(result, rdsRes)
}
}
return result, err
}
// GetZoneList - list all zone
//
// PARAMS:
// - cli: the client agent which can perform sending request
// RETURNS:
// - *GetZoneListResult: result of the zone list
// - error: nil if success otherwise the specific error
func (c *Client) GetZoneList(productType string) (*GetZoneListResult, error) {
if isDDC(productType) {
return c.ddcClient.GetZoneList()
}
rdsRes, err := c.rdsClient.GetZoneList()
if err != nil {
return nil, err
}
result := &GetZoneListResult{}
err = ddc_util.SimpleCopyProperties(result, rdsRes)
if err != nil {
return nil, err
}
return result, err
}
// ListsSubnet - list all Subnets
//
// PARAMS:
// - cli: the client agent which can perform sending request
// - args: the arguments to list all subnets, not necessary
// RETURNS:
// - *ListSubnetsResult: result of the subnet list
// - error: nil if success otherwise the specific error
func (c *Client) ListSubnets(args *ListSubnetsArgs, productType string) (*ListSubnetsResult, error) {
if isDDC(productType) {
return c.ddcClient.ListSubnets(args)
}
rdsArgs := &rds.ListSubnetsArgs{}
err := ddc_util.SimpleCopyProperties(rdsArgs, args)
if err != nil {
return nil, err
}
rdsRes, err := c.rdsClient.ListSubnets(rdsArgs)
if err != nil {
return nil, err
}
result := &ListSubnetsResult{}
err = ddc_util.SimpleCopyProperties(result, rdsRes)
return result, err
}
// GetSecurityIps - get all SecurityIps
//
// PARAMS:
// - instanceId: the specific rds Instance's ID
// RETURNS:
// - *GetSecurityIpsResult: all security IP
// - error: nil if success otherwise the specific error
func (c *Client) GetSecurityIps(instanceId string) (*GetSecurityIpsResult, error) {
if isDDCId(instanceId) {
return c.ddcClient.GetSecurityIps(instanceId)
}
rdsRes, err := c.rdsClient.GetSecurityIps(instanceId)
if err != nil {
return nil, err
}
result := &GetSecurityIpsResult{}
err = ddc_util.SimpleCopyProperties(result, rdsRes)
return result, err
}
// UpdateSecurityIps - update SecurityIps
//
// PARAMS:
// - instanceId: the specific rds Instance's ID
// - Etag: get latest etag by GetSecurityIps
// - Args: all SecurityIps
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) UpdateSecurityIps(instanceId, Etag string, args *UpdateSecurityIpsArgs) error {
if isDDCId(instanceId) {
return c.ddcClient.UpdateSecurityIps(instanceId, args)
}
rdsArgs := &rds.UpdateSecurityIpsArgs{SecurityIps: args.SecurityIps}
err := c.rdsClient.UpdateSecurityIps(instanceId, Etag, rdsArgs)
return err
}
// ListParameters - list all parameters of a RDS instance
//
// PARAMS:
// - instanceId: the specific rds Instance's ID
// RETURNS:
// - *ListParametersResult: the result of list all parameters
// - error: nil if success otherwise the specific error
func (c *Client) ListParameters(instanceId string) (*ListParametersResult, error) {
if isDDCId(instanceId) {
return c.ddcClient.ListParameters(instanceId)
}
rdsRes, err := c.rdsClient.ListParameters(instanceId)
result := &ListParametersResult{}
err1 := ddc_util.SimpleCopyProperties(result, rdsRes)
if err1 != nil {
return nil, err1
}
// 兼容rds处理
if result.Parameters != nil && len(result.Parameters) > 0 {
for i, parameter := range result.Parameters {
result.Parameters[i].IsDynamic = parameter.Dynamic == "true"
result.Parameters[i].ISModifiable = parameter.Modifiable == "true"
}
}
return result, err
}
// UpdateParameter - update Parameter
//
// PARAMS:
// - instanceId: the specific rds Instance's ID
// - Etag: get latest etag by ListParameters
// - Args: *UpdateParameterArgs
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) UpdateParameter(instanceId, Etag string, args *UpdateParameterArgs) (*ProducedMaintainTaskResult, error) {
if isDDCId(instanceId) {
return c.ddcClient.UpdateParameter(instanceId, args)
}
rdsArgs := &rds.UpdateParameterArgs{}
err1 := ddc_util.SimpleCopyProperties(rdsArgs, args)
if err1 != nil {
return nil, err1
}
err := c.rdsClient.UpdateParameter(instanceId, Etag, rdsArgs)
return nil, err
}
// CreateDeploySet - create a deploy set
//
// PARAMS:
// - body: http request body
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) CreateDeploySet(poolId string, args *CreateDeployRequest) (*CreateDeployResult, error) {
return c.ddcClient.CreateDeploySet(poolId, args)
}
// UpdateDeploySet - create a deploy set
//
// PARAMS:
// - body: http request body
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) UpdateDeploySet(poolId, deployId string, args *UpdateDeployRequest) error {
return c.ddcClient.UpdateDeploySet(poolId, deployId, args)
}
// ListDeploySets - list all deploy sets
// RETURNS:
// - *ListResultWithMarker: the result of list deploy sets with marker
// - error: nil if success otherwise the specific error
func (c *Client) ListDeploySets(poolId string, marker *Marker) (*ListDeploySetResult, error) {
return c.ddcClient.ListDeploySets(poolId, marker)
}
// ListPool - list current pools
// RETURNS:
// - *ListResultWithMarker: the result of list hosts with marker
// - error: nil if success otherwise the specific error
func (c *Client) ListPool(marker *Marker, productType string) (*ListPoolResult, error) {
if !isDDC(productType) {
return nil, RDSNotSupportError()
}
return c.ddcClient.ListPool(marker)
}
// GetDeploySet - get details of the deploy set
//
// PARAMS:
// - poolId: the id of the pool
// - cli: the client agent which can perform sending request
// - deploySetId: the id of the deploy set
// RETURNS:
// - *DeploySet: the detail of the deploy set
// - error: nil if success otherwise the specific error
func (c *Client) GetDeploySet(poolId string, deploySetId string) (*DeploySet, error) {
return c.ddcClient.GetDeploySet(poolId, deploySetId)
}
// DeleteDeploySet - delete a deploy set
//
// PARAMS:
// - poolId: the id of the pool
// - deploySetId: the id of the deploy set
// - clientToken: idempotent token, an ASCII string no longer than 64 bits
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) DeleteDeploySet(poolId string, deploySetId string) error {
return c.ddcClient.DeleteDeploySet(poolId, deploySetId)
}
// CreateBackup - create backup of the instance
//
// PARAMS:
// - instanceId: the id of the instance
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) CreateBackup(instanceId string) error {
if !isDDCId(instanceId) {
return RDSNotSupportError()
}
return c.ddcClient.CreateBackup(instanceId)
}
// ModifyBackupPolicy - update backupPolicy
//
// PARAMS:
// - instanceId: the specific rds Instance's ID
// - Args: the specific rds Instance's BackupPolicy
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) ModifyBackupPolicy(instanceId string, args *BackupPolicy) error {
if !isDDCId(instanceId) {
return RDSNotSupportError()
}
return c.ddcClient.ModifyBackupPolicy(instanceId, args)
}
// GetBackupDetail - get details of the instance'Backup
//
// PARAMS:
// - instanceId: the id of the instance
// - snapshotId: the id of the backup
// RETURNS:
// - *BackupDetailResult: the detail of the backup
// - error: nil if success otherwise the specific error
func (c *Client) GetBackupDetail(instanceId string, snapshotId string) (*BackupDetailResult, error) {
if !isDDCId(instanceId) {
return nil, RDSNotSupportError()
}
return c.ddcClient.GetBackupDetail(instanceId, snapshotId)
}
// GetBinlogList - get backup list of the instance
//
// PARAMS:
// - instanceId: id of the instance
// RETURNS:
// - *BinlogListResult: result of the backup list
// - error: nil if success otherwise the specific error
func (c *Client) GetBinlogList(instanceId string, datetime string) (*BinlogListResult, error) {
if !isDDCId(instanceId) {
return nil, RDSNotSupportError()
}
return c.ddcClient.GetBinlogList(instanceId, datetime)
}
// GetBinlogDetail - get details of the instance'Binlog
//
// PARAMS:
// - instanceId: the id of the instance
// - binlog: the id of the binlog
// RETURNS:
// - *BinlogDetailResult: the detail of the binlog
// - error: nil if success otherwise the specific error
func (c *Client) GetBinlogDetail(instanceId string, binlog string) (*BinlogDetailResult, error) {
if !isDDCId(instanceId) {
return nil, RDSNotSupportError()
}
return c.ddcClient.GetBinlogDetail(instanceId, binlog)
}
// SwitchInstance - main standby switching of the instance
//
// PARAMS:
// - instanceId: the id of the instance
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) SwitchInstance(instanceId string, args *SwitchArgs) (*ProducedMaintainTaskResult, error) {
if !isDDCId(instanceId) {
return nil, RDSNotSupportError()
}
return c.ddcClient.SwitchInstance(instanceId, args)
}
// CreateDatabase - create a database with the specific parameters
//
// PARAMS:
// - instanceId: the specific instanceId
// - args: the arguments to create a account
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) CreateDatabase(instanceId string, args *CreateDatabaseArgs) error {
if !isDDCId(instanceId) {
return RDSNotSupportError()
}
return c.ddcClient.CreateDatabase(instanceId, args)
}
// DeleteDatabase - delete an database of a DDC instance
//
// PARAMS:
// - instanceIds: the specific instanceIds
// - dbName: the specific database's name
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) DeleteDatabase(instanceId, dbName string) error {
if !isDDCId(instanceId) {
return RDSNotSupportError()
}
return c.ddcClient.DeleteDatabase(instanceId, dbName)
}
// UpdateDatabaseRemark - update a database remark with the specific parameters
//
// PARAMS:
// - instanceId: the specific instanceId
// - dbName: the specific accountName
// - args: the arguments to update a database remark
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) UpdateDatabaseRemark(instanceId string, dbName string, args *UpdateDatabaseRemarkArgs) error {
if !isDDCId(instanceId) {
return RDSNotSupportError()
}
return c.ddcClient.UpdateDatabaseRemark(instanceId, dbName, args)
}
// GetDatabase - get an database of a DDC instance with the specific parameters
//
// PARAMS:
// - instanceId: the specific rds Instance's ID
// - dbName: the specific database's name
// RETURNS:
// - *Database: the database's meta
// - error: nil if success otherwise the specific error
func (c *Client) GetDatabase(instanceId, dbName string) (*Database, error) {
if !isDDCId(instanceId) {
return nil, RDSNotSupportError()
}
return c.ddcClient.GetDatabase(instanceId, dbName)
}
// ListDatabase - list all database of a DDC instance with the specific parameters
//
// PARAMS:
// - instanceId: the specific ddc Instance's ID
// RETURNS:
// - *ListDatabaseResult: the result of list all database, contains all databases' meta
// - error: nil if success otherwise the specific error
func (c *Client) ListDatabase(instanceId string) (*ListDatabaseResult, error) {
if !isDDCId(instanceId) {
return nil, RDSNotSupportError()
}
return c.ddcClient.ListDatabase(instanceId)
}
// GetTableAmount - query amount of tables
//
// PARAMS:
// - args: the specific ddc instanceId, dbName and search pattern