| @@ -92,20 +92,14 @@ type Action struct { | |||||
| } | } | ||||
| type ActionShow struct { | type ActionShow struct { | ||||
| UserID int64 | |||||
| OpType ActionType | |||||
| ActUserID int64 | |||||
| ActUser *UserShow | |||||
| RepoID int64 | |||||
| Repo *RepositoryShow | |||||
| CommentID int64 | |||||
| Comment *Comment `xorm:"-"` | |||||
| IsDeleted bool `xorm:"INDEX NOT NULL DEFAULT false"` | |||||
| RefName string | |||||
| IsPrivate bool `xorm:"INDEX NOT NULL DEFAULT false"` | |||||
| IsTransformed bool `xorm:"INDEX NOT NULL DEFAULT false"` | |||||
| Content string `xorm:"TEXT"` | |||||
| CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` | |||||
| OpType ActionType | |||||
| RepoLink string | |||||
| ShortRepoFullDisplayName string | |||||
| Content string | |||||
| RefName string | |||||
| IssueInfos []string | |||||
| CommentLink string | |||||
| IssueTitle string | |||||
| } | } | ||||
| // GetOpType gets the ActionType of this action. | // GetOpType gets the ActionType of this action. | ||||
| @@ -243,6 +237,43 @@ func (a *Action) GetRepoLink() string { | |||||
| return "/" + a.GetRepoPath() | return "/" + a.GetRepoPath() | ||||
| } | } | ||||
| func (a *Action) ToShow() *ActionShow { | |||||
| actionShow := &ActionShow{} | |||||
| actionShow.OpType = GetTaskOptType(*a) | |||||
| actionShow.Content = a.Content | |||||
| actionShow.RefName = a.RefName | |||||
| if strings.Contains(a.Content, "|") { | |||||
| actionShow.IssueInfos = a.GetIssueInfos() | |||||
| actionShow.IssueTitle = a.GetIssueTitle() | |||||
| } | |||||
| if a.Repo != nil { | |||||
| actionShow.RepoLink = a.GetRepoLink() | |||||
| actionShow.ShortRepoFullDisplayName = a.ShortRepoFullDisplayName() | |||||
| } | |||||
| if a.Comment != nil { | |||||
| actionShow.CommentLink = a.GetCommentLink() | |||||
| } | |||||
| return actionShow | |||||
| } | |||||
| func GetTaskOptType(action Action) ActionType { | |||||
| switch action.OpType { | |||||
| case ActionCreateDebugGPUTask, | |||||
| ActionCreateDebugNPUTask, | |||||
| ActionCreateTrainTask, | |||||
| ActionCreateInferenceTask, | |||||
| ActionCreateBenchMarkTask, | |||||
| ActionCreateGPUTrainTask: | |||||
| return ActionCreateCloudbrainTask | |||||
| default: | |||||
| return action.OpType | |||||
| } | |||||
| } | |||||
| // GetRepositoryFromMatch returns a *Repository from a username and repo strings | // GetRepositoryFromMatch returns a *Repository from a username and repo strings | ||||
| func GetRepositoryFromMatch(ownerName string, repoName string) (*Repository, error) { | func GetRepositoryFromMatch(ownerName string, repoName string) (*Repository, error) { | ||||
| var err error | var err error | ||||
| @@ -439,7 +470,7 @@ func GetActionByIds(ids []int64) ([]*Action, error) { | |||||
| if err != nil { | if err != nil { | ||||
| return nil, err | return nil, err | ||||
| } | } | ||||
| if err := ActionList(actions).LoadAttributes(); err != nil { | |||||
| if err := ActionList(actions).LoadAllAttributes(); err != nil { | |||||
| return nil, fmt.Errorf("ActionList loadAttributes: %v", err) | return nil, fmt.Errorf("ActionList loadAttributes: %v", err) | ||||
| } | } | ||||
| return actions, nil | return actions, nil | ||||
| @@ -79,6 +79,48 @@ func (actions ActionList) LoadRepositories() ([]*Repository, error) { | |||||
| return actions.loadRepositories(x) | return actions.loadRepositories(x) | ||||
| } | } | ||||
| func (actions ActionList) getCommentIDs() []int64 { | |||||
| commentIDs := make(map[int64]struct{}, len(actions)) | |||||
| for _, action := range actions { | |||||
| if action.CommentID == 0 { | |||||
| continue | |||||
| } | |||||
| if _, ok := commentIDs[action.CommentID]; !ok { | |||||
| commentIDs[action.CommentID] = struct{}{} | |||||
| } | |||||
| } | |||||
| return keysInt64(commentIDs) | |||||
| } | |||||
| func (actions ActionList) loadComments(e Engine) ([]*Comment, error) { | |||||
| if len(actions) == 0 { | |||||
| return nil, nil | |||||
| } | |||||
| commentIDs := actions.getCommentIDs() | |||||
| commentMaps := make(map[int64]*Comment, len(commentIDs)) | |||||
| if len(commentIDs) == 0 { | |||||
| return make([]*Comment, 0), nil | |||||
| } | |||||
| err := e. | |||||
| In("id", commentIDs). | |||||
| Find(&commentMaps) | |||||
| if err != nil { | |||||
| return nil, fmt.Errorf("find comment: %v", err) | |||||
| } | |||||
| for _, action := range actions { | |||||
| action.Comment = commentMaps[action.CommentID] | |||||
| } | |||||
| return valuesComment(commentMaps), nil | |||||
| } | |||||
| // LoadComments loads actions' all comments | |||||
| func (actions ActionList) LoadComments() ([]*Comment, error) { | |||||
| return actions.loadComments(x) | |||||
| } | |||||
| // loadAttributes loads all attributes | // loadAttributes loads all attributes | ||||
| func (actions ActionList) loadAttributes(e Engine) (err error) { | func (actions ActionList) loadAttributes(e Engine) (err error) { | ||||
| if _, err = actions.loadUsers(e); err != nil { | if _, err = actions.loadUsers(e); err != nil { | ||||
| @@ -96,3 +138,26 @@ func (actions ActionList) loadAttributes(e Engine) (err error) { | |||||
| func (actions ActionList) LoadAttributes() error { | func (actions ActionList) LoadAttributes() error { | ||||
| return actions.loadAttributes(x) | return actions.loadAttributes(x) | ||||
| } | } | ||||
| // LoadAllAttributes loads all attributes of the actions | |||||
| // compare with LoadAttributes() ,LoadAllAttributes() loads Comment attribute | |||||
| func (actions ActionList) LoadAllAttributes() error { | |||||
| return actions.loadAllAttributes(x) | |||||
| } | |||||
| // loadAllAttributes | |||||
| func (actions ActionList) loadAllAttributes(e Engine) (err error) { | |||||
| if _, err = actions.loadUsers(e); err != nil { | |||||
| return | |||||
| } | |||||
| if _, err = actions.loadRepositories(e); err != nil { | |||||
| return | |||||
| } | |||||
| if _, err = actions.loadComments(e); err != nil { | |||||
| return | |||||
| } | |||||
| return nil | |||||
| } | |||||
| @@ -169,69 +169,23 @@ type Cloudbrain struct { | |||||
| } | } | ||||
| type CloudbrainShow struct { | type CloudbrainShow struct { | ||||
| JobID string `xorm:"INDEX NOT NULL"` | |||||
| JobType string `xorm:"INDEX NOT NULL DEFAULT 'DEBUG'"` | |||||
| JobName string | |||||
| DisplayJobName string | |||||
| Status string | |||||
| UserID int64 `xorm:"INDEX NOT NULL"` | |||||
| RepoID int64 `xorm:"INDEX NOT NULL"` | |||||
| SubTaskName string | |||||
| ContainerID string | |||||
| ContainerIp string | |||||
| CreatedUnix timeutil.TimeStamp `xorm:"INDEX"` | |||||
| UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` | |||||
| Duration int64 `xorm:"DEFAULT 0"` //运行时长 单位秒 | |||||
| TrainJobDuration string `xorm:"DEFAULT '00:00:00'"` | |||||
| Image string //镜像名称 | |||||
| GpuQueue string //GPU类型即GPU队列 | |||||
| ResourceSpecId int //GPU规格id | |||||
| DeletedAt time.Time `xorm:"deleted"` | |||||
| CanDebug bool `xorm:"-"` | |||||
| CanDel bool `xorm:"-"` | |||||
| CanModify bool `xorm:"-"` | |||||
| Type int | |||||
| BenchmarkTypeID int | |||||
| BenchmarkChildTypeID int | |||||
| VersionID int64 //版本id | |||||
| VersionName string `xorm:"INDEX"` //当前版本 | |||||
| Uuid string //数据集id | |||||
| DatasetName string | |||||
| VersionCount int //任务的当前版本数量,不包括删除的 | |||||
| IsLatestVersion string //是否是最新版本,1是,0否 | |||||
| CommitID string //提交的仓库代码id | |||||
| PreVersionName string //父版本名称 | |||||
| ComputeResource string //计算资源,例如npu | |||||
| EngineID int64 //引擎id | |||||
| TrainUrl string //输出模型的obs路径 | |||||
| BranchName string //分支名称 | |||||
| Parameters string //传给modelarts的param参数 | |||||
| BootFile string //启动文件 | |||||
| DataUrl string //数据集的obs路径 | |||||
| LogUrl string //日志输出的obs路径 | |||||
| PreVersionId int64 //父版本的版本id | |||||
| FlavorCode string //modelarts上的规格id | |||||
| Description string `xorm:"varchar(256)"` //描述 | |||||
| WorkServerNumber int //节点数 | |||||
| FlavorName string //规格名称 | |||||
| EngineName string //引擎名称 | |||||
| TotalVersionCount int //任务的所有版本数量,包括删除的 | |||||
| LabelName string //标签名称 | |||||
| ModelName string //模型名称 | |||||
| ModelVersion string //模型版本 | |||||
| CkptName string //权重文件名称 | |||||
| ResultUrl string //推理结果的obs路径 | |||||
| ID int64 | |||||
| JobType string | |||||
| DisplayJobName string | |||||
| Duration string | |||||
| ResourceSpec *ResourceAndFlavor | |||||
| ComputeResource string | |||||
| } | |||||
| User *User `xorm:"-"` | |||||
| Repo *Repository `xorm:"-"` | |||||
| BenchmarkType string `xorm:"-"` //算法评测,模型评测 | |||||
| BenchmarkTypeName string `xorm:"-"` | |||||
| BenchmarkTypeRankLink string `xorm:"-"` | |||||
| StartTime timeutil.TimeStamp | |||||
| EndTime timeutil.TimeStamp | |||||
| func (task *Cloudbrain) ToShow() *CloudbrainShow { | |||||
| return &CloudbrainShow{ | |||||
| ID: task.ID, | |||||
| JobType: task.JobType, | |||||
| DisplayJobName: task.DisplayJobName, | |||||
| Duration: task.TrainJobDuration, | |||||
| ResourceSpec: GetCloudbrainResourceSpec(task.JobType, task.Type, task.ResourceSpecId, task.FlavorCode), | |||||
| ComputeResource: task.ComputeResource, | |||||
| } | |||||
| } | } | ||||
| func (task *Cloudbrain) ComputeAndSetDuration() { | func (task *Cloudbrain) ComputeAndSetDuration() { | ||||
| @@ -1917,11 +1871,11 @@ func GetStartedCloudbrainTaskByUpdatedUnix(startTime, endTime time.Time) ([]Clou | |||||
| return r, nil | return r, nil | ||||
| } | } | ||||
| func GetCloudbrainByIds(ids []int64) ([]Cloudbrain, error) { | |||||
| func GetCloudbrainByIds(ids []int64) ([]*Cloudbrain, error) { | |||||
| if len(ids) == 0 { | if len(ids) == 0 { | ||||
| return nil, nil | return nil, nil | ||||
| } | } | ||||
| cloudbrains := make([]Cloudbrain, 0) | |||||
| cloudbrains := make([]*Cloudbrain, 0) | |||||
| err := x.In("id", ids).Unscoped().Find(&cloudbrains) | err := x.In("id", ids).Unscoped().Find(&cloudbrains) | ||||
| if err != nil { | if err != nil { | ||||
| return nil, err | return nil, err | ||||
| @@ -1930,31 +1884,128 @@ func GetCloudbrainByIds(ids []int64) ([]Cloudbrain, error) { | |||||
| } | } | ||||
| var ( | var ( | ||||
| DebugResourceSpecs *ResourceSpecs | |||||
| TrainResourceSpecs *ResourceSpecs | |||||
| SpecsMapInitFlag = false | |||||
| CloudbrainDebugResourceSpecsMap map[int]*ResourceSpec | |||||
| CloudbrainTrainResourceSpecsMap map[int]*ResourceSpec | |||||
| CloudbrainBenchmarkResourceSpecsMap map[int]*ResourceSpec | |||||
| ModelArtsDebugResourceSpecsMap map[string]*FlavorInfo | |||||
| ModelArtsTrainResourceSpecsMap map[string]*FlavorInfo | |||||
| ) | ) | ||||
| func GetResourceSpec(jobType string, resourceSpecId int) *ResourceSpec { | |||||
| if jobType == string(JobTypeTrain) { | |||||
| if TrainResourceSpecs == nil { | |||||
| json.Unmarshal([]byte(setting.TrainResourceSpecs), &TrainResourceSpecs) | |||||
| type ModelArtsFlavor struct { | |||||
| Info []struct { | |||||
| Code string `json:"code"` | |||||
| Value string `json:"value"` | |||||
| UnitPrice int64 `json:"unitPrice"` | |||||
| } `json:"flavor"` | |||||
| } | |||||
| func InitResourceSpecMap() { | |||||
| if CloudbrainDebugResourceSpecsMap == nil || len(CloudbrainDebugResourceSpecsMap) == 0 { | |||||
| t := ResourceSpecs{} | |||||
| json.Unmarshal([]byte(setting.ResourceSpecs), &t) | |||||
| CloudbrainDebugResourceSpecsMap = make(map[int]*ResourceSpec, len(t.ResourceSpec)) | |||||
| for _, spec := range t.ResourceSpec { | |||||
| CloudbrainDebugResourceSpecsMap[spec.Id] = spec | |||||
| } | } | ||||
| for _, spec := range TrainResourceSpecs.ResourceSpec { | |||||
| if resourceSpecId == spec.Id { | |||||
| return spec | |||||
| } | |||||
| } | |||||
| if CloudbrainTrainResourceSpecsMap == nil || len(CloudbrainTrainResourceSpecsMap) == 0 { | |||||
| t := ResourceSpecs{} | |||||
| json.Unmarshal([]byte(setting.TrainResourceSpecs), &t) | |||||
| CloudbrainTrainResourceSpecsMap = make(map[int]*ResourceSpec, len(t.ResourceSpec)) | |||||
| for _, spec := range t.ResourceSpec { | |||||
| CloudbrainTrainResourceSpecsMap[spec.Id] = spec | |||||
| } | } | ||||
| } else { | |||||
| if DebugResourceSpecs == nil { | |||||
| json.Unmarshal([]byte(setting.ResourceSpecs), &DebugResourceSpecs) | |||||
| } | |||||
| if CloudbrainBenchmarkResourceSpecsMap == nil || len(CloudbrainBenchmarkResourceSpecsMap) == 0 { | |||||
| t := ResourceSpecs{} | |||||
| json.Unmarshal([]byte(setting.BenchmarkResourceSpecs), &t) | |||||
| CloudbrainBenchmarkResourceSpecsMap = make(map[int]*ResourceSpec, len(t.ResourceSpec)) | |||||
| for _, spec := range t.ResourceSpec { | |||||
| CloudbrainBenchmarkResourceSpecsMap[spec.Id] = spec | |||||
| } | |||||
| } | |||||
| if ModelArtsDebugResourceSpecsMap == nil || len(ModelArtsDebugResourceSpecsMap) == 0 { | |||||
| t := FlavorInfos{} | |||||
| json.Unmarshal([]byte(setting.FlavorInfos), &t) | |||||
| ModelArtsDebugResourceSpecsMap = make(map[string]*FlavorInfo, len(t.FlavorInfo)) | |||||
| for _, spec := range t.FlavorInfo { | |||||
| ModelArtsDebugResourceSpecsMap[spec.Value] = spec | |||||
| } | } | ||||
| for _, spec := range DebugResourceSpecs.ResourceSpec { | |||||
| if resourceSpecId == spec.Id { | |||||
| return spec | |||||
| } | |||||
| if ModelArtsTrainResourceSpecsMap == nil || len(ModelArtsTrainResourceSpecsMap) == 0 { | |||||
| t := ModelArtsFlavor{} | |||||
| json.Unmarshal([]byte(setting.TrainJobFLAVORINFOS), &t) | |||||
| ModelArtsTrainResourceSpecsMap = make(map[string]*FlavorInfo, len(t.Info)) | |||||
| for _, spec := range t.Info { | |||||
| f := &FlavorInfo{ | |||||
| Value: spec.Code, | |||||
| Desc: spec.Value, | |||||
| UnitPrice: spec.UnitPrice, | |||||
| } | } | ||||
| ModelArtsTrainResourceSpecsMap[spec.Value] = f | |||||
| } | } | ||||
| } | |||||
| SpecsMapInitFlag = true | |||||
| } | |||||
| type ResourceAndFlavor struct { | |||||
| ResourceSpec *ResourceSpec | |||||
| FlavorInfo *FlavorInfo | |||||
| } | |||||
| func NewResourceAndFlavor(resourceSpec *ResourceSpec, flavorInfo *FlavorInfo) *ResourceAndFlavor { | |||||
| return &ResourceAndFlavor{ | |||||
| ResourceSpec: resourceSpec, | |||||
| FlavorInfo: flavorInfo, | |||||
| } | |||||
| } | |||||
| func GetCloudbrainResourceSpec(jobType string, clusterType int, resourceSpecId int, flavorCode string) *ResourceAndFlavor { | |||||
| if !SpecsMapInitFlag { | |||||
| InitResourceSpecMap() | |||||
| } | } | ||||
| if clusterType == TypeCloudBrainOne { | |||||
| switch jobType { | |||||
| case string(JobTypeDebug): | |||||
| return NewResourceAndFlavor(CloudbrainDebugResourceSpecsMap[resourceSpecId], nil) | |||||
| case string(JobTypeTrain): | |||||
| return NewResourceAndFlavor(CloudbrainTrainResourceSpecsMap[resourceSpecId], nil) | |||||
| case string(JobTypeBenchmark): | |||||
| return NewResourceAndFlavor(CloudbrainBenchmarkResourceSpecsMap[resourceSpecId], nil) | |||||
| } | |||||
| } else if clusterType == TypeCloudBrainTwo { | |||||
| switch jobType { | |||||
| case string(JobTypeDebug): | |||||
| return NewResourceAndFlavor(nil, ModelArtsDebugResourceSpecsMap[flavorCode]) | |||||
| case string(JobTypeTrain): | |||||
| return NewResourceAndFlavor(nil, ModelArtsTrainResourceSpecsMap[flavorCode]) | |||||
| case string(JobTypeInference): | |||||
| return NewResourceAndFlavor(nil, ModelArtsTrainResourceSpecsMap[flavorCode]) | |||||
| } | |||||
| } | |||||
| return nil | return nil | ||||
| } | } | ||||
| func GetCloudbrainTaskUnitPrice(task Cloudbrain) int64 { | |||||
| spec := GetCloudbrainResourceSpec(task.JobType, task.Type, task.ResourceSpecId, task.FlavorCode) | |||||
| if spec == nil { | |||||
| return 0 | |||||
| } | |||||
| if task.Type == TypeCloudBrainOne { | |||||
| if spec.ResourceSpec == nil { | |||||
| return 0 | |||||
| } | |||||
| return spec.ResourceSpec.UnitPrice | |||||
| } else if task.Type == TypeCloudBrainTwo { | |||||
| if spec.FlavorInfo == nil { | |||||
| return 0 | |||||
| } | |||||
| return spec.FlavorInfo.UnitPrice | |||||
| } | |||||
| return 0 | |||||
| } | |||||
| @@ -27,3 +27,11 @@ func valuesUser(m map[int64]*User) []*User { | |||||
| } | } | ||||
| return values | return values | ||||
| } | } | ||||
| func valuesComment(m map[int64]*Comment) []*Comment { | |||||
| var values = make([]*Comment, 0, len(m)) | |||||
| for _, v := range m { | |||||
| values = append(values, v) | |||||
| } | |||||
| return values | |||||
| } | |||||
| @@ -50,18 +50,18 @@ func UpdateRewardAdminLogStatus(logId string, oldStatus, newStatus int) error { | |||||
| return nil | return nil | ||||
| } | } | ||||
| func GetRewardAdminLogByLogIds(logIds []string) ([]RewardAdminLog, error) { | |||||
| func GetRewardAdminLogByLogIds(logIds []string) ([]*RewardAdminLog, error) { | |||||
| if len(logIds) == 0 { | if len(logIds) == 0 { | ||||
| return nil, nil | return nil, nil | ||||
| } | } | ||||
| adminLogs := make([]AdminLogAndUser, 0) | |||||
| adminLogs := make([]*AdminLogAndUser, 0) | |||||
| err := x.Table("reward_admin_log").Join("LEFT", "user", "reward_admin_log.creator_id = public.user.id").In("reward_admin_log.log_id", logIds).Find(&adminLogs) | err := x.Table("reward_admin_log").Join("LEFT", "user", "reward_admin_log.creator_id = public.user.id").In("reward_admin_log.log_id", logIds).Find(&adminLogs) | ||||
| if err != nil { | if err != nil { | ||||
| return nil, err | return nil, err | ||||
| } | } | ||||
| r := make([]RewardAdminLog, len(adminLogs)) | |||||
| r := make([]*RewardAdminLog, len(adminLogs)) | |||||
| for i, v := range adminLogs { | for i, v := range adminLogs { | ||||
| temp := v.AdminRewardAdminLog | |||||
| temp := &v.AdminRewardAdminLog | |||||
| temp.CreatorName = v.User.Name | temp.CreatorName = v.User.Name | ||||
| r[i] = temp | r[i] = temp | ||||
| } | } | ||||
| @@ -119,7 +119,6 @@ type RewardRecordShowList []*RewardOperateRecordShow | |||||
| func (l *RewardRecordList) ToShow() (RewardRecordShowList, error) { | func (l *RewardRecordList) ToShow() (RewardRecordShowList, error) { | ||||
| actionMap, err := l.GetRewardRecordAction() | actionMap, err := l.GetRewardRecordAction() | ||||
| adminLogMap, err := l.GetRewardRecordAdminLog() | |||||
| CloudbrainMap, err := l.GetRewardRecordCloudbrainTask() | CloudbrainMap, err := l.GetRewardRecordCloudbrainTask() | ||||
| if err != nil { | if err != nil { | ||||
| return nil, err | return nil, err | ||||
| @@ -129,11 +128,9 @@ func (l *RewardRecordList) ToShow() (RewardRecordShowList, error) { | |||||
| temp := v.ToShow() | temp := v.ToShow() | ||||
| switch v.SourceType { | switch v.SourceType { | ||||
| case SourceTypeAccomplishTask.Name(): | case SourceTypeAccomplishTask.Name(): | ||||
| temp.Action = actionMap[v.SourceId] | |||||
| case SourceTypeAdminOperate.Name(): | |||||
| temp.AdminLog = adminLogMap[v.SourceId] | |||||
| temp.Action = actionMap[v.SourceId].ToShow() | |||||
| case SourceTypeRunCloudbrainTask.Name(): | case SourceTypeRunCloudbrainTask.Name(): | ||||
| temp.Cloudbrain = CloudbrainMap[v.SourceId] | |||||
| temp.Cloudbrain = CloudbrainMap[v.SourceId].ToShow() | |||||
| } | } | ||||
| result = append(result, &temp) | result = append(result, &temp) | ||||
| } | } | ||||
| @@ -141,7 +138,7 @@ func (l *RewardRecordList) ToShow() (RewardRecordShowList, error) { | |||||
| return result, nil | return result, nil | ||||
| } | } | ||||
| func (l *RewardRecordList) GetRewardRecordAction() (map[string]Action, error) { | |||||
| func (l *RewardRecordList) GetRewardRecordAction() (map[string]*Action, error) { | |||||
| if len(*l) == 0 { | if len(*l) == 0 { | ||||
| return nil, nil | return nil, nil | ||||
| } | } | ||||
| @@ -157,15 +154,15 @@ func (l *RewardRecordList) GetRewardRecordAction() (map[string]Action, error) { | |||||
| if err != nil { | if err != nil { | ||||
| return nil, err | return nil, err | ||||
| } | } | ||||
| result := make(map[string]Action, 0) | |||||
| result := make(map[string]*Action, 0) | |||||
| for _, v := range actions { | for _, v := range actions { | ||||
| result[fmt.Sprint(v.ID)] = *v | |||||
| result[fmt.Sprint(v.ID)] = v | |||||
| } | } | ||||
| return result, nil | return result, nil | ||||
| } | } | ||||
| func (l *RewardRecordList) GetRewardRecordAdminLog() (map[string]RewardAdminLog, error) { | |||||
| func (l *RewardRecordList) GetRewardRecordAdminLog() (map[string]*RewardAdminLog, error) { | |||||
| if len(*l) == 0 { | if len(*l) == 0 { | ||||
| return nil, nil | return nil, nil | ||||
| } | } | ||||
| @@ -180,7 +177,7 @@ func (l *RewardRecordList) GetRewardRecordAdminLog() (map[string]RewardAdminLog, | |||||
| if err != nil { | if err != nil { | ||||
| return nil, err | return nil, err | ||||
| } | } | ||||
| result := make(map[string]RewardAdminLog, 0) | |||||
| result := make(map[string]*RewardAdminLog, 0) | |||||
| for _, v := range logs { | for _, v := range logs { | ||||
| result[fmt.Sprint(v.LogId)] = v | result[fmt.Sprint(v.LogId)] = v | ||||
| } | } | ||||
| @@ -188,7 +185,7 @@ func (l *RewardRecordList) GetRewardRecordAdminLog() (map[string]RewardAdminLog, | |||||
| } | } | ||||
| func (l *RewardRecordList) GetRewardRecordCloudbrainTask() (map[string]Cloudbrain, error) { | |||||
| func (l *RewardRecordList) GetRewardRecordCloudbrainTask() (map[string]*Cloudbrain, error) { | |||||
| if len(*l) == 0 { | if len(*l) == 0 { | ||||
| return nil, nil | return nil, nil | ||||
| } | } | ||||
| @@ -204,7 +201,7 @@ func (l *RewardRecordList) GetRewardRecordCloudbrainTask() (map[string]Cloudbrai | |||||
| if err != nil { | if err != nil { | ||||
| return nil, err | return nil, err | ||||
| } | } | ||||
| result := make(map[string]Cloudbrain, 0) | |||||
| result := make(map[string]*Cloudbrain, 0) | |||||
| for _, v := range cloudbrains { | for _, v := range cloudbrains { | ||||
| result[fmt.Sprint(v.ID)] = v | result[fmt.Sprint(v.ID)] = v | ||||
| } | } | ||||
| @@ -242,7 +239,6 @@ type AdminRewardOperateReq struct { | |||||
| func (r RewardOperateRecord) ToShow() RewardOperateRecordShow { | func (r RewardOperateRecord) ToShow() RewardOperateRecordShow { | ||||
| return RewardOperateRecordShow{ | return RewardOperateRecordShow{ | ||||
| SerialNo: r.SerialNo, | SerialNo: r.SerialNo, | ||||
| CreateDate: r.CreatedUnix, | |||||
| OperateType: r.OperateType, | OperateType: r.OperateType, | ||||
| Amount: r.Amount, | Amount: r.Amount, | ||||
| Remark: r.Remark, | Remark: r.Remark, | ||||
| @@ -255,7 +251,6 @@ func (r RewardOperateRecord) ToShow() RewardOperateRecordShow { | |||||
| type RewardOperateRecordShow struct { | type RewardOperateRecordShow struct { | ||||
| SerialNo string | SerialNo string | ||||
| CreateDate timeutil.TimeStamp | |||||
| Status string | Status string | ||||
| OperateType string | OperateType string | ||||
| Amount int64 | Amount int64 | ||||
| @@ -263,9 +258,9 @@ type RewardOperateRecordShow struct { | |||||
| Remark string | Remark string | ||||
| SourceType string | SourceType string | ||||
| LastOperateDate timeutil.TimeStamp | LastOperateDate timeutil.TimeStamp | ||||
| Action Action | |||||
| Cloudbrain Cloudbrain | |||||
| AdminLog RewardAdminLog | |||||
| Action *ActionShow | |||||
| Cloudbrain *CloudbrainShow | |||||
| AdminLog *RewardAdminLog | |||||
| } | } | ||||
| func getPointOperateRecord(tl *RewardOperateRecord) (*RewardOperateRecord, error) { | func getPointOperateRecord(tl *RewardOperateRecord) (*RewardOperateRecord, error) { | ||||
| @@ -22,7 +22,6 @@ type CreateModelArtsNotebookForm struct { | |||||
| Description string `form:"description"` | Description string `form:"description"` | ||||
| Flavor string `form:"flavor" binding:"Required"` | Flavor string `form:"flavor" binding:"Required"` | ||||
| ImageId string `form:"image_id" binding:"Required"` | ImageId string `form:"image_id" binding:"Required"` | ||||
| ResourceSpecId int `form:"resource_spec_id"` | |||||
| } | } | ||||
| func (f *CreateModelArtsNotebookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { | func (f *CreateModelArtsNotebookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { | ||||
| @@ -47,7 +46,6 @@ type CreateModelArtsTrainJobForm struct { | |||||
| VersionName string `form:"version_name" binding:"Required"` | VersionName string `form:"version_name" binding:"Required"` | ||||
| FlavorName string `form:"flaver_names" binding:"Required"` | FlavorName string `form:"flaver_names" binding:"Required"` | ||||
| EngineName string `form:"engine_names" binding:"Required"` | EngineName string `form:"engine_names" binding:"Required"` | ||||
| ResourceSpecId int `form:"resource_spec_id"` | |||||
| } | } | ||||
| type CreateModelArtsInferenceJobForm struct { | type CreateModelArtsInferenceJobForm struct { | ||||
| @@ -73,7 +71,6 @@ type CreateModelArtsInferenceJobForm struct { | |||||
| ModelName string `form:"model_name" binding:"Required"` | ModelName string `form:"model_name" binding:"Required"` | ||||
| ModelVersion string `form:"model_version" binding:"Required"` | ModelVersion string `form:"model_version" binding:"Required"` | ||||
| CkptName string `form:"ckpt_name" binding:"Required"` | CkptName string `form:"ckpt_name" binding:"Required"` | ||||
| ResourceSpecId int `form:"resource_spec_id"` | |||||
| } | } | ||||
| func (f *CreateModelArtsTrainJobForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { | func (f *CreateModelArtsTrainJobForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { | ||||
| @@ -140,8 +140,9 @@ type VersionInfo struct { | |||||
| type Flavor struct { | type Flavor struct { | ||||
| Info []struct { | Info []struct { | ||||
| Code string `json:"code"` | |||||
| Value string `json:"value"` | |||||
| Code string `json:"code"` | |||||
| Value string `json:"value"` | |||||
| UnitPrice int64 `json:"unitPrice"` | |||||
| } `json:"flavor"` | } `json:"flavor"` | ||||
| } | } | ||||
| @@ -230,7 +230,7 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { | |||||
| command = commandTrain | command = commandTrain | ||||
| } | } | ||||
| if !account.IsPointBalanceEnough(ctx.User.ID, jobType, resourceSpecId) { | |||||
| if !account.IsPointBalanceEnough(ctx.User.ID, jobType, models.TypeCloudBrainOne, resourceSpecId, "") { | |||||
| log.Error("point balance is not enough,userId=%d jobType=%s resourceSpecId=%d", ctx.User.ID, jobType, resourceSpecId) | log.Error("point balance is not enough,userId=%d jobType=%s resourceSpecId=%d", ctx.User.ID, jobType, resourceSpecId) | ||||
| cloudBrainNewDataPrepare(ctx) | cloudBrainNewDataPrepare(ctx) | ||||
| ctx.RenderWithErr(models.ErrInsufficientPointsBalance{}.Error(), tpl, &form) | ctx.RenderWithErr(models.ErrInsufficientPointsBalance{}.Error(), tpl, &form) | ||||
| @@ -318,7 +318,7 @@ func CloudBrainRestart(ctx *context.Context) { | |||||
| var status = string(models.JobWaiting) | var status = string(models.JobWaiting) | ||||
| task := ctx.Cloudbrain | task := ctx.Cloudbrain | ||||
| for { | for { | ||||
| if !account.IsPointBalanceEnough(ctx.User.ID, task.JobType, task.ResourceSpecId) { | |||||
| if !account.IsPointBalanceEnough(ctx.User.ID, task.JobType, models.TypeCloudBrainOne, task.ResourceSpecId, "") { | |||||
| log.Error("point balance is not enough,userId=%d jobType=%s resourceSpecId=%d", ctx.User.ID, task.JobType, task.ResourceSpecId) | log.Error("point balance is not enough,userId=%d jobType=%s resourceSpecId=%d", ctx.User.ID, task.JobType, task.ResourceSpecId) | ||||
| resultCode = "-1" | resultCode = "-1" | ||||
| errorMsg = models.ErrInsufficientPointsBalance{}.Error() | errorMsg = models.ErrInsufficientPointsBalance{}.Error() | ||||
| @@ -1870,7 +1870,7 @@ func BenchMarkAlgorithmCreate(ctx *context.Context, form auth.CreateCloudBrainFo | |||||
| repo := ctx.Repo.Repository | repo := ctx.Repo.Repository | ||||
| if !account.IsPointBalanceEnough(ctx.User.ID, string(models.JobTypeBenchmark), resourceSpecId) { | |||||
| if !account.IsPointBalanceEnough(ctx.User.ID, string(models.JobTypeBenchmark), models.TypeCloudBrainOne, cloudbrain.BenchMarkResourceID, "") { | |||||
| log.Error("point balance is not enough,userId=%d jobType=%s resourceSpecId=%d", ctx.User.ID, string(models.JobTypeBenchmark), resourceSpecId) | log.Error("point balance is not enough,userId=%d jobType=%s resourceSpecId=%d", ctx.User.ID, string(models.JobTypeBenchmark), resourceSpecId) | ||||
| cloudBrainNewDataPrepare(ctx) | cloudBrainNewDataPrepare(ctx) | ||||
| ctx.RenderWithErr(models.ErrInsufficientPointsBalance{}.Error(), tplCloudBrainBenchmarkNew, &form) | ctx.RenderWithErr(models.ErrInsufficientPointsBalance{}.Error(), tplCloudBrainBenchmarkNew, &form) | ||||
| @@ -2032,7 +2032,7 @@ func ModelBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainForm) | |||||
| tpl := tplCloudBrainBenchmarkNew | tpl := tplCloudBrainBenchmarkNew | ||||
| command := cloudbrain.Command | command := cloudbrain.Command | ||||
| if !account.IsPointBalanceEnough(ctx.User.ID, jobType, resourceSpecId) { | |||||
| if !account.IsPointBalanceEnough(ctx.User.ID, jobType, models.TypeCloudBrainOne, resourceSpecId, "") { | |||||
| log.Error("point balance is not enough,userId=%d jobType=%s resourceSpecId=%d", ctx.User.ID, jobType, resourceSpecId) | log.Error("point balance is not enough,userId=%d jobType=%s resourceSpecId=%d", ctx.User.ID, jobType, resourceSpecId) | ||||
| cloudBrainNewDataPrepare(ctx) | cloudBrainNewDataPrepare(ctx) | ||||
| ctx.RenderWithErr(models.ErrInsufficientPointsBalance{}.Error(), tpl, &form) | ctx.RenderWithErr(models.ErrInsufficientPointsBalance{}.Error(), tpl, &form) | ||||
| @@ -205,10 +205,9 @@ func Notebook2Create(ctx *context.Context, form auth.CreateModelArtsNotebookForm | |||||
| flavor := form.Flavor | flavor := form.Flavor | ||||
| imageId := form.ImageId | imageId := form.ImageId | ||||
| repo := ctx.Repo.Repository | repo := ctx.Repo.Repository | ||||
| resourceSpecId := form.ResourceSpecId | |||||
| if !account.IsPointBalanceEnough(ctx.User.ID, string(models.JobTypeDebug), resourceSpecId) { | |||||
| log.Error("point balance is not enough,userId=%d jobType=%s resourceSpecId=%d", ctx.User.ID, string(models.JobTypeBenchmark), resourceSpecId) | |||||
| if !account.IsPointBalanceEnough(ctx.User.ID, string(models.JobTypeDebug), models.TypeCloudBrainTwo, 0, flavor) { | |||||
| log.Error("point balance is not enough,userId=%d jobType=%s ", ctx.User.ID, string(models.JobTypeBenchmark)) | |||||
| cloudBrainNewDataPrepare(ctx) | cloudBrainNewDataPrepare(ctx) | ||||
| ctx.RenderWithErr(models.ErrInsufficientPointsBalance{}.Error(), tplModelArtsNotebookNew, &form) | ctx.RenderWithErr(models.ErrInsufficientPointsBalance{}.Error(), tplModelArtsNotebookNew, &form) | ||||
| return | return | ||||
| @@ -426,7 +425,7 @@ func NotebookManage(ctx *context.Context) { | |||||
| errorMsg = "you have no right to restart the job" | errorMsg = "you have no right to restart the job" | ||||
| break | break | ||||
| } | } | ||||
| if !account.IsPointBalanceEnough(ctx.User.ID, task.JobType, task.ResourceSpecId) { | |||||
| if !account.IsPointBalanceEnough(ctx.User.ID, task.JobType, task.Type, task.ResourceSpecId, task.FlavorCode) { | |||||
| log.Error("point balance is not enough,userId=%d jobType=%s resourceSpecId=%d", ctx.User.ID, task.JobType, task.ResourceSpecId) | log.Error("point balance is not enough,userId=%d jobType=%s resourceSpecId=%d", ctx.User.ID, task.JobType, task.ResourceSpecId) | ||||
| resultCode = "-1" | resultCode = "-1" | ||||
| errorMsg = models.ErrInsufficientPointsBalance{}.Error() | errorMsg = models.ErrInsufficientPointsBalance{}.Error() | ||||
| @@ -1000,10 +999,9 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) | |||||
| FlavorName := form.FlavorName | FlavorName := form.FlavorName | ||||
| VersionCount := modelarts.VersionCount | VersionCount := modelarts.VersionCount | ||||
| EngineName := form.EngineName | EngineName := form.EngineName | ||||
| resourceSpecId := form.ResourceSpecId | |||||
| if !account.IsPointBalanceEnough(ctx.User.ID, string(models.JobTypeTrain), resourceSpecId) { | |||||
| log.Error("point balance is not enough,userId=%d jobType=%s resourceSpecId=%d", ctx.User.ID, string(models.JobTypeBenchmark), resourceSpecId) | |||||
| if !account.IsPointBalanceEnough(ctx.User.ID, string(models.JobTypeTrain), models.TypeCloudBrainTwo, 0, flavorCode) { | |||||
| log.Error("point balance is not enough,userId=%d jobType=%s", ctx.User.ID, string(models.JobTypeBenchmark)) | |||||
| cloudBrainNewDataPrepare(ctx) | cloudBrainNewDataPrepare(ctx) | ||||
| ctx.RenderWithErr(models.ErrInsufficientPointsBalance{}.Error(), tplModelArtsTrainJobNew, &form) | ctx.RenderWithErr(models.ErrInsufficientPointsBalance{}.Error(), tplModelArtsTrainJobNew, &form) | ||||
| return | return | ||||
| @@ -1183,7 +1181,6 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) | |||||
| EngineName: EngineName, | EngineName: EngineName, | ||||
| VersionCount: VersionCount, | VersionCount: VersionCount, | ||||
| TotalVersionCount: modelarts.TotalVersionCount, | TotalVersionCount: modelarts.TotalVersionCount, | ||||
| ResourceSpecId: resourceSpecId, | |||||
| } | } | ||||
| //将params转换Parameters.Parameter,出错时返回给前端 | //将params转换Parameters.Parameter,出错时返回给前端 | ||||
| @@ -1847,12 +1844,11 @@ func InferenceJobCreate(ctx *context.Context, form auth.CreateModelArtsInference | |||||
| modelName := form.ModelName | modelName := form.ModelName | ||||
| modelVersion := form.ModelVersion | modelVersion := form.ModelVersion | ||||
| ckptName := form.CkptName | ckptName := form.CkptName | ||||
| resourceSpecId := form.ResourceSpecId | |||||
| ckptUrl := form.TrainUrl + form.CkptName | ckptUrl := form.TrainUrl + form.CkptName | ||||
| if !account.IsPointBalanceEnough(ctx.User.ID, string(models.JobTypeInference), resourceSpecId) { | |||||
| log.Error("point balance is not enough,userId=%d jobType=%s resourceSpecId=%d", ctx.User.ID, string(models.JobTypeBenchmark), resourceSpecId) | |||||
| if !account.IsPointBalanceEnough(ctx.User.ID, string(models.JobTypeInference), models.TypeCloudBrainTwo, 0, flavorCode) { | |||||
| log.Error("point balance is not enough,userId=%d jobType=%s ", ctx.User.ID, string(models.JobTypeBenchmark)) | |||||
| inferenceJobErrorNewDataPrepare(ctx, form) | inferenceJobErrorNewDataPrepare(ctx, form) | ||||
| ctx.RenderWithErr(models.ErrInsufficientPointsBalance{}.Error(), tplModelArtsInferenceJobNew, &form) | ctx.RenderWithErr(models.ErrInsufficientPointsBalance{}.Error(), tplModelArtsInferenceJobNew, &form) | ||||
| return | return | ||||
| @@ -2002,7 +1998,6 @@ func InferenceJobCreate(ctx *context.Context, form auth.CreateModelArtsInference | |||||
| ModelVersion: modelVersion, | ModelVersion: modelVersion, | ||||
| CkptName: ckptName, | CkptName: ckptName, | ||||
| ResultUrl: resultObsPath, | ResultUrl: resultObsPath, | ||||
| ResourceSpecId: resourceSpecId, | |||||
| } | } | ||||
| err = modelarts.GenerateInferenceJob(ctx, req) | err = modelarts.GenerateInferenceJob(ctx, req) | ||||
| @@ -20,9 +20,9 @@ func StartAndGetCloudBrainPointDeductTask(task models.Cloudbrain) (*models.Rewar | |||||
| return nil, nil | return nil, nil | ||||
| } | } | ||||
| spec := models.GetResourceSpec(task.JobType, task.ResourceSpecId) | |||||
| if spec == nil || spec.UnitPrice == 0 { | |||||
| log.Debug("GetResourceSpec failed,spec is nil or UnitPrice = 0") | |||||
| unitPrice := models.GetCloudbrainTaskUnitPrice(task) | |||||
| if unitPrice == 0 { | |||||
| log.Debug("finish StartAndGetCloudBrainPointDeductTask, UnitPrice = 0 task.ID=%d", task.ID) | |||||
| return nil, nil | return nil, nil | ||||
| } | } | ||||
| @@ -34,7 +34,7 @@ func StartAndGetCloudBrainPointDeductTask(task models.Cloudbrain) (*models.Rewar | |||||
| OperateType: models.OperateTypeDecrease, | OperateType: models.OperateTypeDecrease, | ||||
| Delay: setting.CloudBrainPayDelay, | Delay: setting.CloudBrainPayDelay, | ||||
| Interval: setting.CloudBrainPayInterval, | Interval: setting.CloudBrainPayInterval, | ||||
| UnitAmount: spec.UnitPrice, | |||||
| UnitAmount: unitPrice, | |||||
| RewardType: models.RewardTypePoint, | RewardType: models.RewardTypePoint, | ||||
| StartTime: time.Unix(int64(task.StartTime), 0), | StartTime: time.Unix(int64(task.StartTime), 0), | ||||
| Tittle: RUN_CLOUDBRAIN_TASK_TITTLE, | Tittle: RUN_CLOUDBRAIN_TASK_TITTLE, | ||||
| @@ -67,12 +67,18 @@ func InitAccount(userId int64) (*models.PointAccount, error) { | |||||
| } | } | ||||
| //IsPointBalanceEnough check whether the user's point balance is bigger than task unit price | //IsPointBalanceEnough check whether the user's point balance is bigger than task unit price | ||||
| func IsPointBalanceEnough(targetUserId int64, jobType string, resourceSpecId int) bool { | |||||
| func IsPointBalanceEnough(targetUserId int64, jobType string, clusterType int, resourceSpecId int, flavorCode string) bool { | |||||
| if !setting.CloudBrainPaySwitch { | if !setting.CloudBrainPaySwitch { | ||||
| return true | return true | ||||
| } | } | ||||
| spec := models.GetResourceSpec(jobType, resourceSpecId) | |||||
| if spec == nil { | |||||
| t := models.Cloudbrain{ | |||||
| Type: clusterType, | |||||
| JobType: jobType, | |||||
| ResourceSpecId: resourceSpecId, | |||||
| FlavorCode: flavorCode, | |||||
| } | |||||
| uniPrice := models.GetCloudbrainTaskUnitPrice(t) | |||||
| if uniPrice == 0 { | |||||
| return true | return true | ||||
| } | } | ||||
| a, err := GetAccount(targetUserId) | a, err := GetAccount(targetUserId) | ||||
| @@ -80,6 +86,6 @@ func IsPointBalanceEnough(targetUserId int64, jobType string, resourceSpecId int | |||||
| log.Error("IsPointBalanceEnough GetAccount error,err=%v", err) | log.Error("IsPointBalanceEnough GetAccount error,err=%v", err) | ||||
| return false | return false | ||||
| } | } | ||||
| return a.Balance >= spec.UnitPrice | |||||
| return a.Balance >= uniPrice | |||||
| } | } | ||||
| @@ -9,19 +9,13 @@ import ( | |||||
| ) | ) | ||||
| func Accomplish(action models.Action) { | func Accomplish(action models.Action) { | ||||
| action.OpType = models.GetTaskOptType(action) | |||||
| switch action.OpType { | switch action.OpType { | ||||
| case models.ActionCreateRepo, | case models.ActionCreateRepo, | ||||
| models.ActionCreateImage: | models.ActionCreateImage: | ||||
| if action.Repo.IsPrivate { | if action.Repo.IsPrivate { | ||||
| return | return | ||||
| } | } | ||||
| case models.ActionCreateDebugGPUTask, | |||||
| models.ActionCreateDebugNPUTask, | |||||
| models.ActionCreateTrainTask, | |||||
| models.ActionCreateInferenceTask, | |||||
| models.ActionCreateBenchMarkTask, | |||||
| models.ActionCreateGPUTrainTask: | |||||
| action.OpType = models.ActionCreateCloudbrainTask | |||||
| } | } | ||||
| go accomplish(action) | go accomplish(action) | ||||
| } | } | ||||