Browse Source

#2225

update
tags/v1.22.9.2^2
chenyifan01 3 years ago
parent
commit
39339a29e6
13 changed files with 295 additions and 152 deletions
  1. +46
    -15
      models/action.go
  2. +65
    -0
      models/action_list.go
  3. +131
    -80
      models/cloudbrain.go
  4. +8
    -0
      models/helper.go
  5. +4
    -4
      models/reward_admin_log.go
  6. +12
    -17
      models/reward_operate_record.go
  7. +0
    -3
      modules/auth/modelarts.go
  8. +3
    -2
      modules/modelarts/modelarts.go
  9. +4
    -4
      routers/repo/cloudbrain.go
  10. +7
    -12
      routers/repo/modelarts.go
  11. +4
    -4
      services/reward/cloubrain_deduct.go
  12. +10
    -4
      services/reward/point/account/point_account.go
  13. +1
    -7
      services/task/task.go

+ 46
- 15
models/action.go View File

@@ -92,20 +92,14 @@ type Action 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.
@@ -243,6 +237,43 @@ func (a *Action) GetRepoLink() string {
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
func GetRepositoryFromMatch(ownerName string, repoName string) (*Repository, error) {
var err error
@@ -439,7 +470,7 @@ func GetActionByIds(ids []int64) ([]*Action, error) {
if err != nil {
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 actions, nil


+ 65
- 0
models/action_list.go View File

@@ -79,6 +79,48 @@ func (actions ActionList) LoadRepositories() ([]*Repository, error) {
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
func (actions ActionList) loadAttributes(e Engine) (err error) {
if _, err = actions.loadUsers(e); err != nil {
@@ -96,3 +138,26 @@ func (actions ActionList) loadAttributes(e Engine) (err error) {
func (actions ActionList) LoadAttributes() error {
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
}

+ 131
- 80
models/cloudbrain.go View File

@@ -169,69 +169,23 @@ type Cloudbrain 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() {
@@ -1917,11 +1871,11 @@ func GetStartedCloudbrainTaskByUpdatedUnix(startTime, endTime time.Time) ([]Clou
return r, nil
}

func GetCloudbrainByIds(ids []int64) ([]Cloudbrain, error) {
func GetCloudbrainByIds(ids []int64) ([]*Cloudbrain, error) {
if len(ids) == 0 {
return nil, nil
}
cloudbrains := make([]Cloudbrain, 0)
cloudbrains := make([]*Cloudbrain, 0)
err := x.In("id", ids).Unscoped().Find(&cloudbrains)
if err != nil {
return nil, err
@@ -1930,31 +1884,128 @@ func GetCloudbrainByIds(ids []int64) ([]Cloudbrain, error) {
}

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

}

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
}

+ 8
- 0
models/helper.go View File

@@ -27,3 +27,11 @@ func valuesUser(m map[int64]*User) []*User {
}
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
}

+ 4
- 4
models/reward_admin_log.go View File

@@ -50,18 +50,18 @@ func UpdateRewardAdminLogStatus(logId string, oldStatus, newStatus int) error {
return nil
}

func GetRewardAdminLogByLogIds(logIds []string) ([]RewardAdminLog, error) {
func GetRewardAdminLogByLogIds(logIds []string) ([]*RewardAdminLog, error) {
if len(logIds) == 0 {
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)
if err != nil {
return nil, err
}
r := make([]RewardAdminLog, len(adminLogs))
r := make([]*RewardAdminLog, len(adminLogs))
for i, v := range adminLogs {
temp := v.AdminRewardAdminLog
temp := &v.AdminRewardAdminLog
temp.CreatorName = v.User.Name
r[i] = temp
}


+ 12
- 17
models/reward_operate_record.go View File

@@ -119,7 +119,6 @@ type RewardRecordShowList []*RewardOperateRecordShow

func (l *RewardRecordList) ToShow() (RewardRecordShowList, error) {
actionMap, err := l.GetRewardRecordAction()
adminLogMap, err := l.GetRewardRecordAdminLog()
CloudbrainMap, err := l.GetRewardRecordCloudbrainTask()
if err != nil {
return nil, err
@@ -129,11 +128,9 @@ func (l *RewardRecordList) ToShow() (RewardRecordShowList, error) {
temp := v.ToShow()
switch v.SourceType {
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():
temp.Cloudbrain = CloudbrainMap[v.SourceId]
temp.Cloudbrain = CloudbrainMap[v.SourceId].ToShow()
}
result = append(result, &temp)
}
@@ -141,7 +138,7 @@ func (l *RewardRecordList) ToShow() (RewardRecordShowList, error) {
return result, nil
}

func (l *RewardRecordList) GetRewardRecordAction() (map[string]Action, error) {
func (l *RewardRecordList) GetRewardRecordAction() (map[string]*Action, error) {
if len(*l) == 0 {
return nil, nil
}
@@ -157,15 +154,15 @@ func (l *RewardRecordList) GetRewardRecordAction() (map[string]Action, error) {
if err != nil {
return nil, err
}
result := make(map[string]Action, 0)
result := make(map[string]*Action, 0)
for _, v := range actions {
result[fmt.Sprint(v.ID)] = *v
result[fmt.Sprint(v.ID)] = v
}
return result, nil

}

func (l *RewardRecordList) GetRewardRecordAdminLog() (map[string]RewardAdminLog, error) {
func (l *RewardRecordList) GetRewardRecordAdminLog() (map[string]*RewardAdminLog, error) {
if len(*l) == 0 {
return nil, nil
}
@@ -180,7 +177,7 @@ func (l *RewardRecordList) GetRewardRecordAdminLog() (map[string]RewardAdminLog,
if err != nil {
return nil, err
}
result := make(map[string]RewardAdminLog, 0)
result := make(map[string]*RewardAdminLog, 0)
for _, v := range logs {
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 {
return nil, nil
}
@@ -204,7 +201,7 @@ func (l *RewardRecordList) GetRewardRecordCloudbrainTask() (map[string]Cloudbrai
if err != nil {
return nil, err
}
result := make(map[string]Cloudbrain, 0)
result := make(map[string]*Cloudbrain, 0)
for _, v := range cloudbrains {
result[fmt.Sprint(v.ID)] = v
}
@@ -242,7 +239,6 @@ type AdminRewardOperateReq struct {
func (r RewardOperateRecord) ToShow() RewardOperateRecordShow {
return RewardOperateRecordShow{
SerialNo: r.SerialNo,
CreateDate: r.CreatedUnix,
OperateType: r.OperateType,
Amount: r.Amount,
Remark: r.Remark,
@@ -255,7 +251,6 @@ func (r RewardOperateRecord) ToShow() RewardOperateRecordShow {

type RewardOperateRecordShow struct {
SerialNo string
CreateDate timeutil.TimeStamp
Status string
OperateType string
Amount int64
@@ -263,9 +258,9 @@ type RewardOperateRecordShow struct {
Remark string
SourceType string
LastOperateDate timeutil.TimeStamp
Action Action
Cloudbrain Cloudbrain
AdminLog RewardAdminLog
Action *ActionShow
Cloudbrain *CloudbrainShow
AdminLog *RewardAdminLog
}

func getPointOperateRecord(tl *RewardOperateRecord) (*RewardOperateRecord, error) {


+ 0
- 3
modules/auth/modelarts.go View File

@@ -22,7 +22,6 @@ type CreateModelArtsNotebookForm struct {
Description string `form:"description"`
Flavor string `form:"flavor" 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 {
@@ -47,7 +46,6 @@ type CreateModelArtsTrainJobForm struct {
VersionName string `form:"version_name" binding:"Required"`
FlavorName string `form:"flaver_names" binding:"Required"`
EngineName string `form:"engine_names" binding:"Required"`
ResourceSpecId int `form:"resource_spec_id"`
}

type CreateModelArtsInferenceJobForm struct {
@@ -73,7 +71,6 @@ type CreateModelArtsInferenceJobForm struct {
ModelName string `form:"model_name" binding:"Required"`
ModelVersion string `form:"model_version" 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 {


+ 3
- 2
modules/modelarts/modelarts.go View File

@@ -140,8 +140,9 @@ type VersionInfo struct {

type Flavor 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"`
}



+ 4
- 4
routers/repo/cloudbrain.go View File

@@ -230,7 +230,7 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) {
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)
cloudBrainNewDataPrepare(ctx)
ctx.RenderWithErr(models.ErrInsufficientPointsBalance{}.Error(), tpl, &form)
@@ -318,7 +318,7 @@ func CloudBrainRestart(ctx *context.Context) {
var status = string(models.JobWaiting)
task := ctx.Cloudbrain
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)
resultCode = "-1"
errorMsg = models.ErrInsufficientPointsBalance{}.Error()
@@ -1870,7 +1870,7 @@ func BenchMarkAlgorithmCreate(ctx *context.Context, form auth.CreateCloudBrainFo

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)
cloudBrainNewDataPrepare(ctx)
ctx.RenderWithErr(models.ErrInsufficientPointsBalance{}.Error(), tplCloudBrainBenchmarkNew, &form)
@@ -2032,7 +2032,7 @@ func ModelBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainForm)
tpl := tplCloudBrainBenchmarkNew
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)
cloudBrainNewDataPrepare(ctx)
ctx.RenderWithErr(models.ErrInsufficientPointsBalance{}.Error(), tpl, &form)


+ 7
- 12
routers/repo/modelarts.go View File

@@ -205,10 +205,9 @@ func Notebook2Create(ctx *context.Context, form auth.CreateModelArtsNotebookForm
flavor := form.Flavor
imageId := form.ImageId
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)
ctx.RenderWithErr(models.ErrInsufficientPointsBalance{}.Error(), tplModelArtsNotebookNew, &form)
return
@@ -426,7 +425,7 @@ func NotebookManage(ctx *context.Context) {
errorMsg = "you have no right to restart the job"
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)
resultCode = "-1"
errorMsg = models.ErrInsufficientPointsBalance{}.Error()
@@ -1000,10 +999,9 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm)
FlavorName := form.FlavorName
VersionCount := modelarts.VersionCount
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)
ctx.RenderWithErr(models.ErrInsufficientPointsBalance{}.Error(), tplModelArtsTrainJobNew, &form)
return
@@ -1183,7 +1181,6 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm)
EngineName: EngineName,
VersionCount: VersionCount,
TotalVersionCount: modelarts.TotalVersionCount,
ResourceSpecId: resourceSpecId,
}

//将params转换Parameters.Parameter,出错时返回给前端
@@ -1847,12 +1844,11 @@ func InferenceJobCreate(ctx *context.Context, form auth.CreateModelArtsInference
modelName := form.ModelName
modelVersion := form.ModelVersion
ckptName := form.CkptName
resourceSpecId := form.ResourceSpecId

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)
ctx.RenderWithErr(models.ErrInsufficientPointsBalance{}.Error(), tplModelArtsInferenceJobNew, &form)
return
@@ -2002,7 +1998,6 @@ func InferenceJobCreate(ctx *context.Context, form auth.CreateModelArtsInference
ModelVersion: modelVersion,
CkptName: ckptName,
ResultUrl: resultObsPath,
ResourceSpecId: resourceSpecId,
}

err = modelarts.GenerateInferenceJob(ctx, req)


+ 4
- 4
services/reward/cloubrain_deduct.go View File

@@ -20,9 +20,9 @@ func StartAndGetCloudBrainPointDeductTask(task models.Cloudbrain) (*models.Rewar
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
}

@@ -34,7 +34,7 @@ func StartAndGetCloudBrainPointDeductTask(task models.Cloudbrain) (*models.Rewar
OperateType: models.OperateTypeDecrease,
Delay: setting.CloudBrainPayDelay,
Interval: setting.CloudBrainPayInterval,
UnitAmount: spec.UnitPrice,
UnitAmount: unitPrice,
RewardType: models.RewardTypePoint,
StartTime: time.Unix(int64(task.StartTime), 0),
Tittle: RUN_CLOUDBRAIN_TASK_TITTLE,


+ 10
- 4
services/reward/point/account/point_account.go View File

@@ -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
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 {
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
}
a, err := GetAccount(targetUserId)
@@ -80,6 +86,6 @@ func IsPointBalanceEnough(targetUserId int64, jobType string, resourceSpecId int
log.Error("IsPointBalanceEnough GetAccount error,err=%v", err)
return false
}
return a.Balance >= spec.UnitPrice
return a.Balance >= uniPrice

}

+ 1
- 7
services/task/task.go View File

@@ -9,19 +9,13 @@ import (
)

func Accomplish(action models.Action) {
action.OpType = models.GetTaskOptType(action)
switch action.OpType {
case models.ActionCreateRepo,
models.ActionCreateImage:
if action.Repo.IsPrivate {
return
}
case models.ActionCreateDebugGPUTask,
models.ActionCreateDebugNPUTask,
models.ActionCreateTrainTask,
models.ActionCreateInferenceTask,
models.ActionCreateBenchMarkTask,
models.ActionCreateGPUTrainTask:
action.OpType = models.ActionCreateCloudbrainTask
}
go accomplish(action)
}


Loading…
Cancel
Save