-
Notifications
You must be signed in to change notification settings - Fork 526
/
Copy pathcurve_tool_main.cpp
183 lines (165 loc) · 7.33 KB
/
curve_tool_main.cpp
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
/*
* Copyright (c) 2020 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: curve
* Created Date: 2019-07-03
* Author: hzchenwei7
*/
#include <gflags/gflags.h>
#include "src/common/curve_version.h"
#include "src/tools/curve_tool_factory.h"
const char* kHelpStr = "Usage: curve_ops_tool [Command] [OPTIONS...]\n"
"COMMANDS:\n"
"space : show curve all disk type space, include total space and used space\n" //NOLINT
"status : show the total status of the cluster\n"
"chunkserver-status : show the chunkserver online status\n"
"mds-status : show the mds status\n"
"client-status : show the client status\n"
"client-list : list all client\n"
"etcd-status : show the etcd status\n"
"snapshot-clone-status : show the snapshot clone server status\n"
"copysets-status : check the health state of all copysets\n"
"chunkserver-list : show curve chunkserver-list, list all chunkserver information\n" //NOLINT
"server-list : list all server information\n"
"logical-pool-list : list all logical pool information\n"
"cluster-status : show cluster status\n"
"get : show the file info and the actual space of file\n"
"list : list the file info of files in the directory\n"
"seginfo : list the segments info of the file\n"
"delete : delete the file, to force delete, should specify the --forcedelete=true\n" //NOLINT
"clean-recycle : clean the RecycleBin\n"
"create : create file, file length unit is GB\n"
"extend : extend volume of file\n"
"chunk-location : query the location of the chunk corresponding to the offset\n" //NOLINT
"check-consistency : check the consistency of three copies\n"
"remove-peer : remove the peer from the copyset\n"
"transfer-leader : transfer the leader of the copyset to the peer\n" //NOLINT
"reset-peer : reset the configuration of copyset, only reset to one peer is supported\n" //NOLINT
"do-snapshot : do snapshot of the peer of the copyset\n"
"do-snapshot-all : do snapshot of all peers of all copysets\n"
"check-chunkserver : check the health state of the chunkserver\n"
"check-copyset : check the health state of one copyset\n"
"check-server : check the health state of the server\n"
"check-operator : check the operators\n"
"list-may-broken-vol: list all volumes on majority offline copysets\n"
"set-copyset-availflag: set copysets available flags\n"
"update-throttle: update file throttle params\n"
"rapid-leader-schedule: rapid leader schedule in cluster in logicalpool\n" //NOLINT
"set-scan-state: set scan state for specify logical pool\n"
"scan-status: show scan status\n\n"
"You can specify the config path by -confPath to avoid typing too many options\n"; //NOLINT
DEFINE_bool(example, false, "print the example of usage");
DEFINE_string(confPath, "/etc/curve/tools.conf", "config file path of tools");
namespace brpc {
DECLARE_int32(health_check_interval);
}
namespace curve {
namespace tool {
extern std::string rootUserName;
extern std::string rootUserPassword;
} // namespace tool
} // namespace curve
void UpdateFlagsFromConf(curve::common::Configuration* conf) {
// 如果配置文件不存在的话不报错,以命令行为准,这是为了不强依赖配置
// 如果配置文件存在并且没有指定命令行的话,就以配置文件为准
google::CommandLineFlagInfo info;
if (GetCommandLineFlagInfo("mdsAddr", &info) && info.is_default) {
conf->GetStringValue("mdsAddr", &FLAGS_mdsAddr);
}
if (GetCommandLineFlagInfo("mdsDummyPort", &info) && info.is_default) {
conf->GetStringValue("mdsDummyPort", &FLAGS_mdsDummyPort);
}
if (GetCommandLineFlagInfo("etcdAddr", &info) && info.is_default) {
conf->GetStringValue("etcdAddr", &FLAGS_etcdAddr);
}
if (GetCommandLineFlagInfo("rpcTimeout", &info) && info.is_default) {
conf->GetUInt64Value("rpcTimeout", &FLAGS_rpcTimeout);
}
if (GetCommandLineFlagInfo("rpcRetryTimes", &info) && info.is_default) {
conf->GetUInt64Value("rpcRetryTimes", &FLAGS_rpcRetryTimes);
}
if (GetCommandLineFlagInfo("rpcConcurrentNum", &info) &&
info.is_default) {
conf->GetUInt64Value("rpcConcurrentNum", &FLAGS_rpcConcurrentNum);
}
if (GetCommandLineFlagInfo("snapshotCloneAddr", &info) &&
info.is_default) {
conf->GetStringValue("snapshotCloneAddr", &FLAGS_snapshotCloneAddr);
}
if (GetCommandLineFlagInfo("snapshotCloneDummyPort", &info) &&
info.is_default) {
conf->GetStringValue("snapshotCloneDummyPort",
&FLAGS_snapshotCloneDummyPort);
}
if (GetCommandLineFlagInfo("userName", &info) &&
info.is_default) {
conf->GetStringValue("rootUserName", &FLAGS_userName);
}
if (GetCommandLineFlagInfo("password", &info) &&
info.is_default) {
conf->GetStringValue("rootUserPassword", &FLAGS_password);
}
}
bool LoadRootUserNameAndPassword(curve::common::Configuration* conf) {
bool rc = conf->GetStringValue("rootUserName", &curve::tool::rootUserName);
if (!rc) {
std::cerr << "Missing rootUserName in '" << FLAGS_confPath << "'\n";
return false;
}
rc = conf->GetStringValue("rootUserPassword",
&curve::tool::rootUserPassword);
if (!rc) {
std::cerr << "Mising rootUserPassword in '" << FLAGS_confPath << "'\n";
return false;
}
return true;
}
int main(int argc, char** argv) {
google::SetUsageMessage(kHelpStr);
google::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
if (argc < 2) {
std::cout << kHelpStr << std::endl;
return -1;
}
std::string command = argv[1];
if (command == curve::tool::kVersionCmd) {
std::cout << curve::common::CurveVersion() << std::endl;
return 0;
}
std::string confPath = FLAGS_confPath.c_str();
curve::common::Configuration conf;
conf.SetConfigPath(confPath);
if (!conf.LoadConfig()) {
return -1;
}
if (!LoadRootUserNameAndPassword(&conf)) {
return -1;
}
UpdateFlagsFromConf(&conf);
// 关掉健康检查,否则Not Connect to的时候重试没有意义
brpc::FLAGS_health_check_interval = -1;
auto curveTool = curve::tool::CurveToolFactory::GenerateCurveTool(command);
if (!curveTool) {
std::cout << kHelpStr << std::endl;
return -1;
}
if (FLAGS_example) {
curveTool->PrintHelp(command);
return 0;
}
return curveTool->RunCommand(command);
}