Browse Source

del job

tags/v1.21.12.2^2
lewis 3 years ago
parent
commit
f6c75361d0
2 changed files with 45 additions and 24 deletions
  1. +19
    -20
      routers/api/v1/repo/modelarts.go
  2. +26
    -4
      routers/repo/modelarts.go

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

@@ -7,7 +7,6 @@ package repo


import ( import (
"net/http" "net/http"
"os"
"strconv" "strconv"
"strings" "strings"


@@ -15,8 +14,8 @@ import (
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/modelarts" "code.gitea.io/gitea/modules/modelarts"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/modules/storage"
routerRepo "code.gitea.io/gitea/routers/repo"
) )


func GetModelArtsNotebook(ctx *context.APIContext) { func GetModelArtsNotebook(ctx *context.APIContext) {
@@ -258,7 +257,7 @@ func DelTrainJobVersion(ctx *context.APIContext) {
} }
} }
} else { //已删除该任务下的所有版本 } else { //已删除该任务下的所有版本
deleteJobStorage(task.JobName)
routerRepo.DeleteJobStorage(task.JobName)
} }


ctx.JSON(http.StatusOK, map[string]interface{}{ ctx.JSON(http.StatusOK, map[string]interface{}{
@@ -326,20 +325,20 @@ func ModelList(ctx *context.APIContext) {
}) })
} }


func deleteJobStorage(jobName string) error {
//delete local
localJobPath := setting.JobPath + jobName
err := os.RemoveAll(localJobPath)
if err != nil {
log.Error("RemoveAll(%s) failed:%v", localJobPath, err)
}
//delete oss
dirPath := setting.CodePathPrefix + jobName + "/"
err = storage.ObsRemoveObject(setting.Bucket, dirPath)
if err != nil {
log.Error("ObsRemoveObject(%s) failed:%v", localJobPath, err)
}
return nil
}
//func DeleteJobStorage(jobName string) error {
// //delete local
// localJobPath := setting.JobPath + jobName
// err := os.RemoveAll(localJobPath)
// if err != nil {
// log.Error("RemoveAll(%s) failed:%v", localJobPath, err)
// }
//
// //delete oss
// dirPath := setting.CodePathPrefix + jobName + "/"
// err = storage.ObsRemoveObject(setting.Bucket, dirPath)
// if err != nil {
// log.Error("ObsRemoveObject(%s) failed:%v", localJobPath, err)
// }
//
// return nil
//}

+ 26
- 4
routers/repo/modelarts.go View File

@@ -11,11 +11,10 @@ import (
"strings" "strings"
"time" "time"


"code.gitea.io/gitea/modules/cloudbrain"

"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/cloudbrain"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
@@ -249,7 +248,7 @@ func NotebookManage(ctx *context.Context) {
break break
} }


if !ctx.IsSigned || (ctx.User.ID != task.UserID && !ctx.IsUserSiteAdmin() && !ctx.IsUserRepoOwner()){
if !ctx.IsSigned || (ctx.User.ID != task.UserID && !ctx.IsUserSiteAdmin() && !ctx.IsUserRepoOwner()) {
log.Error("the user has no right ro stop the job", task.JobName, ctx.Data["MsgID"]) log.Error("the user has no right ro stop the job", task.JobName, ctx.Data["MsgID"])
resultCode = "-1" resultCode = "-1"
errorMsg = "you have no right to stop the job" errorMsg = "you have no right to stop the job"
@@ -263,7 +262,7 @@ func NotebookManage(ctx *context.Context) {
break break
} }


if !ctx.IsSigned || (ctx.User.ID != task.UserID && !ctx.IsUserSiteAdmin()){
if !ctx.IsSigned || (ctx.User.ID != task.UserID && !ctx.IsUserSiteAdmin()) {
log.Error("the user has no right ro restart the job", task.JobName, ctx.Data["MsgID"]) log.Error("the user has no right ro restart the job", task.JobName, ctx.Data["MsgID"])
resultCode = "-1" resultCode = "-1"
errorMsg = "you have no right to restart the job" errorMsg = "you have no right to restart the job"
@@ -1413,6 +1412,11 @@ func TrainJobDel(ctx *context.Context) {
} }
} }


//删除存储
if len(VersionListTasks) > 0 {
DeleteJobStorage(VersionListTasks[0].JobName)
}

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


@@ -1538,3 +1542,21 @@ func ModelDownload(ctx *context.Context) {
} }
http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently) http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently)
} }

func DeleteJobStorage(jobName string) error {
//delete local
localJobPath := setting.JobPath + jobName
err := os.RemoveAll(localJobPath)
if err != nil {
log.Error("RemoveAll(%s) failed:%v", localJobPath, err)
}

//delete oss
dirPath := setting.CodePathPrefix + jobName + "/"
err = storage.ObsRemoveObject(setting.Bucket, dirPath)
if err != nil {
log.Error("ObsRemoveObject(%s) failed:%v", localJobPath, err)
}

return nil
}

Loading…
Cancel
Save