mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-06 18:10:25 +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).
|
cluster, err := this.Query(tx).
|
||||||
Pk(clusterId).
|
Pk(clusterId).
|
||||||
State(NodeClusterStateEnabled).
|
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()
|
Find()
|
||||||
if err != nil || cluster == nil {
|
if err != nil || cluster == nil {
|
||||||
return nil, err
|
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)
|
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 通知更新
|
// NotifyUpdate 通知更新
|
||||||
func (this *NodeClusterDAO) NotifyUpdate(tx *dbs.Tx, clusterId int64) error {
|
func (this *NodeClusterDAO) NotifyUpdate(tx *dbs.Tx, clusterId int64) error {
|
||||||
return SharedNodeTaskDAO.CreateClusterTask(tx, nodeconfigs.NodeRoleNode, clusterId, 0, NodeTaskTypeConfigChanged)
|
return SharedNodeTaskDAO.CreateClusterTask(tx, nodeconfigs.NodeRoleNode, clusterId, 0, NodeTaskTypeConfigChanged)
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ type NodeCluster struct {
|
|||||||
Webp dbs.JSON `field:"webp"` // WebP设置
|
Webp dbs.JSON `field:"webp"` // WebP设置
|
||||||
Uam dbs.JSON `field:"uam"` // UAM设置
|
Uam dbs.JSON `field:"uam"` // UAM设置
|
||||||
Clock dbs.JSON `field:"clock"` // 时钟配置
|
Clock dbs.JSON `field:"clock"` // 时钟配置
|
||||||
|
GlobalServerConfig dbs.JSON `field:"globalServerConfig"` // 全局服务配置
|
||||||
}
|
}
|
||||||
|
|
||||||
type NodeClusterOperator struct {
|
type NodeClusterOperator struct {
|
||||||
@@ -71,6 +72,7 @@ type NodeClusterOperator struct {
|
|||||||
Webp any // WebP设置
|
Webp any // WebP设置
|
||||||
Uam any // UAM设置
|
Uam any // UAM设置
|
||||||
Clock any // 时钟配置
|
Clock any // 时钟配置
|
||||||
|
GlobalServerConfig any // 全局服务配置
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNodeClusterOperator() *NodeClusterOperator {
|
func NewNodeClusterOperator() *NodeClusterOperator {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -64,3 +65,15 @@ func (this *NodeCluster) DecodeClock() *nodeconfigs.ClockConfig {
|
|||||||
}
|
}
|
||||||
return clock
|
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()
|
config.Clock = nodeCluster.DecodeClock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 全局配置
|
||||||
|
if config.GlobalServerConfig == nil {
|
||||||
|
config.GlobalServerConfig = nodeCluster.DecodeGlobalServerConfig()
|
||||||
|
}
|
||||||
|
|
||||||
// 最大线程数、TCP连接数
|
// 最大线程数、TCP连接数
|
||||||
if clusterIndex == 0 {
|
if clusterIndex == 0 {
|
||||||
config.MaxThreads = int(nodeCluster.NodeMaxThreads)
|
config.MaxThreads = int(nodeCluster.NodeMaxThreads)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ type NodeTaskType = string
|
|||||||
const (
|
const (
|
||||||
NodeTaskTypeConfigChanged NodeTaskType = "configChanged" // 节点整体配置变化
|
NodeTaskTypeConfigChanged NodeTaskType = "configChanged" // 节点整体配置变化
|
||||||
NodeTaskTypeDDosProtectionChanged NodeTaskType = "ddosProtectionChanged" // 节点DDoS配置变更
|
NodeTaskTypeDDosProtectionChanged NodeTaskType = "ddosProtectionChanged" // 节点DDoS配置变更
|
||||||
|
NodeTaskTypeGlobalServerConfigChanged NodeTaskType = "globalServerConfigChanged" // 全局服务设置变化
|
||||||
NodeTaskTypeIPItemChanged NodeTaskType = "ipItemChanged"
|
NodeTaskTypeIPItemChanged NodeTaskType = "ipItemChanged"
|
||||||
NodeTaskTypeNodeVersionChanged NodeTaskType = "nodeVersionChanged"
|
NodeTaskTypeNodeVersionChanged NodeTaskType = "nodeVersionChanged"
|
||||||
NodeTaskTypeScriptsChanged NodeTaskType = "scriptsChanged"
|
NodeTaskTypeScriptsChanged NodeTaskType = "scriptsChanged"
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||||
"github.com/andybalholm/brotli"
|
"github.com/andybalholm/brotli"
|
||||||
@@ -1891,6 +1892,55 @@ func (this *NodeService) UpdateNodeDDoSProtection(ctx context.Context, req *pb.U
|
|||||||
return this.Success()
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindNodeGlobalServerConfig 取得节点的服务全局配置
|
||||||
|
func (this *NodeService) FindNodeGlobalServerConfig(ctx context.Context, req *pb.FindNodeGlobalServerConfigRequest) (*pb.FindNodeGlobalServerConfigResponse, error) {
|
||||||
|
var nodeId = req.NodeId
|
||||||
|
|
||||||
|
_, err := this.ValidateAdmin(ctx)
|
||||||
|
if err != nil {
|
||||||
|
// 检查是否来自节点
|
||||||
|
currentNodeId, err2 := this.ValidateNode(ctx)
|
||||||
|
if err2 != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if nodeId > 0 && currentNodeId != nodeId {
|
||||||
|
return nil, errors.New("invalid 'nodeId'")
|
||||||
|
}
|
||||||
|
|
||||||
|
nodeId = currentNodeId
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
|
||||||
|
clusterId, err := models.SharedNodeDAO.FindNodeClusterId(tx, nodeId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var config *serverconfigs.GlobalServerConfig
|
||||||
|
if clusterId > 0 {
|
||||||
|
config, err = models.SharedNodeClusterDAO.FindClusterGlobalServerConfig(tx, clusterId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if config == nil {
|
||||||
|
config = serverconfigs.DefaultGlobalServerConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
configJSON, err := json.Marshal(config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = &pb.FindNodeGlobalServerConfigResponse{
|
||||||
|
GlobalServerConfigJSON: configJSON,
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
// FindEnabledNodeConfigInfo 取得节点的配置概要信息
|
// FindEnabledNodeConfigInfo 取得节点的配置概要信息
|
||||||
func (this *NodeService) FindEnabledNodeConfigInfo(ctx context.Context, req *pb.FindEnabledNodeConfigInfoRequest) (*pb.FindEnabledNodeConfigInfoResponse, error) {
|
func (this *NodeService) FindEnabledNodeConfigInfo(ctx context.Context, req *pb.FindEnabledNodeConfigInfoRequest) (*pb.FindEnabledNodeConfigInfoResponse, error) {
|
||||||
_, err := this.ValidateAdmin(ctx)
|
_, err := this.ValidateAdmin(ctx)
|
||||||
|
|||||||
@@ -1253,3 +1253,53 @@ func (this *NodeClusterService) UpdateNodeClusterDDoSProtection(ctx context.Cont
|
|||||||
}
|
}
|
||||||
return this.Success()
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindNodeClusterGlobalServerConfig 获取集群的全局服务设置
|
||||||
|
func (this *NodeClusterService) FindNodeClusterGlobalServerConfig(ctx context.Context, req *pb.FindNodeClusterGlobalServerConfigRequest) (*pb.FindNodeClusterGlobalServerConfigResponse, error) {
|
||||||
|
_, err := this.ValidateAdmin(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
config, err := models.SharedNodeClusterDAO.FindClusterGlobalServerConfig(tx, req.NodeClusterId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
configJSON, err := json.Marshal(config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.FindNodeClusterGlobalServerConfigResponse{
|
||||||
|
GlobalServerConfigJSON: configJSON,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNodeClusterGlobalServerConfig 修改集群的全局服务设置
|
||||||
|
func (this *NodeClusterService) UpdateNodeClusterGlobalServerConfig(ctx context.Context, req *pb.UpdateNodeClusterGlobalServerConfigRequest) (*pb.RPCSuccess, error) {
|
||||||
|
_, err := this.ValidateAdmin(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var config = serverconfigs.DefaultGlobalServerConfig()
|
||||||
|
err = json.Unmarshal(req.GlobalServerConfigJSON, config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = config.Init()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("validate config failed: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
err = models.SharedNodeClusterDAO.UpdateClusterGlobalServerConfig(tx, req.NodeClusterId, config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.Success()
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -857,5 +857,47 @@ func upgradeV0_5_3(db *dbs.DB) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 升级集群服务配置
|
||||||
|
{
|
||||||
|
type oldGlobalConfig struct {
|
||||||
|
// HTTP & HTTPS相关配置
|
||||||
|
HTTPAll struct {
|
||||||
|
MatchDomainStrictly bool `yaml:"matchDomainStrictly" json:"matchDomainStrictly"` // 是否严格匹配域名
|
||||||
|
AllowMismatchDomains []string `yaml:"allowMismatchDomains" json:"allowMismatchDomains"` // 允许的不匹配的域名
|
||||||
|
DefaultDomain string `yaml:"defaultDomain" json:"defaultDomain"` // 默认的域名
|
||||||
|
DomainMismatchAction *serverconfigs.DomainMismatchAction `yaml:"domainMismatchAction" json:"domainMismatchAction"` // 不匹配时采取的动作
|
||||||
|
} `yaml:"httpAll" json:"httpAll"`
|
||||||
|
}
|
||||||
|
|
||||||
|
value, err := db.FindCol(0, "SELECT value FROM edgeSysSettings WHERE code='serverGlobalConfig'")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if value != nil {
|
||||||
|
var valueJSON = []byte(types.String(value))
|
||||||
|
var oldConfig = &oldGlobalConfig{}
|
||||||
|
err = json.Unmarshal(valueJSON, oldConfig)
|
||||||
|
if err == nil {
|
||||||
|
var newConfig = &serverconfigs.GlobalServerConfig{}
|
||||||
|
newConfig.HTTPAll.MatchDomainStrictly = oldConfig.HTTPAll.MatchDomainStrictly
|
||||||
|
newConfig.HTTPAll.AllowMismatchDomains = oldConfig.HTTPAll.AllowMismatchDomains
|
||||||
|
newConfig.HTTPAll.DefaultDomain = oldConfig.HTTPAll.DefaultDomain
|
||||||
|
if oldConfig.HTTPAll.DomainMismatchAction != nil {
|
||||||
|
newConfig.HTTPAll.DomainMismatchAction = oldConfig.HTTPAll.DomainMismatchAction
|
||||||
|
}
|
||||||
|
newConfig.HTTPAll.AllowNodeIP = true
|
||||||
|
|
||||||
|
newConfig.Log.RecordServerError = false
|
||||||
|
newConfigJSON, err := json.Marshal(newConfig)
|
||||||
|
if err == nil {
|
||||||
|
_, err = db.Exec("UPDATE edgeNodeClusters SET globalServerConfig=?", newConfigJSON)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user