Skip to content

Commit ff9fcec

Browse files
authored
feat(interactive): Support stopping query service (#3698)
Add support for stop the interactive query service.
1 parent 65f652e commit ff9fcec

File tree

4 files changed

+76
-4
lines changed

4 files changed

+76
-4
lines changed

docs/flex/interactive/development/admin_service.md

+31-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ The table below provides an overview of the available APIs:
2121
| GetProcedure | GET /v1/graph/{graph}/procedure/{proc_name} | Get the metadata of the procedure. |
2222
| DeleteProcedure | DELETE /v1/graph/{graph}/procedure/{proc_name} | Delete the specified procedure. |
2323
| UpdateProcedure | PUT /v1/graph/{graph}/procedure/{proc_name} | Update some metadata for the specified procedure, i.e. update description, enable/disable. |
24-
| StartService | POST /v1/service/start | Start the service on the graph specified in request body. |
24+
| StartService | POST /v1/service/start | Start the query service on the graph specified in request body. |
25+
| StopService | GET /v1/service/stop | Stop the query service |
2526
| ServiceStatus | GET /v1/service/status | Get current service status. |
2627
| SystemMetrics | GET /v1/node/status | Get the system metrics of current host/pod, i.e. CPU usage, memory usages. |
2728

@@ -986,6 +987,35 @@ curl -X POST -H "Content-Type: application/json" "http://[host]/v1/service/start
986987
- `200 OK`: Request successful.
987988
- `500 Internal Error`: Server internal Error.
988989

990+
### StopService (ServiceManagement Category)
991+
992+
#### Description
993+
994+
Stop the current running query service.
995+
996+
#### HTTP Request
997+
- **Method**: POST
998+
- **Endpoint**: `/v1/service/stop`
999+
- **Content-type**: `application/json`
1000+
1001+
#### Curl Command Example
1002+
```bash
1003+
curl -X POST -H "Content-Type: application/json" "http://[host]/v1/service/stop"
1004+
```
1005+
1006+
#### Expected Response
1007+
- **Format**: application/json
1008+
- **Body**:
1009+
```json
1010+
{
1011+
"message": "message"
1012+
}
1013+
```
1014+
1015+
#### Status Codes
1016+
- `200 OK`: Request successful.
1017+
- `500 Internal Error`: Server internal Error.
1018+
9891019
### ServiceStatus
9901020

9911021
#### Description

flex/engines/http_server/actor/admin_actor.act.cc

+28
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,40 @@ seastar::future<query_result> admin_actor::start_service(
349349
}
350350
hqps_service.start_query_actors(); // start on a new scope.
351351
LOG(INFO) << "Successfully restart query actors";
352+
// now start the compiler
353+
auto schema_path =
354+
server::WorkDirManipulator::GetGraphSchemaPath(graph_name);
355+
if (!hqps_service.start_compiler_subprocess(schema_path)) {
356+
LOG(ERROR) << "Fail to start compiler";
357+
return seastar::make_exception_future<query_result>(
358+
seastar::sstring("Fail to start compiler"));
359+
}
352360
LOG(INFO) << "Successfully started service with graph: " << graph_name;
353361
return seastar::make_ready_future<query_result>(
354362
"Successfully start service");
355363
});
356364
}
357365

366+
// Stop service.
367+
// Actually stop the query_handler's actors.
368+
// The port is still connectable.
369+
seastar::future<query_result> admin_actor::stop_service(
370+
query_param&& query_param) {
371+
auto& hqps_service = HQPSService::get();
372+
return hqps_service.stop_query_actors().then([&hqps_service] {
373+
LOG(INFO) << "Successfully stopped query handler";
374+
if (hqps_service.stop_compiler_subprocess()) {
375+
LOG(INFO) << "Successfully stop compiler";
376+
return seastar::make_ready_future<query_result>(
377+
seastar::sstring("Successfully stop service"));
378+
} else {
379+
LOG(ERROR) << "Fail to stop compiler";
380+
return seastar::make_ready_future<query_result>(
381+
seastar::sstring("Fail to stop compiler"));
382+
}
383+
});
384+
}
385+
358386
// get service status
359387
seastar::future<query_result> admin_actor::service_status(
360388
query_param&& query_param) {

flex/engines/http_server/actor/admin_actor.act.h

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class ANNOTATION(actor:impl) admin_actor : public hiactor::actor {
4343

4444
seastar::future<query_result> ANNOTATION(actor:method) start_service(query_param&& param);
4545

46+
seastar::future<query_result> ANNOTATION(actor:method) stop_service(query_param&& param);
47+
4648
seastar::future<query_result> ANNOTATION(actor:method) service_status(query_param&& param);
4749

4850
seastar::future<query_result> ANNOTATION(actor:method) get_procedure_by_procedure_name(procedure_query_param&& param);

flex/engines/http_server/handler/admin_http_handler.cc

+15-3
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,21 @@ class admin_http_service_handler_impl : public seastar::httpd::handler_base {
409409
std::unique_ptr<seastar::httpd::reply>>(std::move(rep));
410410
});
411411
} else if (action == "stop") {
412-
return seastar::make_exception_future<
413-
std::unique_ptr<seastar::httpd::reply>>(
414-
std::runtime_error("Stopping service not supported."));
412+
return admin_actor_refs_[dst_executor]
413+
.stop_service(query_param{std::move(req->content)})
414+
.then_wrapped([rep = std::move(rep)](
415+
seastar::future<query_result>&& fut) mutable {
416+
if (__builtin_expect(fut.failed(), false)) {
417+
return seastar::make_exception_future<
418+
std::unique_ptr<seastar::httpd::reply>>(
419+
fut.get_exception());
420+
}
421+
auto result = fut.get0();
422+
rep->write_body("application/json", std::move(result.content));
423+
rep->done();
424+
return seastar::make_ready_future<
425+
std::unique_ptr<seastar::httpd::reply>>(std::move(rep));
426+
});
415427
} else {
416428
return seastar::make_exception_future<
417429
std::unique_ptr<seastar::httpd::reply>>(

0 commit comments

Comments
 (0)