mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-08 03:00:26 +08:00
集群增加是否远程启动选项
This commit is contained in:
@@ -9,3 +9,7 @@ dbs:
|
||||
prefix: "edge"
|
||||
models:
|
||||
package: internal/web/models
|
||||
|
||||
|
||||
fields:
|
||||
bool: [ "uamIsOn", "followPort", "requestHostExcludingPort", "autoRemoteStart" ]
|
||||
|
||||
@@ -197,7 +197,7 @@ func (this *NodeClusterDAO) CreateCluster(tx *dbs.Tx, adminId int64, name string
|
||||
}
|
||||
|
||||
// UpdateCluster 修改集群
|
||||
func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name string, grantId int64, installDir string, timezone string, nodeMaxThreads int32, autoOpenPorts bool, clockConfig *nodeconfigs.ClockConfig) error {
|
||||
func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name string, grantId int64, installDir string, timezone string, nodeMaxThreads int32, autoOpenPorts bool, clockConfig *nodeconfigs.ClockConfig, autoRemoteStart bool) error {
|
||||
if clusterId <= 0 {
|
||||
return errors.New("invalid clusterId")
|
||||
}
|
||||
@@ -222,6 +222,8 @@ func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name stri
|
||||
op.Clock = clockJSON
|
||||
}
|
||||
|
||||
op.AutoRemoteStart = autoRemoteStart
|
||||
|
||||
err := this.Save(tx, op)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -37,6 +37,7 @@ type NodeCluster struct {
|
||||
Uam dbs.JSON `field:"uam"` // UAM设置
|
||||
Clock dbs.JSON `field:"clock"` // 时钟配置
|
||||
GlobalServerConfig dbs.JSON `field:"globalServerConfig"` // 全局服务配置
|
||||
AutoRemoteStart bool `field:"autoRemoteStart"` // 自动远程启动
|
||||
}
|
||||
|
||||
type NodeClusterOperator struct {
|
||||
@@ -73,6 +74,7 @@ type NodeClusterOperator struct {
|
||||
Uam any // UAM设置
|
||||
Clock any // 时钟配置
|
||||
GlobalServerConfig any // 全局服务配置
|
||||
AutoRemoteStart any // 自动远程启动
|
||||
}
|
||||
|
||||
func NewNodeClusterOperator() *NodeClusterOperator {
|
||||
|
||||
@@ -17,6 +17,7 @@ type NSCluster struct {
|
||||
Udp dbs.JSON `field:"udp"` // UDP设置
|
||||
DdosProtection dbs.JSON `field:"ddosProtection"` // DDoS防护设置
|
||||
Hosts dbs.JSON `field:"hosts"` // DNS主机地址
|
||||
AutoRemoteStart bool `field:"autoRemoteStart"` // 自动远程启动
|
||||
}
|
||||
|
||||
type NSClusterOperator struct {
|
||||
@@ -33,6 +34,7 @@ type NSClusterOperator struct {
|
||||
Udp any // UDP设置
|
||||
DdosProtection any // DDoS防护设置
|
||||
Hosts any // DNS主机地址
|
||||
AutoRemoteStart any // 自动远程启动
|
||||
}
|
||||
|
||||
func NewNSClusterOperator() *NSClusterOperator {
|
||||
|
||||
@@ -116,7 +116,7 @@ func (this *NodeClusterService) UpdateNodeCluster(ctx context.Context, req *pb.U
|
||||
}
|
||||
}
|
||||
|
||||
err = models.SharedNodeClusterDAO.UpdateCluster(tx, req.NodeClusterId, req.Name, req.NodeGrantId, req.InstallDir, req.TimeZone, req.NodeMaxThreads, req.AutoOpenPorts, clockConfig)
|
||||
err = models.SharedNodeClusterDAO.UpdateCluster(tx, req.NodeClusterId, req.Name, req.NodeGrantId, req.InstallDir, req.TimeZone, req.NodeMaxThreads, req.AutoOpenPorts, clockConfig, req.AutoRemoteStart)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -167,6 +167,9 @@ func (this *NodeClusterService) FindEnabledNodeCluster(ctx context.Context, req
|
||||
|
||||
if userId > 0 {
|
||||
// TODO 检查用户是否有权限
|
||||
|
||||
// 禁止通过REST访问
|
||||
// TODO
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
@@ -197,6 +200,7 @@ func (this *NodeClusterService) FindEnabledNodeCluster(ctx context.Context, req
|
||||
NodeMaxThreads: int32(cluster.NodeMaxThreads),
|
||||
AutoOpenPorts: cluster.AutoOpenPorts == 1,
|
||||
ClockJSON: cluster.Clock,
|
||||
AutoRemoteStart: cluster.AutoRemoteStart,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,14 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func IsRest(ctx context.Context) bool {
|
||||
if ctx == nil {
|
||||
return false
|
||||
}
|
||||
_, ok := ctx.(*PlainContext)
|
||||
return ok
|
||||
}
|
||||
|
||||
type PlainContext struct {
|
||||
UserType string
|
||||
UserId int64
|
||||
|
||||
@@ -85,6 +85,7 @@ func (this *NodeMonitorTask) MonitorCluster(cluster *models.NodeCluster) error {
|
||||
}
|
||||
|
||||
// 尝试自动远程启动
|
||||
if cluster.AutoRemoteStart {
|
||||
var nodeQueue = installers.NewNodeQueue()
|
||||
for _, node := range inactiveNodes {
|
||||
var nodeId = int64(node.Id)
|
||||
@@ -116,6 +117,7 @@ func (this *NodeMonitorTask) MonitorCluster(cluster *models.NodeCluster) error {
|
||||
_ = models.SharedNodeLogDAO.CreateLog(nil, nodeconfigs.NodeRoleNode, nodeId, 0, 0, models.LevelSuccess, "NODE", "start node from remote API successfully", time.Now().Unix(), "", nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var nodeMap = map[int64]*models.Node{} // nodeId => Node
|
||||
for _, node := range inactiveNodes {
|
||||
|
||||
Reference in New Issue
Block a user