Skip to content

Commit 4e2c7bf

Browse files
authored
fix(region): support lb health check sync status (#23028)
1 parent 78db6c2 commit 4e2c7bf

File tree

5 files changed

+92
-1
lines changed

5 files changed

+92
-1
lines changed

cmd/climc/shell/compute/loadbalancer_health_check.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ func init() {
2727
cmd.Create(&options.LoadbalancerHealthCheckCreateOptions{})
2828
cmd.Delete(&options.LoadbalancerHealthCheckIdOptions{})
2929
cmd.Update(&options.LoadbalancerHealthCheckUpdateOptions{})
30+
cmd.Perform("syncstatus", &options.LoadbalancerHealthCheckIdOptions{})
3031
}

pkg/apis/compute/loadbalancerbackendgroup.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ type LoadbalancerBackendGroupDetails struct {
2929

3030
SLoadbalancerBackendGroup
3131

32+
LoadbalancerHealthCheck string `json:"loadbalancer_health_check"`
33+
3234
LbListenerCount int `json:"lb_listener_count"`
3335

3436
IsDefault bool `json:"is_default"`

pkg/compute/models/loadbalancer_health_checks.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (hc *SLoadbalancerHealthCheck) ValidateUpdateData(
175175
if err != nil {
176176
return nil, errors.Wrap(err, "SVirtualResourceBase.ValidateUpdateData")
177177
}
178-
return nil, cloudprovider.ErrNotImplemented
178+
return input, nil
179179
}
180180

181181
func (hc *SLoadbalancerHealthCheck) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) {
@@ -417,6 +417,10 @@ func (hc *SLoadbalancerHealthCheck) syncRemove(ctx context.Context, userCred mcc
417417
return hc.RealDelete(ctx, userCred)
418418
}
419419

420+
func (hc *SLoadbalancerHealthCheck) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
421+
return nil, StartResourceSyncStatusTask(ctx, userCred, hc, "LoadbalancerHealthCheckSyncstatusTask", "")
422+
}
423+
420424
func (manager *SLoadbalancerHealthCheckManager) ListItemExportKeys(ctx context.Context,
421425
q *sqlchemy.SQuery,
422426
userCred mcclient.TokenCredential,

pkg/compute/models/loadbalancerbackendgroups.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ func (man *SLoadbalancerBackendGroupManager) FetchCustomizeColumns(
450450

451451
lbIds := make([]string, len(objs))
452452
lbbgIds := make([]string, len(objs))
453+
hcIds := make([]string, len(objs))
453454
for i := range rows {
454455
rows[i] = api.LoadbalancerBackendGroupDetails{
455456
StatusStandaloneResourceDetails: stdRows[i],
@@ -458,6 +459,7 @@ func (man *SLoadbalancerBackendGroupManager) FetchCustomizeColumns(
458459
lbbg := objs[i].(*SLoadbalancerBackendGroup)
459460
lbIds[i] = lbbg.LoadbalancerId
460461
lbbgIds[i] = lbbg.Id
462+
hcIds[i] = lbbg.LoadbalancerHealthCheckId
461463
}
462464

463465
lbs := map[string]SLoadbalancer{}
@@ -477,8 +479,17 @@ func (man *SLoadbalancerBackendGroupManager) FetchCustomizeColumns(
477479
}
478480
}
479481
}
482+
483+
hcMap, err := db.FetchIdNameMap2(LoadbalancerHealthCheckManager, hcIds)
484+
if err != nil {
485+
return rows
486+
}
487+
480488
for i := range rows {
481489
rows[i].IsDefault = utils.IsInStringArray(lbbgIds[i], defaultLbgIds)
490+
if hcId, ok := hcMap[hcIds[i]]; ok {
491+
rows[i].LoadbalancerHealthCheck = hcId
492+
}
482493
}
483494

484495
for i := range objs {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2019 Yunion
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package loadbalancer
16+
17+
import (
18+
"context"
19+
20+
"yunion.io/x/cloudmux/pkg/apis"
21+
"yunion.io/x/cloudmux/pkg/cloudprovider"
22+
"yunion.io/x/jsonutils"
23+
"yunion.io/x/pkg/errors"
24+
25+
"yunion.io/x/onecloud/pkg/cloudcommon/db"
26+
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
27+
"yunion.io/x/onecloud/pkg/compute/models"
28+
)
29+
30+
type LoadbalancerHealthCheckSyncstatusTask struct {
31+
taskman.STask
32+
}
33+
34+
func init() {
35+
taskman.RegisterTask(LoadbalancerHealthCheckSyncstatusTask{})
36+
}
37+
38+
func (self *LoadbalancerHealthCheckSyncstatusTask) taskFail(ctx context.Context, hc *models.SLoadbalancerHealthCheck, err error) {
39+
hc.SetStatus(ctx, self.GetUserCred(), apis.STATUS_UNKNOWN, err.Error())
40+
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
41+
}
42+
43+
func (self *LoadbalancerHealthCheckSyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
44+
hc := obj.(*models.SLoadbalancerHealthCheck)
45+
iRegion, err := hc.GetIRegion(ctx)
46+
if err != nil {
47+
self.taskFail(ctx, hc, errors.Wrapf(err, "GetIRegion"))
48+
return
49+
}
50+
hcs, err := iRegion.GetILoadBalancerHealthChecks()
51+
if err != nil {
52+
self.taskFail(ctx, hc, errors.Wrapf(err, "GetLoadbalancerHealthChecks"))
53+
return
54+
}
55+
for i := range hcs {
56+
if hcs[i].GetGlobalId() == hc.ExternalId {
57+
err := hc.SyncWithCloudLoadbalancerHealthCheck(ctx, self.GetUserCred(), hcs[i], hc.GetCloudprovider())
58+
if err != nil {
59+
self.taskFail(ctx, hc, errors.Wrapf(err, "SyncWithCloudLoadbalancerHealthCheck"))
60+
return
61+
}
62+
self.taskComplete(ctx, hc)
63+
return
64+
}
65+
}
66+
67+
self.taskFail(ctx, hc, errors.Wrapf(cloudprovider.ErrNotFound, "LoadbalancerHealthCheck not found"))
68+
}
69+
70+
func (self *LoadbalancerHealthCheckSyncstatusTask) taskComplete(ctx context.Context, hc *models.SLoadbalancerHealthCheck) {
71+
hc.SetStatus(ctx, self.GetUserCred(), apis.STATUS_AVAILABLE, "")
72+
self.SetStageComplete(ctx, nil)
73+
}

0 commit comments

Comments
 (0)