|
|
@@ -253,15 +253,8 @@ func CloudBrainRestart(ctx *context.Context) { |
|
|
|
var errorMsg = "" |
|
|
|
var status = "" |
|
|
|
|
|
|
|
task := ctx.Cloudbrain |
|
|
|
for { |
|
|
|
task, err := models.GetCloudbrainByJobID(jobID) |
|
|
|
if err != nil { |
|
|
|
log.Error("GetCloudbrainByJobID(%s) failed:%v", jobID, err.Error(), ctx.Data["MsgID"]) |
|
|
|
resultCode = "-1" |
|
|
|
errorMsg = "system error" |
|
|
|
break |
|
|
|
} |
|
|
|
|
|
|
|
if task.Status != string(models.JobStopped) && task.Status != string(models.JobSucceeded) && task.Status != string(models.JobFailed) { |
|
|
|
log.Error("the job(%s) is not stopped", task.JobName, ctx.Data["MsgID"]) |
|
|
|
resultCode = "-1" |
|
|
@@ -374,29 +367,14 @@ func CloudBrainDebug(ctx *context.Context) { |
|
|
|
} |
|
|
|
|
|
|
|
func CloudBrainCommitImage(ctx *context.Context, form auth.CommitImageCloudBrainForm) { |
|
|
|
var jobID = ctx.Params(":jobid") |
|
|
|
if !ctx.IsSigned { |
|
|
|
log.Error("the user has not signed in") |
|
|
|
ctx.Error(http.StatusForbidden, "", "the user has not signed in") |
|
|
|
return |
|
|
|
} |
|
|
|
task, err := models.GetCloudbrainByJobID(jobID) |
|
|
|
if err != nil { |
|
|
|
ctx.JSON(200, map[string]string{ |
|
|
|
"result_code": "-1", |
|
|
|
"error_msg": "GetCloudbrainByJobID failed", |
|
|
|
}) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
err = cloudbrain.CommitImage(jobID, models.CommitImageParams{ |
|
|
|
Ip: task.ContainerIp, |
|
|
|
TaskContainerId: task.ContainerID, |
|
|
|
err := cloudbrain.CommitImage(ctx.Cloudbrain.JobID, models.CommitImageParams{ |
|
|
|
Ip: ctx.Cloudbrain.ContainerIp, |
|
|
|
TaskContainerId: ctx.Cloudbrain.ContainerID, |
|
|
|
ImageDescription: form.Description, |
|
|
|
ImageTag: form.Tag, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
log.Error("CommitImage(%s) failed:%v", task.JobName, err.Error(), ctx.Data["msgID"]) |
|
|
|
log.Error("CommitImage(%s) failed:%v", ctx.Cloudbrain.JobName, err.Error(), ctx.Data["msgID"]) |
|
|
|
ctx.JSON(200, map[string]string{ |
|
|
|
"result_code": "-1", |
|
|
|
"error_msg": "CommitImage failed", |
|
|
@@ -416,15 +394,8 @@ func CloudBrainStop(ctx *context.Context) { |
|
|
|
var errorMsg = "" |
|
|
|
var status = "" |
|
|
|
|
|
|
|
task := ctx.Cloudbrain |
|
|
|
for { |
|
|
|
task, err := models.GetCloudbrainByJobID(jobID) |
|
|
|
if err != nil { |
|
|
|
log.Error("GetCloudbrainByJobID(%s) failed:%v", task.JobName, err, ctx.Data["msgID"]) |
|
|
|
resultCode = "-1" |
|
|
|
errorMsg = "system error" |
|
|
|
break |
|
|
|
} |
|
|
|
|
|
|
|
if task.Status == string(models.JobStopped) || task.Status == string(models.JobFailed) { |
|
|
|
log.Error("the job(%s) has been stopped", task.JobName, ctx.Data["msgID"]) |
|
|
|
resultCode = "-1" |
|
|
@@ -432,7 +403,7 @@ func CloudBrainStop(ctx *context.Context) { |
|
|
|
break |
|
|
|
} |
|
|
|
|
|
|
|
err = cloudbrain.StopJob(jobID) |
|
|
|
err := cloudbrain.StopJob(jobID) |
|
|
|
if err != nil { |
|
|
|
log.Error("StopJob(%s) failed:%v", task.JobName, err, ctx.Data["msgID"]) |
|
|
|
resultCode = "-1" |
|
|
@@ -542,12 +513,7 @@ func logErrorAndUpdateJobStatus(err error, taskInfo *models.Cloudbrain) { |
|
|
|
} |
|
|
|
|
|
|
|
func CloudBrainDel(ctx *context.Context) { |
|
|
|
var jobID = ctx.Params(":jobid") |
|
|
|
task, err := models.GetCloudbrainByJobID(jobID) |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("GetCloudbrainByJobID failed", err) |
|
|
|
return |
|
|
|
} |
|
|
|
task := ctx.Cloudbrain |
|
|
|
|
|
|
|
if task.Status != string(models.JobStopped) && task.Status != string(models.JobFailed) { |
|
|
|
log.Error("the job(%s) has not been stopped", task.JobName, ctx.Data["msgID"]) |
|
|
@@ -555,7 +521,7 @@ func CloudBrainDel(ctx *context.Context) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
err = models.DeleteJob(task) |
|
|
|
err := models.DeleteJob(task) |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("DeleteJob failed", err) |
|
|
|
return |
|
|
|