Browse Source

updated queryResources

pull/398/head
tzwang 10 months ago
parent
commit
6e14f47471
3 changed files with 28 additions and 41 deletions
  1. +23
    -14
      internal/logic/schedule/queryresourceslogic.go
  2. +0
    -26
      internal/scheduler/service/utils/cache/localCache.go
  3. +5
    -1
      internal/storeLink/octopus.go

+ 23
- 14
internal/logic/schedule/queryresourceslogic.go View File

@@ -45,18 +45,9 @@ func (l *QueryResourcesLogic) QueryResources(req *types.QueryResourcesReq) (resp
if ok {
specs, ok := resources.([]*collector.ResourceSpec)
if ok {
var count int
for _, spec := range specs {
if spec.Resources != nil {
count++
}
}

if len(specs) == count {
results := handleEmptyResourceUsage(cs.List, specs)
resp.Data = results
return resp, nil
}
results := handleEmptyResourceUsage(cs.List, specs)
resp.Data = results
return resp, nil
}
}

@@ -65,7 +56,10 @@ func (l *QueryResourcesLogic) QueryResources(req *types.QueryResourcesReq) (resp
return nil, err
}

l.svcCtx.Scheduler.AiService.LocalCache[QUERY_RESOURCES] = rus
if checkCachingCondition(cs.List, rus) {
l.svcCtx.Scheduler.AiService.LocalCache[QUERY_RESOURCES] = rus
}

results := handleEmptyResourceUsage(cs.List, rus)
resp.Data = results

@@ -187,7 +181,7 @@ func handleEmptyResourceUsage(list []types.ClusterInfo, ulist []*collector.Resou
} else {
r, ok := s.(*collector.ResourceSpec)
if ok {
if r.Resources == nil {
if r.Resources == nil || len(r.Resources) == 0 {
ru := &collector.ResourceSpec{
ClusterId: r.ClusterId,
Resources: nil,
@@ -209,3 +203,18 @@ func handleEmptyResourceUsage(list []types.ClusterInfo, ulist []*collector.Resou

return rus
}

func checkCachingCondition(clusters []types.ClusterInfo, specs []*collector.ResourceSpec) bool {
var count int
for _, spec := range specs {
if spec.Resources != nil {
count++
}
}

if count == len(clusters) {
return true
}

return false
}

+ 0
- 26
internal/scheduler/service/utils/cache/localCache.go View File

@@ -1,31 +1,5 @@
package localcache

import (
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/schedule"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/collector"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
)

func UpdateQueryResourcesCache(svc *svc.ServiceContext, q *schedule.QueryResourcesLogic) {
cres := make([]*collector.ResourceSpec, 0)
resources, err := q.QueryResourcesByClusterId(nil)
if err != nil {
return
}
if len(resources) != 0 {
for _, resource := range resources {
if resource.Resources == nil {
continue
}
cres = append(cres, resource)
}
}

if len(cres) != 0 {
svc.Scheduler.AiService.LocalCache[schedule.QUERY_RESOURCES] = cres
}
}

func Invalidate(localCache map[string]interface{}, key string) {
delete(localCache, key)
}

+ 5
- 1
internal/storeLink/octopus.go View File

@@ -1280,7 +1280,11 @@ func (o *OctopusLink) CheckModelExistence(ctx context.Context, name string, mtyp
}

func (o *OctopusLink) GetResourceSpecs(ctx context.Context) (*collector.ResourceSpec, error) {
return nil, nil
res := &collector.ResourceSpec{
ClusterId: strconv.FormatInt(o.participantId, 10),
Resources: make([]interface{}, 0),
}
return res, nil
}

func (o *OctopusLink) Stop(ctx context.Context, id string) error {


Loading…
Cancel
Save