loadbalancer_acl_syncstatus_task.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. package loadbalancer
  15. import (
  16. "context"
  17. "yunion.io/x/cloudmux/pkg/apis"
  18. "yunion.io/x/jsonutils"
  19. "yunion.io/x/pkg/errors"
  20. "yunion.io/x/onecloud/pkg/cloudcommon/db"
  21. "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
  22. "yunion.io/x/onecloud/pkg/compute/models"
  23. )
  24. type LoadbalancerAclSyncstatusTask struct {
  25. taskman.STask
  26. }
  27. func init() {
  28. taskman.RegisterTask(LoadbalancerAclSyncstatusTask{})
  29. }
  30. func (self *LoadbalancerAclSyncstatusTask) taskFail(ctx context.Context, lbacl *models.SLoadbalancerAcl, err error) {
  31. lbacl.SetStatus(ctx, self.GetUserCred(), apis.STATUS_UNKNOWN, err.Error())
  32. self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
  33. }
  34. func (self *LoadbalancerAclSyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
  35. lbacl := obj.(*models.SLoadbalancerAcl)
  36. region, err := lbacl.GetRegion()
  37. if err != nil {
  38. self.taskFail(ctx, lbacl, errors.Wrapf(err, "GetRegion"))
  39. return
  40. }
  41. self.SetStage("OnLoadbalancerAclSyncstatusComplete", nil)
  42. err = region.GetDriver().RequestLoadbalancerAclSyncstatus(ctx, self.GetUserCred(), lbacl, self)
  43. if err != nil {
  44. self.taskFail(ctx, lbacl, errors.Wrapf(err, "RequestLoadbalancerAclSyncstatus"))
  45. }
  46. }
  47. func (self *LoadbalancerAclSyncstatusTask) OnLoadbalancerAclSyncstatusComplete(ctx context.Context, lbacl *models.SLoadbalancerAcl, data jsonutils.JSONObject) {
  48. self.SetStageComplete(ctx, nil)
  49. }
  50. func (self *LoadbalancerAclSyncstatusTask) OnLoadbalancerAclSyncstatusCompleteFailed(ctx context.Context, lbacl *models.SLoadbalancerAcl, reason jsonutils.JSONObject) {
  51. self.taskFail(ctx, lbacl, errors.Errorf("%s", reason.String()))
  52. }