Skip to content

Commit

Permalink
Remove unused code and reuse functions
Browse files Browse the repository at this point in the history
  • Loading branch information
0fatal committed Nov 24, 2023
1 parent 4fa3c91 commit 24dbca0
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 80 deletions.
9 changes: 2 additions & 7 deletions cli/command/install/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,13 @@ func genInstallToolPlaybook(curveadm *cli.CurveAdm,
dcs []*topology.DeployConfig,
options installOptions,
) (*playbook.Playbook, error) {
dcs = curveadm.FilterDeployConfig(dcs, topology.FilterOption{
Id: "*",
Role: "*",
Host: options.host,
})

configs := curveadm.FilterDeployConfigByRole(dcs, topology.ROLE_MDS)[:1]
steps := INSTALL_TOOL_PLAYBOOK_STEPS
pb := playbook.NewPlaybook(curveadm)
for _, step := range steps {
pb.AddStep(&playbook.PlaybookStep{
Type: step,
Configs: dcs,
Configs: configs,
Options: map[string]interface{}{
comm.KEY_CLIENT_HOST: options.host,
},
Expand Down
1 change: 0 additions & 1 deletion internal/errno/errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@ var (
ERR_INSTALL_OR_REMOVE_DEBIAN_PACKAGE_FAILED = EC(620024, "install or remove debian package failed (dpkg)")
ERR_INSTALL_OR_REMOVE_RPM_PACKAGE_FAILED = EC(620025, "install or remove rpm package failed (rpm)")
ERR_SECURE_COPY_FILE_TO_REMOTE_FAILED = EC(620026, "secure copy file to remote failed (scp)")
ERR_CHMOD_FILE_FAILED = EC(620027, "chmod file failed (chmod)")
ERR_RUN_SCRIPT_FAILED = EC(620998, "run script failed (bash script.sh)")
ERR_RUN_A_BASH_COMMAND_FAILED = EC(620999, "run a bash command failed (bash -c)")

Expand Down
3 changes: 1 addition & 2 deletions internal/playbook/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ func (p *Playbook) createTasks(step *PlaybookStep) (*tasks.Tasks, error) {
switch step.Type {
case CHECK_SSH_CONNECT,
GET_HOST_DATE,
PULL_IMAGE,
INSTALL_TOOL:
PULL_IMAGE:
host := config.GetDC(i).GetHost()
if once[host] {
continue
Expand Down
16 changes: 0 additions & 16 deletions internal/task/step/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ type (
module.ExecOptions
}

ExtractFile struct {
HostDestPath string
ContainerId string
ContainerSrcPath string
module.ExecOptions
}

InstallFile struct {
Content *string
HostDestPath string
Expand Down Expand Up @@ -159,15 +152,6 @@ func (s *ReadFile) Execute(ctx *context.Context) error {
return nil
}

func (s *ExtractFile) Execute(ctx *context.Context) error {
dockerCli := ctx.Module().DockerCli().CopyFromContainer(s.ContainerId, s.ContainerSrcPath, s.HostDestPath)
_, err := dockerCli.Execute(s.ExecOptions)
if err != nil {
return errno.ERR_COPY_FROM_CONTAINER_FAILED.FD("(%s cp CONTAINER:SRC_PATH DEST_PATH)", s.ExecWithEngine).E(err)
}
return nil
}

func (s *InstallFile) Execute(ctx *context.Context) error {
localPath := utils.RandFilename(TEMP_DIR)
defer os.Remove(localPath)
Expand Down
36 changes: 0 additions & 36 deletions internal/task/step/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,6 @@ type (
module.ExecOptions
}

MoveFile struct {
Source string
Dest string
NoClobber bool // do not overwrite an existing file
Out *string
module.ExecOptions
}

Chmod struct {
Mode string
File string
Recursive bool
Out *string
module.ExecOptions
}

Stat struct {
Files []string
Format string
Expand Down Expand Up @@ -340,26 +324,6 @@ func (s *CopyFile) Execute(ctx *context.Context) error {
return PostHandle(nil, s.Out, out, err, errno.ERR_COPY_FILES_AND_DIRECTORIES_FAILED)
}

func (s *MoveFile) Execute(ctx *context.Context) error {
cmd := ctx.Module().Shell().Rename(s.Source, s.Dest)
if s.NoClobber {
cmd.AddOption("--no-clobber")
}

out, err := cmd.Execute(s.ExecOptions)
return PostHandle(nil, s.Out, out, err, errno.ERR_RENAME_FILE_OR_DIRECTORY_FAILED)
}

func (s *Chmod) Execute(ctx *context.Context) error {
cmd := ctx.Module().Shell().Chmod(s.Mode, s.File)
if s.Recursive {
cmd.AddOption("--recursive")
}

out, err := cmd.Execute(s.ExecOptions)
return PostHandle(nil, s.Out, out, err, errno.ERR_CHMOD_FILE_FAILED)
}

func (s *Stat) Execute(ctx *context.Context) error {
cmd := ctx.Module().Shell().Stat(s.Files...)
if len(s.Format) > 0 {
Expand Down
24 changes: 6 additions & 18 deletions internal/task/task/install/install_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,22 @@ func NewInstallToolTask(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (*tas
subname := fmt.Sprintf("host=%s", host)
t := task.NewTask("Install tool v2", subname, hc.GetSSHConfig())

var confContent string

t.AddStep(&step.ExtractFile{
t.AddStep(&step.CopyFromContainer{
ContainerSrcPath: layout.ToolsV2BinaryPath,
ContainerId: containerId,
HostDestPath: "/usr/bin/curve",
HostDestPath: "/usr/local/bin/curve",
ExecOptions: curveadm.ExecOptions(),
})
t.AddStep(&step.Chmod{
Mode: "+x",
File: "/usr/bin/curve",
t.AddStep(&step.CreateDirectory{
Paths: []string{"~/.curve"},
ExecOptions: curveadm.ExecOptions(),
})
t.AddStep(&step.ReadFile{
t.AddStep(&step.CopyFromContainer{
ContainerSrcPath: layout.ToolsV2ConfSystemPath,
ContainerId: containerId,
Content: &confContent,
HostDestPath: "~/.curve/curve.yaml",
ExecOptions: curveadm.ExecOptions(),
})
t.AddStep(&step.CreateDirectory{
Paths: []string{"~/.curve"},
ExecOptions: curveadm.ExecOptions(),
})
t.AddStep(&step.InstallFile{
Content: &confContent,
HostDestPath: "~/.curve/curve.yaml",
ExecOptions: curveadm.ExecOptions(),
})

return t, nil
}

0 comments on commit 24dbca0

Please sign in to comment.