mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 06:09:39 +08:00
fix(region): support lb health check sync status (#23028)
This commit is contained in:
@@ -27,4 +27,5 @@ func init() {
|
|||||||
cmd.Create(&options.LoadbalancerHealthCheckCreateOptions{})
|
cmd.Create(&options.LoadbalancerHealthCheckCreateOptions{})
|
||||||
cmd.Delete(&options.LoadbalancerHealthCheckIdOptions{})
|
cmd.Delete(&options.LoadbalancerHealthCheckIdOptions{})
|
||||||
cmd.Update(&options.LoadbalancerHealthCheckUpdateOptions{})
|
cmd.Update(&options.LoadbalancerHealthCheckUpdateOptions{})
|
||||||
|
cmd.Perform("syncstatus", &options.LoadbalancerHealthCheckIdOptions{})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ type LoadbalancerBackendGroupDetails struct {
|
|||||||
|
|
||||||
SLoadbalancerBackendGroup
|
SLoadbalancerBackendGroup
|
||||||
|
|
||||||
|
LoadbalancerHealthCheck string `json:"loadbalancer_health_check"`
|
||||||
|
|
||||||
LbListenerCount int `json:"lb_listener_count"`
|
LbListenerCount int `json:"lb_listener_count"`
|
||||||
|
|
||||||
IsDefault bool `json:"is_default"`
|
IsDefault bool `json:"is_default"`
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ func (hc *SLoadbalancerHealthCheck) ValidateUpdateData(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "SVirtualResourceBase.ValidateUpdateData")
|
return nil, errors.Wrap(err, "SVirtualResourceBase.ValidateUpdateData")
|
||||||
}
|
}
|
||||||
return nil, cloudprovider.ErrNotImplemented
|
return input, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hc *SLoadbalancerHealthCheck) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
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
|
|||||||
return hc.RealDelete(ctx, userCred)
|
return hc.RealDelete(ctx, userCred)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (hc *SLoadbalancerHealthCheck) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||||
|
return nil, StartResourceSyncStatusTask(ctx, userCred, hc, "LoadbalancerHealthCheckSyncstatusTask", "")
|
||||||
|
}
|
||||||
|
|
||||||
func (manager *SLoadbalancerHealthCheckManager) ListItemExportKeys(ctx context.Context,
|
func (manager *SLoadbalancerHealthCheckManager) ListItemExportKeys(ctx context.Context,
|
||||||
q *sqlchemy.SQuery,
|
q *sqlchemy.SQuery,
|
||||||
userCred mcclient.TokenCredential,
|
userCred mcclient.TokenCredential,
|
||||||
|
|||||||
@@ -450,6 +450,7 @@ func (man *SLoadbalancerBackendGroupManager) FetchCustomizeColumns(
|
|||||||
|
|
||||||
lbIds := make([]string, len(objs))
|
lbIds := make([]string, len(objs))
|
||||||
lbbgIds := make([]string, len(objs))
|
lbbgIds := make([]string, len(objs))
|
||||||
|
hcIds := make([]string, len(objs))
|
||||||
for i := range rows {
|
for i := range rows {
|
||||||
rows[i] = api.LoadbalancerBackendGroupDetails{
|
rows[i] = api.LoadbalancerBackendGroupDetails{
|
||||||
StatusStandaloneResourceDetails: stdRows[i],
|
StatusStandaloneResourceDetails: stdRows[i],
|
||||||
@@ -458,6 +459,7 @@ func (man *SLoadbalancerBackendGroupManager) FetchCustomizeColumns(
|
|||||||
lbbg := objs[i].(*SLoadbalancerBackendGroup)
|
lbbg := objs[i].(*SLoadbalancerBackendGroup)
|
||||||
lbIds[i] = lbbg.LoadbalancerId
|
lbIds[i] = lbbg.LoadbalancerId
|
||||||
lbbgIds[i] = lbbg.Id
|
lbbgIds[i] = lbbg.Id
|
||||||
|
hcIds[i] = lbbg.LoadbalancerHealthCheckId
|
||||||
}
|
}
|
||||||
|
|
||||||
lbs := map[string]SLoadbalancer{}
|
lbs := map[string]SLoadbalancer{}
|
||||||
@@ -477,8 +479,17 @@ func (man *SLoadbalancerBackendGroupManager) FetchCustomizeColumns(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hcMap, err := db.FetchIdNameMap2(LoadbalancerHealthCheckManager, hcIds)
|
||||||
|
if err != nil {
|
||||||
|
return rows
|
||||||
|
}
|
||||||
|
|
||||||
for i := range rows {
|
for i := range rows {
|
||||||
rows[i].IsDefault = utils.IsInStringArray(lbbgIds[i], defaultLbgIds)
|
rows[i].IsDefault = utils.IsInStringArray(lbbgIds[i], defaultLbgIds)
|
||||||
|
if hcId, ok := hcMap[hcIds[i]]; ok {
|
||||||
|
rows[i].LoadbalancerHealthCheck = hcId
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range objs {
|
for i := range objs {
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
// Copyright 2019 Yunion
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package loadbalancer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"yunion.io/x/cloudmux/pkg/apis"
|
||||||
|
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||||
|
"yunion.io/x/jsonutils"
|
||||||
|
"yunion.io/x/pkg/errors"
|
||||||
|
|
||||||
|
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||||
|
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||||
|
"yunion.io/x/onecloud/pkg/compute/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LoadbalancerHealthCheckSyncstatusTask struct {
|
||||||
|
taskman.STask
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
taskman.RegisterTask(LoadbalancerHealthCheckSyncstatusTask{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *LoadbalancerHealthCheckSyncstatusTask) taskFail(ctx context.Context, hc *models.SLoadbalancerHealthCheck, err error) {
|
||||||
|
hc.SetStatus(ctx, self.GetUserCred(), apis.STATUS_UNKNOWN, err.Error())
|
||||||
|
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *LoadbalancerHealthCheckSyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||||
|
hc := obj.(*models.SLoadbalancerHealthCheck)
|
||||||
|
iRegion, err := hc.GetIRegion(ctx)
|
||||||
|
if err != nil {
|
||||||
|
self.taskFail(ctx, hc, errors.Wrapf(err, "GetIRegion"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
hcs, err := iRegion.GetILoadBalancerHealthChecks()
|
||||||
|
if err != nil {
|
||||||
|
self.taskFail(ctx, hc, errors.Wrapf(err, "GetLoadbalancerHealthChecks"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for i := range hcs {
|
||||||
|
if hcs[i].GetGlobalId() == hc.ExternalId {
|
||||||
|
err := hc.SyncWithCloudLoadbalancerHealthCheck(ctx, self.GetUserCred(), hcs[i], hc.GetCloudprovider())
|
||||||
|
if err != nil {
|
||||||
|
self.taskFail(ctx, hc, errors.Wrapf(err, "SyncWithCloudLoadbalancerHealthCheck"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
self.taskComplete(ctx, hc)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.taskFail(ctx, hc, errors.Wrapf(cloudprovider.ErrNotFound, "LoadbalancerHealthCheck not found"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *LoadbalancerHealthCheckSyncstatusTask) taskComplete(ctx context.Context, hc *models.SLoadbalancerHealthCheck) {
|
||||||
|
hc.SetStatus(ctx, self.GetUserCred(), apis.STATUS_AVAILABLE, "")
|
||||||
|
self.SetStageComplete(ctx, nil)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user