Skip to content

Commit

Permalink
Copy the binary and conf of toolv2 from container to host
Browse files Browse the repository at this point in the history
  • Loading branch information
0fatal committed Nov 8, 2023
1 parent 5551f71 commit 34b3519
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 101 deletions.
7 changes: 0 additions & 7 deletions internal/playbook/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ func (c *SmartConfig) GetDC(index int) *topology.DeployConfig {
return c.dcs[index]
}

func (c *SmartConfig) GetDCS() []*topology.DeployConfig {
if c.ctype != TYPE_CONFIG_DEPLOY {
return nil
}
return c.dcs
}

func (c *SmartConfig) GetCC(index int) *configure.ClientConfig {
if index < 0 || index >= c.len || c.ctype != TYPE_CONFIG_CLIENT {
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/playbook/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (p *Playbook) createTasks(step *PlaybookStep) (*tasks.Tasks, error) {
case UNINSTALL_CLIENT:
t, err = comm.NewUninstallClientTask(curveadm, nil)
case INSTALL_TOOL:
t, err = install.NewInstallToolTask(curveadm, config.GetDCS())
t, err = install.NewInstallToolTask(curveadm, config.GetDC(i))
// bs
case FORMAT_CHUNKFILE_POOL:
t, err = bs.NewFormatChunkfilePoolTask(curveadm, config.GetFC(i))
Expand Down
16 changes: 16 additions & 0 deletions internal/task/step/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ type (
module.ExecOptions
}

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

InstallFile struct {
Content *string
HostDestPath string
Expand Down Expand Up @@ -152,6 +159,15 @@ 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
116 changes: 23 additions & 93 deletions internal/task/task/install/install_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,116 +7,46 @@ import (
"github.com/opencurve/curveadm/internal/configure/topology"
"github.com/opencurve/curveadm/internal/task/step"
"github.com/opencurve/curveadm/internal/task/task"
"strings"
)

const (
FORMAT_TOOLSV2_CONF_BS = `
global:
httpTimeout: 500ms
rpcTimeout: 500ms
rpcRetryTimes: 1
maxChannelSize: 4
showError: false
curvebs:
mdsAddr: %s
mdsDummyAddr: %s
etcdAddr: %s
snapshotAddr: %s
snapshotDummyAddr: %s
root:
user: root
password: root_password
`
FORMAT_TOOLSV2_CONF_FS = `
global:
httpTimeout: 500ms
rpcTimeout: 500ms
rpcRetryTimes: 1
maxChannelSize: 4
showError: false
curvefs:
mdsAddr: %s
mdsDummyAddr: %s
etcdAddr: %s
s3:
ak: ak
sk: sk
endpoint: http://localhost:9000
bucketname: bucketname
blocksize: 4 mib
chunksize: 64 mib
`
)

func genToolV2Conf(dcs []*topology.DeployConfig) string {
var etcdAddr []string
var mdsAddr []string
var mdsDummyAddr []string
var snapshotCloneDummyAddr []string
var snapshotCloneProxyAddr []string

for _, dc := range dcs {
ip := dc.GetListenIp()
switch dc.GetRole() {
case topology.ROLE_ETCD:
etcdAddr = append(etcdAddr, fmt.Sprintf("%s:%d", ip, dc.GetListenClientPort()))
case topology.ROLE_MDS:
mdsAddr = append(mdsAddr, fmt.Sprintf("%s:%d", ip, dc.GetListenPort()))
mdsDummyAddr = append(mdsDummyAddr, fmt.Sprintf("%s:%d", ip, dc.GetListenDummyPort()))
case topology.ROLE_SNAPSHOTCLONE:
snapshotCloneDummyAddr = append(snapshotCloneDummyAddr, fmt.Sprintf("%s:%d", ip, dc.GetListenDummyPort()))
snapshotCloneProxyAddr = append(snapshotCloneProxyAddr, fmt.Sprintf("%s:%d", ip, dc.GetListenProxyPort()))
}
}

var toolConf string
mdsAddrStr := strings.Join(mdsAddr, ",")
mdsDummyAddrStr := strings.Join(mdsDummyAddr, ",")
etcdAddrStr := strings.Join(etcdAddr, ",")
snapshotCloneDummyAddrStr := strings.Join(snapshotCloneDummyAddr, ",")
snapshotCloneProxyAddrStr := strings.Join(snapshotCloneProxyAddr, ",")

if dcs[0].GetKind() == topology.KIND_CURVEBS {
toolConf = fmt.Sprintf(strings.TrimSpace(FORMAT_TOOLSV2_CONF_BS), mdsAddrStr, mdsDummyAddrStr, etcdAddrStr, snapshotCloneProxyAddrStr, snapshotCloneDummyAddrStr)
} else if dcs[0].GetKind() == topology.KIND_CURVEFS {
toolConf = fmt.Sprintf(strings.TrimSpace(FORMAT_TOOLSV2_CONF_FS), mdsAddrStr, mdsDummyAddrStr, etcdAddrStr)
}

return toolConf
}

func NewInstallToolTask(curveadm *cli.CurveAdm, dcs []*topology.DeployConfig) (*task.Task, error) {
func NewInstallToolTask(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (*task.Task, error) {
layout := dc.GetProjectLayout()
host := curveadm.MemStorage().Get(comm.KEY_CLIENT_HOST).(string)
hc, err := curveadm.GetHost(host)
if err != nil {
return nil, err
}

serviceId := curveadm.GetServiceId(dc.GetId())
containerId, err := curveadm.GetContainerId(serviceId)
if err != nil {
return nil, err
}

subname := fmt.Sprintf("host=%s", host)
t := task.NewTask("Install tool v2", subname, hc.GetSSHConfig())

confContent := genToolV2Conf(dcs)
var confContent string

t.AddStep(&step.CreateDirectory{
Paths: []string{"~/.curve"},
ExecOptions: curveadm.ExecOptions(),
})
t.AddStep(&step.Curl{
Url: "https://curve-tool.nos-eastchina1.126.net/release/curve-latest",
Insecure: true,
Silent: true,
Output: "/tmp/curve-latest",
ExecOptions: curveadm.ExecOptions(),
t.AddStep(&step.ExtractFile{
ContainerSrcPath: layout.ToolsV2BinaryPath,
ContainerId: containerId,
HostDestPath: "/usr/bin/curve",
ExecOptions: curveadm.ExecOptions(),
})
t.AddStep(&step.Chmod{
Mode: "+x",
File: "/tmp/curve-latest",
File: "/usr/bin/curve",
ExecOptions: curveadm.ExecOptions(),
})
t.AddStep(&step.MoveFile{
Source: "/tmp/curve-latest",
Dest: "/usr/bin/curve",
t.AddStep(&step.ReadFile{
ContainerSrcPath: layout.ToolsV2ConfSystemPath,
ContainerId: containerId,
Content: &confContent,
ExecOptions: curveadm.ExecOptions(),
})
t.AddStep(&step.CreateDirectory{
Paths: []string{"~/.curve"},
ExecOptions: curveadm.ExecOptions(),
})
t.AddStep(&step.InstallFile{
Expand Down

0 comments on commit 34b3519

Please sign in to comment.