移除多余代码

Former-commit-id: 6e245fdcda9efae192ad676ac3f6c2510df129a3
This commit is contained in:
zhangwei 2024-06-05 15:54:25 +08:00
parent e29002b4d6
commit 68e497760f
53 changed files with 20 additions and 2889 deletions

View File

@ -50,10 +50,6 @@ service pcm {
@handler TaskListHandler
get /core/taskList (taskListReq) returns (taskListResp)
@doc "查询任务详情"
@handler TaskDetailHandler
get /core/taskDetail/:taskId (taskDetailReq) returns (taskDetailResp)
@doc "任务概览"
@handler JobTotalHandler
get /core/jobTotal returns (jobTotalResp)
@ -216,14 +212,6 @@ service pcm {
@handler deleteClusterHandler
post /cloud/deleteCluster (deleteClusterReq) returns (CloudResp)
@doc "触发租户更新"
@handler noticeTenantHandler
get /cloud/noticeTenant returns (CloudResp)
@doc "租户更新"
@handler updateTenantHandler
post /cloud/updateTenant (UpdateTenantReq) returns (CloudResp)
@doc "Obtain cluster list information according to adapterId"
@handler getClusterListHandler
get /core/clusterList (getClusterListReq) returns (getClusterListResp)
@ -398,33 +386,6 @@ service pcm {
get /storage/perCenterComputerPowers (PerCenterComputerPowersReq) returns (PerCenterComputerPowersResp)
}
//镜像接口
@server(
prefix: pcm/v1
group: image
)
service pcm {
@doc "镜像上传"
@handler uploadHandler
post /upload
@doc "镜像分块"
@handler chunkHandler
post /chunk
@doc "查询镜像列表"
@handler imageListHandler
get /image/list returns (imageListResp)
@doc "数据集检查"
@handler dataSetCheckHandler
get /dataSet/check/:fileMd5 (checkReq) returns (checkResp)
@doc "上传数据集"
@handler uploadDataSetHandler
post /dataSet/upload
}
//openstack 接口
@server(
prefix: pcm/v1
@ -855,49 +816,6 @@ service pcm {
get /storelink/getResourceSpecs (GetResourceSpecsReq) returns (GetResourceSpecsResp)
}
// 接口
@server(
prefix: pcm/v1
group: apps
)
service pcm {
@doc "应用列表"
@handler AppListHandler
get /apps/list (AppListReq) returns (AppListResp)
@doc "获取应用分发详情"
@handler AppDetailHandler
get /apps/distribute/:appName (AppDetailReq) returns (AppDetailResp)
@doc "应用pods列表"
@handler AppPodsHandler
get /apps/pods/:appName (AppDetailReq) returns (AppDetailResp)
@doc "获取应用详情"
@handler GetAppByAppName
get /apps/getAppByAppName/:appName (AppDetailReq) returns (AppTaskResp)
@doc "删除应用"
@handler DeleteAppByAppName
delete /apps/deleteApp (DeleteAppReq) returns (DeleteAppResp)
@doc "更新应用"
@handler UpdateAppByAppName
put /apps/updateApp (DeleteAppReq) returns (AppTaskResp)
@doc "重启应用"
@handler RestartAppByAppName
put /apps/restartApp (DeleteAppReq) returns (AppResp)
@doc "暂停应用"
@handler PauseAppByAppName
put /apps/pauseApp (DeleteAppReq) returns (AppResp)
@doc "启动应用"
@handler StartAppByAppName
put /apps/startApp (DeleteAppReq) returns (AppResp)
}
// 接口
@server(
prefix: pcm/v1

View File

@ -15,14 +15,6 @@ Monitoring:
PromUrl: http://47.92.39.128:30877
AlertUrl: 47.92.39.128:32243
# k8s rpc
K8sNativeConf:
# target: nacos://10.206.0.12:8848/pcm.kubenative.rpc?timeout=30s&namespaceid=test&groupname=DEFAULT_GROUP&appName=pcm.core.api
Endpoints:
- 127.0.0.1:2003
NonBlock: true
#rpc
THRpcConf:
target: nacos://10.206.0.12:8848/pcm.th.rpc?timeout=30s&namespaceid=test&groupname=DEFAULT_GROUP&appName=pcm.core.api
@ -82,19 +74,10 @@ PcmCoreRpcConf:
NonBlock: true
Timeout: 20000
NexusUrl: http://10.101.15.175:8081
JccScheduleUrl: http://jcce-schedule-service:8082
MinioConf:
Secret: minio_xnu122@_
AccessKey: minioadmin
Endpoint: http://121.89.220.60:9000
RegistryConf:
Username: jointcloudNudt
Password: Nudt@123
SnowflakeConf:
MachineId: 1

View File

@ -37,17 +37,13 @@ type Config struct {
OpenstackRpcConf zrpc.RpcClientConf
OctopusRpcConf zrpc.RpcClientConf
PcmCoreRpcConf zrpc.RpcClientConf
JccScheduleUrl string
MinioConf struct {
MinioConf struct {
Secret string
AccessKey string
Endpoint string
}
RegistryConf struct {
Username string
Password string
}
SnowflakeConf SnowflakeConf
Monitoring Monitoring
}

View File

@ -1,32 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package cron
import (
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
)
func AddCronGroup(svc *svc.ServiceContext) {
// 删除三天前的监控信息
svc.Cron.AddFunc("0 0 0 ? * ? ", func() {
ClearMetricsData(svc)
})
// 同步任务信息到core端
svc.Cron.AddFunc("*/5 * * * * ?", func() {
SyncParticipantRpc(svc)
})
}

View File

@ -1,28 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package cron
import (
"github.com/rs/zerolog/log"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
)
func ClearMetricsData(svc *svc.ServiceContext) {
tx := svc.DbEngin.Where("DATE(created_time) <= DATE(DATE_SUB(NOW(),INTERVAL 3 DAY))").Delete(&models.ScNodeAvailInfo{})
if tx.Error != nil {
log.Err(tx.Error)
}
}

View File

@ -1,41 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package cron
import (
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/tracker"
)
func SyncParticipantRpc(svc *svc.ServiceContext) {
// 查询出所有p端信息
var participants []*models.ScParticipantPhyInfo
svc.DbEngin.Where("type in (?)", []string{constants.CLOUD, constants.SEALOS}).Find(&participants)
if len(participants) != 0 {
for _, participant := range participants {
if len(participant.MetricsUrl) != 0 {
// 初始化p端prometheus client
promClient, err := tracker.NewPrometheus(participant.MetricsUrl)
if err != nil {
return
}
svc.MonitorClient[participant.Id] = promClient
}
}
}
}

View File

@ -1,24 +0,0 @@
package apps
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/apps"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func AppDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AppDetailReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := apps.NewAppDetailLogic(r.Context(), svcCtx)
resp, err := l.AppDetail(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,24 +0,0 @@
package apps
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/apps"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func AppListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AppListReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := apps.NewAppListLogic(r.Context(), svcCtx)
resp, err := l.AppList(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,24 +0,0 @@
package apps
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/apps"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func AppPodsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AppDetailReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := apps.NewAppPodsLogic(r.Context(), svcCtx)
resp, err := l.AppPods(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,24 +0,0 @@
package apps
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/apps"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func DeleteAppByAppNameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DeleteAppReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := apps.NewDeleteAppByAppNameLogic(r.Context(), svcCtx)
resp, err := l.DeleteAppByAppName(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,24 +0,0 @@
package apps
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/apps"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func GetAppByAppNameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AppDetailReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := apps.NewGetAppByAppNameLogic(r.Context(), svcCtx)
resp, err := l.GetAppByAppName(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,24 +0,0 @@
package apps
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/apps"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func PauseAppByAppNameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DeleteAppReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := apps.NewPauseAppByAppNameLogic(r.Context(), svcCtx)
resp, err := l.PauseAppByAppName(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,24 +0,0 @@
package apps
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/apps"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func RestartAppByAppNameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DeleteAppReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := apps.NewRestartAppByAppNameLogic(r.Context(), svcCtx)
resp, err := l.RestartAppByAppName(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,24 +0,0 @@
package apps
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/apps"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func StartAppByAppNameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DeleteAppReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := apps.NewStartAppByAppNameLogic(r.Context(), svcCtx)
resp, err := l.StartAppByAppName(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,24 +0,0 @@
package apps
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/apps"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func UpdateAppByAppNameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DeleteAppReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := apps.NewUpdateAppByAppNameLogic(r.Context(), svcCtx)
resp, err := l.UpdateAppByAppName(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,16 +0,0 @@
package cloud
import (
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func NoticeTenantHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := cloud.NewNoticeTenantLogic(r.Context(), svcCtx)
resp, err := l.NoticeTenant()
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,24 +0,0 @@
package cloud
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func UpdateTenantHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UpdateTenantReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := cloud.NewUpdateTenantLogic(r.Context(), svcCtx)
resp, err := l.UpdateTenant(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,24 +0,0 @@
package core
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/core"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func TaskDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.TaskDetailReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := core.NewTaskDetailLogic(r.Context(), svcCtx)
resp, err := l.TaskDetail(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,16 +0,0 @@
package image
import (
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/image"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func ChunkHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := image.NewChunkLogic(r.Context(), svcCtx)
err := l.Chunk()
result.HttpResult(r, w, nil, err)
}
}

View File

@ -1,24 +0,0 @@
package image
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/image"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func DataSetCheckHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CheckReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := image.NewDataSetCheckLogic(r.Context(), svcCtx)
resp, err := l.DataSetCheck(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,16 +0,0 @@
package image
import (
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/image"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func ImageListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := image.NewImageListLogic(r.Context(), svcCtx)
resp, err := l.ImageList()
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,16 +0,0 @@
package image
import (
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/image"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func UploadDataSetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := image.NewUploadDataSetLogic(r.Context(), svcCtx)
err := l.UploadDataSet()
result.HttpResult(r, w, nil, err)
}
}

View File

@ -1,16 +0,0 @@
package image
import (
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/image"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func UploadHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := image.NewUploadLogic(r.Context(), svcCtx)
err := l.Upload()
result.HttpResult(r, w, nil, err)
}
}

View File

@ -6,12 +6,10 @@ import (
adapters "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/adapters"
ai "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/ai"
apps "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/apps"
cloud "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/cloud"
core "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/core"
dictionary "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/dictionary"
hpc "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/hpc"
image "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/image"
monitoring "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/monitoring"
schedule "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/schedule"
storage "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/storage"
@ -55,11 +53,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/core/taskList",
Handler: core.TaskListHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/core/taskDetail/:taskId",
Handler: core.TaskDetailHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/core/jobTotal",
@ -257,16 +250,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/cloud/deleteCluster",
Handler: cloud.DeleteClusterHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/cloud/noticeTenant",
Handler: cloud.NoticeTenantHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/cloud/updateTenant",
Handler: cloud.UpdateTenantHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/core/clusterList",
@ -478,37 +461,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithPrefix("/pcm/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/upload",
Handler: image.UploadHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/chunk",
Handler: image.ChunkHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/image/list",
Handler: image.ImageListHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/dataSet/check/:fileMd5",
Handler: image.DataSetCheckHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/dataSet/upload",
Handler: image.UploadDataSetHandler(serverCtx),
},
},
rest.WithPrefix("/pcm/v1"),
)
server.AddRoutes(
[]rest.Route{
{
@ -1051,57 +1003,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithPrefix("/pcm/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/apps/list",
Handler: apps.AppListHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/apps/distribute/:appName",
Handler: apps.AppDetailHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/apps/pods/:appName",
Handler: apps.AppPodsHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/apps/getAppByAppName/:appName",
Handler: apps.GetAppByAppNameHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/apps/deleteApp",
Handler: apps.DeleteAppByAppNameHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/apps/updateApp",
Handler: apps.UpdateAppByAppNameHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/apps/restartApp",
Handler: apps.RestartAppByAppNameHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/apps/pauseApp",
Handler: apps.PauseAppByAppNameHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/apps/startApp",
Handler: apps.StartAppByAppNameHandler(serverCtx),
},
},
rest.WithPrefix("/pcm/v1"),
)
server.AddRoutes(
[]rest.Route{
{

View File

@ -43,5 +43,23 @@ func (l *CreateClusterLogic) CreateCluster(req *types.ClusterCreateReq) (resp *t
logx.Errorf(tx.Error.Error())
return nil, errors.New("cluster create failed")
}
// push cluster info to adapter
var adapterServer string
l.svcCtx.DbEngin.Raw("select server from t_adapter where id = ?", req.AdapterId).Scan(&adapterServer)
response, err := l.svcCtx.HttpClient.R().
SetBody(&types.ClusterInfo{
Name: req.Name,
Server: req.Server,
Token: req.Token,
MonitorServer: req.MonitorServer,
}).
ForceContentType("application/json").
Post(adapterServer + "/api/v1/cluster/info")
if err != nil {
}
if response.IsError() {
}
return
}

View File

@ -1,42 +0,0 @@
package apps
import (
"context"
"gitlink.org.cn/JointCloud/pcm-kubernetes/kubernetes"
"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 AppDetailLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAppDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AppDetailLogic {
return &AppDetailLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *AppDetailLogic) AppDetail(req *types.AppDetailReq) (resp *kubernetes.AppDetailResp, err error) {
resp = &kubernetes.AppDetailResp{}
//调用p端接口查询应用详情
appDetail, err := l.svcCtx.K8sRpc.GetAppDetail(context.Background(), &kubernetes.AppDetailReq{
Namespace: req.NsID,
Name: req.Name,
})
if err != nil {
logx.Errorf("调用p端接口查询应用详情失败err:%v", err)
resp.Code = "500"
resp.Msg = err.Error()
return resp, err
}
resp.Code = "200"
return appDetail, err
}

View File

@ -1,114 +0,0 @@
package apps
import (
"context"
"gitlink.org.cn/JointCloud/pcm-kubernetes/kubernetes"
"gorm.io/datatypes"
"gorm.io/gorm"
"time"
"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 AppListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAppListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AppListLogic {
return &AppListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
type Task struct {
Id int64 `db:"id"` // id
Name string `db:"name"` // 作业名称
Description string `db:"description"` // 作业描述
Status string `db:"status"` // 作业状态
Strategy int64 `db:"strategy"` // 策略
SynergyStatus int64 `db:"synergy_status"` // 协同状态0-未协同、1-已协同)
CommitTime time.Time `db:"commit_time"` // 提交时间
StartTime string `db:"start_time"` // 开始时间
EndTime string `db:"end_time"` // 结束运行时间
RunningTime int64 `db:"running_time"` // 已运行时间(单位秒)
YamlString datatypes.JSON `db:"yaml_string"`
Result string `db:"result"` // 作业结果
DeletedAt gorm.DeletedAt `gorm:"index"`
NsID string `db:"ns_id"`
PName string `db:"p_name"` // p端名称
PId int64 `db:"p_id"` // p端id
}
func (l *AppListLogic) AppList(req *types.AppListReq) (resp *types.AppListResp, err error) {
var tasks []Task
resp = &types.AppListResp{}
l.svcCtx.DbEngin.Raw("select * from task t where t.`ns_id` = ? AND t.`deleted_at` IS NULL ORDER BY t.created_time Desc", req.NsID).Scan(&tasks)
for _, task := range tasks {
//调用p端接口查询应用状态 running、creating、waiting、error、pause
data, err := l.svcCtx.K8sRpc.GetAppByAppName(context.Background(), &kubernetes.DeploymentDetailReq{
Namespace: req.NsID,
Name: task.Name,
})
if err != nil {
logx.Errorf("调用p端接口查询应用失败err:%v", err)
return resp, err
}
minReplicas := ""
maxReplicas := ""
status := "creating"
if data.Data.Deployment != nil {
app := data.Data.Deployment
maxReplicas = app.Metadata.Annotations["deploy.cloud.sealos.io/maxReplicas"]
minReplicas = app.Metadata.Annotations["deploy.cloud.sealos.io/minReplicas"]
if app.Status != nil {
if app.Status.Replicas == nil && app.Status.AvailableReplicas == nil {
status = "pause"
} else if app.Status.Replicas != nil && app.Status.AvailableReplicas == nil {
status = "creating"
} else if *app.Status.Replicas == *app.Status.AvailableReplicas {
status = "running"
}
}
} else if data.Data.StatefulSet != nil {
app := data.Data.StatefulSet
maxReplicas = app.Metadata.Annotations["deploy.cloud.sealos.io/maxReplicas"]
minReplicas = app.Metadata.Annotations["deploy.cloud.sealos.io/minReplicas"]
if app.Status != nil {
replicas := app.Status.Replicas
availableReplicas := app.Status.AvailableReplicas
if *replicas == 0 && *availableReplicas == 0 {
status = "pause"
} else if *replicas == *availableReplicas {
status = "running"
} else if *replicas > *availableReplicas {
status = "creating"
}
}
}
var details []types.AppLocation
sql :=
`select phy.id as participant_id, phy.name as participant_name, c.kind
from cloud c
join sc_participant_phy_info phy on c.participant_id = phy.id
WHERE c.kind in ('Deployment', 'StatefulSet')
and task_id = ?`
l.svcCtx.DbEngin.Raw(sql, task.Id).Scan(&details)
resp.Apps = append(resp.Apps, types.App{
Id: task.Id,
Name: task.Name,
Status: status,
CreateTime: task.CommitTime.Format("2006-01-02 15:04:05"),
MinReplicas: minReplicas,
MaxReplicas: maxReplicas,
AppLocations: details,
})
}
return
}

View File

@ -1,42 +0,0 @@
package apps
import (
"context"
"gitlink.org.cn/JointCloud/pcm-kubernetes/kubernetes"
"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 AppPodsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAppPodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AppPodsLogic {
return &AppPodsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *AppPodsLogic) AppPods(req *types.AppDetailReq) (resp *kubernetes.PodDetailResp, err error) {
resp = &kubernetes.PodDetailResp{}
//调用p端接口查询应用详情
podList, err := l.svcCtx.K8sRpc.GetAppPodsByAppName(context.Background(), &kubernetes.AppDetailReq{
Namespace: req.NsID,
Name: req.Name,
})
if err != nil {
logx.Errorf("调用p端接口查询应用详情失败err:%v", err)
resp.Code = "500"
resp.Msg = err.Error()
return resp, err
}
resp.Code = "200"
return podList, err
}

View File

@ -1,49 +0,0 @@
package apps
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
)
type DeleteAppByAppNameLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteAppByAppNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteAppByAppNameLogic {
return &DeleteAppByAppNameLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DeleteAppByAppNameLogic) DeleteAppByAppName(req *types.DeleteAppReq) (resp *types.DeleteAppResp, err error) {
resp = &types.DeleteAppResp{}
var task = &Task{}
//查询应用的yamlString
l.svcCtx.DbEngin.Raw(`select * from task where ns_id= ? and name= ? AND deleted_at IS NULL`, req.NsID, req.Name).Scan(&task)
if task.Id == 0 {
resp.Code = 500
resp.Msg = "App not fount"
return resp, err
}
//删除主任务信息
l.svcCtx.DbEngin.Model(&models.Task{}).Where("id", task.Id).Update("status", constants.Deleted)
tx := l.svcCtx.DbEngin.Delete(&models.Task{}, task.Id)
if tx.Error != nil {
return nil, tx.Error
}
// 将子任务状态修改为待删除
tx = l.svcCtx.DbEngin.Model(&models.Cloud{}).Where("task_id", task.Id).Update("status", constants.WaitDelete)
l.svcCtx.DbEngin.Where("task_id = ?", task.Id).Delete(&models.Cloud{})
if tx.Error != nil {
return nil, tx.Error
}
return
}

View File

@ -1,33 +0,0 @@
package apps
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
)
type GetAppByAppNameLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetAppByAppNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAppByAppNameLogic {
return &GetAppByAppNameLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetAppByAppNameLogic) GetAppByAppName(req *types.AppDetailReq) (resp interface{}, err error) {
var task Task
db := l.svcCtx.DbEngin.Raw("select * from task where ns_id = ? and name = ? AND deleted_at IS NULL", req.NsID, req.Name).Scan(&task)
if db.Error != nil {
logx.Errorf("db error: %v", db.Error)
return
}
resp = task.YamlString
return
}

View File

@ -1,41 +0,0 @@
package apps
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"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 PauseAppByAppNameLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewPauseAppByAppNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PauseAppByAppNameLogic {
return &PauseAppByAppNameLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *PauseAppByAppNameLogic) PauseAppByAppName(req *types.DeleteAppReq) (resp *types.AppResp, err error) {
resp = &types.AppResp{}
var task = &Task{}
//查询应用的yamlString
l.svcCtx.DbEngin.Raw(`select * from task where ns_id= ? and name= ? AND deleted_at IS NULL`, req.NsID, req.Name).Scan(&task)
if task.Id == 0 {
resp.Code = 500
resp.Msg = "App not fount"
return resp, err
}
// 将子任务状态修改为待暂停
l.svcCtx.DbEngin.Model(&models.Cloud{}).Where("task_id", task.Id).Update("status", constants.WaitPause)
return
}

View File

@ -1,41 +0,0 @@
package apps
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"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 RestartAppByAppNameLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewRestartAppByAppNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RestartAppByAppNameLogic {
return &RestartAppByAppNameLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *RestartAppByAppNameLogic) RestartAppByAppName(req *types.DeleteAppReq) (resp *types.AppResp, err error) {
resp = &types.AppResp{}
var task = &Task{}
//查询应用的yamlString
l.svcCtx.DbEngin.Raw(`select * from task where ns_id= ? and name= ? AND deleted_at IS NULL`, req.NsID, req.Name).Scan(&task)
if task.Id == 0 {
resp.Code = 500
resp.Msg = "App not fount"
return resp, err
}
// 将子任务状态修改为待重启
l.svcCtx.DbEngin.Model(&models.Cloud{}).Where("task_id", task.Id).Update("status", constants.WaitRestart)
return
}

View File

@ -1,41 +0,0 @@
package apps
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"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 StartAppByAppNameLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewStartAppByAppNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StartAppByAppNameLogic {
return &StartAppByAppNameLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *StartAppByAppNameLogic) StartAppByAppName(req *types.DeleteAppReq) (resp *types.AppResp, err error) {
resp = &types.AppResp{}
var task = &Task{}
//查询应用的yamlString
l.svcCtx.DbEngin.Raw(`select * from task where ns_id= ? and name= ? AND deleted_at IS NULL`, req.NsID, req.Name).Scan(&task)
if task.Id == 0 {
resp.Code = 500
resp.Msg = "App not fount"
return resp, err
}
// 将子任务状态修改为待启动
l.svcCtx.DbEngin.Model(&models.Cloud{}).Where("task_id", task.Id).Update("status", constants.WaitStart)
return
}

View File

@ -1,30 +0,0 @@
package apps
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 UpdateAppByAppNameLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUpdateAppByAppNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateAppByAppNameLogic {
return &UpdateAppByAppNameLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UpdateAppByAppNameLogic) UpdateAppByAppName(req *types.DeleteAppReq) (resp *types.AppTaskResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -1,56 +0,0 @@
package cloud
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"gitlink.org.cn/JointCloud/pcm-kubernetes/kubernetes"
"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 NoticeTenantLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewNoticeTenantLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NoticeTenantLogic {
return &NoticeTenantLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// NoticeTenant 通知更新租户数据
func (l *NoticeTenantLogic) NoticeTenant() (resp *types.CloudResp, err error) {
var tenants []*models.ScTenantInfo
//从p端kubernetes获取租户信息
namespace, err := l.svcCtx.K8sRpc.ListNamespace(context.Background(), &kubernetes.NamespaceListReq{})
if err != nil {
logx.Errorf("获取租户信息失败:%v", err)
return nil, err
}
//先删除所有租户数据
l.svcCtx.DbEngin.Where("type = 0").Delete(models.ScTenantInfo{})
//遍历租户信息
for k, v := range namespace.Data {
tenants = append(tenants, &models.ScTenantInfo{
Id: utils.GenSnowflakeID(),
TenantName: k,
Clusters: v,
Type: 0,
})
}
tx := l.svcCtx.DbEngin.Save(&tenants)
if tx.Error != nil {
logx.Errorf("保存租户信息失败:%v", tx.Error)
return nil, err
}
logx.Info("更新租户数据成功")
return
}

View File

@ -1,49 +0,0 @@
package cloud
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"gitlink.org.cn/JointCloud/pcm-kubernetes/kubernetes"
)
type UpdateTenantLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUpdateTenantLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateTenantLogic {
return &UpdateTenantLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// UpdateTenant 更新租户数据
func (l *UpdateTenantLogic) UpdateTenant(req *types.UpdateTenantReq) (resp *types.CloudResp, err error) {
var tenants []*models.ScTenantInfo
//从p端kubernetes获取租户信息
namespace, err := l.svcCtx.K8sRpc.ListNamespace(context.Background(), &kubernetes.NamespaceListReq{})
if err != nil {
return nil, err
}
//先删除所有租户数据
l.svcCtx.DbEngin.Where("type = 0").Delete(models.ScTenantInfo{})
//遍历租户信息
for k, v := range namespace.Data {
tenants = append(tenants, &models.ScTenantInfo{
Id: utils.GenSnowflakeID(),
TenantName: k,
Clusters: v,
Type: 0,
})
}
l.svcCtx.DbEngin.Save(&tenants)
return
}

View File

@ -1,147 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package core
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/tracker"
"gitlink.org.cn/JointCloud/pcm-kubernetes/kubernetesclient"
"time"
"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 TaskDetailLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewTaskDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TaskDetailLogic {
return &TaskDetailLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *TaskDetailLogic) TaskDetail(req *types.TaskDetailReq) (resp *types.TaskDetailResp, err error) {
resp = &types.TaskDetailResp{}
var clouds []models.Cloud
l.svcCtx.DbEngin.Where("task_id = ?", req.TaskId).Find(&clouds)
for _, cloud := range clouds {
if l.svcCtx.K8sRpc == nil {
continue
}
// 查询监控地址
var metricsUrl string
l.svcCtx.DbEngin.Raw(" SELECT metrics_url FROM `sc_participant_phy_info` WHERE id = ? ", cloud.ParticipantId).Scan(&metricsUrl)
//
var pods []*kubernetesclient.Pod
switch cloud.Kind {
case "Job":
jobResult, err := l.svcCtx.K8sRpc.JobDetail(context.Background(), &kubernetesclient.JobDetailReq{
Namespace: cloud.Namespace,
Name: cloud.Name,
})
if err != nil {
return nil, err
}
// 查询出job下关联的pod列表
uid := jobResult.Job.Metadata.Labels["controller-uid"]
LabelSelector := "controller-uid=" + uid
podResp, err := l.svcCtx.K8sRpc.PodList(context.Background(), &kubernetesclient.PodListReq{
ListOptions: &kubernetesclient.ListOptions{
LabelSelector: &LabelSelector,
},
})
if err != nil {
return nil, err
}
pods = podResp.PodList.Items
case "Deployment":
deploymentResult, err := l.svcCtx.K8sRpc.DeploymentDetail(context.Background(), &kubernetesclient.DeploymentDetailReq{
Namespace: cloud.Namespace,
Name: cloud.Name,
})
if err != nil {
return nil, err
}
// 查询出job下关联的pod列表
uid := deploymentResult.Deployment.Spec.Selector.MatchLabels["app"]
LabelSelector := "app=" + uid
podResp, err := l.svcCtx.K8sRpc.PodList(context.Background(), &kubernetesclient.PodListReq{
ListOptions: &kubernetesclient.ListOptions{
LabelSelector: &LabelSelector,
},
})
if err != nil {
return nil, err
}
pods = podResp.PodList.Items
}
podsMetrics(metricsUrl, pods, resp)
}
return resp, nil
}
func podsMetrics(metricsUrl string, pods []*kubernetesclient.Pod, resp *types.TaskDetailResp) {
// 查询每个pod资源使用情况
for _, pod := range pods {
prometheusClient, _ := tracker.NewPrometheus(metricsUrl)
// cpu需求量
podCpuLimit := prometheusClient.GetNamedMetrics([]string{"pod_cpu_resource_limits"}, time.Now(), tracker.PodOption{
PodName: *pod.Metadata.Name,
NamespaceName: *pod.Metadata.Namespace,
})
resp.CpuLimit = metricAdd(resp.CpuLimit, podCpuLimit)
// cpu使用量
podCpuUsage := prometheusClient.GetNamedMetrics([]string{"pod_cpu_usage"}, time.Now(), tracker.PodOption{
PodName: *pod.Metadata.Name,
NamespaceName: *pod.Metadata.Namespace,
})
resp.CpuCores = metricAdd(resp.CpuCores, podCpuUsage)
// 内存使用量
podMemoryUsage := prometheusClient.GetNamedMetrics([]string{"pod_memory_usage"}, time.Now(), tracker.PodOption{
PodName: *pod.Metadata.Name,
NamespaceName: *pod.Metadata.Namespace,
})
resp.MemoryTotal = metricAdd(resp.MemoryTotal, podMemoryUsage)
// 内存需求量
podMemoryLimit := prometheusClient.GetNamedMetrics([]string{"pod_memory_resource_limits"}, time.Now(), tracker.PodOption{
PodName: *pod.Metadata.Name,
NamespaceName: *pod.Metadata.Namespace,
})
resp.MemoryLimit = metricAdd(resp.MemoryLimit, podMemoryLimit)
}
resp.MemoryTotal = resp.MemoryTotal / float64(1073741824)
resp.MemoryLimit = resp.MemoryLimit / float64(1073741824)
}
func metricAdd(z float64, metric []tracker.Metric) float64 {
if metric[0].MetricValues != nil {
z = z + metric[0].MetricValues[0].Sample.Value()
}
return z
}

View File

@ -1,42 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package image
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
)
type ChunkLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChunkLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChunkLogic {
return &ChunkLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChunkLogic) Chunk() error {
// todo: add your logic here and delete this line
return nil
}

View File

@ -1,51 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package image
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"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 DataSetCheckLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDataSetCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DataSetCheckLogic {
return &DataSetCheckLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DataSetCheckLogic) DataSetCheck(req *types.CheckReq) (resp *types.CheckResp, err error) {
resp = &types.CheckResp{}
var dataSets []models.File
l.svcCtx.DbEngin.Find(&dataSets).Where("md5", req.FileMd5)
if len(dataSets) != 0 {
resp.Exist = true
} else {
resp.Exist = false
}
return resp, nil
}

View File

@ -1,52 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package image
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
)
type ImageListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
type ImageTags struct {
Name string `json:"name"`
Tags []string `json:"tags" copier:"tags"`
}
func NewImageListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ImageListLogic {
return &ImageListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ImageListLogic) ImageList() (resp *types.ImageListResp, err error) {
var images []string
l.svcCtx.DbEngin.Raw("select distinct name from file where kind = 'image'").Scan(&images)
result := types.ImageListResp{
Repositories: images,
}
return &result, nil
}

View File

@ -1,40 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package image
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
)
type UploadDataSetLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUploadDataSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadDataSetLogic {
return &UploadDataSetLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UploadDataSetLogic) UploadDataSet() error {
return nil
}

View File

@ -1,42 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package image
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
)
type UploadLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogic {
return &UploadLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UploadLogic) Upload() error {
// todo: add your logic here and delete this line
return nil
}

View File

@ -18,7 +18,6 @@ import (
"github.com/go-redis/redis/v8"
"github.com/go-resty/resty/v2"
alert "github.com/prometheus/alertmanager/api/v2/client"
"github.com/robfig/cron/v3"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/zrpc"
"gitlink.org.cn/JointCloud/pcm-ac/hpcacclient"
@ -29,7 +28,6 @@ import (
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/tracker"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"gitlink.org.cn/JointCloud/pcm-coordinator/rpc/client/participantservice"
"gitlink.org.cn/JointCloud/pcm-kubernetes/kubernetesclient"
"gitlink.org.cn/JointCloud/pcm-modelarts/client/imagesservice"
"gitlink.org.cn/JointCloud/pcm-modelarts/client/modelartsservice"
"gitlink.org.cn/JointCloud/pcm-octopus/octopusclient"
@ -46,7 +44,6 @@ import (
type ServiceContext struct {
Config config.Config
RedisClient *redis.Client
Cron *cron.Cron
ModelArtsRpc modelartsservice.ModelArtsService
ModelArtsImgRpc imagesservice.ImagesService
DbEngin *gorm.DB
@ -55,7 +52,6 @@ type ServiceContext struct {
OctopusRpc octopusclient.Octopus
CephRpc cephclient.Ceph
OpenstackRpc openstackclient.Openstack
K8sRpc kubernetesclient.Kubernetes
MonitorClient map[int64]tracker.Prometheus
ParticipantRpc participantservice.ParticipantService
PromClient tracker.Prometheus
@ -126,7 +122,6 @@ func NewServiceContext(c config.Config) *ServiceContext {
scheduler := scheduler.NewSchdlr(aiService, storage)
return &ServiceContext{
Cron: cron.New(cron.WithSeconds()),
DbEngin: dbEngin,
Config: c,
RedisClient: redisClient,
@ -136,7 +131,6 @@ func NewServiceContext(c config.Config) *ServiceContext {
ACRpc: hpcacclient.NewHpcAC(zrpc.MustNewClient(c.ACRpcConf)),
OctopusRpc: octopusclient.NewOctopus(zrpc.MustNewClient(c.OctopusRpcConf)),
OpenstackRpc: openstackclient.NewOpenstack(zrpc.MustNewClient(c.OpenstackRpcConf)),
K8sRpc: kubernetesclient.NewKubernetes(zrpc.MustNewClient(c.K8sNativeConf)),
MonitorClient: make(map[int64]tracker.Prometheus),
ParticipantRpc: participantservice.NewParticipantService(zrpc.MustNewClient(c.PcmCoreRpcConf)),
PromClient: promClient,

View File

@ -22,7 +22,6 @@ import (
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/rest"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/config"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/cron"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/mqs"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
@ -44,8 +43,6 @@ func main() {
ctx := svc.NewServiceContext(c)
// start log component
logx.MustSetup(c.LogConf)
ctx.Cron.Start()
cron.AddCronGroup(ctx)
handler.RegisterHandlers(server, ctx)
serviceGroup.Add(server)

View File

@ -68,7 +68,6 @@ podTemplate(label: label, containers: [
cd ${code_path}
sed -i 's#image_name#${image}#' ${project_name}.yaml
sed -i 's#secret_name#${secret_name}#' ${project_name}.yaml
sed -i 's#nacos_host#${nacos_host}#' ${project_name}.yaml
cat ${project_name}.yaml
kubectl apply -f ${project_name}.yaml
"""

View File

@ -67,7 +67,6 @@ podTemplate(label: label, containers: [
cd ${code_path}
sed -i 's#image_name#${image}#' ${project_name}.yaml
sed -i 's#secret_name#${secret_name}#' ${project_name}.yaml
sed -i 's#nacos_host#${nacos_host}#' ${project_name}.yaml
cat ${project_name}.yaml
kubectl apply -f ${project_name}.yaml
"""

12
go.mod
View File

@ -5,9 +5,7 @@ go 1.21
retract v0.1.20-0.20240319015239-6ae13da05255
require (
github.com/JCCE-nudt/zero-contrib/zrpc/registry/nacos v0.0.0-20230419021610-13bbc83fbc3c
github.com/Masterminds/squirrel v1.5.4
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1800
github.com/bwmarrin/snowflake v0.3.0
github.com/ghodss/yaml v1.0.0
github.com/go-redis/redis/v8 v8.11.5
@ -15,14 +13,12 @@ require (
github.com/go-sql-driver/mysql v1.7.1
github.com/jinzhu/copier v0.4.0
github.com/json-iterator/go v1.1.12
github.com/nacos-group/nacos-sdk-go/v2 v2.2.5
github.com/pkg/errors v0.9.1
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.71.2
github.com/prometheus/alertmanager v0.27.0
github.com/prometheus/client_golang v1.19.0
github.com/prometheus/common v0.52.2
github.com/robfig/cron/v3 v3.0.1
github.com/rs/zerolog v1.28.0
github.com/zeromicro/go-zero v1.6.3
gitlink.org.cn/JointCloud/pcm-ac v0.0.0-20240426095603-549fefd8bece
gitlink.org.cn/JointCloud/pcm-kubernetes v0.0.0-20240301071143-347480abff2c
@ -46,17 +42,11 @@ require (
require (
github.com/alecthomas/kingpin/v2 v2.4.0 // indirect
github.com/alecthomas/units v0.0.0-20231202071711-9a357b53e9c9 // indirect
github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 // indirect
github.com/alibabacloud-go/tea v1.1.17 // indirect
github.com/alibabacloud-go/tea-utils v1.4.4 // indirect
github.com/aliyun/alibabacloud-dkms-gcs-go-sdk v0.2.2 // indirect
github.com/aliyun/alibabacloud-dkms-transfer-go-sdk v0.1.7 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/aws/aws-sdk-go v1.50.8 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
@ -166,8 +156,6 @@ require (
google.golang.org/genproto/googleapis/api v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.29.3 // indirect

988
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -1,241 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package nacos
import (
"context"
"encoding/json"
"fmt"
"github.com/JCCE-nudt/zero-contrib/zrpc/registry/nacos"
"github.com/nacos-group/nacos-sdk-go/v2/clients"
"github.com/nacos-group/nacos-sdk-go/v2/clients/nacos_client"
"github.com/nacos-group/nacos-sdk-go/v2/clients/naming_client/naming_cache"
"github.com/nacos-group/nacos-sdk-go/v2/clients/naming_client/naming_proxy"
"github.com/nacos-group/nacos-sdk-go/v2/common/constant"
"github.com/nacos-group/nacos-sdk-go/v2/common/http_agent"
"github.com/nacos-group/nacos-sdk-go/v2/common/nacos_server"
"github.com/nacos-group/nacos-sdk-go/v2/common/security"
"github.com/nacos-group/nacos-sdk-go/v2/vo"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest"
"github.com/zeromicro/go-zero/zrpc"
nacosVo "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/helper/nacos/vo"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"net/http"
"sync"
)
type (
BootstrapConfig struct {
NacosConfig NacosConfig
}
ListenConfig func(data string)
NacosServerConfig struct {
IpAddr string
Port uint64
}
NacosClientConfig struct {
NamespaceId string
TimeoutMs uint64
NotLoadCacheAtStart bool
LogDir string
CacheDir string
LogLevel string
}
NacosConfig struct {
ServerConfigs []NacosServerConfig
ClientConfig NacosClientConfig
DataId string
Group string
}
)
// NamingClient ...
type NamingClient struct {
nacos_client.INacosClient
ctx context.Context
cancel context.CancelFunc
serviceProxy naming_proxy.INamingProxy
serviceInfoHolder *naming_cache.ServiceInfoHolder
clientConfig constant.ClientConfig
}
func (n *NacosConfig) Discovery(c *zrpc.RpcServerConf) {
sc, cc := n.buildConfig()
opts := nacos.NewNacosConfig(c.Name, c.ListenOn, sc, &cc)
opts.Group = n.Group
err := nacos.RegisterService(opts)
if err != nil {
panic(err)
}
}
func (n *NacosConfig) DiscoveryRest(c *rest.RestConf) {
sc, cc := n.buildConfig()
opts := nacos.NewNacosConfig(c.Name, fmt.Sprintf("%s:%d", c.Host, c.Port), sc, &cc)
err := nacos.RegisterService(opts)
if err != nil {
panic(err)
}
}
func (n *NacosConfig) InitConfig(listenConfigCallback ListenConfig) string {
//nacos server
sc, cc := n.buildConfig()
pa := vo.NacosClientParam{
ClientConfig: &cc,
ServerConfigs: sc,
}
configClient, err := clients.NewConfigClient(pa)
if err != nil {
panic(err)
}
//获取配置中心内容
content, err := configClient.GetConfig(vo.ConfigParam{
DataId: n.DataId,
Group: n.Group,
})
if err != nil {
panic(err)
}
//设置配置监听
if err = configClient.ListenConfig(vo.ConfigParam{
DataId: n.DataId,
Group: n.Group,
OnChange: func(namespace, group, dataId, data string) {
//配置文件产生变化就会触发
if len(data) == 0 {
logx.Errorf("listen nacos data nil error , namespace : %sgroup : %s , dataId : %s , data : %s", namespace, group, dataId, data)
return
}
listenConfigCallback(data)
},
}); err != nil {
panic(err)
}
if len(content) == 0 {
panic("read nacos nacos content err , content is nil")
}
return content
}
func (n *NacosConfig) buildConfig() ([]constant.ServerConfig, constant.ClientConfig) {
var sc []constant.ServerConfig
if len(n.ServerConfigs) == 0 {
panic("nacos server no set")
}
for _, serveConfig := range n.ServerConfigs {
sc = append(sc, constant.ServerConfig{
Port: serveConfig.Port,
IpAddr: serveConfig.IpAddr,
},
)
}
//nacos client
cc := constant.ClientConfig{
NamespaceId: n.ClientConfig.NamespaceId,
TimeoutMs: n.ClientConfig.TimeoutMs,
NotLoadCacheAtStart: n.ClientConfig.NotLoadCacheAtStart,
LogDir: n.ClientConfig.LogDir,
CacheDir: n.ClientConfig.CacheDir,
LogLevel: n.ClientConfig.LogLevel,
}
return sc, cc
}
type NacosServer struct {
sync.RWMutex
securityLogin security.AuthClient
serverList []constant.ServerConfig
httpAgent http_agent.IHttpAgent
timeoutMs uint64
endpoint string
lastSrvRefTime int64
vipSrvRefInterMills int64
contextPath string
currentIndex int32
ServerSrcChangeSignal chan struct{}
}
// GetAllServicesInfo Get all Services
func (n *NacosConfig) GetAllServicesInfo() (nacosVo.NacosServiceList, error) {
nacosServiceList := nacosVo.NacosServiceList{}
api := constant.SERVICE_BASE_PATH + "/catalog/services"
nacosServer, err := nacos_server.NewNacosServer(context.Background(),
[]constant.ServerConfig{*constant.NewServerConfig(n.ServerConfigs[0].IpAddr, n.ServerConfigs[0].Port)},
constant.ClientConfig{},
&http_agent.HttpAgent{},
1000,
"")
if err != nil {
return nacosServiceList, err
}
params := map[string]string{}
params["namespaceId"] = n.ClientConfig.NamespaceId
params["groupName"] = ""
params["pageNo"] = "1"
params["pageSize"] = "10000"
result, err := nacosServer.ReqApi(api, params, http.MethodGet, constant.ClientConfig{})
if err != nil {
logx.Errorf("Failed to get all services ,error: <%+v>, namespace : <%s> ", err, n.ClientConfig.NamespaceId)
return nacosServiceList, err
}
err1 := json.Unmarshal([]byte(result), &nacosServiceList)
if err1 != nil {
logx.Errorf("Conversion failed ,error: %+v, str: %s", err1, result)
return nacosServiceList, err
}
return nacosServiceList, err
}
// GetAllGroupName Get all GroupName
func (n *NacosConfig) GetAllGroupName() (nacosGroupList nacosVo.NacosGroupList, err error) {
nacosServiceList := nacosVo.NacosServiceList{}
api := constant.SERVICE_BASE_PATH + "/catalog/services"
nacosServer, err := nacos_server.NewNacosServer(context.Background(),
[]constant.ServerConfig{*constant.NewServerConfig(n.ServerConfigs[0].IpAddr, n.ServerConfigs[0].Port)},
constant.ClientConfig{},
&http_agent.HttpAgent{},
1000,
"")
if err != nil {
return nacosGroupList, err
}
params := map[string]string{}
params["namespaceId"] = "test"
params["groupName"] = ""
params["pageNo"] = "1"
params["pageSize"] = "10000"
result, err := nacosServer.ReqApi(api, params, http.MethodGet, constant.ClientConfig{})
err1 := json.Unmarshal([]byte(result), &nacosServiceList)
if err1 != nil {
logx.Errorf("Conversion failed ,error: %+v, str: %s", err1, result)
return nacosGroupList, err1
}
for _, v := range nacosServiceList.ServiceList {
nacosGroupList.GroupName = append(nacosGroupList.GroupName, v.GroupName)
}
nacosGroupList.GroupName = utils.RemoveDuplication_map(nacosGroupList.GroupName)
return nacosGroupList, err
}

View File

@ -1,19 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package vo
type NacosGroupList struct {
GroupName []string `json:"groupName"`
}

View File

@ -1,22 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package vo
import "github.com/aliyun/alibaba-cloud-sdk-go/services/mse"
type NacosServiceList struct {
Count int `json:"count"`
ServiceList []mse.SimpleNacosAnsService `json:"serviceList"`
}

View File

@ -20,15 +20,7 @@ import (
)
type Interface interface {
//GetMetric(expr string, time time.Time) Metric
//GetMetricOverTime(expr string, start, end time.Time, step time.Duration) Metric
GetNamedMetrics(metrics []string, time time.Time, opt QueryOption) []Metric
GetNamedMetricsByTime(metrics []string, start, end string, step time.Duration, opt QueryOption) []Metric
//GetMetadata(namespace string) []Metadata
//GetMetricLabelSet(expr string, start, end time.Time) []map[string]string
//
//// meter
//GetNamedMeters(meters []string, time time.Time, opts []QueryOption) []Metric
//GetNamedMetersOverTime(metrics []string, start, end time.Time, step time.Duration, opts []QueryOption) []Metric
GetRawData(expr string, o QueryOption) (model.Value, error)
}

View File

@ -17,7 +17,6 @@ package svc
import (
"github.com/go-redis/redis/v8"
_ "github.com/go-sql-driver/mysql"
"github.com/robfig/cron/v3"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"gitlink.org.cn/JointCloud/pcm-coordinator/rpc/internal/config"
@ -31,7 +30,6 @@ import (
type ServiceContext struct {
Config config.Config
DbEngin *gorm.DB
Cron *cron.Cron
RedisClient *redis.Client
}
@ -59,7 +57,6 @@ func NewServiceContext(c config.Config) *ServiceContext {
panic("InitSnowflake err")
}
return &ServiceContext{
Cron: cron.New(cron.WithSeconds()),
Config: c,
DbEngin: dbEngin,
RedisClient: redis.NewClient(&redis.Options{