|
|
|
@@ -15,6 +15,7 @@ import ( |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"sync" |
|
|
|
"sync/atomic" |
|
|
|
) |
|
|
|
|
|
|
|
const ( |
|
|
|
@@ -123,11 +124,17 @@ func (o OpenI) GetResourceSpecs(ctx context.Context) (*collector.ResourceSpec, e |
|
|
|
res := &collector.ResourceSpec{ |
|
|
|
ClusterId: strconv.FormatInt(o.participantId, 10), |
|
|
|
} |
|
|
|
url := o.host + "/api/v1/task/creationRequired" |
|
|
|
creationRequirelUrl := o.host + "/api/v1/task/creationRequired" |
|
|
|
reposUrl := o.host + "/api/v1/user/repos" |
|
|
|
taskListUrl := o.host + "/api/v1/task/list" |
|
|
|
//taskDetailsUrl := o.host + "/api/v1/task/detail" |
|
|
|
|
|
|
|
var wg sync.WaitGroup |
|
|
|
var ch = make(chan *collector.Usage) |
|
|
|
defer close(ch) |
|
|
|
|
|
|
|
var once sync.Once |
|
|
|
|
|
|
|
for c := range ComputeSource { |
|
|
|
wg.Add(1) |
|
|
|
i := c |
|
|
|
@@ -151,9 +158,9 @@ func (o OpenI) GetResourceSpecs(ctx context.Context) (*collector.ResourceSpec, e |
|
|
|
}{} |
|
|
|
|
|
|
|
req := common.GetRestyRequest(common.TIMEOUT) |
|
|
|
r, _ := http.NewRequest("GET", url, byt) |
|
|
|
r, _ := http.NewRequest("GET", creationRequirelUrl, byt) |
|
|
|
req.RawRequest = r |
|
|
|
req.URL = url |
|
|
|
req.URL = creationRequirelUrl |
|
|
|
|
|
|
|
_, err := req. |
|
|
|
SetHeader("Content-Type", "application/json"). |
|
|
|
@@ -170,6 +177,24 @@ func (o OpenI) GetResourceSpecs(ctx context.Context) (*collector.ResourceSpec, e |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// balance |
|
|
|
wg.Add(1) |
|
|
|
go func() { |
|
|
|
defer wg.Done() |
|
|
|
var balanceCheck = func() { |
|
|
|
balance := resp.Data.Data.PointAccount.Balance |
|
|
|
bal := &collector.Usage{} |
|
|
|
bal.Type = strings.ToUpper(BALANCE) |
|
|
|
bal.Total = &collector.UnitValue{ |
|
|
|
Unit: POINT, |
|
|
|
Value: balance, |
|
|
|
} |
|
|
|
|
|
|
|
ch <- bal |
|
|
|
} |
|
|
|
once.Do(balanceCheck) |
|
|
|
}() |
|
|
|
|
|
|
|
m := make(map[string]struct { |
|
|
|
Id int `json:"id"` |
|
|
|
AccCardsNum int `json:"acc_cards_num"` |
|
|
|
@@ -209,12 +234,108 @@ func (o OpenI) GetResourceSpecs(ctx context.Context) (*collector.ResourceSpec, e |
|
|
|
}() |
|
|
|
} |
|
|
|
|
|
|
|
// tasks |
|
|
|
var jch = make(chan *collector.Usage, 1) |
|
|
|
wg.Add(1) |
|
|
|
go func() { |
|
|
|
defer close(jch) |
|
|
|
defer wg.Done() |
|
|
|
reporesp := struct { |
|
|
|
Code int `json:"code"` |
|
|
|
Msg string `json:"msg"` |
|
|
|
Data []model.Repo `json:"data"` |
|
|
|
}{} |
|
|
|
|
|
|
|
reporeq := common.GetRestyRequest(common.TIMEOUT) |
|
|
|
repor, _ := http.NewRequest("GET", reposUrl, nil) |
|
|
|
reporeq.RawRequest = repor |
|
|
|
reporeq.URL = reposUrl |
|
|
|
|
|
|
|
_, err := reporeq. |
|
|
|
SetHeader("Content-Type", "application/json"). |
|
|
|
SetQueryParam(common.ACCESSTOKEN, o.accessToken). |
|
|
|
SetResult(&reporesp). |
|
|
|
Send() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if len(reporesp.Data) == 0 { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
var runningJobs atomic.Int64 |
|
|
|
var jwg sync.WaitGroup |
|
|
|
for _, datum := range reporesp.Data { |
|
|
|
jwg.Add(1) |
|
|
|
dat := datum |
|
|
|
go func() { |
|
|
|
defer jwg.Done() |
|
|
|
param := model.TaskListParam{ |
|
|
|
UserName: o.userName, |
|
|
|
RepoName: dat.Name, |
|
|
|
} |
|
|
|
|
|
|
|
b, _ := json.Marshal(param) |
|
|
|
byt := bytes.NewBuffer(b) |
|
|
|
|
|
|
|
resp := struct { |
|
|
|
Code int `json:"code"` |
|
|
|
Msg string `json:"msg"` |
|
|
|
Data model.TaskList `json:"data"` |
|
|
|
}{} |
|
|
|
|
|
|
|
req := common.GetRestyRequest(common.TIMEOUT) |
|
|
|
r, _ := http.NewRequest("GET", taskListUrl, byt) |
|
|
|
req.RawRequest = r |
|
|
|
req.URL = taskListUrl |
|
|
|
|
|
|
|
_, 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.Tasks) == 0 { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
for _, task := range resp.Data.Data.Tasks { |
|
|
|
if task.Task.Status == RUNNING { |
|
|
|
runningJobs.Add(1) |
|
|
|
} |
|
|
|
} |
|
|
|
}() |
|
|
|
} |
|
|
|
jwg.Wait() |
|
|
|
|
|
|
|
run := &collector.Usage{} |
|
|
|
run.Type = strings.ToUpper(RUNNING) |
|
|
|
run.Total = &collector.UnitValue{ |
|
|
|
Unit: NUMBER, |
|
|
|
Value: runningJobs.Load(), |
|
|
|
} |
|
|
|
|
|
|
|
jch <- run |
|
|
|
|
|
|
|
}() |
|
|
|
|
|
|
|
go func() { |
|
|
|
for v := range ch { |
|
|
|
resources = append(resources, v) |
|
|
|
} |
|
|
|
}() |
|
|
|
|
|
|
|
for v := range jch { |
|
|
|
resources = append(resources, v) |
|
|
|
} |
|
|
|
|
|
|
|
wg.Wait() |
|
|
|
|
|
|
|
res.Resources = resources |
|
|
|
|