@@ -317,6 +317,37 @@ func (me *GaapService) DeleteCertificate(ctx context.Context, id string) error {
317
317
return nil
318
318
}
319
319
320
+ func waitTaskReady (ctx context.Context , client * gaap.Client , reqeustId string ) error {
321
+ logId := tccommon .GetLogId (ctx )
322
+
323
+ describeRequest := gaap .NewDescribeTaskStatusRequest ()
324
+ describeRequest .TaskId = helper .String (reqeustId )
325
+
326
+ err := resource .Retry (2 * tccommon .WriteRetryTimeout , func () * resource.RetryError {
327
+ ratelimit .Check (describeRequest .GetAction ())
328
+ response , err := client .DescribeTaskStatus (describeRequest )
329
+ if err != nil {
330
+ log .Printf ("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]" ,
331
+ logId , describeRequest .GetAction (), describeRequest .ToJsonString (), err )
332
+ return tccommon .RetryError (err )
333
+ }
334
+ // 任务状态:RUNNING,FAIL,SUCCESS
335
+ status := * response .Response .Status
336
+ if status == "SUCCESS" {
337
+ return nil
338
+ } else if status == "FAIL" {
339
+ return resource .NonRetryableError (fmt .Errorf ("Task[%s] failed" , reqeustId ))
340
+ } else {
341
+ return resource .RetryableError (fmt .Errorf ("Task[%s] status: %s" , reqeustId , status ))
342
+ }
343
+ })
344
+ if err != nil {
345
+ log .Printf ("[CRITAL]%s task failed, reason: %v" , logId , err )
346
+ return err
347
+ }
348
+ return nil
349
+ }
350
+
320
351
func (me * GaapService ) CreateProxy (
321
352
ctx context.Context ,
322
353
name , accessRegion , realserverRegion string ,
@@ -326,7 +357,7 @@ func (me *GaapService) CreateProxy(
326
357
) (id string , err error ) {
327
358
logId := tccommon .GetLogId (ctx )
328
359
client := me .client .UseGaapClient ()
329
-
360
+ var createProxyRequestId string
330
361
createRequest := gaap .NewCreateProxyRequest ()
331
362
createRequest .ProxyName = & name
332
363
createRequest .ProjectId = helper .IntInt64 (projectId )
@@ -362,57 +393,15 @@ func (me *GaapService) CreateProxy(
362
393
}
363
394
364
395
id = * response .Response .InstanceId
396
+ createProxyRequestId = * response .Response .RequestId
365
397
return nil
366
398
}); err != nil {
367
399
log .Printf ("[CRITAL]%s create proxy failed, reason: %v" , logId , err )
368
400
return "" , err
369
401
}
370
402
371
- describeRequest := gaap .NewDescribeProxiesRequest ()
372
- describeRequest .ProxyIds = []* string {& id }
373
-
374
- if err := resource .Retry (tccommon .ReadRetryTimeout , func () * resource.RetryError {
375
- ratelimit .Check (describeRequest .GetAction ())
376
-
377
- response , err := client .DescribeProxies (describeRequest )
378
- if err != nil {
379
- log .Printf ("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]" ,
380
- logId , describeRequest .GetAction (), describeRequest .ToJsonString (), err )
381
- return tccommon .RetryError (err )
382
- }
383
-
384
- proxies := response .Response .ProxySet
385
-
386
- switch len (proxies ) {
387
- case 0 :
388
- err := errors .New ("read no proxy" )
389
- log .Printf ("[DEBUG]%s %v" , logId , err )
390
- return resource .RetryableError (err )
391
-
392
- default :
393
- err := errors .New ("return more than 1 proxy" )
394
- log .Printf ("[DEBUG]%s %v" , logId , err )
395
- return resource .NonRetryableError (err )
396
-
397
- case 1 :
398
- }
399
-
400
- proxy := proxies [0 ]
401
- if proxy .Status == nil {
402
- err := errors .New ("proxy status is nil" )
403
- log .Printf ("[CRITAL]%s %v" , logId , err )
404
- return resource .NonRetryableError (err )
405
- }
406
-
407
- if * proxy .Status != GAAP_PROXY_RUNNING {
408
- err := errors .New ("proxy is still creating" )
409
- log .Printf ("[DEBUG]%s %v" , logId , err )
410
- return resource .RetryableError (err )
411
- }
412
-
413
- return nil
414
- }); err != nil {
415
- log .Printf ("[CRITAL]%s create proxy failed, reason: %v" , logId , err )
403
+ time .Sleep (3 * time .Second )
404
+ if err := waitTaskReady (ctx , client , createProxyRequestId ); err != nil {
416
405
return "" , err
417
406
}
418
407
@@ -717,7 +706,7 @@ func (me *GaapService) ModifyProxyProjectId(ctx context.Context, id string, proj
717
706
func (me * GaapService ) ModifyProxyConfiguration (ctx context.Context , id string , bandwidth , concurrent * int ) error {
718
707
logId := tccommon .GetLogId (ctx )
719
708
client := me .client .UseGaapClient ()
720
-
709
+ var modifyProxyRequestId string
721
710
modifyRequest := gaap .NewModifyProxyConfigurationRequest ()
722
711
modifyRequest .ProxyId = & id
723
712
if bandwidth != nil {
@@ -731,56 +720,21 @@ func (me *GaapService) ModifyProxyConfiguration(ctx context.Context, id string,
731
720
ratelimit .Check (modifyRequest .GetAction ())
732
721
modifyRequest .ClientToken = helper .String (helper .BuildToken ())
733
722
734
- if _ , err := client .ModifyProxyConfiguration (modifyRequest ); err != nil {
723
+ response , err := client .ModifyProxyConfiguration (modifyRequest )
724
+ if err != nil {
735
725
log .Printf ("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]" ,
736
726
logId , modifyRequest .GetAction (), modifyRequest .ToJsonString (), err )
737
727
return tccommon .RetryError (err )
738
728
}
729
+ modifyProxyRequestId = * response .Response .RequestId
739
730
return nil
740
731
}); err != nil {
741
732
log .Printf ("[CRITAL]%s modify proxy configuration failed, reason: %v" , logId , err )
742
733
return err
743
734
}
744
735
745
- time .Sleep (5 * time .Second )
746
-
747
- describeRequest := gaap .NewDescribeProxiesRequest ()
748
- describeRequest .ProxyIds = []* string {& id }
749
-
750
- if err := resource .Retry (3 * tccommon .ReadRetryTimeout , func () * resource.RetryError {
751
- ratelimit .Check (describeRequest .GetAction ())
752
-
753
- response , err := client .DescribeProxies (describeRequest )
754
- if err != nil {
755
- log .Printf ("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]" ,
756
- logId , describeRequest .GetAction (), describeRequest .ToJsonString (), err )
757
- return tccommon .RetryError (err )
758
- }
759
-
760
- proxies := response .Response .ProxySet
761
-
762
- if len (proxies ) != 1 {
763
- err := fmt .Errorf ("api[%s] read %d proxies" , describeRequest .GetAction (), len (proxies ))
764
- log .Printf ("[CRITAL]%s %v" , logId , err )
765
- return resource .NonRetryableError (err )
766
- }
767
-
768
- proxy := proxies [0 ]
769
- if proxy .Status == nil {
770
- err := fmt .Errorf ("api[%s] proxy status is nil" , describeRequest .GetAction ())
771
- log .Printf ("[CRITAL]%s %v" , logId , err )
772
- return resource .NonRetryableError (err )
773
- }
774
-
775
- if * proxy .Status == GAAP_PROXY_ADJUSTING {
776
- err := errors .New ("proxy is still modifying" )
777
- log .Printf ("[DEBUG]%s %v" , logId , err )
778
- return resource .RetryableError (err )
779
- }
780
-
781
- return nil
782
- }); err != nil {
783
- log .Printf ("[CRITAL]%s modify proxy configuration failed, reason: %v" , logId , err )
736
+ time .Sleep (3 * time .Second )
737
+ if err := waitTaskReady (ctx , client , modifyProxyRequestId ); err != nil {
784
738
return err
785
739
}
786
740
0 commit comments