| 238 | } |
| 239 | |
| 240 | void 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 | |
| 278 | HTTPRequestHandlerFactoryPtr createAPIRequestHandlerFactory(IServer & server, const std::string & config_prefix) |
| 279 | { |
nothing calls this directly
no test coverage detected