Browse Source

updated resourceSpec

pull/391/head
tzwang 10 months ago
parent
commit
d937c49013
4 changed files with 46 additions and 8 deletions
  1. +2
    -1
      internal/logic/schedule/schedulecreatetasklogic.go
  2. +5
    -0
      internal/scheduler/service/collector/collector.go
  3. +35
    -7
      internal/storeLink/openi.go
  4. +4
    -0
      internal/storeLink/storeLink.go

+ 2
- 1
internal/logic/schedule/schedulecreatetasklogic.go View File

@@ -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)), "")
}
}



+ 5
- 0
internal/scheduler/service/collector/collector.go View File

@@ -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"`


+ 35
- 7
internal/storeLink/openi.go View File

@@ -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}
}
}()



+ 4
- 0
internal/storeLink/storeLink.go View File

@@ -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"


Loading…
Cancel
Save