change rollback api impl

This commit is contained in:
barnett 2019-06-29 23:33:27 +08:00
parent 14c12e1dbd
commit 601f22783b
2 changed files with 8 additions and 32 deletions

View File

@ -737,42 +737,19 @@ func (t *TenantStruct) CheckCode(w http.ResponseWriter, r *http.Request) {
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
func (t *TenantStruct) RollBack(w http.ResponseWriter, r *http.Request) {
rules := validator.MapData{
"deploy_version": []string{"required"},
"operator": []string{},
}
data, ok := httputil.ValidatorRequestMapAndErrorResponse(r, w, rules, nil)
var rollbackRequest api_model.RollbackInfoRequestStruct
ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &rollbackRequest, 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, "rollback", tenantID, data["deploy_version"].(string))
handleStatus(status, err, w, r)
if status != 0 {
if rollbackRequest.ServiceID != serviceID {
httputil.ReturnError(r, w, 400, "rollback service id failure")
return
}
eventID := sEvent.EventID
logger := event.GetManager().GetLogger(eventID)
defer event.CloseManager()
rs := &api_model.RollbackStruct{
TenantID: tenantID,
ServiceID: serviceID,
EventID: eventID,
//todo
DeployVersion: data["deploy_version"].(string),
}
if _, ok := data["operator"]; ok {
rs.Operator = data["operator"].(string)
}
if err := handler.GetServiceManager().RollBack(rs); err != nil {
logger.Error("应用回滚任务发送失败 "+err.Error(), map[string]string{"step": "callback", "status": "failure"})
httputil.ReturnError(r, w, 500, fmt.Sprintf("check deploy version error, %v", err))
return
}
logger.Info("应用回滚任务发送成功 ", map[string]string{"step": "rollback-service", "status": "starting"})
httputil.ReturnSuccess(r, w, sEvent)
re := handler.GetOperationHandler().RollBack(rollbackRequest)
httputil.ReturnSuccess(r, w, re)
return
}

View File

@ -669,8 +669,7 @@ func MergeDir(fromdir, todir string) error {
//CreateVersionByTime create version number
func CreateVersionByTime() string {
now := time.Now()
re := fmt.Sprintf("%d%d%d%d%d%d", now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second())
return re
return now.Format("20060102150405")
}
// GetDirList get all lower level dir