From f32b20bd1861428f290b5503aa8a484905430bde Mon Sep 17 00:00:00 2001 From: zhangwei <894646498@qq.com> Date: Mon, 22 Apr 2024 15:14:26 +0800 Subject: [PATCH 1/3] Add filtering fields to the alarm list Former-commit-id: f99531dec1e2610267446bb414fb529bd4b5f97b --- api/desc/monitoring/pcm-monitoring.api | 2 + .../logic/monitoring/alertruleslogic.go | 10 +- api/internal/types/types.go | 180 ++++++++++++++++++ 3 files changed, 191 insertions(+), 1 deletion(-) diff --git a/api/desc/monitoring/pcm-monitoring.api b/api/desc/monitoring/pcm-monitoring.api index a70f3bf5..06f84557 100644 --- a/api/desc/monitoring/pcm-monitoring.api +++ b/api/desc/monitoring/pcm-monitoring.api @@ -14,6 +14,8 @@ type CreateAlertRuleReq { type ( AlertRulesReq { AlertType string `form:"alertType"` + AdapterId string `form:"adapterId,optional"` + ClusterId string `form:"clusterId,optional"` } AlertRulesResp { alertRules []AlertRule `json:"alertRules"` diff --git a/api/internal/logic/monitoring/alertruleslogic.go b/api/internal/logic/monitoring/alertruleslogic.go index e821897a..d7d2dde8 100644 --- a/api/internal/logic/monitoring/alertruleslogic.go +++ b/api/internal/logic/monitoring/alertruleslogic.go @@ -2,6 +2,7 @@ package monitoring import ( "context" + "fmt" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" @@ -26,7 +27,14 @@ func NewAlertRulesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AlertR func (l *AlertRulesLogic) AlertRules(req *types.AlertRulesReq) (resp *types.AlertRulesResp, err error) { resp = &types.AlertRulesResp{} var alertRules []types.AlertRule - l.svcCtx.DbEngin.Raw("SELECT ar.id,ar.*,GROUP_CONCAT(tc.`name` ORDER BY tc.`name` ASC SEPARATOR ',') as cluster_name FROM alert_rule ar JOIN t_cluster tc ON ar.cluster_id = tc.id WHERE ar.alert_type = ? AND ar.deleted_at IS NULL AND tc.deleted_at IS NULL GROUP BY ar.id", req.AlertType).Scan(&alertRules) + sql := fmt.Sprintf("SELECT ar.*,GROUP_CONCAT(tc.`name` ORDER BY tc.`name` ASC SEPARATOR ',') as cluster_name FROM alert_rule ar JOIN t_cluster tc ON ar.cluster_id = tc.id WHERE ar.alert_type = %s AND ar.deleted_at IS NULL AND tc.deleted_at IS NULL GROUP BY ar.id", req.AlertType) + if req.AdapterId != "" { + sql = fmt.Sprintf("SELECT tar.*,GROUP_CONCAT( tc.`name` ORDER BY tc.`name` ASC SEPARATOR ',' ) AS cluster_name FROM talert_rule ar JOIN t_cluster tc ON ar.cluster_id = tc.id JOIN t_adapter ta ON ta.id = tc.adapter_id WHERE tar.alert_type = %s AND ta.id = %s AND ar.deleted_at IS NULL AND tc.deleted_at IS NULL GROUP BY tar.id", req.AlertType, req.AdapterId) + } + if req.ClusterId != "" { + sql = fmt.Sprintf("SELECT ar.*,GROUP_CONCAT(tc.`name` ORDER BY tc.`name` ASC SEPARATOR ',') as cluster_name FROM alert_rule ar JOIN t_cluster tc ON ar.cluster_id = tc.id WHERE ar.alert_type = %s AND ar.cluster_id = %s AND ar.deleted_at IS NULL AND tc.deleted_at IS NULL GROUP BY ar.id", req.AlertType, req.ClusterId) + } + l.svcCtx.DbEngin.Raw(sql).Scan(&alertRules) resp.AlertRules = alertRules return resp, nil } diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 5b0c362d..757053fb 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -874,6 +874,184 @@ type ListResult struct { List interface{} `json:"list,omitempty"` } +type HpcInfo struct { + Id int64 `json:"id"` // id + TaskId int64 `json:"task_id"` // 任务id + JobId string `json:"job_id"` // 作业id(在第三方系统中的作业id) + AdapterId int64 `json:"adapter_id"` // 执行任务的适配器id + ClusterId int64 `json:"cluster_id"` // 执行任务的集群id + ClusterType string `json:"cluster_type"` // 执行任务的集群类型 + Name string `json:"name"` // 名称 + Status string `json:"status"` // 状态 + CmdScript string `json:"cmd_script"` + StartTime string `json:"start_time"` // 开始时间 + RunningTime int64 `json:"running_time"` // 运行时间 + DerivedEs string `json:"derived_es"` + Cluster string `json:"cluster"` + BlockId int64 `json:"block_id"` + AllocNodes int64 `json:"alloc_nodes"` + AllocCpu int64 `json:"alloc_cpu"` + CardCount int64 `json:"card_count"` // 卡数 + Version string `json:"version"` + Account string `json:"account"` + WorkDir string `json:"work_dir"` // 工作路径 + AssocId int64 `json:"assoc_id"` + ExitCode int64 `json:"exit_code"` + WallTime string `json:"wall_time"` // 最大运行时间 + Result string `json:"result"` // 运行结果 + DeletedAt string `json:"deleted_at"` // 删除时间 + YamlString string `json:"yaml_string"` + AppType string `json:"app_type"` // 应用类型 + AppName string `json:"app_name"` // 应用名称 + Queue string `json:"queue"` // 队列名称 + SubmitType string `json:"submit_type"` // cmd(命令行模式) + NNode string `json:"n_node"` // 节点个数(当指定该参数时,GAP_NODE_STRING必须为"") + StdOutFile string `json:"std_out_file"` // 工作路径/std.err.%j + StdErrFile string `json:"std_err_file"` // 工作路径/std.err.%j + StdInput string `json:"std_input"` + Environment string `json:"environment"` + DeletedFlag int64 `json:"deleted_flag"` // 是否删除(0-否,1-是) + CreatedBy int64 `json:"created_by"` // 创建人 + CreatedTime string `json:"created_time"` // 创建时间 + UpdatedBy int64 `json:"updated_by"` // 更新人 + UpdatedTime string `json:"updated_time"` // 更新时间 +} + +type CloudInfo struct { + Participant int64 `json:"participant,omitempty"` + Id int64 `json:"id,omitempty"` + TaskId int64 `json:"taskId,omitempty"` + ApiVersion string `json:"apiVersion,omitempty"` + Kind string `json:"kind,omitempty"` + Namespace string `json:"namespace,omitempty"` + Name string `json:"name,omitempty"` + Status string `json:"status,omitempty"` + StartTime string `json:"startTime,omitempty"` + RunningTime int64 `json:"runningTime,omitempty"` + Result string `json:"result,omitempty"` + YamlString string `json:"yamlString,omitempty"` +} + +type AiInfo struct { + ParticipantId int64 `json:"participantId,omitempty"` + TaskId int64 `json:"taskId,omitempty"` + ProjectId string `json:"project_id,omitempty"` + Name string `json:"name,omitempty"` + Status string `json:"status,omitempty"` + StartTime string `json:"startTime,omitempty"` + RunningTime int64 `json:"runningTime,omitempty"` + Result string `json:"result,omitempty"` + JobId string `json:"jobId,omitempty"` + CreateTime string `json:"createTime,omitempty"` + ImageUrl string `json:"imageUrl,omitempty"` + Command string `json:"command,omitempty"` + FlavorId string `json:"flavorId,omitempty"` + SubscriptionId string `json:"subscriptionId,omitempty"` + ItemVersionId string `json:"itemVersionId,omitempty"` +} + +type VmInfo struct { + ParticipantId int64 `json:"participantId,omitempty"` + TaskId int64 `json:"taskId,omitempty"` + Name string `json:"name,omitempty"` + FlavorRef string `json:"flavor_ref,omitempty"` + ImageRef string `json:"image_ref,omitempty"` + NetworkUuid string `json:"network_uuid,omitempty"` + BlockUuid string `json:"block_uuid,omitempty"` + SourceType string `json:"source_type,omitempty"` + DeleteOnTermination bool `json:"delete_on_termination,omitempty"` + Status string `json:"status,omitempty"` + MinCount string `json:"min_count,omitempty"` + Platform string `json:"platform,omitempty"` + Uuid string `json:"uuid,omitempty"` +} + +type PullTaskInfoReq struct { + AdapterId int64 `form:"adapterId"` +} + +type PullTaskInfoResp struct { + HpcInfoList []*HpcInfo `json:"HpcInfoList,omitempty"` + CloudInfoList []*CloudInfo `json:"CloudInfoList,omitempty"` + AiInfoList []*AiInfo `json:"AiInfoList,omitempty"` + VmInfoList []*VmInfo `json:"VmInfoList,omitempty"` +} + +type PushTaskInfoReq struct { + AdapterId int64 `json:"adapterId"` + HpcInfoList []*HpcInfo `json:"hpcInfoList"` + CloudInfoList []*CloudInfo `json:"cloudInfoList"` + AiInfoList []*AiInfo `json:"aiInfoList"` + VmInfoList []*VmInfo `json:"vmInfoList"` +} + +type PushTaskInfoResp struct { + Code int64 `json:"code"` + Msg string `json:"msg"` +} + +type PushResourceInfoReq struct { + AdapterId int64 `json:"adapterId"` + ResourceStats []ResourceStats `json:"resourceStats"` +} + +type PushResourceInfoResp struct { + Code int64 `json:"code"` + Msg string `json:"msg"` +} + +type NoticeInfo struct { + AdapterId int64 `json:"adapterId"` + AdapterName string `json:"adapterName"` + ClusterId int64 `json:"clusterId"` + ClusterName string `json:"clusterName"` + NoticeType string `json:"noticeType"` + TaskName string `json:"taskName"` + Incident string `json:"incident"` +} + +type ListNoticeReq struct { +} + +type ListNoticeResp struct { + Code int64 `json:"code"` + Msg string `json:"msg"` + Data []NoticeInfo `json:"data"` +} + +type PushNoticeReq struct { + NoticeInfo NoticeInfo `json:"noticeInfo"` +} + +type PushNoticeResp struct { + Code int64 `json:"code"` + Msg string `json:"msg"` +} + +type ResourceStats struct { + ClusterId int64 `json:"clusterId"` + Name string `json:"name"` + CpuCoreAvail int64 `json:"cpuCoreAvail"` + CpuCoreTotal int64 `json:"cpuCoreTotal"` + MemAvail float64 `json:"memAvail"` + MemTotal float64 `json:"memTotal"` + DiskAvail float64 `json:"diskAvail"` + DiskTotal float64 `json:"diskTotal"` + GpuAvail int64 `json:"gpuAvail"` + CardsAvail []*Card `json:"cardsAvail"` + CpuCoreHours float64 `json:"cpuCoreHours"` + Balance float64 `json:"balance"` +} + +type Card struct { + Platform string `json:"platform"` + Type string `json:"type"` + Name string `json:"name"` + TOpsAtFp16 float64 `json:"TOpsAtFp16"` + CardHours float64 `json:"cardHours"` + CardNum int32 `json:"cardNum"` +} + type CommitHpcTaskReq struct { Name string `json:"name"` // paratera:jobName Description string `json:"description,optional"` @@ -5363,6 +5541,8 @@ type CreateAlertRuleReq struct { type AlertRulesReq struct { AlertType string `form:"alertType"` + AdapterId string `form:"adapterId,optional"` + ClusterId string `form:"clusterId,optional"` } type AlertRulesResp struct { From 8fd635b4a7bdf58a8d9fb39362523e7d69b10e36 Mon Sep 17 00:00:00 2001 From: zhangwei <894646498@qq.com> Date: Thu, 25 Apr 2024 10:09:57 +0800 Subject: [PATCH 2/3] query task num Former-commit-id: 2e88ecb4d707b7d9f662146415a6999610fe5e53 --- api/desc/monitoring/pcm-monitoring.api | 14 +++++++- api/desc/pcm.api | 13 +++++--- .../handler/monitoring/tasknumhandler.go | 25 ++++++++++++++ api/internal/handler/routes.go | 7 +++- .../logic/monitoring/alertruleslogic.go | 2 +- .../logic/monitoring/createalertrulelogic.go | 2 ++ api/internal/logic/monitoring/tasknumlogic.go | 33 +++++++++++++++++++ api/internal/types/types.go | 13 ++++++++ 8 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 api/internal/handler/monitoring/tasknumhandler.go create mode 100644 api/internal/logic/monitoring/tasknumlogic.go diff --git a/api/desc/monitoring/pcm-monitoring.api b/api/desc/monitoring/pcm-monitoring.api index 06f84557..cdd39fdc 100644 --- a/api/desc/monitoring/pcm-monitoring.api +++ b/api/desc/monitoring/pcm-monitoring.api @@ -58,4 +58,16 @@ type ( type SyncClusterAlertReq { AlertRecordsMap map[string]interface{} `json:"alertRecordsMap"` -} \ No newline at end of file +} + +type ( + taskNumReq { + clusterId string `form:"clusterId"` + } + taskNumResp { + current int `json:"current"` + today int `json:"today"` + history int `json:"history"` + failed int `json:"failed"` + } +) \ No newline at end of file diff --git a/api/desc/pcm.api b/api/desc/pcm.api index 2c76692c..51e5502c 100644 --- a/api/desc/pcm.api +++ b/api/desc/pcm.api @@ -132,11 +132,11 @@ service pcm { @doc "paging queries the task list" @handler pageListTaskHandler - get /core/task/list (pageTaskReq) returns(PageResult) + get /core/task/list (pageTaskReq) returns (PageResult) @doc "Statistical task status" @handler countTaskStatus - get /core/task/countTaskStatus () returns(TaskStatusResp) + get /core/task/countTaskStatus () returns (TaskStatusResp) } //hpc二级接口 @@ -210,7 +210,7 @@ service pcm { @doc "Create cloud computing common tasks" @handler commitGeneralTask - post /cloud/task/create (GeneralTaskReq) returns() + post /cloud/task/create (GeneralTaskReq) returns () } //智算二级接口 @@ -975,7 +975,7 @@ service pcm { @doc "alert rules" @handler alertRulesHandler - get /monitoring/alert/rule (AlertRulesReq)returns (AlertRulesResp) + get /monitoring/alert/rule (AlertRulesReq) returns (AlertRulesResp) @doc "cluster resource load" @handler clustersLoadHandler @@ -991,5 +991,8 @@ service pcm { @doc "Synchronize Cluster alert Information" @handler syncClusterAlertHandler - post /core/syncClusterAlert (SyncClusterAlertReq) + post /monitoring/syncClusterAlert (SyncClusterAlertReq) + + @handler taskNumHandler + get /monitoring/task/num (taskNumReq) returns (taskNumResp) } \ No newline at end of file diff --git a/api/internal/handler/monitoring/tasknumhandler.go b/api/internal/handler/monitoring/tasknumhandler.go new file mode 100644 index 00000000..4b7751bc --- /dev/null +++ b/api/internal/handler/monitoring/tasknumhandler.go @@ -0,0 +1,25 @@ +package monitoring + +import ( + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/monitoring" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" +) + +func TaskNumHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.TaskNumReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := monitoring.NewTaskNumLogic(r.Context(), svcCtx) + resp, err := l.TaskNum(&req) + result.HttpResult(r, w, resp, err) + } +} diff --git a/api/internal/handler/routes.go b/api/internal/handler/routes.go index a68efc58..9fe292b5 100644 --- a/api/internal/handler/routes.go +++ b/api/internal/handler/routes.go @@ -1244,9 +1244,14 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { }, { Method: http.MethodPost, - Path: "/core/syncClusterAlert", + Path: "/monitoring/syncClusterAlert", Handler: monitoring.SyncClusterAlertHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/monitoring/task/num", + Handler: monitoring.TaskNumHandler(serverCtx), + }, }, rest.WithPrefix("/pcm/v1"), ) diff --git a/api/internal/logic/monitoring/alertruleslogic.go b/api/internal/logic/monitoring/alertruleslogic.go index d7d2dde8..7c63dcff 100644 --- a/api/internal/logic/monitoring/alertruleslogic.go +++ b/api/internal/logic/monitoring/alertruleslogic.go @@ -29,7 +29,7 @@ func (l *AlertRulesLogic) AlertRules(req *types.AlertRulesReq) (resp *types.Aler var alertRules []types.AlertRule sql := fmt.Sprintf("SELECT ar.*,GROUP_CONCAT(tc.`name` ORDER BY tc.`name` ASC SEPARATOR ',') as cluster_name FROM alert_rule ar JOIN t_cluster tc ON ar.cluster_id = tc.id WHERE ar.alert_type = %s AND ar.deleted_at IS NULL AND tc.deleted_at IS NULL GROUP BY ar.id", req.AlertType) if req.AdapterId != "" { - sql = fmt.Sprintf("SELECT tar.*,GROUP_CONCAT( tc.`name` ORDER BY tc.`name` ASC SEPARATOR ',' ) AS cluster_name FROM talert_rule ar JOIN t_cluster tc ON ar.cluster_id = tc.id JOIN t_adapter ta ON ta.id = tc.adapter_id WHERE tar.alert_type = %s AND ta.id = %s AND ar.deleted_at IS NULL AND tc.deleted_at IS NULL GROUP BY tar.id", req.AlertType, req.AdapterId) + sql = fmt.Sprintf("SELECT ar.*,GROUP_CONCAT( tc.`name` ORDER BY tc.`name` ASC SEPARATOR ',' ) AS cluster_name FROM alert_rule ar JOIN t_cluster tc ON ar.cluster_id = tc.id JOIN t_adapter ta ON ta.id = tc.adapter_id WHERE ar.alert_type = %s AND ta.id = %s AND ar.deleted_at IS NULL AND tc.deleted_at IS NULL GROUP BY ar.id", req.AlertType, req.AdapterId) } if req.ClusterId != "" { sql = fmt.Sprintf("SELECT ar.*,GROUP_CONCAT(tc.`name` ORDER BY tc.`name` ASC SEPARATOR ',') as cluster_name FROM alert_rule ar JOIN t_cluster tc ON ar.cluster_id = tc.id WHERE ar.alert_type = %s AND ar.cluster_id = %s AND ar.deleted_at IS NULL AND tc.deleted_at IS NULL GROUP BY ar.id", req.AlertType, req.ClusterId) diff --git a/api/internal/logic/monitoring/createalertrulelogic.go b/api/internal/logic/monitoring/createalertrulelogic.go index fadf50c3..c9685c98 100644 --- a/api/internal/logic/monitoring/createalertrulelogic.go +++ b/api/internal/logic/monitoring/createalertrulelogic.go @@ -11,6 +11,7 @@ import ( v12 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/json" + "strconv" ) type CreateAlertRuleLogic struct { @@ -38,6 +39,7 @@ func (l *CreateAlertRuleLogic) CreateAlertRule(req *types.CreateAlertRuleReq) er // save to db var alertRule models.AlertRule tool.Convert(req, &alertRule) + alertRule.ClusterId, _ = strconv.ParseInt(req.CLusterId, 10, 64) alertRule.Id = tool.GenSnowflakeID() tx := l.svcCtx.DbEngin.Save(&alertRule) if tx.Error != nil { diff --git a/api/internal/logic/monitoring/tasknumlogic.go b/api/internal/logic/monitoring/tasknumlogic.go new file mode 100644 index 00000000..0b7f1659 --- /dev/null +++ b/api/internal/logic/monitoring/tasknumlogic.go @@ -0,0 +1,33 @@ +package monitoring + +import ( + "context" + + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type TaskNumLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewTaskNumLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TaskNumLogic { + return &TaskNumLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *TaskNumLogic) TaskNum(req *types.TaskNumReq) (resp *types.TaskNumResp, err error) { + resp = &types.TaskNumResp{} + l.svcCtx.DbEngin.Raw("SELECT COUNT(id) from task_cloud where cluster_id = ? and status = 'running'", req.ClusterId).Scan(resp.Current) + l.svcCtx.DbEngin.Raw("SELECT COUNT(id) from task_cloud where cluster_id = '' and DATE(start_time) = CURDATE()", req.ClusterId).Scan(resp.Today) + l.svcCtx.DbEngin.Raw("SELECT COUNT(id) from task_cloud where cluster_id = ?", req.ClusterId).Scan(resp.History) + l.svcCtx.DbEngin.Raw("SELECT COUNT(id) from task_cloud where cluster_id = ? and status = 'failed'", req.ClusterId).Scan(resp.Failed) + return resp, nil +} diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 59dd185d..b4e691db 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -5548,6 +5548,8 @@ type CreateAlertRuleReq struct { type AlertRulesReq struct { AlertType string `form:"alertType"` + AdapterId string `form:"adapterId,optional"` + ClusterId string `form:"clusterId,optional"` } type AlertRulesResp struct { @@ -5589,3 +5591,14 @@ type AlertListResp struct { type SyncClusterAlertReq struct { AlertRecordsMap map[string]interface{} `json:"alertRecordsMap"` } + +type TaskNumReq struct { + ClusterId string `form:"clusterId"` +} + +type TaskNumResp struct { + Current int `json:"current"` + Today int `json:"today"` + History int `json:"history"` + Failed int `json:"failed"` +} From 2210db4d3cfac5086bb3b25d3c16fd0c6d7d3a8f Mon Sep 17 00:00:00 2001 From: zhangwei <894646498@qq.com> Date: Fri, 26 Apr 2024 16:27:26 +0800 Subject: [PATCH 3/3] adapter info Former-commit-id: c717f0f1d0eabd7121ed7d43a8e22e82603b8d64 --- api/desc/monitoring/pcm-monitoring.api | 10 ++++++ api/desc/pcm.api | 3 ++ .../handler/monitoring/adapterinfohandler.go | 25 +++++++++++++++ api/internal/handler/routes.go | 5 +++ .../logic/monitoring/adapterinfologic.go | 31 +++++++++++++++++++ api/internal/types/types.go | 9 ++++++ 6 files changed, 83 insertions(+) create mode 100644 api/internal/handler/monitoring/adapterinfohandler.go create mode 100644 api/internal/logic/monitoring/adapterinfologic.go diff --git a/api/desc/monitoring/pcm-monitoring.api b/api/desc/monitoring/pcm-monitoring.api index cdd39fdc..8dc7cdd9 100644 --- a/api/desc/monitoring/pcm-monitoring.api +++ b/api/desc/monitoring/pcm-monitoring.api @@ -70,4 +70,14 @@ type ( history int `json:"history"` failed int `json:"failed"` } +) + +type ( + adapterInfoReq{ + clusterId string `form:"clusterId"` + } + adapterInfoResp{ + name string `json:"name"` + version string `json:"version"` + } ) \ No newline at end of file diff --git a/api/desc/pcm.api b/api/desc/pcm.api index 51e5502c..de215d2f 100644 --- a/api/desc/pcm.api +++ b/api/desc/pcm.api @@ -995,4 +995,7 @@ service pcm { @handler taskNumHandler get /monitoring/task/num (taskNumReq) returns (taskNumResp) + + @handler adapterInfoHandler + get /monitoring/adapter/info (adapterInfoReq) returns (adapterInfoResp) } \ No newline at end of file diff --git a/api/internal/handler/monitoring/adapterinfohandler.go b/api/internal/handler/monitoring/adapterinfohandler.go new file mode 100644 index 00000000..4869213f --- /dev/null +++ b/api/internal/handler/monitoring/adapterinfohandler.go @@ -0,0 +1,25 @@ +package monitoring + +import ( + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/monitoring" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" +) + +func AdapterInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.AdapterInfoReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := monitoring.NewAdapterInfoLogic(r.Context(), svcCtx) + resp, err := l.AdapterInfo(&req) + result.HttpResult(r, w, resp, err) + } +} diff --git a/api/internal/handler/routes.go b/api/internal/handler/routes.go index 9fe292b5..599422d5 100644 --- a/api/internal/handler/routes.go +++ b/api/internal/handler/routes.go @@ -1252,6 +1252,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/monitoring/task/num", Handler: monitoring.TaskNumHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/monitoring/adapter/info", + Handler: monitoring.AdapterInfoHandler(serverCtx), + }, }, rest.WithPrefix("/pcm/v1"), ) diff --git a/api/internal/logic/monitoring/adapterinfologic.go b/api/internal/logic/monitoring/adapterinfologic.go new file mode 100644 index 00000000..1afc91e4 --- /dev/null +++ b/api/internal/logic/monitoring/adapterinfologic.go @@ -0,0 +1,31 @@ +package monitoring + +import ( + "context" + + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type AdapterInfoLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewAdapterInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdapterInfoLogic { + return &AdapterInfoLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *AdapterInfoLogic) AdapterInfo(req *types.AdapterInfoReq) (resp *types.AdapterInfoResp, err error) { + // todo: add your logic here and delete this line + resp = &types.AdapterInfoResp{} + l.svcCtx.DbEngin.Raw("select ta.name , ta.version from t_adapter ta,t_cluster tc where tc.id = ? and tc.adapter_id = ta.id", req.ClusterId).Scan(resp) + return resp, nil +} diff --git a/api/internal/types/types.go b/api/internal/types/types.go index b4e691db..ab192993 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -5602,3 +5602,12 @@ type TaskNumResp struct { History int `json:"history"` Failed int `json:"failed"` } + +type AdapterInfoReq struct { + ClusterId string `form:"clusterId"` +} + +type AdapterInfoResp struct { + Name string `json:"name"` + Version string `json:"version"` +}