Skip to content

Commit

Permalink
Feature/split cluster into small files (#979)
Browse files Browse the repository at this point in the history
* style(cluster): move ca-cert into manager_util.go

* style(cluster): rm once used struct

* style(cluster): manager_util.go -> cacert.go

* style(cluster): move task releated into builder.go

* refact(cluster): add function regenConfigTasks to dry

* feat(clustertask/action): simply code

* typo(cluster,repository): fix with make check

* refact(cluster): add sshTaskBuilder to reduce code

* refact(cluster): manager as module

* refact(dm,cluster): compatible with module cluster

* refact(cluster/manger): split into small files

* style(cluster/manager): unified clusterName to name

* typo(cluster/manager): naming

* refact(cluster,dm): use gOpt directly
  • Loading branch information
jsvisa authored Dec 11, 2020
1 parent 9e5f2bd commit 91466ae
Show file tree
Hide file tree
Showing 58 changed files with 2,945 additions and 2,719 deletions.
2 changes: 1 addition & 1 deletion components/cluster/command/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ You can retain some nodes and roles data when cleanup the cluster, eg:
return cmd.Help()
}

return manager.CleanCluster(clusterName, gOpt, cleanOpt, skipConfirm)
return cm.CleanCluster(clusterName, gOpt, cleanOpt, skipConfirm)
},
}

Expand Down
16 changes: 3 additions & 13 deletions components/cluster/command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"path"

"github.com/pingcap/tiup/pkg/cliutil"
"github.com/pingcap/tiup/pkg/cluster"
"github.com/pingcap/tiup/pkg/cluster/executor"
"github.com/pingcap/tiup/pkg/cluster/manager"
operator "github.com/pingcap/tiup/pkg/cluster/operation"
"github.com/pingcap/tiup/pkg/cluster/report"
"github.com/pingcap/tiup/pkg/cluster/spec"
Expand All @@ -45,7 +45,7 @@ var (
)

func newDeploy() *cobra.Command {
opt := cluster.DeployOptions{
opt := manager.DeployOptions{
IdentityFile: path.Join(utils.UserHome(), ".ssh", "id_rsa"),
}
cmd := &cobra.Command{
Expand Down Expand Up @@ -77,17 +77,7 @@ func newDeploy() *cobra.Command {
teleTopology = string(data)
}

return manager.Deploy(
clusterName,
version,
topoFile,
opt,
postDeployHook,
skipConfirm,
gOpt.OptTimeout,
gOpt.SSHTimeout,
gOpt.SSHType,
)
return cm.Deploy(clusterName, version, topoFile, opt, postDeployHook, skipConfirm, gOpt)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ You can retain some nodes and roles data when destroy cluster, eg:
}
}

return manager.DestroyCluster(clusterName, gOpt, destoyOpt, skipConfirm)
return cm.DestroyCluster(clusterName, gOpt, destoyOpt, skipConfirm)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func newDisableCmd() *cobra.Command {
clusterName := args[0]
teleCommand = append(teleCommand, scrubClusterName(clusterName))

return manager.EnableCluster(clusterName, gOpt, false)
return cm.EnableCluster(clusterName, gOpt, false)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func newDisplayCmd() *cobra.Command {
return displayDashboardInfo(clusterName, tlsCfg)
}

return manager.Display(clusterName, gOpt)
return cm.Display(clusterName, gOpt)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/edit_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func newEditConfigCmd() *cobra.Command {
clusterName := args[0]
teleCommand = append(teleCommand, scrubClusterName(clusterName))

return manager.EditConfig(clusterName, skipConfirm)
return cm.EditConfig(clusterName, skipConfirm)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func newEnableCmd() *cobra.Command {
clusterName := args[0]
teleCommand = append(teleCommand, scrubClusterName(clusterName))

return manager.EnableCluster(clusterName, gOpt, true)
return cm.EnableCluster(clusterName, gOpt, true)
},
}

Expand Down
6 changes: 3 additions & 3 deletions components/cluster/command/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
package command

import (
"github.com/pingcap/tiup/pkg/cluster"
"github.com/pingcap/tiup/pkg/cluster/manager"
"github.com/spf13/cobra"
)

func newExecCmd() *cobra.Command {
opt := cluster.ExecOptions{}
opt := manager.ExecOptions{}
cmd := &cobra.Command{
Use: "exec <cluster-name>",
Short: "Run shell command on host in the tidb cluster",
Expand All @@ -31,7 +31,7 @@ func newExecCmd() *cobra.Command {
clusterName := args[0]
teleCommand = append(teleCommand, scrubClusterName(clusterName))

return manager.Exec(clusterName, opt, gOpt)
return cm.Exec(clusterName, opt, gOpt)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func newListCmd() *cobra.Command {
Use: "list",
Short: "List all clusters",
RunE: func(cmd *cobra.Command, args []string) error {
return manager.ListCluster()
return cm.ListCluster()
},
}
return cmd
Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func newPatchCmd() *cobra.Command {
clusterName := args[0]
teleCommand = append(teleCommand, scrubClusterName(clusterName))

return manager.Patch(clusterName, args[1], gOpt, overwrite)
return cm.Patch(clusterName, args[1], gOpt, overwrite)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func newPruneCmd() *cobra.Command {

clusterName := args[0]

return manager.DestroyTombstone(clusterName, gOpt, skipConfirm)
return cm.DestroyTombstone(clusterName, gOpt, skipConfirm)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func newReloadCmd() *cobra.Command {
clusterName := args[0]
teleCommand = append(teleCommand, scrubClusterName(clusterName))

return manager.Reload(clusterName, gOpt, skipRestart)
return cm.Reload(clusterName, gOpt, skipRestart)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func newRenameCmd() *cobra.Command {
newClusterName := args[1]
teleCommand = append(teleCommand, scrubClusterName(oldClusterName))

return manager.Rename(oldClusterName, gOpt, newClusterName)
return cm.Rename(oldClusterName, gOpt, newClusterName)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func newRestartCmd() *cobra.Command {
clusterName := args[0]
teleCommand = append(teleCommand, scrubClusterName(clusterName))

return manager.RestartCluster(clusterName, gOpt)
return cm.RestartCluster(clusterName, gOpt)
},
}

Expand Down
6 changes: 3 additions & 3 deletions components/cluster/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
"github.com/google/uuid"
"github.com/joomcode/errorx"
"github.com/pingcap/tiup/pkg/cliutil"
"github.com/pingcap/tiup/pkg/cluster"
"github.com/pingcap/tiup/pkg/cluster/executor"
"github.com/pingcap/tiup/pkg/cluster/flags"
"github.com/pingcap/tiup/pkg/cluster/manager"
operator "github.com/pingcap/tiup/pkg/cluster/operation"
"github.com/pingcap/tiup/pkg/cluster/report"
"github.com/pingcap/tiup/pkg/cluster/spec"
Expand All @@ -52,7 +52,7 @@ var (
)

var tidbSpec *spec.SpecManager
var manager *cluster.Manager
var cm *manager.Manager

func scrubClusterName(n string) string {
return "cluster_" + telemetry.HashReport(n)
Expand Down Expand Up @@ -100,7 +100,7 @@ func init() {
}

tidbSpec = spec.GetSpecManager()
manager = cluster.NewManager("tidb", tidbSpec, spec.TiDBComponentVersion)
cm = manager.NewManager("tidb", tidbSpec, spec.TiDBComponentVersion)
logger.EnableAuditLog(spec.AuditDir())

// Running in other OS/ARCH Should be fine we only download manifest file.
Expand Down
11 changes: 1 addition & 10 deletions components/cluster/command/scale_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,7 @@ func newScaleInCmd() *cobra.Command {
UpdateTopology(clusterName, tidbSpec.Path(clusterName), metadata, nodes)
}

return manager.ScaleIn(
clusterName,
skipConfirm,
gOpt.OptTimeout,
gOpt.SSHTimeout,
gOpt.SSHType,
gOpt.Force,
gOpt.Nodes,
scale,
)
return cm.ScaleIn(clusterName, skipConfirm, gOpt, scale)
},
}

Expand Down
10 changes: 4 additions & 6 deletions components/cluster/command/scale_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import (
"io/ioutil"
"path/filepath"

"github.com/pingcap/tiup/pkg/cluster"
"github.com/pingcap/tiup/pkg/cluster/executor"
"github.com/pingcap/tiup/pkg/cluster/manager"
"github.com/pingcap/tiup/pkg/cluster/spec"
"github.com/pingcap/tiup/pkg/cluster/task"
"github.com/pingcap/tiup/pkg/utils"
"github.com/spf13/cobra"
)

func newScaleOutCmd() *cobra.Command {
opt := cluster.ScaleOutOptions{
opt := manager.ScaleOutOptions{
IdentityFile: filepath.Join(utils.UserHome(), ".ssh", "id_rsa"),
}
cmd := &cobra.Command{
Expand All @@ -51,16 +51,14 @@ func newScaleOutCmd() *cobra.Command {
teleTopology = string(data)
}

return manager.ScaleOut(
return cm.ScaleOut(
clusterName,
topoFile,
postScaleOutHook,
final,
opt,
skipConfirm,
gOpt.OptTimeout,
gOpt.SSHTimeout,
gOpt.SSHType,
gOpt,
)
},
}
Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func newStartCmd() *cobra.Command {
clusterName := args[0]
teleCommand = append(teleCommand, scrubClusterName(clusterName))

return manager.StartCluster(clusterName, gOpt, func(b *task.Builder, metadata spec.Metadata) {
return cm.StartCluster(clusterName, gOpt, func(b *task.Builder, metadata spec.Metadata) {
b.UpdateTopology(
clusterName,
tidbSpec.Path(clusterName),
Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func newStopCmd() *cobra.Command {
clusterName := args[0]
teleCommand = append(teleCommand, scrubClusterName(clusterName))

return manager.StopCluster(clusterName, gOpt)
return cm.StopCluster(clusterName, gOpt)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func newUpgradeCmd() *cobra.Command {
teleCommand = append(teleCommand, scrubClusterName(clusterName))
teleCommand = append(teleCommand, version)

return manager.Upgrade(clusterName, version, gOpt, skipConfirm)
return cm.Upgrade(clusterName, version, gOpt, skipConfirm)
},
}
cmd.Flags().BoolVar(&gOpt.Force, "force", false, "Force upgrade without transferring PD leader")
Expand Down
16 changes: 3 additions & 13 deletions components/dm/command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import (

"github.com/pingcap/errors"
"github.com/pingcap/tiup/pkg/cliutil"
"github.com/pingcap/tiup/pkg/cluster"
"github.com/pingcap/tiup/pkg/cluster/executor"
"github.com/pingcap/tiup/pkg/cluster/manager"
"github.com/pingcap/tiup/pkg/utils"
"github.com/spf13/cobra"
"golang.org/x/mod/semver"
)

func newDeployCmd() *cobra.Command {
opt := cluster.DeployOptions{
opt := manager.DeployOptions{
IdentityFile: path.Join(utils.UserHome(), ".ssh", "id_rsa"),
}
cmd := &cobra.Command{
Expand Down Expand Up @@ -56,17 +56,7 @@ func newDeployCmd() *cobra.Command {
return err
}

return manager.Deploy(
clusterName,
version,
topoFile,
opt,
nil,
skipConfirm,
gOpt.OptTimeout,
gOpt.SSHTimeout,
gOpt.SSHType,
)
return cm.Deploy(clusterName, version, topoFile, opt, nil, skipConfirm, gOpt)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/dm/command/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func newDestroyCmd() *cobra.Command {

clusterName := args[0]

return manager.DestroyCluster(clusterName, gOpt, operator.Options{}, skipConfirm)
return cm.DestroyCluster(clusterName, gOpt, operator.Options{}, skipConfirm)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/dm/command/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func newDisplayCmd() *cobra.Command {

clusterName = args[0]

return manager.Display(clusterName, gOpt)
return cm.Display(clusterName, gOpt)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/dm/command/edit_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func newEditConfigCmd() *cobra.Command {

clusterName := args[0]

return manager.EditConfig(clusterName, skipConfirm)
return cm.EditConfig(clusterName, skipConfirm)
},
}

Expand Down
6 changes: 3 additions & 3 deletions components/dm/command/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
package command

import (
"github.com/pingcap/tiup/pkg/cluster"
"github.com/pingcap/tiup/pkg/cluster/manager"
"github.com/spf13/cobra"
)

func newExecCmd() *cobra.Command {
opt := cluster.ExecOptions{}
opt := manager.ExecOptions{}
cmd := &cobra.Command{
Use: "exec <cluster-name>",
Short: "Run shell command on host in the dm cluster",
Expand All @@ -30,7 +30,7 @@ func newExecCmd() *cobra.Command {

clusterName := args[0]

return manager.Exec(clusterName, opt, gOpt)
return cm.Exec(clusterName, opt, gOpt)
},
}

Expand Down
Loading

0 comments on commit 91466ae

Please sign in to comment.