Skip to content

Commit

Permalink
Change install tool to copy tool
Browse files Browse the repository at this point in the history
Signed-off-by: 0fatal <[email protected]>
  • Loading branch information
0fatal committed Dec 25, 2023
1 parent 0a65671 commit 76b591d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 37 deletions.
4 changes: 2 additions & 2 deletions cli/command/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ package command

import (
"fmt"
copycmd "github.com/opencurve/curveadm/cli/command/copy"

"github.com/opencurve/curveadm/cli/cli"
"github.com/opencurve/curveadm/cli/command/client"
"github.com/opencurve/curveadm/cli/command/cluster"
"github.com/opencurve/curveadm/cli/command/config"
"github.com/opencurve/curveadm/cli/command/hosts"
"github.com/opencurve/curveadm/cli/command/install"
"github.com/opencurve/curveadm/cli/command/monitor"
"github.com/opencurve/curveadm/cli/command/pfs"
"github.com/opencurve/curveadm/cli/command/playground"
Expand Down Expand Up @@ -67,7 +67,7 @@ func addSubCommands(cmd *cobra.Command, curveadm *cli.CurveAdm) {
target.NewTargetCommand(curveadm), // curveadm target ...
pfs.NewPFSCommand(curveadm), // curveadm pfs ...
monitor.NewMonitorCommand(curveadm), // curveadm monitor ...
install.NewInstallCommand(curveadm), // curveadm install ...
copycmd.NewCopyCommand(curveadm), // curveadm copy ...

NewAuditCommand(curveadm), // curveadm audit
NewCleanCommand(curveadm), // curveadm clean
Expand Down
12 changes: 6 additions & 6 deletions cli/command/install/cmd.go → cli/command/copy/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@

/*
* Project: CurveAdm
* Created Date: 2023-12-21
* Created Date: 2023-12-25
* Author: Xinyu Zhuo (0fatal)
*/

package install
package copy

import (
"github.com/opencurve/curveadm/cli/cli"
cliutil "github.com/opencurve/curveadm/internal/utils"
"github.com/spf13/cobra"
)

func NewInstallCommand(curveadm *cli.CurveAdm) *cobra.Command {
func NewCopyCommand(curveadm *cli.CurveAdm) *cobra.Command {
cmd := &cobra.Command{
Use: "install",
Short: "Manage install",
Use: "copy",
Short: "Manage copy",
Args: cliutil.NoArgs,
RunE: cliutil.ShowHelp(curveadm.Err()),
}

cmd.AddCommand(
NewInstallToolCommand(curveadm),
NewCopyTool2Command(curveadm),
)
return cmd
}
36 changes: 18 additions & 18 deletions cli/command/install/tool.go → cli/command/copy/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

/*
* Project: CurveAdm
* Created Date: 2023-12-21
* Created Date: 2023-12-25
* Author: Xinyu Zhuo (0fatal)
*/

package install
package copy

import (
"github.com/fatih/color"
Expand All @@ -34,68 +34,68 @@ import (
)

var (
INSTALL_TOOL_PLAYBOOK_STEPS = []int{
playbook.INSTALL_TOOL,
COPY_TOOL_PLAYBOOK_STEPS = []int{
playbook.COPY_TOOL,
}
)

type installOptions struct {
type copyOptions struct {
host string
path string
confPath string
}

func NewInstallToolCommand(curveadm *cli.CurveAdm) *cobra.Command {
var options installOptions
func NewCopyTool2Command(curveadm *cli.CurveAdm) *cobra.Command {
var options copyOptions

cmd := &cobra.Command{
Use: "tool [OPTIONS]",
Short: "Install tool v2 on the specified host",
Short: "Copy tool v2 on the specified host",
Args: cliutil.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runInstallTool(curveadm, options)
return runCopyTool(curveadm, options)
},
DisableFlagsInUseLine: true,
}

flags := cmd.Flags()
flags.StringVar(&options.host, "host", "localhost", "Specify target host")
flags.StringVar(&options.path, "path", "/usr/local/bin/curve", "Specify target install path of tool v2")
flags.StringVar(&options.path, "path", "/usr/local/bin/curve", "Specify target copy path of tool v2")
flags.StringVar(&options.confPath, "confPath", "/etc/curve/curve.yaml", "Specify target config path of tool v2")

return cmd
}

func genInstallToolPlaybook(curveadm *cli.CurveAdm,
func genCopyToolPlaybook(curveadm *cli.CurveAdm,
dcs []*topology.DeployConfig,
options installOptions,
options copyOptions,
) (*playbook.Playbook, error) {
configs := curveadm.FilterDeployConfig(dcs, topology.FilterOption{Id: "*", Role: "*", Host: options.host})[:1]
if len(configs) == 0 {
return nil, errno.ERR_NO_SERVICES_MATCHED
}
steps := INSTALL_TOOL_PLAYBOOK_STEPS
steps := COPY_TOOL_PLAYBOOK_STEPS
pb := playbook.NewPlaybook(curveadm)
for _, step := range steps {
pb.AddStep(&playbook.PlaybookStep{
Type: step,
Configs: configs,
Options: map[string]interface{}{
comm.KEY_INSTALL_PATH: options.path,
comm.KEY_INSTALL_CONF_PATH: options.confPath,
comm.KEY_COPY_PATH: options.path,
comm.KEY_COPY_CONF_PATH: options.confPath,
},
})
}
return pb, nil
}

func runInstallTool(curveadm *cli.CurveAdm, options installOptions) error {
func runCopyTool(curveadm *cli.CurveAdm, options copyOptions) error {
dcs, err := curveadm.ParseTopology()
if err != nil {
return err
}

pb, err := genInstallToolPlaybook(curveadm, dcs, options)
pb, err := genCopyToolPlaybook(curveadm, dcs, options)
if err != nil {
return err
}
Expand All @@ -105,7 +105,7 @@ func runInstallTool(curveadm *cli.CurveAdm, options installOptions) error {
return err
}

curveadm.WriteOutln(color.GreenString("Install %s to %s success."),
curveadm.WriteOutln(color.GreenString("Copy %s to %s success."),
"curve tool v2", options.host)
return nil
}
6 changes: 3 additions & 3 deletions internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ const (
KEY_MONITOR_STATUS = "MONITOR_STATUS"
CLEANED_MONITOR_CONF = "-"

// install
KEY_INSTALL_PATH = "INSTALL_PATH"
KEY_INSTALL_CONF_PATH = "INSTALL_CONF_PATH"
// copy
KEY_COPY_PATH = "COPY_PATH"
KEY_COPY_CONF_PATH = "COPY_CONF_PATH"
)

// others
Expand Down
7 changes: 3 additions & 4 deletions internal/playbook/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/opencurve/curveadm/internal/task/task/checker"
comm "github.com/opencurve/curveadm/internal/task/task/common"
"github.com/opencurve/curveadm/internal/task/task/fs"
"github.com/opencurve/curveadm/internal/task/task/install"
"github.com/opencurve/curveadm/internal/task/task/monitor"
pg "github.com/opencurve/curveadm/internal/task/task/playground"
"github.com/opencurve/curveadm/internal/tasks"
Expand Down Expand Up @@ -85,7 +84,7 @@ const (
INSTALL_CLIENT
UNINSTALL_CLIENT
ATTACH_LEADER_OR_RANDOM_CONTAINER
INSTALL_TOOL
COPY_TOOL

// bs
FORMAT_CHUNKFILE_POOL
Expand Down Expand Up @@ -252,8 +251,8 @@ func (p *Playbook) createTasks(step *PlaybookStep) (*tasks.Tasks, error) {
t, err = comm.NewInstallClientTask(curveadm, config.GetCC(i))
case UNINSTALL_CLIENT:
t, err = comm.NewUninstallClientTask(curveadm, nil)
case INSTALL_TOOL:
t, err = install.NewInstallToolTask(curveadm, config.GetDC(i))
case COPY_TOOL:
t, err = comm.NewCopyToolTask(curveadm, config.GetDC(i))
// bs
case FORMAT_CHUNKFILE_POOL:
t, err = bs.NewFormatChunkfilePoolTask(curveadm, config.GetFC(i))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Author: Xinyu Zhuo (0fatal)
*/

package install
package common

import (
"fmt"
Expand Down Expand Up @@ -51,10 +51,10 @@ func checkPathExist(path string, sshConfig *module.SSHConfig, curveadm *cli.Curv
return nil
}

func NewInstallToolTask(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (*task.Task, error) {
func NewCopyToolTask(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (*task.Task, error) {
layout := dc.GetProjectLayout()
path := curveadm.MemStorage().Get(comm.KEY_INSTALL_PATH).(string)
confPath := curveadm.MemStorage().Get(comm.KEY_INSTALL_CONF_PATH).(string)
path := curveadm.MemStorage().Get(comm.KEY_COPY_PATH).(string)
confPath := curveadm.MemStorage().Get(comm.KEY_COPY_CONF_PATH).(string)
hc, err := curveadm.GetHost(dc.GetHost())
if err != nil {
return nil, err
Expand Down

0 comments on commit 76b591d

Please sign in to comment.