Skip to content

Commit

Permalink
Refactor the DMS and Cluster components topology (pingcap#525)
Browse files Browse the repository at this point in the history
Signed-off-by: Lonng <[email protected]>
  • Loading branch information
lonng authored Jun 23, 2020
1 parent 4dfcc90 commit 0267fbc
Show file tree
Hide file tree
Showing 100 changed files with 3,794 additions and 3,655 deletions.
Empty file modified cmd/clean.go
100755 → 100644
Empty file.
Empty file modified cmd/help.go
100755 → 100644
Empty file.
Empty file modified cmd/mirror.go
100755 → 100644
Empty file.
Empty file modified cmd/run.go
100755 → 100644
Empty file.
Empty file modified cmd/status.go
100755 → 100644
Empty file.
Empty file modified cmd/telemetry.go
100755 → 100644
Empty file.
Empty file modified cmd/uninstall.go
100755 → 100644
Empty file.
8 changes: 4 additions & 4 deletions components/cluster/command/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/tiup/pkg/base52"
"github.com/pingcap/tiup/pkg/cliutil"
"github.com/pingcap/tiup/pkg/cluster/meta"
"github.com/pingcap/tiup/pkg/cluster/spec"
tiuputils "github.com/pingcap/tiup/pkg/utils"
"github.com/spf13/cobra"
)
Expand All @@ -51,7 +51,7 @@ func newAuditCmd() *cobra.Command {

func showAuditList() error {
firstLine := func(fileName string) (string, error) {
file, err := os.Open(meta.ProfilePath(meta.TiOpsAuditDir, fileName))
file, err := os.Open(spec.ProfilePath(spec.TiOpsAuditDir, fileName))
if err != nil {
return "", errors.Trace(err)
}
Expand All @@ -64,7 +64,7 @@ func showAuditList() error {
return "", errors.New("unknown audit log format")
}

auditDir := meta.ProfilePath(meta.TiOpsAuditDir)
auditDir := spec.ProfilePath(spec.TiOpsAuditDir)
// Header
clusterTable := [][]string{{"ID", "Time", "Command"}}
fileInfos, err := ioutil.ReadDir(auditDir)
Expand Down Expand Up @@ -100,7 +100,7 @@ func showAuditList() error {
}

func showAuditLog(auditID string) error {
path := meta.ProfilePath(meta.TiOpsAuditDir, auditID)
path := spec.ProfilePath(spec.TiOpsAuditDir, auditID)
if tiuputils.IsNotExist(path) {
return errors.Errorf("cannot find the audit log '%s'", auditID)
}
Expand Down
21 changes: 11 additions & 10 deletions components/cluster/command/check.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import (
"github.com/pingcap/tiup/pkg/cliutil"
"github.com/pingcap/tiup/pkg/cliutil/prepare"
"github.com/pingcap/tiup/pkg/cluster/clusterutil"
"github.com/pingcap/tiup/pkg/cluster/meta"
operator "github.com/pingcap/tiup/pkg/cluster/operation"
"github.com/pingcap/tiup/pkg/cluster/spec"
"github.com/pingcap/tiup/pkg/cluster/task"
"github.com/pingcap/tiup/pkg/logger"
"github.com/pingcap/tiup/pkg/logger/log"
"github.com/pingcap/tiup/pkg/meta"
tiuputils "github.com/pingcap/tiup/pkg/utils"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -64,14 +65,14 @@ conflict checks with other clusters`,

logger.EnableAuditLog()

var topo meta.ClusterSpecification
var topo spec.Specification
if opt.existCluster { // check for existing cluster
clusterName := args[0]
if tiuputils.IsNotExist(meta.ClusterPath(clusterName, meta.MetaFileName)) {
if tiuputils.IsNotExist(spec.ClusterPath(clusterName, spec.MetaFileName)) {
return perrs.Errorf("cluster %s does not exist", clusterName)
}
metadata, err := meta.ClusterMetadata(clusterName)
if err != nil && !errors.Is(perrs.Cause(err), meta.ValidateErr) {
metadata, err := spec.ClusterMetadata(clusterName)
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) {
return err
}
topo = *metadata.Topology
Expand Down Expand Up @@ -112,25 +113,25 @@ conflict checks with other clusters`,
}

// checkSystemInfo performs series of checks and tests of the deploy server
func checkSystemInfo(s *cliutil.SSHConnectionProps, topo *meta.ClusterSpecification, opt *checkOptions) error {
func checkSystemInfo(s *cliutil.SSHConnectionProps, topo *spec.Specification, opt *checkOptions) error {
var (
collectTasks []*task.StepDisplay
checkSysTasks []*task.StepDisplay
cleanTasks []*task.StepDisplay
applyFixTasks []*task.StepDisplay
downloadTasks []*task.StepDisplay
)
insightVer := meta.ComponentVersion(meta.ComponentCheckCollector, "")
insightVer := spec.ComponentVersion(spec.ComponentCheckCollector, "")

uniqueHosts := map[string]int{} // host -> ssh-port
uniqueArchList := make(map[string]struct{}) // map["os-arch"]{}
topo.IterInstance(func(inst meta.Instance) {
topo.IterInstance(func(inst spec.Instance) {
archKey := fmt.Sprintf("%s-%s", inst.OS(), inst.Arch())
if _, found := uniqueArchList[archKey]; !found {
uniqueArchList[archKey] = struct{}{}
t0 := task.NewBuilder().
Download(
meta.ComponentCheckCollector,
spec.ComponentCheckCollector,
inst.OS(),
inst.Arch(),
insightVer,
Expand All @@ -154,7 +155,7 @@ func checkSystemInfo(s *cliutil.SSHConnectionProps, topo *meta.ClusterSpecificat
).
Mkdir(opt.user, inst.GetHost(), filepath.Join(task.CheckToolsPathDir, "bin")).
CopyComponent(
meta.ComponentCheckCollector,
spec.ComponentCheckCollector,
inst.OS(),
inst.Arch(),
insightVer,
Expand Down
37 changes: 19 additions & 18 deletions components/cluster/command/deploy.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ import (
"github.com/pingcap/tiup/pkg/cliutil"
"github.com/pingcap/tiup/pkg/cliutil/prepare"
"github.com/pingcap/tiup/pkg/cluster/clusterutil"
"github.com/pingcap/tiup/pkg/cluster/meta"
operator "github.com/pingcap/tiup/pkg/cluster/operation"
"github.com/pingcap/tiup/pkg/cluster/report"
"github.com/pingcap/tiup/pkg/cluster/spec"
"github.com/pingcap/tiup/pkg/cluster/task"
"github.com/pingcap/tiup/pkg/errutil"
"github.com/pingcap/tiup/pkg/logger"
"github.com/pingcap/tiup/pkg/logger/log"
"github.com/pingcap/tiup/pkg/meta"
"github.com/pingcap/tiup/pkg/set"
telemetry2 "github.com/pingcap/tiup/pkg/telemetry"
tiuputils "github.com/pingcap/tiup/pkg/utils"
Expand Down Expand Up @@ -110,7 +111,7 @@ func newDeploy() *cobra.Command {
return cmd
}

func confirmTopology(clusterName, version string, topo *meta.ClusterSpecification, patchedRoles set.StringSet) error {
func confirmTopology(clusterName, version string, topo *spec.Specification, patchedRoles set.StringSet) error {
log.Infof("Please confirm your topology:")

cyan := color.New(color.FgCyan, color.Bold)
Expand All @@ -122,7 +123,7 @@ func confirmTopology(clusterName, version string, topo *meta.ClusterSpecificatio
{"Type", "Host", "Ports", "OS/Arch", "Directories"},
}

topo.IterInstance(func(instance meta.Instance) {
topo.IterInstance(func(instance spec.Instance) {
comp := instance.ComponentName()
if patchedRoles.Exist(comp) {
comp = comp + " (patched)"
Expand Down Expand Up @@ -152,14 +153,14 @@ func deploy(clusterName, clusterVersion, topoFile string, opt deployOptions) err
if err := clusterutil.ValidateClusterNameOrError(clusterName); err != nil {
return err
}
if tiuputils.IsExist(meta.ClusterPath(clusterName, meta.MetaFileName)) {
if tiuputils.IsExist(spec.ClusterPath(clusterName, spec.MetaFileName)) {
// FIXME: When change to use args, the suggestion text need to be updated.
return errDeployNameDuplicate.
New("Cluster name '%s' is duplicated", clusterName).
WithProperty(cliutil.SuggestionFromFormat("Please specify another cluster name"))
}

var topo meta.ClusterSpecification
var topo spec.Specification
if err := clusterutil.ParseTopologyYaml(topoFile, &topo); err != nil {
return err
}
Expand All @@ -186,9 +187,9 @@ func deploy(clusterName, clusterVersion, topoFile string, opt deployOptions) err
return err
}

if err := os.MkdirAll(meta.ClusterPath(clusterName), 0755); err != nil {
if err := os.MkdirAll(spec.ClusterPath(clusterName), 0755); err != nil {
return errorx.InitializationFailed.
Wrap(err, "Failed to create cluster metadata directory '%s'", meta.ClusterPath(clusterName)).
Wrap(err, "Failed to create cluster metadata directory '%s'", spec.ClusterPath(clusterName)).
WithProperty(cliutil.SuggestionFromString("Please check file system permissions and try again."))
}

Expand All @@ -203,7 +204,7 @@ func deploy(clusterName, clusterVersion, topoFile string, opt deployOptions) err
globalOptions := topo.GlobalOptions
var iterErr error // error when itering over instances
iterErr = nil
topo.IterInstance(func(inst meta.Instance) {
topo.IterInstance(func(inst spec.Instance) {
if _, found := uniqueHosts[inst.GetHost()]; !found {
// check for "imported" parameter, it can not be true when scaling out
if inst.IsImported() {
Expand Down Expand Up @@ -255,8 +256,8 @@ func deploy(clusterName, clusterVersion, topoFile string, opt deployOptions) err
downloadCompTasks = prepare.BuildDownloadCompTasks(clusterVersion, &topo)

// Deploy components to remote
topo.IterInstance(func(inst meta.Instance) {
version := meta.ComponentVersion(inst.ComponentName(), clusterVersion)
topo.IterInstance(func(inst spec.Instance) {
version := spec.ComponentVersion(inst.ComponentName(), clusterVersion)
deployDir := clusterutil.Abs(globalOptions.User, inst.DeployDir())
// data dir would be empty for components which don't need it
dataDirs := clusterutil.MultiDirAbs(globalOptions.User, inst.DataDir())
Expand Down Expand Up @@ -289,7 +290,7 @@ func deploy(clusterName, clusterVersion, topoFile string, opt deployOptions) err
Deploy: deployDir,
Data: dataDirs,
Log: logDir,
Cache: meta.ClusterPath(clusterName, meta.TempConfigPath),
Cache: spec.ClusterPath(clusterName, spec.TempConfigPath),
},
).
BuildAsStep(fmt.Sprintf(" - Copy %s -> %s", inst.ComponentName(), inst.GetHost()))
Expand Down Expand Up @@ -320,7 +321,7 @@ func deploy(clusterName, clusterVersion, topoFile string, opt deployOptions) err

builder := task.NewBuilder().
Step("+ Generate SSH keys",
task.NewBuilder().SSHKeyGen(meta.ClusterPath(clusterName, "ssh", "id_rsa")).Build()).
task.NewBuilder().SSHKeyGen(spec.ClusterPath(clusterName, "ssh", "id_rsa")).Build()).
ParallelStep("+ Download TiDB components", downloadCompTasks...).
ParallelStep("+ Initialize target host environments", envInitTasks...).
ParallelStep("+ Copy files", deployCompTasks...)
Expand All @@ -339,7 +340,7 @@ func deploy(clusterName, clusterVersion, topoFile string, opt deployOptions) err
return errors.Trace(err)
}

err = meta.SaveClusterMeta(clusterName, &meta.ClusterMeta{
err = spec.SaveClusterMeta(clusterName, &spec.ClusterMeta{
User: globalOptions.User,
Version: clusterVersion,
Topology: &topo,
Expand All @@ -356,14 +357,14 @@ func deploy(clusterName, clusterVersion, topoFile string, opt deployOptions) err
func buildMonitoredDeployTask(
clusterName string,
uniqueHosts map[string]hostInfo, // host -> ssh-port, os, arch
globalOptions meta.GlobalOptions,
monitoredOptions meta.MonitoredOptions,
globalOptions spec.GlobalOptions,
monitoredOptions spec.MonitoredOptions,
version string,
) (downloadCompTasks []*task.StepDisplay, deployCompTasks []*task.StepDisplay) {
uniqueCompOSArch := make(map[string]struct{}) // comp-os-arch -> {}
// monitoring agents
for _, comp := range []string{meta.ComponentNodeExporter, meta.ComponentBlackboxExporter} {
version := meta.ComponentVersion(comp, version)
for _, comp := range []string{spec.ComponentNodeExporter, spec.ComponentBlackboxExporter} {
version := spec.ComponentVersion(comp, version)

for host, info := range uniqueHosts {
// populate unique os/arch set
Expand Down Expand Up @@ -411,7 +412,7 @@ func buildMonitoredDeployTask(
Deploy: deployDir,
Data: []string{dataDir},
Log: logDir,
Cache: meta.ClusterPath(clusterName, meta.TempConfigPath),
Cache: spec.ClusterPath(clusterName, spec.TempConfigPath),
},
).
BuildAsStep(fmt.Sprintf(" - Copy %s -> %s", comp, host))
Expand Down
17 changes: 9 additions & 8 deletions components/cluster/command/destroy.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import (
"github.com/joomcode/errorx"
perrs "github.com/pingcap/errors"
"github.com/pingcap/tiup/pkg/cliutil"
"github.com/pingcap/tiup/pkg/cluster/meta"
operator "github.com/pingcap/tiup/pkg/cluster/operation"
"github.com/pingcap/tiup/pkg/cluster/spec"
"github.com/pingcap/tiup/pkg/cluster/task"
"github.com/pingcap/tiup/pkg/logger"
"github.com/pingcap/tiup/pkg/logger/log"
"github.com/pingcap/tiup/pkg/meta"
"github.com/pingcap/tiup/pkg/set"
tiuputils "github.com/pingcap/tiup/pkg/utils"
"github.com/spf13/cobra"
Expand All @@ -47,7 +48,7 @@ You can retain some nodes and roles data when destroy cluster, eg:

// Validate the retained roles to prevent unexpected deleting data
if len(destoyOpt.RetainDataRoles) > 0 {
validRoles := set.NewStringSet(meta.AllComponentNames()...)
validRoles := set.NewStringSet(spec.AllComponentNames()...)
for _, role := range destoyOpt.RetainDataRoles {
if !validRoles.Exist(role) {
return perrs.Errorf("role name `%s` invalid", role)
Expand All @@ -57,13 +58,13 @@ You can retain some nodes and roles data when destroy cluster, eg:

clusterName := args[0]
teleCommand = append(teleCommand, scrubClusterName(clusterName))
if tiuputils.IsNotExist(meta.ClusterPath(clusterName, meta.MetaFileName)) {
if tiuputils.IsNotExist(spec.ClusterPath(clusterName, spec.MetaFileName)) {
return perrs.Errorf("cannot destroy non-exists cluster %s", clusterName)
}

logger.EnableAuditLog()
metadata, err := meta.ClusterMetadata(clusterName)
if err != nil && !errors.Is(perrs.Cause(err), meta.ValidateErr) {
metadata, err := spec.ClusterMetadata(clusterName)
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) {
return err
}

Expand All @@ -79,8 +80,8 @@ You can retain some nodes and roles data when destroy cluster, eg:

t := task.NewBuilder().
SSHKeySet(
meta.ClusterPath(clusterName, "ssh", "id_rsa"),
meta.ClusterPath(clusterName, "ssh", "id_rsa.pub")).
spec.ClusterPath(clusterName, "ssh", "id_rsa"),
spec.ClusterPath(clusterName, "ssh", "id_rsa.pub")).
ClusterSSH(metadata.Topology, metadata.User, gOpt.SSHTimeout).
ClusterOperate(metadata.Topology, operator.StopOperation, operator.Options{}).
ClusterOperate(metadata.Topology, operator.DestroyOperation, destoyOpt).
Expand All @@ -94,7 +95,7 @@ You can retain some nodes and roles data when destroy cluster, eg:
return perrs.Trace(err)
}

if err := os.RemoveAll(meta.ClusterPath(clusterName)); err != nil {
if err := os.RemoveAll(spec.ClusterPath(clusterName)); err != nil {
return perrs.Trace(err)
}
log.Infof("Destroyed cluster `%s` successfully", clusterName)
Expand Down
Loading

0 comments on commit 0267fbc

Please sign in to comment.