Merge pull request #3670 from tb365/bugfix/tb-bugfix-111402

* 修复redis新建无密码及公网访问地址未同步的问题
This commit is contained in:
yunion-ci-robot
2019-11-15 16:53:19 +08:00
committed by GitHub
6 changed files with 95 additions and 13 deletions
+7 -4
View File
@@ -446,14 +446,17 @@ func (manager *SElasticcacheManager) ValidateCreateData(ctx context.Context, use
func (self *SElasticcache) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
self.SVirtualResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
self.SetStatus(userCred, api.LB_CREATING, "")
if err := self.StartElasticcacheCreateTask(ctx, userCred, data.(*jsonutils.JSONDict), ""); err != nil {
params := jsonutils.NewDict()
password, _ := data.GetString("password")
params.Set("password", jsonutils.NewString(password))
self.SetStatus(userCred, api.ELASTIC_CACHE_STATUS_DEPLOYING, "")
if err := self.StartElasticcacheCreateTask(ctx, userCred, params, ""); err != nil {
log.Errorf("Failed to create elastic cache error: %v", err)
}
}
func (self *SElasticcache) StartElasticcacheCreateTask(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict, parentTaskId string) error {
task, err := taskman.TaskManager.NewTask(ctx, "ElasticcacheCreateTask", self, userCred, jsonutils.NewDict(), parentTaskId, "", nil)
func (self *SElasticcache) StartElasticcacheCreateTask(ctx context.Context, userCred mcclient.TokenCredential, params *jsonutils.JSONDict, parentTaskId string) error {
task, err := taskman.TaskManager.NewTask(ctx, "ElasticcacheCreateTask", self, userCred, params, parentTaskId, "", nil)
if err != nil {
return err
}
+11 -2
View File
@@ -1964,8 +1964,17 @@ func (self *SManagedVirtualizationRegionDriver) RequestElasticcacheReleasePublic
return errors.Wrap(err, "managedVirtualizationRegionDriver.RequestElasticcacheReleasePublicConnection.AllocatePublicConnection")
}
// todo: sync instance spec
return cloudprovider.WaitStatusWithDelay(iec, api.ELASTIC_CACHE_STATUS_RUNNING, 10*time.Second, 10*time.Second, 300*time.Second)
err = cloudprovider.WaitStatusWithDelay(iec, api.ELASTIC_CACHE_STATUS_RUNNING, 10*time.Second, 10*time.Second, 300*time.Second)
if err != nil {
return errors.Wrap(errors.ErrTimeout, "managedVirtualizationRegionDriver.RequestElasticcacheReleasePublicConnection.WaitStatusWithDelay")
}
err = ec.SyncWithCloudElasticcache(ctx, task.GetUserCred(), nil, iec)
if err != nil {
return errors.Wrap(err, "managedVirtualizationRegionDriver.RequestElasticcacheAllocatePublicConnection.SyncWithCloudElasticcache")
}
return nil
}
func (self *SManagedVirtualizationRegionDriver) RequestElasticcacheFlushInstance(ctx context.Context, userCred mcclient.TokenCredential, ec *models.SElasticcache, task taskman.ITask) error {
@@ -53,7 +53,7 @@ func (self *ElasticcacheCreateTask) OnInit(ctx context.Context, obj db.IStandalo
}
// sync security group here
self.SetStage("OnSyncSecurityGroupComplete", nil)
self.SetStage("OnSyncSecurityGroupComplete", data.(*jsonutils.JSONDict))
self.OnSyncSecurityGroupComplete(ctx, elasticcache, data)
}
@@ -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 tasks
import (
"context"
"fmt"
"yunion.io/x/jsonutils"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/util/logclient"
)
type ElasticcacheReleasePublicConnectionTask struct {
taskman.STask
}
func init() {
taskman.RegisterTask(ElasticcacheReleasePublicConnectionTask{})
}
func (self *ElasticcacheReleasePublicConnectionTask) taskFail(ctx context.Context, elasticcache *models.SElasticcache, reason string) {
elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CHANGING, reason)
db.OpsLog.LogEvent(elasticcache, db.ACT_DELOCATE_FAIL, reason, self.UserCred)
logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_DELOCATE, reason, self.UserCred, false)
notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason)
self.SetStageFailed(ctx, reason)
}
func (self *ElasticcacheReleasePublicConnectionTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
elasticcache := obj.(*models.SElasticcache)
region := elasticcache.GetRegion()
if region == nil {
self.taskFail(ctx, elasticcache, fmt.Sprintf("failed to find region for elastic cache %s", elasticcache.GetName()))
return
}
self.SetStage("OnElasticcacheReleasePublicConnectionComplete", nil)
if err := region.GetDriver().RequestElasticcacheReleasePublicConnection(ctx, self.GetUserCred(), elasticcache, self); err != nil {
self.OnElasticcacheReleasePublicConnectionCompleteFailed(ctx, elasticcache, err.Error())
return
}
self.OnElasticcacheReleasePublicConnectionComplete(ctx, elasticcache, data)
return
}
func (self *ElasticcacheReleasePublicConnectionTask) OnElasticcacheReleasePublicConnectionComplete(ctx context.Context, elasticcache *models.SElasticcache, data jsonutils.JSONObject) {
elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_RUNNING, "")
logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_DELOCATE, "release public connection", self.UserCred, true)
self.SetStageComplete(ctx, nil)
}
func (self *ElasticcacheReleasePublicConnectionTask) OnElasticcacheReleasePublicConnectionCompleteFailed(ctx context.Context, elasticcache *models.SElasticcache, reason string) {
self.taskFail(ctx, elasticcache, reason)
}
@@ -439,10 +439,6 @@ func (self *SElasticcache) GetAttribute() (*SElasticcacheAttribute, error) {
}
func (self *SElasticcache) GetNetInfo() ([]SNetInfo, error) {
if self.netinfo != nil && len(self.netinfo) > 0 {
return self.netinfo, nil
}
params := make(map[string]string)
params["RegionId"] = self.region.RegionId
params["InstanceId"] = self.GetId()
@@ -457,6 +453,7 @@ func (self *SElasticcache) GetNetInfo() ([]SNetInfo, error) {
return self.netinfo, nil
}
// https://help.aliyun.com/document_detail/66742.html?spm=a2c4g.11186623.6.731.54c123d2P02qhk
func (self *SElasticcache) GetPublicNetInfo() (*SNetInfo, error) {
nets, err := self.GetNetInfo()
if err != nil {
@@ -464,7 +461,7 @@ func (self *SElasticcache) GetPublicNetInfo() (*SNetInfo, error) {
}
for i := range nets {
if nets[i].DBInstanceNetType == "2" && nets[i].IPType == "Public" {
if nets[i].IPType == "Public" {
return &nets[i], nil
}
}
@@ -170,7 +170,7 @@ func (self *SBaseManager) jsonRequest(request requests.IRequest) (http.Header, j
if err.Code == 499 && retry > 0 && request.GetMethod() == "GET" {
retry -= 1
time.Sleep(time.Second * time.Duration(MAX_RETRY-retry))
} else if (err.Code == 404 || strings.Index(err.Details, "could not be found") > 0) && request.GetMethod() != "POST" {
} else if (err.Code == 404 || strings.Contains(err.Details, "could not be found") || strings.Contains(err.Details, "does not exist")) && request.GetMethod() != "POST" {
return h, b, cloudprovider.ErrNotFound
} else {
return h, b, e