MCPcopy Create free account
hub / github.com/ByConity/ByConity / onResourceReportAction

Method onResourceReportAction

src/Server/APIRequestHandler.cpp:240–276  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

238}
239
240void APIRequestHandler::onResourceReportAction(
241 [[maybe_unused]] HTTPServerRequest & request, [[maybe_unused]] HTMLForm & params, HTTPServerResponse & response)
242{
243 if (getContext()->getServerType() != ServerType::cnch_worker)
244 throw Exception("/api/resource_report can only run on cnch_worker", ErrorCodes::LOGICAL_ERROR);
245 if (!params.has("action"))
246 throw Exception("/api/resource_report requires parameter: action", ErrorCodes::BAD_ARGUMENTS);
247 auto action = params.get("action");
248
249 Result res;
250 try
251 {
252 if (action == "stop")
253 {
254 getContext()->stopResourceReport();
255 res.add("success", true);
256 }
257 else if (action == "start")
258 {
259 getContext()->startResourceReport();
260 res.add("success", true);
261 }
262 else if (action == "check")
263 {
264 bool registered = getContext()->isResourceReportRegistered();
265 res.add("success", true);
266 res.add("registered", registered);
267 }
268 }
269 catch (const Exception & e)
270 {
271 tryLogCurrentException(log, __PRETTY_FUNCTION__);
272 res.add("success", false);
273 res.add("exception", e.message());
274 }
275 sendResult(res, response);
276}
277
278HTTPRequestHandlerFactoryPtr createAPIRequestHandlerFactory(IServer & server, const std::string & config_prefix)
279{

Callers

nothing calls this directly

Calls 9

tryLogCurrentExceptionFunction · 0.85
getServerTypeMethod · 0.80
ExceptionClass · 0.50
hasMethod · 0.45
getMethod · 0.45
stopResourceReportMethod · 0.45
addMethod · 0.45
startResourceReportMethod · 0.45

Tested by

no test coverage detected