集群增加自动同步时钟选项

This commit is contained in:
刘祥超
2022-09-15 15:56:50 +08:00
parent c8057457cc
commit 320d381bd9
5 changed files with 79 additions and 35 deletions

View File

@@ -187,7 +187,7 @@ func (this *NodeClusterDAO) CreateCluster(tx *dbs.Tx, adminId int64, name string
} }
// UpdateCluster 修改集群 // UpdateCluster 修改集群
func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name string, grantId int64, installDir string, timezone string, nodeMaxThreads int32, autoOpenPorts bool) 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) error {
if clusterId <= 0 { if clusterId <= 0 {
return errors.New("invalid clusterId") return errors.New("invalid clusterId")
} }
@@ -204,6 +204,14 @@ func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name stri
op.NodeMaxThreads = nodeMaxThreads op.NodeMaxThreads = nodeMaxThreads
op.AutoOpenPorts = autoOpenPorts op.AutoOpenPorts = autoOpenPorts
if clockConfig != nil {
clockJSON, err := json.Marshal(clockConfig)
if err != nil {
return err
}
op.Clock = clockJSON
}
err := this.Save(tx, op) err := this.Save(tx, op)
if err != nil { if err != nil {
return err return err
@@ -926,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"). Result("id", "timeZone", "nodeMaxThreads", "cachePolicyId", "httpFirewallPolicyId", "autoOpenPorts", "webp", "uam", "isOn", "ddosProtection", "clock").
Find() Find()
if err != nil || cluster == nil { if err != nil || cluster == nil {
return nil, err return nil, err

View File

@@ -30,45 +30,47 @@ type NodeCluster struct {
SystemServices dbs.JSON `field:"systemServices"` // 系统服务设置 SystemServices dbs.JSON `field:"systemServices"` // 系统服务设置
TimeZone string `field:"timeZone"` // 时区 TimeZone string `field:"timeZone"` // 时区
NodeMaxThreads uint32 `field:"nodeMaxThreads"` // 节点最大线程数 NodeMaxThreads uint32 `field:"nodeMaxThreads"` // 节点最大线程数
DdosProtection dbs.JSON `field:"ddosProtection"` // DDOS端口 DdosProtection dbs.JSON `field:"ddosProtection"` // DDoS防护设置
AutoOpenPorts uint8 `field:"autoOpenPorts"` // 是否自动尝试开放端口 AutoOpenPorts uint8 `field:"autoOpenPorts"` // 是否自动尝试开放端口
IsPinned bool `field:"isPinned"` // 是否置顶 IsPinned bool `field:"isPinned"` // 是否置顶
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"` // 时钟配置
} }
type NodeClusterOperator struct { type NodeClusterOperator struct {
Id interface{} // ID Id any // ID
AdminId interface{} // 管理员ID AdminId any // 管理员ID
UserId interface{} // 用户ID UserId any // 用户ID
IsOn interface{} // 是否启用 IsOn any // 是否启用
Name interface{} // 名称 Name any // 名称
UseAllAPINodes interface{} // 是否使用所有API节点 UseAllAPINodes any // 是否使用所有API节点
ApiNodes interface{} // 使用的API节点 ApiNodes any // 使用的API节点
InstallDir interface{} // 安装目录 InstallDir any // 安装目录
Order interface{} // 排序 Order any // 排序
CreatedAt interface{} // 创建时间 CreatedAt any // 创建时间
GrantId interface{} // 默认认证方式 GrantId any // 默认认证方式
State interface{} // 状态 State any // 状态
AutoRegister interface{} // 是否开启自动注册 AutoRegister any // 是否开启自动注册
UniqueId interface{} // 唯一ID UniqueId any // 唯一ID
Secret interface{} // 密钥 Secret any // 密钥
HealthCheck interface{} // 健康检查 HealthCheck any // 健康检查
DnsName interface{} // DNS名称 DnsName any // DNS名称
DnsDomainId interface{} // 域名ID DnsDomainId any // 域名ID
Dns interface{} // DNS配置 Dns any // DNS配置
Toa interface{} // TOA配置 Toa any // TOA配置
CachePolicyId interface{} // 缓存策略ID CachePolicyId any // 缓存策略ID
HttpFirewallPolicyId interface{} // WAF策略ID HttpFirewallPolicyId any // WAF策略ID
AccessLog interface{} // 访问日志设置 AccessLog any // 访问日志设置
SystemServices interface{} // 系统服务设置 SystemServices any // 系统服务设置
TimeZone interface{} // 时区 TimeZone any // 时区
NodeMaxThreads interface{} // 节点最大线程数 NodeMaxThreads any // 节点最大线程数
DdosProtection interface{} // DDOS端口 DdosProtection any // DDoS防护设置
AutoOpenPorts interface{} // 是否自动尝试开放端口 AutoOpenPorts any // 是否自动尝试开放端口
IsPinned interface{} // 是否置顶 IsPinned any // 是否置顶
Webp interface{} // WebP设置 Webp any // WebP设置
Uam interface{} // UAM设置 Uam any // UAM设置
Clock any // 时钟配置
} }
func NewNodeClusterOperator() *NodeClusterOperator { func NewNodeClusterOperator() *NodeClusterOperator {

View File

@@ -2,7 +2,9 @@ package models
import ( import (
"encoding/json" "encoding/json"
"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/serverconfigs/ddosconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
) )
@@ -50,3 +52,15 @@ func (this *NodeCluster) HasDDoSProtection() bool {
} }
return false return false
} }
// DecodeClock 解析时钟配置
func (this *NodeCluster) DecodeClock() *nodeconfigs.ClockConfig {
var clock = nodeconfigs.DefaultClockConfig()
if IsNotNull(this.Clock) {
err := json.Unmarshal(this.Clock, clock)
if err != nil {
remotelogs.Error("NodeCluster.DecodeClock()", err.Error())
}
}
return clock
}

View File

@@ -1085,6 +1085,11 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, cacheMap *utils
} }
} }
// 时钟
if config.Clock == nil {
config.Clock = nodeCluster.DecodeClock()
}
// 最大线程数、TCP连接数 // 最大线程数、TCP连接数
if clusterIndex == 0 { if clusterIndex == 0 {
config.MaxThreads = int(nodeCluster.NodeMaxThreads) config.MaxThreads = int(nodeCluster.NodeMaxThreads)

View File

@@ -89,7 +89,21 @@ func (this *NodeClusterService) UpdateNodeCluster(ctx context.Context, req *pb.U
var tx = this.NullTx() var tx = this.NullTx()
err = models.SharedNodeClusterDAO.UpdateCluster(tx, req.NodeClusterId, req.Name, req.NodeGrantId, req.InstallDir, req.TimeZone, req.NodeMaxThreads, req.AutoOpenPorts) // validate clock
var clockConfig = nodeconfigs.DefaultClockConfig()
if len(req.ClockJSON) > 0 {
err = json.Unmarshal(req.ClockJSON, clockConfig)
if err != nil {
return nil, errors.New("decode clock failed: " + err.Error())
}
err = clockConfig.Init()
if err != nil {
return nil, errors.New("validate clock failed: " + err.Error())
}
}
err = models.SharedNodeClusterDAO.UpdateCluster(tx, req.NodeClusterId, req.Name, req.NodeGrantId, req.InstallDir, req.TimeZone, req.NodeMaxThreads, req.AutoOpenPorts, clockConfig)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -169,6 +183,7 @@ func (this *NodeClusterService) FindEnabledNodeCluster(ctx context.Context, req
TimeZone: cluster.TimeZone, TimeZone: cluster.TimeZone,
NodeMaxThreads: int32(cluster.NodeMaxThreads), NodeMaxThreads: int32(cluster.NodeMaxThreads),
AutoOpenPorts: cluster.AutoOpenPorts == 1, AutoOpenPorts: cluster.AutoOpenPorts == 1,
ClockJSON: cluster.Clock,
}}, nil }}, nil
} }