mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-04 07:50:25 +08:00
提供手动控制节点上下线的接口
This commit is contained in:
@@ -828,7 +828,7 @@ func (this *NodeDAO) UpdateNodeDNS(tx *dbs.Tx, nodeId int64, routes map[int64][]
|
||||
}
|
||||
|
||||
// 计算节点上线|下线状态
|
||||
func (this *NodeDAO) UpdateNodeUp(tx *dbs.Tx, nodeId int64, isUp bool, maxUp int, maxDown int) (changed bool, err error) {
|
||||
func (this *NodeDAO) UpdateNodeUpCount(tx *dbs.Tx, nodeId int64, isUp bool, maxUp int, maxDown int) (changed bool, err error) {
|
||||
if nodeId <= 0 {
|
||||
return false, errors.New("invalid nodeId")
|
||||
}
|
||||
@@ -888,6 +888,23 @@ func (this *NodeDAO) UpdateNodeUp(tx *dbs.Tx, nodeId int64, isUp bool, maxUp int
|
||||
return
|
||||
}
|
||||
|
||||
// 设置节点上下线状态
|
||||
func (this *NodeDAO) UpdateNodeUp(tx *dbs.Tx, nodeId int64, isUp bool) error {
|
||||
if nodeId <= 0 {
|
||||
return errors.New("invalid nodeId")
|
||||
}
|
||||
op := NewNodeOperator()
|
||||
op.Id = nodeId
|
||||
op.IsUp = isUp
|
||||
op.CountDown = 0
|
||||
op.CountDown = 0
|
||||
err := this.Save(tx, op)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return this.NotifyDNSUpdate(tx, nodeId)
|
||||
}
|
||||
|
||||
// 修改节点活跃状态
|
||||
func (this *NodeDAO) UpdateNodeActive(tx *dbs.Tx, nodeId int64, isActive bool) error {
|
||||
if nodeId <= 0 {
|
||||
|
||||
@@ -1271,6 +1271,11 @@ func (this *NodeService) FindEnabledNodesWithIds(ctx context.Context, req *pb.Fi
|
||||
|
||||
// 检查新版本
|
||||
func (this *NodeService) CheckNodeLatestVersion(ctx context.Context, req *pb.CheckNodeLatestVersionRequest) (*pb.CheckNodeLatestVersionResponse, error) {
|
||||
_, err := this.ValidateAdmin(ctx, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
deployFiles := installers.SharedDeployManager.LoadFiles()
|
||||
for _, file := range deployFiles {
|
||||
if file.OS == req.Os && file.Arch == req.Arch && stringutil.VersionCompare(file.Version, req.CurrentVersion) > 0 {
|
||||
@@ -1282,3 +1287,19 @@ func (this *NodeService) CheckNodeLatestVersion(ctx context.Context, req *pb.Che
|
||||
}
|
||||
return &pb.CheckNodeLatestVersionResponse{HasNewVersion: false}, nil
|
||||
}
|
||||
|
||||
// 设置节点上线状态
|
||||
func (this *NodeService) UpdateNodeUp(ctx context.Context, req *pb.UpdateNodeUpRequest) (*pb.RPCSuccess, error) {
|
||||
_, err := this.ValidateAdmin(ctx, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
err = models.SharedNodeDAO.UpdateNodeUp(tx, req.NodeId, req.IsUp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
@@ -94,6 +94,7 @@ func (this *DNSTaskExecutor) Loop() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 修改服务相关记录
|
||||
func (this *DNSTaskExecutor) doServer(taskId int64, serverId int64) error {
|
||||
var tx *dbs.Tx
|
||||
|
||||
@@ -208,6 +209,7 @@ func (this *DNSTaskExecutor) doServer(taskId int64, serverId int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 修改节点相关记录
|
||||
func (this *DNSTaskExecutor) doNode(taskId int64, nodeId int64) error {
|
||||
isOk := false
|
||||
defer func() {
|
||||
@@ -245,6 +247,7 @@ func (this *DNSTaskExecutor) doNode(taskId int64, nodeId int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 修改集群相关记录
|
||||
func (this *DNSTaskExecutor) doCluster(taskId int64, clusterId int64) error {
|
||||
isOk := false
|
||||
defer func() {
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/dns"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
@@ -131,16 +130,10 @@ func (this *HealthCheckExecutor) Run() ([]*HealthCheckResult, error) {
|
||||
|
||||
// 修改节点状态
|
||||
if healthCheckConfig.AutoDown {
|
||||
isChanged, err := models.SharedNodeDAO.UpdateNodeUp(nil, int64(result.Node.Id), result.IsOk, healthCheckConfig.CountUp, healthCheckConfig.CountDown)
|
||||
isChanged, err := models.SharedNodeDAO.UpdateNodeUpCount(nil, int64(result.Node.Id), result.IsOk, healthCheckConfig.CountUp, healthCheckConfig.CountDown)
|
||||
if err != nil {
|
||||
logs.Println("[HEALTH_CHECK]" + err.Error())
|
||||
} else if isChanged {
|
||||
// 通知DNS更新
|
||||
err = dns.SharedDNSTaskDAO.CreateNodeTask(nil, int64(result.Node.Id), dns.DNSTaskTypeNodeChange)
|
||||
if err != nil {
|
||||
logs.Println("[HEALTH_CHECK]" + err.Error())
|
||||
}
|
||||
|
||||
// 通知恢复或下线
|
||||
if result.IsOk {
|
||||
err = models.NewMessageDAO().CreateNodeMessage(nil, this.clusterId, int64(result.Node.Id), models.MessageTypeHealthCheckNodeUp, models.MessageLevelSuccess, "健康检查成功,节点\""+result.Node.Name+"\"已恢复上线", nil)
|
||||
|
||||
Reference in New Issue
Block a user