| @@ -119,7 +119,12 @@ type GetJobResult struct { | |||
| type GetImagesResult struct { | |||
| Code string `json:"code"` | |||
| Msg string `json:"msg"` | |||
| Payload map[string]*ImageInfo `json:"payload"` | |||
| Payload GetImagesPayload `json:"payload"` | |||
| } | |||
| type GetImagesPayload struct { | |||
| Count int `json:"count"` | |||
| ImageInfo []*ImageInfo `json:"rows"` | |||
| } | |||
| type CloudbrainsOptions struct { | |||
| @@ -255,6 +260,7 @@ type ImageInfo struct { | |||
| Provider string `json:"provider"` | |||
| Createtime string `json:"createtime"` | |||
| Remark string `json:"remark"` | |||
| IsPublic int `json:"isPublic"` | |||
| PlaceView string | |||
| } | |||
| @@ -55,7 +55,6 @@ func GenerateTask(ctx *context.Context, jobName, uuid string) error { | |||
| RepoID: ctx.Repo.Repository.ID, | |||
| JobID: jobResult.ID, | |||
| JobName: jobName, | |||
| SubTaskName: subTaskName, | |||
| JobType: string(models.JobTypeDebug), | |||
| Type: models.TypeCloudBrainTwo, | |||
| }) | |||
| @@ -2,6 +2,7 @@ package modelarts | |||
| import ( | |||
| "code.gitea.io/gitea/modules/log" | |||
| "crypto/tls" | |||
| "fmt" | |||
| "net/http" | |||
| @@ -21,11 +22,12 @@ const ( | |||
| urlGetToken = "/v3/auth/tokens" | |||
| urlNotebook = "/demanager/instances" | |||
| urlQuaryNotebook = "/demanager/instances" | |||
| urlQueryNotebook = "/demanager/instances" | |||
| ) | |||
| func getRestyClient() *resty.Client { | |||
| if restyClient == nil { | |||
| restyClient = resty.New() | |||
| restyClient.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}) | |||
| } | |||
| return restyClient | |||
| } | |||
| @@ -67,10 +69,13 @@ func getToken() error { | |||
| }, | |||
| } | |||
| log.Info("params:", params) | |||
| res, err := client.R(). | |||
| SetHeader("Content-Type", "application/json"). | |||
| SetBody(params). | |||
| Post(HOST + urlGetToken) | |||
| Post(setting.IamHost + urlGetToken) | |||
| log.Info("", res.Request.Body) | |||
| if err != nil { | |||
| return fmt.Errorf("resty getToken: %s", err) | |||
| } | |||
| @@ -80,6 +85,7 @@ func getToken() error { | |||
| } | |||
| TOKEN = res.Header().Get("X-Subject-Token") | |||
| log.Info(TOKEN) | |||
| return nil | |||
| } | |||
| @@ -459,6 +459,7 @@ var ( | |||
| //modelarts config | |||
| ModelArtsHost string | |||
| IamHost string | |||
| ProjectID string | |||
| ProjectName string | |||
| ModelArtsUsername string | |||
| @@ -1159,6 +1160,7 @@ func NewContext() { | |||
| sec = Cfg.Section("modelarts") | |||
| ModelArtsHost = sec.Key("ENDPOINT").MustString("112.95.163.80") | |||
| IamHost = sec.Key("IAMHOST").MustString("112.95.163.80") | |||
| ProjectID = sec.Key("PROJECT_ID").MustString("") | |||
| ProjectName = sec.Key("PROJECT_NAME").MustString("") | |||
| ModelArtsUsername = sec.Key("USERNAME").MustString("") | |||
| @@ -852,6 +852,9 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
| m.Group("/cloudbrain", func() { | |||
| m.Get("/:jobid", repo.GetCloudbrainTask) | |||
| }, reqRepoReader(models.UnitTypeCloudBrain)) | |||
| m.Group("/modelarts", func() { | |||
| m.Get("/:jobid", repo.GetModelArtsTask) | |||
| }, reqRepoReader(models.UnitTypeCloudBrain)) | |||
| }, repoAssignment()) | |||
| }) | |||
| @@ -0,0 +1,40 @@ | |||
| // Copyright 2016 The Gogs Authors. All rights reserved. | |||
| // Copyright 2018 The Gitea Authors. All rights reserved. | |||
| // Use of this source code is governed by a MIT-style | |||
| // license that can be found in the LICENSE file. | |||
| package repo | |||
| import ( | |||
| "code.gitea.io/gitea/models" | |||
| "code.gitea.io/gitea/modules/context" | |||
| "code.gitea.io/gitea/modules/modelarts" | |||
| ) | |||
| func GetModelArtsTask(ctx *context.APIContext) { | |||
| var ( | |||
| err error | |||
| ) | |||
| jobID := ctx.Params(":jobid") | |||
| repoID := ctx.Repo.Repository.ID | |||
| _, err = models.GetRepoCloudBrainByJobID(repoID, jobID) | |||
| if err != nil { | |||
| ctx.NotFound(err) | |||
| return | |||
| } | |||
| _, err = modelarts.GetJob(jobID) | |||
| if err != nil { | |||
| ctx.NotFound(err) | |||
| 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"), | |||
| //}) | |||
| } | |||
| @@ -88,17 +88,18 @@ func CloudBrainNew(ctx *context.Context) { | |||
| result, err := cloudbrain.GetImages() | |||
| if err != nil { | |||
| ctx.Data["error"] = err.Error() | |||
| log.Error("cloudbrain.GetImages failed:", err.Error()) | |||
| } | |||
| for i, payload := range result.Payload { | |||
| if strings.HasPrefix(result.Payload[i].Place, "192.168") { | |||
| result.Payload[i].PlaceView = payload.Place[strings.Index(payload.Place, "/"):len(payload.Place)] | |||
| for i, payload := range result.Payload.ImageInfo { | |||
| if strings.HasPrefix(result.Payload.ImageInfo[i].Place, "192.168") { | |||
| result.Payload.ImageInfo[i].PlaceView = payload.Place[strings.Index(payload.Place, "/"):len(payload.Place)] | |||
| } else { | |||
| result.Payload[i].PlaceView = payload.Place | |||
| result.Payload.ImageInfo[i].PlaceView = payload.Place | |||
| } | |||
| } | |||
| ctx.Data["images"] = result.Payload | |||
| ctx.Data["images"] = result.Payload.ImageInfo | |||
| attachs, err := models.GetAllUserAttachments(ctx.User.ID) | |||
| if err != nil { | |||
| @@ -266,15 +266,6 @@ | |||
| </span> | |||
| </div> | |||
| <!-- 评分 --> | |||
| <div class="one wide column"> | |||
| <div class="ui text center clipboard"> | |||
| <a class="title" onclick="stop(this)" href="{{if and (ne .Status "WAITING") (eq .JobType "BENCHMARK")}}{{$.Link}}/{{.JobID}}/benchmark{{else}}javascript:void(0);{{end}}" style="{{if and (ne .Status "WAITING") (eq .JobType "BENCHMARK")}}{{else}}color:#CCCCCC{{end}}"> | |||
| <span class="fitted">评分</span> | |||
| </a> | |||
| </div> | |||
| </div> | |||
| <!-- 删除镜像 --> | |||
| <div class="one wide column"> | |||
| <div class="ui text center clipboard"> | |||
| @@ -304,10 +295,6 @@ | |||
| </div> | |||
| </div> | |||
| <!-- 接收结果 --> | |||
| <iframe src="" frameborder="0" name="iframeContent" style="display: none;"></iframe> | |||
| <a class="imageBtn" style="{{if not .CanDebug}}color:#CCCCCC;cursor:pointer;pointer-events:none;{{end}}; font-size:16px; font-weight:bold" value="{{.CanDebug}}">提交镜像</a> | |||
| <!-- 镜像列表弹窗 --> | |||
| <div id="imageModal" class="modal" style="display: none;"> | |||
| <div class="modal-content"> | |||
| @@ -430,7 +417,7 @@ | |||
| return | |||
| } | |||
| $.get(`/api/v1/repos/${repoPath}/cloudbrain/${jobID}`, (data) => { | |||
| $.get(`/api/v1/repos/${repoPath}/modelarts/${jobID}`, (data) => { | |||
| const jobID = data.JobID | |||
| const status = data.JobStatus | |||
| $('#' + jobID).text(status) | |||