From d937c4901325e5c074369c906ab6c08cc83e7534 Mon Sep 17 00:00:00 2001 From: tzwang Date: Wed, 8 Jan 2025 15:53:54 +0800 Subject: [PATCH] updated resourceSpec --- .../logic/schedule/schedulecreatetasklogic.go | 3 +- .../scheduler/service/collector/collector.go | 5 +++ internal/storeLink/openi.go | 42 +++++++++++++++---- internal/storeLink/storeLink.go | 4 ++ 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/internal/logic/schedule/schedulecreatetasklogic.go b/internal/logic/schedule/schedulecreatetasklogic.go index 4e6f22c2..82366dbd 100644 --- a/internal/logic/schedule/schedulecreatetasklogic.go +++ b/internal/logic/schedule/schedulecreatetasklogic.go @@ -2,8 +2,8 @@ package schedule import ( "context" - "errors" "fmt" + "github.com/pkg/errors" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/common" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/collector" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/strategy" @@ -113,6 +113,7 @@ func validateJobResources(resources types.JobResources) error { if len(c.Resources) == 0 { return fmt.Errorf("cluster: %s must specify at least one compute resource", c.ClusterID) + //return errors.Wrapf(xerr.NewErrCodeMsg(1234, fmt.Sprintf("cluster: %s must specify at least one compute resource", c.ClusterID)), "") } } diff --git a/internal/scheduler/service/collector/collector.go b/internal/scheduler/service/collector/collector.go index 32654c5f..d6172788 100644 --- a/internal/scheduler/service/collector/collector.go +++ b/internal/scheduler/service/collector/collector.go @@ -25,6 +25,11 @@ type ResourceSpec struct { Msg string `json:"msg"` } +type ClusterResource struct { + Resource *Usage `json:"resource"` + BaseResources []*Usage `json:"baseResources,omitempty"` +} + type UnitValue struct { Unit string `json:"unit"` Value interface{} `json:"value"` diff --git a/internal/storeLink/openi.go b/internal/storeLink/openi.go index 56889ddf..e20b0484 100644 --- a/internal/storeLink/openi.go +++ b/internal/storeLink/openi.go @@ -488,12 +488,13 @@ func (o OpenI) GetResourceSpecs(ctx context.Context) (*collector.ResourceSpec, e res := &collector.ResourceSpec{ ClusterId: strconv.FormatInt(o.participantId, 10), } + //clres := &collector.ClusterResource{} creationRequirelUrl := o.host + CreationRequirelUrl reposUrl := o.host + ReposUrl taskListUrl := o.host + TaskListUrl var wg sync.WaitGroup - var ch = make(chan *collector.Usage) + var ch = make(chan *collector.ClusterResource) var once sync.Once wg.Add(2) @@ -551,7 +552,7 @@ func (o OpenI) GetResourceSpecs(ctx context.Context) (*collector.ResourceSpec, e Value: balance, } - ch <- bal + ch <- &collector.ClusterResource{Resource: bal} //rate var v float64 @@ -561,7 +562,7 @@ func (o OpenI) GetResourceSpecs(ctx context.Context) (*collector.ResourceSpec, e Total: &collector.UnitValue{Unit: PERHOUR, Value: v}, } - ch <- rate + ch <- &collector.ClusterResource{Resource: rate} } once.Do(balanceCheck) @@ -592,13 +593,40 @@ func (o OpenI) GetResourceSpecs(ctx context.Context) (*collector.ResourceSpec, e } for k, v := range m { - u := &collector.Usage{ + bres := make([]*collector.Usage, 0) + cres := &collector.ClusterResource{} + card := &collector.Usage{ Type: ComputeSource[i], Name: strings.ToUpper(k), Total: &collector.UnitValue{Unit: NUMBER, Value: v.AccCardsNum}, Available: &collector.UnitValue{Unit: NUMBER, Value: v.AccCardsNum}, } - ch <- u + cpu := &collector.Usage{ + Type: strings.ToUpper(CPU), + Name: strings.ToUpper(CPU), + Total: &collector.UnitValue{Unit: CPUCORE, Value: v.CpuCores}, + Available: &collector.UnitValue{Unit: CPUCORE, Value: v.CpuCores}, + } + mem := &collector.Usage{ + Type: strings.ToUpper(MEMORY), + Name: strings.ToUpper(RAM), + Total: &collector.UnitValue{Unit: CPUCORE, Value: v.MemGiB}, + Available: &collector.UnitValue{Unit: CPUCORE, Value: v.MemGiB}, + } + vmem := &collector.Usage{ + Type: strings.ToUpper(MEMORY), + Name: strings.ToUpper(VRAM), + Total: &collector.UnitValue{Unit: CPUCORE, Value: v.GpuMemGiB}, + Available: &collector.UnitValue{Unit: CPUCORE, Value: v.GpuMemGiB}, + } + bres = append(bres, cpu) + bres = append(bres, mem) + bres = append(bres, vmem) + + cres.Resource = card + cres.BaseResources = bres + + ch <- cres } }() } @@ -710,7 +738,7 @@ func (o OpenI) GetResourceSpecs(ctx context.Context) (*collector.ResourceSpec, e Value: runningNum, } - ch <- run + ch <- &collector.ClusterResource{Resource: run} } else { runningNum = int64(len(errs)) * 4 run.Total = &collector.UnitValue{ @@ -718,7 +746,7 @@ func (o OpenI) GetResourceSpecs(ctx context.Context) (*collector.ResourceSpec, e Value: runningNum, } - ch <- run + ch <- &collector.ClusterResource{Resource: run} } }() diff --git a/internal/storeLink/storeLink.go b/internal/storeLink/storeLink.go index a7a5fac2..98aa8fbf 100644 --- a/internal/storeLink/storeLink.go +++ b/internal/storeLink/storeLink.go @@ -76,9 +76,13 @@ const ( PERHOUR = "per-hour" NUMBER = "number" KILOBYTE = "kb" + GIGABYTE = "gb" CPUCORE = "core" STORAGE = "STORAGE" DISK = "disk" + MEMORY = "memory" + RAM = "ram" + VRAM = "vram" RMB = "rmb" POINT = "point" RUNNINGTASK = "RUNNING_TASK"