mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2026-01-04 14:27:05 +08:00
集群设置中增加服务设置
This commit is contained in:
@@ -934,7 +934,7 @@ func (this *NodeClusterDAO) FindClusterBasicInfo(tx *dbs.Tx, clusterId int64, ca
|
||||
cluster, err := this.Query(tx).
|
||||
Pk(clusterId).
|
||||
State(NodeClusterStateEnabled).
|
||||
Result("id", "timeZone", "nodeMaxThreads", "cachePolicyId", "httpFirewallPolicyId", "autoOpenPorts", "webp", "uam", "isOn", "ddosProtection", "clock").
|
||||
Result("id", "timeZone", "nodeMaxThreads", "cachePolicyId", "httpFirewallPolicyId", "autoOpenPorts", "webp", "uam", "isOn", "ddosProtection", "clock", "globalServerConfig").
|
||||
Find()
|
||||
if err != nil || cluster == nil {
|
||||
return nil, err
|
||||
@@ -1102,6 +1102,49 @@ func (this *NodeClusterDAO) UpdateClusterDDoSProtection(tx *dbs.Tx, clusterId in
|
||||
return SharedNodeTaskDAO.CreateClusterTask(tx, nodeconfigs.NodeRoleNode, clusterId, 0, NodeTaskTypeDDosProtectionChanged)
|
||||
}
|
||||
|
||||
// FindClusterGlobalServerConfig 查询全局服务配置
|
||||
func (this *NodeClusterDAO) FindClusterGlobalServerConfig(tx *dbs.Tx, clusterId int64) (*serverconfigs.GlobalServerConfig, error) {
|
||||
configJSON, err := this.Query(tx).
|
||||
Pk(clusterId).
|
||||
Result("globalServerConfig").
|
||||
FindJSONCol()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var config = serverconfigs.DefaultGlobalServerConfig()
|
||||
if IsNull(configJSON) {
|
||||
return config, nil
|
||||
}
|
||||
|
||||
err = json.Unmarshal(configJSON, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// UpdateClusterGlobalServerConfig 修改全局服务配置
|
||||
func (this *NodeClusterDAO) UpdateClusterGlobalServerConfig(tx *dbs.Tx, clusterId int64, config *serverconfigs.GlobalServerConfig) error {
|
||||
if config == nil {
|
||||
config = serverconfigs.DefaultGlobalServerConfig()
|
||||
}
|
||||
configJSON, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = this.Query(tx).
|
||||
Pk(clusterId).
|
||||
Set("globalServerConfig", configJSON).
|
||||
UpdateQuickly()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return SharedNodeTaskDAO.CreateClusterTask(tx, nodeconfigs.NodeRoleNode, clusterId, 0, NodeTaskTypeGlobalServerConfigChanged)
|
||||
}
|
||||
|
||||
// NotifyUpdate 通知更新
|
||||
func (this *NodeClusterDAO) NotifyUpdate(tx *dbs.Tx, clusterId int64) error {
|
||||
return SharedNodeTaskDAO.CreateClusterTask(tx, nodeconfigs.NodeRoleNode, clusterId, 0, NodeTaskTypeConfigChanged)
|
||||
|
||||
@@ -36,6 +36,7 @@ type NodeCluster struct {
|
||||
Webp dbs.JSON `field:"webp"` // WebP设置
|
||||
Uam dbs.JSON `field:"uam"` // UAM设置
|
||||
Clock dbs.JSON `field:"clock"` // 时钟配置
|
||||
GlobalServerConfig dbs.JSON `field:"globalServerConfig"` // 全局服务配置
|
||||
}
|
||||
|
||||
type NodeClusterOperator struct {
|
||||
@@ -71,6 +72,7 @@ type NodeClusterOperator struct {
|
||||
Webp any // WebP设置
|
||||
Uam any // UAM设置
|
||||
Clock any // 时钟配置
|
||||
GlobalServerConfig any // 全局服务配置
|
||||
}
|
||||
|
||||
func NewNodeClusterOperator() *NodeClusterOperator {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
|
||||
)
|
||||
|
||||
@@ -64,3 +65,15 @@ func (this *NodeCluster) DecodeClock() *nodeconfigs.ClockConfig {
|
||||
}
|
||||
return clock
|
||||
}
|
||||
|
||||
// DecodeGlobalServerConfig 解析全局服务配置
|
||||
func (this *NodeCluster) DecodeGlobalServerConfig() *serverconfigs.GlobalServerConfig {
|
||||
var config = serverconfigs.DefaultGlobalServerConfig()
|
||||
if IsNotNull(this.GlobalServerConfig) {
|
||||
err := json.Unmarshal(this.GlobalServerConfig, config)
|
||||
if err != nil {
|
||||
remotelogs.Error("NodeCluster.DecodeGlobalServerConfig()", err.Error())
|
||||
}
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
@@ -1090,6 +1090,11 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, cacheMap *utils
|
||||
config.Clock = nodeCluster.DecodeClock()
|
||||
}
|
||||
|
||||
// 全局配置
|
||||
if config.GlobalServerConfig == nil {
|
||||
config.GlobalServerConfig = nodeCluster.DecodeGlobalServerConfig()
|
||||
}
|
||||
|
||||
// 最大线程数、TCP连接数
|
||||
if clusterIndex == 0 {
|
||||
config.MaxThreads = int(nodeCluster.NodeMaxThreads)
|
||||
|
||||
@@ -14,12 +14,13 @@ import (
|
||||
type NodeTaskType = string
|
||||
|
||||
const (
|
||||
NodeTaskTypeConfigChanged NodeTaskType = "configChanged" // 节点整体配置变化
|
||||
NodeTaskTypeDDosProtectionChanged NodeTaskType = "ddosProtectionChanged" // 节点DDoS配置变更
|
||||
NodeTaskTypeIPItemChanged NodeTaskType = "ipItemChanged"
|
||||
NodeTaskTypeNodeVersionChanged NodeTaskType = "nodeVersionChanged"
|
||||
NodeTaskTypeScriptsChanged NodeTaskType = "scriptsChanged"
|
||||
NodeTaskTypeNodeLevelChanged NodeTaskType = "nodeLevelChanged"
|
||||
NodeTaskTypeConfigChanged NodeTaskType = "configChanged" // 节点整体配置变化
|
||||
NodeTaskTypeDDosProtectionChanged NodeTaskType = "ddosProtectionChanged" // 节点DDoS配置变更
|
||||
NodeTaskTypeGlobalServerConfigChanged NodeTaskType = "globalServerConfigChanged" // 全局服务设置变化
|
||||
NodeTaskTypeIPItemChanged NodeTaskType = "ipItemChanged"
|
||||
NodeTaskTypeNodeVersionChanged NodeTaskType = "nodeVersionChanged"
|
||||
NodeTaskTypeScriptsChanged NodeTaskType = "scriptsChanged"
|
||||
NodeTaskTypeNodeLevelChanged NodeTaskType = "nodeLevelChanged"
|
||||
|
||||
// NS相关
|
||||
|
||||
|
||||
Reference in New Issue
Block a user