Skip to content

Commit

Permalink
[feat] api resize loadbalancer
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Oct 25, 2024
1 parent b4c1b48 commit 967fa54
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/lb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions vngcloud/sdk_error/error_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ const (
EcVLBLoadBalancerIsDeleting = ErrorCode("VngCloudVLBLoadBalancerIsDeleting")
EcVLBLoadBalancerIsCreating = ErrorCode("VngCloudVLBLoadBalancerIsCreating")
EcVLBLoadBalancerResizeSamePackage = ErrorCode("VngCloudVLBLoadBalancerResizeSamePackage")
EcVLBLoadBalancerPackageNotFound = ErrorCode("VngCloudVLBLoadBalancerPackageNotFound")
)

// Endpoint
Expand Down
16 changes: 16 additions & 0 deletions vngcloud/sdk_error/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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())
}
}
}
1 change: 1 addition & 0 deletions vngcloud/services/loadbalancer/v2/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 967fa54

Please sign in to comment.