Skip to content

Commit

Permalink
Merge pull request #1015 from signal18/rename
Browse files Browse the repository at this point in the history
Feature: drop and rename cluster
  • Loading branch information
svaroqui authored Jan 21, 2025
2 parents c364d66 + efd1b37 commit 0ee4450
Show file tree
Hide file tree
Showing 21 changed files with 507 additions and 77 deletions.
5 changes: 4 additions & 1 deletion cluster/cluster_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type APIUser struct {
Password string `json:"-"`
GitToken string `json:"-"`
GitUser string `json:"-"`
IsExternal bool `json:"-"`
IsExternal bool `json:"isExternal"`
Roles map[string]bool `json:"roles"`
Grants map[string]bool `json:"grants"`
}
Expand Down Expand Up @@ -818,6 +818,9 @@ func (cluster *Cluster) IsURLPassACL(strUser string, URL string, errorPrint bool
if strings.Contains(URL, "/api/clusters/actions/delete") {
return true
}
if strings.Contains(URL, "/api/clusters/actions/rename") {
return true
}
}
if cluster.APIUsers[strUser].Grants[config.GrantClusterConfigGraphs] {
if strings.Contains(URL, "/api/clusters/"+cluster.Name+"/settings/actions/set-graphite-filterlist") {
Expand Down
32 changes: 32 additions & 0 deletions cluster/cluster_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"fmt"
"io"
"net/http"
"os"
"os/exec"
"strconv"
"strings"
Expand Down Expand Up @@ -2228,3 +2229,34 @@ func (cluster *Cluster) SetResticVersion() error {
func (cluster *Cluster) SetInRollingRestart(value bool) {
cluster.InRollingRestart = value
}

func (cluster *Cluster) RenameCluster(newClusterName string) error {

cluster.Lock()
defer func() {
cluster.Unlock()
cluster.Save()
}()

cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral, config.LvlInfo, "Initiate rename cluster %s to %s", cluster.Name, newClusterName)

// Rename cluster directory
err := os.Rename(cluster.Conf.WorkingDir+"/"+cluster.Name, cluster.Conf.WorkingDir+"/"+newClusterName)
if err != nil {
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral, config.LvlErr, "Rename cluster working directory fail: %s", err)
return err
}

// Rename cluster configuration file
err = os.Rename(cluster.Conf.WorkingDir+"/"+newClusterName+"/"+cluster.Name+".toml", cluster.Conf.WorkingDir+"/"+newClusterName+"/"+newClusterName+".toml")
if err != nil {
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral, config.LvlErr, "Rename cluster working directory fail: %s", err)
return err
}

// Rename cluster name
cluster.Name = newClusterName

return nil

}
1 change: 1 addition & 0 deletions cluster/prov_onpremise_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (cluster *Cluster) OnPremiseGetNodes() ([]Agent, error) {
client, err := cluster.OnPremiseConnect(server)
if err != nil {
cluster.errorChan <- err
continue
}
defer client.Close()

Expand Down
5 changes: 2 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,6 @@ const (
GrantDBDebug string = "db-debug"
GrantClusterCreate string = "cluster-create"
GrantClusterDelete string = "cluster-delete"
GrantClusterDrop string = "cluster-drop"
GrantClusterCreateMonitor string = "cluster-create-monitor"
GrantClusterDropMonitor string = "cluster-drop-monitor"
GrantClusterFailover string = "cluster-failover"
Expand Down Expand Up @@ -2127,7 +2126,7 @@ func GetGrantType() map[string]string {
GrantDBShowLogs: GrantDBShowLogs,
GrantDBDebug: GrantDBDebug,
GrantClusterCreate: GrantClusterCreate,
GrantClusterDrop: GrantClusterDrop,
GrantClusterDelete: GrantClusterDelete,
GrantClusterCreateMonitor: GrantClusterCreateMonitor,
GrantClusterDropMonitor: GrantClusterDropMonitor,
GrantClusterFailover: GrantClusterFailover,
Expand Down Expand Up @@ -2221,7 +2220,7 @@ func HasAllDBGrants(grants map[string]bool) bool {
func GetGrantCluster() []string {
return []string{
GrantClusterCreate,
GrantClusterDrop,
GrantClusterDelete,
GrantClusterCreateMonitor,
GrantClusterDropMonitor,
GrantClusterFailover,
Expand Down
102 changes: 99 additions & 3 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,61 @@ const docTemplate = `{
"type": "string"
}
},
"400": {
"description": "Invalid cluster name",
"500": {
"description": "Invalid cluster name\" or \"No Valid ACL",
"schema": {
"type": "string"
}
}
}
}
},
"/api/clusters/actions/rename/{clusterName}/{newClusterName}": {
"post": {
"description": "Renames a cluster identified by its name.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Cluster"
],
"summary": "Rename a cluster",
"parameters": [
{
"type": "string",
"default": "Bearer \u003cAdd access token here\u003e",
"description": "Insert your access token",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "string",
"description": "Cluster Name",
"name": "clusterName",
"in": "path",
"required": true
},
{
"type": "string",
"description": "New Cluster Name",
"name": "newClusterName",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Cluster renamed successfully",
"schema": {
"type": "string"
}
},
"500": {
"description": "Internal server error",
"description": "Invalid cluster name\" or \"Cluster name already exists\" or \"No Valid ACL",
"schema": {
"type": "string"
}
Expand Down Expand Up @@ -1020,6 +1067,55 @@ const docTemplate = `{
}
}
},
"/api/clusters/{clusterName}/actions/refresh-staging": {
"post": {
"description": "Refreshes the staging cluster specified by the cluster name in the URL.",
"produces": [
"application/json"
],
"tags": [
"ClusterActions"
],
"summary": "Refresh Staging Cluster",
"parameters": [
{
"type": "string",
"default": "Bearer \u003cAdd access token here\u003e",
"description": "Insert your access token",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "string",
"description": "Cluster Name",
"name": "clusterName",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Staging cluster refresh initiated",
"schema": {
"type": "string"
}
},
"403": {
"description": "No valid ACL",
"schema": {
"type": "string"
}
},
"500": {
"description": "No cluster",
"schema": {
"type": "string"
}
}
}
}
},
"/api/clusters/{clusterName}/actions/replication/bootstrap/{topology}": {
"post": {
"description": "This endpoint triggers the bootstrap replication process for the specified cluster.",
Expand Down
102 changes: 99 additions & 3 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,61 @@
"type": "string"
}
},
"400": {
"description": "Invalid cluster name",
"500": {
"description": "Invalid cluster name\" or \"No Valid ACL",
"schema": {
"type": "string"
}
}
}
}
},
"/api/clusters/actions/rename/{clusterName}/{newClusterName}": {
"post": {
"description": "Renames a cluster identified by its name.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Cluster"
],
"summary": "Rename a cluster",
"parameters": [
{
"type": "string",
"default": "Bearer \u003cAdd access token here\u003e",
"description": "Insert your access token",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "string",
"description": "Cluster Name",
"name": "clusterName",
"in": "path",
"required": true
},
{
"type": "string",
"description": "New Cluster Name",
"name": "newClusterName",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Cluster renamed successfully",
"schema": {
"type": "string"
}
},
"500": {
"description": "Internal server error",
"description": "Invalid cluster name\" or \"Cluster name already exists\" or \"No Valid ACL",
"schema": {
"type": "string"
}
Expand Down Expand Up @@ -1009,6 +1056,55 @@
}
}
},
"/api/clusters/{clusterName}/actions/refresh-staging": {
"post": {
"description": "Refreshes the staging cluster specified by the cluster name in the URL.",
"produces": [
"application/json"
],
"tags": [
"ClusterActions"
],
"summary": "Refresh Staging Cluster",
"parameters": [
{
"type": "string",
"default": "Bearer \u003cAdd access token here\u003e",
"description": "Insert your access token",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "string",
"description": "Cluster Name",
"name": "clusterName",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Staging cluster refresh initiated",
"schema": {
"type": "string"
}
},
"403": {
"description": "No valid ACL",
"schema": {
"type": "string"
}
},
"500": {
"description": "No cluster",
"schema": {
"type": "string"
}
}
}
}
},
"/api/clusters/{clusterName}/actions/replication/bootstrap/{topology}": {
"post": {
"description": "This endpoint triggers the bootstrap replication process for the specified cluster.",
Expand Down
Loading

0 comments on commit 0ee4450

Please sign in to comment.