Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/342 Reviewed-by: avadesian <xuchx@pcl.ac.cn>tags/v1.21.9.1^2
@@ -7,7 +7,7 @@ import ( | |||||
type CreateModelArtsForm struct { | type CreateModelArtsForm struct { | ||||
JobName string `form:"job_name" binding:"Required"` | JobName string `form:"job_name" binding:"Required"` | ||||
Attachment string `form:"attachment" binding:"Required"` | |||||
Attachment string `form:"attachment"` | |||||
Description string `form:"description"` | Description string `form:"description"` | ||||
} | } | ||||
@@ -1,13 +1,13 @@ | |||||
package modelarts | package modelarts | ||||
import ( | import ( | ||||
"code.gitea.io/gitea/modules/setting" | |||||
"encoding/json" | |||||
"path" | |||||
"code.gitea.io/gitea/models" | "code.gitea.io/gitea/models" | ||||
"code.gitea.io/gitea/modules/context" | "code.gitea.io/gitea/modules/context" | ||||
"code.gitea.io/gitea/modules/log" | "code.gitea.io/gitea/modules/log" | ||||
"code.gitea.io/gitea/modules/setting" | |||||
"code.gitea.io/gitea/modules/storage" | |||||
"encoding/json" | |||||
"path" | |||||
) | ) | ||||
const ( | const ( | ||||
@@ -25,7 +25,27 @@ var ( | |||||
) | ) | ||||
func GenerateTask(ctx *context.Context, jobName, uuid, description string) error { | func GenerateTask(ctx *context.Context, jobName, uuid, description string) error { | ||||
dataActualPath := setting.Bucket + "/" + setting.BasePath + path.Join(uuid[0:1], uuid[1:2]) + "/" + uuid + "/" | |||||
var dataActualPath string | |||||
if uuid != "" { | |||||
dataActualPath = setting.Bucket + "/" + setting.BasePath + path.Join(uuid[0:1], uuid[1:2]) + "/" + uuid + "/" | |||||
} else { | |||||
userPath := setting.UserBasePath + ctx.User.Name + "/" | |||||
isExist, err := storage.ObsHasObject(userPath) | |||||
if err != nil { | |||||
log.Error("ObsHasObject failed:%v", err.Error(), ctx.Data["MsgID"]) | |||||
return err | |||||
} | |||||
if !isExist { | |||||
if err = storage.ObsCreateObject(userPath); err != nil { | |||||
log.Error("ObsCreateObject failed:%v", err.Error(), ctx.Data["MsgID"]) | |||||
return err | |||||
} | |||||
} | |||||
dataActualPath = setting.Bucket + "/" + userPath | |||||
} | |||||
if poolInfos == nil { | if poolInfos == nil { | ||||
json.Unmarshal([]byte(setting.PoolInfos), &poolInfos) | json.Unmarshal([]byte(setting.PoolInfos), &poolInfos) | ||||
} | } | ||||
@@ -463,7 +463,7 @@ var ( | |||||
Bucket string | Bucket string | ||||
Location string | Location string | ||||
BasePath string | BasePath string | ||||
//RealPath string | |||||
UserBasePath string | |||||
//modelarts config | //modelarts config | ||||
ModelArtsHost string | ModelArtsHost string | ||||
@@ -473,10 +473,10 @@ var ( | |||||
ModelArtsUsername string | ModelArtsUsername string | ||||
ModelArtsPassword string | ModelArtsPassword string | ||||
ModelArtsDomain string | ModelArtsDomain string | ||||
ProfileID string | |||||
PoolInfos string | |||||
Flavor string | |||||
FlavorInfos string | |||||
ProfileID string | |||||
PoolInfos string | |||||
Flavor string | |||||
FlavorInfos string | |||||
) | ) | ||||
// DateLang transforms standard language locale name to corresponding value in datetime plugin. | // DateLang transforms standard language locale name to corresponding value in datetime plugin. | ||||
@@ -1177,6 +1177,7 @@ func NewContext() { | |||||
Bucket = sec.Key("BUCKET").MustString("testopendata") | Bucket = sec.Key("BUCKET").MustString("testopendata") | ||||
Location = sec.Key("LOCATION").MustString("cn-south-222") | Location = sec.Key("LOCATION").MustString("cn-south-222") | ||||
BasePath = sec.Key("BASE_PATH").MustString("attachment/") | BasePath = sec.Key("BASE_PATH").MustString("attachment/") | ||||
UserBasePath = sec.Key("BASE_PATH_USER").MustString("users/") | |||||
sec = Cfg.Section("modelarts") | sec = Cfg.Section("modelarts") | ||||
ModelArtsHost = sec.Key("ENDPOINT").MustString("112.95.163.80") | ModelArtsHost = sec.Key("ENDPOINT").MustString("112.95.163.80") | ||||
@@ -143,3 +143,17 @@ func ObsGetPreSignedUrl(uuid, fileName string) (string, error) { | |||||
return output.SignedUrl, nil | return output.SignedUrl, nil | ||||
} | } | ||||
func ObsCreateObject(path string) error { | |||||
input := &obs.PutObjectInput{} | |||||
input.Bucket = setting.Bucket | |||||
input.Key = path | |||||
_, err := ObsCli.PutObject(input) | |||||
if err != nil { | |||||
log.Error("PutObject failed:", err.Error()) | |||||
return err | |||||
} | |||||
return nil | |||||
} |
@@ -112,14 +112,15 @@ | |||||
<input name="job_name" id="cloudbrain_job_name" placeholder="任务名称" value="{{.job_name}}" tabindex="3" autofocus required maxlength="255"> | <input name="job_name" id="cloudbrain_job_name" placeholder="任务名称" value="{{.job_name}}" tabindex="3" autofocus required maxlength="255"> | ||||
</div> | </div> | ||||
<div class="inline required field"> | |||||
<div class="inline field"> | |||||
<label>数据集</label> | <label>数据集</label> | ||||
<select id="cloudbrain_dataset" class="ui search dropdown" placeholder="选择数据集" style='width:385px' name="attachment"> | |||||
<input type="text" list="cloudbrain_dataset" placeholder="选择数据集" name="attachment" autofocus maxlength="36"> | |||||
<datalist id="cloudbrain_dataset" class="ui search" style='width:385px' name="attachment"> | |||||
{{range .attachments}} | {{range .attachments}} | ||||
<option name="attachment" value="{{.UUID}}">{{.Attachment.Name}}</option> | <option name="attachment" value="{{.UUID}}">{{.Attachment.Name}}</option> | ||||
{{end}} | {{end}} | ||||
</select> | |||||
</datalist> | |||||
</div> | </div> | ||||
<div class="inline required field"> | <div class="inline required field"> | ||||