From c9d1acd4b7c0993b9a665e22489949ac227a2717 Mon Sep 17 00:00:00 2001 From: sunty <1172534965@qq.com> Date: 星期一, 13 四月 2020 17:04:49 +0800 Subject: [PATCH] add volume to master server --- controllers/swfsControllers.go | 25 ++++++++++++++++++------- 1 files changed, 18 insertions(+), 7 deletions(-) diff --git a/controllers/swfsControllers.go b/controllers/swfsControllers.go index 3e770e3..95d1a8c 100644 --- a/controllers/swfsControllers.go +++ b/controllers/swfsControllers.go @@ -30,7 +30,6 @@ oldPeers := GetOldPeers(config.Server.ScriptPath, StartServerScript) newPeers := GetNewPeers() UpdatePeers(config.Server.ScriptPath, StartServerScript, oldPeers, newPeers) - ReplaceLineContentBySearch(StartScriptAsVolume, config.Server.ScriptPath, StartServerScript) } // @Security ApiKeyAuth @@ -48,14 +47,18 @@ c.BindJSON(&body) role := body.Role if role == "master" { - AddNewMasterToPeers() AsMaster() util.ResponseFormat(c, code.AddSuccess, "鍔犲叆鑺傜偣鎴愬姛") return } else if role == "volume" { - AsVolume() - util.ResponseFormat(c, code.AddSuccess, "鍔犲叆鑺傜偣鎴愬姛") - return + status := AsVolume() + if status == true { + util.ResponseFormat(c, code.AddSuccess, "鍔犲叆鑺傜偣鎴愬姛") + return + } else { + util.ResponseFormat(c, code.AddClusterInfoErr, "褰撳墠杩樻病鏈変富鑺傜偣") + return + } } else { util.ResponseFormat(c, code.RequestParamError, "閫夋嫨鑺傜偣绫诲瀷閿欒") return @@ -65,6 +68,7 @@ func (sc *SeaweedfsController) RoleOfVolumeToMasterController(c *gin.Context) { AsMaster() + ReplaceLineContentBySearch(StartScriptAsMaster, config.Server.ScriptPath, StartServerScript) } func (sc *SeaweedfsController) RestartMasterController(c *gin.Context) { @@ -170,17 +174,24 @@ } //浣滀负鏁版嵁鑺傜偣鍔犲叆 -func AsVolume() { +func AsVolume() bool { + nowPeers := GetNowPeersList() + if nowPeers == nil || len(nowPeers) == 0 { + return false + } UpdatePeers(config.Server.ScriptPath, StartServerScript, GetNewPeers(), GetNewPeers()) ReplaceLineContentBySearch(StartScriptAsVolume, config.Server.ScriptPath, StartServerScript) ReplaceLineContentBySearch("peers=", config.Server.ScriptPath, StartServerScript) StartServer(config.Server.ScriptPath) + return true } //浣滀负涓昏妭鐐瑰姞鍏ワ紙榛樿鍖呭惈鏁版嵁鑺傜偣锛� -func AsMaster() { +func AsMaster() bool { + AddNewMasterToPeers() nowPeers := GetNowPeersList() RequestMasterNodesOperation(nowPeers) + return true } //鑾峰彇褰撳墠闆嗙兢鍒楄〃 -- Gitblit v1.8.0