|
|
|
@@ -1,17 +1,25 @@ |
|
|
|
package octopusHttp |
|
|
|
|
|
|
|
import ( |
|
|
|
"bytes" |
|
|
|
"context" |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"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/service/inference" |
|
|
|
omodel "gitlink.org.cn/JointCloud/pcm-octopus/http/model" |
|
|
|
"gitlink.org.cn/JointCloud/pcm-openi/common" |
|
|
|
"mime/multipart" |
|
|
|
"net/http" |
|
|
|
) |
|
|
|
|
|
|
|
const ( |
|
|
|
RESOURCE_POOL = "common-pool" |
|
|
|
Param_Token = "token" |
|
|
|
Param_Addr = "addr" |
|
|
|
Octopus = "octopus" |
|
|
|
Forward_Slash = "/" |
|
|
|
) |
|
|
|
|
|
|
|
const ( |
|
|
|
@@ -24,18 +32,16 @@ const ( |
|
|
|
) |
|
|
|
|
|
|
|
type OctopusHttp struct { |
|
|
|
server string |
|
|
|
host string |
|
|
|
platform string |
|
|
|
participantId int64 |
|
|
|
token *Token |
|
|
|
} |
|
|
|
|
|
|
|
func NewOctopusHttp(name string, id int64, host string, user string, pwd string) *OctopusHttp { |
|
|
|
token, err := NewToken(host, user, pwd) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err.Error()) |
|
|
|
} |
|
|
|
return &OctopusHttp{platform: name, participantId: id, host: host, token: token} |
|
|
|
func NewOctopusHttp(id int64, name, server, host string, user string, pwd string) *OctopusHttp { |
|
|
|
token, _ := NewToken(host, user, pwd) |
|
|
|
return &OctopusHttp{platform: name, participantId: id, server: server, host: host, token: token} |
|
|
|
} |
|
|
|
|
|
|
|
// executor |
|
|
|
@@ -51,6 +57,71 @@ func (o *OctopusHttp) Stop(ctx context.Context, id string) error { |
|
|
|
|
|
|
|
// collector |
|
|
|
func (o *OctopusHttp) GetResourceStats(ctx context.Context) (*collector.ResourceStats, error) { |
|
|
|
resourcespecsUrl := o.server + Forward_Slash + ResourcespecsUrl |
|
|
|
token, err := o.token.Get() |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
param := omodel.ResourceSpecParam{ |
|
|
|
ResourcePool: RESOURCE_POOL, |
|
|
|
} |
|
|
|
|
|
|
|
b, _ := json.Marshal(param) |
|
|
|
byt := bytes.NewBuffer(b) |
|
|
|
|
|
|
|
resp := struct { |
|
|
|
Code int `json:"code"` |
|
|
|
Msg string `json:"msg"` |
|
|
|
Data interface{} `json:"data"` |
|
|
|
}{} |
|
|
|
|
|
|
|
req := common.GetRestyRequest(common.TIMEOUT) |
|
|
|
r, _ := http.NewRequest("GET", resourcespecsUrl, byt) |
|
|
|
req.RawRequest = r |
|
|
|
req.URL = resourcespecsUrl |
|
|
|
|
|
|
|
_, err = req. |
|
|
|
SetHeader("Content-Type", "application/json"). |
|
|
|
SetQueryParam(Param_Token, token). |
|
|
|
SetQueryParam(Param_Addr, o.host). |
|
|
|
SetBody(byt). |
|
|
|
SetResult(&resp). |
|
|
|
Send() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
if resp.Code != http.StatusOK { |
|
|
|
if resp.Data != nil { |
|
|
|
marshal, err := json.Marshal(resp.Data) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
errormdl := &omodel.Error{} |
|
|
|
err = json.Unmarshal(marshal, errormdl) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
return nil, errors.New(errormdl.Message) |
|
|
|
} |
|
|
|
} else { |
|
|
|
if resp.Data != nil { |
|
|
|
spec := omodel.ResourceSpec{} |
|
|
|
|
|
|
|
marshal, err := json.Marshal(resp.Data) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
err = json.Unmarshal(marshal, &spec.Payload) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return nil, nil |
|
|
|
} |
|
|
|
|
|
|
|
|