-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathdc_get.go
More file actions
344 lines (303 loc) · 12.5 KB
/
Copy pathdc_get.go
File metadata and controls
344 lines (303 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/*
* Copyright (c) 2021 NetEase 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Project: CurveAdm
* Created Date: 2021-12-23
* Author: Jingli Chen (Wine93)
*/
// __SIGN_BY_WINE93__
package topology
import (
"fmt"
"path"
"github.com/opencurve/curveadm/internal/utils"
"github.com/opencurve/curveadm/pkg/variable"
)
const (
// service project layout
LAYOUT_CURVEFS_ROOT_DIR = "/curvefs"
LAYOUT_CURVEBS_ROOT_DIR = "/curvebs"
LAYOUT_PLAYGROUND_ROOT_DIR = "playground"
LAYOUT_CONF_SRC_DIR = "/conf"
LAYOUT_SERVICE_BIN_DIR = "/sbin"
LAYOUT_SERVICE_CONF_DIR = "/conf"
LAYOUT_SERVICE_LOG_DIR = "/logs"
LAYOUT_SERVICE_DATA_DIR = "/data"
LAYOUT_SERVICE_WAL_DIR = "/wal"
LAYOUT_TOOLS_DIR = "/tools"
LAYOUT_TOOLS_V2_DIR = "/tools-v2"
LAYOUT_CURVEBS_CHUNKFILE_POOL_DIR = "chunkfilepool"
LAYOUT_CURVEBS_COPYSETS_DIR = "copysets"
LAYOUT_CURVEBS_RECYCLER_DIR = "recycler"
LAYOUT_CURVEBS_TOOLS_CONFIG_SYSTEM_PATH = "/etc/curve/tools.conf"
LAYOUT_CURVEFS_TOOLS_CONFIG_SYSTEM_PATH = "/etc/curvefs/tools.conf"
LAYOUT_CURVE_TOOLSV2_CONFIG_SYSTEM_PATH = "/etc/curve/curve.yaml"
LAYOUT_CORE_SYSTEM_DIR = "/core"
BINARY_CURVEBS_TOOL = "curvebs-tool"
BINARY_CURVEBS_FORMAT = "curve_format"
BINARY_CURVEFS_TOOL = "curvefs_tool"
BINARY_CURVE_TOOL_V2 = "curve"
METAFILE_CHUNKFILE_POOL = "chunkfilepool.meta"
METAFILE_CHUNKSERVER_ID = "chunkserver.dat"
)
var (
DefaultCurveBSDeployConfig = &DeployConfig{kind: KIND_CURVEBS}
DefaultCurveFSDeployConfig = &DeployConfig{kind: KIND_CURVEFS}
ServiceConfigs = map[string][]string{
ROLE_ETCD: []string{"etcd.conf"},
ROLE_MDS: []string{"mds.conf"},
ROLE_CHUNKSERVER: []string{"chunkserver.conf", "cs_client.conf", "s3.conf"},
ROLE_SNAPSHOTCLONE: []string{"snapshotclone.conf", "snap_client.conf", "s3.conf", "nginx.conf"},
ROLE_METASERVER: []string{"metaserver.conf"},
}
)
func (dc *DeployConfig) get(i *item) interface{} {
if v, ok := dc.config[i.key]; ok {
return v
}
defaultValue := i.defaultValue
if defaultValue != nil && utils.IsFunc(defaultValue) {
return defaultValue.(func(*DeployConfig) interface{})(dc)
}
return defaultValue
}
func (dc *DeployConfig) getString(i *item) string {
v := dc.get(i)
if v == nil {
return ""
}
return v.(string)
}
func (dc *DeployConfig) getInt(i *item) int {
v := dc.get(i)
if v == nil {
return 0
}
return v.(int)
}
func (dc *DeployConfig) getBool(i *item) bool {
v := dc.get(i)
if v == nil {
return false
}
return v.(bool)
}
// (1): config property
func (dc *DeployConfig) GetKind() string { return dc.kind }
func (dc *DeployConfig) GetId() string { return dc.id }
func (dc *DeployConfig) GetParentId() string { return dc.parentId }
func (dc *DeployConfig) GetRole() string { return dc.role }
func (dc *DeployConfig) GetHost() string { return dc.host }
func (dc *DeployConfig) GetHostname() string { return dc.hostname }
func (dc *DeployConfig) GetName() string { return dc.name }
func (dc *DeployConfig) GetReplicas() int { return dc.replicas }
func (dc *DeployConfig) GetHostSequence() int { return dc.hostSequence }
func (dc *DeployConfig) GetReplicasSequence() int { return dc.replicasSequence }
func (dc *DeployConfig) GetServiceConfig() map[string]string { return dc.serviceConfig }
func (dc *DeployConfig) GetVariables() *variable.Variables { return dc.variables }
// (2): config item
func (dc *DeployConfig) GetPrefix() string { return dc.getString(CONFIG_PREFIX) }
func (dc *DeployConfig) GetReportUsage() bool { return dc.getBool(CONFIG_REPORT_USAGE) }
func (dc *DeployConfig) GetContainerImage() string {
return dc.getString(CONFIG_GLOBAL_CONTAINER_IMAGE)
}
func (dc *DeployConfig) GetLogDir() string { return dc.getString(CONFIG_LOG_DIR) }
func (dc *DeployConfig) GetDataDir() string { return dc.getString(CONFIG_DATA_DIR) }
func (dc *DeployConfig) GetWalDir() string { return dc.getString(CONFIG_WAL_DIR) }
func (dc *DeployConfig) GetCoreDir() string { return dc.getString(CONFIG_CORE_DIR) }
func (dc *DeployConfig) GetListenIp() string { return dc.getString(CONFIG_LISTEN_IP) }
func (dc *DeployConfig) GetListenPort() int { return dc.getInt(CONFIG_LISTEN_PORT) }
func (dc *DeployConfig) GetListenClientPort() int { return dc.getInt(CONFIG_LISTEN_CLIENT_PORT) }
func (dc *DeployConfig) GetListenDummyPort() int { return dc.getInt(CONFIG_LISTEN_DUMMY_PORT) }
func (dc *DeployConfig) GetListenProxyPort() int { return dc.getInt(CONFIG_LISTEN_PROXY_PORT) }
func (dc *DeployConfig) GetListenExternalIp() string { return dc.getString(CONFIG_LISTEN_EXTERNAL_IP) }
func (dc *DeployConfig) GetCopysets() int { return dc.getInt(CONFIG_COPYSETS) }
func (dc *DeployConfig) GetS3AccessKey() string { return dc.getString(CONFIG_S3_ACCESS_KEY) }
func (dc *DeployConfig) GetS3SecretKey() string { return dc.getString(CONFIG_S3_SECRET_KEY) }
func (dc *DeployConfig) GetS3Address() string { return dc.getString(CONFIG_S3_ADDRESS) }
func (dc *DeployConfig) GetS3BucketName() string { return dc.getString(CONFIG_S3_BUCKET_NAME) }
func (dc *DeployConfig) GetEnableRDMA() bool { return dc.getBool(CONFIG_ENABLE_RDMA) }
func (dc *DeployConfig) GetEnableRenameAt2() bool { return dc.getBool(CONFIG_ENABLE_RENAMEAT2) }
func (dc *DeployConfig) GetEnableChunkfilePool() bool {
return dc.getBool(CONFIG_ENABLE_CHUNKFILE_POOL)
}
func (dc *DeployConfig) GetEnableExternalServer() bool {
return dc.getBool(CONFIG_ENABLE_EXTERNAL_SERVER)
}
func (dc *DeployConfig) GetListenExternalPort() int {
if dc.GetEnableExternalServer() {
return dc.getInt(CONFIG_LISTEN_EXTERNAL_PORT)
}
return dc.GetListenPort()
}
// (3): service project layout
/* /curvebs
* ├── conf
* │ ├── chunkserver.conf
* │ ├── etcd.conf
* │ ├── mds.conf
* │ └── tools.conf
* ├── etcd
* │ ├── conf
* │ ├── data
* │ ├── log
* │ └── sbin
* ├── mds
* │ ├── conf
* │ ├── data
* │ ├── log
* │ └── sbin
* ├── chunkserver
* │ ├── conf
* │ ├── data
* │ ├── log
* │ ├── sbin
* │ └── wal
* ├── snapshotclone
* │ ├── conf
* │ ├── data
* │ ├── log
* │ └── sbin
* └── tools
* ├── conf
* ├── data
* ├── log
* └── sbin
*/
type (
ConfFile struct {
Name string
Path string
SourcePath string
}
Layout struct {
// project: curvebs/curvefs
ProjectRootDir string // /curvebs
PlaygroundRootDir string // /curvebs/playground
// service
ServiceRootDir string // /curvebs/mds
ServiceBinDir string // /curvebs/mds/sbin
ServiceConfDir string // /curvebs/mds/conf
ServiceLogDir string // /curvebs/mds/logs
ServiceDataDir string // /curvebs/mds/data
ServiceWalDir string // /curvebs/chunkserver/wal
ServiceConfPath string // /curvebs/mds/conf/mds.conf
ServiceConfSrcPath string // /curvebs/conf/mds.conf
ServiceConfFiles []ConfFile
// tools
ToolsRootDir string // /curvebs/tools
ToolsBinDir string // /curvebs/tools/sbin
ToolsDataDir string // /curvebs/tools/data
ToolsConfDir string // /curvebs/tools/conf
ToolsConfPath string // /curvebs/tools/conf/tools.conf
ToolsConfSrcPath string // /curvebs/conf/tools.conf
ToolsConfSystemPath string // /etc/curve/tools.conf
ToolsBinaryPath string // /curvebs/tools/sbin/curvebs-tool
// toolsv2
ToolsV2ConfSrcPath string // /curvebs/conf/curve.yaml
ToolsV2ConfSystemPath string // /etc/curve/curve.yaml
ToolsV2BinaryPath string // /curvebs/tools-v2/sbin/curve
// format
FormatBinaryPath string // /curvebs/tools/sbin/curve_format
ChunkfilePoolRootDir string // /curvebs/chunkserver/data
ChunkfilePoolDir string // /curvebs/chunkserver/data/chunkfilepool
ChunkfilePoolMetaPath string // /curvebs/chunkserver/data/chunkfilepool.meta
WalfilePoolRootDir string // /curvebs/chunkserver/wal
WalfilePoolDir string // /curvebs/chunkserver/wal/walfilepool
WalfilePoolMetaPath string // /curvebs/chunkserver/wal/walfilepool.meta
// core
CoreSystemDir string
}
)
func (dc *DeployConfig) GetProjectLayout() Layout {
kind := dc.GetKind()
role := dc.GetRole()
// project
root := utils.Choose(kind == KIND_CURVEBS, LAYOUT_CURVEBS_ROOT_DIR, LAYOUT_CURVEFS_ROOT_DIR)
// service
confSrcDir := root + LAYOUT_CONF_SRC_DIR
serviceRootDir := dc.GetPrefix()
serviceConfDir := fmt.Sprintf("%s/conf", serviceRootDir)
serviceConfFiles := []ConfFile{}
for _, item := range ServiceConfigs[role] {
serviceConfFiles = append(serviceConfFiles, ConfFile{
Name: item,
Path: fmt.Sprintf("%s/%s", serviceConfDir, item),
SourcePath: fmt.Sprintf("%s/%s", confSrcDir, item),
})
}
// tools
toolsRootDir := root + LAYOUT_TOOLS_DIR
toolsBinDir := toolsRootDir + LAYOUT_SERVICE_BIN_DIR
toolsConfDir := toolsRootDir + LAYOUT_SERVICE_CONF_DIR
toolsBinaryName := utils.Choose(kind == KIND_CURVEBS, BINARY_CURVEBS_TOOL, BINARY_CURVEFS_TOOL)
toolsConfSystemPath := utils.Choose(kind == KIND_CURVEBS,
LAYOUT_CURVEBS_TOOLS_CONFIG_SYSTEM_PATH,
LAYOUT_CURVEFS_TOOLS_CONFIG_SYSTEM_PATH)
// tools-v2
toolsV2RootDir := root + LAYOUT_TOOLS_V2_DIR
toolsV2BinDir := toolsV2RootDir + LAYOUT_SERVICE_BIN_DIR
toolsV2BinaryName := BINARY_CURVE_TOOL_V2
toolsV2ConfSystemPath := LAYOUT_CURVE_TOOLSV2_CONFIG_SYSTEM_PATH
// format
chunkserverDataDir := fmt.Sprintf("%s/%s%s", root, ROLE_CHUNKSERVER, LAYOUT_SERVICE_DATA_DIR)
return Layout{
// project
ProjectRootDir: root,
// playground
PlaygroundRootDir: path.Join(root, LAYOUT_PLAYGROUND_ROOT_DIR),
// service
ServiceRootDir: serviceRootDir,
ServiceBinDir: serviceRootDir + LAYOUT_SERVICE_BIN_DIR,
ServiceConfDir: serviceRootDir + LAYOUT_SERVICE_CONF_DIR,
ServiceLogDir: serviceRootDir + LAYOUT_SERVICE_LOG_DIR,
ServiceDataDir: serviceRootDir + LAYOUT_SERVICE_DATA_DIR,
ServiceWalDir: serviceRootDir + LAYOUT_SERVICE_WAL_DIR,
ServiceConfPath: fmt.Sprintf("%s/%s.conf", serviceConfDir, role),
ServiceConfSrcPath: fmt.Sprintf("%s/%s.conf", confSrcDir, role),
ServiceConfFiles: serviceConfFiles,
// tools
ToolsRootDir: toolsRootDir,
ToolsBinDir: toolsRootDir + LAYOUT_SERVICE_BIN_DIR,
ToolsDataDir: toolsRootDir + LAYOUT_SERVICE_DATA_DIR,
ToolsConfDir: toolsRootDir + LAYOUT_SERVICE_CONF_DIR,
ToolsConfPath: fmt.Sprintf("%s/tools.conf", toolsConfDir),
ToolsConfSrcPath: fmt.Sprintf("%s/tools.conf", confSrcDir),
ToolsConfSystemPath: toolsConfSystemPath,
ToolsBinaryPath: fmt.Sprintf("%s/%s", toolsBinDir, toolsBinaryName),
// toolsv2
ToolsV2ConfSrcPath: fmt.Sprintf("%s/curve.yaml", confSrcDir),
ToolsV2ConfSystemPath: toolsV2ConfSystemPath,
ToolsV2BinaryPath: fmt.Sprintf("%s/%s", toolsV2BinDir, toolsV2BinaryName),
// format
FormatBinaryPath: fmt.Sprintf("%s/%s", toolsBinDir, BINARY_CURVEBS_FORMAT),
ChunkfilePoolRootDir: chunkserverDataDir,
ChunkfilePoolDir: fmt.Sprintf("%s/%s", chunkserverDataDir, LAYOUT_CURVEBS_CHUNKFILE_POOL_DIR),
ChunkfilePoolMetaPath: fmt.Sprintf("%s/%s", chunkserverDataDir, METAFILE_CHUNKFILE_POOL),
// core
CoreSystemDir: LAYOUT_CORE_SYSTEM_DIR,
}
}
func GetProjectLayout(kind, role string) Layout {
dc := DeployConfig{kind: kind, role: role}
return dc.GetProjectLayout()
}
func GetCurveBSProjectLayout() Layout {
return DefaultCurveBSDeployConfig.GetProjectLayout()
}
func GetCurveFSProjectLayout() Layout {
return DefaultCurveFSDeployConfig.GetProjectLayout()
}