diff --git a/api/controller/service_action.go b/api/controller/service_action.go index decd145f6..697cd1617 100644 --- a/api/controller/service_action.go +++ b/api/controller/service_action.go @@ -20,12 +20,14 @@ package controller import ( "fmt" - "github.com/goodrain/rainbond/db/errors" "io/ioutil" "net/http" "os" "time" + "github.com/goodrain/rainbond/db/errors" + validator "github.com/thedevsaddam/govalidator" + "github.com/Sirupsen/logrus" "github.com/go-chi/chi" "github.com/goodrain/rainbond/api/handler" @@ -39,7 +41,6 @@ import ( "github.com/goodrain/rainbond/worker/discover/model" "github.com/jinzhu/gorm" "github.com/pquerna/ffjson/ffjson" - "github.com/thedevsaddam/govalidator" ) //TIMELAYOUT timelayout @@ -694,40 +695,26 @@ func (t *TenantStruct) DeployService(w http.ResponseWriter, r *http.Request) { // "$ref": "#/responses/commandResponse" // description: 统一返回格式 func (t *TenantStruct) UpgradeService(w http.ResponseWriter, r *http.Request) { - rules := validator.MapData{ - "deploy_version": []string{"required"}, - } - data, ok := httputil.ValidatorRequestMapAndErrorResponse(r, w, rules, nil) + var upgradeRequest api_model.UpgradeInfoRequestStruct + ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &upgradeRequest, nil) if !ok { + logrus.Errorf("start operation validate request body failure") return } tenantID := r.Context().Value(middleware.ContextKey("tenant_id")).(string) serviceID := r.Context().Value(middleware.ContextKey("service_id")).(string) - - sEvent, status, err := createEvent(getOrNilEventID(data), serviceID, "update", tenantID, data["deploy_version"].(string)) + sEvent, status, err := createEvent(upgradeRequest.EventID, serviceID, "update", tenantID, upgradeRequest.UpgradeVersion) handleStatus(status, err, w, r) if status != 0 { return } - eventID := sEvent.EventID + upgradeRequest.EventID = eventID logger := event.GetManager().GetLogger(eventID) defer event.CloseManager() - newDeployVersion := data["deploy_version"].(string) - //两个deploy version - upgradeTask := &model.RollingUpgradeTaskBody{ - TenantID: tenantID, - ServiceID: serviceID, - NewDeployVersion: newDeployVersion, - EventID: eventID, - } - if err := handler.GetServiceManager().ServiceUpgrade(upgradeTask); err != nil { - logger.Error("应用升级任务发送失败 "+err.Error(), map[string]string{"step": "callback", "status": "failure"}) - httputil.ReturnError(r, w, 500, fmt.Sprintf("service upgrade error, %v", err)) - return - } - logger.Info("应用升级任务发送成功 ", map[string]string{"step": "upgrade-service", "status": "starting"}) - httputil.ReturnSuccess(r, w, sEvent) + re := handler.GetOperationHandler().Upgrade(upgradeRequest) + logger.Info("The application upgrade task was sent successfully", map[string]string{"step": "upgrade-service", "status": "starting"}) + httputil.ReturnSuccess(r, w, re) } //CheckCode CheckCode diff --git a/api/handler/service_operation.go b/api/handler/service_operation.go index b7cf5a0e0..9e97331c7 100644 --- a/api/handler/service_operation.go +++ b/api/handler/service_operation.go @@ -248,6 +248,10 @@ func (o *OperationHandler) Upgrade(ru model.UpgradeInfoRequestStruct) (re Operat } } re.EventID = eventBody.EventID + // By default, the same version is updated + if ru.UpgradeVersion == "" { + ru.UpgradeVersion = services.DeployVersion + } version, err := db.GetManager().VersionInfoDao().GetVersionByDeployVersion(ru.UpgradeVersion, ru.ServiceID) if err != nil { logrus.Errorf("get service version by id %s version %s error, %s", ru.ServiceID, ru.UpgradeVersion, err.Error()) diff --git a/api/model/model.go b/api/model/model.go index edb96e4e5..255e03a2d 100644 --- a/api/model/model.go +++ b/api/model/model.go @@ -1488,6 +1488,7 @@ type BuildInfoRequestStruct struct { //UpgradeInfoRequestStruct - type UpgradeInfoRequestStruct struct { //UpgradeVersion The target version of the upgrade + //If empty, the same version is upgraded UpgradeVersion string `json:"upgrade_version"` //Event trace ID EventID string `json:"event_id"`