From 1aa4706b85cc25024d4723bd96e868731f70b8ad Mon Sep 17 00:00:00 2001 From: 9547 Date: Sat, 30 Jan 2021 23:59:37 +0800 Subject: [PATCH 1/5] typo(*): help message more fulent --- components/cluster/command/disable.go | 2 +- pkg/cluster/spec/instance.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/components/cluster/command/disable.go b/components/cluster/command/disable.go index 0386c21aae..88c735e34b 100644 --- a/components/cluster/command/disable.go +++ b/components/cluster/command/disable.go @@ -20,7 +20,7 @@ import ( func newDisableCmd() *cobra.Command { cmd := &cobra.Command{ Use: "disable ", - Short: "Disable starting a TiDB cluster automatically at boot", + Short: "Disable automatic enabling of TiDB clusters at boot", RunE: func(cmd *cobra.Command, args []string) error { if len(args) != 1 { return cmd.Help() diff --git a/pkg/cluster/spec/instance.go b/pkg/cluster/spec/instance.go index 0a4ec96e58..16424060dc 100644 --- a/pkg/cluster/spec/instance.go +++ b/pkg/cluster/spec/instance.go @@ -272,17 +272,17 @@ func (i *BaseInstance) InstanceName() string { // ServiceName implements Instance interface func (i *BaseInstance) ServiceName() string { + var name string switch i.ComponentName() { case ComponentSpark, ComponentTiSpark: - if i.Port > 0 { - return fmt.Sprintf("%s-%d.service", i.Role(), i.Port) - } - return fmt.Sprintf("%s.service", i.Role()) + name = i.Role() + default: + name = i.Name } if i.Port > 0 { - return fmt.Sprintf("%s-%d.service", i.Name, i.Port) + return fmt.Sprintf("%s-%d.service", name, i.Port) } - return fmt.Sprintf("%s.service", i.Name) + return fmt.Sprintf("%s.service", name) } // GetHost implements Instance interface From dea437514fa565928d50a43364dee12343f79b93 Mon Sep 17 00:00:00 2001 From: 9547 Date: Sun, 31 Jan 2021 00:00:40 +0800 Subject: [PATCH 2/5] feat(dm): set service enabled after cluster deployed --- components/dm/command/deploy.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/components/dm/command/deploy.go b/components/dm/command/deploy.go index f99a4c6a1d..f12bd17bdc 100644 --- a/components/dm/command/deploy.go +++ b/components/dm/command/deploy.go @@ -14,12 +14,16 @@ package command import ( + "context" "path" "github.com/pingcap/errors" "github.com/pingcap/tiup/pkg/cliutil" "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/spec" + "github.com/pingcap/tiup/pkg/cluster/task" "github.com/pingcap/tiup/pkg/utils" "github.com/spf13/cobra" "golang.org/x/mod/semver" @@ -59,7 +63,7 @@ func newDeployCmd() *cobra.Command { return err } - return cm.Deploy(clusterName, version, topoFile, opt, nil, skipConfirm, gOpt) + return cm.Deploy(clusterName, version, topoFile, opt, postDeployHook, skipConfirm, gOpt) }, } @@ -82,3 +86,11 @@ func supportVersion(vs string) error { return nil } + +func postDeployHook(builder *task.Builder, topo spec.Topology) { + enableTask := task.NewBuilder().Func("Setting service auto start on boot", func(ctx context.Context) error { + return operator.Enable(ctx, topo, operator.Options{}, true) + }).BuildAsStep("Enable service").SetHidden(true) + + builder.Parallel(false, enableTask) +} From bfaefb2485b24ec920f33448606b9d4ab810e031 Mon Sep 17 00:00:00 2001 From: 9547 Date: Sun, 31 Jan 2021 00:01:15 +0800 Subject: [PATCH 3/5] feat(dm): add enable/disable subcommand --- components/dm/command/disable.go | 43 ++++++++++++++++++++++++++++++++ components/dm/command/enable.go | 43 ++++++++++++++++++++++++++++++++ components/dm/command/root.go | 2 ++ 3 files changed, 88 insertions(+) create mode 100644 components/dm/command/disable.go create mode 100644 components/dm/command/enable.go diff --git a/components/dm/command/disable.go b/components/dm/command/disable.go new file mode 100644 index 0000000000..3251c74646 --- /dev/null +++ b/components/dm/command/disable.go @@ -0,0 +1,43 @@ +// Copyright 2021 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +package command + +import ( + "github.com/spf13/cobra" +) + +func newDisableCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "disable ", + Short: "Disable automatic enabling of DM clusters at boot", + RunE: func(cmd *cobra.Command, args []string) error { + if len(args) != 1 { + return cmd.Help() + } + + if err := validRoles(gOpt.Roles); err != nil { + return nil + } + + clusterName := args[0] + + return cm.EnableCluster(clusterName, gOpt, false) + }, + } + + cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only disable specified roles") + cmd.Flags().StringSliceVarP(&gOpt.Nodes, "node", "N", nil, "Only disable specified nodes") + + return cmd +} diff --git a/components/dm/command/enable.go b/components/dm/command/enable.go new file mode 100644 index 0000000000..0a4ec5fe78 --- /dev/null +++ b/components/dm/command/enable.go @@ -0,0 +1,43 @@ +// Copyright 2021 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +package command + +import ( + "github.com/spf13/cobra" +) + +func newEnableCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "enable ", + Short: "Enable a DM cluster automatically at boot", + RunE: func(cmd *cobra.Command, args []string) error { + if len(args) != 1 { + return cmd.Help() + } + + if err := validRoles(gOpt.Roles); err != nil { + return nil + } + + clusterName := args[0] + + return cm.EnableCluster(clusterName, gOpt, true) + }, + } + + cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only enable specified roles") + cmd.Flags().StringSliceVarP(&gOpt.Nodes, "node", "N", nil, "Only enable specified nodes") + + return cmd +} diff --git a/components/dm/command/root.go b/components/dm/command/root.go index 2b5c031c4d..bc935c672e 100644 --- a/components/dm/command/root.go +++ b/components/dm/command/root.go @@ -141,6 +141,8 @@ please backup your data before process.`, newScaleOutCmd(), newScaleInCmd(), newImportCmd(), + newEnableCmd(), + newDisableCmd(), ) } From f6b1ba06afa3972e1d6458499e8667661a23260b Mon Sep 17 00:00:00 2001 From: 9547 Date: Sun, 31 Jan 2021 00:05:12 +0800 Subject: [PATCH 4/5] feat(dm): auto enable scale-out components --- components/dm/command/scale_out.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/dm/command/scale_out.go b/components/dm/command/scale_out.go index 18d8b0a400..6fb233e74a 100644 --- a/components/dm/command/scale_out.go +++ b/components/dm/command/scale_out.go @@ -18,6 +18,8 @@ import ( "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" ) @@ -43,7 +45,7 @@ func newScaleOutCmd() *cobra.Command { clusterName := args[0] topoFile := args[1] - return cm.ScaleOut(clusterName, topoFile, nil, nil, opt, skipConfirm, gOpt) + return cm.ScaleOut(clusterName, topoFile, postScaleOutHook, nil, opt, skipConfirm, gOpt) }, } @@ -53,3 +55,7 @@ func newScaleOutCmd() *cobra.Command { return cmd } + +func postScaleOutHook(builder *task.Builder, newPart spec.Topology) { + postDeployHook(builder, newPart) +} From 511183343fc8681e5a9e8b26c2135db057653258 Mon Sep 17 00:00:00 2001 From: 9547 Date: Sun, 31 Jan 2021 00:27:34 +0800 Subject: [PATCH 5/5] feat(tests/dm): add testcase for enable/disable --- tests/tiup-dm/test_cmd.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/tiup-dm/test_cmd.sh b/tests/tiup-dm/test_cmd.sh index 4912ea2da7..21ad4c8b66 100755 --- a/tests/tiup-dm/test_cmd.sh +++ b/tests/tiup-dm/test_cmd.sh @@ -43,6 +43,18 @@ tiup-dm --yes start $name tiup-dm exec $name -N $ipprefix.102 --command "grep /home/tidb/deploy/dm-master-8261/data /home/tidb/deploy/dm-master-8261/scripts/run_dm-master.sh" tiup-dm exec $name -N $ipprefix.103 --command "grep /home/tidb/my_master_data /home/tidb/deploy/dm-master-8261/scripts/run_dm-master.sh" +# check the service enabled +tiup-dm exec $name -N $ipprefix.102 --command "systemctl status dm-master-8261 | grep 'enabled;'" +tiup-dm exec $name -N $ipprefix.102 --command "systemctl status dm-worker-8262 | grep 'enabled;'" + +# check enable/disable service +tiup-dm disable $name -R dm-master +tiup-dm exec $name -N $ipprefix.102 --command "systemctl status dm-master-8261 | grep 'disabled;'" +tiup-dm exec $name -N $ipprefix.102 --command "systemctl status dm-worker-8262 | grep 'enabled;'" +tiup-dm enable $name -R dm-master +tiup-dm exec $name -N $ipprefix.102 --command "systemctl status dm-master-8261 | grep 'enabled;'" +tiup-dm exec $name -N $ipprefix.102 --command "systemctl status dm-worker-8262 | grep 'enabled;'" + tiup-dm --yes stop $name tiup-dm --yes restart $name @@ -62,6 +74,7 @@ topo_master=./topo/full_scale_in_dm-master.yaml sed "s/__IPPREFIX__/$ipprefix/g" $topo_master.tpl > $topo_master tiup-dm --yes scale-out $name $topo_master tiup-dm exec $name -N $ipprefix.101 --command "grep -q $ipprefix.101:8261 /home/tidb/deploy/prometheus-9090/conf/prometheus.yml" +tiup-dm exec $name -N $ipprefix.101 --command "systemctl status dm-master-8261 | grep 'enabled;'" echo "start scale in dm-worker" yes | tiup-dm scale-in $name -N $ipprefix.102:8262 @@ -74,6 +87,7 @@ topo_worker=./topo/full_scale_in_dm-worker.yaml sed "s/__IPPREFIX__/$ipprefix/g" $topo_worker.tpl > $topo_worker yes | tiup-dm scale-out $name $topo_worker tiup-dm exec $name -N $ipprefix.101 --command "grep -q $ipprefix.102:8262 /home/tidb/deploy/prometheus-9090/conf/prometheus.yml" +tiup-dm exec $name -N $ipprefix.101 --command "systemctl status dm-worker-8262 | grep 'enabled;'" echo "start scale in grafana" yes | tiup-dm scale-in $name -N $ipprefix.101:3000