Browse Source

update

tags/v1.21.12.1
liuzx 4 years ago
parent
commit
4dda69d812
2 changed files with 92 additions and 59 deletions
  1. +3
    -3
      routers/api/v1/repo/modelarts.go
  2. +89
    -56
      routers/repo/modelarts.go

+ 3
- 3
routers/api/v1/repo/modelarts.go View File

@@ -250,7 +250,7 @@ func DelTrainJobVersion(ctx *context.APIContext) {
if page <= 0 {
page = 1
}
_, VersionListCount, err := models.CloudbrainsVersionList(&models.CloudbrainsOptions{
VersionListTasks, VersionListCount, err := models.CloudbrainsVersionList(&models.CloudbrainsOptions{
ListOptions: models.ListOptions{
Page: page,
PageSize: setting.UI.IssuePagingNum,
@@ -265,9 +265,9 @@ func DelTrainJobVersion(ctx *context.APIContext) {
return
}

//判断当前的任务是否是最新版本的,若是,将V0001设置为最新版本,若不是,最新版本不变,更改最新版本的版本数。
//判断当前的任务是否是最新版本,若是,将排序后的第一个版本设置为最新版本,若不是,最新版本不变,更改最新版本的版本数。
if task.IsLatestVersion == modelarts.IsLatestVersion {
err = models.SetVersionCountAndLatestVersionByJobIDAndVersionName(jobID, modelarts.InitFatherVersionName, VersionListCount, modelarts.IsLatestVersion)
err = models.SetVersionCountAndLatestVersionByJobIDAndVersionName(jobID, VersionListTasks[0].Cloudbrain.VersionName, VersionListCount, modelarts.IsLatestVersion)
if err != nil {
ctx.ServerError("UpdateJobVersionCount failed", err)
return


+ 89
- 56
routers/repo/modelarts.go View File

@@ -288,6 +288,17 @@ func TrainJobIndex(ctx *context.Context) {
return
}

// for i, task := range tasks {
// result, err := modelarts.GetTrainJob(task.JobID, strconv.FormatInt(task.VersionID, 10))
// if err != nil {
// log.Error("GetJob(%s) failed:%v", task.JobID, err.Error())
// return
// }
// // tasks[i].Status = modelarts.TransTrainJobStatus(result.Status)
// tasks[i].Status = result.Status
// tasks[i].Duration = result.Duration
// }

pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, 5)
pager.SetDefaultParams(ctx)
ctx.Data["Page"] = pager
@@ -957,11 +968,6 @@ func TrainJobShow(ctx *context.Context) {
ctx.Data["PageIsCloudBrain"] = true

var jobID = ctx.Params(":jobid")
task, err := models.GetCloudbrainByJobID(jobID)
if err != nil {
ctx.ServerError("GetCloudbrainByJobID faild", err)
return
}

repo := ctx.Repo.Repository
page := ctx.QueryInt("page")
@@ -996,56 +1002,56 @@ func TrainJobShow(ctx *context.Context) {
// return
// }

result, err := modelarts.GetTrainJob(jobID, strconv.FormatInt(task.VersionID, 10))
if err != nil {
log.Error("GetJob(%s) failed:%v", jobID, err.Error())
ctx.RenderWithErr(err.Error(), tplModelArtsTrainJobShow, nil)
return
}

if result != nil {
result.CreateTime = time.Unix(int64(result.LongCreateTime/1000), 0).Format("2006-01-02 15:04:05")
if result.Duration != 0 {
result.TrainJobDuration = addZero(result.Duration/3600000) + ":" + addZero(result.Duration%3600000/60000) + ":" + addZero(result.Duration%60000/1000)

} else {
result.TrainJobDuration = "00:00:00"
}
result.Status = modelarts.TransTrainJobStatus(result.IntStatus)
err = models.SetTrainJobStatusByJobID(jobID, result.Status, result.Duration, string(result.TrainJobDuration))
if err != nil {
ctx.ServerError("UpdateJob failed", err)
return
}
// result, err := modelarts.GetTrainJob(jobID, strconv.FormatInt(task.VersionID, 10))
// if err != nil {
// log.Error("GetJob(%s) failed:%v", jobID, err.Error())
// ctx.RenderWithErr(err.Error(), tplModelArtsTrainJobShow, nil)
// return
// }

result.DatasetName = task.DatasetName
}
// if result != nil {
// result.CreateTime = time.Unix(int64(result.LongCreateTime/1000), 0).Format("2006-01-02 15:04:05")
// if result.Duration != 0 {
// result.TrainJobDuration = addZero(result.Duration/3600000) + ":" + addZero(result.Duration%3600000/60000) + ":" + addZero(result.Duration%60000/1000)

// } else {
// result.TrainJobDuration = "00:00:00"
// }
// result.Status = modelarts.TransTrainJobStatus(result.IntStatus)
// err = models.SetTrainJobStatusByJobID(jobID, result.Status, result.Duration, string(result.TrainJobDuration))
// if err != nil {
// ctx.ServerError("UpdateJob failed", err)
// return
// }

// result.DatasetName = task.DatasetName
// }

resultLogFile, resultLog, err := trainJobGetLog(jobID)
if err != nil {
log.Error("trainJobGetLog(%s) failed:%v", jobID, err.Error())
ctx.RenderWithErr(err.Error(), tplModelArtsTrainJobShow, nil)
return
}
// resultLogFile, resultLog, err := trainJobGetLog(jobID)
// if err != nil {
// log.Error("trainJobGetLog(%s) failed:%v", jobID, err.Error())
// ctx.RenderWithErr(err.Error(), tplModelArtsTrainJobShow, nil)
// return
// }

ctx.Data["log_file_name"] = resultLogFile.LogFileList[0]
ctx.Data["log"] = resultLog
ctx.Data["task"] = task
// ctx.Data["log_file_name"] = resultLogFile.LogFileList[0]
// ctx.Data["log"] = resultLog
// ctx.Data["task"] = task
ctx.Data["jobID"] = jobID
ctx.Data["result"] = result
// ctx.Data["result"] = result
ctx.Data["version_list_task"] = VersionListTasks
ctx.Data["version_list_count"] = VersionListCount
ctx.HTML(http.StatusOK, tplModelArtsTrainJobShow)
}

func addZero(t int64) (m string) {
if t < 10 {
m = "0" + strconv.FormatInt(t, 10)
return m
} else {
return strconv.FormatInt(t, 10)
}
}
// func addZero(t int64) (m string) {
// if t < 10 {
// m = "0" + strconv.FormatInt(t, 10)
// return m
// } else {
// return strconv.FormatInt(t, 10)
// }
// }

func TrainJobGetLog(ctx *context.Context) {
ctx.Data["PageIsTrainJob"] = true
@@ -1103,25 +1109,52 @@ func trainJobGetLog(jobID string) (*models.GetTrainJobLogFileNamesResult, *model

func TrainJobDel(ctx *context.Context) {
var jobID = ctx.Params(":jobid")
task, err := models.GetCloudbrainByJobID(jobID)
repo := ctx.Repo.Repository
page := ctx.QueryInt("page")

if page <= 0 {
page = 1
}
VersionListTasks, _, err := models.CloudbrainsVersionList(&models.CloudbrainsOptions{
ListOptions: models.ListOptions{
Page: page,
PageSize: setting.UI.IssuePagingNum,
},
RepoID: repo.ID,
Type: models.TypeCloudBrainTwo,
JobType: string(models.JobTypeTrain),
JobID: jobID,
})
if err != nil {
log.Error("GetCloudbrainByJobID(%s) failed:%v", task.JobName, err.Error())
ctx.RenderWithErr(err.Error(), tplModelArtsTrainJobIndex, nil)
ctx.ServerError("get VersionListTasks failed", err)
return
}

for _, task := range VersionListTasks {
err = models.DeleteJobVersion(&task.Cloudbrain)
if err != nil {
ctx.ServerError("DeleteJobVersion failed", err)
return
}
}
_, err = modelarts.DelTrainJob(jobID)
if err != nil {
log.Error("DelTrainJob(%s) failed:%v", task.JobName, err.Error())
log.Error("DelTrainJob(%s) failed:%v", jobID, err.Error())
ctx.RenderWithErr(err.Error(), tplModelArtsTrainJobIndex, nil)
return
}

err = models.DeleteJob(task)
if err != nil {
ctx.ServerError("DeleteJob failed", err)
return
}
// task, err := models.GetCloudbrainByJobID(jobID)
// if err != nil {
// log.Error("GetCloudbrainByJobID(%s) failed:%v", task.JobName, err.Error())
// ctx.RenderWithErr(err.Error(), tplModelArtsTrainJobIndex, nil)
// return
// }

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

ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/modelarts/train-job")
}


Loading…
Cancel
Save