Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.21.12.1^2
zouap 3 years ago
parent
commit
696836fdfd
2 changed files with 16 additions and 9 deletions
  1. +2
    -1
      modules/storage/obs.go
  2. +14
    -8
      routers/repo/ai_model_manage.go

+ 2
- 1
modules/storage/obs.go View File

@@ -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


+ 14
- 8
routers/repo/ai_model_manage.go View File

@@ -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


Loading…
Cancel
Save