diff --git a/presto-native-execution/presto_cpp/main/PrestoServer.cpp b/presto-native-execution/presto_cpp/main/PrestoServer.cpp index 4a3be413c27f6..e37fd9e1f2ab0 100644 --- a/presto-native-execution/presto_cpp/main/PrestoServer.cpp +++ b/presto-native-execution/presto_cpp/main/PrestoServer.cpp @@ -61,6 +61,10 @@ #include "velox/functions/prestosql/registration/RegistrationFunctions.h" #include "velox/functions/prestosql/window/WindowFunctionsRegistration.h" #include "velox/serializers/PrestoSerializer.h" +#include +#include +#include + #ifdef PRESTO_ENABLE_REMOTE_FUNCTIONS #include "presto_cpp/main/RemoteFunctionRegisterer.h" @@ -374,39 +378,39 @@ void PrestoServer::run() { http::sendOkResponse(downstream, infoStateJson); }); httpServer_->registerPut( - "/v1/info/state", - [server = this]( - proxygen::HTTPMessage* /*message*/, - const std::vector>& body , - proxygen::ResponseHandler* downstream) { - std::string requestBody=getRequestBody(body); - try { - folly::dynamic jsonBody = folly::parseJson(requestBody); - if (jsonBody == "SHUTTING_DOWN") { - // Print message and initiate shutdown - LOG(INFO) << "Shutdown requested"; - if (server->nodeState() == NodeState::kActive) { - // Call stop() to handle the shutdown process - std::thread([server]() { - server->stop(); - }).detach(); - } else { - // Print message and indicate that shutdown is already requested - LOG(INFO) << "Shutdown already requested"; - } - http::sendOkResponse(downstream); - } else { - // Throw a 400 Bad Request error if the body has some other value - http::sendErrorResponse( - downstream, - "Bad Request: Body must contain 'SHUTTING_DOWN'.",http::kHttpBadRequest); - } - } - catch (const folly::json::parse_error& e) { - // Handle JSON parse errors and send a 400 Bad Request response - http::sendErrorResponse(downstream, e.what(), http::kHttpBadRequest); // 400 Bad Request - } - }); + "/v1/info/state", + [server = this]( + proxygen::HTTPMessage* /*message*/, + const std::vector>& body , + proxygen::ResponseHandler* downstream) { + std::string requestBody=getRequestBody(body); + try { + folly::dynamic jsonBody = folly::parseJson(requestBody); + if (jsonBody == "SHUTTING_DOWN") { + // Print message and initiate shutdown + LOG(INFO) << "Shutdown requested"; + if (server->nodeState() == NodeState::kActive) { + // Call stop() to handle the shutdown process + std::thread([server]() { + server->stop(); + }).detach(); + } else { + // Print message and indicate that node is inactive or shutdown is already requested + LOG(INFO) << "Node is inactive or shutdown is already requested"; + } + http::sendOkResponse(downstream); + } else { + // Throw a 400 Bad Request error if the body has some other value + http::sendErrorResponse( + downstream, + "Bad Request: Body must contain 'SHUTTING_DOWN'.",http::kHttpBadRequest); + } + } + catch (const folly::json::parse_error& e) { + // Handle JSON parse errors and send a 400 Bad Request response + http::sendErrorResponse(downstream, e.what(), http::kHttpBadRequest); // 400 Bad Request + } + }); httpServer_->registerGet( "/v1/status", [server = this](