Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/dm enable disable #1114

Merged
merged 7 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/cluster/command/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
func newDisableCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "disable <cluster-name>",
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()
Expand Down
14 changes: 13 additions & 1 deletion components/dm/command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
},
}

Expand All @@ -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)
}
43 changes: 43 additions & 0 deletions components/dm/command/disable.go
Original file line number Diff line number Diff line change
@@ -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 <cluster-name>",
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
}
43 changes: 43 additions & 0 deletions components/dm/command/enable.go
Original file line number Diff line number Diff line change
@@ -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 <cluster-name>",
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
}
2 changes: 2 additions & 0 deletions components/dm/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ please backup your data before process.`,
newScaleOutCmd(),
newScaleInCmd(),
newImportCmd(),
newEnableCmd(),
newDisableCmd(),
)
}

Expand Down
8 changes: 7 additions & 1 deletion components/dm/command/scale_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
},
}

Expand All @@ -53,3 +55,7 @@ func newScaleOutCmd() *cobra.Command {

return cmd
}

func postScaleOutHook(builder *task.Builder, newPart spec.Topology) {
postDeployHook(builder, newPart)
}
12 changes: 6 additions & 6 deletions pkg/cluster/spec/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/tiup-dm/test_cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down