mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 23:20:26 +08:00
集群健康检查可以同时检查单节点的多个IP
This commit is contained in:
@@ -162,17 +162,36 @@ func CheckClusterDNS(tx *dbs.Tx, cluster *models.NodeCluster, checkNodeIssues bo
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(ipAddr) == 0 {
|
if len(ipAddr) == 0 {
|
||||||
|
// 检查是否有离线
|
||||||
|
anyIPAddr, _, err := models.SharedNodeIPAddressDAO.FindFirstNodeAccessIPAddress(tx, nodeId, false, nodeconfigs.NodeRoleNode)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(anyIPAddr) > 0 {
|
||||||
issues = append(issues, &pb.DNSIssue{
|
issues = append(issues, &pb.DNSIssue{
|
||||||
Target: node.Name,
|
Target: node.Name,
|
||||||
TargetId: nodeId,
|
TargetId: nodeId,
|
||||||
Type: "node",
|
Type: "node",
|
||||||
Description: "没有设置IP地址",
|
Description: "节点所有IP地址处于离线状态",
|
||||||
Params: map[string]string{
|
Params: map[string]string{
|
||||||
"clusterName": cluster.Name,
|
"clusterName": cluster.Name,
|
||||||
"clusterId": numberutils.FormatInt64(clusterId),
|
"clusterId": numberutils.FormatInt64(clusterId),
|
||||||
},
|
},
|
||||||
MustFix: true,
|
MustFix: true,
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
issues = append(issues, &pb.DNSIssue{
|
||||||
|
Target: node.Name,
|
||||||
|
TargetId: nodeId,
|
||||||
|
Type: "node",
|
||||||
|
Description: "没有设置可用的IP地址",
|
||||||
|
Params: map[string]string{
|
||||||
|
"clusterName": cluster.Name,
|
||||||
|
"clusterId": numberutils.FormatInt64(clusterId),
|
||||||
|
},
|
||||||
|
MustFix: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -307,7 +307,7 @@ func (this *NodeIPAddressDAO) FindFirstNodeAccessIPAddressId(tx *dbs.Tx, nodeId
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindNodeAccessAndUpIPAddresses 查找节点所有的可访问的IP地址
|
// FindNodeAccessAndUpIPAddresses 查找节点所有的可访问且在线的IP地址
|
||||||
func (this *NodeIPAddressDAO) FindNodeAccessAndUpIPAddresses(tx *dbs.Tx, nodeId int64, role nodeconfigs.NodeRole) (result []*NodeIPAddress, err error) {
|
func (this *NodeIPAddressDAO) FindNodeAccessAndUpIPAddresses(tx *dbs.Tx, nodeId int64, role nodeconfigs.NodeRole) (result []*NodeIPAddress, err error) {
|
||||||
if len(role) == 0 {
|
if len(role) == 0 {
|
||||||
role = nodeconfigs.NodeRoleNode
|
role = nodeconfigs.NodeRoleNode
|
||||||
@@ -326,6 +326,24 @@ func (this *NodeIPAddressDAO) FindNodeAccessAndUpIPAddresses(tx *dbs.Tx, nodeId
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindNodeAccessIPAddresses 查找节点所有的可访问的IP地址,包括在线和离线
|
||||||
|
func (this *NodeIPAddressDAO) FindNodeAccessIPAddresses(tx *dbs.Tx, nodeId int64, role nodeconfigs.NodeRole) (result []*NodeIPAddress, err error) {
|
||||||
|
if len(role) == 0 {
|
||||||
|
role = nodeconfigs.NodeRoleNode
|
||||||
|
}
|
||||||
|
_, err = this.Query(tx).
|
||||||
|
Attr("role", role).
|
||||||
|
Attr("nodeId", nodeId).
|
||||||
|
State(NodeIPAddressStateEnabled).
|
||||||
|
Attr("canAccess", true).
|
||||||
|
Attr("isOn", true).
|
||||||
|
Desc("order").
|
||||||
|
AscPk().
|
||||||
|
Slice(&result).
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// CountAllEnabledIPAddresses 计算IP地址数量
|
// CountAllEnabledIPAddresses 计算IP地址数量
|
||||||
// TODO 目前支持边缘节点,将来支持NS节点
|
// TODO 目前支持边缘节点,将来支持NS节点
|
||||||
func (this *NodeIPAddressDAO) CountAllEnabledIPAddresses(tx *dbs.Tx, role string, nodeClusterId int64, upState configutils.BoolState, keyword string) (int64, error) {
|
func (this *NodeIPAddressDAO) CountAllEnabledIPAddresses(tx *dbs.Tx, role string, nodeClusterId int64, upState configutils.BoolState, keyword string) (int64, error) {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeutils"
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
"github.com/iwind/TeaGo/lists"
|
"github.com/iwind/TeaGo/lists"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
@@ -63,27 +64,32 @@ func (this *HealthCheckExecutor) Run() ([]*HealthCheckResult, error) {
|
|||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var tx *dbs.Tx
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
if !node.IsOn {
|
if !node.IsOn {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
result := &HealthCheckResult{
|
|
||||||
Node: node,
|
|
||||||
}
|
|
||||||
|
|
||||||
ipAddr, ipAddrId, err := models.NewNodeIPAddressDAO().FindFirstNodeAccessIPAddress(nil, int64(node.Id), false, nodeconfigs.NodeRoleNode)
|
ipAddrs, err := models.SharedNodeIPAddressDAO.FindNodeAccessIPAddresses(tx, int64(node.Id), nodeconfigs.NodeRoleNode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(ipAddr) == 0 {
|
for _, ipAddr := range ipAddrs {
|
||||||
result.Error = "no ip address can be used"
|
var ipClusterIds = ipAddr.DecodeClusterIds()
|
||||||
} else {
|
if len(ipClusterIds) > 0 && !lists.ContainsInt64(ipClusterIds, this.clusterId) {
|
||||||
result.NodeAddr = ipAddr
|
continue
|
||||||
result.NodeAddrId = ipAddrId
|
}
|
||||||
|
|
||||||
|
// TODO 支持备用IP
|
||||||
|
var result = &HealthCheckResult{
|
||||||
|
Node: node,
|
||||||
|
NodeAddrId: int64(ipAddr.Id),
|
||||||
|
NodeAddr: ipAddr.Ip,
|
||||||
}
|
}
|
||||||
|
|
||||||
results = append(results, result)
|
results = append(results, result)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 并行检查
|
// 并行检查
|
||||||
var preparedResults = []*HealthCheckResult{}
|
var preparedResults = []*HealthCheckResult{}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ func TestHealthCheckExecutor_Run(t *testing.T) {
|
|||||||
teaconst.IsPlus = true
|
teaconst.IsPlus = true
|
||||||
dbs.NotifyReady()
|
dbs.NotifyReady()
|
||||||
|
|
||||||
executor := tasks.NewHealthCheckExecutor(35)
|
var executor = tasks.NewHealthCheckExecutor(42)
|
||||||
results, err := executor.Run()
|
results, err := executor.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ package tasks
|
|||||||
|
|
||||||
import "github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
import "github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||||
|
|
||||||
|
// HealthCheckResult 健康检查结果
|
||||||
type HealthCheckResult struct {
|
type HealthCheckResult struct {
|
||||||
Node *models.Node
|
Node *models.Node
|
||||||
NodeAddr string
|
NodeAddr string // 节点IP地址
|
||||||
NodeAddrId int64
|
NodeAddrId int64 // 节点IP地址ID
|
||||||
IsOk bool
|
IsOk bool
|
||||||
Error string
|
Error string
|
||||||
CostMs float64
|
CostMs float64
|
||||||
|
|||||||
Reference in New Issue
Block a user