From ff9fcecf43d254399330fb80e0a112590fde3614 Mon Sep 17 00:00:00 2001 From: Zhang Lei Date: Tue, 9 Apr 2024 16:48:38 +0800 Subject: [PATCH] feat(interactive): Support stopping query service (#3698) Add support for stop the interactive query service. --- .../interactive/development/admin_service.md | 32 ++++++++++++++++++- .../http_server/actor/admin_actor.act.cc | 28 ++++++++++++++++ .../http_server/actor/admin_actor.act.h | 2 ++ .../http_server/handler/admin_http_handler.cc | 18 +++++++++-- 4 files changed, 76 insertions(+), 4 deletions(-) diff --git a/docs/flex/interactive/development/admin_service.md b/docs/flex/interactive/development/admin_service.md index b3923290208a..9d0fa8dfd230 100644 --- a/docs/flex/interactive/development/admin_service.md +++ b/docs/flex/interactive/development/admin_service.md @@ -21,7 +21,8 @@ The table below provides an overview of the available APIs: | GetProcedure | GET /v1/graph/{graph}/procedure/{proc_name} | Get the metadata of the procedure. | | DeleteProcedure | DELETE /v1/graph/{graph}/procedure/{proc_name} | Delete the specified procedure. | | UpdateProcedure | PUT /v1/graph/{graph}/procedure/{proc_name} | Update some metadata for the specified procedure, i.e. update description, enable/disable. | -| StartService | POST /v1/service/start | Start the service on the graph specified in request body. | +| StartService | POST /v1/service/start | Start the query service on the graph specified in request body. | +| StopService | GET /v1/service/stop | Stop the query service | | ServiceStatus | GET /v1/service/status | Get current service status. | | SystemMetrics | GET /v1/node/status | Get the system metrics of current host/pod, i.e. CPU usage, memory usages. | @@ -986,6 +987,35 @@ curl -X POST -H "Content-Type: application/json" "http://[host]/v1/service/start - `200 OK`: Request successful. - `500 Internal Error`: Server internal Error. +### StopService (ServiceManagement Category) + +#### Description + +Stop the current running query service. + +#### HTTP Request +- **Method**: POST +- **Endpoint**: `/v1/service/stop` +- **Content-type**: `application/json` + +#### Curl Command Example +```bash +curl -X POST -H "Content-Type: application/json" "http://[host]/v1/service/stop" +``` + +#### Expected Response +- **Format**: application/json +- **Body**: +```json +{ + "message": "message" +} +``` + +#### Status Codes +- `200 OK`: Request successful. +- `500 Internal Error`: Server internal Error. + ### ServiceStatus #### Description diff --git a/flex/engines/http_server/actor/admin_actor.act.cc b/flex/engines/http_server/actor/admin_actor.act.cc index 021054f7919e..ca77032016c6 100644 --- a/flex/engines/http_server/actor/admin_actor.act.cc +++ b/flex/engines/http_server/actor/admin_actor.act.cc @@ -349,12 +349,40 @@ seastar::future admin_actor::start_service( } hqps_service.start_query_actors(); // start on a new scope. LOG(INFO) << "Successfully restart query actors"; + // now start the compiler + auto schema_path = + server::WorkDirManipulator::GetGraphSchemaPath(graph_name); + if (!hqps_service.start_compiler_subprocess(schema_path)) { + LOG(ERROR) << "Fail to start compiler"; + return seastar::make_exception_future( + seastar::sstring("Fail to start compiler")); + } LOG(INFO) << "Successfully started service with graph: " << graph_name; return seastar::make_ready_future( "Successfully start service"); }); } +// Stop service. +// Actually stop the query_handler's actors. +// The port is still connectable. +seastar::future admin_actor::stop_service( + query_param&& query_param) { + auto& hqps_service = HQPSService::get(); + return hqps_service.stop_query_actors().then([&hqps_service] { + LOG(INFO) << "Successfully stopped query handler"; + if (hqps_service.stop_compiler_subprocess()) { + LOG(INFO) << "Successfully stop compiler"; + return seastar::make_ready_future( + seastar::sstring("Successfully stop service")); + } else { + LOG(ERROR) << "Fail to stop compiler"; + return seastar::make_ready_future( + seastar::sstring("Fail to stop compiler")); + } + }); +} + // get service status seastar::future admin_actor::service_status( query_param&& query_param) { diff --git a/flex/engines/http_server/actor/admin_actor.act.h b/flex/engines/http_server/actor/admin_actor.act.h index 556c84936e22..ed0eb2852655 100644 --- a/flex/engines/http_server/actor/admin_actor.act.h +++ b/flex/engines/http_server/actor/admin_actor.act.h @@ -43,6 +43,8 @@ class ANNOTATION(actor:impl) admin_actor : public hiactor::actor { seastar::future ANNOTATION(actor:method) start_service(query_param&& param); + seastar::future ANNOTATION(actor:method) stop_service(query_param&& param); + seastar::future ANNOTATION(actor:method) service_status(query_param&& param); seastar::future ANNOTATION(actor:method) get_procedure_by_procedure_name(procedure_query_param&& param); diff --git a/flex/engines/http_server/handler/admin_http_handler.cc b/flex/engines/http_server/handler/admin_http_handler.cc index fedaa2b62b22..ebba9dba514e 100644 --- a/flex/engines/http_server/handler/admin_http_handler.cc +++ b/flex/engines/http_server/handler/admin_http_handler.cc @@ -409,9 +409,21 @@ class admin_http_service_handler_impl : public seastar::httpd::handler_base { std::unique_ptr>(std::move(rep)); }); } else if (action == "stop") { - return seastar::make_exception_future< - std::unique_ptr>( - std::runtime_error("Stopping service not supported.")); + return admin_actor_refs_[dst_executor] + .stop_service(query_param{std::move(req->content)}) + .then_wrapped([rep = std::move(rep)]( + seastar::future&& fut) mutable { + if (__builtin_expect(fut.failed(), false)) { + return seastar::make_exception_future< + std::unique_ptr>( + fut.get_exception()); + } + auto result = fut.get0(); + rep->write_body("application/json", std::move(result.content)); + rep->done(); + return seastar::make_ready_future< + std::unique_ptr>(std::move(rep)); + }); } else { return seastar::make_exception_future< std::unique_ptr>(