Browse Source

update createTask

undefined
tzwang 11 months ago
parent
commit
94d11d6d68
3 changed files with 62 additions and 25 deletions
  1. +4
    -4
      internal/logic/schedule/queryresourceslogic.go
  2. +47
    -7
      internal/logic/schedule/schedulecreatetasklogic.go
  3. +11
    -14
      internal/storeLink/openi.go

+ 4
- 4
internal/logic/schedule/queryresourceslogic.go View File

@@ -14,6 +14,10 @@ import (
"time"
)

const (
ADAPTERID = "1777144940459986944" // 异构适配器id
)

type QueryResourcesLogic struct {
logx.Logger
ctx context.Context
@@ -28,10 +32,6 @@ func NewQueryResourcesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Qu
}
}

const (
ADAPTERID = "1777144940459986944" // 异构适配器id
)

func (l *QueryResourcesLogic) QueryResources(req *types.QueryResourcesReq) (resp *types.QueryResourcesResp, err error) {
resp = &types.QueryResourcesResp{}
rus, err := l.queryResources(req.ClusterIDs)


+ 47
- 7
internal/logic/schedule/schedulecreatetasklogic.go View File

@@ -6,6 +6,7 @@ import (
"fmt"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/common"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/schedulers/option"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/collector"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/strategy"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/storeLink"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
@@ -14,6 +15,7 @@ import (
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"slices"
"strings"
"time"

"github.com/zeromicro/go-zero/core/logx"
)
@@ -21,6 +23,7 @@ import (
const (
TRAINNING_TASK_REPLICA = 1
TRAINNING_TASK_SUFFIX_LEN = 10
QUERY_RESOURCE_RETRY = 3
)

type ScheduleCreateTaskLogic struct {
@@ -70,6 +73,10 @@ func (l *ScheduleCreateTaskLogic) ScheduleCreateTask(req *types.CreateTaskReq) (
return nil, err
}

if len(clusterInfos) == 0 {
return nil, fmt.Errorf("failed to create task, no scheduled cluster found")
}

for _, info := range clusterInfos {
clusters = append(clusters, info.ClusterID)
}
@@ -89,26 +96,59 @@ func (l *ScheduleCreateTaskLogic) ScheduleCreateTask(req *types.CreateTaskReq) (
}

func (l *ScheduleCreateTaskLogic) getClusterInfosByStrategy(resources *types.JobResources) ([]*types.JobClusterInfo, error) {
cResources, err := l.queryResource.queryResources(make([]string, 0))
if err != nil {
return nil, err

var resSpecs []*collector.ResourceSpec
var resCount int
for i := 0; i < QUERY_RESOURCE_RETRY; i++ {
defer time.Sleep(time.Second)
qResources, err := l.queryResource.queryResources(make([]string, 0))
if err != nil {
continue
}

for _, resource := range qResources {
if resource.Resources != nil {
resCount++
}
}

if resCount >= 1 {
resSpecs = qResources
break
} else {
resCount = 0
continue
}
}

if resCount == 0 {
return nil, fmt.Errorf("failed to create task, resources counting fails")
}

var clusterInfos []*types.JobClusterInfo
switch resources.ScheduleStrategy {
case strategy.LEASTLOADFIRST:
strtg := strategy.NewLeastLoadFirst(TRAINNING_TASK_REPLICA, cResources)
strtg := strategy.NewLeastLoadFirst(TRAINNING_TASK_REPLICA, resSpecs)
clusters, err := strtg.Schedule()
if err != nil {
return nil, err
}
clusterInfos = genClusterInfos(clusters, resources.Clusters)
clusterInfos = filterClusterInfos(clusters, resources.Clusters)
}

return clusterInfos, nil
}

func genClusterInfos(clusters []*strategy.AssignedCluster, clusterInfos []*types.JobClusterInfo) []*types.JobClusterInfo {
return nil
func filterClusterInfos(clusters []*strategy.AssignedCluster, clusterInfos []*types.JobClusterInfo) []*types.JobClusterInfo {
var result []*types.JobClusterInfo
for _, cinfo := range clusterInfos {
for _, c := range clusters {
if cinfo.ClusterID == c.ClusterId {
result = append(result, cinfo)
}
}
}
return result
}

func (l *ScheduleCreateTaskLogic) createTask(taskName string, strategyName string, jobClusterInfo []*types.JobClusterInfo) (int64, error) {


+ 11
- 14
internal/storeLink/openi.go View File

@@ -132,7 +132,7 @@ func (o OpenI) GetResourceSpecs(ctx context.Context) (*collector.ResourceSpec, e
var wg sync.WaitGroup
var ch = make(chan *collector.Usage)
var once sync.Once
wg.Add(3)
wg.Add(2)

go func() {
defer wg.Done()
@@ -189,6 +189,16 @@ func (o OpenI) GetResourceSpecs(ctx context.Context) (*collector.ResourceSpec, e
}

ch <- bal

//rate
var v float64
v = 1
rate := &collector.Usage{
Type: strings.ToUpper(RATE),
Total: &collector.UnitValue{Unit: PERHOUR, Value: v},
}

ch <- rate
}
once.Do(balanceCheck)

@@ -349,19 +359,6 @@ func (o OpenI) GetResourceSpecs(ctx context.Context) (*collector.ResourceSpec, e
}
}()

// rate
go func() {
defer wg.Done()
var v float64
v = 1
rate := &collector.Usage{
Type: strings.ToUpper(RATE),
Total: &collector.UnitValue{Unit: PERHOUR, Value: v},
}

ch <- rate
}()

go func() {
wg.Wait()
close(ch)


Loading…
Cancel
Save