Skip to content

Commit

Permalink
refactor(interactive): Refactor StopService API for Interactive SDKs (#…
Browse files Browse the repository at this point in the history
…4271)

As titled.

Fix #4265
  • Loading branch information
zhanglei1949 authored Oct 9, 2024
1 parent 728bca0 commit 8f7c620
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 14 deletions.
3 changes: 2 additions & 1 deletion coordinator/gscoordinator/flex/core/interactive/hqps.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from gs_interactive.models.create_procedure_request import CreateProcedureRequest
from gs_interactive.models.schema_mapping import SchemaMapping
from gs_interactive.models.start_service_request import StartServiceRequest
from gs_interactive.models.stop_service_request import StopServiceRequest
from gs_interactive.models.update_procedure_request import UpdateProcedureRequest

from gscoordinator.flex.core.config import CLUSTER_TYPE
Expand Down Expand Up @@ -263,7 +264,7 @@ def stop_service(self) -> str:
gs_interactive.Configuration(self._hqps_endpoint)
) as api_client:
api_instance = gs_interactive.AdminServiceServiceManagementApi(api_client)
return api_instance.stop_service()
return api_instance.stop_service(StopServiceRequest())

def restart_service(self) -> str:
with gs_interactive.ApiClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,16 @@ No authorization required
[[Back to top]](#) [[Back to API list]](python_sdk.md#documentation-for-service-apis) [[Back to Model list]](python_sdk.md#documentation-for-data-structures) [[Back to python_sdk]](python_sdk.md)

# **StopService**
> [Result](./result.rst)[str] stop_service()
> [Result](./result.rst)[str] stop_service(graph_id : str = None)
Stop the current query service while the admin service continues to operate. You can specify a `graph_id` to indicate which graph's service to stop. Since only one graph can run at a time, the `graph_id` will verify if the query service is active on that graph. If no `graph_id` is provided, the query service will be stopped without this verification.


Stop current query service. The admin service will still be serving.

### Example


```python
stop_res = sess.stop_service()
stop_res = sess.stop_service(graph_id = '1')
assert stop_res.is_ok()
print("stop service result", stop_res)
```
Expand Down
4 changes: 2 additions & 2 deletions docs/flex/interactive/development/python/python_sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ Finally, we can delete the graph. The graph data and stored procedure bound to t
Currently Interactive forbid deleting a graph which is currently serving in the service, so to delete graph, stop the service first.

```python
# stop the service first
resp = sess.stop_service()
# stop the service first, note that graph_id is optional.
resp = sess.stop_service(graph_id)
assert resp.is_ok()
print("successfully stopped the service")

Expand Down
34 changes: 33 additions & 1 deletion flex/engines/http_server/actor/admin_actor.act.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1033,15 +1033,47 @@ seastar::future<admin_query_result> admin_actor::start_service(
// The port is still connectable.
seastar::future<admin_query_result> admin_actor::stop_service(
query_param&& query_param) {
// Try to get the json content from query_param
std::string graph_id = "";
try {
auto& content = query_param.content;
if (!content.empty()) {
rapidjson::Document json;
if (json.Parse(content.c_str()).HasParseError()) {
throw std::runtime_error("Fail to parse json: " +
std::to_string(json.GetParseError()));
}
if (json.HasMember("graph_id")) {
graph_id = json["graph_id"].GetString();
}
LOG(INFO) << "Stop service with graph: " << graph_id;
}
} catch (std::exception& e) {
LOG(ERROR) << "Fail to stop service: ";
return seastar::make_ready_future<admin_query_result>(
gs::Result<seastar::sstring>(
gs::Status(gs::StatusCode::BAD_REQUEST,
"Fail to parse json: " + std::string(e.what()))));
}

auto& graph_db_service = GraphDBService::get();
return graph_db_service.stop_query_actors().then([this] {
return graph_db_service.stop_query_actors().then([this, graph_id] {
LOG(INFO) << "Successfully stopped query handler";
// Add also remove current running graph
{
std::lock_guard<std::mutex> lock(mtx_);
// unlock the graph
auto cur_running_graph_res = metadata_store_->GetRunningGraph();
if (cur_running_graph_res.ok()) {
if (!graph_id.empty() && graph_id != cur_running_graph_res.value()) {
LOG(ERROR) << "The specified graph is not running: "
<< cur_running_graph_res.value();
return seastar::make_ready_future<admin_query_result>(
gs::Result<seastar::sstring>(
gs::Status(gs::StatusCode::NOT_FOUND,
"The graph is not running: " +
cur_running_graph_res.value())));
}
auto unlock_res =
metadata_store_->UnlockGraphIndices(cur_running_graph_res.value());
if (!unlock_res.ok()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.alibaba.graphscope.interactive.client.common.Result;
import com.alibaba.graphscope.interactive.models.ServiceStatus;
import com.alibaba.graphscope.interactive.models.StartServiceRequest;
import com.alibaba.graphscope.interactive.models.StopServiceRequest;

/**
* Manage the query interface.
Expand All @@ -29,5 +30,5 @@ public interface QueryServiceInterface {

Result<String> startService(StartServiceRequest service);

Result<String> stopService();
Result<String> stopService(StopServiceRequest graphId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -801,9 +801,9 @@ public Result<String> startService(StartServiceRequest service) {
}

@Override
public Result<String> stopService() {
public Result<String> stopService(StopServiceRequest request) {
try {
ApiResponse<String> response = serviceApi.stopServiceWithHttpInfo();
ApiResponse<String> response = serviceApi.stopServiceWithHttpInfo(request);
return Result.fromResponse(response);
} catch (ApiException e) {
e.printStackTrace();
Expand Down
10 changes: 7 additions & 3 deletions flex/interactive/sdk/python/gs_interactive/client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
from gs_interactive.models import SchemaMapping
from gs_interactive.models import ServiceStatus
from gs_interactive.models import StartServiceRequest
from gs_interactive.models import StopServiceRequest
from gs_interactive.models import UpdateProcedureRequest
from gs_interactive.models import UploadFileResponse
from gs_interactive.models import VertexData
Expand Down Expand Up @@ -265,7 +266,7 @@ def start_service(
raise NotImplementedError

@abstractmethod
def stop_service(self) -> Result[str]:
def stop_service(self, graph_id: str) -> Result[str]:
raise NotImplementedError

@abstractmethod
Expand Down Expand Up @@ -805,13 +806,16 @@ def start_service(
except Exception as e:
return Result.from_exception(e)

def stop_service(self) -> Result[str]:
def stop_service(self, graph_id: str = None) -> Result[str]:
"""
Stop the service.
"""

try:
response = self._service_api.stop_service_with_http_info()
req = StopServiceRequest()
if graph_id:
req.graph_id = graph_id
response = self._service_api.stop_service_with_http_info(req)
return Result.from_response(response)
except Exception as e:
return Result.from_exception(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,11 @@ def test_builtin_procedure(interactive_session, neo4j_session, create_modern_gra
# Call the builtin procedure
start_service_on_graph(interactive_session, create_modern_graph)
call_procedure(neo4j_session, create_modern_graph, "count_vertices", '"person"')


def test_stop_service(interactive_session, create_modern_graph):
print("[Test stop service]")
start_service_on_graph(interactive_session, create_modern_graph)
# stop the service
stop_res = interactive_session.stop_service(graph_id="A Invalid graph id")
assert not stop_res.is_ok()
13 changes: 13 additions & 0 deletions flex/openapi/openapi_interactive.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,12 @@ paths:
- AdminService/ServiceManagement
description: Stop current service
operationId: stop_service
requestBody:
description: Stop service on a specified graph
content:
application/json:
schema:
$ref: '#/components/schemas/StopServiceRequest'
responses:
'200':
description: successful operation
Expand Down Expand Up @@ -2015,6 +2021,13 @@ components:
properties:
graph_id:
type: string
StopServiceRequest:
x-body-name: stop_service_request
properties:
graph_id:
type: string
nullable: true
additionalProperties: false
ServiceStatus:
x-body-name: service_status
type: object
Expand Down

0 comments on commit 8f7c620

Please sign in to comment.