From 696836fdfde482dde77cb8c302a4588f536898e8 Mon Sep 17 00:00:00 2001 From: zouap Date: Fri, 5 Nov 2021 14:22:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- modules/storage/obs.go | 3 ++- routers/repo/ai_model_manage.go | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/modules/storage/obs.go b/modules/storage/obs.go index e78c07708..6636f0976 100755 --- a/modules/storage/obs.go +++ b/modules/storage/obs.go @@ -5,6 +5,7 @@ package storage import ( + "errors" "io" "path" "strconv" @@ -142,7 +143,7 @@ func ObsMultiPartUpload(uuid string, uploadId string, partNumber int, fileName s func ObsRemoveObject(bucket string, path string) error { log.Info("Bucket=" + bucket + " path=" + path) if len(path) == 0 { - return error.Error("path cannot be null.") + return errors.New("path canot be null.") } input := &obs.ListObjectsInput{} input.Bucket = bucket diff --git a/routers/repo/ai_model_manage.go b/routers/repo/ai_model_manage.go index 859a2f7b8..f3e1a4439 100644 --- a/routers/repo/ai_model_manage.go +++ b/routers/repo/ai_model_manage.go @@ -14,6 +14,10 @@ import ( uuid "github.com/satori/go.uuid" ) +const ( + Model_prefix = "aimodels/" +) + func SaveModelByParameters(jobId string, name string, version string, label string, description string, userId int64) error { aiTask, err := models.GetCloudbrainByJobID(jobId) if err != nil { @@ -89,8 +93,7 @@ func SaveModel(ctx *context.Context) { } func downloadModelFromCloudBrainTwo(modelUUID string, jobName string, parentDir string) (string, int64, error) { - dataActualPath := setting.Bucket + "/" + - "aimodels/" + + dataActualPath := setting.Bucket + "/" + Model_prefix + models.AttachmentRelativePath(modelUUID) + "/" @@ -105,7 +108,7 @@ func downloadModelFromCloudBrainTwo(modelUUID string, jobName string, parentDir var size int64 prefix := strings.TrimPrefix(path.Join(setting.TrainJobModelPath, jobName, setting.OutPutPath, parentDir), "/") + "/" for _, modelFile := range modelDbResult { - destKeyNamePrefix := "aimodels/" + models.AttachmentRelativePath(modelUUID) + "/" + destKeyNamePrefix := Model_prefix + models.AttachmentRelativePath(modelUUID) + "/" log.Info("copy file, bucket=" + setting.Bucket + ", src keyname=" + prefix + modelFile.FileName) log.Info("Dest key name=" + destKeyNamePrefix + modelFile.FileName) @@ -138,11 +141,14 @@ func DeleteModelByID(id string) error { model, err := models.QueryModelById(id) if err == nil { log.Info("bucket=" + setting.Bucket + " path=" + model.Path) - //err := storage.ObsRemoveObject(setting.Bucket, model.Path) - //if err != nil { - // log.Info("Failed to delete model. id=" + id) - // return err - //} + if strings.HasPrefix(model.Path, setting.Bucket+"/"+Model_prefix) { + err := storage.ObsRemoveObject(setting.Bucket, model.Path[len(setting.Bucket+"/"+Model_prefix):]) + if err != nil { + log.Info("Failed to delete model. id=" + id) + return err + } + } + return models.DeleteModelById(id) } return err