Skip to content

Commit 78c415a

Browse files
committed
[feat] add toolsv2
Signed-off-by: Cyber-SiKu <[email protected]>
1 parent 397fc08 commit 78c415a

File tree

5 files changed

+164
-2
lines changed

5 files changed

+164
-2
lines changed

internal/configure/topology/dc_get.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,19 @@ const (
4343
LAYOUT_SERVICE_LOG_DIR = "/logs"
4444
LAYOUT_SERVICE_DATA_DIR = "/data"
4545
LAYOUT_TOOLS_DIR = "/tools"
46+
LAYOUT_TOOLS_V2_DIR = "/tools-v2"
4647
LAYOUT_CURVEBS_CHUNKFILE_POOL_DIR = "chunkfilepool"
4748
LAYOUT_CURVEBS_COPYSETS_DIR = "copysets"
4849
LAYOUT_CURVEBS_RECYCLER_DIR = "recycler"
4950
LAYOUT_CURVEBS_TOOLS_CONFIG_SYSTEM_PATH = "/etc/curve/tools.conf"
5051
LAYOUT_CURVEFS_TOOLS_CONFIG_SYSTEM_PATH = "/etc/curvefs/tools.conf"
52+
LAYOUT_CURVE_TOOLSV2_CONFIG_SYSTEM_PATH = "/etc/curve/curve.yaml"
5153
LAYOUT_CORE_SYSTEM_DIR = "/core"
5254

5355
BINARY_CURVEBS_TOOL = "curvebs-tool"
5456
BINARY_CURVEBS_FORMAT = "curve_format"
5557
BINARY_CURVEFS_TOOL = "curvefs_tool"
58+
BINARY_CURVE_TOOL_V2 = "curve"
5659
METAFILE_CHUNKFILE_POOL = "chunkfilepool.meta"
5760
METAFILE_CHUNKSERVER_ID = "chunkserver.dat"
5861
)
@@ -223,6 +226,11 @@ type (
223226
ToolsConfSystemPath string // /etc/curve/tools.conf
224227
ToolsBinaryPath string // /curvebs/tools/sbin/curvebs-tool
225228

229+
// toolsv2
230+
ToolsV2ConfSrcPath string // /curvebs/conf/curve.yaml
231+
ToolsV2ConfSystemPath string // /etc/curve/curve.yaml
232+
ToolsV2BinaryPath string // /curvebs/tools-v2/sbin/curve
233+
226234
// format
227235
FormatBinaryPath string // /curvebs/tools/sbin/curve_format
228236
ChunkfilePoolRootDir string // /curvebs/chunkserver/data
@@ -262,6 +270,12 @@ func (dc *DeployConfig) GetProjectLayout() Layout {
262270
LAYOUT_CURVEBS_TOOLS_CONFIG_SYSTEM_PATH,
263271
LAYOUT_CURVEFS_TOOLS_CONFIG_SYSTEM_PATH)
264272

273+
// tools-v2
274+
toolsV2RootDir := root + LAYOUT_TOOLS_V2_DIR
275+
toolsV2BinDir := toolsV2RootDir + LAYOUT_SERVICE_BIN_DIR
276+
toolsV2BinaryName := BINARY_CURVE_TOOL_V2
277+
toolsV2ConfSystemPath := LAYOUT_CURVE_TOOLSV2_CONFIG_SYSTEM_PATH
278+
265279
// format
266280
chunkserverDataDir := fmt.Sprintf("%s/%s%s", root, ROLE_CHUNKSERVER, LAYOUT_SERVICE_DATA_DIR)
267281

@@ -292,6 +306,11 @@ func (dc *DeployConfig) GetProjectLayout() Layout {
292306
ToolsConfSystemPath: toolsConfSystemPath,
293307
ToolsBinaryPath: fmt.Sprintf("%s/%s", toolsBinDir, toolsBinaryName),
294308

309+
// toolsv2
310+
ToolsV2ConfSrcPath: fmt.Sprintf("%s/curve.yaml", confSrcDir),
311+
ToolsV2ConfSystemPath: toolsV2ConfSystemPath,
312+
ToolsV2BinaryPath: fmt.Sprintf("%s/%s", toolsV2BinDir, toolsV2BinaryName),
313+
295314
// format
296315
FormatBinaryPath: fmt.Sprintf("%s/%s", toolsBinDir, BINARY_CURVEBS_FORMAT),
297316
ChunkfilePoolRootDir: chunkserverDataDir,

internal/task/step/file.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ type (
7979
module.ExecOptions
8080
}
8181

82+
TrySyncFile struct {
83+
ContainerSrcId *string
84+
ContainerSrcPath string
85+
ContainerDestId *string
86+
ContainerDestPath string
87+
KVFieldSplit string
88+
Mutate func(string, string, string) (string, error)
89+
module.ExecOptions
90+
}
91+
8292
DownloadFile struct {
8393
RemotePath string
8494
LocalPath string
@@ -244,3 +254,27 @@ func (s *SyncFile) Execute(ctx *context.Context) error {
244254
func (s *DownloadFile) Execute(ctx *context.Context) error {
245255
return ctx.Module().File().Download(s.RemotePath, s.LocalPath)
246256
}
257+
258+
func (s *TrySyncFile) Execute(ctx *context.Context) error {
259+
var input string
260+
step := &ReadFile{
261+
ContainerId: *s.ContainerSrcId,
262+
ContainerSrcPath: s.ContainerSrcPath,
263+
Content: &input,
264+
ExecOptions: s.ExecOptions,
265+
}
266+
if err := step.Execute(ctx); err != nil {
267+
// no this file
268+
return nil
269+
}
270+
sync := SyncFile{
271+
ContainerSrcId: s.ContainerSrcId,
272+
ContainerSrcPath: s.ContainerSrcPath,
273+
ContainerDestId: s.ContainerDestId,
274+
ContainerDestPath: s.ContainerDestPath,
275+
KVFieldSplit: s.KVFieldSplit,
276+
Mutate: s.Mutate,
277+
ExecOptions: s.ExecOptions,
278+
}
279+
return sync.Execute(ctx)
280+
}

internal/task/task/bs/map.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ import (
3636
"github.com/opencurve/curveadm/internal/task/task"
3737
)
3838

39+
const (
40+
TOOLSV2_CONFIG_DELIMITER = ":"
41+
TOOLSV2_CONFIG_SRC_PATH = "/curvebs/conf/curve.yaml"
42+
TOOLSV2_CONFIG_DEST_PATH = "/etc/curve/curve.yaml"
43+
)
44+
3945
type (
4046
MapOptions struct {
4147
Host string
@@ -115,6 +121,15 @@ func NewMapTask(curveadm *cli.CurveAdm, cc *configure.ClientConfig) (*task.Task,
115121
ContainerDestPath: scriptPath,
116122
ExecOptions: curveadm.ExecOptions(),
117123
})
124+
t.AddStep(&step.TrySyncFile{ // sync toolsv2 config
125+
ContainerSrcId: &containerId,
126+
ContainerSrcPath: TOOLSV2_CONFIG_SRC_PATH,
127+
ContainerDestId: &containerId,
128+
ContainerDestPath: TOOLSV2_CONFIG_DEST_PATH,
129+
KVFieldSplit: TOOLSV2_CONFIG_DELIMITER,
130+
Mutate: newToolsV2Mutate(cc, TOOLSV2_CONFIG_DELIMITER),
131+
ExecOptions: curveadm.ExecOptions(),
132+
})
118133
t.AddStep(&step.ContainerExec{
119134
ContainerId: &containerId,
120135
Command: command,
@@ -128,3 +143,26 @@ func NewMapTask(curveadm *cli.CurveAdm, cc *configure.ClientConfig) (*task.Task,
128143

129144
return t, nil
130145
}
146+
147+
func newToolsV2Mutate(cc *configure.ClientConfig, delimiter string) step.Mutate {
148+
clientConfig := cc.GetServiceConfig()
149+
tools2client := map[string]string{
150+
"mdsAddr": "mdsOpt.rpcRetryOpt.addrs",
151+
}
152+
return func(in, key, value string) (out string, err error) {
153+
if len(key) == 0 {
154+
out = in
155+
return
156+
}
157+
replaceKey := strings.TrimSpace(key)
158+
if tools2client[strings.TrimSpace(key)] != "" {
159+
replaceKey = tools2client[strings.TrimSpace(key)]
160+
}
161+
v, ok := clientConfig[strings.ToLower(replaceKey)]
162+
if ok {
163+
value = v
164+
}
165+
out = fmt.Sprintf("%s%s %s", key, delimiter, value)
166+
return
167+
}
168+
}

internal/task/task/common/sync_config.go

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ import (
3737
)
3838

3939
const (
40-
DEFAULT_CONFIG_DELIMITER = "="
41-
ETCD_CONFIG_DELIMITER = ": "
40+
DEFAULT_CONFIG_DELIMITER = "="
41+
ETCD_CONFIG_DELIMITER = ": "
42+
TOOLS_V2_CONFIG_DELIMITER = ":"
4243

4344
CURVE_CRONTAB_FILE = "/tmp/curve_crontab"
4445
)
@@ -71,6 +72,34 @@ func newMutate(dc *topology.DeployConfig, delimiter string, forceRender bool) st
7172
}
7273
}
7374

75+
func newToolV2Mutate(dc *topology.DeployConfig, delimiter string, forceRender bool) step.Mutate {
76+
serviceConfig := dc.GetServiceConfig()
77+
return func(in, key, value string) (out string, err error) {
78+
if len(key) == 0 {
79+
out = in
80+
if forceRender { // only for nginx.conf
81+
out, err = dc.GetVariables().Rendering(in)
82+
}
83+
return
84+
}
85+
86+
// replace config
87+
v, ok := serviceConfig[strings.ToLower(key)]
88+
if ok {
89+
value = v
90+
}
91+
92+
// replace variable
93+
value, err = dc.GetVariables().Rendering(value)
94+
if err != nil {
95+
return
96+
}
97+
98+
out = fmt.Sprintf("%s%s %s", key, delimiter, value)
99+
return
100+
}
101+
}
102+
74103
func newCrontab(uuid string, dc *topology.DeployConfig, reportScriptPath string) string {
75104
var period, command string
76105
if dc.GetReportUsage() == true {
@@ -146,6 +175,15 @@ func NewSyncConfigTask(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (*task
146175
Mutate: newMutate(dc, DEFAULT_CONFIG_DELIMITER, false),
147176
ExecOptions: curveadm.ExecOptions(),
148177
})
178+
t.AddStep(&step.TrySyncFile{ // sync toolsv2 config
179+
ContainerSrcId: &containerId,
180+
ContainerSrcPath: layout.ToolsV2ConfSrcPath,
181+
ContainerDestId: &containerId,
182+
ContainerDestPath: layout.ToolsV2ConfSystemPath,
183+
KVFieldSplit: TOOLS_V2_CONFIG_DELIMITER,
184+
Mutate: newToolV2Mutate(dc, TOOLS_V2_CONFIG_DELIMITER, false),
185+
ExecOptions: curveadm.ExecOptions(),
186+
})
149187
t.AddStep(&step.InstallFile{ // install report script
150188
ContainerId: &containerId,
151189
ContainerDestPath: reportScriptPath,

internal/task/task/fs/mount.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const (
4545
FORMAT_MOUNT_OPTION = "type=bind,source=%s,target=%s,bind-propagation=rshared"
4646

4747
CLIENT_CONFIG_DELIMITER = "="
48+
TOOLSV2_CONFIG_DELIMITER = ":"
4849

4950
KEY_CURVEBS_CLUSTER = "curvebs.cluster"
5051

@@ -212,6 +213,29 @@ func newToolsMutate(cc *configure.ClientConfig, delimiter string) step.Mutate {
212213
}
213214
}
214215

216+
func newToolsV2Mutate(cc *configure.ClientConfig, delimiter string) step.Mutate {
217+
clientConfig := cc.GetServiceConfig()
218+
tools2client := map[string]string{
219+
"mdsAddr": "mdsOpt.rpcRetryOpt.addrs",
220+
}
221+
return func(in, key, value string) (out string, err error) {
222+
if len(key) == 0 {
223+
out = in
224+
return
225+
}
226+
replaceKey := strings.TrimSpace(key)
227+
if tools2client[strings.TrimSpace(key)] != "" {
228+
replaceKey = tools2client[strings.TrimSpace(key)]
229+
}
230+
v, ok := clientConfig[strings.ToLower(replaceKey)]
231+
if ok {
232+
value = v
233+
}
234+
out = fmt.Sprintf("%s%s %s", key, delimiter, value)
235+
return
236+
}
237+
}
238+
215239
func mountPoint2ContainerName(mountPoint string) string {
216240
return fmt.Sprintf("curvefs-filesystem-%s", utils.MD5Sum(mountPoint))
217241
}
@@ -372,6 +396,15 @@ func NewMountFSTask(curveadm *cli.CurveAdm, cc *configure.ClientConfig) (*task.T
372396
Mutate: newToolsMutate(cc, CLIENT_CONFIG_DELIMITER),
373397
ExecOptions: curveadm.ExecOptions(),
374398
})
399+
t.AddStep(&step.TrySyncFile{ // sync toolsv2 config
400+
ContainerSrcId: &containerId,
401+
ContainerSrcPath: fmt.Sprintf("%s/conf/curve.yaml", root),
402+
ContainerDestId: &containerId,
403+
ContainerDestPath: topology.GetCurveFSProjectLayout().ToolsV2ConfSystemPath,
404+
KVFieldSplit: TOOLSV2_CONFIG_DELIMITER,
405+
Mutate: newToolsV2Mutate(cc, TOOLSV2_CONFIG_DELIMITER),
406+
ExecOptions: curveadm.ExecOptions(),
407+
})
375408
t.AddStep(&step.InstallFile{ // install client.sh shell
376409
ContainerId: &containerId,
377410
ContainerDestPath: createfsScriptPath,

0 commit comments

Comments
 (0)