|
|
|
@@ -23,6 +23,7 @@ type ResourceSpecification struct { |
|
|
|
ShareMemGiB float32 |
|
|
|
UnitPrice int |
|
|
|
Status int |
|
|
|
IsAvailable bool |
|
|
|
IsAutomaticSync bool |
|
|
|
CreatedTime timeutil.TimeStamp `xorm:"created"` |
|
|
|
CreatedBy int64 |
|
|
|
@@ -41,6 +42,7 @@ func (r ResourceSpecification) ConvertToRes() *ResourceSpecificationRes { |
|
|
|
GPUMemGiB: r.GPUMemGiB, |
|
|
|
UnitPrice: r.UnitPrice, |
|
|
|
Status: r.Status, |
|
|
|
IsAvailable: r.IsAvailable, |
|
|
|
UpdatedTime: r.UpdatedTime, |
|
|
|
} |
|
|
|
} |
|
|
|
@@ -73,14 +75,16 @@ func (r ResourceSpecificationReq) ToDTO() ResourceSpecification { |
|
|
|
IsAutomaticSync: r.IsAutomaticSync, |
|
|
|
CreatedBy: r.CreatorId, |
|
|
|
UpdatedBy: r.CreatorId, |
|
|
|
IsAvailable: true, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
type SearchResourceSpecificationOptions struct { |
|
|
|
ListOptions |
|
|
|
QueueId int64 |
|
|
|
Status int |
|
|
|
Cluster string |
|
|
|
QueueId int64 |
|
|
|
Status int |
|
|
|
Cluster string |
|
|
|
AvailableCode int |
|
|
|
} |
|
|
|
|
|
|
|
type SearchResourceBriefSpecificationOptions struct { |
|
|
|
@@ -114,6 +118,7 @@ type ResourceSpecificationRes struct { |
|
|
|
ShareMemGiB float32 |
|
|
|
UnitPrice int |
|
|
|
Status int |
|
|
|
IsAvailable bool |
|
|
|
UpdatedTime timeutil.TimeStamp |
|
|
|
} |
|
|
|
|
|
|
|
@@ -215,6 +220,11 @@ func SearchResourceSpecification(opts SearchResourceSpecificationOptions) (int64 |
|
|
|
if opts.Cluster != "" { |
|
|
|
cond = cond.And(builder.Eq{"resource_queue.cluster": opts.Cluster}) |
|
|
|
} |
|
|
|
if opts.AvailableCode == 1 { |
|
|
|
cond = cond.And(builder.Eq{"resource_specification.is_available": true}) |
|
|
|
} else if opts.AvailableCode == 2 { |
|
|
|
cond = cond.And(builder.Eq{"resource_specification.is_available": false}) |
|
|
|
} |
|
|
|
//cond = cond.And(builder.Or(builder.Eq{"resource_queue.deleted_time": 0}).Or(builder.IsNull{"resource_queue.deleted_time"})) |
|
|
|
n, err := x.Where(cond).Join("INNER", "resource_queue", "resource_queue.ID = resource_specification.queue_id"). |
|
|
|
Unscoped().Count(&ResourceSpecAndQueue{}) |
|
|
|
@@ -304,7 +314,7 @@ func SyncGrampusSpecs(updateList []ResourceSpecification, insertList []ResourceS |
|
|
|
return err |
|
|
|
} |
|
|
|
if len(deleteIds) > 0 { |
|
|
|
if _, err = sess.In("id", deleteIds).Update(&ResourceSpecification{Status: SpecOffShelf}); err != nil { |
|
|
|
if _, err = sess.Cols("status", "is_available").In("id", deleteIds).Update(&ResourceSpecification{Status: SpecOffShelf, IsAvailable: false}); err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if _, err = sess.In("spec_id", deleteIds).Delete(&ResourceSceneSpec{}); err != nil { |
|
|
|
@@ -315,7 +325,7 @@ func SyncGrampusSpecs(updateList []ResourceSpecification, insertList []ResourceS |
|
|
|
//update exists specs |
|
|
|
if len(updateList) > 0 { |
|
|
|
for _, v := range updateList { |
|
|
|
if _, err = sess.ID(v.ID).Update(&v); err != nil { |
|
|
|
if _, err = sess.ID(v.ID).UseBool("is_available").Update(&v); err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|