Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.21.12.1^2
zouap 3 years ago
parent
commit
76ea89deeb
3 changed files with 81 additions and 47 deletions
  1. +25
    -6
      modules/storage/obs.go
  2. +53
    -41
      routers/repo/ai_model_manage.go
  3. +3
    -0
      routers/repo/modelarts.go

+ 25
- 6
modules/storage/obs.go View File

@@ -174,6 +174,25 @@ func ObsModelDownload(JobName string, fileName string) (io.ReadCloser, error) {
}
}

func ObsCopyFile(srcBucket string, srcKeyName string, destBucket string, destKeyName string) error {
input := &obs.CopyObjectInput{}
input.Bucket = srcBucket
input.Key = srcKeyName
input.CopySourceBucket = destBucket
input.CopySourceKey = destKeyName
_, err := ObsCli.CopyObject(input)
if err == nil {
log.Info("copy success,destBuckName:%s, destkeyname:%s", destBucket, destKeyName)
} else {
if obsError, ok := err.(obs.ObsError); ok {
log.Info(obsError.Code)
log.Info(obsError.Message)
}
return err
}
return nil
}

func GetObsListObject(jobName, parentDir string) ([]FileInfo, error) {
input := &obs.ListObjectsInput{}
input.Bucket = setting.Bucket
@@ -184,12 +203,12 @@ func GetObsListObject(jobName, parentDir string) ([]FileInfo, error) {
for _, val := range output.Contents {
str1 := strings.Split(val.Key, "/")
var isDir bool
var fileName,nextParentDir string
var fileName, nextParentDir string
if strings.HasSuffix(val.Key, "/") {
fileName = str1[len(str1)-2]
isDir = true
nextParentDir = fileName
if fileName == parentDir || (fileName + "/") == setting.OutPutPath {
if fileName == parentDir || (fileName+"/") == setting.OutPutPath {
continue
}
} else {
@@ -198,10 +217,10 @@ func GetObsListObject(jobName, parentDir string) ([]FileInfo, error) {
}

fileInfo := FileInfo{
ModTime: val.LastModified.Format("2006-01-02 15:04:05"),
ModTime: val.LastModified.Format("2006-01-02 15:04:05"),
FileName: fileName,
Size: val.Size,
IsDir:isDir,
Size: val.Size,
IsDir: isDir,
ParenDir: nextParentDir,
}
fileInfos = append(fileInfos, fileInfo)
@@ -242,7 +261,7 @@ func GetObsCreateSignedUrl(jobName, parentDir, fileName string) (string, error)
input := &obs.CreateSignedUrlInput{}
input.Bucket = setting.Bucket
input.Key = strings.TrimPrefix(path.Join(setting.TrainJobModelPath, jobName, setting.OutPutPath, parentDir, fileName), "/")
input.Expires = 60 * 60
input.Method = obs.HttpMethodGet



+ 53
- 41
routers/repo/ai_model_manage.go View File

@@ -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.")

}

+ 3
- 0
routers/repo/modelarts.go View File

@@ -1107,6 +1107,9 @@ func TrainJobShowModels(ctx *context.Context) {

jobID := ctx.Params(":jobid")
parentDir := ctx.Query("parentDir")

log.Info("parentDir=" + parentDir)

dirArray := strings.Split(parentDir, "/")
task, err := models.GetCloudbrainByJobID(jobID)
if err != nil {


Loading…
Cancel
Save