|
|
@@ -141,6 +141,37 @@ func (r ResourceSpecAndQueue) ConvertToRes() *ResourceSpecAndQueueRes { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
type FindSpecsOptions struct { |
|
|
|
JobType JobType |
|
|
|
ComputeResource string |
|
|
|
Cluster string |
|
|
|
AiCenterCode string |
|
|
|
} |
|
|
|
|
|
|
|
type Specification struct { |
|
|
|
ID int64 |
|
|
|
SourceSpecId string |
|
|
|
AccCardsNum int |
|
|
|
AccCardType string |
|
|
|
CpuCores int |
|
|
|
MemGiB float32 |
|
|
|
GPUMemGiB float32 |
|
|
|
ShareMemGiB float32 |
|
|
|
ComputeResource string |
|
|
|
UnitPrice int |
|
|
|
QueueId int64 |
|
|
|
QueueCode string |
|
|
|
Cluster string |
|
|
|
AiCenterCode string |
|
|
|
AiCenterName string |
|
|
|
IsExclusive bool |
|
|
|
ExclusiveOrg string |
|
|
|
} |
|
|
|
|
|
|
|
func (Specification) TableName() string { |
|
|
|
return "resource_specification" |
|
|
|
} |
|
|
|
|
|
|
|
func InsertResourceSpecification(r ResourceSpecification) (int64, error) { |
|
|
|
return x.Insert(&r) |
|
|
|
} |
|
|
@@ -283,3 +314,32 @@ func SyncGrampusSpecs(updateList []ResourceSpecification, insertList []ResourceS |
|
|
|
|
|
|
|
return sess.Commit() |
|
|
|
} |
|
|
|
|
|
|
|
func FindAvailableSpecs(opts FindSpecsOptions) ([]Specification, error) { |
|
|
|
var cond = builder.NewCond() |
|
|
|
if opts.JobType != "" { |
|
|
|
cond = cond.And(builder.Eq{"resource_scene.job_type": opts.JobType}) |
|
|
|
} |
|
|
|
if opts.ComputeResource != "" { |
|
|
|
cond = cond.And(builder.Eq{"resource_queue.compute_resource": opts.ComputeResource}) |
|
|
|
} |
|
|
|
if opts.ComputeResource != "" { |
|
|
|
cond = cond.And(builder.Eq{"resource_queue.cluster": opts.Cluster}) |
|
|
|
} |
|
|
|
if opts.AiCenterCode != "" { |
|
|
|
cond = cond.And(builder.Eq{"resource_queue.ai_center_code": opts.AiCenterCode}) |
|
|
|
} |
|
|
|
cond = cond.And(builder.Or(builder.Eq{"resource_scene.delete_time": 0}, builder.IsNull{"resource_scene.delete_time"})) |
|
|
|
|
|
|
|
r := make([]Specification, 0) |
|
|
|
err := x.Where(cond). |
|
|
|
Join("INNER", "resource_scene_spec", "resource_scene_spec.spec_id = resource_specification.id"). |
|
|
|
Join("INNER", "resource_scene", "resource_scene_spec.scene_id = resource_scene.id"). |
|
|
|
Join("INNER", "resource_queue", "resource_queue.id = resource_specification.queue_id"). |
|
|
|
OrderBy("resource_queue.compute_resource asc,resource_queue.acc_card_type asc,resource_specification.acc_cards_num asc"). |
|
|
|
Unscoped().Find(&r) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
return r, nil |
|
|
|
} |