Skip to content

Commit

Permalink
🌱 add: get glb by id
Browse files Browse the repository at this point in the history
  • Loading branch information
anngdinh committed Dec 26, 2024
1 parent 6831108 commit bdb18ad
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 1 deletion.
22 changes: 22 additions & 0 deletions test/lb_global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,25 @@ func TestDeleteGlobalLoadBalancerSuccess(t *ltesting.T) {

t.Log("PASS")
}

func TestGetGlobalLoadBalancerSuccess(t *ltesting.T) {
vngcloud := validSdkConfig()
opt := global.NewGetGlobalLoadBalancerByIdRequest("glb-d81be06b-5109-46ad-97d9-e97fe1aa7933")
lb, sdkerr := vngcloud.VLBGateway().Global().LoadBalancerService().GetGlobalLoadBalancerById(opt)
if sdkerr != nil {
t.Fatalf("Expect nil but got %+v", sdkerr)
}

if lb == nil {
t.Fatalf("Expect not nil but got nil")
}

t.Logf("Result: %+v", lb)
for _, vip := range lb.Vips {
t.Logf(" - VIP: %+v", vip)
}
for _, domain := range lb.Domains {
t.Logf(" - Domain: %+v", domain)
}
t.Log("PASS")
}
20 changes: 20 additions & 0 deletions vngcloud/services/loadbalancer/global/glb.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,23 @@ func (s *LoadBalancerServiceGlobal) DeleteGlobalLoadBalancer(popts IDeleteGlobal

return nil
}

// --------------------------------------------------

func (s *LoadBalancerServiceGlobal) GetGlobalLoadBalancerById(popts IGetGlobalLoadBalancerByIdRequest) (*lsentity.GlobalLoadBalancer, lserr.IError) {
url := getGlobalLoadBalancerByIdUrl(s.VLBClient, popts)
resp := new(GetGlobalLoadBalancerByIdResponse)
errResp := lserr.NewErrorResponse(lserr.NormalErrorType)
req := lsclient.NewRequest().
WithHeader("User-Agent", popts.ParseUserAgent()).
WithOkCodes(200).
WithJsonResponse(resp).
WithJsonError(errResp)

if _, sdkErr := s.VLBClient.Get(url, req); sdkErr != nil {
return nil, lserr.SdkErrorHandler(sdkErr, errResp).
AppendCategories(lserr.ErrCatProductVlb)
}

return resp.ToEntityGlobalLoadBalancer(), nil
}
23 changes: 23 additions & 0 deletions vngcloud/services/loadbalancer/global/glb_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,26 @@ func NewDeleteGlobalLoadBalancerRequest(lbId string) IDeleteGlobalLoadBalancerRe
}
return opts
}

// --------------------------------------------------------------------------

var _ IGetGlobalLoadBalancerByIdRequest = &GetGlobalLoadBalancerByIdRequest{}

type GetGlobalLoadBalancerByIdRequest struct {
lscommon.UserAgent
lscommon.LoadBalancerCommon
}

func (s *GetGlobalLoadBalancerByIdRequest) WithLoadBalancerId(plbId string) IGetGlobalLoadBalancerByIdRequest {
s.LoadBalancerId = plbId
return s
}

func NewGetGlobalLoadBalancerByIdRequest(lbId string) IGetGlobalLoadBalancerByIdRequest {
opts := &GetGlobalLoadBalancerByIdRequest{
LoadBalancerCommon: lscommon.LoadBalancerCommon{
LoadBalancerId: lbId,
},
}
return opts
}
8 changes: 8 additions & 0 deletions vngcloud/services/loadbalancer/global/glb_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,11 @@ type CreateGlobalLoadBalancerResponse struct {
func (s *CreateGlobalLoadBalancerResponse) ToEntityGlobalLoadBalancer() *lsentity.GlobalLoadBalancer {
return s.GlobalLoadBalancer.ToEntityGlobalLoadBalancer()
}

// --------------------------------------------------

type GetGlobalLoadBalancerByIdResponse GlobalLoadBalancerResponse

func (s *GetGlobalLoadBalancerByIdResponse) ToEntityGlobalLoadBalancer() *lsentity.GlobalLoadBalancer {
return (*GlobalLoadBalancerResponse)(s).ToEntityGlobalLoadBalancer()
}
9 changes: 9 additions & 0 deletions vngcloud/services/loadbalancer/global/irequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,12 @@ type IDeleteGlobalLoadBalancerRequest interface {

ParseUserAgent() string
}

// --------------------------------------------------------

type IGetGlobalLoadBalancerByIdRequest interface {
WithLoadBalancerId(plbId string) IGetGlobalLoadBalancerByIdRequest
GetLoadBalancerId() string // to use in request url

ParseUserAgent() string
}
7 changes: 7 additions & 0 deletions vngcloud/services/loadbalancer/global/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,10 @@ func deleteGlobalLoadBalancerUrl(psc lsclient.IServiceClient, popts IDeleteGloba
popts.GetLoadBalancerId(),
)
}

func getGlobalLoadBalancerByIdUrl(psc lsclient.IServiceClient, popts IGetGlobalLoadBalancerByIdRequest) string {
return psc.ServiceURL(
"global-load-balancers",
popts.GetLoadBalancerId(),
)
}
2 changes: 1 addition & 1 deletion vngcloud/services/loadbalancer/iloadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ type ILoadBalancerServiceGlobal interface {
ListGlobalLoadBalancers(popts global.IListGlobalLoadBalancersRequest) (*lsentity.ListGlobalLoadBalancers, lserr.IError)
CreateGlobalLoadBalancer(popts global.ICreateGlobalLoadBalancerRequest) (*lsentity.GlobalLoadBalancer, lserr.IError)
DeleteGlobalLoadBalancer(popts global.IDeleteGlobalLoadBalancerRequest) lserr.IError
GetGlobalLoadBalancerById(popts global.IGetGlobalLoadBalancerByIdRequest) (*lsentity.GlobalLoadBalancer, lserr.IError)

// GetGlobalLoadBalancerPoolById(popts global.IGetGlobalLoadBalancerPoolByIdRequest) (*lsentity.GlobalLoadBalancerPool, lserr.IError)
// GetGlobalLoadBalancerPoolMemberById(popts global.IGetGlobalLoadBalancerPoolMemberByIdRequest) (*lsentity.GlobalLoadBalancerPoolMember, lserr.IError)
// UpdateGlobalLoadBalancerPoolMember(popts global.IUpdateGlobalLoadBalancerPoolMemberRequest) lserr.IError
// DeleteGlobalLoadBalancerPoolMemberById(popts global.IDeleteGlobalLoadBalancerPoolMemberByIdRequest) lserr.IError
// UpdateGlobalLoadBalancer(popts global.IUpdateGlobalLoadBalancerRequest) lserr.IError
// GetGlobalLoadBalancerById(popts global.IGetGlobalLoadBalancerByIdRequest) (*lsentity.GlobalLoadBalancer, lserr.IError)
// ListGlobalLoadBalancerHealthMonitors(popts global.IListGlobalLoadBalancerHealthMonitorsRequest) (*lsentity.ListGlobalLoadBalancerHealthMonitors, lserr.IError)
// GetGlobalLoadBalancerHealthMonitorById(popts global.IGetGlobalLoadBalancerHealthMonitorByIdRequest) (*lsentity.GlobalLoadBalancerHealthMonitor, lserr.IError)
// CreateGlobalLoadBalancerHealthMonitor(popts global.ICreateGlobalLoadBalancerHealthMonitorRequest) (*lsentity.GlobalLoadBalancerHealthMonitor, lserr.IError)
Expand Down

0 comments on commit bdb18ad

Please sign in to comment.