gsctl 0.29.0a20250114__py2.py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. graphscope/flex/rest/__init__.py +106 -0
  2. graphscope/flex/rest/api/__init__.py +12 -0
  3. graphscope/flex/rest/api/alert_api.py +2790 -0
  4. graphscope/flex/rest/api/data_source_api.py +1177 -0
  5. graphscope/flex/rest/api/deployment_api.py +1323 -0
  6. graphscope/flex/rest/api/graph_api.py +2813 -0
  7. graphscope/flex/rest/api/job_api.py +1408 -0
  8. graphscope/flex/rest/api/service_api.py +1316 -0
  9. graphscope/flex/rest/api/stored_procedure_api.py +1454 -0
  10. graphscope/flex/rest/api/utils_api.py +310 -0
  11. graphscope/flex/rest/api_client.py +789 -0
  12. graphscope/flex/rest/api_response.py +21 -0
  13. graphscope/flex/rest/configuration.py +451 -0
  14. graphscope/flex/rest/exceptions.py +200 -0
  15. graphscope/flex/rest/models/__init__.py +82 -0
  16. graphscope/flex/rest/models/base_edge_type.py +102 -0
  17. graphscope/flex/rest/models/base_edge_type_vertex_type_pair_relations_inner.py +108 -0
  18. graphscope/flex/rest/models/base_edge_type_vertex_type_pair_relations_inner_x_csr_params.py +98 -0
  19. graphscope/flex/rest/models/base_property_meta.py +105 -0
  20. graphscope/flex/rest/models/base_vertex_type.py +96 -0
  21. graphscope/flex/rest/models/base_vertex_type_x_csr_params.py +88 -0
  22. graphscope/flex/rest/models/column_mapping.py +94 -0
  23. graphscope/flex/rest/models/column_mapping_column.py +90 -0
  24. graphscope/flex/rest/models/create_alert_receiver_request.py +103 -0
  25. graphscope/flex/rest/models/create_alert_rule_request.py +112 -0
  26. graphscope/flex/rest/models/create_dataloading_job_response.py +88 -0
  27. graphscope/flex/rest/models/create_edge_type.py +114 -0
  28. graphscope/flex/rest/models/create_graph_request.py +106 -0
  29. graphscope/flex/rest/models/create_graph_response.py +88 -0
  30. graphscope/flex/rest/models/create_graph_schema_request.py +106 -0
  31. graphscope/flex/rest/models/create_property_meta.py +105 -0
  32. graphscope/flex/rest/models/create_stored_proc_request.py +101 -0
  33. graphscope/flex/rest/models/create_stored_proc_response.py +88 -0
  34. graphscope/flex/rest/models/create_vertex_type.py +108 -0
  35. graphscope/flex/rest/models/dataloading_job_config.py +136 -0
  36. graphscope/flex/rest/models/dataloading_job_config_edges_inner.py +92 -0
  37. graphscope/flex/rest/models/dataloading_job_config_loading_config.py +104 -0
  38. graphscope/flex/rest/models/dataloading_job_config_loading_config_format.py +90 -0
  39. graphscope/flex/rest/models/dataloading_job_config_vertices_inner.py +88 -0
  40. graphscope/flex/rest/models/dataloading_mr_job_config.py +88 -0
  41. graphscope/flex/rest/models/date_type.py +88 -0
  42. graphscope/flex/rest/models/edge_mapping.py +122 -0
  43. graphscope/flex/rest/models/edge_mapping_type_triplet.py +92 -0
  44. graphscope/flex/rest/models/error.py +90 -0
  45. graphscope/flex/rest/models/get_alert_message_response.py +123 -0
  46. graphscope/flex/rest/models/get_alert_receiver_response.py +107 -0
  47. graphscope/flex/rest/models/get_alert_rule_response.py +114 -0
  48. graphscope/flex/rest/models/get_edge_type.py +116 -0
  49. graphscope/flex/rest/models/get_graph_response.py +139 -0
  50. graphscope/flex/rest/models/get_graph_schema_response.py +106 -0
  51. graphscope/flex/rest/models/get_pod_log_response.py +88 -0
  52. graphscope/flex/rest/models/get_property_meta.py +107 -0
  53. graphscope/flex/rest/models/get_resource_usage_response.py +105 -0
  54. graphscope/flex/rest/models/get_storage_usage_response.py +88 -0
  55. graphscope/flex/rest/models/get_stored_proc_response.py +130 -0
  56. graphscope/flex/rest/models/get_vertex_type.py +110 -0
  57. graphscope/flex/rest/models/gs_data_type.py +152 -0
  58. graphscope/flex/rest/models/job_status.py +107 -0
  59. graphscope/flex/rest/models/long_text.py +93 -0
  60. graphscope/flex/rest/models/node_status.py +94 -0
  61. graphscope/flex/rest/models/parameter.py +96 -0
  62. graphscope/flex/rest/models/pod_status.py +108 -0
  63. graphscope/flex/rest/models/primitive_type.py +95 -0
  64. graphscope/flex/rest/models/resource_usage.py +92 -0
  65. graphscope/flex/rest/models/running_deployment_info.py +128 -0
  66. graphscope/flex/rest/models/running_deployment_status.py +124 -0
  67. graphscope/flex/rest/models/schema_mapping.py +106 -0
  68. graphscope/flex/rest/models/service_status.py +112 -0
  69. graphscope/flex/rest/models/service_status_sdk_endpoints.py +94 -0
  70. graphscope/flex/rest/models/start_service_request.py +88 -0
  71. graphscope/flex/rest/models/stored_procedure_meta.py +126 -0
  72. graphscope/flex/rest/models/string_type.py +92 -0
  73. graphscope/flex/rest/models/string_type_string.py +124 -0
  74. graphscope/flex/rest/models/temporal_type.py +92 -0
  75. graphscope/flex/rest/models/temporal_type_temporal.py +138 -0
  76. graphscope/flex/rest/models/time_stamp_type.py +88 -0
  77. graphscope/flex/rest/models/update_alert_message_status_request.py +97 -0
  78. graphscope/flex/rest/models/update_stored_proc_request.py +88 -0
  79. graphscope/flex/rest/models/upload_file_response.py +90 -0
  80. graphscope/flex/rest/models/vertex_mapping.py +100 -0
  81. graphscope/flex/rest/py.typed +0 -0
  82. graphscope/flex/rest/rest.py +258 -0
  83. graphscope/gsctl/V6D_VERSION +1 -0
  84. graphscope/gsctl/VERSION +1 -0
  85. graphscope/gsctl/__init__.py +22 -0
  86. graphscope/gsctl/commands/__init__.py +148 -0
  87. graphscope/gsctl/commands/common.py +200 -0
  88. graphscope/gsctl/commands/dev.py +448 -0
  89. graphscope/gsctl/commands/insight/__init__.py +17 -0
  90. graphscope/gsctl/commands/insight/glob.py +234 -0
  91. graphscope/gsctl/commands/insight/graph.py +205 -0
  92. graphscope/gsctl/commands/interactive/__init__.py +17 -0
  93. graphscope/gsctl/commands/interactive/glob.py +280 -0
  94. graphscope/gsctl/commands/interactive/graph.py +259 -0
  95. graphscope/gsctl/config.py +221 -0
  96. graphscope/gsctl/gsctl.py +51 -0
  97. graphscope/gsctl/impl/__init__.py +64 -0
  98. graphscope/gsctl/impl/alert.py +135 -0
  99. graphscope/gsctl/impl/common.py +53 -0
  100. graphscope/gsctl/impl/datasource.py +80 -0
  101. graphscope/gsctl/impl/deployment.py +62 -0
  102. graphscope/gsctl/impl/graph.py +150 -0
  103. graphscope/gsctl/impl/job.py +63 -0
  104. graphscope/gsctl/impl/service.py +62 -0
  105. graphscope/gsctl/impl/stored_procedure.py +92 -0
  106. graphscope/gsctl/impl/utils.py +38 -0
  107. graphscope/gsctl/scripts/install_deps.sh +969 -0
  108. graphscope/gsctl/tests/__init__.py +17 -0
  109. graphscope/gsctl/tests/test_graphscope_insight.py +401 -0
  110. graphscope/gsctl/tests/test_interactive.py +516 -0
  111. graphscope/gsctl/utils.py +337 -0
  112. graphscope/gsctl/version.py +31 -0
  113. gsctl-0.29.0a20250114.dist-info/METADATA +20 -0
  114. gsctl-0.29.0a20250114.dist-info/RECORD +117 -0
  115. gsctl-0.29.0a20250114.dist-info/WHEEL +6 -0
  116. gsctl-0.29.0a20250114.dist-info/entry_points.txt +3 -0
  117. gsctl-0.29.0a20250114.dist-info/top_level.txt +1 -0
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # Copyright 2024 Alibaba Group Holding Limited. All Rights Reserved.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ from typing import List
20
+
21
+ import graphscope.flex.rest
22
+ from graphscope.flex.rest import CreateAlertReceiverRequest
23
+ from graphscope.flex.rest import CreateAlertRuleRequest
24
+ from graphscope.flex.rest import GetAlertMessageResponse
25
+ from graphscope.flex.rest import GetAlertReceiverResponse
26
+ from graphscope.flex.rest import GetAlertRuleResponse
27
+ from graphscope.flex.rest import UpdateAlertMessageStatusRequest
28
+ from graphscope.gsctl.config import get_current_context
29
+
30
+
31
+ def list_alert_rules() -> List[GetAlertRuleResponse]:
32
+ context = get_current_context()
33
+ with graphscope.flex.rest.ApiClient(
34
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
35
+ ) as api_client:
36
+ api_instance = graphscope.flex.rest.AlertApi(api_client)
37
+ return api_instance.list_alert_rules()
38
+
39
+
40
+ def update_alert_rule_by_id(rule_id: str, rule: dict) -> str:
41
+ context = get_current_context()
42
+ with graphscope.flex.rest.ApiClient(
43
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
44
+ ) as api_client:
45
+ api_instance = graphscope.flex.rest.AlertApi(api_client)
46
+ return api_instance.update_alert_rule_by_id(
47
+ rule_id, CreateAlertRuleRequest.from_dict(rule)
48
+ )
49
+
50
+
51
+ def delete_alert_rule_by_id(rule_id: str) -> str:
52
+ context = get_current_context()
53
+ with graphscope.flex.rest.ApiClient(
54
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
55
+ ) as api_client:
56
+ api_instance = graphscope.flex.rest.AlertApi(api_client)
57
+ return api_instance.delete_alert_rule_by_id(rule_id)
58
+
59
+
60
+ def list_alert_messages(
61
+ alert_type=None,
62
+ status=None,
63
+ severity=None,
64
+ start_time=None,
65
+ end_time=None,
66
+ limit=None,
67
+ ) -> List[GetAlertMessageResponse]:
68
+ context = get_current_context()
69
+ with graphscope.flex.rest.ApiClient(
70
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
71
+ ) as api_client:
72
+ api_instance = graphscope.flex.rest.AlertApi(api_client)
73
+ return api_instance.list_alert_messages(
74
+ alert_type, status, severity, start_time, end_time, limit
75
+ )
76
+
77
+
78
+ def update_alert_message_in_batch(message_status: dict) -> str:
79
+ context = get_current_context()
80
+ with graphscope.flex.rest.ApiClient(
81
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
82
+ ) as api_client:
83
+ api_instance = graphscope.flex.rest.AlertApi(api_client)
84
+ return api_instance.update_alert_message_in_batch(
85
+ UpdateAlertMessageStatusRequest.from_dict(message_status)
86
+ )
87
+
88
+
89
+ def delete_alert_message_in_batch(message_ids: str) -> str:
90
+ context = get_current_context()
91
+ with graphscope.flex.rest.ApiClient(
92
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
93
+ ) as api_client:
94
+ api_instance = graphscope.flex.rest.AlertApi(api_client)
95
+ return api_instance.delete_alert_message_in_batch(message_ids)
96
+
97
+
98
+ def create_alert_receiver(receiver: dict) -> str:
99
+ context = get_current_context()
100
+ with graphscope.flex.rest.ApiClient(
101
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
102
+ ) as api_client:
103
+ api_instance = graphscope.flex.rest.AlertApi(api_client)
104
+ return api_instance.create_alert_receiver(
105
+ CreateAlertReceiverRequest.from_dict(receiver)
106
+ )
107
+
108
+
109
+ def update_alert_receiver_by_id(receiver_id: str, receiver: dict) -> str:
110
+ context = get_current_context()
111
+ with graphscope.flex.rest.ApiClient(
112
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
113
+ ) as api_client:
114
+ api_instance = graphscope.flex.rest.AlertApi(api_client)
115
+ return api_instance.update_alert_receiver_by_id(
116
+ receiver_id, CreateAlertReceiverRequest.from_dict(receiver)
117
+ )
118
+
119
+
120
+ def list_alert_receivers() -> List[GetAlertReceiverResponse]:
121
+ context = get_current_context()
122
+ with graphscope.flex.rest.ApiClient(
123
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
124
+ ) as api_client:
125
+ api_instance = graphscope.flex.rest.AlertApi(api_client)
126
+ return api_instance.list_alert_receivers()
127
+
128
+
129
+ def delete_alert_receiver_by_id(receiver_id: str) -> str:
130
+ context = get_current_context()
131
+ with graphscope.flex.rest.ApiClient(
132
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
133
+ ) as api_client:
134
+ api_instance = graphscope.flex.rest.AlertApi(api_client)
135
+ return api_instance.delete_alert_receiver_by_id(receiver_id)
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # Copyright 2024 Alibaba Group Holding Limited. All Rights Reserved.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ from typing import Union
20
+
21
+ import graphscope.flex.rest
22
+ from graphscope.flex.rest import RunningDeploymentInfo
23
+ from graphscope.gsctl.config import Context
24
+ from graphscope.gsctl.config import load_gs_config
25
+
26
+
27
+ def connect_coordinator(coordinator_endpoint: str) -> RunningDeploymentInfo:
28
+ with graphscope.flex.rest.ApiClient(
29
+ graphscope.flex.rest.Configuration(coordinator_endpoint)
30
+ ) as api_client:
31
+ api_instance = graphscope.flex.rest.DeploymentApi(api_client)
32
+ deployment_info = api_instance.get_deployment_info()
33
+ # coordinator connected, set the context
34
+ flex = {
35
+ "engine": deployment_info.engine,
36
+ "storage": deployment_info.storage,
37
+ "frontend": deployment_info.frontend,
38
+ }
39
+ context = Context(
40
+ flex=flex,
41
+ coordinator_endpoint=coordinator_endpoint,
42
+ )
43
+ config = load_gs_config()
44
+ config.set_and_write(context)
45
+ return deployment_info
46
+
47
+
48
+ def disconnect_coordinator() -> Union[None, Context]:
49
+ config = load_gs_config()
50
+ current_context = config.current_context()
51
+ if current_context is not None:
52
+ config.remove_and_write(current_context)
53
+ return current_context
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # Copyright 2024 Alibaba Group Holding Limited. All Rights Reserved.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ import itertools
20
+ import os
21
+
22
+ import graphscope.flex.rest
23
+ from graphscope.flex.rest import SchemaMapping
24
+ from graphscope.gsctl.config import get_current_context
25
+ from graphscope.gsctl.impl.utils import upload_file
26
+
27
+
28
+ def bind_datasource_in_batch(graph_identifier: str, datasource: dict) -> str:
29
+ # upload files
30
+ for mapping in itertools.chain(
31
+ datasource["vertex_mappings"], datasource["edge_mappings"]
32
+ ):
33
+ for index, location in enumerate(mapping["inputs"]):
34
+ # path begin with "@" represents the local file
35
+ if location.startswith("@"):
36
+ location = location[1:]
37
+ mapping["inputs"][index] = upload_file(location)
38
+ # bind data source
39
+ context = get_current_context()
40
+ with graphscope.flex.rest.ApiClient(
41
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
42
+ ) as api_client:
43
+ api_instance = graphscope.flex.rest.DataSourceApi(api_client)
44
+ return api_instance.bind_datasource_in_batch(
45
+ graph_identifier, SchemaMapping.from_dict(datasource)
46
+ )
47
+
48
+
49
+ def get_datasource_by_id(graph_identifier: str) -> SchemaMapping:
50
+ context = get_current_context()
51
+ with graphscope.flex.rest.ApiClient(
52
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
53
+ ) as api_client:
54
+ api_instance = graphscope.flex.rest.DataSourceApi(api_client)
55
+ return api_instance.get_datasource_by_id(graph_identifier)
56
+
57
+
58
+ def unbind_vertex_datasource(graph_identifier: str, vertex_type: str) -> str:
59
+ context = get_current_context()
60
+ with graphscope.flex.rest.ApiClient(
61
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
62
+ ) as api_client:
63
+ api_instance = graphscope.flex.rest.DataSourceApi(api_client)
64
+ return api_instance.unbind_vertex_datasource(graph_identifier, vertex_type)
65
+
66
+
67
+ def unbind_edge_datasource(
68
+ graph_identifier: str,
69
+ vertex_type: str,
70
+ source_vertex_type: str,
71
+ destination_vertex_type: str,
72
+ ) -> str:
73
+ context = get_current_context()
74
+ with graphscope.flex.rest.ApiClient(
75
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
76
+ ) as api_client:
77
+ api_instance = graphscope.flex.rest.DataSourceApi(api_client)
78
+ return api_instance.unbind_edge_datasource(
79
+ graph_identifier, vertex_type, source_vertex_type, destination_vertex_type
80
+ )
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # Copyright 2024 Alibaba Group Holding Limited. All Rights Reserved.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ import graphscope.flex.rest
20
+ from graphscope.flex.rest import GetPodLogResponse
21
+ from graphscope.flex.rest import GetResourceUsageResponse
22
+ from graphscope.flex.rest import GetStorageUsageResponse
23
+ from graphscope.flex.rest import RunningDeploymentStatus
24
+ from graphscope.gsctl.config import get_current_context
25
+
26
+
27
+ def get_deployment_status() -> RunningDeploymentStatus:
28
+ context = get_current_context()
29
+ with graphscope.flex.rest.ApiClient(
30
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
31
+ ) as api_client:
32
+ api_instance = graphscope.flex.rest.DeploymentApi(api_client)
33
+ return api_instance.get_deployment_status()
34
+
35
+
36
+ def get_deployment_resource_usage() -> GetResourceUsageResponse:
37
+ context = get_current_context()
38
+ with graphscope.flex.rest.ApiClient(
39
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
40
+ ) as api_client:
41
+ api_instance = graphscope.flex.rest.DeploymentApi(api_client)
42
+ return api_instance.get_deployment_resource_usage()
43
+
44
+
45
+ def get_storage_usage() -> GetStorageUsageResponse:
46
+ context = get_current_context()
47
+ with graphscope.flex.rest.ApiClient(
48
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
49
+ ) as api_client:
50
+ api_instance = graphscope.flex.rest.DeploymentApi(api_client)
51
+ return api_instance.get_storage_usage()
52
+
53
+
54
+ def get_deployment_pod_log(
55
+ pod_name: str, component: str, from_cache: bool
56
+ ) -> GetPodLogResponse:
57
+ context = get_current_context()
58
+ with graphscope.flex.rest.ApiClient(
59
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
60
+ ) as api_client:
61
+ api_instance = graphscope.flex.rest.DeploymentApi(api_client)
62
+ return api_instance.get_deployment_pod_log(pod_name, component, from_cache)
@@ -0,0 +1,150 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # Copyright 2024 Alibaba Group Holding Limited. All Rights Reserved.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ from typing import List
20
+
21
+ import graphscope.flex.rest
22
+ from graphscope.flex.rest import CreateEdgeType
23
+ from graphscope.flex.rest import CreateGraphRequest
24
+ from graphscope.flex.rest import CreateGraphSchemaRequest
25
+ from graphscope.flex.rest import CreateVertexType
26
+ from graphscope.flex.rest import GetGraphResponse
27
+ from graphscope.gsctl.config import get_current_context
28
+
29
+
30
+ def import_schema(graph_identifier: str, schema: dict) -> str:
31
+ context = get_current_context()
32
+ with graphscope.flex.rest.ApiClient(
33
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
34
+ ) as api_client:
35
+ api_instance = graphscope.flex.rest.GraphApi(api_client)
36
+ return api_instance.import_schema_by_id(
37
+ graph_identifier, CreateGraphSchemaRequest.from_dict(schema)
38
+ )
39
+
40
+
41
+ def create_vertex_type(graph_identifier: str, vertex_type: dict) -> str:
42
+ context = get_current_context()
43
+ with graphscope.flex.rest.ApiClient(
44
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
45
+ ) as api_client:
46
+ api_instance = graphscope.flex.rest.GraphApi(api_client)
47
+ return api_instance.create_vertex_type(
48
+ graph_identifier, CreateVertexType.from_dict(vertex_type)
49
+ )
50
+
51
+
52
+ def delete_vertex_type_by_name(graph_identifier: str, vertex_type: str) -> str:
53
+ context = get_current_context()
54
+ with graphscope.flex.rest.ApiClient(
55
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
56
+ ) as api_client:
57
+ api_instance = graphscope.flex.rest.GraphApi(api_client)
58
+ return api_instance.delete_vertex_type_by_name(graph_identifier, vertex_type)
59
+
60
+
61
+ def create_edge_type(graph_identifier: str, edge_type: dict) -> str:
62
+ context = get_current_context()
63
+ with graphscope.flex.rest.ApiClient(
64
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
65
+ ) as api_client:
66
+ api_instance = graphscope.flex.rest.GraphApi(api_client)
67
+ return api_instance.create_edge_type(
68
+ graph_identifier, CreateEdgeType.from_dict(edge_type)
69
+ )
70
+
71
+
72
+ def delete_edge_type_by_name(
73
+ graph_identifier: str,
74
+ edge_type: str,
75
+ source_vertex_type: str,
76
+ destination_vertex_type: str,
77
+ ) -> str:
78
+ context = get_current_context()
79
+ with graphscope.flex.rest.ApiClient(
80
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
81
+ ) as api_client:
82
+ api_instance = graphscope.flex.rest.GraphApi(api_client)
83
+ return api_instance.delete_edge_type_by_name(
84
+ graph_identifier, edge_type, source_vertex_type, destination_vertex_type
85
+ )
86
+
87
+
88
+ def list_graphs() -> List[GetGraphResponse]:
89
+ context = get_current_context()
90
+ with graphscope.flex.rest.ApiClient(
91
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
92
+ ) as api_client:
93
+ api_instance = graphscope.flex.rest.GraphApi(api_client)
94
+ graphs = api_instance.list_graphs()
95
+ return graphs
96
+
97
+
98
+ def get_graph_by_id(graph_identifier: str) -> GetGraphResponse:
99
+ context = get_current_context()
100
+ with graphscope.flex.rest.ApiClient(
101
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
102
+ ) as api_client:
103
+ api_instance = graphscope.flex.rest.GraphApi(api_client)
104
+ return api_instance.get_graph_by_id(graph_identifier)
105
+
106
+
107
+ def create_graph(graph: dict) -> str:
108
+ context = get_current_context()
109
+ with graphscope.flex.rest.ApiClient(
110
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
111
+ ) as api_client:
112
+ api_instance = graphscope.flex.rest.GraphApi(api_client)
113
+ response = api_instance.create_graph(CreateGraphRequest.from_dict(graph))
114
+ return response.graph_id
115
+
116
+
117
+ def delete_graph_by_id(graph_identifier: str) -> str:
118
+ context = get_current_context()
119
+ with graphscope.flex.rest.ApiClient(
120
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
121
+ ) as api_client:
122
+ api_instance = graphscope.flex.rest.GraphApi(api_client)
123
+ return api_instance.delete_graph_by_id(graph_identifier)
124
+
125
+
126
+ def get_graph_id_by_name(name_or_id: str):
127
+ graphs = list_graphs()
128
+ id_candidate = []
129
+ for g in graphs:
130
+ if name_or_id == g.id:
131
+ return name_or_id
132
+ if name_or_id == g.name:
133
+ id_candidate.append(g.id)
134
+ if not id_candidate:
135
+ raise RuntimeError(
136
+ f"Graph '{name_or_id}' not exists, see graph information with `ls` command."
137
+ )
138
+ if len(id_candidate) > 1:
139
+ raise RuntimeError(
140
+ f"Found multiple id candidates {id_candidate} for graph {name_or_id}, please choose one."
141
+ )
142
+ return id_candidate[0]
143
+
144
+
145
+ def get_graph_name_by_id(graph_identifier: str):
146
+ graphs = list_graphs()
147
+ for g in graphs:
148
+ if g.id == graph_identifier:
149
+ return g.name
150
+ return graph_identifier
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # Copyright 2024 Alibaba Group Holding Limited. All Rights Reserved.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ from typing import List
20
+
21
+ import graphscope.flex.rest
22
+ from graphscope.flex.rest import DataloadingJobConfig
23
+ from graphscope.flex.rest import JobStatus
24
+ from graphscope.gsctl.config import get_current_context
25
+
26
+
27
+ def submit_dataloading_job(graph_identifier: str, config: dict) -> str:
28
+ context = get_current_context()
29
+ with graphscope.flex.rest.ApiClient(
30
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
31
+ ) as api_client:
32
+ api_instance = graphscope.flex.rest.JobApi(api_client)
33
+ response = api_instance.submit_dataloading_job(
34
+ graph_identifier, DataloadingJobConfig.from_dict(config)
35
+ )
36
+ return response.job_id
37
+
38
+
39
+ def list_jobs() -> List[JobStatus]:
40
+ context = get_current_context()
41
+ with graphscope.flex.rest.ApiClient(
42
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
43
+ ) as api_client:
44
+ api_instance = graphscope.flex.rest.JobApi(api_client)
45
+ return api_instance.list_jobs()
46
+
47
+
48
+ def delete_job_by_id(job_identifier: str, delete_scheduler=False) -> str:
49
+ context = get_current_context()
50
+ with graphscope.flex.rest.ApiClient(
51
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
52
+ ) as api_client:
53
+ api_instance = graphscope.flex.rest.JobApi(api_client)
54
+ return api_instance.delete_job_by_id(job_identifier, delete_scheduler)
55
+
56
+
57
+ def get_job_by_id(job_identifier: str) -> JobStatus:
58
+ context = get_current_context()
59
+ with graphscope.flex.rest.ApiClient(
60
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
61
+ ) as api_client:
62
+ api_instance = graphscope.flex.rest.JobApi(api_client)
63
+ return api_instance.get_job_by_id(job_identifier)
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # Copyright 2024 Alibaba Group Holding Limited. All Rights Reserved.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ from typing import List
20
+
21
+ import graphscope.flex.rest
22
+ from graphscope.flex.rest import ServiceStatus
23
+ from graphscope.flex.rest import StartServiceRequest
24
+ from graphscope.gsctl.config import get_current_context
25
+
26
+
27
+ def list_service_status() -> List[ServiceStatus]:
28
+ context = get_current_context()
29
+ with graphscope.flex.rest.ApiClient(
30
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
31
+ ) as api_client:
32
+ api_instance = graphscope.flex.rest.ServiceApi(api_client)
33
+ return api_instance.list_service_status()
34
+
35
+
36
+ def start_service(graph_identifier: str) -> str:
37
+ context = get_current_context()
38
+ with graphscope.flex.rest.ApiClient(
39
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
40
+ ) as api_client:
41
+ api_instance = graphscope.flex.rest.ServiceApi(api_client)
42
+ return api_instance.start_service(
43
+ StartServiceRequest.from_dict({"graph_id": graph_identifier})
44
+ )
45
+
46
+
47
+ def stop_service() -> str:
48
+ context = get_current_context()
49
+ with graphscope.flex.rest.ApiClient(
50
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
51
+ ) as api_client:
52
+ api_instance = graphscope.flex.rest.ServiceApi(api_client)
53
+ return api_instance.stop_service()
54
+
55
+
56
+ def restart_service() -> str:
57
+ context = get_current_context()
58
+ with graphscope.flex.rest.ApiClient(
59
+ graphscope.flex.rest.Configuration(context.coordinator_endpoint)
60
+ ) as api_client:
61
+ api_instance = graphscope.flex.rest.ServiceApi(api_client)
62
+ return api_instance.restart_service()