From c5654846d3b8b002284dee57aa50e95d67649f0e Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期二, 24 十月 2023 18:59:31 +0800 Subject: [PATCH] 集群退出密码 --- system-service/controllers/cluster.go | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 41 insertions(+), 7 deletions(-) diff --git a/system-service/controllers/cluster.go b/system-service/controllers/cluster.go index eb8bddf..90c5ee3 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 } } @@ -74,9 +75,10 @@ return &bhomeclient.Reply{Success: true, Data: map[string]interface{}{ "clusterId": arr[0].ClusterId, "clusterName": arr[0].ClusterName, - "password": arr[0].Password, - "nodes": nodes, - "virtualIp": arr[0].VirtualIp, + //"password": arr[0].Password, + "nodes": nodes, + "virtualIp": arr[0].VirtualIp, + "localId": config.Server.AnalyServerId, }} } else { return &bhomeclient.Reply{Success: true} @@ -110,6 +112,22 @@ return &bhomeclient.Reply{Success: true, Data: clusterVo} } else { return &bhomeclient.Reply{Success: false, Msg: "鍒涘缓闆嗙兢澶辫触"} + } +} + +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: "鍙樻洿澶辫触"} } } @@ -233,7 +251,8 @@ } type LeaveArg struct { - IsDel bool `json:"isDel"` //鏄惁鍒犻櫎鏁版嵁 + IsDel bool `json:"isDel"` //鏄惁鍒犻櫎鏁版嵁 + Pwd string `json:"password"` //鏄惁鍒犻櫎鏁版嵁 } // @Summary 閫�鍑洪泦缇� @@ -246,6 +265,21 @@ func (cc ClusterController) Leave(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply { var reqBody LeaveArg c.BindJSON(&reqBody) + + var clusterE models.Cluster + arr, err := clusterE.FindAll() + if err != nil { + return &bhomeclient.Reply{Success: false, Msg: "闆嗙兢鏌ヨ澶辫触"} + } + + if arr != nil && len(arr) > 0 { + if config.ClusterSet.PwdPre+reqBody.Pwd != arr[0].Password { + return &bhomeclient.Reply{Success: false, Msg: "瀵嗙爜閿欒"} + } + } else { + return &bhomeclient.Reply{Success: false, Msg: "闆嗙兢鏌ヨ澶辫触"} + } + sv := service.NewClusterService(h.Bk) if b, err := sv.Leave(reqBody.IsDel); b { return &bhomeclient.Reply{Success: true, Msg: "閫�鍑烘垚鍔�"} -- Gitblit v1.8.0