可以在集群中指定节点时区

This commit is contained in:
GoEdgeLab
2021-10-12 11:44:24 +08:00
parent 3321b548bc
commit bc6aa9f64e
4 changed files with 42 additions and 4 deletions

View File

@@ -177,7 +177,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) error { func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name string, grantId int64, installDir string, timezone string) error {
if clusterId <= 0 { if clusterId <= 0 {
return errors.New("invalid clusterId") return errors.New("invalid clusterId")
} }
@@ -186,9 +186,13 @@ func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name stri
op.Name = name op.Name = name
op.GrantId = grantId op.GrantId = grantId
op.InstallDir = installDir op.InstallDir = installDir
op.TimeZone = timezone
err := this.Save(tx, op) err := this.Save(tx, op)
if err != nil {
return err return err
} }
return this.NotifyUpdate(tx, clusterId)
}
// CountAllEnabledClusters 计算所有集群数量 // CountAllEnabledClusters 计算所有集群数量
func (this *NodeClusterDAO) CountAllEnabledClusters(tx *dbs.Tx, keyword string) (int64, error) { func (this *NodeClusterDAO) CountAllEnabledClusters(tx *dbs.Tx, keyword string) (int64, error) {
@@ -407,7 +411,7 @@ func (this *NodeClusterDAO) FindClusterDNSInfo(tx *dbs.Tx, clusterId int64, cach
if cacheMap == nil { if cacheMap == nil {
cacheMap = maps.Map{} cacheMap = maps.Map{}
} }
var cacheKey = this.Table + ":record:" + types.String(clusterId) var cacheKey = this.Table + ":FindClusterDNSInfo:" + types.String(clusterId)
var cache = cacheMap.Get(cacheKey) var cache = cacheMap.Get(cacheKey)
if cache != nil { if cache != nil {
return cache.(*NodeCluster), nil return cache.(*NodeCluster), nil
@@ -811,6 +815,28 @@ func (this *NodeClusterDAO) ExistsEnabledCluster(tx *dbs.Tx, clusterId int64) (b
Exist() Exist()
} }
// FindClusterTimezone 查找时区
func (this *NodeClusterDAO) FindClusterTimezone(tx *dbs.Tx, clusterId int64, cacheMap maps.Map) (string, error) {
if cacheMap == nil {
cacheMap = maps.Map{}
}
var cacheKey = this.Table + ":FindEnabledTimeZone:" + types.String(clusterId)
var cache = cacheMap.Get(cacheKey)
if cache != nil {
return cache.(string), nil
}
timeZone, err := this.Query(tx).
Pk(clusterId).
Result("timeZone").
FindStringCol("")
if err != nil {
return "", err
}
cacheMap[cacheKey] = timeZone
return timeZone, nil
}
// 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, NodeTaskTypeConfigChanged) return SharedNodeTaskDAO.CreateClusterTask(tx, nodeconfigs.NodeRoleNode, clusterId, NodeTaskTypeConfigChanged)

View File

@@ -26,6 +26,7 @@ type NodeCluster struct {
HttpFirewallPolicyId uint32 `field:"httpFirewallPolicyId"` // WAF策略ID HttpFirewallPolicyId uint32 `field:"httpFirewallPolicyId"` // WAF策略ID
AccessLog string `field:"accessLog"` // 访问日志设置 AccessLog string `field:"accessLog"` // 访问日志设置
SystemServices string `field:"systemServices"` // 系统服务设置 SystemServices string `field:"systemServices"` // 系统服务设置
TimeZone string `field:"timeZone"` // 时区
} }
type NodeClusterOperator struct { type NodeClusterOperator struct {
@@ -53,6 +54,7 @@ type NodeClusterOperator struct {
HttpFirewallPolicyId interface{} // WAF策略ID HttpFirewallPolicyId interface{} // WAF策略ID
AccessLog interface{} // 访问日志设置 AccessLog interface{} // 访问日志设置
SystemServices interface{} // 系统服务设置 SystemServices interface{} // 系统服务设置
TimeZone interface{} // 时区
} }
func NewNodeClusterOperator() *NodeClusterOperator { func NewNodeClusterOperator() *NodeClusterOperator {

View File

@@ -770,6 +770,15 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, cacheMap maps.M
config.HTTPCachePolicies = append(config.HTTPCachePolicies, cachePolicy) config.HTTPCachePolicies = append(config.HTTPCachePolicies, cachePolicy)
} }
} }
// 时区
timeZone, err := SharedNodeClusterDAO.FindClusterTimezone(tx, clusterId, cacheMap)
if err != nil {
return nil, err
}
if len(timeZone) > 0 {
config.TimeZone = timeZone
}
} }
// 缓存最大容量设置 // 缓存最大容量设置

View File

@@ -83,7 +83,7 @@ func (this *NodeClusterService) UpdateNodeCluster(ctx context.Context, req *pb.U
tx := this.NullTx() tx := this.NullTx()
err = models.SharedNodeClusterDAO.UpdateCluster(tx, req.NodeClusterId, req.Name, req.NodeGrantId, req.InstallDir) err = models.SharedNodeClusterDAO.UpdateCluster(tx, req.NodeClusterId, req.Name, req.NodeGrantId, req.InstallDir, req.TimeZone)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -160,6 +160,7 @@ func (this *NodeClusterService) FindEnabledNodeCluster(ctx context.Context, req
DnsName: cluster.DnsName, DnsName: cluster.DnsName,
DnsDomainId: int64(cluster.DnsDomainId), DnsDomainId: int64(cluster.DnsDomainId),
IsOn: cluster.IsOn == 1, IsOn: cluster.IsOn == 1,
TimeZone: cluster.TimeZone,
}}, nil }}, nil
} }