From 71b8885babe6dfd25c91b007018347c0c1bfac74 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期五, 20 十月 2023 17:35:52 +0800
Subject: [PATCH] 添加主节点变更和主动切换功能

---
 system-service/controllers/cluster.go |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/system-service/controllers/cluster.go b/system-service/controllers/cluster.go
index eb8bddf..39b980f 100644
--- a/system-service/controllers/cluster.go
+++ b/system-service/controllers/cluster.go
@@ -25,7 +25,7 @@
 	var clusterE models.Cluster
 	var reply = bhomeclient.Reply{
 		Success: false,
-		Msg:     "leave",
+		Msg:     "",
 		Data:    nil,
 	}
 
@@ -37,9 +37,9 @@
 
 			var nodeE models.Node
 			nodes, _ := nodeE.FindNodesByClusterId(arr[0].ClusterId)
-			logger.Debug("鏌ヨ闆嗙兢鑺傜偣:", nodes)
+			//logger.Debug("鏌ヨ闆嗙兢鑺傜偣:", nodes)
 			for _, node := range nodes {
-				logger.Debug("鑺傜偣:", node.NodeId, " servceId:", config.Server.AnalyServerId, " stat:", node.DriftState)
+				//logger.Debug("鑺傜偣:", node.NodeId, " serverId:", config.Server.AnalyServerId, " stat:", node.DriftState)
 				if node.NodeId == config.Server.AnalyServerId {
 					if node.DriftState == "master" {
 						reply.Msg = "master"
@@ -50,6 +50,7 @@
 					break
 				}
 			}
+			reply.Data = nodes
 		}
 	}
 
@@ -77,6 +78,7 @@
 				"password":    arr[0].Password,
 				"nodes":       nodes,
 				"virtualIp":   arr[0].VirtualIp,
+				"localId":     config.Server.AnalyServerId,
 			}}
 		} else {
 			return &bhomeclient.Reply{Success: true}
@@ -113,6 +115,22 @@
 	}
 }
 
+func (cc ClusterController) Update2Master(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
+	var nodeVo vo.UpdateClusterVo
+	err := c.BindJSON(&nodeVo)
+	if err != nil || nodeVo.NodeId == "" {
+		return &bhomeclient.Reply{Success: false, Msg: "鍙傛暟鏈夎"}
+	}
+
+	sv := service.NewClusterService(h.Bk)
+	b, _ := sv.UpdateDriftStateByNodeId(nodeVo.ClusterId, nodeVo.NodeId, "master")
+	if b {
+		return &bhomeclient.Reply{Success: true, Data: nil}
+	} else {
+		return &bhomeclient.Reply{Success: false, Msg: "鍙樻洿澶辫触"}
+	}
+}
+
 // @Summary 鎼滅储闆嗙兢
 // @Description 鎼滅储闆嗙兢
 // @Accept json

--
Gitblit v1.8.0