Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/643 Reviewed-by: liuzx <liuzx@pcl.ac.cn>tags/v1.21.12.1
| @@ -181,17 +181,28 @@ func GetObsListObject(jobName, parentDir string) ([]FileInfo, error) { | |||||
| output, err := ObsCli.ListObjects(input) | output, err := ObsCli.ListObjects(input) | ||||
| fileInfos := make([]FileInfo, 0) | fileInfos := make([]FileInfo, 0) | ||||
| if err == nil { | if err == nil { | ||||
| for index, val := range output.Contents { | |||||
| log.Info("Content[%d]-OwnerId:%s, ETag:%s, Key:%s, LastModified:%s, Size:%d\n", | |||||
| index, val.Owner.ID, val.ETag, val.Key, val.LastModified, val.Size) | |||||
| for _, val := range output.Contents { | |||||
| str1 := strings.Split(val.Key, "/") | str1 := strings.Split(val.Key, "/") | ||||
| fileName := str1[len(str1)-1] | |||||
| log.Info("", fileName) | |||||
| var isDir bool | |||||
| var fileName,nextParentDir string | |||||
| if strings.HasSuffix(val.Key, "/") { | |||||
| fileName = str1[len(str1)-2] | |||||
| isDir = true | |||||
| nextParentDir = fileName | |||||
| if fileName == parentDir || (fileName + "/") == setting.OutPutPath { | |||||
| continue | |||||
| } | |||||
| } else { | |||||
| fileName = str1[len(str1)-1] | |||||
| isDir = false | |||||
| } | |||||
| fileInfo := FileInfo{ | fileInfo := FileInfo{ | ||||
| ModTime: val.LastModified.Format("2006-01-02 15:04:05"), | ModTime: val.LastModified.Format("2006-01-02 15:04:05"), | ||||
| FileName: fileName, | FileName: fileName, | ||||
| Size: val.Size, | Size: val.Size, | ||||
| IsDir:false, | |||||
| IsDir:isDir, | |||||
| ParenDir: nextParentDir, | |||||
| } | } | ||||
| fileInfos = append(fileInfos, fileInfo) | fileInfos = append(fileInfos, fileInfo) | ||||
| } | } | ||||
| @@ -227,20 +238,17 @@ func ObsGenMultiPartSignedUrl(uuid string, uploadId string, partNumber int, file | |||||
| return output.SignedUrl, nil | return output.SignedUrl, nil | ||||
| } | } | ||||
| func GetObsCreateSignedUrl(uuid string, uploadId string, partNumber int, fileName string) (string, error) { | |||||
| func GetObsCreateSignedUrl(jobName, parentDir, fileName string) (string, error) { | |||||
| input := &obs.CreateSignedUrlInput{} | input := &obs.CreateSignedUrlInput{} | ||||
| input.Bucket = setting.Bucket | input.Bucket = setting.Bucket | ||||
| input.Key = strings.TrimPrefix(path.Join(setting.BasePath, path.Join(uuid[0:1], uuid[1:2], uuid, fileName)), "/") | |||||
| input.Key = strings.TrimPrefix(path.Join(setting.TrainJobModelPath, jobName, setting.OutPutPath, parentDir, fileName), "/") | |||||
| input.Expires = 60 * 60 | input.Expires = 60 * 60 | ||||
| input.Method = obs.HttpMethodPut | |||||
| input.QueryParams = map[string]string{ | |||||
| "partNumber": com.ToStr(partNumber, 10), | |||||
| "uploadId": uploadId, | |||||
| //"partSize": com.ToStr(partSize,10), | |||||
| } | |||||
| input.Method = obs.HttpMethodGet | |||||
| reqParams := make(map[string]string) | |||||
| reqParams["response-content-disposition"] = "attachment; filename=\"" + fileName + "\"" | |||||
| input.QueryParams = reqParams | |||||
| output, err := ObsCli.CreateSignedUrl(input) | output, err := ObsCli.CreateSignedUrl(input) | ||||
| if err != nil { | if err != nil { | ||||
| log.Error("CreateSignedUrl failed:", err.Error()) | log.Error("CreateSignedUrl failed:", err.Error()) | ||||
| @@ -583,34 +583,6 @@ func CloudBrainDownloadModel(ctx *context.Context) { | |||||
| http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently) | http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently) | ||||
| } | } | ||||
| func TrainJobDownloadModel(ctx *context.Context) { | |||||
| JobName := ctx.Query("JobName") | |||||
| fileName := ctx.Query("file_name") | |||||
| body, err := storage.ObsModelDownload(JobName, fileName) | |||||
| if err != nil { | |||||
| log.Info("download error.") | |||||
| } else { | |||||
| defer body.Close() | |||||
| ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+fileName) | |||||
| ctx.Resp.Header().Set("Content-Type", "application/octet-stream") | |||||
| p := make([]byte, 1024) | |||||
| var readErr error | |||||
| var readCount int | |||||
| // 读取对象内容 | |||||
| for { | |||||
| readCount, readErr = body.Read(p) | |||||
| if readCount > 0 { | |||||
| ctx.Resp.Write(p[:readCount]) | |||||
| //fmt.Printf("%s", p[:readCount]) | |||||
| } | |||||
| if readErr != nil { | |||||
| break | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| func GetRate(ctx *context.Context) { | func GetRate(ctx *context.Context) { | ||||
| var jobID = ctx.Params(":jobid") | var jobID = ctx.Params(":jobid") | ||||
| job, err := models.GetCloudbrainByJobID(jobID) | job, err := models.GetCloudbrainByJobID(jobID) | ||||
| @@ -1086,3 +1086,16 @@ func TrainJobShowModels(ctx *context.Context) { | |||||
| ctx.Data["JobID"] = jobID | ctx.Data["JobID"] = jobID | ||||
| ctx.HTML(200, tplModelArtsTrainJobShowModels) | ctx.HTML(200, tplModelArtsTrainJobShowModels) | ||||
| } | } | ||||
| func TrainJobDownloadModel(ctx *context.Context) { | |||||
| parentDir := ctx.Query("parentDir") | |||||
| fileName := ctx.Query("fileName") | |||||
| jobName := ctx.Query("jobName") | |||||
| url, err := storage.GetObsCreateSignedUrl(jobName, parentDir, fileName) | |||||
| if err != nil { | |||||
| log.Error("GetObsCreateSignedUrl failed: %v", err.Error(), ctx.Data["msgID"]) | |||||
| ctx.ServerError("GetObsCreateSignedUrl", err) | |||||
| return | |||||
| } | |||||
| http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently) | |||||
| } | |||||
| @@ -6,7 +6,7 @@ | |||||
| <td class="name four wide"> | <td class="name four wide"> | ||||
| <span class="truncate"> | <span class="truncate"> | ||||
| <span class="octicon octicon-file-directory"></span> | <span class="octicon octicon-file-directory"></span> | ||||
| <a class="title" href="{{if .IsDir}}{{$.RepoLink}}/cloudbrain/{{$.JobID}}/models?parentDir={{.ParenDir}}{{else}}{{$.RepoLink}}/cloudbrain/{{$.JobID}}/download_model?parentDir={{.ParenDir}}&fileName={{.FileName}}&jobName={{$.task.JobName}}{{end}}"> | |||||
| <a class="title" href="{{if .IsDir}}{{$.RepoLink}}/modelarts/train-job/{{$.JobID}}/models?parentDir={{.ParenDir}}{{else}}{{$.RepoLink}}/modelarts/train-job/{{$.JobID}}/download_model?parentDir={{.ParenDir}}&fileName={{.FileName}}&jobName={{$.task.JobName}}{{end}}"> | |||||
| <span class="fitted">{{if .IsDir}} {{svg "octicon-file-directory" 16}}{{else}}{{svg "octicon-file" 16}}{{end}}</span> {{.FileName}} | <span class="fitted">{{if .IsDir}} {{svg "octicon-file-directory" 16}}{{else}}{{svg "octicon-file" 16}}{{end}}</span> {{.FileName}} | ||||
| </a> | </a> | ||||
| </span> | </span> | ||||
| @@ -16,7 +16,7 @@ | |||||
| <div class="row"> | <div class="row"> | ||||
| <div class="ui sixteen wide column"> | <div class="ui sixteen wide column"> | ||||
| <div class="dir list"> | <div class="dir list"> | ||||
| {{template "repo/cloudbrain/models/dir_list" .}} | |||||
| {{template "repo/modelarts/trainjob/models/dir_list" .}} | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| </div> | </div> | ||||