| @@ -34,12 +34,7 @@ type Cloudbrain struct { | |||||
| type CloudBrainLoginResult struct { | type CloudBrainLoginResult struct { | ||||
| Code string | Code string | ||||
| Msg string | Msg string | ||||
| Payload struct { | |||||
| UserID string `json:"userId"` | |||||
| RealName string `json:"realName"` | |||||
| Token string `json:"token"` | |||||
| Admin bool `json:"admin"` | |||||
| } | |||||
| Payload map[string]interface{} | |||||
| } | } | ||||
| type TaskRole struct { | type TaskRole struct { | ||||
| @@ -67,72 +62,13 @@ type CreateJobParams struct { | |||||
| type CreateJobResult struct { | type CreateJobResult struct { | ||||
| Code string | Code string | ||||
| Msg string | Msg string | ||||
| Payload struct { | |||||
| JobID string `json:"jobId"` | |||||
| } | |||||
| Payload map[string]interface{} | |||||
| } | } | ||||
| type GetJobResult struct { | type GetJobResult struct { | ||||
| Code string | |||||
| Msg string | |||||
| Payload struct { | |||||
| ID string `json:"Id"` | |||||
| Name string | |||||
| Platform string | |||||
| JobStatus struct { | |||||
| Username string | |||||
| State string | |||||
| SubState string `json:"subState"` | |||||
| ExecutionType string `json:"executionType"` | |||||
| Retries int8 `json:"retries"` | |||||
| CreatedTime int64 `json:"createdTime"` | |||||
| CompletedTime int64 `json:"completedTime"` | |||||
| AppID string `json:"appId"` | |||||
| AppProgress string `json:"appProgress"` | |||||
| AppTrackingURL string `json:"appTrackingUrl"` | |||||
| AppLaunchedTime int64 `json:"appLaunchedTime"` | |||||
| AppCompletedTime int64 `json:"appCompletedTime"` | |||||
| AppExitCode int8 `json:"appExitCode"` | |||||
| AppExitDiagnostics string `json:"appExitDiagnostics"` | |||||
| AppExitType string `json:"appExitType"` | |||||
| VirtualCluster string `json:"virtualCluster"` | |||||
| } `json:"jobStatus"` | |||||
| TaskRoles string `json:"taskRoles"` | |||||
| Resource struct { | |||||
| CPU int8 `json:"cpu"` | |||||
| Memory string | |||||
| GPU string `json:"nvidia.com/gpu"` | |||||
| } `json:"resource"` | |||||
| Config struct { | |||||
| Image string | |||||
| JobID string `json:"jobId"` | |||||
| GpuType string `json:"gpuType"` | |||||
| JobName string `json:"jobName"` | |||||
| JobType string `json:"jobType"` | |||||
| RetryCount int8 `json:"retryCount"` | |||||
| TaskRoles []struct { | |||||
| Name string `json:"name"` | |||||
| ShmMB int32 `json:"shmMB"` | |||||
| Command string `json:"command"` | |||||
| MemoryMB int64 `json:"memoryMB"` | |||||
| CPUNumber int8 `json:"cpuNumber"` | |||||
| GPUNumber int8 `json:"gpuNumber"` | |||||
| IsMainRole bool `json:"isMainRole"` | |||||
| TaskNumber int32 `json:"taskNumber"` | |||||
| NeedIBDevice bool `json:"needIBDevice"` | |||||
| MinFailedTaskCount int8 `json:"minFailedTaskCount"` | |||||
| MinSucceededTaskCount int8 `json:"minSucceededTaskCount"` | |||||
| } `json:"taskRoles"` | |||||
| } | |||||
| Userinfo struct { | |||||
| User string | |||||
| OrgID string `json:"org_id"` | |||||
| } | |||||
| } | |||||
| Code string `json:"code"` | |||||
| Msg string `json:"msg"` | |||||
| Payload map[string]interface{} `json:"payload"` | |||||
| } | } | ||||
| type CloudbrainsOptions struct { | type CloudbrainsOptions struct { | ||||
| @@ -43,11 +43,12 @@ func GenerateTask(ctx *context.Context, image, command string) error { | |||||
| return errors.New(jobResult.Msg) | return errors.New(jobResult.Msg) | ||||
| } | } | ||||
| var jobID = jobResult.Payload["jobId"].(string) | |||||
| err = models.CreateCloudbrain(&models.Cloudbrain{ | err = models.CreateCloudbrain(&models.Cloudbrain{ | ||||
| Status: int32(models.JobWaiting), | Status: int32(models.JobWaiting), | ||||
| UserID: ctx.User.ID, | UserID: ctx.User.ID, | ||||
| RepoID: ctx.Repo.Repository.ID, | RepoID: ctx.Repo.Repository.ID, | ||||
| JobID: jobResult.Payload.JobID, | |||||
| JobID: jobID, | |||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| @@ -51,7 +51,7 @@ func loginCloudbrain() error { | |||||
| return fmt.Errorf("%s: %s", loginResult.Msg, res.String()) | return fmt.Errorf("%s: %s", loginResult.Msg, res.String()) | ||||
| } | } | ||||
| TOKEN = loginResult.Payload.Token | |||||
| TOKEN = loginResult.Payload["token"].(string) | |||||
| return nil | return nil | ||||
| } | } | ||||
| @@ -12,6 +12,7 @@ import ( | |||||
| const ( | const ( | ||||
| tplCloudBrainIndex base.TplName = "repo/cloudbrain/index" | tplCloudBrainIndex base.TplName = "repo/cloudbrain/index" | ||||
| tplCloudBrainNew base.TplName = "repo/cloudbrain/new" | tplCloudBrainNew base.TplName = "repo/cloudbrain/new" | ||||
| tplCloudBrainShow base.TplName = "repo/cloudbrain/show" | |||||
| ) | ) | ||||
| // MustEnableDataset check if repository enable internal cb | // MustEnableDataset check if repository enable internal cb | ||||
| @@ -70,3 +71,20 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { | |||||
| } | } | ||||
| ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain") | ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain") | ||||
| } | } | ||||
| func CloudBrainShow(ctx *context.Context) { | |||||
| ctx.Data["PageIsCloudBrain"] = true | |||||
| var jobID = ctx.Params(":jobid") | |||||
| var result, err = cloudbrain.GetJob(jobID) | |||||
| if err != nil { | |||||
| ctx.Data["error"] = err.Error() | |||||
| } | |||||
| if result != nil { | |||||
| ctx.Data["result"] = result | |||||
| } | |||||
| ctx.Data["jobID"] = jobID | |||||
| ctx.HTML(200, tplCloudBrainShow) | |||||
| } | |||||
| @@ -873,6 +873,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| m.Group("/cloudbrain", func() { | m.Group("/cloudbrain", func() { | ||||
| m.Get("", reqRepoCloudBrainReader, repo.CloudBrainIndex) | m.Get("", reqRepoCloudBrainReader, repo.CloudBrainIndex) | ||||
| m.Get("/:jobid", reqRepoCloudBrainReader, repo.CloudBrainShow) | |||||
| m.Get("/create", reqRepoCloudBrainWriter, repo.CloudBrainNew) | m.Get("/create", reqRepoCloudBrainWriter, repo.CloudBrainNew) | ||||
| m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateCloudBrainForm{}), repo.CloudBrainCreate) | m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateCloudBrainForm{}), repo.CloudBrainCreate) | ||||
| }, context.RepoRef()) | }, context.RepoRef()) | ||||
| @@ -0,0 +1,18 @@ | |||||
| {{template "base/head" .}} | |||||
| <div class="repository new repo"> | |||||
| {{template "repo/header" .}} | |||||
| <div class="ui middle very relaxed page grid"> | |||||
| <div class="column"> | |||||
| {{template "base/alert" .}} | |||||
| <div id="id">{{.jobID}}</div> | |||||
| <hr> | |||||
| <p>err</p> | |||||
| <div>{{.error}}</div> | |||||
| <hr> | |||||
| <p>result</p> | |||||
| <div>{{.result}}</div> | |||||
| <hr> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| {{template "base/footer" .}} | |||||