mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 15:00:27 +08:00
显示SSH认证相关集群、节点
This commit is contained in:
@@ -249,6 +249,25 @@ func (this *NodeClusterDAO) UpdateClusterHealthCheck(clusterId int64, healthChec
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 计算使用某个认证的集群数量
|
||||||
|
func (this *NodeClusterDAO) CountAllEnabledClustersWithGrantId(grantId int64) (int64, error) {
|
||||||
|
return this.Query().
|
||||||
|
State(NodeClusterStateEnabled).
|
||||||
|
Attr("grantId", grantId).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取使用某个认证的所有集群
|
||||||
|
func (this *NodeClusterDAO) FindAllEnabledClustersWithGrantId(grantId int64) (result []*NodeCluster, err error) {
|
||||||
|
_, err = this.Query().
|
||||||
|
State(NodeClusterStateEnabled).
|
||||||
|
Attr("grantId", grantId).
|
||||||
|
Slice(&result).
|
||||||
|
DescPk().
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 生成唯一ID
|
// 生成唯一ID
|
||||||
func (this *NodeClusterDAO) genUniqueId() (string, error) {
|
func (this *NodeClusterDAO) genUniqueId() (string, error) {
|
||||||
for {
|
for {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/rands"
|
"github.com/iwind/TeaGo/rands"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -300,6 +301,7 @@ func (this *NodeDAO) FindAllInactiveNodesWithClusterId(clusterId int64) (result
|
|||||||
State(NodeStateEnabled).
|
State(NodeStateEnabled).
|
||||||
Attr("clusterId", clusterId).
|
Attr("clusterId", clusterId).
|
||||||
Attr("isOn", true). // 只监控启用的节点
|
Attr("isOn", true). // 只监控启用的节点
|
||||||
|
Attr("isInstalled", true). // 只监控已经安装的节点
|
||||||
Where("(status IS NULL OR (JSON_EXTRACT(status, '$.isActive')=false AND UNIX_TIMESTAMP()-JSON_EXTRACT(status, '$.updatedAt')>10) OR UNIX_TIMESTAMP()-JSON_EXTRACT(status, '$.updatedAt')>120)").
|
Where("(status IS NULL OR (JSON_EXTRACT(status, '$.isActive')=false AND UNIX_TIMESTAMP()-JSON_EXTRACT(status, '$.updatedAt')>10) OR UNIX_TIMESTAMP()-JSON_EXTRACT(status, '$.updatedAt')>120)").
|
||||||
Slice(&result).
|
Slice(&result).
|
||||||
FindAll()
|
FindAll()
|
||||||
@@ -501,6 +503,27 @@ func (this *NodeDAO) FindEnabledNodeIdWithUniqueId(uniqueId string) (int64, erro
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 计算使用某个认证的节点数量
|
||||||
|
func (this *NodeDAO) CountAllEnabledNodesWithGrantId(grantId int64) (int64, error) {
|
||||||
|
return this.Query().
|
||||||
|
State(NodeStateEnabled).
|
||||||
|
Where("id IN (SELECT nodeId FROM edgeNodeLogins WHERE type='ssh' AND JSON_CONTAINS(params, :grantParam))").
|
||||||
|
Param("grantParam", string(maps.Map{"grantId": grantId}.AsJSON())).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查找使用某个认证的所有节点
|
||||||
|
func (this *NodeDAO) FindAllEnabledNodesWithGrantId(grantId int64) (result []*Node, err error) {
|
||||||
|
_, err = this.Query().
|
||||||
|
State(NodeStateEnabled).
|
||||||
|
Where("id IN (SELECT nodeId FROM edgeNodeLogins WHERE type='ssh' AND JSON_CONTAINS(params, :grantParam))").
|
||||||
|
Param("grantParam", string(maps.Map{"grantId": grantId}.AsJSON())).
|
||||||
|
Slice(&result).
|
||||||
|
DescPk().
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 生成唯一ID
|
// 生成唯一ID
|
||||||
func (this *NodeDAO) genUniqueId() (string, error) {
|
func (this *NodeDAO) genUniqueId() (string, error) {
|
||||||
for {
|
for {
|
||||||
|
|||||||
@@ -428,3 +428,56 @@ func (this *NodeService) UpdateNodeConnectedAPINodes(ctx context.Context, req *p
|
|||||||
|
|
||||||
return rpcutils.RPCUpdateSuccess()
|
return rpcutils.RPCUpdateSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 计算使用某个认证的节点数量
|
||||||
|
func (this *NodeService) CountAllEnabledNodesWithGrantId(ctx context.Context, req *pb.CountAllEnabledNodesWithGrantIdRequest) (*pb.CountAllEnabledNodesWithGrantIdResponse, error) {
|
||||||
|
// 校验请求
|
||||||
|
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
count, err := models.SharedNodeDAO.CountAllEnabledNodesWithGrantId(req.GrantId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &pb.CountAllEnabledNodesWithGrantIdResponse{Count: count}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查找使用某个认证的所有节点
|
||||||
|
func (this *NodeService) FindAllEnabledNodesWithGrantId(ctx context.Context, req *pb.FindAllEnabledNodesWithGrantIdRequest) (*pb.FindAllEnabledNodesWithGrantIdResponse, error) {
|
||||||
|
// 校验请求
|
||||||
|
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes, err := models.SharedNodeDAO.FindAllEnabledNodesWithGrantId(req.GrantId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := []*pb.Node{}
|
||||||
|
for _, node := range nodes {
|
||||||
|
// 集群信息
|
||||||
|
clusterName, err := models.SharedNodeClusterDAO.FindNodeClusterName(int64(node.ClusterId))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result = append(result, &pb.Node{
|
||||||
|
Id: int64(node.Id),
|
||||||
|
Name: node.Name,
|
||||||
|
Version: int64(node.Version),
|
||||||
|
IsInstalled: node.IsInstalled == 1,
|
||||||
|
Status: node.Status,
|
||||||
|
Cluster: &pb.NodeCluster{
|
||||||
|
Id: int64(node.ClusterId),
|
||||||
|
Name: clusterName,
|
||||||
|
},
|
||||||
|
IsOn: node.IsOn == 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.FindAllEnabledNodesWithGrantIdResponse{Nodes: result}, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -309,3 +309,44 @@ func (this *NodeClusterService) ExecuteNodeClusterHealthCheck(ctx context.Contex
|
|||||||
}
|
}
|
||||||
return &pb.ExecuteNodeClusterHealthCheckResponse{Results: pbResults}, nil
|
return &pb.ExecuteNodeClusterHealthCheckResponse{Results: pbResults}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 计算使用某个认证的集群数量
|
||||||
|
func (this *NodeClusterService) CountAllEnabledNodeClustersWithGrantId(ctx context.Context, req *pb.CountAllEnabledNodeClustersWithGrantIdRequest) (*pb.CountAllEnabledNodeClustersWithGrantIdResponse, error) {
|
||||||
|
// 校验请求
|
||||||
|
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
count, err := models.SharedNodeClusterDAO.CountAllEnabledClustersWithGrantId(req.GrantId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &pb.CountAllEnabledNodeClustersWithGrantIdResponse{Count: count}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查找使用某个认证的所有集群
|
||||||
|
func (this *NodeClusterService) FindAllEnabledNodeClustersWithGrantId(ctx context.Context, req *pb.FindAllEnabledNodeClustersWithGrantIdRequest) (*pb.FindAllEnabledNodeClustersWithGrantIdResponse, error) {
|
||||||
|
// 校验请求
|
||||||
|
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
clusters, err := models.SharedNodeClusterDAO.FindAllEnabledClustersWithGrantId(req.GrantId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := []*pb.NodeCluster{}
|
||||||
|
for _, cluster := range clusters {
|
||||||
|
result = append(result, &pb.NodeCluster{
|
||||||
|
Id: int64(cluster.Id),
|
||||||
|
Name: cluster.Name,
|
||||||
|
CreatedAt: int64(cluster.CreatedAt),
|
||||||
|
UniqueId: cluster.UniqueId,
|
||||||
|
Secret: cluster.Secret,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return &pb.FindAllEnabledNodeClustersWithGrantIdResponse{Clusters: result}, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ func (this *NodeMonitorTask) monitorCluster(cluster *models.NodeCluster) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO 检查恢复连接
|
||||||
|
|
||||||
// 检查CPU、内存、磁盘不足节点,而且离线的节点不再重复提示
|
// 检查CPU、内存、磁盘不足节点,而且离线的节点不再重复提示
|
||||||
// TODO 需要实现
|
// TODO 需要实现
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user