|
|
@@ -13,6 +13,7 @@ import ( |
|
|
|
"code.gitea.io/gitea/modules/context" |
|
|
|
"code.gitea.io/gitea/modules/log" |
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
"code.gitea.io/gitea/modules/storage" |
|
|
|
uuid "github.com/satori/go.uuid" |
|
|
|
) |
|
|
|
|
|
|
@@ -55,16 +56,9 @@ func SaveModel(ctx *context.Context) { |
|
|
|
} |
|
|
|
} |
|
|
|
cloudType = aiTask.Cloudbrain.Type |
|
|
|
//download model zip |
|
|
|
if cloudType == models.TypeCloudBrainOne { |
|
|
|
modelPath, modelSize, err = downloadModelFromCloudBrainOne(id, aiTask.JobName, "") |
|
|
|
if err != nil { |
|
|
|
log.Info("download model from CloudBrainOne faild." + err.Error()) |
|
|
|
ctx.Error(500, fmt.Sprintf("%v", err)) |
|
|
|
return |
|
|
|
} |
|
|
|
} else if cloudType == models.TypeCloudBrainTwo { |
|
|
|
modelPath, err = downloadModelFromCloudBrainTwo(id) |
|
|
|
//download model zip //train type |
|
|
|
if cloudType == models.TypeCloudBrainTrainJob { |
|
|
|
modelPath, modelSize, err = downloadModelFromCloudBrainTwo(id, aiTask.JobName, "") |
|
|
|
if err == nil { |
|
|
|
|
|
|
|
} else { |
|
|
@@ -94,6 +88,55 @@ func SaveModel(ctx *context.Context) { |
|
|
|
log.Info("save model end.") |
|
|
|
} |
|
|
|
|
|
|
|
func downloadModelFromCloudBrainTwo(modelUUID string, jobName string, parentDir string) (string, int64, error) { |
|
|
|
dataActualPath := setting.Bucket + "/" + |
|
|
|
"aimodels/" + |
|
|
|
models.AttachmentRelativePath(modelUUID) + |
|
|
|
"/" |
|
|
|
|
|
|
|
models, err := storage.GetObsListObject(jobName, parentDir) |
|
|
|
if err != nil { |
|
|
|
log.Info("get TrainJobListModel failed:", err) |
|
|
|
return "", 0, err |
|
|
|
} |
|
|
|
if len(models) == 0 { |
|
|
|
return "", 0, errors.New("cannot create model, as model is empty.") |
|
|
|
} |
|
|
|
|
|
|
|
for _, modelFile := range models { |
|
|
|
log.Info("copy file, bucket=%s, src keyname=%s,dest keyname=%s", setting.Bucket, modelFile.ParenDir+modelFile.FileName, dataActualPath+modelFile.FileName) |
|
|
|
// err := storage.ObsCopyFile(setting.Bucket, modelFile.ParenDir+modelFile.FileName, setting.Bucket, dataActualPath+modelFile.FileName) |
|
|
|
// if err != nil { |
|
|
|
// log.Info("copy failed.") |
|
|
|
// } |
|
|
|
} |
|
|
|
|
|
|
|
return dataActualPath, 0, nil |
|
|
|
} |
|
|
|
|
|
|
|
func DeleteModel(ctx *context.Context) { |
|
|
|
log.Info("delete model start.") |
|
|
|
id := ctx.Query("ID") |
|
|
|
err := models.DeleteModelById(id) |
|
|
|
if err != nil { |
|
|
|
ctx.JSON(500, err.Error()) |
|
|
|
} else { |
|
|
|
ctx.JSON(200, map[string]string{ |
|
|
|
"result_code": "0", |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func DownloadModel(ctx *context.Context) { |
|
|
|
log.Info("download model start.") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func ShowModelInfo(ctx *context.Context) { |
|
|
|
log.Info("ShowModelInfo.") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func downloadModelFromCloudBrainOne(modelUUID string, jobName string, parentDir string) (string, int64, error) { |
|
|
|
|
|
|
|
modelActualPath := setting.Attachment.Minio.RealPath + |
|
|
@@ -161,34 +204,3 @@ func zipDir(dir, zipFile string) error { |
|
|
|
} |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func downloadModelFromCloudBrainTwo(modelUUID string) (string, error) { |
|
|
|
dataActualPath := setting.Bucket + "/" + |
|
|
|
"aimodels/" + |
|
|
|
models.AttachmentRelativePath(modelUUID) + |
|
|
|
"/" |
|
|
|
return dataActualPath, nil |
|
|
|
} |
|
|
|
|
|
|
|
func DeleteModel(ctx *context.Context) { |
|
|
|
log.Info("delete model start.") |
|
|
|
id := ctx.Query("ID") |
|
|
|
err := models.DeleteModelById(id) |
|
|
|
if err != nil { |
|
|
|
ctx.JSON(500, err.Error()) |
|
|
|
} else { |
|
|
|
ctx.JSON(200, map[string]string{ |
|
|
|
"result_code": "0", |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func DownloadModel(ctx *context.Context) { |
|
|
|
log.Info("download model start.") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func ShowModelInfo(ctx *context.Context) { |
|
|
|
log.Info("ShowModelInfo.") |
|
|
|
|
|
|
|
} |