| @@ -30,6 +30,7 @@ type AiModelManage struct { | |||||
| CodeBranch string `xorm:"varchar(400) NULL"` | CodeBranch string `xorm:"varchar(400) NULL"` | ||||
| CodeCommitID string `xorm:"NULL"` | CodeCommitID string `xorm:"NULL"` | ||||
| UserId int64 `xorm:"NOT NULL"` | UserId int64 `xorm:"NOT NULL"` | ||||
| UserName string `xorm:"NULL"` | |||||
| TrainTaskInfo string `xorm:"text NULL"` | TrainTaskInfo string `xorm:"text NULL"` | ||||
| CreatedUnix timeutil.TimeStamp `xorm:"created"` | CreatedUnix timeutil.TimeStamp `xorm:"created"` | ||||
| UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` | UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` | ||||
| @@ -31,6 +31,7 @@ const ( | |||||
| JobTypeBrainScore JobType = "BRAINSCORE" | JobTypeBrainScore JobType = "BRAINSCORE" | ||||
| JobTypeTrain JobType = "TRAIN" | JobTypeTrain JobType = "TRAIN" | ||||
| //notebook | |||||
| ModelArtsCreateQueue ModelArtsJobStatus = "CREATE_QUEUING" //免费资源创建排队中 | ModelArtsCreateQueue ModelArtsJobStatus = "CREATE_QUEUING" //免费资源创建排队中 | ||||
| ModelArtsCreating ModelArtsJobStatus = "CREATING" //创建中 | ModelArtsCreating ModelArtsJobStatus = "CREATING" //创建中 | ||||
| ModelArtsCreateFailed ModelArtsJobStatus = "CREATE_FAILED" //创建失败 | ModelArtsCreateFailed ModelArtsJobStatus = "CREATE_FAILED" //创建失败 | ||||
| @@ -46,6 +47,30 @@ const ( | |||||
| ModelArtsDeleted ModelArtsJobStatus = "DELETED" //已删除 | ModelArtsDeleted ModelArtsJobStatus = "DELETED" //已删除 | ||||
| ModelArtsResizing ModelArtsJobStatus = "RESIZING" //规格变更中 | ModelArtsResizing ModelArtsJobStatus = "RESIZING" //规格变更中 | ||||
| ModelArtsResizFailed ModelArtsJobStatus = "RESIZE_FAILED" //规格变更失败 | ModelArtsResizFailed ModelArtsJobStatus = "RESIZE_FAILED" //规格变更失败 | ||||
| //trainjob | |||||
| ModelArtsTrainJobUnknown ModelArtsJobStatus = "UNKNOWN" //作业状态未知 | |||||
| ModelArtsTrainJobInit ModelArtsJobStatus = "INIT" //作业初始化状态 | |||||
| ModelArtsTrainJobImageCreating ModelArtsJobStatus = "IMAGE_CREATING" //作业镜像正在创建 | |||||
| ModelArtsTrainJobImageFailed ModelArtsJobStatus = "IMAGE_FAILED" //作业镜像创建失败 | |||||
| ModelArtsTrainJobSubmitTrying ModelArtsJobStatus = "SUBMIT_TRYING" //作业正在提交 | |||||
| ModelArtsTrainJobSubmitFailed ModelArtsJobStatus = "SUBMIT_FAILED" //作业提交失败 | |||||
| ModelArtsTrainJobDeleteFailed ModelArtsJobStatus = "DELETE_FAILED" //作业删除失败 | |||||
| ModelArtsTrainJobWaiting ModelArtsJobStatus = "WAITING" //作业正在排队中 | |||||
| ModelArtsTrainJobRunning ModelArtsJobStatus = "RUNNING" //作业正在运行中 | |||||
| ModelArtsTrainJobKilling ModelArtsJobStatus = "KILLING" //作业正在取消 | |||||
| ModelArtsTrainJobCompleted ModelArtsJobStatus = "COMPLETED" //作业已经完成 | |||||
| ModelArtsTrainJobFailed ModelArtsJobStatus = "FAILED" //作业运行失败 | |||||
| ModelArtsTrainJobKilled ModelArtsJobStatus = "KILLED" //作业取消成功 | |||||
| ModelArtsTrainJobCanceled ModelArtsJobStatus = "CANCELED" //作业取消 | |||||
| ModelArtsTrainJobLost ModelArtsJobStatus = "LOST" //作业丢失 | |||||
| ModelArtsTrainJobScaling ModelArtsJobStatus = "SCALING" //作业正在扩容 | |||||
| ModelArtsTrainJobSubmitModelFailed ModelArtsJobStatus = "SUBMIT_MODEL_FAILED" //提交模型失败 | |||||
| ModelArtsTrainJobDeployServiceFailed ModelArtsJobStatus = "DEPLOY_SERVICE_FAILED" //部署服务失败 | |||||
| ModelArtsTrainJobCheckInit ModelArtsJobStatus = "CHECK_INIT" //审核作业初始化 | |||||
| ModelArtsTrainJobCheckRunning ModelArtsJobStatus = "CHECK_RUNNING" //审核作业正在运行中 | |||||
| ModelArtsTrainJobCheckRunningCompleted ModelArtsJobStatus = "CHECK_RUNNING_COMPLETED" //审核作业已经完成 | |||||
| ModelArtsTrainJobCheckFailed ModelArtsJobStatus = "CHECK_FAILED" //审核作业失败 | |||||
| ) | ) | ||||
| type Cloudbrain struct { | type Cloudbrain struct { | ||||
| @@ -1133,3 +1158,14 @@ func CanDelJob(isSigned bool, user *User, job *CloudbrainInfo) bool { | |||||
| } | } | ||||
| return false | return false | ||||
| } | } | ||||
| func GetCloudBrainUnStoppedJob() ([]*Cloudbrain, error) { | |||||
| cloudbrains := make([]*Cloudbrain, 0, 10) | |||||
| return cloudbrains, x. | |||||
| NotIn("status", | |||||
| JobStopped, JobSucceeded, JobFailed, ModelArtsCreateFailed, ModelArtsStartFailed, ModelArtsUnavailable, ModelArtsResizFailed, ModelArtsDeleted, | |||||
| ModelArtsStopped, ModelArtsTrainJobCanceled, ModelArtsTrainJobCheckFailed, ModelArtsTrainJobCompleted, ModelArtsTrainJobDeleteFailed, ModelArtsTrainJobDeployServiceFailed, | |||||
| ModelArtsTrainJobFailed, ModelArtsTrainJobImageFailed, ModelArtsTrainJobKilled, ModelArtsTrainJobLost, ModelArtsTrainJobSubmitFailed, ModelArtsTrainJobSubmitModelFailed). | |||||
| Limit(100). | |||||
| Find(&cloudbrains) | |||||
| } | |||||
| @@ -9,6 +9,9 @@ import ( | |||||
| "reflect" | "reflect" | ||||
| "strings" | "strings" | ||||
| "code.gitea.io/gitea/modules/base" | |||||
| "code.gitea.io/gitea/modules/setting" | |||||
| "code.gitea.io/gitea/models" | "code.gitea.io/gitea/models" | ||||
| "code.gitea.io/gitea/modules/auth/sso" | "code.gitea.io/gitea/modules/auth/sso" | ||||
| "code.gitea.io/gitea/modules/validation" | "code.gitea.io/gitea/modules/validation" | ||||
| @@ -31,6 +34,8 @@ func SignedInUser(ctx *macaron.Context, sess session.Store) (*models.User, bool) | |||||
| return nil, false | return nil, false | ||||
| } | } | ||||
| checkAutoLogin(ctx, sess) | |||||
| // Try to sign in with each of the enabled plugins | // Try to sign in with each of the enabled plugins | ||||
| for _, ssoMethod := range sso.Methods() { | for _, ssoMethod := range sso.Methods() { | ||||
| if !ssoMethod.IsEnabled() { | if !ssoMethod.IsEnabled() { | ||||
| @@ -46,6 +51,23 @@ func SignedInUser(ctx *macaron.Context, sess session.Store) (*models.User, bool) | |||||
| return nil, false | return nil, false | ||||
| } | } | ||||
| func checkAutoLogin(ctx *macaron.Context, sess session.Store) { | |||||
| uid := sess.Get("uid") | |||||
| if uid == nil { | |||||
| uname := ctx.GetCookie(setting.CookieUserName) | |||||
| u, err := models.GetUserByName(uname) | |||||
| if err == nil { | |||||
| if val, ok := ctx.GetSuperSecureCookie( | |||||
| base.EncodeMD5(u.Rands+u.Passwd), setting.CookieRememberName); ok && val == u.Name { | |||||
| sess.Set("uid", u.ID) | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| // Form form binding interface | // Form form binding interface | ||||
| type Form interface { | type Form interface { | ||||
| binding.Validator | binding.Validator | ||||
| @@ -185,6 +185,17 @@ func registerHandleSummaryStatistic() { | |||||
| }) | }) | ||||
| } | } | ||||
| func registerSyncCloudbrainStatus() { | |||||
| RegisterTaskFatal("sync_cloudbrain_status", &BaseConfig{ | |||||
| Enabled: true, | |||||
| RunAtStart: false, | |||||
| Schedule: "@every 10m", | |||||
| }, func(ctx context.Context, _ *models.User, _ Config) error { | |||||
| repo.SyncCloudbrainStatus() | |||||
| return nil | |||||
| }) | |||||
| } | |||||
| func initBasicTasks() { | func initBasicTasks() { | ||||
| registerUpdateMirrorTask() | registerUpdateMirrorTask() | ||||
| registerRepoHealthCheck() | registerRepoHealthCheck() | ||||
| @@ -202,4 +213,6 @@ func initBasicTasks() { | |||||
| registerHandleRepoAndUserStatistic() | registerHandleRepoAndUserStatistic() | ||||
| registerHandleSummaryStatistic() | registerHandleSummaryStatistic() | ||||
| registerSyncCloudbrainStatus() | |||||
| } | } | ||||
| @@ -51,6 +51,7 @@ func Init() error { | |||||
| switch setting.Attachment.StoreType { | switch setting.Attachment.StoreType { | ||||
| case LocalStorageType: | case LocalStorageType: | ||||
| Attachments, err = NewLocalStorage(setting.Attachment.Path) | Attachments, err = NewLocalStorage(setting.Attachment.Path) | ||||
| log.Info("local storage inited.") | |||||
| case MinioStorageType: | case MinioStorageType: | ||||
| minio := setting.Attachment.Minio | minio := setting.Attachment.Minio | ||||
| Attachments, err = NewMinioStorage( | Attachments, err = NewMinioStorage( | ||||
| @@ -62,6 +63,7 @@ func Init() error { | |||||
| minio.BasePath, | minio.BasePath, | ||||
| minio.UseSSL, | minio.UseSSL, | ||||
| ) | ) | ||||
| log.Info("minio storage inited.") | |||||
| default: | default: | ||||
| return fmt.Errorf("Unsupported attachment store type: %s", setting.Attachment.StoreType) | return fmt.Errorf("Unsupported attachment store type: %s", setting.Attachment.StoreType) | ||||
| } | } | ||||
| @@ -71,6 +73,7 @@ func Init() error { | |||||
| log.Error("obs.New failed:", err) | log.Error("obs.New failed:", err) | ||||
| return err | return err | ||||
| } | } | ||||
| log.Info("obs cli inited.") | |||||
| if err != nil { | if err != nil { | ||||
| return err | return err | ||||
| @@ -25,7 +25,7 @@ const ( | |||||
| MODEL_NOT_LATEST = 0 | MODEL_NOT_LATEST = 0 | ||||
| ) | ) | ||||
| func saveModelByParameters(jobId string, versionName string, name string, version string, label string, description string, userId int64) error { | |||||
| func saveModelByParameters(jobId string, versionName string, name string, version string, label string, description string, userId int64, userName string) error { | |||||
| aiTask, err := models.GetCloudbrainByJobIDAndVersionName(jobId, versionName) | aiTask, err := models.GetCloudbrainByJobIDAndVersionName(jobId, versionName) | ||||
| //aiTask, err := models.GetCloudbrainByJobID(jobId) | //aiTask, err := models.GetCloudbrainByJobID(jobId) | ||||
| if err != nil { | if err != nil { | ||||
| @@ -82,6 +82,7 @@ func saveModelByParameters(jobId string, versionName string, name string, versio | |||||
| AttachmentId: aiTask.Uuid, | AttachmentId: aiTask.Uuid, | ||||
| RepoId: aiTask.RepoID, | RepoId: aiTask.RepoID, | ||||
| UserId: userId, | UserId: userId, | ||||
| UserName: userName, | |||||
| CodeBranch: aiTask.BranchName, | CodeBranch: aiTask.BranchName, | ||||
| CodeCommitID: aiTask.CommitID, | CodeCommitID: aiTask.CommitID, | ||||
| Engine: aiTask.EngineID, | Engine: aiTask.EngineID, | ||||
| @@ -122,7 +123,7 @@ func SaveModel(ctx *context.Context) { | |||||
| return | return | ||||
| } | } | ||||
| err := saveModelByParameters(JobId, VersionName, name, version, label, description, ctx.User.ID) | |||||
| err := saveModelByParameters(JobId, VersionName, name, version, label, description, ctx.User.ID, ctx.User.Name) | |||||
| if err != nil { | if err != nil { | ||||
| log.Info("save model error." + err.Error()) | log.Info("save model error." + err.Error()) | ||||
| @@ -715,3 +715,78 @@ func downloadRateCode(repo *models.Repository, taskName, gitPath, codePath, benc | |||||
| return nil | return nil | ||||
| } | } | ||||
| func SyncCloudbrainStatus() { | |||||
| cloudBrains, err := models.GetCloudBrainUnStoppedJob() | |||||
| if err != nil { | |||||
| log.Error("GetCloudBrainUnStoppedJob failed:", err.Error()) | |||||
| return | |||||
| } | |||||
| for _, task := range cloudBrains { | |||||
| if task.Type == models.TypeCloudBrainOne { | |||||
| result, err := cloudbrain.GetJob(task.JobID) | |||||
| if err != nil { | |||||
| log.Error("GetJob(%s) failed:%v", task.JobName, err) | |||||
| continue | |||||
| } | |||||
| if result != nil { | |||||
| jobRes, _ := models.ConvertToJobResultPayload(result.Payload) | |||||
| taskRoles := jobRes.TaskRoles | |||||
| taskRes, _ := models.ConvertToTaskPod(taskRoles[cloudbrain.SubTaskName].(map[string]interface{})) | |||||
| task.Status = taskRes.TaskStatuses[0].State | |||||
| if task.Status != string(models.JobWaiting) { | |||||
| err = models.UpdateJob(task) | |||||
| if err != nil { | |||||
| log.Error("UpdateJob(%s) failed:%v", task.JobName, err) | |||||
| continue | |||||
| } | |||||
| } | |||||
| } | |||||
| } else if task.Type == models.TypeCloudBrainTwo { | |||||
| if task.JobType == string(models.JobTypeDebug) { | |||||
| result, err := modelarts.GetJob(task.JobID) | |||||
| if err != nil { | |||||
| log.Error("GetJob(%s) failed:%v", task.JobName, err) | |||||
| continue | |||||
| } | |||||
| if result != nil { | |||||
| task.Status = result.Status | |||||
| err = models.UpdateJob(task) | |||||
| if err != nil { | |||||
| log.Error("UpdateJob(%s) failed:%v", task.JobName, err) | |||||
| continue | |||||
| } | |||||
| } | |||||
| } else if task.JobType == string(models.JobTypeTrain) { | |||||
| result, err := modelarts.GetTrainJob(task.JobID, strconv.FormatInt(task.VersionID, 10)) | |||||
| if err != nil { | |||||
| log.Error("GetTrainJob(%s) failed:%v", task.JobName, err) | |||||
| continue | |||||
| } | |||||
| if result != nil { | |||||
| task.Status = modelarts.TransTrainJobStatus(result.IntStatus) | |||||
| task.Duration = result.Duration | |||||
| task.TrainJobDuration = result.TrainJobDuration | |||||
| err = models.UpdateJob(task) | |||||
| if err != nil { | |||||
| log.Error("UpdateJob(%s) failed:%v", task.JobName, err) | |||||
| continue | |||||
| } | |||||
| } | |||||
| } else { | |||||
| log.Error("task.JobType(%s) is error:%s", task.JobName, task.JobType) | |||||
| } | |||||
| } else { | |||||
| log.Error("task.Type(%s) is error:%d", task.JobName, task.Type) | |||||
| } | |||||
| } | |||||
| return | |||||
| } | |||||
| @@ -364,13 +364,17 @@ func trainJobNewDataPrepare(ctx *context.Context) error { | |||||
| Branches, err := ctx.Repo.GitRepo.GetBranches() | Branches, err := ctx.Repo.GitRepo.GetBranches() | ||||
| if err != nil { | if err != nil { | ||||
| log.Error("GetBranches failed:%v", err) | |||||
| ctx.ServerError("GetBranches error:", err) | ctx.ServerError("GetBranches error:", err) | ||||
| return err | return err | ||||
| } | } | ||||
| ctx.Data["Branches"] = Branches | |||||
| if Branches != nil { | |||||
| ctx.Data["Branches"] = Branches | |||||
| } | |||||
| ctx.Data["BranchesCount"] = len(Branches) | ctx.Data["BranchesCount"] = len(Branches) | ||||
| ctx.Data["params"] = "" | ctx.Data["params"] = "" | ||||
| ctx.Data["BranchName"] = ctx.Repo.BranchName | |||||
| ctx.Data["branchName"] = ctx.Repo.BranchName | |||||
| 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 { | ||||
| @@ -103,9 +103,9 @@ | |||||
| {{end}} | {{end}} | ||||
| {{end}} | {{end}} | ||||
| {{else}} | {{else}} | ||||
| <option name="branch_name" value="{{.BranchName}}">{{.BranchName}}</option> | |||||
| <option name="branch_name" value="{{.branchName}}">{{.branchName}}</option> | |||||
| {{range $k, $v :=.Branches}} | {{range $k, $v :=.Branches}} | ||||
| {{ if ne $v $.BranchName }} | |||||
| {{ if ne $v $.branchName }} | |||||
| <option name="branch_name" value="{{$v}}">{{$v}}</option> | <option name="branch_name" value="{{$v}}">{{$v}}</option> | ||||
| {{end}} | {{end}} | ||||
| {{end}} | {{end}} | ||||