| @@ -384,6 +384,12 @@ type GetNotebookResult struct { | |||||
| EndTime string | EndTime string | ||||
| Rank int `json:"rank"` //rank of instance in queue | Rank int `json:"rank"` //rank of instance in queue | ||||
| } `json:"queuing_info"` | } `json:"queuing_info"` | ||||
| Spec struct{ | |||||
| Annotations struct{ | |||||
| TargetDomain string `json:"target_domain"` | |||||
| Url string `json:"url"` | |||||
| } `json:"annotations"` | |||||
| } `json:"spec"` | |||||
| } | } | ||||
| type GetTokenParams struct { | type GetTokenParams struct { | ||||
| @@ -441,6 +447,12 @@ type NotebookActionResult struct { | |||||
| PreviousState string `json:"previous_state"` | PreviousState string `json:"previous_state"` | ||||
| } | } | ||||
| type NotebookGetJobTokenResult struct { | |||||
| ErrorCode string `json:"error_code"` | |||||
| ErrorMsg string `json:"error_msg"` | |||||
| Token string `json:"token"` | |||||
| } | |||||
| type NotebookDelResult struct { | type NotebookDelResult struct { | ||||
| InstanceID string `json:"instance_id"` | InstanceID string `json:"instance_id"` | ||||
| } | } | ||||
| @@ -196,11 +196,11 @@ func (s datasetMetaSearch) Less(i, j int) bool { | |||||
| return s.ID[i] < s.ID[j] | return s.ID[i] < s.ID[j] | ||||
| } | } | ||||
| func GetDatasetAttachments(rels ...*Dataset) (err error) { | |||||
| return getDatasetAttachments(x, rels...) | |||||
| func GetDatasetAttachments(typeCloudBrain int ,rels ...*Dataset) (err error) { | |||||
| return getDatasetAttachments(x, typeCloudBrain, rels...) | |||||
| } | } | ||||
| func getDatasetAttachments(e Engine, rels ...*Dataset) (err error) { | |||||
| func getDatasetAttachments(e Engine, typeCloudBrain int, rels ...*Dataset) (err error) { | |||||
| if len(rels) == 0 { | if len(rels) == 0 { | ||||
| return | return | ||||
| } | } | ||||
| @@ -223,6 +223,7 @@ func getDatasetAttachments(e Engine, rels ...*Dataset) (err error) { | |||||
| err = e. | err = e. | ||||
| Asc("dataset_id"). | Asc("dataset_id"). | ||||
| In("dataset_id", sortedRels.ID). | In("dataset_id", sortedRels.ID). | ||||
| And("type = ?", typeCloudBrain). | |||||
| Find(&attachments, Attachment{}) | Find(&attachments, Attachment{}) | ||||
| if err != nil { | if err != nil { | ||||
| return err | return err | ||||
| @@ -151,6 +151,8 @@ sendjob: | |||||
| goto sendjob | goto sendjob | ||||
| } | } | ||||
| log.Info(string(res.Body())) | |||||
| var response models.NotebookResult | var response models.NotebookResult | ||||
| err = json.Unmarshal(res.Body(), &response) | err = json.Unmarshal(res.Body(), &response) | ||||
| if err != nil { | if err != nil { | ||||
| @@ -244,3 +246,42 @@ sendjob: | |||||
| return &result, nil | return &result, nil | ||||
| } | } | ||||
| func GetJobToken(jobID string) (*models.NotebookGetJobTokenResult, error) { | |||||
| checkSetting() | |||||
| client := getRestyClient() | |||||
| var result models.NotebookGetJobTokenResult | |||||
| retry := 0 | |||||
| sendjob: | |||||
| res, err := client.R(). | |||||
| SetHeader("Content-Type", "application/json"). | |||||
| SetAuthToken(TOKEN). | |||||
| SetResult(&result). | |||||
| Get(HOST + "/v1/" + setting.ProjectID + urlNotebook + "/" + jobID + "/token") | |||||
| if err != nil { | |||||
| return &result, fmt.Errorf("resty GetJobToken: %v", err) | |||||
| } | |||||
| if res.StatusCode() == http.StatusUnauthorized && retry < 1 { | |||||
| retry++ | |||||
| _ = getToken() | |||||
| goto sendjob | |||||
| } | |||||
| 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("GetJobToken failed(%s): %s", response.ErrorCode, response.ErrorMsg) | |||||
| return &result, fmt.Errorf("GetJobToken failed(%s): %s", response.ErrorCode, response.ErrorMsg) | |||||
| } | |||||
| return &result, nil | |||||
| } | |||||
| @@ -9,6 +9,7 @@ import ( | |||||
| "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/modelarts" | "code.gitea.io/gitea/modules/modelarts" | ||||
| "net/http" | |||||
| ) | ) | ||||
| func GetModelArtsTask(ctx *context.APIContext) { | func GetModelArtsTask(ctx *context.APIContext) { | ||||
| @@ -23,18 +24,15 @@ func GetModelArtsTask(ctx *context.APIContext) { | |||||
| ctx.NotFound(err) | ctx.NotFound(err) | ||||
| return | return | ||||
| } | } | ||||
| _, err = modelarts.GetJob(jobID) | |||||
| result, err := modelarts.GetJob(jobID) | |||||
| if err != nil { | if err != nil { | ||||
| ctx.NotFound(err) | ctx.NotFound(err) | ||||
| return | return | ||||
| } | } | ||||
| //ctx.JSON(http.StatusOK, map[string]interface{}{ | |||||
| // "JobID": result.Config.JobID, | |||||
| // "JobStatus": result.JobStatus.State, | |||||
| // "SubState": result.JobStatus.SubState, | |||||
| // "CreatedTime": time.Unix(result.JobStatus.CreatedTime/1000, 0).Format("2006-01-02 15:04:05"), | |||||
| // "CompletedTime": time.Unix(result.JobStatus.CompletedTime/1000, 0).Format("2006-01-02 15:04:05"), | |||||
| //}) | |||||
| ctx.JSON(http.StatusOK, map[string]interface{}{ | |||||
| "JobID": jobID, | |||||
| "JobStatus": result.Status, | |||||
| }) | |||||
| } | } | ||||
| @@ -49,7 +49,7 @@ func DatasetIndex(ctx *context.Context) { | |||||
| ctx.NotFound("GetDatasetByRepo", err) | ctx.NotFound("GetDatasetByRepo", err) | ||||
| return | return | ||||
| } | } | ||||
| err = models.GetDatasetAttachments(dataset) | |||||
| err = models.GetDatasetAttachments(ctx.QueryInt("type"), dataset) | |||||
| if err != nil { | if err != nil { | ||||
| ctx.ServerError("GetDatasetAttachments", err) | ctx.ServerError("GetDatasetAttachments", err) | ||||
| return | return | ||||
| @@ -152,10 +152,25 @@ func ModelArtsDebug(ctx *context.Context) { | |||||
| return | return | ||||
| } | } | ||||
| result, err := modelarts.GetJob(jobID) | |||||
| if err != nil { | |||||
| ctx.RenderWithErr(err.Error(), tplModelArtsIndex, nil) | |||||
| return | |||||
| } | |||||
| res, err := modelarts.GetJobToken(jobID) | |||||
| if err != nil { | |||||
| ctx.RenderWithErr(err.Error(), tplModelArtsIndex, nil) | |||||
| return | |||||
| } | |||||
| urlPrefix := result.Spec.Annotations.TargetDomain + "/modelarts/internal/hub/notebook/user/" + task.JobID | |||||
| //https://console.ai.pcl.cn/modelarts/internal/hub/notebook/user/DE-afcdf674-6489-11eb-bfe7-0255ac100057/lab | //https://console.ai.pcl.cn/modelarts/internal/hub/notebook/user/DE-afcdf674-6489-11eb-bfe7-0255ac100057/lab | ||||
| //debugUrl := setting.DebugServerHost + "jpylab_" + task.JobID + "_" + task.SubTaskName | //debugUrl := setting.DebugServerHost + "jpylab_" + task.JobID + "_" + task.SubTaskName | ||||
| //debugUrl := setting.ModelArtsHost + "/modelarts/internal/hub/notebook/user/" + task.JobID + "/lab" | //debugUrl := setting.ModelArtsHost + "/modelarts/internal/hub/notebook/user/" + task.JobID + "/lab" | ||||
| debugUrl := "https://console.ai.pcl.cn/modelarts/internal/hub/notebook/user/" + task.JobID + "/lab" | |||||
| //debugUrl := "https://console.ai.pcl.cn/modelarts/internal/hub/notebook/user/" + task.JobID + "/lab" | |||||
| debugUrl := urlPrefix + "?token=" + res.Token | |||||
| ctx.Redirect(debugUrl) | ctx.Redirect(debugUrl) | ||||
| } | } | ||||