From 9730f3ba661dc8a0abcd9e985aa014b8747d0a56 Mon Sep 17 00:00:00 2001 From: Dongze Li Date: Fri, 29 Mar 2024 16:22:37 +0800 Subject: [PATCH] Add get_procedure_by_name interface --- .../controllers/procedure_controller.py | 16 +++ .../core/client_wrapper.py | 5 + .../core/interactive/hqps.py | 7 + .../gs_flex_coordinator/openapi/openapi.yaml | 121 +++++++++--------- flex/coordinator/setup.py | 8 +- flex/openapi/openapi_coordinator.yaml | 68 +++++++++- python/setup.py | 4 +- 7 files changed, 164 insertions(+), 65 deletions(-) diff --git a/flex/coordinator/gs_flex_coordinator/controllers/procedure_controller.py b/flex/coordinator/gs_flex_coordinator/controllers/procedure_controller.py index 6ce6cfe5bf16..b753673a612a 100644 --- a/flex/coordinator/gs_flex_coordinator/controllers/procedure_controller.py +++ b/flex/coordinator/gs_flex_coordinator/controllers/procedure_controller.py @@ -43,6 +43,22 @@ def delete_procedure(graph_name, procedure_name): # noqa: E501 return client_wrapper.delete_procedure_by_name(graph_name, procedure_name) +@handle_api_exception() +def get_procedure(graph_name, procedure_name): # noqa: E501 + """get_procedure + + Get a procedure by name # noqa: E501 + + :param graph_name: + :type graph_name: str + :param procedure_name: + :type procedure_name: str + + :rtype: Union[Procedure, Tuple[Procedure, int], Tuple[Procedure, int, Dict[str, str]] + """ + return client_wrapper.get_procedure_by_name(graph_name, procedure_name) + + @handle_api_exception() def list_procedures(): # noqa: E501 """list_procedures diff --git a/flex/coordinator/gs_flex_coordinator/core/client_wrapper.py b/flex/coordinator/gs_flex_coordinator/core/client_wrapper.py index 9be80ef70dc8..07f5845d639a 100644 --- a/flex/coordinator/gs_flex_coordinator/core/client_wrapper.py +++ b/flex/coordinator/gs_flex_coordinator/core/client_wrapper.py @@ -212,6 +212,11 @@ def create_procedure(self, graph_name: str, procedure: Procedure) -> str: procedure_dict = procedure.to_dict() return self._client.create_procedure(graph_name, procedure_dict) + def get_procedure_by_name(self, graph_name: str, procedure_name: str) -> Procedure: + return Procedure.from_dict( + self._client.get_procedure_by_name(graph_name, procedure_name).to_dict() + ) + def list_procedures(self, graph_name: Union[None, str]) -> List[Procedure]: procedures = self._client.list_procedures(graph_name) # transfer diff --git a/flex/coordinator/gs_flex_coordinator/core/interactive/hqps.py b/flex/coordinator/gs_flex_coordinator/core/interactive/hqps.py index 2f98fbae896e..76c46eda507e 100644 --- a/flex/coordinator/gs_flex_coordinator/core/interactive/hqps.py +++ b/flex/coordinator/gs_flex_coordinator/core/interactive/hqps.py @@ -171,6 +171,13 @@ def delete_procedure_by_name(self, graph_name: str, procedure_name: str) -> str: api_instance = hqps_client.ProcedureApi(api_client) return api_instance.delete_procedure(graph_name, procedure_name) + def get_procedure_by_name(self, graph_name: str, procedure_name: str) -> Procedure: + with hqps_client.ApiClient( + hqps_client.Configuration(self._hqps_endpoint) + ) as api_client: + api_instance = hqps_client.ProcedureApi(api_client) + return api_instance.get_procedure(graph_name, procedure_name) + def get_service_status(self) -> dict: with hqps_client.ApiClient( hqps_client.Configuration(self._hqps_endpoint) diff --git a/flex/coordinator/gs_flex_coordinator/openapi/openapi.yaml b/flex/coordinator/gs_flex_coordinator/openapi/openapi.yaml index 0493d4fdd715..cd10244c5098 100644 --- a/flex/coordinator/gs_flex_coordinator/openapi/openapi.yaml +++ b/flex/coordinator/gs_flex_coordinator/openapi/openapi.yaml @@ -804,6 +804,34 @@ paths: tags: - procedure x-openapi-router-controller: gs_flex_coordinator.controllers.procedure_controller + get: + description: Get a procedure by name + operationId: get_procedure + parameters: + - explode: false + in: path + name: graph_name + required: true + schema: + type: string + style: simple + - explode: false + in: path + name: procedure_name + required: true + schema: + type: string + style: simple + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/Procedure' + description: successful operation + tags: + - procedure + x-openapi-router-controller: gs_flex_coordinator.controllers.procedure_controller put: description: Update stored procedure on a certain graph operationId: update_procedure @@ -1752,7 +1780,7 @@ components: graph_name: mocking_graph sdk_endpoints: gremlin: ws://111.111.111.111:12312/gremlin - cypher: neo4j://111.111.111.111:7687 + cypher: neo4j://mock.api.cypher:7676 hqps: neo4j://111.111.111.111:10000 grpc: 111.111.111.111:55556 status: running @@ -2333,82 +2361,58 @@ components: x-body-name: data_source GrootGraph: example: - creation_time: creation_time + name: demo + type: GrootGraph + directed: true + creation_time: 2024-02-29 12:00:00 + gremlin_interface: + gremlin_endpoint: ws://127.0.0.1:12312/gremmin + grpc_endpoint: 127.0.0.1:55556 schema: vertices: - - label: label + - label: person properties: - - is_primary_key: true - name: name - id: 0 + - name: id type: STRING - - is_primary_key: true - name: name - id: 0 + is_primary_key: true + - name: name type: STRING - - label: label + is_primary_key: false + - label: software properties: - - is_primary_key: true - name: name - id: 0 + - name: id type: STRING - - is_primary_key: true - name: name - id: 0 + is_primary_key: true + - name: name type: STRING + is_primary_key: false edges: - - label: label + - label: knows relations: - - src_label: src_label - dst_label: dst_label - - src_label: src_label - dst_label: dst_label + - src_label: person + dst_label: person properties: - - is_primary_key: true - name: name - id: 0 - type: STRING - - is_primary_key: true - name: name - id: 0 - type: STRING - - label: label + - name: weight + type: DOUBLE + is_primary_key: false + - label: created relations: - - src_label: src_label - dst_label: dst_label - - src_label: src_label - dst_label: dst_label + - src_label: person + dst_label: software properties: - - is_primary_key: true - name: name - id: 0 - type: STRING - - is_primary_key: true - name: name - id: 0 - type: STRING - directed: true - gremlin_interface: - grpc_endpoint: grpc_endpoint - password: password - gremlin_endpoint: gremlin_endpoint - username: username - name: name - type: GrootGraph + - name: weight + type: DOUBLE + is_primary_key: false properties: name: - title: name type: string type: enum: - GrootGraph - title: type type: string directed: - title: directed type: boolean creation_time: - title: creation_time type: string schema: $ref: '#/components/schemas/GrootSchema' @@ -2738,12 +2742,12 @@ components: ServiceStatus_sdk_endpoints: example: gremlin: ws://111.111.111.111:12312/gremlin - cypher: neo4j://111.111.111.111:7687 + cypher: neo4j://mock.api.cypher:7676 hqps: neo4j://111.111.111.111:10000 grpc: 111.111.111.111:55556 properties: cypher: - example: neo4j://111.111.111.111:7687 + example: neo4j://mock.api.cypher:7676 title: cypher type: string gremlin: @@ -2865,11 +2869,6 @@ components: title: EdgeMapping_destination_vertex_mappings_inner type: object GrootGraph_gremlin_interface: - example: - grpc_endpoint: grpc_endpoint - password: password - gremlin_endpoint: gremlin_endpoint - username: username properties: gremlin_endpoint: title: gremlin_endpoint diff --git a/flex/coordinator/setup.py b/flex/coordinator/setup.py index 9aa784fef0a8..dcf10ee1c86a 100644 --- a/flex/coordinator/setup.py +++ b/flex/coordinator/setup.py @@ -64,10 +64,12 @@ def run(self): "--package-name", "gs_flex_coordinator", ] + env = os.environ.copy() + env["OPENAPI_GENERATOR_VERSION"] = "7.3.0" print(" ".join(cmd)) subprocess.check_call( cmd, - env=os.environ.copy(), + env=env, ) @@ -107,10 +109,12 @@ def run(self): "--package-name", "hqps_client", ] + env = os.environ.copy() + env["OPENAPI_GENERATOR_VERSION"] = "7.3.0" print(" ".join(cmd)) subprocess.check_call( cmd, - env=os.environ.copy(), + env=env, ) # cp subprocess.run(["cp", "-r", os.path.join(tempdir, "hqps_client"), targetdir]) diff --git a/flex/openapi/openapi_coordinator.yaml b/flex/openapi/openapi_coordinator.yaml index 479f20a1a289..03d20e2d6e2c 100644 --- a/flex/openapi/openapi_coordinator.yaml +++ b/flex/openapi/openapi_coordinator.yaml @@ -671,6 +671,29 @@ paths: items: $ref: '#/components/schemas/Procedure' /api/v1/graph/{graph_name}/procedure/{procedure_name}: + get: + tags: + - procedure + description: Get a procedure by name + operationId: get_procedure + parameters: + - name: graph_name + in : path + required: true + schema: + type: string + - name: procedure_name + in : path + required: true + schema: + type: string + responses: + '200': + description: successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/Procedure' put: tags: - procedure @@ -1422,7 +1445,7 @@ components: properties: cypher: type: string - example: neo4j://111.111.111.111:7687 + example: neo4j://mock.api.cypher:7676 gremlin: type: string example: ws://111.111.111.111:12312/gremlin @@ -1797,6 +1820,49 @@ components: type: string password: type: string + example: + name: demo + type: GrootGraph + directed: true + creation_time: 2024-02-29 12:00:00 + gremlin_interface: + gremlin_endpoint: ws://127.0.0.1:12312/gremmin + grpc_endpoint: 127.0.0.1:55556 + schema: + vertices: + - label: person + properties: + - name: id + type: STRING + is_primary_key: true + - name: name + type: STRING + is_primary_key: false + - label: software + properties: + - name: id + type: STRING + is_primary_key: true + - name: name + type: STRING + is_primary_key: false + edges: + - label: knows + relations: + - src_label: person + dst_label: person + properties: + - name: weight + type: DOUBLE + is_primary_key: false + - label: created + relations: + - src_label: person + dst_label: software + properties: + - name: weight + type: DOUBLE + is_primary_key: false GrootSchema: x-body-name: groot_schema type: object diff --git a/python/setup.py b/python/setup.py index e2eb5e3326fb..706f254a435c 100644 --- a/python/setup.py +++ b/python/setup.py @@ -126,10 +126,12 @@ def run(self): "--package-name", "graphscope.flex.rest", ] + env = os.environ.copy() + env["OPENAPI_GENERATOR_VERSION"] = "7.3.0" print(" ".join(cmd)) subprocess.check_call( cmd, - env=os.environ.copy(), + env=env, ) # cp subprocess.run(