From 657dec1d0bbe25c85e5672f86179302c0cce9c76 Mon Sep 17 00:00:00 2001 From: JeshuaRen <270813223@qq.com> Date: Fri, 30 Aug 2024 17:07:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E5=88=97=E8=A1=A8=E7=AD=89=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sdks/scheduler/modeljob.go | 145 +++++++++++++++++++++++++++++++++++++ sdks/scheduler/models.go | 12 ++- sdks/scheduler/response.go | 26 ------- 3 files changed, 153 insertions(+), 30 deletions(-) create mode 100644 sdks/scheduler/modeljob.go delete mode 100644 sdks/scheduler/response.go diff --git a/sdks/scheduler/modeljob.go b/sdks/scheduler/modeljob.go new file mode 100644 index 0000000..12545e9 --- /dev/null +++ b/sdks/scheduler/modeljob.go @@ -0,0 +1,145 @@ +package schsdk + +import ( + "fmt" + "gitlink.org.cn/cloudream/common/consts/errorcode" + "gitlink.org.cn/cloudream/common/pkgs/mq" + myhttp "gitlink.org.cn/cloudream/common/utils/http" + "gitlink.org.cn/cloudream/common/utils/serder" + "net/url" + "strings" +) + +// 这个结构体无任何字段,但实现了Noop,每种MessageBody都要内嵌这个结构体 +type MessageBodyBase struct{} + +// 此处的receiver是指针 +func (b *MessageBodyBase) Noop() {} + +type RunningModelResp struct { + MessageBodyBase + RunningModels map[string]RunningModelInfo `json:"allNode"` +} + +type NodeInfo struct { + MessageBodyBase + InstanceID JobID `json:"instanceID"` + //NodeID NodeID `json:"nodeID"` + Address Address `json:"address"` + Status string `json:"status"` +} + +type RunningModelInfo struct { + MessageBodyBase + JobSetID JobSetID `json:"jobSetID"` + ModelID ModelID `json:"modelID"` + ModelName ModelName `json:"modelName"` + CustomModelName ModelName `json:"customModelName"` + Nodes []NodeInfo `json:"nodes"` +} + +type ECSNodeRunningInfoReq struct { + mq.MessageBodyBase + CustomModelName ModelName `form:"customModelName" json:"customModelName" binding:"required"` + ModelID ModelID `form:"modelID" json:"modelID" binding:"required"` +} + +type ECSNodeRunningInfoResp struct { + MessageBodyBase + NodeUsageRateInfos []NodeUsageRateInfo `json:"nodeUsageRateInfos"` +} + +func NewECSNodeRunningInfoResp(nodeUsageRateInfos []NodeUsageRateInfo) *ECSNodeRunningInfoResp { + return &ECSNodeRunningInfoResp{ + NodeUsageRateInfos: nodeUsageRateInfos, + } +} + +type NodeUsageRateInfo struct { + MessageBodyBase + InstanceID JobID `json:"instanceID"` + Address Address `json:"address"` + GPURate []UsageRate `json:"GPURate"` + AccCardRate []UsageRate `json:"AccCardRate"` +} + +type UsageRate struct { + Timestamp string `json:"timestamp"` + Number string `json:"number"` +} + +const ( + RunStatus = "run" + StopStatus = "stop" + FineTuning = "finetuning" + + CreateECS = "create" + RunECS = "run" + PauseECS = "pause" + DestroyECS = "destroy" + OperateServer = "operate" +) + +type QueryAllModelsReq struct { + UserID int64 `form:"userID" json:"userID"` +} + +func (c *Client) QueryAllModels(req QueryAllModelsReq) (*RunningModelResp, error) { + url, err := url.JoinPath(c.baseURL, "/job/queryRunningModels") + if err != nil { + return nil, err + } + + resp, err := myhttp.GetJSON(url, myhttp.RequestParam{ + Body: req, + }) + if err != nil { + return nil, err + } + + contType := resp.Header.Get("Content-Type") + if strings.Contains(contType, myhttp.ContentTypeJSON) { + var codeResp response[RunningModelResp] + if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil { + return nil, fmt.Errorf("parsing response: %w", err) + } + + if codeResp.Code == errorcode.OK { + return &codeResp.Data, nil + } + + return nil, codeResp.ToError() + } + + return nil, fmt.Errorf("unknow response content type: %s", contType) +} + +func (c *Client) ECSNodeRunningInfo(req ECSNodeRunningInfoReq) (*ECSNodeRunningInfoResp, error) { + url, err := url.JoinPath(c.baseURL, "/job/getECSNodeRunningInfo") + if err != nil { + return nil, err + } + + resp, err := myhttp.GetJSON(url, myhttp.RequestParam{ + Body: req, + }) + if err != nil { + return nil, err + } + + contType := resp.Header.Get("Content-Type") + if strings.Contains(contType, myhttp.ContentTypeJSON) { + var codeResp response[ECSNodeRunningInfoResp] + if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil { + return nil, fmt.Errorf("parsing response: %w", err) + } + + if codeResp.Code == errorcode.OK { + return &codeResp.Data, nil + } + + return nil, codeResp.ToError() + } + + return nil, fmt.Errorf("unknow response content type: %s", contType) +} diff --git a/sdks/scheduler/models.go b/sdks/scheduler/models.go index f990dc3..2313866 100644 --- a/sdks/scheduler/models.go +++ b/sdks/scheduler/models.go @@ -27,6 +27,7 @@ type ImageID int64 type CCID int64 type ModelID string +type ModelName string type NodeID int64 type Address string @@ -90,13 +91,16 @@ type UpdateMultiInstanceJobInfo struct { Files JobFilesInfo `json:"files"` Runtime JobRuntimeInfo `json:"runtime"` MultiInstanceJobSetID JobSetID `json:"multiInstanceJobSetID"` - //InstanceIDs []JobID `json:"instanceIDs"` - UpdateStrategy string `json:"updateStrategy"` + UpdateType string `json:"updateType"` + SubJobs []JobID `json:"subJobs"` + Operate string `json:"operate"` } type ModelJobInfo struct { - Type string `json:"type"` - ModelID string `json:"modelID"` + Type string `json:"type"` + ModelID ModelID `json:"modelID"` + CustomModelName ModelName `json:"customModelName"` + Command string `json:"command"` } type InstanceJobInfo struct { diff --git a/sdks/scheduler/response.go b/sdks/scheduler/response.go deleted file mode 100644 index 4c8db4c..0000000 --- a/sdks/scheduler/response.go +++ /dev/null @@ -1,26 +0,0 @@ -package schsdk - -// 这个结构体无任何字段,但实现了Noop,每种MessageBody都要内嵌这个结构体 -type MessageBodyBase struct{} - -// 此处的receiver是指针 -func (b *MessageBodyBase) Noop() {} - -type AvailableNodesResp struct { - MessageBodyBase - AvailableNodes map[ModelID]AvailableNodes `json:"allNode"` -} - -type AvailableNodes struct { - MessageBodyBase - //ModelID ModelID `json:"modelID"` - JobID JobID `json:"jobID"` - Nodes []NodeInfo `json:"nodes"` -} - -type NodeInfo struct { - MessageBodyBase - InstanceID JobID `json:"instanceID"` - NodeID NodeID `json:"nodeID"` - Address Address `json:"address"` -}