fix
liuxiaolong
2019-11-13 263c7b18ce7f18f1222318f6e0e499e907895a52
controllers/cluster.go
@@ -40,6 +40,7 @@
   Password string `json:"password"`
   ClusterName string `json:"clusterName"`
   ClusterId string `json:"clusterId"`
   VirtualIp string `json:"virtualIp"`
}
type ClusterSearchVo struct {
@@ -53,15 +54,22 @@
   NodeIps []string `json:"nodeIps"`
}
// @Summary 创建集群
// @Description 创建集群
// @Accept json
// @Produce json
// @Tags cluster
// @Param  clusterArg body controllers.ClusterCreateVo true "集群创建参数"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/cluster/create [post]
type ClusterDb struct {
   ClusterId   string `json:"clusterId"`
   ClusterName string `json:"clusterName"`
   Nodes []NodeDb     `json:"nodes"`
}
type NodeDb struct {
   Id string `json:"id"`
   ClusterId string `json:"cluster_id"`
   NodeName string `json:"node_name"`
   NodeId string `json:"node_id"`
   NodeIp string `json:"node_ip"`
   CreateTime string `json:"create_time"`
   IsDelete bool `json:"isDelete"`
}
func (cc ClusterController) Create(c *gin.Context) {
   var clusterVo ClusterCreateVo
   err := c.BindJSON(&clusterVo)
@@ -70,7 +78,7 @@
      return
   }
   var api dbapi.ClusterApi
   b, d := api.Create(clusterVo.ClusterName, clusterVo.Password)
   b, d := api.Create(clusterVo.ClusterName, clusterVo.Password, clusterVo.VirtualIp)
   if b {
      util.ResponseFormat(c,code.Success, d)
   } else {
@@ -78,27 +86,32 @@
   }
}
// @Summary 生成集群6位随机密码
// @Description 生成集群6位随机密码
// @Produce json
// @Tags cluster
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/cluster/randomPwd [get]
func (cc ClusterController) RandomPwd(c *gin.Context) {
   pwd := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
   util.ResponseFormat(c,code.Success,pwd)
}
// @Summary 搜索集群
// @Description 搜索集群
// @Accept json
/*
// @Security ApiKeyAuth
// @Summary 查询本地集群
// @Description 查询本地集群
// @Produce json
// @Tags cluster
// @Param searchArg body controllers.ClusterSearchVo true "集群搜索参数"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/cluster/search [post]
// @Router /data/api-v/cluster/findCluster [get]
*/
func (cc ClusterController) FindCluster(c *gin.Context) {
   var clusterApi dbapi.ClusterApi
   b, d := clusterApi.FindCluster()
   if b {
      util.ResponseFormat(c,code.Success, d)
   } else {
      util.ResponseFormat(c,code.ComError,"集群查询失败")
   }
}
func (cc ClusterController) Search(c *gin.Context) {
   var csv ClusterSearchVo
   err := c.BindJSON(&csv)
@@ -115,14 +128,7 @@
   }
}
// @Summary 通过searchNum异步获取集群节点信息
// @Description 通过searchNum异步获取集群节点信息
// @Accept json
// @Produce json
// @Tags cluster
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/cluster/getNodesByNum [get]
func (cc ClusterController) GetSearchNodes(c *gin.Context) {
   var api dbapi.ClusterApi
   b, d := api.GetSearchNodes()
@@ -133,14 +139,7 @@
   }
}
// @Summary 通过searchNum停止搜索
// @Description 通过searchNum停止搜索
// @Produce json
// @Tags cluster
// @Param searchNum query string true "搜索编号"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/cluster/stopSearching [post]
func (cc ClusterController) StopSearching(c *gin.Context) {
   searchNum := c.Query("searchNum")
   if searchNum == "" {
@@ -157,15 +156,6 @@
}
// @Summary 加入集群
// @Description 加入集群
// @Accept json
// @Produce json
// @Tags cluster
// @Param  clusterArg body controllers.ClusterCreateVo true "集群创建参数"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/cluster/joinCluster [post]
func (cc ClusterController) JoinCluster(c *gin.Context) {
   var arg ClusterJoinVo
   err := c.BindJSON(&arg)
@@ -182,3 +172,51 @@
      util.ResponseFormat(c,code.ComError,"加入失败")
   }
}
/*
// @Security ApiKeyAuth
// @Summary 保存集群名称
// @Description 保存集群名称
// @Accept x-www-form-urlencoded
// @Produce json
// @Tags cluster
// @Param clusterName formData string true "集群名称"
// @Param virtualIp formData string false "虚拟ip"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/cluster/updateClusterName [post]
*/
func (cc ClusterController) UpdateClusterName(c *gin.Context) {
   clusterName := c.PostForm("clusterName")
   if clusterName == "" {
      util.ResponseFormat(c,code.RequestParamError, "参数有误")
      return
   }
   virtualIp := c.PostForm("virtualIp")
   var api dbapi.ClusterApi
   b,_ := api.UpdateClusterName(clusterName,virtualIp)
   if b {
      util.ResponseFormat(c,code.UpdateSuccess,"更新成功")
   } else {
      util.ResponseFormat(c,code.ComError, "更新失败")
   }
}
/*
// @Security ApiKeyAuth
// @Summary 退出集群
// @Description 退出集群
// @Produce json
// @Tags cluster
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/cluster/leave [post]
*/
func (cc ClusterController) Leave(c *gin.Context) {
   var api dbapi.ClusterApi
   if b,_:= api.Leave();b {
      util.ResponseFormat(c,code.Success,"退出成功")
   } else {
      util.ResponseFormat(c,code.ComError,"退出失败")
   }
}