|
|
@@ -1,8 +1,6 @@ |
|
|
|
package repo |
|
|
|
|
|
|
|
import ( |
|
|
|
"code.gitea.io/gitea/modules/git" |
|
|
|
"code.gitea.io/gitea/modules/storage" |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"net/http" |
|
|
@@ -13,6 +11,9 @@ import ( |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/git" |
|
|
|
"code.gitea.io/gitea/modules/storage" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
"code.gitea.io/gitea/modules/auth" |
|
|
|
"code.gitea.io/gitea/modules/base" |
|
|
@@ -23,10 +24,10 @@ import ( |
|
|
|
) |
|
|
|
|
|
|
|
const ( |
|
|
|
tplCloudBrainIndex base.TplName = "repo/cloudbrain/index" |
|
|
|
tplCloudBrainNew base.TplName = "repo/cloudbrain/new" |
|
|
|
tplCloudBrainShow base.TplName = "repo/cloudbrain/show" |
|
|
|
tplCloudBrainShowModels base.TplName = "repo/cloudbrain/models/index" |
|
|
|
tplCloudBrainIndex base.TplName = "repo/cloudbrain/index" |
|
|
|
tplCloudBrainNew base.TplName = "repo/cloudbrain/new" |
|
|
|
tplCloudBrainShow base.TplName = "repo/cloudbrain/show" |
|
|
|
tplCloudBrainShowModels base.TplName = "repo/cloudbrain/models/index" |
|
|
|
) |
|
|
|
|
|
|
|
var ( |
|
|
@@ -89,13 +90,12 @@ func cutString(str string, lens int) string { |
|
|
|
|
|
|
|
func jobNamePrefixValid(s string) string { |
|
|
|
lowStr := strings.ToLower(s) |
|
|
|
re := regexp.MustCompile(`[^a-z0-9\\.\\-]+`) |
|
|
|
re := regexp.MustCompile(`[^a-z0-9_\\-]+`) |
|
|
|
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 |
|
|
@@ -103,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 { |
|
|
@@ -119,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 { |
|
|
@@ -134,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 |
|
|
@@ -162,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) |
|
|
|
} |
|
|
|
|
|
|
@@ -177,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 |
|
|
|
} |
|
|
@@ -185,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 |
|
|
|
} |
|
|
@@ -200,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 |
|
|
|
} |
|
|
@@ -223,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 |
|
|
|
} |
|
|
@@ -397,6 +412,38 @@ func CloudBrainShowModels(ctx *context.Context) { |
|
|
|
ctx.HTML(200, tplCloudBrainShowModels) |
|
|
|
} |
|
|
|
|
|
|
|
func GetPublicImages(ctx *context.Context) { |
|
|
|
|
|
|
|
getImages(ctx, cloudbrain.Public) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func GetCustomImages(ctx *context.Context) { |
|
|
|
|
|
|
|
getImages(ctx, cloudbrain.Custom) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func getImages(ctx *context.Context, imageType string) { |
|
|
|
log.Info("Get images begin") |
|
|
|
|
|
|
|
page := ctx.QueryInt("page") |
|
|
|
size := ctx.QueryInt("size") |
|
|
|
name := ctx.Query("name") |
|
|
|
getImagesResult, err := cloudbrain.GetImagesPageable(page, size, imageType, name) |
|
|
|
if err != nil { |
|
|
|
log.Error("Can not get images:%v", err) |
|
|
|
ctx.JSON(http.StatusOK, models.GetImagesPayload{ |
|
|
|
Count: 0, |
|
|
|
TotalPages: 0, |
|
|
|
ImageInfo: []*models.ImageInfo{}, |
|
|
|
}) |
|
|
|
} else { |
|
|
|
ctx.JSON(http.StatusOK, getImagesResult.Payload) |
|
|
|
} |
|
|
|
log.Info("Get images end") |
|
|
|
} |
|
|
|
|
|
|
|
func getModelDirs(jobName string, parentDir string) (string, error) { |
|
|
|
var req string |
|
|
|
modelActualPath := setting.JobPath + jobName + "/model/" |
|
|
@@ -413,7 +460,7 @@ func CloudBrainDownloadModel(ctx *context.Context) { |
|
|
|
parentDir := ctx.Query("parentDir") |
|
|
|
fileName := ctx.Query("fileName") |
|
|
|
jobName := ctx.Query("jobName") |
|
|
|
filePath := "jobs/" +jobName + "/model/" + parentDir |
|
|
|
filePath := "jobs/" + jobName + "/model/" + parentDir |
|
|
|
url, err := storage.Attachments.PresignedGetURL(filePath, fileName) |
|
|
|
if err != nil { |
|
|
|
log.Error("PresignedGetURL failed: %v", err.Error(), ctx.Data["msgID"]) |
|
|
|