From 1896651d697ccc59143a6e2cb0cb730f268f78e1 Mon Sep 17 00:00:00 2001 From: tangbin Date: Sat, 9 Nov 2019 16:41:45 +0800 Subject: [PATCH 1/2] redis sync fix --- cmd/climc/shell/notification.go | 1 - pkg/apis/compute/elasticcache_const.go | 8 +++ pkg/cloudcommon/db/opslog.go | 5 ++ pkg/compute/models/elasticcache_accounts.go | 3 +- pkg/compute/models/elasticcache_backups.go | 15 ++++-- pkg/compute/models/elasticcache_instances.go | 49 ++++++++++++++----- pkg/compute/models/regiondrivers.go | 2 + pkg/compute/models/skus_tools.go | 16 +++--- pkg/compute/regiondrivers/aliyun.go | 2 +- pkg/compute/regiondrivers/huawei.go | 18 ++++++- pkg/compute/regiondrivers/kvm.go | 8 +++ pkg/compute/regiondrivers/managedvirtual.go | 14 ++++++ .../tasks/elasticcache_account_create_task.go | 1 + .../tasks/elasticcache_account_delete_task.go | 6 ++- ...lasticcache_account_reset_password_task.go | 29 +++++++---- .../tasks/elasticcache_acl_create_task.go | 1 + .../tasks/elasticcache_acl_delete_task.go | 1 + .../tasks/elasticcache_acl_update_task.go | 1 + ...iccache_allocate_public_connection_task.go | 1 + .../tasks/elasticcache_backup_create_task.go | 9 ++-- ...asticcache_backup_restore_instance_task.go | 1 + .../tasks/elasticcache_change_spec_task.go | 1 + pkg/compute/tasks/elasticcache_create_task.go | 2 + pkg/compute/tasks/elasticcache_delete_task.go | 1 + .../tasks/elasticcache_flush_instance.go | 9 ++-- .../elasticcache_parameter_update_task.go | 7 +-- .../tasks/elasticcache_restart_task.go | 1 + .../elasticcache_set_maintain_time_task.go | 7 +-- pkg/compute/tasks/elasticcache_sync_task.go | 1 + .../elasticcache_update_auth_mode_task.go | 5 +- .../elasticcache_update_backup_policy_task.go | 5 +- .../aliyun/elasticcache_instance.go | 8 +-- .../huawei/client/modules/manager_base.go | 3 +- pkg/multicloud/huawei/elasticcache_account.go | 21 +------- .../huawei/elasticcache_instance.go | 29 +++++++---- pkg/util/logclient/consts.go | 2 + 36 files changed, 199 insertions(+), 94 deletions(-) diff --git a/cmd/climc/shell/notification.go b/cmd/climc/shell/notification.go index 4803a25892..a3d0320809 100644 --- a/cmd/climc/shell/notification.go +++ b/cmd/climc/shell/notification.go @@ -61,7 +61,6 @@ func init() { * 发送全局通知 */ type NotificationBroadcastOptions struct { - // CONTACTTYPE string `help:"User's contacts type, cloud be email|mobile|dingtalk|/webconsole" choices:"email|mobile|dingtalk|webconsole"` Topic string `required:"true" help:"Title or topic of the notification"` Priority string `help:"Priority of the notification" choices:"normal|important|fatal" default:"normal"` diff --git a/pkg/apis/compute/elasticcache_const.go b/pkg/apis/compute/elasticcache_const.go index e2099600d0..b4c212e260 100644 --- a/pkg/apis/compute/elasticcache_const.go +++ b/pkg/apis/compute/elasticcache_const.go @@ -24,6 +24,7 @@ const ( ELASTIC_CACHE_STATUS_CHANGE_FAILED = "change_failed" //(修改失败) ELASTIC_CACHE_STATUS_INACTIVE = "inactive" //(被禁用) ELASTIC_CACHE_STATUS_FLUSHING = "flushing" //(清除中) + ELASTIC_CACHE_STATUS_FLUSHING_FAILED = "flushing_failed" //(清除失败) ELASTIC_CACHE_STATUS_RELEASED = "released" //(已释放) ELASTIC_CACHE_STATUS_RELEASE_FAILED = "release_failed" //(释放失败) ELASTIC_CACHE_STATUS_TRANSFORMING = "transforming" //(转换中) @@ -94,3 +95,10 @@ const ( ELASTIC_CACHE_PARAMETER_STATUS_UPDATING = "updating" // 更新中 ELASTIC_CACHE_PARAMETER_STATUS_UPDATE_FAILED = "update_failed" // 更新失败 ) + +const ( + ELASTIC_CACHE_ARCH_TYPE_SINGLE = "single" // 单副本 + ELASTIC_CACHE_ARCH_TYPE_MASTER = "master" // 主备 + ELASTIC_CACHE_ARCH_TYPE_CLUSTER = "cluster" // 集群 + ELASTIC_CACHE_ARCH_TYPE_RWSPLIT = "rwsplit" // 读写分离 +) diff --git a/pkg/cloudcommon/db/opslog.go b/pkg/cloudcommon/db/opslog.go index 6b41e2ce5b..8c01b1b8ec 100644 --- a/pkg/cloudcommon/db/opslog.go +++ b/pkg/cloudcommon/db/opslog.go @@ -250,6 +250,11 @@ const ( ACT_RESTORE = "restore" ACT_CHANGE_CONFIG = "change_config" ACT_RESET_PASSWORD = "reset_password" + + ACT_SUBIMAGE_UPDATE_FAIL = "guest_image_subimages_update_fail" + + ACT_FLUSH_INSTANCE = "flush_instance" + ACT_FLUSH_INSTANCE_FAIL = "flush_instance_fail" ) type SOpsLogManager struct { diff --git a/pkg/compute/models/elasticcache_accounts.go b/pkg/compute/models/elasticcache_accounts.go index 6547589521..5febff7a2d 100644 --- a/pkg/compute/models/elasticcache_accounts.go +++ b/pkg/compute/models/elasticcache_accounts.go @@ -289,7 +289,8 @@ func (self *SElasticcacheAccount) GetUpdateHuaweiElasticcacheAccountParams(data ret.Password = &password oldpasswd, err := self.GetDecodedPassword() if err != nil { - return ret, err + // can not update password, if old password is emtpy + return ret, errors.Wrap(err, "ElasticcacheAccount.GetUpdateHuaweiElasticcacheAccountParams.GetDecodedPassword") } ret.OldPassword = &oldpasswd diff --git a/pkg/compute/models/elasticcache_backups.go b/pkg/compute/models/elasticcache_backups.go index 41a453d5de..78ce8b426d 100644 --- a/pkg/compute/models/elasticcache_backups.go +++ b/pkg/compute/models/elasticcache_backups.go @@ -205,22 +205,30 @@ func (manager *SElasticcacheBackupManager) AllowCreateItem(ctx context.Context, func (manager *SElasticcacheBackupManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { var region *SCloudregion + var ec *SElasticcache if id, _ := data.GetString("elasticcache"); len(id) > 0 { - ec, err := db.FetchByIdOrName(ElasticcacheManager, userCred, id) + _ec, err := db.FetchByIdOrName(ElasticcacheManager, userCred, id) if err != nil { return nil, fmt.Errorf("getting elastic cache instance failed") } - region = ec.(*SElasticcache).GetRegion() + + ec = _ec.(*SElasticcache) } else { return nil, httperrors.NewMissingParameterError("elasticcache") } + region = ec.GetRegion() + driver := region.GetDriver() + if err := driver.AllowCreateElasticcacheBackup(ctx, userCred, ownerId, ec); err != nil { + return nil, err + } + data, err := manager.SStandaloneResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, data) if err != nil { return nil, err } - return region.GetDriver().ValidateCreateElasticcacheBackupData(ctx, userCred, ownerId, data) + return driver.ValidateCreateElasticcacheBackupData(ctx, userCred, ownerId, data) } func (self *SElasticcacheBackup) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) { @@ -282,6 +290,7 @@ func (self *SElasticcacheBackup) PerformRestoreInstance(ctx context.Context, use return nil, err } + self.SetStatus(userCred, api.ELASTIC_CACHE_STATUS_BACKUPRECOVERING, "") return nil, self.StartRestoreInstanceTask(ctx, userCred, data.(*jsonutils.JSONDict), "") } diff --git a/pkg/compute/models/elasticcache_instances.go b/pkg/compute/models/elasticcache_instances.go index a124e407ac..ec0d80e8c9 100644 --- a/pkg/compute/models/elasticcache_instances.go +++ b/pkg/compute/models/elasticcache_instances.go @@ -460,7 +460,7 @@ func (self *SElasticcache) GetIRegion() (cloudprovider.ICloudRegion, error) { return provider.GetIRegionById(region.ExternalId) } -func (self *SElasticcache) GetCreateAliyunElasticcacheParams() (*cloudprovider.SCloudElasticCacheInput, error) { +func (self *SElasticcache) GetCreateAliyunElasticcacheParams(data *jsonutils.JSONDict) (*cloudprovider.SCloudElasticCacheInput, error) { input := &cloudprovider.SCloudElasticCacheInput{} iregion, err := self.GetIRegion() if err != nil { @@ -472,8 +472,10 @@ func (self *SElasticcache) GetCreateAliyunElasticcacheParams() (*cloudprovider.S input.InstanceType = self.InstanceType input.InstanceName = self.GetName() - // todo: inject password here - // input.Password = "xxxx" + if password, _ := data.GetString("password"); len(password) > 0 { + input.Password = password + } + input.Engine = strings.Title(self.Engine) input.EngineVersion = self.EngineVersion input.PrivateIpAddress = self.PrivateIpAddr @@ -539,7 +541,7 @@ func (self *SElasticcache) GetCreateAliyunElasticcacheParams() (*cloudprovider.S return input, nil } -func (self *SElasticcache) GetCreateHuaweiElasticcacheParams() (*cloudprovider.SCloudElasticCacheInput, error) { +func (self *SElasticcache) GetCreateHuaweiElasticcacheParams(data *jsonutils.JSONDict) (*cloudprovider.SCloudElasticCacheInput, error) { input := &cloudprovider.SCloudElasticCacheInput{} iregion, err := self.GetIRegion() if err != nil { @@ -552,16 +554,13 @@ func (self *SElasticcache) GetCreateHuaweiElasticcacheParams() (*cloudprovider.S input.CapacityGB = int64(self.CapacityMB / 1024) } - sku, err := db.FetchById(ElasticcacheSkuManager, self.InstanceType) - if err != nil { - return nil, err - } - - input.InstanceType = sku.(*SElasticcacheSku).InstanceSpec + input.InstanceType = self.InstanceType input.InstanceName = self.GetName() - // todo: inject password here - // input.Password = "xxxx" + if password, _ := data.GetString("password"); len(password) > 0 { + input.Password = password + } + switch self.Engine { case "redis": input.Engine = "Redis" @@ -648,6 +647,7 @@ func (self *SElasticcache) AllowPerformRestart(ctx context.Context, userCred mcc func (self *SElasticcache) PerformRestart(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { if utils.IsInStringArray(self.Status, []string{api.ELASTIC_CACHE_STATUS_RUNNING, api.ELASTIC_CACHE_STATUS_INACTIVE}) { + self.SetStatus(userCred, api.ELASTIC_CACHE_STATUS_RESTARTING, "") return nil, self.StartRestartTask(ctx, userCred, "", data) } else { return nil, httperrors.NewInvalidStatusError("Cannot do restart elasticcache instance in status %s", self.Status) @@ -723,11 +723,11 @@ func (self *SElasticcache) PerformChangeSpec(ctx context.Context, userCred mccli params := jsonutils.NewDict() sku, _ := data.GetString("sku_ext_id") params.Set("sku_ext_id", jsonutils.NewString(sku)) + self.SetStatus(userCred, api.ELASTIC_CACHE_STATUS_CHANGING, "") return nil, self.StartChangeSpecTask(ctx, userCred, params, "") } func (self *SElasticcache) StartChangeSpecTask(ctx context.Context, userCred mcclient.TokenCredential, params *jsonutils.JSONDict, parentTaskId string) error { - self.SetStatus(userCred, api.ELASTIC_CACHE_STATUS_CHANGING, "") task, err := taskman.TaskManager.NewTask(ctx, "ElasticcacheChangeSpecTask", self, userCred, params, parentTaskId, "", nil) if err != nil { return err @@ -742,6 +742,21 @@ func (self *SElasticcache) AllowPerformUpdateAuthMode(ctx context.Context, userC } func (self *SElasticcache) ValidatorUpdateAuthModeData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { + region := self.GetRegion() + if region == nil { + return nil, fmt.Errorf("fail to found region for elastic cache") + } + + driver := region.GetDriver() + if driver == nil { + return nil, fmt.Errorf("fail to found driver for elastic cache") + } + + err := driver.AllowUpdateElasticcacheAuthMode(ctx, userCred, self.GetOwnerId(), self) + if err != nil { + return nil, err + } + authModeV := validators.NewStringChoicesValidator("auth_mode", choices.NewChoices("on", "off")) if err := authModeV.Optional(false).Validate(data.(*jsonutils.JSONDict)); err != nil { return nil, err @@ -763,6 +778,7 @@ func (self *SElasticcache) PerformUpdateAuthMode(ctx context.Context, userCred m params := jsonutils.NewDict() authMode, _ := data.GetString("auth_mode") params.Set("auth_mode", jsonutils.NewString(authMode)) + self.SetStatus(userCred, api.ELASTIC_CACHE_STATUS_CHANGING, "") return nil, self.StartUpdateAuthModeTask(ctx, userCred, params, "") } @@ -805,6 +821,7 @@ func (self *SElasticcache) PerformResetPassword(ctx context.Context, userCred mc return nil, err } + self.SetStatus(userCred, api.ELASTIC_CACHE_STATUS_CHANGING, "") return nil, self.StartResetPasswordTask(ctx, userCred, data.(*jsonutils.JSONDict), "") } @@ -875,6 +892,7 @@ func (self *SElasticcache) PerformSetMaintainTime(ctx context.Context, userCred endTime, _ := data.GetString("maintain_end_time") params.Set("maintain_start_time", jsonutils.NewString(startTime)) params.Set("maintain_end_time", jsonutils.NewString(endTime)) + self.SetStatus(userCred, api.ELASTIC_CACHE_STATUS_CHANGING, "") return nil, self.StartSetMaintainTimeTask(ctx, userCred, params, "") } @@ -915,6 +933,7 @@ func (self *SElasticcache) PerformAllocatePublicConnection(ctx context.Context, params := jsonutils.NewDict() port, _ := data.Int("port") params.Set("port", jsonutils.NewInt(port)) + self.SetStatus(userCred, api.ELASTIC_CACHE_STATUS_NETWORKMODIFYING, "") return nil, self.StartAllocatePublicConnectionTask(ctx, userCred, params, "") } @@ -946,6 +965,7 @@ func (self *SElasticcache) PerformReleasePublicConnection(ctx context.Context, u return nil, err } + self.SetStatus(userCred, api.ELASTIC_CACHE_STATUS_NETWORKMODIFYING, "") return nil, self.StartReleasePublicConnectionTask(ctx, userCred, jsonutils.NewDict(), "") } @@ -1005,6 +1025,7 @@ func (self *SElasticcache) PerformUpdateInstanceParameters(ctx context.Context, params := jsonutils.NewDict() parameters, _ := data.Get("parameters") params.Set("parameters", parameters) + self.SetStatus(userCred, api.ELASTIC_CACHE_STATUS_CHANGING, "") return nil, self.StartUpdateInstanceParametersTask(ctx, userCred, params, "") } @@ -1051,6 +1072,7 @@ func (self *SElasticcache) PerformUpdateBackupPolicy(ctx context.Context, userCr return nil, err } + self.SetStatus(userCred, api.ELASTIC_CACHE_STATUS_CHANGING, "") return nil, self.StartUpdateBackupPolicyTask(ctx, userCred, data.(*jsonutils.JSONDict), "") } @@ -1069,6 +1091,7 @@ func (self *SElasticcache) AllowPerformSync(ctx context.Context, userCred mcclie } func (self *SElasticcache) PerformSync(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { + self.SetStatus(userCred, api.ELASTIC_CACHE_STATUS_SYNCING, "") return nil, self.StartSyncTask(ctx, userCred, data.(*jsonutils.JSONDict), "") } diff --git a/pkg/compute/models/regiondrivers.go b/pkg/compute/models/regiondrivers.go index 003c058f37..752ccf72ef 100644 --- a/pkg/compute/models/regiondrivers.go +++ b/pkg/compute/models/regiondrivers.go @@ -141,6 +141,8 @@ type IRegionDriver interface { } type IElasticcacheDriver interface { + AllowCreateElasticcacheBackup(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, elasticcache *SElasticcache) error + AllowUpdateElasticcacheAuthMode(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, elasticcache *SElasticcache) error ValidateCreateElasticcacheData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) ValidateCreateElasticcacheAccountData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) ValidateCreateElasticcacheAclData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) diff --git a/pkg/compute/models/skus_tools.go b/pkg/compute/models/skus_tools.go index 5dd18d53b0..d5ad3cba77 100644 --- a/pkg/compute/models/skus_tools.go +++ b/pkg/compute/models/skus_tools.go @@ -84,18 +84,16 @@ func (self *SSkuResourcesMeta) GetElasticCacheSkus() ([]SElasticcacheSku, error) return nil, errors.Wrap(err, "obj.Unmarshal") } // 处理数据 - provider := sku.Provider - region := sku.CloudregionId - sku.Id = "" - r, err := self.fetchRegion(provider, region) + + r, err := self.fetchRegion(sku.CloudregionId) if err != nil { return nil, errors.Wrap(err, "SkuResourcesMeta.GetElasticCacheSkus.fetchRegion") } sku.CloudregionId = r.GetId() if len(sku.ZoneId) > 0 { - zone, err := self.fetchZone(provider, region, sku.ZoneId) + zone, err := self.fetchZone(sku.ZoneId) if err != nil { return nil, errors.Wrap(err, "SkuResourcesMeta.GetElasticCacheSkus.MasterZone") } @@ -104,7 +102,7 @@ func (self *SSkuResourcesMeta) GetElasticCacheSkus() ([]SElasticcacheSku, error) } if len(sku.SlaveZoneId) > 0 { - zone, err := self.fetchZone(provider, region, sku.SlaveZoneId) + zone, err := self.fetchZone(sku.SlaveZoneId) if err != nil { return nil, errors.Wrap(err, "SkuResourcesMeta.GetElasticCacheSkus.SlaveZone") } @@ -117,12 +115,11 @@ func (self *SSkuResourcesMeta) GetElasticCacheSkus() ([]SElasticcacheSku, error) return result, nil } -func (self *SSkuResourcesMeta) fetchZone(provider, region, zone string) (*SZone, error) { +func (self *SSkuResourcesMeta) fetchZone(zoneExternalId string) (*SZone, error) { if self.zoneCaches == nil { self.zoneCaches = map[string]*SZone{} } - zoneExternalId := strings.Join([]string{provider, region, zone}, "/") if z, ok := self.zoneCaches[zoneExternalId]; ok { return z, nil } @@ -137,12 +134,11 @@ func (self *SSkuResourcesMeta) fetchZone(provider, region, zone string) (*SZone, return z, nil } -func (self *SSkuResourcesMeta) fetchRegion(provider, region string) (*SCloudregion, error) { +func (self *SSkuResourcesMeta) fetchRegion(regionExternalId string) (*SCloudregion, error) { if self.regionCaches == nil { self.regionCaches = map[string]*SCloudregion{} } - regionExternalId := strings.Join([]string{provider, region}, "/") if r, ok := self.regionCaches[regionExternalId]; ok { return r, nil } diff --git a/pkg/compute/regiondrivers/aliyun.go b/pkg/compute/regiondrivers/aliyun.go index 1da5c74e92..d40e9aeee4 100644 --- a/pkg/compute/regiondrivers/aliyun.go +++ b/pkg/compute/regiondrivers/aliyun.go @@ -1265,7 +1265,7 @@ func (self *SAliyunRegionDriver) RequestCreateElasticcache(ctx context.Context, provider := iprovider.(*models.SCloudprovider) - params, err := ec.GetCreateAliyunElasticcacheParams() + params, err := ec.GetCreateAliyunElasticcacheParams(task.GetParams()) if err != nil { return nil, errors.Wrap(err, "aliyunRegionDriver.CreateElasticcache.GetCreateAliyunElasticcacheParams") } diff --git a/pkg/compute/regiondrivers/huawei.go b/pkg/compute/regiondrivers/huawei.go index 3df2754789..49d06f7bb4 100644 --- a/pkg/compute/regiondrivers/huawei.go +++ b/pkg/compute/regiondrivers/huawei.go @@ -2418,7 +2418,7 @@ func (self *SHuaWeiRegionDriver) RequestCreateElasticcache(ctx context.Context, provider := iprovider.(*models.SCloudprovider) - params, err := ec.GetCreateHuaweiElasticcacheParams() + params, err := ec.GetCreateHuaweiElasticcacheParams(task.GetParams()) if err != nil { return nil, errors.Wrap(err, "huaweiRegionDriver.CreateElasticcache.GetCreateHuaweiElasticcacheParams") } @@ -2546,3 +2546,19 @@ func (self *SHuaWeiRegionDriver) RequestElasticcacheAccountResetPassword(ctx con return ea.SetStatus(userCred, api.ELASTIC_CACHE_ACCOUNT_STATUS_AVAILABLE, "") } + +func (self *SHuaWeiRegionDriver) RequestUpdateElasticcacheAuthMode(ctx context.Context, userCred mcclient.TokenCredential, ec *models.SElasticcache, task taskman.ITask) error { + return errors.Wrap(fmt.Errorf("not support update huawei elastic cache auth_mode"), "HuaWeiRegionDriver.RequestUpdateElasticcacheAuthMode") +} + +func (self *SHuaWeiRegionDriver) AllowCreateElasticcacheBackup(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, elasticcache *models.SElasticcache) error { + if elasticcache.LocalCategory == api.ELASTIC_CACHE_ARCH_TYPE_SINGLE { + return httperrors.NewBadRequestError("huawei %s mode elastic not support create backup", elasticcache.LocalCategory) + } + + return nil +} + +func (self *SHuaWeiRegionDriver) AllowUpdateElasticcacheAuthMode(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, elasticcache *models.SElasticcache) error { + return fmt.Errorf("not support update huawei elastic cache auth_mode") +} diff --git a/pkg/compute/regiondrivers/kvm.go b/pkg/compute/regiondrivers/kvm.go index 2bf3d5c906..1148c76b01 100644 --- a/pkg/compute/regiondrivers/kvm.go +++ b/pkg/compute/regiondrivers/kvm.go @@ -946,6 +946,10 @@ func (self *SKVMRegionDriver) ValidateCreateElasticcacheAclData(ctx context.Cont return nil, nil } +func (self *SKVMRegionDriver) AllowCreateElasticcacheBackup(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, elasticcache *models.SElasticcache) error { + return fmt.Errorf("not support create kvm elastic cache backup") +} + func (self *SKVMRegionDriver) ValidateCreateElasticcacheBackupData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { return nil, nil } @@ -985,3 +989,7 @@ func (self *SKVMRegionDriver) RequestElasticcacheAclUpdate(ctx context.Context, func (self *SKVMRegionDriver) RequestElasticcacheBackupRestoreInstance(ctx context.Context, userCred mcclient.TokenCredential, ea *models.SElasticcacheBackup, task taskman.ITask) error { return nil } + +func (self *SKVMRegionDriver) AllowUpdateElasticcacheAuthMode(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, elasticcache *models.SElasticcache) error { + return fmt.Errorf("not support update kvm elastic cache auth_mode") +} diff --git a/pkg/compute/regiondrivers/managedvirtual.go b/pkg/compute/regiondrivers/managedvirtual.go index 084b6ec88b..dc20e7acc9 100644 --- a/pkg/compute/regiondrivers/managedvirtual.go +++ b/pkg/compute/regiondrivers/managedvirtual.go @@ -1622,6 +1622,7 @@ func (self *SManagedVirtualizationRegionDriver) RequestCreateDBInstance(ctx cont } func (self *SManagedVirtualizationRegionDriver) RequestCreateElasticcache(ctx context.Context, userCred mcclient.TokenCredential, elasticcache *models.SElasticcache, task taskman.ITask) error { + task.ScheduleRun(nil) return nil } @@ -1661,6 +1662,11 @@ func (self *SManagedVirtualizationRegionDriver) RequestSyncElasticcache(ctx cont iec, err := iregion.GetIElasticcacheById(ec.ExternalId) if err != nil { + if err == cloudprovider.ErrNotFound { + ec.SetStatus(userCred, api.ELASTIC_CACHE_STATUS_UNKNOWN, "") + return nil + } + return errors.Wrap(err, "managedVirtualizationRegionDriver.RequestSyncElasticcache.GetIElasticcacheById") } @@ -2050,6 +2056,10 @@ func (self *SManagedVirtualizationRegionDriver) ValidateCreateElasticcacheAclDat return data, nil } +func (self *SManagedVirtualizationRegionDriver) AllowCreateElasticcacheBackup(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, elasticcache *models.SElasticcache) error { + return nil +} + func (self *SManagedVirtualizationRegionDriver) ValidateCreateElasticcacheBackupData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { elasticcacheV := validators.NewModelIdOrNameValidator("elasticcache", "elasticcache", ownerId) if err := elasticcacheV.Validate(data); err != nil { @@ -2518,3 +2528,7 @@ func (self *SManagedVirtualizationRegionDriver) RequestElasticcacheBackupRestore } return nil } + +func (self *SManagedVirtualizationRegionDriver) AllowUpdateElasticcacheAuthMode(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, elasticcache *models.SElasticcache) error { + return nil +} diff --git a/pkg/compute/tasks/elasticcache_account_create_task.go b/pkg/compute/tasks/elasticcache_account_create_task.go index c9ffb0e521..e4a95989d9 100644 --- a/pkg/compute/tasks/elasticcache_account_create_task.go +++ b/pkg/compute/tasks/elasticcache_account_create_task.go @@ -60,6 +60,7 @@ func (self *ElasticcacheAccountCreateTask) OnInit(ctx context.Context, obj db.IS } func (self *ElasticcacheAccountCreateTask) OnElasticcacheAccountCreateComplete(ctx context.Context, ea *models.SElasticcacheAccount, data jsonutils.JSONObject) { + logclient.AddActionLogWithStartable(self, ea, logclient.ACT_CREATE, nil, self.UserCred, true) self.SetStageComplete(ctx, nil) } diff --git a/pkg/compute/tasks/elasticcache_account_delete_task.go b/pkg/compute/tasks/elasticcache_account_delete_task.go index b1672a34b5..4a5fd9b829 100644 --- a/pkg/compute/tasks/elasticcache_account_delete_task.go +++ b/pkg/compute/tasks/elasticcache_account_delete_task.go @@ -38,8 +38,8 @@ func init() { func (self *ElasticcacheAccountDeleteTask) taskFail(ctx context.Context, ea *models.SElasticcacheAccount, reason string) { ea.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_ACCOUNT_STATUS_DELETE_FAILED, reason) - db.OpsLog.LogEvent(ea, db.ACT_ALLOCATE_FAIL, reason, self.UserCred) - logclient.AddActionLogWithStartable(self, ea, logclient.ACT_CREATE, reason, self.UserCred, false) + db.OpsLog.LogEvent(ea, db.ACT_DELETE_FAIL, reason, self.UserCred) + logclient.AddActionLogWithStartable(self, ea, logclient.ACT_DELETE, reason, self.UserCred, false) notifyclient.NotifySystemError(ea.Id, ea.Name, api.ELASTIC_CACHE_ACCOUNT_STATUS_DELETE_FAILED, reason) self.SetStageFailed(ctx, reason) } @@ -62,6 +62,8 @@ func (self *ElasticcacheAccountDeleteTask) OnInit(ctx context.Context, obj db.IS self.taskFail(ctx, ea, err.Error()) return } + + logclient.AddActionLogWithStartable(self, ea, logclient.ACT_DELETE, nil, self.UserCred, true) self.SetStageComplete(ctx, nil) } } diff --git a/pkg/compute/tasks/elasticcache_account_reset_password_task.go b/pkg/compute/tasks/elasticcache_account_reset_password_task.go index 0a05e62254..a51e801c59 100644 --- a/pkg/compute/tasks/elasticcache_account_reset_password_task.go +++ b/pkg/compute/tasks/elasticcache_account_reset_password_task.go @@ -36,27 +36,36 @@ func init() { taskman.RegisterTask(ElasticcacheAccountResetPasswordTask{}) } -func (self *ElasticcacheAccountResetPasswordTask) taskFail(ctx context.Context, elasticcache *models.SElasticcacheAccount, reason string) { - elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_UNAVAILABLE, reason) - db.OpsLog.LogEvent(elasticcache, db.ACT_ALLOCATE_FAIL, reason, self.UserCred) - logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_CREATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CREATE_FAILED, reason) +func (self *ElasticcacheAccountResetPasswordTask) taskFail(ctx context.Context, ea *models.SElasticcacheAccount, reason string) { + ea.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason) + ec, err := db.FetchById(models.ElasticcacheManager, ea.ElasticcacheId) + if err == nil { + ec.(*models.SElasticcache).SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason) + } + db.OpsLog.LogEvent(ea, db.ACT_RESET_PASSWORD, reason, self.UserCred) + logclient.AddActionLogWithStartable(self, ea, logclient.ACT_RESET_PASSWORD, reason, self.UserCred, false) + notifyclient.NotifySystemError(ea.Id, ea.Name, api.ELASTIC_CACHE_STATUS_CREATE_FAILED, reason) self.SetStageFailed(ctx, reason) } func (self *ElasticcacheAccountResetPasswordTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { - ec := obj.(*models.SElasticcacheAccount) - region := ec.GetRegion() + ea := obj.(*models.SElasticcacheAccount) + region := ea.GetRegion() if region == nil { - self.taskFail(ctx, ec, fmt.Sprintf("failed to find region for elastic cache %s", ec.GetName())) + self.taskFail(ctx, ea, fmt.Sprintf("failed to find region for elastic cache account %s", ea.GetName())) return } self.SetStage("OnElasticcacheAccountResetPasswordComplete", nil) - if err := region.GetDriver().RequestElasticcacheAccountResetPassword(ctx, self.GetUserCred(), ec, self); err != nil { - self.taskFail(ctx, ec, err.Error()) + if err := region.GetDriver().RequestElasticcacheAccountResetPassword(ctx, self.GetUserCred(), ea, self); err != nil { + self.taskFail(ctx, ea, err.Error()) return } else { + logclient.AddActionLogWithStartable(self, ea, logclient.ACT_RESET_PASSWORD, nil, self.UserCred, true) + ec, err := db.FetchById(models.ElasticcacheManager, ea.ElasticcacheId) + if err == nil { + ec.(*models.SElasticcache).SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_RUNNING, "") + } self.SetStageComplete(ctx, nil) } } diff --git a/pkg/compute/tasks/elasticcache_acl_create_task.go b/pkg/compute/tasks/elasticcache_acl_create_task.go index 98a2156ed1..6decf4f7c6 100644 --- a/pkg/compute/tasks/elasticcache_acl_create_task.go +++ b/pkg/compute/tasks/elasticcache_acl_create_task.go @@ -59,6 +59,7 @@ func (self *ElasticcacheAclCreateTask) OnInit(ctx context.Context, obj db.IStand } func (self *ElasticcacheAclCreateTask) OnElasticcacheAclCreateComplete(ctx context.Context, ea *models.SElasticcacheAcl, data jsonutils.JSONObject) { + logclient.AddActionLogWithStartable(self, ea, logclient.ACT_CREATE, nil, self.UserCred, true) self.SetStageComplete(ctx, nil) } diff --git a/pkg/compute/tasks/elasticcache_acl_delete_task.go b/pkg/compute/tasks/elasticcache_acl_delete_task.go index 466f64e24b..812f909904 100644 --- a/pkg/compute/tasks/elasticcache_acl_delete_task.go +++ b/pkg/compute/tasks/elasticcache_acl_delete_task.go @@ -61,6 +61,7 @@ func (self *ElasticcacheAclDeleteTask) OnInit(ctx context.Context, obj db.IStand self.taskFail(ctx, ea, err.Error()) return } + logclient.AddActionLogWithStartable(self, ea, logclient.ACT_DELETE, nil, self.UserCred, true) self.SetStageComplete(ctx, nil) } } diff --git a/pkg/compute/tasks/elasticcache_acl_update_task.go b/pkg/compute/tasks/elasticcache_acl_update_task.go index 0487242eb2..5dfb681213 100644 --- a/pkg/compute/tasks/elasticcache_acl_update_task.go +++ b/pkg/compute/tasks/elasticcache_acl_update_task.go @@ -59,6 +59,7 @@ func (self *ElasticcacheAclUpdateTask) OnInit(ctx context.Context, obj db.IStand } func (self *ElasticcacheAclUpdateTask) OnElasticcacheAclUpdateComplete(ctx context.Context, ea *models.SElasticcacheAcl, data jsonutils.JSONObject) { + logclient.AddActionLogWithStartable(self, ea, logclient.ACT_UPDATE, nil, self.UserCred, true) self.SetStageComplete(ctx, nil) } diff --git a/pkg/compute/tasks/elasticcache_allocate_public_connection_task.go b/pkg/compute/tasks/elasticcache_allocate_public_connection_task.go index f40616f09f..0b6eb8cae2 100644 --- a/pkg/compute/tasks/elasticcache_allocate_public_connection_task.go +++ b/pkg/compute/tasks/elasticcache_allocate_public_connection_task.go @@ -64,6 +64,7 @@ func (self *ElasticcacheAllocatePublicConnectionTask) OnInit(ctx context.Context func (self *ElasticcacheAllocatePublicConnectionTask) OnElasticcacheAllocatePublicConnectionComplete(ctx context.Context, elasticcache *models.SElasticcache, data jsonutils.JSONObject) { elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_RUNNING, "") + logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_ALLOCATE, "allocate public connection", self.UserCred, true) self.SetStageComplete(ctx, nil) } diff --git a/pkg/compute/tasks/elasticcache_backup_create_task.go b/pkg/compute/tasks/elasticcache_backup_create_task.go index 9d39f4e3d7..79e5d6d8f4 100644 --- a/pkg/compute/tasks/elasticcache_backup_create_task.go +++ b/pkg/compute/tasks/elasticcache_backup_create_task.go @@ -59,11 +59,12 @@ func (self *ElasticcacheBackupCreateTask) OnInit(ctx context.Context, obj db.ISt } } -func (self *ElasticcacheBackupCreateTask) OnElasticcacheBackupCreateComplete(ctx context.Context, ea *models.SElasticcacheBackup, data jsonutils.JSONObject) { - ea.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_RUNNING, "") +func (self *ElasticcacheBackupCreateTask) OnElasticcacheBackupCreateComplete(ctx context.Context, eb *models.SElasticcacheBackup, data jsonutils.JSONObject) { + eb.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_RUNNING, "") + logclient.AddActionLogWithStartable(self, eb, logclient.ACT_CREATE, "", self.UserCred, true) self.SetStageComplete(ctx, nil) } -func (self *ElasticcacheBackupCreateTask) OnElasticcacheBackupCreateCompleteFailed(ctx context.Context, ea *models.SElasticcacheBackup, reason string) { - self.taskFail(ctx, ea, reason) +func (self *ElasticcacheBackupCreateTask) OnElasticcacheBackupCreateCompleteFailed(ctx context.Context, eb *models.SElasticcacheBackup, reason string) { + self.taskFail(ctx, eb, reason) } diff --git a/pkg/compute/tasks/elasticcache_backup_restore_instance_task.go b/pkg/compute/tasks/elasticcache_backup_restore_instance_task.go index 477e9e4a55..05ee6a3182 100644 --- a/pkg/compute/tasks/elasticcache_backup_restore_instance_task.go +++ b/pkg/compute/tasks/elasticcache_backup_restore_instance_task.go @@ -64,6 +64,7 @@ func (self *ElasticcacheBackupRestoreInstanceTask) OnInit(ctx context.Context, o func (self *ElasticcacheBackupRestoreInstanceTask) OnElasticcacheBackupRestoreInstanceComplete(ctx context.Context, eb *models.SElasticcacheBackup, data jsonutils.JSONObject) { eb.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_RUNNING, "") + logclient.AddActionLogWithStartable(self, eb, logclient.ACT_RESTORE, "", self.UserCred, true) self.SetStageComplete(ctx, nil) } diff --git a/pkg/compute/tasks/elasticcache_change_spec_task.go b/pkg/compute/tasks/elasticcache_change_spec_task.go index 5fb66e5b82..530f0de686 100644 --- a/pkg/compute/tasks/elasticcache_change_spec_task.go +++ b/pkg/compute/tasks/elasticcache_change_spec_task.go @@ -64,6 +64,7 @@ func (self *ElasticcacheChangeSpecTask) OnInit(ctx context.Context, obj db.IStan func (self *ElasticcacheChangeSpecTask) OnElasticcacheChangeSpecComplete(ctx context.Context, elasticcache *models.SElasticcache, data jsonutils.JSONObject) { elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_RUNNING, "") + logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_VM_CHANGE_FLAVOR, "", self.UserCred, true) self.SetStageComplete(ctx, nil) } diff --git a/pkg/compute/tasks/elasticcache_create_task.go b/pkg/compute/tasks/elasticcache_create_task.go index 85cc25c781..4804296e3f 100644 --- a/pkg/compute/tasks/elasticcache_create_task.go +++ b/pkg/compute/tasks/elasticcache_create_task.go @@ -67,6 +67,8 @@ func (self *ElasticcacheCreateTask) OnSyncSecurityGroupComplete(ctx context.Cont } func (self *ElasticcacheCreateTask) OnElasticcacheCreateComplete(ctx context.Context, elasticcache *models.SElasticcache, data jsonutils.JSONObject) { + elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_RUNNING, "") + logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_CREATE, "", self.UserCred, true) self.SetStageComplete(ctx, nil) } diff --git a/pkg/compute/tasks/elasticcache_delete_task.go b/pkg/compute/tasks/elasticcache_delete_task.go index 2b1c548cce..df4b19a26e 100644 --- a/pkg/compute/tasks/elasticcache_delete_task.go +++ b/pkg/compute/tasks/elasticcache_delete_task.go @@ -60,6 +60,7 @@ func (self *ElasticcacheDeleteTask) OnInit(ctx context.Context, obj db.IStandalo ec.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_RELEASED, "") // delete related resources ec.DeleteSubResources(ctx, self.UserCred) + logclient.AddActionLogWithStartable(self, ec, logclient.ACT_DELETE, "", self.UserCred, true) self.SetStageComplete(ctx, nil) } } diff --git a/pkg/compute/tasks/elasticcache_flush_instance.go b/pkg/compute/tasks/elasticcache_flush_instance.go index f075ab0c33..1ec623ad38 100644 --- a/pkg/compute/tasks/elasticcache_flush_instance.go +++ b/pkg/compute/tasks/elasticcache_flush_instance.go @@ -37,10 +37,10 @@ func init() { } func (self *ElasticcacheFlushInstanceTask) taskFail(ctx context.Context, elasticcache *models.SElasticcache, reason string) { - elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CREATE_FAILED, reason) - db.OpsLog.LogEvent(elasticcache, db.ACT_REW_FAIL, reason, self.UserCred) - logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_UNCACHED_IMAGE, reason, self.UserCred, false) - notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_ACL_STATUS_UPDATE_FAILED, reason) + elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_FLUSHING_FAILED, reason) + db.OpsLog.LogEvent(elasticcache, db.ACT_FLUSH_INSTANCE_FAIL, reason, self.UserCred) + logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_FLUSH_INSTANCE, reason, self.UserCred, false) + notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_FLUSHING_FAILED, reason) self.SetStageFailed(ctx, reason) } @@ -64,6 +64,7 @@ func (self *ElasticcacheFlushInstanceTask) OnInit(ctx context.Context, obj db.IS func (self *ElasticcacheFlushInstanceTask) OnElasticcacheFlushInstanceComplete(ctx context.Context, elasticcache *models.SElasticcache, data jsonutils.JSONObject) { elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_RUNNING, "") + logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_FLUSH_INSTANCE, "", self.UserCred, true) self.SetStageComplete(ctx, nil) } diff --git a/pkg/compute/tasks/elasticcache_parameter_update_task.go b/pkg/compute/tasks/elasticcache_parameter_update_task.go index b14cb6fe70..8f2c917958 100644 --- a/pkg/compute/tasks/elasticcache_parameter_update_task.go +++ b/pkg/compute/tasks/elasticcache_parameter_update_task.go @@ -64,10 +64,11 @@ func (self *ElasticcacheParameterUpdateTask) OnInit(ctx context.Context, obj db. } } -func (self *ElasticcacheParameterUpdateTask) OnElasticcacheParameterUpdateComplete(ctx context.Context, ea *models.SElasticcacheParameter, data jsonutils.JSONObject) { +func (self *ElasticcacheParameterUpdateTask) OnElasticcacheParameterUpdateComplete(ctx context.Context, ep *models.SElasticcacheParameter, data jsonutils.JSONObject) { + logclient.AddActionLogWithStartable(self, ep, logclient.ACT_UPDATE, "", self.UserCred, true) self.SetStageComplete(ctx, nil) } -func (self *ElasticcacheParameterUpdateTask) OnElasticcacheParameterUpdateCompleteFailed(ctx context.Context, ea *models.SElasticcacheParameter, reason string) { - self.taskFail(ctx, ea, reason) +func (self *ElasticcacheParameterUpdateTask) OnElasticcacheParameterUpdateCompleteFailed(ctx context.Context, ep *models.SElasticcacheParameter, reason string) { + self.taskFail(ctx, ep, reason) } diff --git a/pkg/compute/tasks/elasticcache_restart_task.go b/pkg/compute/tasks/elasticcache_restart_task.go index e43089eee5..d3ad8f6d28 100644 --- a/pkg/compute/tasks/elasticcache_restart_task.go +++ b/pkg/compute/tasks/elasticcache_restart_task.go @@ -57,6 +57,7 @@ func (self *ElasticcacheRestartTask) OnInit(ctx context.Context, obj db.IStandal self.taskFail(ctx, ec, err.Error()) return } else { + logclient.AddActionLogWithStartable(self, ec, logclient.ACT_VM_RESTART, nil, self.UserCred, true) self.SetStageComplete(ctx, nil) } } diff --git a/pkg/compute/tasks/elasticcache_set_maintain_time_task.go b/pkg/compute/tasks/elasticcache_set_maintain_time_task.go index 68ff0657a7..19bed2ca4c 100644 --- a/pkg/compute/tasks/elasticcache_set_maintain_time_task.go +++ b/pkg/compute/tasks/elasticcache_set_maintain_time_task.go @@ -37,10 +37,10 @@ func init() { } func (self *ElasticcacheSetMaintainTimeTask) taskFail(ctx context.Context, elasticcache *models.SElasticcache, reason string) { - elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CREATE_FAILED, reason) - db.OpsLog.LogEvent(elasticcache, db.ACT_ALLOCATE_FAIL, reason, self.UserCred) + elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason) + db.OpsLog.LogEvent(elasticcache, db.ACT_UPDATE, reason, self.UserCred) logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_UPDATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_ACL_STATUS_UPDATE_FAILED, reason) + notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason) self.SetStageFailed(ctx, reason) } @@ -64,6 +64,7 @@ func (self *ElasticcacheSetMaintainTimeTask) OnInit(ctx context.Context, obj db. func (self *ElasticcacheSetMaintainTimeTask) OnElasticcacheSetMaintainTimeComplete(ctx context.Context, elasticcache *models.SElasticcache, data jsonutils.JSONObject) { elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_RUNNING, "") + logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_UPDATE, "", self.UserCred, true) self.SetStageComplete(ctx, nil) } diff --git a/pkg/compute/tasks/elasticcache_sync_task.go b/pkg/compute/tasks/elasticcache_sync_task.go index 673576669d..aa8540accd 100644 --- a/pkg/compute/tasks/elasticcache_sync_task.go +++ b/pkg/compute/tasks/elasticcache_sync_task.go @@ -57,6 +57,7 @@ func (self *ElasticcacheSyncTask) OnInit(ctx context.Context, obj db.IStandalone self.taskFail(ctx, ec, err.Error()) return } else { + logclient.AddActionLogWithStartable(self, ec, logclient.ACT_SYNC_CONF, "", self.UserCred, true) self.SetStageComplete(ctx, nil) } } diff --git a/pkg/compute/tasks/elasticcache_update_auth_mode_task.go b/pkg/compute/tasks/elasticcache_update_auth_mode_task.go index 269ca3ad6a..7acc9c652d 100644 --- a/pkg/compute/tasks/elasticcache_update_auth_mode_task.go +++ b/pkg/compute/tasks/elasticcache_update_auth_mode_task.go @@ -37,10 +37,10 @@ func init() { } func (self *ElasticcacheUpdateAuthModeTask) taskFail(ctx context.Context, elasticcache *models.SElasticcache, reason string) { - elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CREATE_FAILED, reason) + elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason) db.OpsLog.LogEvent(elasticcache, db.ACT_UPDATE, reason, self.UserCred) logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_UPDATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_ACL_STATUS_UPDATE_FAILED, reason) + notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason) self.SetStageFailed(ctx, reason) } @@ -64,6 +64,7 @@ func (self *ElasticcacheUpdateAuthModeTask) OnInit(ctx context.Context, obj db.I func (self *ElasticcacheUpdateAuthModeTask) OnElasticcacheUpdateAuthModeComplete(ctx context.Context, elasticcache *models.SElasticcache, data jsonutils.JSONObject) { elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_RUNNING, "") + logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_UPDATE, "", self.UserCred, true) self.SetStageComplete(ctx, nil) } diff --git a/pkg/compute/tasks/elasticcache_update_backup_policy_task.go b/pkg/compute/tasks/elasticcache_update_backup_policy_task.go index de5412a94a..001b8222ed 100644 --- a/pkg/compute/tasks/elasticcache_update_backup_policy_task.go +++ b/pkg/compute/tasks/elasticcache_update_backup_policy_task.go @@ -37,10 +37,10 @@ func init() { } func (self *ElasticcacheUpdateBackupPolicyTask) taskFail(ctx context.Context, elasticcache *models.SElasticcache, reason string) { - elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CREATE_FAILED, reason) + elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason) db.OpsLog.LogEvent(elasticcache, db.ACT_UPDATE, reason, self.UserCred) logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_UPDATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_ACL_STATUS_UPDATE_FAILED, reason) + notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason) self.SetStageFailed(ctx, reason) } @@ -64,6 +64,7 @@ func (self *ElasticcacheUpdateBackupPolicyTask) OnInit(ctx context.Context, obj func (self *ElasticcacheUpdateBackupPolicyTask) OnElasticcacheUpdateBackupPolicyComplete(ctx context.Context, elasticcache *models.SElasticcache, data jsonutils.JSONObject) { elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_RUNNING, "") + logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_UPDATE, "", self.UserCred, true) self.SetStageComplete(ctx, nil) } diff --git a/pkg/multicloud/aliyun/elasticcache_instance.go b/pkg/multicloud/aliyun/elasticcache_instance.go index 5e8e79e964..90b33bc09d 100644 --- a/pkg/multicloud/aliyun/elasticcache_instance.go +++ b/pkg/multicloud/aliyun/elasticcache_instance.go @@ -209,14 +209,14 @@ func (self *SElasticcache) GetCapacityMB() int { func (self *SElasticcache) GetArchType() string { switch self.ArchitectureType { case "rwsplit": - return "rwsplit" + return api.ELASTIC_CACHE_ARCH_TYPE_RWSPLIT case "cluster": - return "cluster" + return api.ELASTIC_CACHE_ARCH_TYPE_CLUSTER case "standard": if self.NodeType == "single" { - return "single" + return api.ELASTIC_CACHE_ARCH_TYPE_SINGLE } else if self.NodeType == "double" { - return "master" + return api.ELASTIC_CACHE_ARCH_TYPE_MASTER } } diff --git a/pkg/multicloud/huawei/client/modules/manager_base.go b/pkg/multicloud/huawei/client/modules/manager_base.go index 4b1cd5bf17..b5c2c67afc 100644 --- a/pkg/multicloud/huawei/client/modules/manager_base.go +++ b/pkg/multicloud/huawei/client/modules/manager_base.go @@ -68,7 +68,8 @@ func (self *SBaseManager) _list(request requests.IRequest, responseKey string) ( return nil, err } if body == nil { - return nil, fmt.Errorf("empty response") + log.Warningf("empty response") + return &responses.ListResult{}, nil } rets, err := body.GetArray(responseKey) diff --git a/pkg/multicloud/huawei/elasticcache_account.go b/pkg/multicloud/huawei/elasticcache_account.go index aeebb9b45a..8c39d40a00 100644 --- a/pkg/multicloud/huawei/elasticcache_account.go +++ b/pkg/multicloud/huawei/elasticcache_account.go @@ -32,7 +32,7 @@ type SElasticcacheAccount struct { } func (self *SElasticcacheAccount) GetId() string { - return fmt.Sprintf("%s/%s", self.cacheDB.InstanceID, self.cacheDB.AccessUser) + return fmt.Sprintf("%s/admin", self.cacheDB.InstanceID) } func (self *SElasticcacheAccount) GetName() string { @@ -56,28 +56,11 @@ func (self *SElasticcacheAccount) GetAccountPrivilege() string { } // https://support.huaweicloud.com/api-dcs/dcs-zh-api-180423031.html -// 未找到关闭密码的开放api +// 未找到关闭密码的开放api, 不支持开启/关闭密码访问 // https://console.huaweicloud.com/dcs/rest/v2/41f6bfe48d7f4455b7754f7c1b11ae34/instances/26db46e2-c7d8-4b5e-bd36-b5278d2fe17c/password/reset // new_password: "26db46e2!" // no_password_access: false func (self *SElasticcacheAccount) ResetPassword(input cloudprovider.SCloudElasticCacheAccountResetPasswordInput) error { - if input.NoPasswordAccess != nil { - params := jsonutils.NewDict() - if *input.NoPasswordAccess == true { - params.Set("no_password_access", jsonutils.JSONTrue) - } else { - params.Set("no_password_access", jsonutils.JSONFalse) - } - - params.Set("new_password", jsonutils.JSONNull) - err := DoUpdateWithSpec(self.cacheDB.region.ecsClient.Elasticcache.UpdateInContextWithSpec, self.GetId(), "password/reset", params) - if err != nil { - return errors.Wrap(err, "elasticcacheAccount.NoPasswordAccess") - } - - return nil - } - if input.OldPassword == nil { return fmt.Errorf("elasticcacheAccount.ResetPassword.input OldPassword should not be empty") } diff --git a/pkg/multicloud/huawei/elasticcache_instance.go b/pkg/multicloud/huawei/elasticcache_instance.go index 0280e9b91b..97b380a3bb 100644 --- a/pkg/multicloud/huawei/elasticcache_instance.go +++ b/pkg/multicloud/huawei/elasticcache_instance.go @@ -173,13 +173,13 @@ func (self *SElasticcache) GetArchType() string { dcs.cluster:表示实例类型为集群 */ if strings.Contains(self.ResourceSpecCode, "single") { - return "single" + return api.ELASTIC_CACHE_ARCH_TYPE_SINGLE } else if strings.Contains(self.ResourceSpecCode, "ha") { - return "master" + return api.ELASTIC_CACHE_ARCH_TYPE_MASTER } else if strings.Contains(self.ResourceSpecCode, "cluster") { - return "cluster" + return api.ELASTIC_CACHE_ARCH_TYPE_CLUSTER } else if strings.Contains(self.ResourceSpecCode, "proxy") { - return "cluster" + return api.ELASTIC_CACHE_ARCH_TYPE_CLUSTER } return "" @@ -257,11 +257,8 @@ func (self *SElasticcache) GetMaintainEndTime() string { func (self *SElasticcache) GetICloudElasticcacheAccounts() ([]cloudprovider.ICloudElasticcacheAccount, error) { iaccounts := []cloudprovider.ICloudElasticcacheAccount{} - if len(self.AccessUser) > 0 { - iaccount := &SElasticcacheAccount{cacheDB: self} - iaccounts = append(iaccounts, iaccount) - } - + iaccount := &SElasticcacheAccount{cacheDB: self} + iaccounts = append(iaccounts, iaccount) return iaccounts, nil } @@ -672,7 +669,19 @@ func (self *SElasticcache) GetAuthMode() string { } func (self *SElasticcache) GetICloudElasticcacheAccount(accountId string) (cloudprovider.ICloudElasticcacheAccount, error) { - return nil, cloudprovider.ErrNotSupported + accounts, err := self.GetICloudElasticcacheAccounts() + if err != nil { + return nil, errors.Wrap(err, "Elasticcache.GetICloudElasticcacheAccount.Accounts") + } + + for i := range accounts { + account := accounts[i] + if account.GetGlobalId() == accountId { + return account, nil + } + } + + return nil, cloudprovider.ErrNotFound } func (self *SElasticcache) GetICloudElasticcacheAcl(aclId string) (cloudprovider.ICloudElasticcacheAcl, error) { diff --git a/pkg/util/logclient/consts.go b/pkg/util/logclient/consts.go index 444f949b02..c5a9ab2e5a 100644 --- a/pkg/util/logclient/consts.go +++ b/pkg/util/logclient/consts.go @@ -175,4 +175,6 @@ const ( ACT_INSTANCE_GROUP_BIND = "绑定主机组" ACT_INSTANCE_GROUP_UNBIND = "解绑主机组" + + ACT_FLUSH_INSTANCE = "清空数据" ) From 54e7eb9c368ae33a07771271ebb2197e216ea94c Mon Sep 17 00:00:00 2001 From: tangbin Date: Sun, 10 Nov 2019 09:29:06 +0800 Subject: [PATCH 2/2] add elastic cache delete protect --- pkg/compute/models/elasticcache_instances.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/compute/models/elasticcache_instances.go b/pkg/compute/models/elasticcache_instances.go index ec0d80e8c9..f0a4426fb8 100644 --- a/pkg/compute/models/elasticcache_instances.go +++ b/pkg/compute/models/elasticcache_instances.go @@ -23,6 +23,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" "yunion.io/x/pkg/errors" + "yunion.io/x/pkg/tristate" "yunion.io/x/pkg/util/compare" "yunion.io/x/pkg/utils" "yunion.io/x/sqlchemy" @@ -69,6 +70,8 @@ type SElasticcache struct { SZoneResourceBase // 主可用区. SlaveZones string `width:"128" charset:"ascii" nullable:"false" list:"user" create:"optional"` // 备可用区 + DisableDelete tristate.TriState `nullable:"false" default:"true" list:"user" update:"user" create:"optional"` // Column(Boolean, nullable=False, default=True) + InstanceType string `width:"96" charset:"ascii" nullable:"true" list:"user" create:"optional"` // redis.master.micro.default CapacityMB int `nullable:"false" list:"user" create:"optional"` // 1024 LocalCategory string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"optional"` // 对应Sku local_category @@ -666,6 +669,14 @@ func (self *SElasticcache) StartRestartTask(ctx context.Context, userCred mcclie return nil } +func (self *SElasticcache) ValidateDeleteCondition(ctx context.Context) error { + if self.DisableDelete.IsTrue() { + return httperrors.NewInvalidStatusError("Elastic cache is locked, cannot delete") + } + + return self.SVirtualResourceBase.ValidateDeleteCondition(ctx) +} + func (self *SElasticcache) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error { return self.StartDeleteElasticcacheTask(ctx, userCred, jsonutils.NewDict(), "") }