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