From 1691639812dff66d392c0d4864a04814ccd63e2a Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 29 Aug 2021 16:41:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=8A=82=E7=82=B9=E8=BD=AC?= =?UTF-8?q?=E7=A7=BB=E9=9B=86=E7=BE=A4=E5=90=8E=E6=B2=A1=E6=9C=89=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E8=80=81=E7=9A=84DNS=E8=AE=B0=E5=BD=95=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/db/models/node_dao.go | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/internal/db/models/node_dao.go b/internal/db/models/node_dao.go index 59debf99..9df9f8bc 100644 --- a/internal/db/models/node_dao.go +++ b/internal/db/models/node_dao.go @@ -167,6 +167,13 @@ func (this *NodeDAO) UpdateNode(tx *dbs.Tx, nodeId int64, name string, clusterId if nodeId <= 0 { return errors.New("invalid nodeId") } + + // 老的集群 + oldClusterIds, err := this.FindEnabledNodeClusterIds(tx, nodeId) + if err != nil { + return err + } + op := NewNodeOperator() op.Id = nodeId op.Name = name @@ -210,6 +217,16 @@ func (this *NodeDAO) UpdateNode(tx *dbs.Tx, nodeId int64, name string, clusterId return err } + // 通知老的集群更新 + for _, oldClusterId := range oldClusterIds { + if oldClusterId != clusterId && !lists.ContainsInt64(secondaryClusterIds, oldClusterId) { + err = dns.SharedDNSTaskDAO.CreateClusterTask(tx, oldClusterId, dns.DNSTaskTypeClusterChange) + if err != nil { + return err + } + } + } + return this.NotifyDNSUpdate(tx, nodeId) } @@ -385,6 +402,30 @@ func (this *NodeDAO) FindEnabledAndOnNodeClusterIds(tx *dbs.Tx, nodeId int64) (r return } +// FindEnabledNodeClusterIds 获取节点所属所有可用的集群ID +func (this *NodeDAO) FindEnabledNodeClusterIds(tx *dbs.Tx, nodeId int64) (result []int64, err error) { + one, err := this.Query(tx). + Pk(nodeId). + Result("clusterId", "secondaryClusterIds"). + Find() + if one == nil { + return nil, err + } + var clusterId = int64(one.(*Node).ClusterId) + if clusterId > 0 { + result = append(result, clusterId) + } + + for _, clusterId := range one.(*Node).DecodeSecondaryClusterIds() { + if lists.ContainsInt64(result, clusterId) { + continue + } + + result = append(result, clusterId) + } + return +} + // FindAllNodeIdsMatch 匹配节点并返回节点ID func (this *NodeDAO) FindAllNodeIdsMatch(tx *dbs.Tx, clusterId int64, includeSecondaryNodes bool, isOn configutils.BoolState) (result []int64, err error) { query := this.Query(tx)