| @@ -94,9 +94,8 @@ func jobNamePrefixValid(s string) string { | |||
| return re.ReplaceAllString(lowStr, "") | |||
| } | |||
| func CloudBrainNew(ctx *context.Context) { | |||
| func cloudBrainNewDataPrepare(ctx *context.Context) error{ | |||
| ctx.Data["PageIsCloudBrain"] = true | |||
| t := time.Now() | |||
| var jobName = jobNamePrefixValid(cutString(ctx.User.Name, 5)) + t.Format("2006010215") + strconv.Itoa(int(t.Unix()))[5:] | |||
| ctx.Data["job_name"] = jobName | |||
| @@ -104,7 +103,7 @@ func CloudBrainNew(ctx *context.Context) { | |||
| result, err := cloudbrain.GetImages() | |||
| if err != nil { | |||
| ctx.Data["error"] = err.Error() | |||
| log.Error("cloudbrain.GetImages failed:", err.Error(), ctx.Data["msgID"]) | |||
| log.Error("cloudbrain.GetImages failed:", err.Error(), ctx.Data["MsgID"]) | |||
| } | |||
| for i, payload := range result.Payload.ImageInfo { | |||
| @@ -120,7 +119,7 @@ func CloudBrainNew(ctx *context.Context) { | |||
| resultPublic, err := cloudbrain.GetPublicImages() | |||
| if err != nil { | |||
| ctx.Data["error"] = err.Error() | |||
| log.Error("cloudbrain.GetPublicImages failed:", err.Error(), ctx.Data["msgID"]) | |||
| log.Error("cloudbrain.GetPublicImages failed:", err.Error(), ctx.Data["MsgID"]) | |||
| } | |||
| for i, payload := range resultPublic.Payload.ImageInfo { | |||
| @@ -135,8 +134,8 @@ func CloudBrainNew(ctx *context.Context) { | |||
| attachs, err := models.GetAllUserAttachments(ctx.User.ID) | |||
| if err != nil { | |||
| ctx.ServerError("GetAllUserAttachments failed:", err) | |||
| return | |||
| log.Error("GetAllUserAttachments failed: %v", err, ctx.Data["MsgID"]) | |||
| return err | |||
| } | |||
| ctx.Data["attachments"] = attachs | |||
| @@ -163,6 +162,16 @@ func CloudBrainNew(ctx *context.Context) { | |||
| ctx.Data["resource_specs"] = cloudbrain.ResourceSpecs.ResourceSpec | |||
| ctx.Data["snn4imagenet_path"] = cloudbrain.Snn4imagenetMountPath | |||
| ctx.Data["is_snn4imagenet_enabled"] = setting.IsSnn4imagenetEnabled | |||
| return nil | |||
| } | |||
| func CloudBrainNew(ctx *context.Context) { | |||
| err := cloudBrainNewDataPrepare(ctx) | |||
| if err != nil { | |||
| ctx.ServerError("get new cloudbrain info failed", err) | |||
| return | |||
| } | |||
| ctx.HTML(200, tplCloudBrainNew) | |||
| } | |||
| @@ -178,7 +187,8 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { | |||
| resourceSpecId := form.ResourceSpecId | |||
| if jobType != string(models.JobTypeBenchmark) && jobType != string(models.JobTypeDebug) && jobType != string(models.JobTypeSnn4imagenet) { | |||
| log.Error("jobtype error:", jobType, ctx.Data["msgID"]) | |||
| log.Error("jobtype error:", jobType, ctx.Data["MsgID"]) | |||
| cloudBrainNewDataPrepare(ctx) | |||
| ctx.RenderWithErr("jobtype error", tplCloudBrainNew, &form) | |||
| return | |||
| } | |||
| @@ -186,11 +196,13 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { | |||
| _, err := models.GetCloudbrainByName(jobName) | |||
| if err == nil { | |||
| log.Error("the job name did already exist", ctx.Data["MsgID"]) | |||
| cloudBrainNewDataPrepare(ctx) | |||
| ctx.RenderWithErr("the job name did already exist", tplCloudBrainNew, &form) | |||
| return | |||
| } else { | |||
| if !models.IsErrJobNotExist(err) { | |||
| log.Error("system error, %v", err, ctx.Data["MsgID"]) | |||
| cloudBrainNewDataPrepare(ctx) | |||
| ctx.RenderWithErr("system error", tplCloudBrainNew, &form) | |||
| return | |||
| } | |||
| @@ -201,6 +213,7 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { | |||
| modelPath := setting.JobPath + jobName + cloudbrain.ModelMountPath | |||
| err = os.MkdirAll(modelPath, os.ModePerm) | |||
| if err != nil { | |||
| cloudBrainNewDataPrepare(ctx) | |||
| ctx.RenderWithErr(err.Error(), tplCloudBrainNew, &form) | |||
| return | |||
| } | |||
| @@ -224,6 +237,7 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { | |||
| err = cloudbrain.GenerateTask(ctx, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, snn4imagenetPath, jobType, gpuQueue, resourceSpecId) | |||
| if err != nil { | |||
| cloudBrainNewDataPrepare(ctx) | |||
| ctx.RenderWithErr(err.Error(), tplCloudBrainNew, &form) | |||
| return | |||
| } | |||