From 967fa5465abb5e15c013a9aca6c18ad4b706261e Mon Sep 17 00:00:00 2001 From: "Cuong. Duong Manh" Date: Fri, 25 Oct 2024 15:31:25 +0700 Subject: [PATCH] [feat] api resize loadbalancer --- test/lb_test.go | 2 +- vngcloud/sdk_error/error_codes.go | 1 + vngcloud/sdk_error/loadbalancer.go | 16 ++++++++++++++++ .../services/loadbalancer/v2/loadbalancer.go | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/test/lb_test.go b/test/lb_test.go index f583bbb..47c764d 100644 --- a/test/lb_test.go +++ b/test/lb_test.go @@ -567,7 +567,7 @@ func TestGetListenerByIdSuccess(t *ltesting.T) { func TestResizeLoadBalancer(t *ltesting.T) { vngcloud := validSdkConfig() - opt := lslbv2.NewResizeLoadBalancerByIdRequest("lb-8d11bcf3-d763-4716-adbc-74ba53fdf77f", "lbp-96b6b072-aadb-4b58-9d5f-c16ad69d36aa") + opt := lslbv2.NewResizeLoadBalancerByIdRequest("lb-ab3c3e19-16ea-40b9-bd83-ad700a690153", "lbp-96b6b073-aadb-4b58-9d5f-c16ad69d36aa") sdkerr := vngcloud.VLBGateway().V2().LoadBalancerService().ResizeLoadBalancerById(opt) if sdkerr != nil { t.Fatalf("Expect nil but got %+v", sdkerr) diff --git a/vngcloud/sdk_error/error_codes.go b/vngcloud/sdk_error/error_codes.go index 01ba955..d6eac61 100644 --- a/vngcloud/sdk_error/error_codes.go +++ b/vngcloud/sdk_error/error_codes.go @@ -133,6 +133,7 @@ const ( EcVLBLoadBalancerIsDeleting = ErrorCode("VngCloudVLBLoadBalancerIsDeleting") EcVLBLoadBalancerIsCreating = ErrorCode("VngCloudVLBLoadBalancerIsCreating") EcVLBLoadBalancerResizeSamePackage = ErrorCode("VngCloudVLBLoadBalancerResizeSamePackage") + EcVLBLoadBalancerPackageNotFound = ErrorCode("VngCloudVLBLoadBalancerPackageNotFound") ) // Endpoint diff --git a/vngcloud/sdk_error/loadbalancer.go b/vngcloud/sdk_error/loadbalancer.go index 5e1085c..4ac2de2 100644 --- a/vngcloud/sdk_error/loadbalancer.go +++ b/vngcloud/sdk_error/loadbalancer.go @@ -23,6 +23,7 @@ const ( patternLoadBalancerIsDeleting = `load balancer id [^.]+ is deleting` patternLoadBalancerIsCreating = `load balancer id [^.]+ is creating` patternLoadBalancerResizeSamePackage = "is the same as the current package" + patternLoadbalancerPackageNotFound = "invalid package id" ) var ( @@ -247,3 +248,18 @@ func WithErrorLoadBalancerResizeSamePackage(perrResp IErrorRespone) func(sdkErro } } } + +func WithErrorLoadBalancerPackageNotFound(perrResp IErrorRespone) func(sdkError IError) { + return func(sdkError IError) { + if perrResp == nil { + return + } + + errMsg := perrResp.GetMessage() + if lstr.Contains(lstr.ToLower(lstr.TrimSpace(errMsg)), patternLoadbalancerPackageNotFound) { + sdkError.WithErrorCode(EcVLBLoadBalancerPackageNotFound). + WithMessage(errMsg). + WithErrors(perrResp.GetError()) + } + } +} diff --git a/vngcloud/services/loadbalancer/v2/loadbalancer.go b/vngcloud/services/loadbalancer/v2/loadbalancer.go index 8dc89d7..cffc125 100644 --- a/vngcloud/services/loadbalancer/v2/loadbalancer.go +++ b/vngcloud/services/loadbalancer/v2/loadbalancer.go @@ -351,6 +351,7 @@ func (s *LoadBalancerServiceV2) ResizeLoadBalancerById(popts IResizeLoadBalancer if _, sdkErr := s.VLBClient.Put(url, req); sdkErr != nil { return lserr.SdkErrorHandler(sdkErr, errResp, + lserr.WithErrorLoadBalancerPackageNotFound(errResp), lserr.WithErrorLoadBalancerNotFound(errResp), lserr.WithErrorLoadBalancerNotFound2(errResp), lserr.WithErrorLoadBalancerNotReady(errResp),