Skip to content

Commit 3973f3e

Browse files
committed
fix(qcloud): lb listener rule create
1 parent fb231d4 commit 3973f3e

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

pkg/multicloud/qcloud/loadbalancer_listener.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"yunion.io/x/jsonutils"
2525
"yunion.io/x/pkg/errors"
26+
"yunion.io/x/pkg/utils"
2627

2728
api "yunion.io/x/cloudmux/pkg/apis/compute"
2829
"yunion.io/x/cloudmux/pkg/cloudprovider"
@@ -95,7 +96,7 @@ func (self *SLBListener) GetBackendServerPort() int {
9596
// https://cloud.tencent.com/document/product/214/30691
9697
func (self *SLBListener) CreateILoadBalancerListenerRule(rule *cloudprovider.SLoadbalancerListenerRule) (cloudprovider.ICloudLoadbalancerListenerRule, error) {
9798
hc := getListenerRuleHealthCheck(rule)
98-
requestId, err := self.lb.region.CreateLoadbalancerListenerRule(self.lb.GetId(),
99+
resp, err := self.lb.region.CreateLoadbalancerListenerRule(self.lb.GetId(),
99100
self.GetId(),
100101
rule.Domain,
101102
rule.Path,
@@ -106,7 +107,7 @@ func (self *SLBListener) CreateILoadBalancerListenerRule(rule *cloudprovider.SLo
106107
return nil, err
107108
}
108109

109-
err = self.lb.region.WaitLBTaskSuccess(requestId, 5*time.Second, 60*time.Second)
110+
err = self.lb.region.WaitLBTaskSuccess(resp.RequestId, 5*time.Second, 60*time.Second)
110111
if err != nil {
111112
return nil, err
112113
}
@@ -116,14 +117,13 @@ func (self *SLBListener) CreateILoadBalancerListenerRule(rule *cloudprovider.SLo
116117
return nil, err
117118
}
118119

119-
for _, r := range self.Rules {
120-
if r.GetPath() == rule.Path {
121-
r.listener = self
120+
for i := range self.Rules {
121+
r := self.Rules[i]
122+
if utils.IsInStringArray(r.LocationId, resp.LocationIds) {
122123
return &r, nil
123124
}
124125
}
125-
126-
return nil, cloudprovider.ErrNotFound
126+
return nil, errors.Wrapf(cloudprovider.ErrNotFound, jsonutils.Marshal(resp).String())
127127
}
128128

129129
func (self *SLBListener) GetILoadBalancerListenerRuleById(ruleId string) (cloudprovider.ICloudLoadbalancerListenerRule, error) {
@@ -452,12 +452,13 @@ func (self *SRegion) GetLoadbalancerListeners(lbId string, lblisIds []string, pr
452452
return listeners, nil
453453
}
454454

455-
// 返回requestId
456-
func (self *SRegion) CreateLoadbalancerListenerRule(lbid string, listenerId string, domain string, url string, scheduler string, sessionExpireTime int, hc *HealthCheck) (string, error) {
457-
if len(lbid) == 0 {
458-
return "", fmt.Errorf("loadbalancer id should not be empty")
459-
}
455+
type ListenerRuleResponse struct {
456+
RequestId string
457+
LocationIds []string
458+
}
460459

460+
// 返回requestId
461+
func (self *SRegion) CreateLoadbalancerListenerRule(lbid string, listenerId string, domain string, url string, scheduler string, sessionExpireTime int, hc *HealthCheck) (*ListenerRuleResponse, error) {
461462
params := map[string]string{
462463
"LoadBalancerId": lbid,
463464
"ListenerId": listenerId,
@@ -482,10 +483,14 @@ func (self *SRegion) CreateLoadbalancerListenerRule(lbid string, listenerId stri
482483

483484
resp, err := self.clbRequest("CreateRule", params)
484485
if err != nil {
485-
return "", err
486+
return nil, err
486487
}
487-
488-
return resp.GetString("RequestId")
488+
ret := &ListenerRuleResponse{}
489+
err = resp.Unmarshal(ret)
490+
if err != nil {
491+
return nil, err
492+
}
493+
return ret, nil
489494
}
490495

491496
// 返回requestId

pkg/multicloud/qcloud/loadbalancer_listenerrule.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type SLBListenerRule struct {
3636
Certificate Certificate `json:"Certificate"`
3737
URL string `json:"Url"`
3838
HealthCheck HealthCheck `json:"HealthCheck"`
39-
LocationID string `json:"LocationId"`
39+
LocationId string `json:"LocationId"`
4040
Scheduler string `json:"Scheduler"`
4141
SessionExpireTime int64 `json:"SessionExpireTime"`
4242
}
@@ -52,15 +52,15 @@ func (self *SLBListenerRule) Delete(ctx context.Context) error {
5252
}
5353

5454
func (self *SLBListenerRule) GetId() string {
55-
return self.LocationID
55+
return self.LocationId
5656
}
5757

5858
func (self *SLBListenerRule) GetName() string {
59-
return self.LocationID
59+
return self.LocationId
6060
}
6161

6262
func (self *SLBListenerRule) GetGlobalId() string {
63-
return self.LocationID
63+
return self.LocationId
6464
}
6565

6666
func (self *SLBListenerRule) GetStatus() string {

0 commit comments

Comments
 (0)