Skip to content

Commit

Permalink
feat(interactive): Support stopping query service (#3698)
Browse files Browse the repository at this point in the history
Add support for stop the interactive query service.
  • Loading branch information
zhanglei1949 committed Apr 9, 2024
1 parent 65f652e commit ff9fcec
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 4 deletions.
32 changes: 31 additions & 1 deletion docs/flex/interactive/development/admin_service.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |

Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions flex/engines/http_server/actor/admin_actor.act.cc
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,40 @@ seastar::future<query_result> 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<query_result>(
seastar::sstring("Fail to start compiler"));
}
LOG(INFO) << "Successfully started service with graph: " << graph_name;
return seastar::make_ready_future<query_result>(
"Successfully start service");
});
}

// Stop service.
// Actually stop the query_handler's actors.
// The port is still connectable.
seastar::future<query_result> 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<query_result>(
seastar::sstring("Successfully stop service"));
} else {
LOG(ERROR) << "Fail to stop compiler";
return seastar::make_ready_future<query_result>(
seastar::sstring("Fail to stop compiler"));
}
});
}

// get service status
seastar::future<query_result> admin_actor::service_status(
query_param&& query_param) {
Expand Down
2 changes: 2 additions & 0 deletions flex/engines/http_server/actor/admin_actor.act.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class ANNOTATION(actor:impl) admin_actor : public hiactor::actor {

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

seastar::future<query_result> ANNOTATION(actor:method) stop_service(query_param&& param);

seastar::future<query_result> ANNOTATION(actor:method) service_status(query_param&& param);

seastar::future<query_result> ANNOTATION(actor:method) get_procedure_by_procedure_name(procedure_query_param&& param);
Expand Down
18 changes: 15 additions & 3 deletions flex/engines/http_server/handler/admin_http_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,21 @@ class admin_http_service_handler_impl : public seastar::httpd::handler_base {
std::unique_ptr<seastar::httpd::reply>>(std::move(rep));
});
} else if (action == "stop") {
return seastar::make_exception_future<
std::unique_ptr<seastar::httpd::reply>>(
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<query_result>&& fut) mutable {
if (__builtin_expect(fut.failed(), false)) {
return seastar::make_exception_future<
std::unique_ptr<seastar::httpd::reply>>(
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<seastar::httpd::reply>>(std::move(rep));
});
} else {
return seastar::make_exception_future<
std::unique_ptr<seastar::httpd::reply>>(
Expand Down

0 comments on commit ff9fcec

Please sign in to comment.