diff --git a/flex/coordinator/gs_flex_coordinator/core/interactive/hqps.py b/flex/coordinator/gs_flex_coordinator/core/interactive/hqps.py index 993036ec7cf6..431324526750 100644 --- a/flex/coordinator/gs_flex_coordinator/core/interactive/hqps.py +++ b/flex/coordinator/gs_flex_coordinator/core/interactive/hqps.py @@ -93,6 +93,12 @@ def list_graphs(self) -> List[dict]: ) graphs = [g.to_dict() for g in api_instance.list_graphs()] for g in graphs: + g["creation_time"] = encode_datetime( + datetime.datetime.fromtimestamp(g["creation_time"] / 1000) + ) + g["data_update_time"] = encode_datetime( + datetime.datetime.fromtimestamp(g["data_update_time"] / 1000) + ) # `schema_update_time` is same to `creation_time` in Interactive g["schema_update_time"] = g["creation_time"] # we do not have edge's primary key in Interactive @@ -138,6 +144,12 @@ def get_graph_by_id(self, graph_id: str) -> dict: api_client ) g = api_instance.get_graph(graph_id).to_dict() + g["creation_time"] = encode_datetime( + datetime.datetime.fromtimestamp(g["creation_time"] / 1000) + ) + g["data_update_time"] = encode_datetime( + datetime.datetime.fromtimestamp(g["data_update_time"] / 1000) + ) # `schema_update_time` is same to `creation_time` in Interactive g["schema_update_time"] = g["creation_time"] # we do not have edge's primary key in Interactive @@ -242,10 +254,16 @@ def get_service_status(self) -> dict: }, } if response.graph is not None: - graph = response.graph.to_dict() + g = response.graph.to_dict() + g["creation_time"] = encode_datetime( + datetime.datetime.fromtimestamp(g["creation_time"] / 1000) + ) + g["data_update_time"] = encode_datetime( + datetime.datetime.fromtimestamp(g["data_update_time"] / 1000) + ) # `schema_update_time` is same to `creation_time` in Interactive - graph["schema_update_time"] = graph["creation_time"] - status["graph"] = graph + g["schema_update_time"] = g["creation_time"] + status["graph"] = g return status def stop_service(self) -> str: diff --git a/flex/coordinator/gs_flex_coordinator/openapi/openapi.yaml b/flex/coordinator/gs_flex_coordinator/openapi/openapi.yaml index af758d57795a..89a5a08a3e27 100644 --- a/flex/coordinator/gs_flex_coordinator/openapi/openapi.yaml +++ b/flex/coordinator/gs_flex_coordinator/openapi/openapi.yaml @@ -1016,6 +1016,239 @@ paths: tags: - DataSource x-openapi-router-controller: gs_flex_coordinator.controllers.data_source_controller + /api/v1/graph/{graph_id}/procedure: + get: + description: List all stored procedures on a certain graph + operationId: list_procedures + parameters: + - explode: false + in: path + name: graph_id + required: true + schema: + type: string + style: simple + responses: + "200": + content: + application/json: + example: + - id: PROCEDUREID-1 + name: procedure_name_1 + type: cypher + query: MATCH(a) return COUNT(a); + library: /path/to/library + params: + - name: param1 + type: + string: + long_text: null + returns: + - name: return1 + type: + PrimitiveType: DT_SIGNED_INT64 + bound_graph: demo + runnable: true + - id: PROCEDUREID-2 + name: procedure_name_2 + type: cypher + query: MATCH(a) return COUNT(a); + library: /path/to/library + params: + - name: param1 + type: + string: + long_text: null + returns: + - name: return1 + type: + PrimitiveType: DT_SIGNED_INT64 + bound_graph: demo + runnable: false + schema: + items: + $ref: '#/components/schemas/GetProcedureResponse' + type: array + description: Successful operation + "400": + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + description: Bad request + "500": + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + description: Server error + tags: + - Procedure + x-openapi-router-controller: gs_flex_coordinator.controllers.procedure_controller + post: + description: Create a new stored procedure on a certain graph + operationId: create_procedure + parameters: + - explode: false + in: path + name: graph_id + required: true + schema: + type: string + style: simple + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateProcedureRequest' + required: true + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/CreateProcedureResponse' + description: Successfully created a procedure + "400": + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + description: Bad request + "500": + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + description: Server error + tags: + - Procedure + x-openapi-router-controller: gs_flex_coordinator.controllers.procedure_controller + /api/v1/graph/{graph_id}/procedure/{procedure_id}: + delete: + description: Delete a stored procedure by ID + operationId: delete_procedure_by_id + parameters: + - explode: false + in: path + name: graph_id + required: true + schema: + type: string + style: simple + - explode: false + in: path + name: procedure_id + required: true + schema: + type: string + style: simple + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/APIResponse' + description: Successfully deleted the stored procedure + "500": + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + description: Server error + tags: + - Procedure + x-openapi-router-controller: gs_flex_coordinator.controllers.procedure_controller + get: + description: Get a stored procedure by ID + operationId: get_procedure_by_id + parameters: + - explode: false + in: path + name: graph_id + required: true + schema: + type: string + style: simple + - explode: false + in: path + name: procedure_id + required: true + schema: + type: string + style: simple + responses: + "200": + content: + application/json: + example: + id: PROCEDUREID + name: procedure_name + type: cypher + query: MATCH(a) return COUNT(a); + library: /path/to/library + params: + - name: param1 + type: + string: + long_text: null + returns: + - name: return1 + type: + PrimitiveType: DT_SIGNED_INT64 + bound_graph: demo + runnable: true + schema: + $ref: '#/components/schemas/GetProcedureResponse' + description: Successfully returned the procedure + "500": + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + description: Server error + tags: + - Procedure + x-openapi-router-controller: gs_flex_coordinator.controllers.procedure_controller + put: + description: Update a stored procedure by ID + operationId: update_procedure_by_id + parameters: + - explode: false + in: path + name: graph_id + required: true + schema: + type: string + style: simple + - explode: false + in: path + name: procedure_id + required: true + schema: + type: string + style: simple + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/UpdateProcedureRequest' + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/APIResponse' + description: Successfully updated the stored procedure + "500": + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + description: Server error + tags: + - Procedure + x-openapi-router-controller: gs_flex_coordinator.controllers.procedure_controller /api/v1/graph/{graph_id}/schema: get: description: Get graph schema by ID @@ -1597,239 +1830,6 @@ paths: tags: - Service x-openapi-router-controller: gs_flex_coordinator.controllers.service_controller - /v1/graph/{graph_id}/procedure: - get: - description: List all stored procedures on a certain graph - operationId: list_procedures - parameters: - - explode: false - in: path - name: graph_id - required: true - schema: - type: string - style: simple - responses: - "200": - content: - application/json: - example: - - id: PROCEDUREID-1 - name: procedure_name_1 - type: cypher - query: MATCH(a) return COUNT(a); - library: /path/to/library - params: - - name: param1 - type: - string: - long_text: null - returns: - - name: return1 - type: - PrimitiveType: DT_SIGNED_INT64 - bound_graph: demo - runnable: true - - id: PROCEDUREID-2 - name: procedure_name_2 - type: cypher - query: MATCH(a) return COUNT(a); - library: /path/to/library - params: - - name: param1 - type: - string: - long_text: null - returns: - - name: return1 - type: - PrimitiveType: DT_SIGNED_INT64 - bound_graph: demo - runnable: false - schema: - items: - $ref: '#/components/schemas/GetProcedureResponse' - type: array - description: Successful operation - "400": - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - description: Bad request - "500": - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - description: Server error - tags: - - Procedure - x-openapi-router-controller: gs_flex_coordinator.controllers.procedure_controller - post: - description: Create a new stored procedure on a certain graph - operationId: create_procedure - parameters: - - explode: false - in: path - name: graph_id - required: true - schema: - type: string - style: simple - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/CreateProcedureRequest' - required: true - responses: - "200": - content: - application/json: - schema: - $ref: '#/components/schemas/CreateProcedureResponse' - description: Successfully created a procedure - "400": - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - description: Bad request - "500": - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - description: Server error - tags: - - Procedure - x-openapi-router-controller: gs_flex_coordinator.controllers.procedure_controller - /v1/graph/{graph_id}/procedure/{procedure_id}: - delete: - description: Delete a stored procedure by ID - operationId: delete_procedure_by_id - parameters: - - explode: false - in: path - name: graph_id - required: true - schema: - type: string - style: simple - - explode: false - in: path - name: procedure_id - required: true - schema: - type: string - style: simple - responses: - "200": - content: - application/json: - schema: - $ref: '#/components/schemas/APIResponse' - description: Successfully deleted the stored procedure - "500": - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - description: Server error - tags: - - Procedure - x-openapi-router-controller: gs_flex_coordinator.controllers.procedure_controller - get: - description: Get a stored procedure by ID - operationId: get_procedure_by_id - parameters: - - explode: false - in: path - name: graph_id - required: true - schema: - type: string - style: simple - - explode: false - in: path - name: procedure_id - required: true - schema: - type: string - style: simple - responses: - "200": - content: - application/json: - example: - id: PROCEDUREID - name: procedure_name - type: cypher - query: MATCH(a) return COUNT(a); - library: /path/to/library - params: - - name: param1 - type: - string: - long_text: null - returns: - - name: return1 - type: - PrimitiveType: DT_SIGNED_INT64 - bound_graph: demo - runnable: true - schema: - $ref: '#/components/schemas/GetProcedureResponse' - description: Successfully returned the procedure - "500": - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - description: Server error - tags: - - Procedure - x-openapi-router-controller: gs_flex_coordinator.controllers.procedure_controller - put: - description: Update a stored procedure by ID - operationId: update_procedure_by_id - parameters: - - explode: false - in: path - name: graph_id - required: true - schema: - type: string - style: simple - - explode: false - in: path - name: procedure_id - required: true - schema: - type: string - style: simple - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/UpdateProcedureRequest' - responses: - "200": - content: - application/json: - schema: - $ref: '#/components/schemas/APIResponse' - description: Successfully updated the stored procedure - "500": - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - description: Server error - tags: - - Procedure - x-openapi-router-controller: gs_flex_coordinator.controllers.procedure_controller components: responses: "400": diff --git a/flex/openapi/openapi_coordinator.yaml b/flex/openapi/openapi_coordinator.yaml index eda59ec3d48e..bd5dfef6e0a8 100644 --- a/flex/openapi/openapi_coordinator.yaml +++ b/flex/openapi/openapi_coordinator.yaml @@ -1614,7 +1614,7 @@ paths: 500: $ref: "#/components/responses/500" - /v1/graph/{graph_id}/procedure: + /api/v1/graph/{graph_id}/procedure: post: tags: [Procedure] description: Create a new stored procedure on a certain graph @@ -1700,7 +1700,7 @@ paths: 500: $ref: "#/components/responses/500" - /v1/graph/{graph_id}/procedure/{procedure_id}: + /api/v1/graph/{graph_id}/procedure/{procedure_id}: get: tags: [Procedure] description: Get a stored procedure by ID diff --git a/python/graphscope/flex/rest/api/procedure_api.py b/python/graphscope/flex/rest/api/procedure_api.py index 686af4a625e1..f7ab039d81ab 100644 --- a/python/graphscope/flex/rest/api/procedure_api.py +++ b/python/graphscope/flex/rest/api/procedure_api.py @@ -317,7 +317,7 @@ def _create_procedure_serialize( return self.api_client.param_serialize( method='POST', - resource_path='/v1/graph/{graph_id}/procedure', + resource_path='/api/v1/graph/{graph_id}/procedure', path_params=_path_params, query_params=_query_params, header_params=_header_params, @@ -592,7 +592,7 @@ def _delete_procedure_by_id_serialize( return self.api_client.param_serialize( method='DELETE', - resource_path='/v1/graph/{graph_id}/procedure/{procedure_id}', + resource_path='/api/v1/graph/{graph_id}/procedure/{procedure_id}', path_params=_path_params, query_params=_query_params, header_params=_header_params, @@ -867,7 +867,7 @@ def _get_procedure_by_id_serialize( return self.api_client.param_serialize( method='GET', - resource_path='/v1/graph/{graph_id}/procedure/{procedure_id}', + resource_path='/api/v1/graph/{graph_id}/procedure/{procedure_id}', path_params=_path_params, query_params=_query_params, header_params=_header_params, @@ -1130,7 +1130,7 @@ def _list_procedures_serialize( return self.api_client.param_serialize( method='GET', - resource_path='/v1/graph/{graph_id}/procedure', + resource_path='/api/v1/graph/{graph_id}/procedure', path_params=_path_params, query_params=_query_params, header_params=_header_params, @@ -1433,7 +1433,7 @@ def _update_procedure_by_id_serialize( return self.api_client.param_serialize( method='PUT', - resource_path='/v1/graph/{graph_id}/procedure/{procedure_id}', + resource_path='/api/v1/graph/{graph_id}/procedure/{procedure_id}', path_params=_path_params, query_params=_query_params, header_params=_header_params, diff --git a/python/graphscope/gsctl/impl/__init__.py b/python/graphscope/gsctl/impl/__init__.py index b2ee74ea67ba..7f84689dfd4b 100644 --- a/python/graphscope/gsctl/impl/__init__.py +++ b/python/graphscope/gsctl/impl/__init__.py @@ -24,6 +24,7 @@ from graphscope.gsctl.impl.datasource import unbind_vertex_datasource from graphscope.gsctl.impl.graph import create_graph from graphscope.gsctl.impl.graph import delete_graph_by_id +from graphscope.gsctl.impl.graph import get_graph_id_by_name from graphscope.gsctl.impl.graph import list_graphs from graphscope.gsctl.impl.job import delete_job_by_id from graphscope.gsctl.impl.job import get_job_by_id @@ -38,6 +39,5 @@ from graphscope.gsctl.impl.service import restart_service from graphscope.gsctl.impl.service import start_service from graphscope.gsctl.impl.service import stop_service -from graphscope.gsctl.impl.utils import get_graph_id_by_name from graphscope.gsctl.impl.utils import switch_context from graphscope.gsctl.impl.utils import upload_file diff --git a/python/graphscope/gsctl/impl/graph.py b/python/graphscope/gsctl/impl/graph.py index ed091986b3d1..06399e7968d3 100644 --- a/python/graphscope/gsctl/impl/graph.py +++ b/python/graphscope/gsctl/impl/graph.py @@ -51,3 +51,22 @@ def delete_graph_by_id(graph_identifier: str) -> str: ) as api_client: api_instance = graphscope.flex.rest.GraphApi(api_client) return api_instance.delete_graph_by_id(graph_identifier) + + +def get_graph_id_by_name(name_or_id: str): + graphs = list_graphs() + id_candidate = [] + for g in graphs: + if name_or_id == g.id: + return name_or_id + if name_or_id == g.name: + id_candidate.append(g.id) + if not id_candidate: + raise RuntimeError( + f"Graph '{name_or_id}' not exists, see graph information with `ls` command." + ) + if len(id_candidate) > 1: + raise RuntimeError( + f"Found multiple id candidates {id_candidate} for graph {name_or_id}, please choose one." + ) + return id_candidate[0] diff --git a/python/graphscope/gsctl/impl/utils.py b/python/graphscope/gsctl/impl/utils.py index d5d57b632a50..cd30821bddfe 100644 --- a/python/graphscope/gsctl/impl/utils.py +++ b/python/graphscope/gsctl/impl/utils.py @@ -19,7 +19,6 @@ import graphscope.flex.rest from graphscope.gsctl.config import get_current_context from graphscope.gsctl.config import load_gs_config -from graphscope.gsctl.impl import list_graphs def upload_file(location: str) -> str: @@ -36,22 +35,3 @@ def switch_context(context: str): current_context = get_current_context() current_context.switch_context(context) config.update_and_write(current_context) - - -def get_graph_id_by_name(name_or_id: str): - graphs = list_graphs() - id_candidate = [] - for g in graphs: - if name_or_id == g.id: - return name_or_id - if name_or_id == g.name: - id_candidate.append(g.id) - if not id_candidate: - raise RuntimeError( - f"Graph '{name_or_id}' not exists, see graph information with `ls` command." - ) - if len(id_candidate) > 1: - raise RuntimeError( - f"Found multiple id candidates {id_candidate} for graph {name_or_id}, please choose one." - ) - return id_candidate[0]