MCPcopy Create free account
hub / github.com/baidu/tera / SafemodeOp

Function SafemodeOp

src/lbcli_main.cc:152–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150}
151
152int32_t SafemodeOp(Client* client, int32_t argc, std::string* argv, ErrorCode* err) {
153 if (argc < 3) {
154 PrintCmdHelpInfo(argv[1]);
155 return -1;
156 }
157
158 std::string op = argv[2];
159 if (op != "get" && op != "leave" && op != "enter") {
160 PrintCmdHelpInfo(argv[1]);
161 return -1;
162 }
163
164 load_balancer::LBClient lb_client(GetServerAddr());
165 CmdCtrlRequest request;
166 CmdCtrlResponse response;
167
168 request.set_sequence_id(0);
169 request.set_command("safemode");
170 request.add_arg_list(op);
171
172 string reason;
173 if (lb_client.CmdCtrl(&request, &response)) {
174 if (response.status() != tera::kLoadBalancerOk) {
175 reason = StatusCodeToString(response.status());
176 LOG(ERROR) << reason;
177 std::cout << reason << std::endl;
178 err->SetFailed(ErrorCode::kSystem, reason);
179 return -1;
180 }
181 if (op == "get") {
182 if (response.bool_result()) {
183 std::cout << "true" << std::endl;
184 } else {
185 std::cout << "false" << std::endl;
186 }
187 }
188 return 0;
189 } else {
190 reason = "fail to CmdCtrl";
191 LOG(ERROR) << reason;
192 std::cout << reason << std::endl;
193 err->SetFailed(ErrorCode::kSystem, reason);
194 return -1;
195 }
196}
197
198int32_t HelpOp(Client*, int32_t argc, std::string* argv, ErrorCode*) {
199 if (argc == 2) {

Callers

nothing calls this directly

Calls 6

GetServerAddrFunction · 0.85
StatusCodeToStringFunction · 0.85
SetFailedMethod · 0.80
PrintCmdHelpInfoFunction · 0.70
CmdCtrlMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected