|
|
|
@@ -1,10 +1,16 @@ |
|
|
|
package storeLink |
|
|
|
|
|
|
|
import ( |
|
|
|
"bytes" |
|
|
|
"context" |
|
|
|
"encoding/json" |
|
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/collector" |
|
|
|
"gitlink.org.cn/JointCloud/pcm-openi/common" |
|
|
|
"gitlink.org.cn/JointCloud/pcm-openi/model" |
|
|
|
"net/http" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"sync" |
|
|
|
) |
|
|
|
|
|
|
|
const ( |
|
|
|
@@ -42,31 +48,8 @@ func (o OpenI) GetResourceStats(ctx context.Context) (*collector.ResourceStats, |
|
|
|
} |
|
|
|
|
|
|
|
func (o OpenI) GetDatasetsSpecs(ctx context.Context) ([]*collector.DatasetsSpecs, error) { |
|
|
|
var specs []*collector.DatasetsSpecs |
|
|
|
var url string |
|
|
|
|
|
|
|
for _ = range ComputeSource { |
|
|
|
param := model.TaskCreationRequiredParam{} |
|
|
|
resp := model.TaskCreationRequired{} |
|
|
|
go func() { |
|
|
|
req := common.GetRestyRequest(common.TIMEOUT) |
|
|
|
_, err := req. |
|
|
|
SetBody(param). |
|
|
|
SetQueryParam(common.ACCESSTOKEN, o.accessToken). |
|
|
|
SetResult(&resp). |
|
|
|
Get(url) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
spec := &collector.DatasetsSpecs{} |
|
|
|
specs = append(specs, spec) |
|
|
|
}() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return specs, nil |
|
|
|
//TODO implement me |
|
|
|
panic("implement me") |
|
|
|
} |
|
|
|
|
|
|
|
func (o OpenI) GetAlgorithms(ctx context.Context) ([]*collector.Algorithm, error) { |
|
|
|
@@ -105,6 +88,103 @@ func (o OpenI) GetUserBalance(ctx context.Context) (float64, error) { |
|
|
|
} |
|
|
|
|
|
|
|
func (o OpenI) GetResourceSpecs(ctx context.Context) (*collector.ResourceSpec, error) { |
|
|
|
//TODO implement me |
|
|
|
panic("implement me") |
|
|
|
var resources []interface{} |
|
|
|
res := &collector.ResourceSpec{ |
|
|
|
ClusterId: strconv.FormatInt(o.participantId, 10), |
|
|
|
} |
|
|
|
url := o.host + "/api/v1/task/creationRequired" |
|
|
|
var wg sync.WaitGroup |
|
|
|
var ch = make(chan *collector.Usage) |
|
|
|
|
|
|
|
for c := range ComputeSource { |
|
|
|
wg.Add(1) |
|
|
|
i := c |
|
|
|
go func() { |
|
|
|
defer wg.Done() |
|
|
|
param := model.TaskCreationRequiredParam{ |
|
|
|
UserName: o.userName, |
|
|
|
RepoName: TESTREPO, |
|
|
|
JobType: TRAIN, |
|
|
|
ComputeSource: ComputeSource[i], |
|
|
|
ClusterType: C2NET, |
|
|
|
} |
|
|
|
|
|
|
|
b, _ := json.Marshal(param) |
|
|
|
byt := bytes.NewBuffer(b) |
|
|
|
|
|
|
|
resp := struct { |
|
|
|
Code int `json:"code"` |
|
|
|
Msg string `json:"msg"` |
|
|
|
Data model.TaskCreationRequired `json:"data"` |
|
|
|
}{} |
|
|
|
|
|
|
|
req := common.GetRestyRequest(common.TIMEOUT) |
|
|
|
r, _ := http.NewRequest("GET", url, byt) |
|
|
|
req.RawRequest = r |
|
|
|
req.URL = url |
|
|
|
|
|
|
|
_, err := req. |
|
|
|
SetHeader("Content-Type", "application/json"). |
|
|
|
SetQueryParam(common.ACCESSTOKEN, o.accessToken). |
|
|
|
SetBody(byt). |
|
|
|
SetResult(&resp). |
|
|
|
Send() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if len(resp.Data.Data.Specs.All) == 0 { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
m := make(map[string]struct { |
|
|
|
Id int `json:"id"` |
|
|
|
AccCardsNum int `json:"acc_cards_num"` |
|
|
|
AccCardType string `json:"acc_card_type"` |
|
|
|
CpuCores int `json:"cpu_cores"` |
|
|
|
MemGiB int `json:"mem_gi_b"` |
|
|
|
GpuMemGiB int `json:"gpu_mem_gi_b"` |
|
|
|
ShareMemGiB int `json:"share_mem_gi_b"` |
|
|
|
ComputeResource string `json:"compute_resource"` |
|
|
|
UnitPrice int `json:"unit_price"` |
|
|
|
SourceSpecId string `json:"source_spec_id"` |
|
|
|
HasInternet int `json:"has_internet"` |
|
|
|
EnableVisualization bool `json:"enable_visualization"` |
|
|
|
}) |
|
|
|
|
|
|
|
for _, s := range resp.Data.Data.Specs.All { |
|
|
|
e, ok := m[s.AccCardType] |
|
|
|
if ok { |
|
|
|
if s.AccCardsNum > e.AccCardsNum { |
|
|
|
m[s.AccCardType] = s |
|
|
|
} |
|
|
|
} else { |
|
|
|
m[s.AccCardType] = s |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for k, v := range m { |
|
|
|
u := &collector.Usage{ |
|
|
|
Type: strings.ToUpper(k), |
|
|
|
Total: v.AccCardsNum, |
|
|
|
Available: v.AccCardsNum, |
|
|
|
} |
|
|
|
ch <- u |
|
|
|
} |
|
|
|
|
|
|
|
}() |
|
|
|
} |
|
|
|
|
|
|
|
go func() { |
|
|
|
for v := range ch { |
|
|
|
resources = append(resources, v) |
|
|
|
} |
|
|
|
}() |
|
|
|
|
|
|
|
wg.Wait() |
|
|
|
|
|
|
|
res.Resource = resources |
|
|
|
|
|
|
|
return res, nil |
|
|
|
} |