@@ -314,6 +314,11 @@ type Location struct { | |||
Path string `json:"path"` | |||
} | |||
type NotebookResult struct { | |||
ErrorCode string `json:"error_code"` | |||
ErrorMsg string `json:"error_msg"` | |||
} | |||
type CreateNotebookResult struct { | |||
ErrorCode string `json:"error_code"` | |||
ErrorMsg string `json:"error_msg"` | |||
@@ -378,39 +383,39 @@ type GetNotebookResult struct { | |||
} | |||
type GetTokenParams struct { | |||
Auth Auth `json:auth` | |||
Auth Auth `json:"auth"` | |||
} | |||
type Auth struct { | |||
Identity Identity `json:identity` | |||
Scope Scope `json:scope` | |||
Identity Identity `json:"identity"` | |||
Scope Scope `json:"scope"` | |||
} | |||
type Scope struct { | |||
Project Project `json:project` | |||
Project Project `json:"project"` | |||
} | |||
type Project struct { | |||
Name string `json:name` | |||
Name string `json:"name"` | |||
} | |||
type Identity struct { | |||
Methods []string `json:"methods"` | |||
Password Password `json:password` | |||
Password Password `json:"password"` | |||
} | |||
type Password struct { | |||
User NotebookUser `json:user` | |||
User NotebookUser `json:"user"` | |||
} | |||
type NotebookUser struct { | |||
Name string `json:name` | |||
Name string `json:"name"` | |||
Password string `json:"password"` | |||
Domain Domain `json:domain` | |||
Domain Domain `json:"domain"` | |||
} | |||
type Domain struct { | |||
Name string `json:name` | |||
Name string `json:"name"` | |||
} | |||
const ( | |||
@@ -8,6 +8,7 @@ import ( | |||
type CreateModelArtsForm struct { | |||
JobName string `form:"job_name" binding:"Required"` | |||
Attachment string `form:"attachment" binding:"Required"` | |||
Description string `form:"description"` | |||
} | |||
func (f *CreateModelArtsForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { | |||
@@ -11,23 +11,21 @@ import ( | |||
const ( | |||
storageTypeOBS = "obs" | |||
autoStopDuration = 4 * 60 *60 | |||
autoStopDuration = 4 * 60 * 60 | |||
flavor = "modelarts.kat1.xlarge" | |||
profileID = "Python3-ascend910-arm" | |||
subTaskName = "task1" | |||
DataSetMountPath = "/home/ma-user/work" | |||
NotebookEnv = "Python3" | |||
NotebookType = "Ascend" | |||
FlavorInfo = "Ascend: 1*Ascend 910 CPU: 24 核 96GiB (modelarts.kat1.xlarge)" | |||
) | |||
func GenerateTask(ctx *context.Context, jobName, uuid 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]) + "/" | |||
jobResult, err := CreateJob(models.CreateNotebookParams{ | |||
JobName: jobName, | |||
Description:"", | |||
Description:description, | |||
ProfileID: profileID, | |||
Flavor: flavor, | |||
Spec: models.Spec{ | |||
@@ -45,7 +43,7 @@ func GenerateTask(ctx *context.Context, jobName, uuid string) error { | |||
}) | |||
if err != nil { | |||
log.Error("CreateJob failed:", err.Error()) | |||
log.Error("CreateJob failed: %v", err.Error()) | |||
return err | |||
} | |||
@@ -3,6 +3,7 @@ package modelarts | |||
import ( | |||
"code.gitea.io/gitea/modules/log" | |||
"crypto/tls" | |||
"encoding/json" | |||
"fmt" | |||
"net/http" | |||
@@ -39,7 +40,7 @@ func checkSetting() { | |||
err := getToken() | |||
if err != nil { | |||
log.Error("getToken falied:", err.Error()) | |||
log.Error("getToken failed:%v", err) | |||
} | |||
} | |||
@@ -69,15 +70,12 @@ func getToken() error { | |||
}, | |||
} | |||
log.Info("params:", params) | |||
res, err := client.R(). | |||
SetHeader("Content-Type", "application/json"). | |||
SetBody(params). | |||
Post(setting.IamHost + urlGetToken) | |||
log.Info("", res.Request.Body) | |||
if err != nil { | |||
return fmt.Errorf("resty getToken: %s", err) | |||
return fmt.Errorf("resty getToken: %v", err) | |||
} | |||
if res.StatusCode() != http.StatusCreated { | |||
@@ -85,7 +83,6 @@ func getToken() error { | |||
} | |||
TOKEN = res.Header().Get("X-Subject-Token") | |||
log.Info(TOKEN) | |||
return nil | |||
} | |||
@@ -115,9 +112,16 @@ sendjob: | |||
goto sendjob | |||
} | |||
if len(result.ErrorCode) != 0 { | |||
log.Error("CreateJob failed(%s): %s", result.ErrorCode, result.ErrorMsg) | |||
return &result, fmt.Errorf("CreateJob failed(%s): %s", result.ErrorCode, result.ErrorMsg) | |||
var response models.NotebookResult | |||
err = json.Unmarshal(res.Body(), &response) | |||
if err != nil { | |||
log.Error("json.Unmarshal failed: %s", err.Error()) | |||
return &result, fmt.Errorf("son.Unmarshal failed: %s", err.Error()) | |||
} | |||
if len(response.ErrorCode) != 0 { | |||
log.Error("CreateJob failed(%s): %s", response.ErrorCode, response.ErrorMsg) | |||
return &result, fmt.Errorf("CreateJob failed(%s): %s", response.ErrorCode, response.ErrorMsg) | |||
} | |||
return &result, nil | |||
@@ -147,8 +151,16 @@ sendjob: | |||
goto sendjob | |||
} | |||
if len(result.ErrorCode) != 0 { | |||
return &result, fmt.Errorf("CreateJob failed(%s): %s", result.ErrorCode, result.ErrorMsg) | |||
var response models.NotebookResult | |||
err = json.Unmarshal(res.Body(), &response) | |||
if err != nil { | |||
log.Error("json.Unmarshal failed: %s", err.Error()) | |||
return &result, fmt.Errorf("son.Unmarshal failed: %s", err.Error()) | |||
} | |||
if len(response.ErrorCode) != 0 { | |||
log.Error("GetJob failed(%s): %s", response.ErrorCode, response.ErrorMsg) | |||
return &result, fmt.Errorf("GetJob failed(%s): %s", response.ErrorCode, response.ErrorMsg) | |||
} | |||
return &result, nil | |||
@@ -179,8 +191,16 @@ sendjob: | |||
goto sendjob | |||
} | |||
if len(result.ErrorCode) != 0 { | |||
return &result, fmt.Errorf("CreateJob failed(%s): %s", result.ErrorCode, result.ErrorMsg) | |||
var response models.NotebookResult | |||
err = json.Unmarshal(res.Body(), &response) | |||
if err != nil { | |||
log.Error("json.Unmarshal failed: %s", err.Error()) | |||
return &result, fmt.Errorf("son.Unmarshal failed: %s", err.Error()) | |||
} | |||
if len(response.ErrorCode) != 0 { | |||
log.Error("StopJob failed(%s): %s", response.ErrorCode, response.ErrorMsg) | |||
return &result, fmt.Errorf("StopJob failed(%s): %s", response.ErrorCode, response.ErrorMsg) | |||
} | |||
return &result, nil | |||
@@ -92,11 +92,12 @@ func ModelArtsCreate(ctx *context.Context, form auth.CreateModelArtsForm) { | |||
ctx.Data["PageIsCloudBrain"] = true | |||
jobName := form.JobName | |||
uuid := form.Attachment | |||
description := form.Description | |||
//repo := ctx.Repo.Repository | |||
log.Info(uuid) | |||
err := modelarts.GenerateTask(ctx, jobName, uuid) | |||
err := modelarts.GenerateTask(ctx, jobName, uuid, description) | |||
if err != nil { | |||
ctx.RenderWithErr(err.Error(), tplModelArtsNew, &form) | |||
return | |||
@@ -139,6 +139,10 @@ | |||
<label>数据集存放路径</label> | |||
<input name="dataset_path" id="cloudbrain_dataset_path" value="{{.dataset_path}}" tabindex="3" autofocus required maxlength="255" readonly="readonly"> | |||
</div> | |||
<div class="inline field"> | |||
<label>描述</label> | |||
<input name="description" id="cloudbrain_description" tabindex="3" autofocus maxlength="255"> | |||
</div> | |||
<div class="inline field"> | |||
<label></label> | |||
<button class="ui green button" onclick="showmask()"> | |||