Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/1021pull/1023/head
@@ -1127,3 +1127,20 @@ func GetCloudBrainUnStoppedJob() ([]*Cloudbrain, error) { | |||||
Limit(100). | Limit(100). | ||||
Find(&cloudbrains) | Find(&cloudbrains) | ||||
} | } | ||||
func GetCloudbrainCountByUserID(userID int64) (int, error) { | |||||
count, err := x.In("status", JobWaiting, JobRunning).And("job_type = ? and user_id = ? and type = ?", JobTypeDebug, userID, TypeCloudBrainOne).Count(new(Cloudbrain)) | |||||
return int(count), err | |||||
} | |||||
func GetCloudbrainNotebookCountByUserID(userID int64) (int, error) { | |||||
count, err := x.In("status", ModelArtsCreateQueue, ModelArtsCreating, ModelArtsStarting, ModelArtsReadyToStart, ModelArtsResizing, ModelArtsStartQueuing, ModelArtsRunning, ModelArtsRestarting). | |||||
And("job_type = ? and user_id = ? and type = ?", JobTypeDebug, userID, TypeCloudBrainTwo).Count(new(Cloudbrain)) | |||||
return int(count), err | |||||
} | |||||
func GetCloudbrainTrainJobCountByUserID(userID int64) (int, error) { | |||||
count, err := x.In("status", ModelArtsTrainJobInit, ModelArtsTrainJobImageCreating, ModelArtsTrainJobSubmitTrying, ModelArtsTrainJobWaiting, ModelArtsTrainJobRunning, ModelArtsTrainJobScaling, ModelArtsTrainJobCheckInit, ModelArtsTrainJobCheckRunning, ModelArtsTrainJobCheckRunningCompleted). | |||||
And("job_type = ? and user_id = ? and type = ?", JobTypeTrain, userID, TypeCloudBrainTwo).Count(new(Cloudbrain)) | |||||
return int(count), err | |||||
} |
@@ -524,7 +524,7 @@ func RepoAssignment() macaron.Handler { | |||||
} | } | ||||
ctx.Data["Tags"] = tags | ctx.Data["Tags"] = tags | ||||
brs, err := ctx.Repo.GitRepo.GetBranches() | |||||
brs, _, err := ctx.Repo.GitRepo.GetBranches(0, 0) | |||||
if err != nil { | if err != nil { | ||||
ctx.ServerError("GetBranches", err) | ctx.ServerError("GetBranches", err) | ||||
return | return | ||||
@@ -712,7 +712,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler { | |||||
refName = ctx.Repo.Repository.DefaultBranch | refName = ctx.Repo.Repository.DefaultBranch | ||||
ctx.Repo.BranchName = refName | ctx.Repo.BranchName = refName | ||||
if !ctx.Repo.GitRepo.IsBranchExist(refName) { | if !ctx.Repo.GitRepo.IsBranchExist(refName) { | ||||
brs, err := ctx.Repo.GitRepo.GetBranches() | |||||
brs, _, err := ctx.Repo.GitRepo.GetBranches(0, 0) | |||||
if err != nil { | if err != nil { | ||||
ctx.ServerError("GetBranches", err) | ctx.ServerError("GetBranches", err) | ||||
return | return | ||||
@@ -6,7 +6,9 @@ | |||||
package git | package git | ||||
import ( | import ( | ||||
"bufio" | |||||
"fmt" | "fmt" | ||||
"io" | |||||
"strings" | "strings" | ||||
"github.com/go-git/go-git/v5/plumbing" | "github.com/go-git/go-git/v5/plumbing" | ||||
@@ -74,25 +76,6 @@ func (repo *Repository) SetDefaultBranch(name string) error { | |||||
return err | return err | ||||
} | } | ||||
// GetBranches returns all branches of the repository. | |||||
func (repo *Repository) GetBranches() ([]string, error) { | |||||
var branchNames []string | |||||
branches, err := repo.gogitRepo.Branches() | |||||
if err != nil { | |||||
return nil, err | |||||
} | |||||
_ = branches.ForEach(func(branch *plumbing.Reference) error { | |||||
branchNames = append(branchNames, strings.TrimPrefix(branch.Name().String(), BranchPrefix)) | |||||
return nil | |||||
}) | |||||
// TODO: Sort? | |||||
return branchNames, nil | |||||
} | |||||
// GetBranch returns a branch by it's name | // GetBranch returns a branch by it's name | ||||
func (repo *Repository) GetBranch(branch string) (*Branch, error) { | func (repo *Repository) GetBranch(branch string) (*Branch, error) { | ||||
if !repo.IsBranchExist(branch) { | if !repo.IsBranchExist(branch) { | ||||
@@ -106,16 +89,16 @@ func (repo *Repository) GetBranch(branch string) (*Branch, error) { | |||||
} | } | ||||
// GetBranchesByPath returns a branch by it's path | // GetBranchesByPath returns a branch by it's path | ||||
func GetBranchesByPath(path string) ([]*Branch, error) { | |||||
func GetBranchesByPath(path string, skip, limit int) ([]*Branch, int, error) { | |||||
gitRepo, err := OpenRepository(path) | gitRepo, err := OpenRepository(path) | ||||
if err != nil { | if err != nil { | ||||
return nil, err | |||||
return nil, 0, err | |||||
} | } | ||||
defer gitRepo.Close() | defer gitRepo.Close() | ||||
brs, err := gitRepo.GetBranches() | |||||
brs, countAll, err := gitRepo.GetBranches(skip, limit) | |||||
if err != nil { | if err != nil { | ||||
return nil, err | |||||
return nil, 0, err | |||||
} | } | ||||
branches := make([]*Branch, len(brs)) | branches := make([]*Branch, len(brs)) | ||||
@@ -127,7 +110,7 @@ func GetBranchesByPath(path string) ([]*Branch, error) { | |||||
} | } | ||||
} | } | ||||
return branches, nil | |||||
return branches, countAll, nil | |||||
} | } | ||||
// DeleteBranchOptions Option(s) for delete branch | // DeleteBranchOptions Option(s) for delete branch | ||||
@@ -183,3 +166,91 @@ func (repo *Repository) RemoveRemote(name string) error { | |||||
func (branch *Branch) GetCommit() (*Commit, error) { | func (branch *Branch) GetCommit() (*Commit, error) { | ||||
return branch.gitRepo.GetBranchCommit(branch.Name) | return branch.gitRepo.GetBranchCommit(branch.Name) | ||||
} | } | ||||
// GetBranches returns branches from the repository, skipping skip initial branches and | |||||
// returning at most limit branches, or all branches if limit is 0. | |||||
func (repo *Repository) GetBranches(skip, limit int) ([]string, int, error) { | |||||
return callShowRef(repo.Path, BranchPrefix, "--heads", skip, limit) | |||||
} | |||||
// callShowRef return refs, if limit = 0 it will not limit | |||||
func callShowRef(repoPath, prefix, arg string, skip, limit int) (branchNames []string, countAll int, err error) { | |||||
stdoutReader, stdoutWriter := io.Pipe() | |||||
defer func() { | |||||
_ = stdoutReader.Close() | |||||
_ = stdoutWriter.Close() | |||||
}() | |||||
go func() { | |||||
stderrBuilder := &strings.Builder{} | |||||
err := NewCommand("show-ref", arg).RunInDirPipeline(repoPath, stdoutWriter, stderrBuilder) | |||||
if err != nil { | |||||
if stderrBuilder.Len() == 0 { | |||||
_ = stdoutWriter.Close() | |||||
return | |||||
} | |||||
_ = stdoutWriter.CloseWithError(ConcatenateError(err, stderrBuilder.String())) | |||||
} else { | |||||
_ = stdoutWriter.Close() | |||||
} | |||||
}() | |||||
i := 0 | |||||
bufReader := bufio.NewReader(stdoutReader) | |||||
for i < skip { | |||||
_, isPrefix, err := bufReader.ReadLine() | |||||
if err == io.EOF { | |||||
return branchNames, i, nil | |||||
} | |||||
if err != nil { | |||||
return nil, 0, err | |||||
} | |||||
if !isPrefix { | |||||
i++ | |||||
} | |||||
} | |||||
for limit == 0 || i < skip+limit { | |||||
// The output of show-ref is simply a list: | |||||
// <sha> SP <ref> LF | |||||
_, err := bufReader.ReadSlice(' ') | |||||
for err == bufio.ErrBufferFull { | |||||
// This shouldn't happen but we'll tolerate it for the sake of peace | |||||
_, err = bufReader.ReadSlice(' ') | |||||
} | |||||
if err == io.EOF { | |||||
return branchNames, i, nil | |||||
} | |||||
if err != nil { | |||||
return nil, 0, err | |||||
} | |||||
branchName, err := bufReader.ReadString('\n') | |||||
if err == io.EOF { | |||||
// This shouldn't happen... but we'll tolerate it for the sake of peace | |||||
return branchNames, i, nil | |||||
} | |||||
if err != nil { | |||||
return nil, i, err | |||||
} | |||||
branchName = strings.TrimPrefix(branchName, prefix) | |||||
if len(branchName) > 0 { | |||||
branchName = branchName[:len(branchName)-1] | |||||
} | |||||
branchNames = append(branchNames, branchName) | |||||
i++ | |||||
} | |||||
// count all refs | |||||
for limit != 0 { | |||||
_, isPrefix, err := bufReader.ReadLine() | |||||
if err == io.EOF { | |||||
return branchNames, i, nil | |||||
} | |||||
if err != nil { | |||||
return nil, 0, err | |||||
} | |||||
if !isPrefix { | |||||
i++ | |||||
} | |||||
} | |||||
return branchNames, i, nil | |||||
} |
@@ -10,7 +10,6 @@ import ( | |||||
"strings" | "strings" | ||||
"github.com/go-git/go-git/v5/plumbing" | "github.com/go-git/go-git/v5/plumbing" | ||||
"github.com/mcuadros/go-version" | |||||
) | ) | ||||
// TagPrefix tags prefix path on the repository | // TagPrefix tags prefix path on the repository | ||||
@@ -225,29 +224,35 @@ func (repo *Repository) GetTagInfos(page, pageSize int) ([]*Tag, error) { | |||||
return tags, nil | return tags, nil | ||||
} | } | ||||
// GetTags returns all tags of the repository. | |||||
func (repo *Repository) GetTags() ([]string, error) { | |||||
var tagNames []string | |||||
tags, err := repo.gogitRepo.Tags() | |||||
if err != nil { | |||||
return nil, err | |||||
} | |||||
//// GetTags returns all tags of the repository. | |||||
//func (repo *Repository) GetTags() ([]string, error) { | |||||
// var tagNames []string | |||||
// | |||||
// tags, err := repo.gogitRepo.Tags() | |||||
// if err != nil { | |||||
// return nil, err | |||||
// } | |||||
// | |||||
// _ = tags.ForEach(func(tag *plumbing.Reference) error { | |||||
// tagNames = append(tagNames, strings.TrimPrefix(tag.Name().String(), TagPrefix)) | |||||
// return nil | |||||
// }) | |||||
// | |||||
// version.Sort(tagNames) | |||||
// | |||||
// // Reverse order | |||||
// for i := 0; i < len(tagNames)/2; i++ { | |||||
// j := len(tagNames) - i - 1 | |||||
// tagNames[i], tagNames[j] = tagNames[j], tagNames[i] | |||||
// } | |||||
// | |||||
// return tagNames, nil | |||||
//} | |||||
_ = tags.ForEach(func(tag *plumbing.Reference) error { | |||||
tagNames = append(tagNames, strings.TrimPrefix(tag.Name().String(), TagPrefix)) | |||||
return nil | |||||
}) | |||||
version.Sort(tagNames) | |||||
// Reverse order | |||||
for i := 0; i < len(tagNames)/2; i++ { | |||||
j := len(tagNames) - i - 1 | |||||
tagNames[i], tagNames[j] = tagNames[j], tagNames[i] | |||||
} | |||||
return tagNames, nil | |||||
// GetTags returns all tags of the repository. | |||||
func (repo *Repository) GetTags() (tags []string, err error) { | |||||
tags, _, err = callShowRef(repo.Path, TagPrefix, "--tags", 0, 0) | |||||
return | |||||
} | } | ||||
// GetTagType gets the type of the tag, either commit (simple) or tag (annotated) | // GetTagType gets the type of the tag, either commit (simple) or tag (annotated) | ||||
@@ -140,3 +140,11 @@ func ParseBool(value string) (result bool, valid bool) { | |||||
} | } | ||||
return intValue != 0, true | return intValue != 0, true | ||||
} | } | ||||
// ConcatenateError concatenats an error with stderr string | |||||
func ConcatenateError(err error, stderr string) error { | |||||
if len(stderr) == 0 { | |||||
return err | |||||
} | |||||
return fmt.Errorf("%w - %s", err, stderr) | |||||
} |
@@ -23,9 +23,10 @@ func GetBranch(repo *models.Repository, branch string) (*git.Branch, error) { | |||||
return gitRepo.GetBranch(branch) | return gitRepo.GetBranch(branch) | ||||
} | } | ||||
// GetBranches returns all the branches of a repository | |||||
func GetBranches(repo *models.Repository) ([]*git.Branch, error) { | |||||
return git.GetBranchesByPath(repo.RepoPath()) | |||||
// GetBranches returns branches from the repository, skipping skip initial branches and | |||||
// returning at most limit branches, or all branches if limit is 0. | |||||
func GetBranches(repo *models.Repository, skip, limit int) ([]*git.Branch, int, error) { | |||||
return git.GetBranchesByPath(repo.RepoPath(), skip, limit) | |||||
} | } | ||||
// checkBranchName validates branch name with existing repository branches | // checkBranchName validates branch name with existing repository branches | ||||
@@ -36,7 +37,7 @@ func checkBranchName(repo *models.Repository, name string) error { | |||||
} | } | ||||
defer gitRepo.Close() | defer gitRepo.Close() | ||||
branches, err := GetBranches(repo) | |||||
branches, _, err := GetBranches(repo, 0, 0) | |||||
if err != nil { | if err != nil { | ||||
return err | return err | ||||
} | } | ||||
@@ -204,7 +204,7 @@ func ListBranches(ctx *context.APIContext) { | |||||
// "200": | // "200": | ||||
// "$ref": "#/responses/BranchList" | // "$ref": "#/responses/BranchList" | ||||
branches, err := repo_module.GetBranches(ctx.Repo.Repository) | |||||
branches, _, err := repo_module.GetBranches(ctx.Repo.Repository,0,0) | |||||
if err != nil { | if err != nil { | ||||
ctx.Error(http.StatusInternalServerError, "GetBranches", err) | ctx.Error(http.StatusInternalServerError, "GetBranches", err) | ||||
return | return | ||||
@@ -181,7 +181,7 @@ func deleteBranch(ctx *context.Context, branchName string) error { | |||||
} | } | ||||
func loadBranches(ctx *context.Context) []*Branch { | func loadBranches(ctx *context.Context) []*Branch { | ||||
rawBranches, err := repo_module.GetBranches(ctx.Repo.Repository) | |||||
rawBranches, _, err := repo_module.GetBranches(ctx.Repo.Repository, 0, 0) | |||||
if err != nil { | if err != nil { | ||||
ctx.ServerError("GetBranches", err) | ctx.ServerError("GetBranches", err) | ||||
return nil | return nil | ||||
@@ -216,7 +216,22 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { | |||||
return | return | ||||
} | } | ||||
_, err := models.GetCloudbrainByName(jobName) | |||||
count, err := models.GetCloudbrainCountByUserID(ctx.User.ID) | |||||
if err != nil { | |||||
log.Error("GetCloudbrainCountByUserID failed:%v", err, ctx.Data["MsgID"]) | |||||
cloudBrainNewDataPrepare(ctx) | |||||
ctx.RenderWithErr("system error", tplCloudBrainNew, &form) | |||||
return | |||||
} else { | |||||
if count >= 1 { | |||||
log.Error("the user already has running or waiting task", ctx.Data["MsgID"]) | |||||
cloudBrainNewDataPrepare(ctx) | |||||
ctx.RenderWithErr("you have already a running or waiting task, can not create more", tplCloudBrainNew, &form) | |||||
return | |||||
} | |||||
} | |||||
_, err = models.GetCloudbrainByName(jobName) | |||||
if err == nil { | if err == nil { | ||||
log.Error("the job name did already exist", ctx.Data["MsgID"]) | log.Error("the job name did already exist", ctx.Data["MsgID"]) | ||||
cloudBrainNewDataPrepare(ctx) | cloudBrainNewDataPrepare(ctx) | ||||
@@ -507,7 +507,7 @@ func getBranchesForRepo(user *models.User, repo *models.Repository) (bool, []str | |||||
} | } | ||||
defer gitRepo.Close() | defer gitRepo.Close() | ||||
branches, err := gitRepo.GetBranches() | |||||
branches, _, err := gitRepo.GetBranches(0, 0) | |||||
if err != nil { | if err != nil { | ||||
return false, nil, err | return false, nil, err | ||||
} | } | ||||
@@ -528,7 +528,7 @@ func CompareDiff(ctx *context.Context) { | |||||
} | } | ||||
if ctx.Data["PageIsComparePull"] == true { | if ctx.Data["PageIsComparePull"] == true { | ||||
headBranches, err := headGitRepo.GetBranches() | |||||
headBranches, _, err := headGitRepo.GetBranches(0,0) | |||||
if err != nil { | if err != nil { | ||||
ctx.ServerError("GetBranches", err) | ctx.ServerError("GetBranches", err) | ||||
return | return | ||||
@@ -424,7 +424,7 @@ func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository, isPull boo | |||||
return nil | return nil | ||||
} | } | ||||
brs, err := ctx.Repo.GitRepo.GetBranches() | |||||
brs, _, err := ctx.Repo.GitRepo.GetBranches(0,0) | |||||
if err != nil { | if err != nil { | ||||
ctx.ServerError("GetBranches", err) | ctx.ServerError("GetBranches", err) | ||||
return nil | return nil | ||||
@@ -115,7 +115,22 @@ func NotebookCreate(ctx *context.Context, form auth.CreateModelArtsNotebookForm) | |||||
description := form.Description | description := form.Description | ||||
flavor := form.Flavor | flavor := form.Flavor | ||||
err := modelarts.GenerateTask(ctx, jobName, uuid, description, flavor) | |||||
count, err := models.GetCloudbrainNotebookCountByUserID(ctx.User.ID) | |||||
if err != nil { | |||||
log.Error("GetCloudbrainNotebookCountByUserID failed:%v", err, ctx.Data["MsgID"]) | |||||
cloudBrainNewDataPrepare(ctx) | |||||
ctx.RenderWithErr("system error", tplModelArtsNotebookNew, &form) | |||||
return | |||||
} else { | |||||
if count >= 1 { | |||||
log.Error("the user already has running or waiting task", ctx.Data["MsgID"]) | |||||
cloudBrainNewDataPrepare(ctx) | |||||
ctx.RenderWithErr("you have already a running or waiting task, can not create more", tplModelArtsNotebookNew, &form) | |||||
return | |||||
} | |||||
} | |||||
err = modelarts.GenerateTask(ctx, jobName, uuid, description, flavor) | |||||
if err != nil { | if err != nil { | ||||
ctx.RenderWithErr(err.Error(), tplModelArtsNotebookNew, &form) | ctx.RenderWithErr(err.Error(), tplModelArtsNotebookNew, &form) | ||||
return | return | ||||
@@ -360,18 +375,6 @@ func trainJobNewDataPrepare(ctx *context.Context) error { | |||||
outputObsPath := "/" + setting.Bucket + modelarts.JobPath + jobName + modelarts.OutputPath | outputObsPath := "/" + setting.Bucket + modelarts.JobPath + jobName + modelarts.OutputPath | ||||
ctx.Data["train_url"] = outputObsPath | ctx.Data["train_url"] = outputObsPath | ||||
Branches, err := ctx.Repo.GitRepo.GetBranches() | |||||
if err != nil { | |||||
log.Error("GetBranches failed:%v", err) | |||||
ctx.ServerError("GetBranches error:", err) | |||||
return err | |||||
} | |||||
if Branches != nil { | |||||
ctx.Data["Branches"] = Branches | |||||
} | |||||
ctx.Data["BranchesCount"] = len(Branches) | |||||
ctx.Data["params"] = "" | ctx.Data["params"] = "" | ||||
ctx.Data["branchName"] = ctx.Repo.BranchName | ctx.Data["branchName"] = ctx.Repo.BranchName | ||||
@@ -442,14 +445,6 @@ func trainJobErrorNewDataPrepare(ctx *context.Context, form auth.CreateModelArts | |||||
outputObsPath := "/" + setting.Bucket + modelarts.JobPath + jobName + modelarts.OutputPath | outputObsPath := "/" + setting.Bucket + modelarts.JobPath + jobName + modelarts.OutputPath | ||||
ctx.Data["train_url"] = outputObsPath | ctx.Data["train_url"] = outputObsPath | ||||
Branches, err := ctx.Repo.GitRepo.GetBranches() | |||||
if err != nil { | |||||
ctx.ServerError("GetBranches error:", err) | |||||
return err | |||||
} | |||||
ctx.Data["Branches"] = Branches | |||||
ctx.Data["BranchesCount"] = len(Branches) | |||||
configList, err := getConfigList(modelarts.PerPage, 1, modelarts.SortByCreateTime, "desc", "", modelarts.ConfigTypeCustom) | configList, err := getConfigList(modelarts.PerPage, 1, modelarts.SortByCreateTime, "desc", "", modelarts.ConfigTypeCustom) | ||||
if err != nil { | if err != nil { | ||||
ctx.ServerError("getConfigList failed:", err) | ctx.ServerError("getConfigList failed:", err) | ||||
@@ -545,13 +540,13 @@ func trainJobNewVersionDataPrepare(ctx *context.Context) error { | |||||
outputObsPath := "/" + setting.Bucket + modelarts.JobPath + jobName + modelarts.OutputPath | outputObsPath := "/" + setting.Bucket + modelarts.JobPath + jobName + modelarts.OutputPath | ||||
ctx.Data["train_url"] = outputObsPath | ctx.Data["train_url"] = outputObsPath | ||||
Branches, err := ctx.Repo.GitRepo.GetBranches() | |||||
branches, _, err := ctx.Repo.GitRepo.GetBranches(0, 0) | |||||
if err != nil { | if err != nil { | ||||
ctx.ServerError("GetBranches error:", err) | ctx.ServerError("GetBranches error:", err) | ||||
return err | return err | ||||
} | } | ||||
ctx.Data["branches"] = Branches | |||||
ctx.Data["branches"] = branches | |||||
ctx.Data["branch_name"] = task.BranchName | ctx.Data["branch_name"] = task.BranchName | ||||
ctx.Data["description"] = task.Description | ctx.Data["description"] = task.Description | ||||
ctx.Data["boot_file"] = task.BootFile | ctx.Data["boot_file"] = task.BootFile | ||||
@@ -634,12 +629,12 @@ func versionErrorDataPrepare(ctx *context.Context, form auth.CreateModelArtsTrai | |||||
outputObsPath := "/" + setting.Bucket + modelarts.JobPath + jobName + modelarts.OutputPath | outputObsPath := "/" + setting.Bucket + modelarts.JobPath + jobName + modelarts.OutputPath | ||||
ctx.Data["train_url"] = outputObsPath | ctx.Data["train_url"] = outputObsPath | ||||
Branches, err := ctx.Repo.GitRepo.GetBranches() | |||||
branches, _, err := ctx.Repo.GitRepo.GetBranches(0, 0) | |||||
if err != nil { | if err != nil { | ||||
ctx.ServerError("GetBranches error:", err) | ctx.ServerError("GetBranches error:", err) | ||||
return err | return err | ||||
} | } | ||||
ctx.Data["branches"] = Branches | |||||
ctx.Data["branches"] = branches | |||||
ctx.Data["description"] = form.Description | ctx.Data["description"] = form.Description | ||||
ctx.Data["dataset_name"] = task.DatasetName | ctx.Data["dataset_name"] = task.DatasetName | ||||
ctx.Data["work_server_number"] = form.WorkServerNumber | ctx.Data["work_server_number"] = form.WorkServerNumber | ||||
@@ -687,6 +682,21 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) | |||||
VersionCount := modelarts.VersionCount | VersionCount := modelarts.VersionCount | ||||
EngineName := form.EngineName | EngineName := form.EngineName | ||||
count, err := models.GetCloudbrainTrainJobCountByUserID(ctx.User.ID) | |||||
if err != nil { | |||||
log.Error("GetCloudbrainTrainJobCountByUserID failed:%v", err, ctx.Data["MsgID"]) | |||||
trainJobErrorNewDataPrepare(ctx, form) | |||||
ctx.RenderWithErr("system error", tplModelArtsTrainJobNew, &form) | |||||
return | |||||
} else { | |||||
if count >= 1 { | |||||
log.Error("the user already has running or waiting task", ctx.Data["MsgID"]) | |||||
trainJobErrorNewDataPrepare(ctx, form) | |||||
ctx.RenderWithErr("you have already a running or waiting task, can not create more", tplModelArtsTrainJobNew, &form) | |||||
return | |||||
} | |||||
} | |||||
if err := paramCheckCreateTrainJob(form); err != nil { | if err := paramCheckCreateTrainJob(form); err != nil { | ||||
log.Error("paramCheckCreateTrainJob failed:(%v)", err) | log.Error("paramCheckCreateTrainJob failed:(%v)", err) | ||||
trainJobErrorNewDataPrepare(ctx, form) | trainJobErrorNewDataPrepare(ctx, form) | ||||
@@ -839,7 +849,7 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) | |||||
return | return | ||||
} | } | ||||
err := modelarts.GenerateTrainJob(ctx, req) | |||||
err = modelarts.GenerateTrainJob(ctx, req) | |||||
if err != nil { | if err != nil { | ||||
log.Error("GenerateTrainJob failed:%v", err.Error()) | log.Error("GenerateTrainJob failed:%v", err.Error()) | ||||
trainJobErrorNewDataPrepare(ctx, form) | trainJobErrorNewDataPrepare(ctx, form) | ||||
@@ -853,6 +863,21 @@ func TrainJobCreateVersion(ctx *context.Context, form auth.CreateModelArtsTrainJ | |||||
ctx.Data["PageIsTrainJob"] = true | ctx.Data["PageIsTrainJob"] = true | ||||
var jobID = ctx.Params(":jobid") | var jobID = ctx.Params(":jobid") | ||||
count, err := models.GetCloudbrainTrainJobCountByUserID(ctx.User.ID) | |||||
if err != nil { | |||||
log.Error("GetCloudbrainTrainJobCountByUserID failed:%v", err, ctx.Data["MsgID"]) | |||||
versionErrorDataPrepare(ctx, form) | |||||
ctx.RenderWithErr("system error", tplModelArtsTrainJobVersionNew, &form) | |||||
return | |||||
} else { | |||||
if count >= 1 { | |||||
log.Error("the user already has running or waiting task", ctx.Data["MsgID"]) | |||||
versionErrorDataPrepare(ctx, form) | |||||
ctx.RenderWithErr("you have already a running or waiting task, can not create more", tplModelArtsTrainJobVersionNew, &form) | |||||
return | |||||
} | |||||
} | |||||
latestTask, err := models.GetCloudbrainByJobIDAndIsLatestVersion(jobID, modelarts.IsLatestVersion) | latestTask, err := models.GetCloudbrainByJobIDAndIsLatestVersion(jobID, modelarts.IsLatestVersion) | ||||
if err != nil { | if err != nil { | ||||
ctx.ServerError("GetCloudbrainByJobIDAndIsLatestVersion faild:", err) | ctx.ServerError("GetCloudbrainByJobIDAndIsLatestVersion faild:", err) | ||||
@@ -252,7 +252,7 @@ func runSync(m *models.Mirror) ([]*mirrorSyncResult, bool) { | |||||
} | } | ||||
} | } | ||||
branches, err := repo_module.GetBranches(m.Repo) | |||||
branches, _, err := repo_module.GetBranches(m.Repo,0,0) | |||||
if err != nil { | if err != nil { | ||||
log.Error("GetBranches: %v", err) | log.Error("GetBranches: %v", err) | ||||
return nil, false | return nil, false | ||||
@@ -452,7 +452,7 @@ func CloseBranchPulls(doer *models.User, repoID int64, branch string) error { | |||||
// CloseRepoBranchesPulls close all pull requests which head branches are in the given repository | // CloseRepoBranchesPulls close all pull requests which head branches are in the given repository | ||||
func CloseRepoBranchesPulls(doer *models.User, repo *models.Repository) error { | func CloseRepoBranchesPulls(doer *models.User, repo *models.Repository) error { | ||||
branches, err := git.GetBranchesByPath(repo.RepoPath()) | |||||
branches, _, err := git.GetBranchesByPath(repo.RepoPath(), 0, 0) | |||||
if err != nil { | if err != nil { | ||||
return err | return err | ||||
} | } | ||||
@@ -474,6 +474,7 @@ td, th { | |||||
<script> | <script> | ||||
console.log({{.version_list_task}}) | console.log({{.version_list_task}}) | ||||
console.log({{.}}) | |||||
$('.menu .item').tab() | $('.menu .item').tab() | ||||
// $('.ui.style.accordion').accordion(); | // $('.ui.style.accordion').accordion(); | ||||
@@ -709,11 +710,13 @@ td, th { | |||||
} | } | ||||
function logScroll(version_name) { | function logScroll(version_name) { | ||||
let container = document.querySelector(`#log${version_name}`) | let container = document.querySelector(`#log${version_name}`) | ||||
let scrollTop = container.scrollTop | let scrollTop = container.scrollTop | ||||
let scrollHeight = container.scrollHeight | let scrollHeight = container.scrollHeight | ||||
let clientHeight = container.clientHeight | let clientHeight = container.clientHeight | ||||
if(parseInt(scrollTop) + clientHeight == scrollHeight || parseInt(scrollTop) + clientHeight +1 == scrollHeight || parseInt(scrollTop) + clientHeight - 1 == scrollHeight){ | |||||
let scrollLeft = container.scrollLeft | |||||
if((parseInt(scrollTop) + clientHeight == scrollHeight || parseInt(scrollTop) + clientHeight +1 == scrollHeight || parseInt(scrollTop) + clientHeight - 1 == scrollHeight) && (scrollLeft===0)){ | |||||
let end_line = $(`#log${version_name} input[name=end_line]`).val() | let end_line = $(`#log${version_name} input[name=end_line]`).val() | ||||
$.get(`/api/v1/repos/${userName}/${repoPath}/modelarts/train-job/${jobID}/log?version_name=${version_name}&base_line=${end_line}&lines=50&order=desc`, (data) => { | $.get(`/api/v1/repos/${userName}/${repoPath}/modelarts/train-job/${jobID}/log?version_name=${version_name}&base_line=${end_line}&lines=50&order=desc`, (data) => { | ||||
if (data.Lines == 0){ | if (data.Lines == 0){ | ||||
@@ -736,7 +739,7 @@ td, th { | |||||
console.log(err); | console.log(err); | ||||
}); | }); | ||||
} | } | ||||
if(scrollTop == 0){ | |||||
if(scrollTop == 0 && scrollLeft==0){ | |||||
let start_line = $(`#log${version_name} input[name=start_line]`).val() | let start_line = $(`#log${version_name} input[name=start_line]`).val() | ||||
$.get(`/api/v1/repos/${userName}/${repoPath}/modelarts/train-job/${jobID}/log?version_name=${version_name}&base_line=${start_line}&lines=50&order=asc`, (data) => { | $.get(`/api/v1/repos/${userName}/${repoPath}/modelarts/train-job/${jobID}/log?version_name=${version_name}&base_line=${start_line}&lines=50&order=asc`, (data) => { | ||||
if (data.Lines == 0){ | if (data.Lines == 0){ | ||||
@@ -346,7 +346,7 @@ | |||||
{{template "base/footer" .}} | {{template "base/footer" .}} | ||||
<script> | <script> | ||||
let url_href = location.pathname.split('create_version')[0] | |||||
let url_href = location.pathname.split('/create_version')[0] | |||||
let url_post = location.pathname | let url_post = location.pathname | ||||
let version_name = location.search.split('?version_name=')[1] | let version_name = location.search.split('?version_name=')[1] | ||||
$("#parents_version").val(version_name) | $("#parents_version").val(version_name) | ||||