Skip to content

Commit

Permalink
refactor(backend): refactor manage cluster, add delete cluster and ch…
Browse files Browse the repository at this point in the history
…ange cluster status

Signed-off-by: lily-lee <[email protected]>
  • Loading branch information
lily-lee committed Feb 5, 2024
1 parent e6fd437 commit af662a2
Show file tree
Hide file tree
Showing 36 changed files with 531 additions and 292 deletions.
3 changes: 2 additions & 1 deletion backend/handler/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ package auth

import (
"errors"

"github.com/cubefs/cubefs/blobstore/util/log"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"

"github.com/cubefs/cubefs/blobstore/util/log"
"github.com/cubefs/cubefs-dashboard/backend/helper/codes"
"github.com/cubefs/cubefs-dashboard/backend/helper/ginutils"
"github.com/cubefs/cubefs-dashboard/backend/model"
Expand Down
16 changes: 3 additions & 13 deletions backend/handler/blobstore/blobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import (

"github.com/cubefs/cubefs-dashboard/backend/handler/blobstore/common"
"github.com/cubefs/cubefs-dashboard/backend/helper/codes"
"github.com/cubefs/cubefs-dashboard/backend/helper/enums"
"github.com/cubefs/cubefs-dashboard/backend/helper/ginutils"
"github.com/cubefs/cubefs-dashboard/backend/model"
cm "github.com/cubefs/cubefs-dashboard/backend/service/blobstore/clustermgr"
"github.com/cubefs/cubefs-dashboard/backend/service/consul"
)
Expand Down Expand Up @@ -102,21 +100,13 @@ func MemberRemove(c *gin.Context) {
}

func ListClusters(c *gin.Context) {
name := c.Param(ginutils.Cluster)
cluster, err := new(model.Cluster).FindName(name)
addr, err := ginutils.GetConsulAddr(c)
if err != nil {
log.Errorf("cluster.FindName failed.name:%+v,err:%+v", name, err)
ginutils.Send(c, codes.DatabaseError.Code(), err.Error(), nil)
return
}
if cluster.VolType != enums.VolTypeLowFrequency || cluster.ConsulAddr == "" {
log.Errorf("type error or no consul_addr.clusterModel:%+v", cluster)
ginutils.Send(c, codes.NotFound.Code(), codes.NotFound.Msg(), nil)
return
}
clusters, err := consul.GetRegionClusters(c, cluster.ConsulAddr)
clusters, err := consul.GetRegionClusters(c, addr)
if err != nil {
log.Errorf("get clusters failed.name:%+v,consul:%s,err:%+v", name, cluster.ConsulAddr, err)
log.Errorf("get clusters failed.id:%s,consul:%s,err:%+v", c.Param(ginutils.Cluster), addr, err)
ginutils.Send(c, codes.ThirdPartyError.Code(), err.Error(), nil)
return
}
Expand Down
2 changes: 1 addition & 1 deletion backend/handler/blobstore/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package common
import (
"github.com/gin-gonic/gin"

"github.com/cubefs/cubefs/blobstore/common/codemode"
"github.com/cubefs/cubefs-dashboard/backend/service/blobstore/clustermgr/config"
"github.com/cubefs/cubefs/blobstore/common/codemode"
)

type CodeMode struct {
Expand Down
46 changes: 29 additions & 17 deletions backend/handler/blobstore/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,35 +272,39 @@ func Offline(c *gin.Context) {
}

type ConfigReloadInput struct {
Nodes []string `json:"nodes" binding:"required"`
Key string `json:"key" binding:"required"`
Value string `json:"value" binding:"required"`
cluster string
Nodes []string `json:"nodes" binding:"required"`
Key string `json:"key" binding:"required"`
Value string `json:"value" binding:"required"`
clusterId int64
}

func ConfigReload(c *gin.Context) {
input := &ConfigReloadInput{}
if !ginutils.Check(c, input) {
return
}
input.cluster = c.Param(ginutils.Cluster)
cluster, err := ginutils.GetCluster(c)
if err != nil {
return
}
input.clusterId = cluster.Id
poolSize := 30
if len(input.Nodes) < poolSize {
poolSize = len(input.Nodes)
}
tp := pool.New(poolSize, poolSize)
errChan := make(chan configReloadErr, poolSize)
go configReload(c, input, tp, errChan)
err := map[string]string{}
errRes := map[string]string{}
for e := range errChan {
err[e.Node] = e.Err
errRes[e.Node] = e.Err
}
if len(err) != 0 {
log.Errorf("reload error. args:%+v, err:%+v", input, err)
ginutils.Send(c, codes.OK.Code(), codes.ThirdPartyError.Msg(), err)
if len(errRes) != 0 {
log.Errorf("reload error. args:%+v, err:%+v", input, errRes)
ginutils.Send(c, codes.OK.Code(), codes.ThirdPartyError.Msg(), errRes)
return
}
ginutils.Send(c, codes.OK.Code(), codes.OK.Msg(), nil)
ginutils.Success(c, nil)
}

type configReloadErr struct {
Expand Down Expand Up @@ -335,20 +339,20 @@ func configReload(c *gin.Context, input *ConfigReloadInput, tp pool.TaskPool, er
func recordConfigFailure(node string, input *ConfigReloadInput, err error) {
failure := &model.NodeConfigFailure{
Node: node,
Cluster: input.cluster,
ClusterId: input.clusterId,
Key: input.Key,
Value: input.Value,
FailedReason: err.Error(),
CreatedAt: time.Now(),
}
if err = failure.Insert(); err != nil {
log.Errorf("record failure failed. err:%v, node[%s], cluster[%s]", err, node, input.cluster)
log.Errorf("record failure failed. err:%v, node[%s], cluster[%d]", err, node, input.clusterId)
}
}

func recordConfigSuccess(node string, input *ConfigReloadInput) {
if err := new(model.NodeConfig).Upsert(node, input.cluster, input.Key, input.Value); err != nil {
log.Errorf("record success failed. err:%v, node[%s], cluster[%s]", err, node, input.cluster)
if err := new(model.NodeConfig).Upsert(node, input.Key, input.Value, input.clusterId); err != nil {
log.Errorf("record success failed. err:%v, node[%s], cluster[%d]", err, node, input.clusterId)
}
}

Expand All @@ -361,8 +365,12 @@ func ConfigInfo(c *gin.Context) {
if !ginutils.Check(c, input) {
return
}
cluster, err := ginutils.GetCluster(c)
if err != nil {
return
}
info := &model.NodeConfig{Configuration: map[string]string{}}
if err := info.One(input.Node, c.Param(ginutils.Cluster)); err != nil {
if err := info.One(input.Node, cluster.Id); err != nil {
log.Errorf("info.One failed.node:%s, err:%+v", input.Node, err)
ginutils.Send(c, codes.DatabaseError.Code(), err.Error(), nil)
return
Expand All @@ -375,8 +383,12 @@ func ConfigFailures(c *gin.Context) {
if !ginutils.Check(c, input) {
return
}
cluster, err := ginutils.GetCluster(c)
if err != nil {
return
}
failure := &model.NodeConfigFailure{}
if err := failure.One(input.Node, c.Param(ginutils.Cluster)); err != nil {
if err := failure.One(input.Node, cluster.Id); err != nil {
log.Errorf("failure.One failed.node:%s, err:%+v", input.Node, err)
ginutils.Send(c, codes.DatabaseError.Code(), err.Error(), nil)
return
Expand Down
Loading

0 comments on commit af662a2

Please sign in to comment.