Skip to content

Commit

Permalink
Merge branch 'enhanced-checkpoint' of https://github.com/lucklove/tiup
Browse files Browse the repository at this point in the history
…into enhanced-checkpoint
  • Loading branch information
lucklove committed Feb 26, 2021
2 parents f96e2ca + 73b651d commit e469a5b
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 0 deletions.
1 change: 1 addition & 0 deletions components/cluster/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func init() {
newTestCmd(), // hidden command for test internally
newTelemetryCmd(),
newReplayCmd(),
newTemplateCmd(),
)
}

Expand Down
64 changes: 64 additions & 0 deletions components/cluster/command/template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// 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 (
"fmt"
"path"

"github.com/pingcap/errors"
"github.com/pingcap/tiup/embed"
"github.com/spf13/cobra"
)

// TemplateOptions contains the options for print topology template.
type TemplateOptions struct {
Full bool // print full template
MultiDC bool // print template for deploying to multiple data center
}

func newTemplateCmd() *cobra.Command {
opt := TemplateOptions{}

cmd := &cobra.Command{
Use: "template",
Short: "Print topology template",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
if opt.Full && opt.MultiDC {
return errors.New("at most one of 'full' and 'multi-dc' can be specified")
}
name := "minimal.yaml"
if opt.Full {
name = "topology.example.yaml"
} else if opt.MultiDC {
name = "multi-dc.yaml"
}

fp := path.Join("templates", "examples", name)
tpl, err := embed.ReadFile(fp)
if err != nil {
return err
}

fmt.Println(string(tpl))
return nil
},
}

cmd.Flags().BoolVar(&opt.Full, "full", false, "Print the full topology template for TiDB cluster.")
cmd.Flags().BoolVar(&opt.MultiDC, "multi-dc", false, "Print template for deploying to multiple data center.")

return cmd
}
1 change: 1 addition & 0 deletions components/dm/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ please backup your data before process.`,
newEnableCmd(),
newDisableCmd(),
newReplayCmd(),
newTemplateCmd(),
)
}

Expand Down
56 changes: 56 additions & 0 deletions components/dm/command/template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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 (
"fmt"
"path"

"github.com/pingcap/tiup/embed"
"github.com/spf13/cobra"
)

// TemplateOptions contains the options for print topology template.
type TemplateOptions struct {
Full bool // print full template
}

func newTemplateCmd() *cobra.Command {
opt := TemplateOptions{}

cmd := &cobra.Command{
Use: "template",
Short: "Print topology template",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
name := "minimal.yaml"
if opt.Full {
name = "topology.example.yaml"
}

fp := path.Join("templates", "examples", "dm", name)
tpl, err := embed.ReadFile(fp)
if err != nil {
return err
}

fmt.Println(string(tpl))
return nil
},
}

cmd.Flags().BoolVar(&opt.Full, "full", false, "Print the full topology template for DM cluster.")

return cmd
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions examples

0 comments on commit e469a5b

Please sign in to comment.