Browse Source

Merge branch 'modelarts' of git.pcl.ac.cn:yoyoyard/opendata into modelarts

tags/v1.21.12.1
Gitea 4 years ago
parent
commit
5c196c73eb
5 changed files with 116 additions and 39 deletions
  1. +8
    -0
      models/cloudbrain.go
  2. +39
    -0
      modules/modelarts/resty.go
  3. +17
    -3
      routers/repo/modelarts.go
  4. +0
    -2
      templates/explore/dataset_list.tmpl
  5. +52
    -34
      templates/repo/modelarts/show.tmpl

+ 8
- 0
models/cloudbrain.go View File

@@ -353,7 +353,9 @@ type GetNotebookResult struct {
Description string `json:"description"`
Status string `json:"status"`
CreationTimestamp string `json:"creation_timestamp"`
CreateTime string
LatestUpdateTimestamp string `json:"latest_update_timestamp"`
LatestUpdateTime string
Profile struct {
ID string `json:"id"`
Name string `json:"name"`
@@ -376,8 +378,10 @@ type GetNotebookResult struct {
DeType string `json:"de_type"`
Status string `json:"status"`
BeginTimestamp int `json:"begin_timestamp"`//time of instance begin in queue
BeginTime string
RemainTime int `json:"remain_time"` //remain time of instance
EndTimestamp int `json:"end_timestamp"` //
EndTime string
Rank int `json:"rank"` //rank of instance in queue
} `json:"queuing_info"`
}
@@ -437,6 +441,10 @@ type NotebookActionResult struct {
PreviousState string `json:"previous_state"`
}

type NotebookDelResult struct {
InstanceID string `json:"instance_id"`
}

func Cloudbrains(opts *CloudbrainsOptions) ([]*Cloudbrain, int64, error) {
sess := x.NewSession()
defer sess.Close()


+ 39
- 0
modules/modelarts/resty.go View File

@@ -205,3 +205,42 @@ sendjob:

return &result, nil
}

func DelJob(jobID string) (*models.NotebookDelResult, error) {
checkSetting()
client := getRestyClient()
var result models.NotebookDelResult

retry := 0

sendjob:
res, err := client.R().
SetHeader("Content-Type", "application/json").
SetAuthToken(TOKEN).
SetResult(&result).
Delete(HOST + "/v1/" + setting.ProjectID + urlNotebook + "/" + jobID)

if err != nil {
return &result, fmt.Errorf("resty DelJob: %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("DelJob failed(%s): %s", response.ErrorCode, response.ErrorMsg)
return &result, fmt.Errorf("DelJob failed(%s): %s", response.ErrorCode, response.ErrorMsg)
}

return &result, nil
}

+ 17
- 3
routers/repo/modelarts.go View File

@@ -3,6 +3,7 @@ package repo
import (
"code.gitea.io/gitea/modules/modelarts"
"errors"
"github.com/unknwon/com"
"strconv"
"time"

@@ -129,10 +130,18 @@ func ModelArtsShow(ctx *context.Context) {
ctx.RenderWithErr(err.Error(), tplModelArtsIndex, nil)
return
}

createTime, _ := com.StrTo(result.CreationTimestamp).Int64()
result.CreateTime = time.Unix(int64(createTime/1000), 0).Format("2006-01-02 15:04:05")
endTime, _ := com.StrTo(result.LatestUpdateTimestamp).Int64()
result.LatestUpdateTime = time.Unix(int64(endTime/1000), 0).Format("2006-01-02 15:04:05")
result.QueuingInfo.BeginTime = time.Unix(int64(result.QueuingInfo.BeginTimestamp/1000), 0).Format("2006-01-02 15:04:05")
result.QueuingInfo.EndTime = time.Unix(int64(result.QueuingInfo.EndTimestamp/1000), 0).Format("2006-01-02 15:04:05")
}

ctx.Data["task"] = task
ctx.Data["jobID"] = jobID
ctx.Data["result"] = result
ctx.HTML(200, tplModelArtsShow)
}

@@ -176,9 +185,7 @@ func ModelArtsStop(ctx *context.Context) {
return
}

log.Info("pre(%s), current(%s)", res.PreviousState, res.CurrentStatus)

task.Status = string(models.JobStopped)
task.Status = res.CurrentStatus
err = models.UpdateJob(task)
if err != nil {
ctx.ServerError("UpdateJob failed", err)
@@ -202,6 +209,13 @@ func ModelArtsDel(ctx *context.Context) {
return
}

_, err = modelarts.DelJob(jobID)
if err != nil {
log.Error("DelJob(%s) failed:%v", task.JobName, err.Error())
ctx.ServerError("DelJob failed", err)
return
}

err = models.DeleteJob(task)
if err != nil {
ctx.ServerError("DeleteJob failed", err)


+ 0
- 2
templates/explore/dataset_list.tmpl View File

@@ -31,9 +31,7 @@
<div class="ui right metas">
<span class="text grey">{{svg "octicon-tasklist" 16}} {{$.i18n.Tr (printf "dataset.task.%s" .Task)}}</span>
<span class="text grey">{{svg "octicon-tag" 16}}{{$.i18n.Tr (printf "dataset.category.%s" .Category)}}</span>
{{if ne .DownloadTimes 0}}
<span class="text grey">{{svg "octicon-flame" 16}} {{.DownloadTimes}}</span>
{{end}}
</div>
</div>
<div class="description">


+ 52
- 34
templates/repo/modelarts/show.tmpl View File

@@ -16,81 +16,99 @@
</div>
<div class="ui green segment">
<p>任务结果:</p>
{{with .taskRes}}
{{range .TaskStatuses}}
{{with .result}}
<table class="ui celled striped table">
<tbody>
<tr>
<td class="four wide"> 状态 </td>
<td> {{.State}} </td>
<td> {{.Status}} </td>
</tr>
<tr>
<td> 开始时间 </td>
<td>{{.StartTime}}</td>
<td>{{.CreateTime}}</td>
</tr>
<tr>
<td> 结束时间 </td>
<td>{{.FinishedTime}}</td>
</tr>
<tr>
<td> ExitCode </td>
<td>{{.ExitCode}}</td>
</tr>
<tr>
<td> 退出信息 </td>
<td>{{.ExitDiagnostics| nl2br}}</td>
<td> 最后更新时间 </td>
<td>{{.LatestUpdateTime}}</td>
</tr>
</tbody>
</table>
{{end}}
{{end}}
</div>
<div class="ui blue segment">
{{with .result}}
<table class="ui celled striped table">
<thead>
<tr> <th colspan="2"> 硬件信息 </th> </tr>
<tr> <th colspan="2"> 配置信息 </th> </tr>
</thead>
<tbody>
<tr>
<td class="four wide"> 开发环境类型 </td>
<td>{{.Profile.DeType}}</td>
</tr>
<tr>
<td> 硬件类型 </td>
<td>{{.Profile.FlavorType}}</td>
</tr>
</tbody>
</table>

<table class="ui celled striped table">
<thead>
<tr> <th colspan="2"> 机器规格详情 </th> </tr>
</thead>
<tbody>
<tr>
<td class="four wide"> CPU </td>
<td>{{.Resource.CPU}}</td>
<td class="four wide"> 机器规格 </td>
<td> {{.Flavor}} </td>
</tr>
<tr>
<td> 规格名称 </td>
<td>{{.FlavorDetails.Name}}</td>
</tr>
<tr>
<td> 规格销售状态 </td>
<td>{{.FlavorDetails.Status}}</td>
</tr>
<tr>
<td> 排队个数 </td>
<td>{{.FlavorDetails.QueuingNum}}</td>
</tr>
<tr>
<td> Memory </td>
<td>{{.Resource.Memory}}</td>
<td> 排到队的剩余时间(秒) </td>
<td>{{.FlavorDetails.QueueLeftTime}}</td>
</tr>
<tr>
<td> NvidiaComGpu </td>
<td>{{.Resource.NvidiaComGpu}}</td>
<td> 自动停止时间(秒) </td>
<td>{{.FlavorDetails.Duration}}</td>
</tr>
</tbody>
</table>

<table class="ui celled striped table">
<table class="ui celled striped table" {{if eq .QueuingInfo.RemainTime 0}}hidden{{end}}>
<thead>
<tr> <th colspan="2"> 调试信息 </th> </tr>
<tr> <th colspan="2"> 排队信息 </th> </tr>
</thead>
<tbody>
<tr>
<td class="four wide"> 状态 </td>
<td> {{.Platform}} </td>
<td> 实例状态 </td>
<td>{{.QueuingInfo.Status}}</td>
</tr>
<tr>
<td> 开始时间 </td>
<td>{{.JobStatus.StartTime}}</td>
<td> 实例排队的开始时间 </td>
<td>{{.QueuingInfo.BeginTime}}</td>
</tr>
<tr>
<td> 结束时间 </td>
<td>{{.JobStatus.EndTime}}</td>
<td> 排到队的剩余时间(秒) </td>
<td>{{.QueuingInfo.RemainTime}}</td>
</tr>
<tr>
<td> ExitCode </td>
<td>{{.JobStatus.AppExitCode}}</td>
<td> 实例排队的预计停止时间 </td>
<td>{{.QueuingInfo.EndTime}}</td>
</tr>
<tr>
<td> 退出信息 </td>
<td>{{.JobStatus.AppExitDiagnostics | nl2br}}</td>
<td> 实例在队列中的排位 </td>
<td>{{.QueuingInfo.Rank}}</td>
</tr>
</tbody>
</table>


Loading…
Cancel
Save