Skip to content

Commit fbfcc4a

Browse files
committedOct 19, 2018
add curvefs tools
Change-Id: I5da753029b1af098848b658a60906aa24b6f5ed4
1 parent e66f855 commit fbfcc4a

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed
 

‎tools/BUILD

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cc_binary(
2+
name = "curvefsTool",
3+
srcs = ["curvefs.cpp"],
4+
deps = ["//proto:topology_cc_proto",
5+
"//external:gflags",
6+
"//src/mds/common:mds_common",
7+
"//external:glog",
8+
"//external:brpc"]
9+
)

‎tools/curvefs.cpp

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Project: curve
3+
* Created Date: Fri Oct 19 2018
4+
* Author: xuchaojie
5+
* Copyright (c) 2018 netease
6+
*/
7+
8+
#include <gflags/gflags.h>
9+
#include <glog/logging.h>
10+
#include <brpc/server.h>
11+
#include <brpc/channel.h>
12+
13+
14+
15+
#include "proto/topology.pb.h"
16+
17+
18+
DEFINE_string(op, "CreateLogicalPool", "operation.");
19+
DEFINE_string(name, "defaultLogicalPool", "logical pool name.");
20+
DEFINE_int32(physicalPoolID, 1, "physicalPool id.");
21+
DEFINE_int32(logicalPoolType,
22+
::curve::mds::topology::PAGEFILE,
23+
"logical pool type.");
24+
DEFINE_int32(copysetNum, 100, "copyset num.");
25+
26+
DEFINE_string(mds_ip, "172.0.0.1", "mds ip");
27+
DEFINE_int32(mds_port, 8000, "mds port");
28+
29+
30+
namespace curve {
31+
namespace mds {
32+
namespace topology {
33+
34+
class CurvefsTools {
35+
public:
36+
CurvefsTools() {}
37+
~CurvefsTools() {}
38+
39+
bool HandleCreateLogicalPool();
40+
};
41+
42+
bool CurvefsTools::HandleCreateLogicalPool() {
43+
bool ret = true;
44+
45+
brpc::Channel channel;
46+
if (channel.Init(FLAGS_mds_ip.c_str(), FLAGS_mds_port, NULL) != 0) {
47+
LOG(FATAL) << "Fail to init channel to ip: "
48+
<< FLAGS_mds_ip
49+
<< " port "
50+
<< FLAGS_mds_port
51+
<< std::endl;
52+
}
53+
54+
TopologyService_Stub stub(&channel);
55+
56+
brpc::Controller cntl;
57+
cntl.set_timeout_ms(10);
58+
cntl.set_log_id(1);
59+
60+
CreateLogicalPoolRequest request;
61+
request.set_logicalpoolname(FLAGS_name);
62+
request.set_physicalpoolid(FLAGS_physicalPoolID);
63+
request.set_type(static_cast<LogicalPoolType>(FLAGS_logicalPoolType));
64+
65+
std::string copysetNumStr = std::to_string(FLAGS_copysetNum);
66+
67+
std::string rapString = "{\"replicaNum\":3, \"copysetNum\":"
68+
+ copysetNumStr + ", \"zoneNum\":3}";
69+
70+
request.set_redundanceandplacementpolicy(rapString);
71+
request.set_userpolicy("{}");
72+
73+
CreateLogicalPoolResponse response;
74+
stub.CreateLogicalPool(&cntl, &request, &response, nullptr);
75+
76+
if (cntl.Failed()) {
77+
LOG(ERROR) << "Create file failed, errcorde = "
78+
<< response.statuscode()
79+
<< ", error content:"
80+
<< cntl.ErrorText();
81+
}
82+
if (response.statuscode() != 0) {
83+
LOG(ERROR) << "Rpc response fail. "
84+
<< "Message is :"
85+
<< response.DebugString();
86+
}
87+
88+
return ret;
89+
}
90+
91+
92+
} // namespace topology
93+
} // namespace mds
94+
} // namespace curve
95+
96+
97+
98+
int main(int argc, char **argv) {
99+
google::InitGoogleLogging(argv[0]);
100+
google::ParseCommandLineFlags(&argc, &argv, false);
101+
102+
curve::mds::topology::CurvefsTools tools;
103+
104+
std::string operation = FLAGS_op;
105+
if (operation == "CreateLogicalPool") {
106+
tools.HandleCreateLogicalPool();
107+
}
108+
109+
return 0;
110+
}
111+
112+

0 commit comments

Comments
 (0)
Please sign in to comment.