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.
- graphscope/flex/rest/__init__.py +106 -0
- graphscope/flex/rest/api/__init__.py +12 -0
- graphscope/flex/rest/api/alert_api.py +2790 -0
- graphscope/flex/rest/api/data_source_api.py +1177 -0
- graphscope/flex/rest/api/deployment_api.py +1323 -0
- graphscope/flex/rest/api/graph_api.py +2813 -0
- graphscope/flex/rest/api/job_api.py +1408 -0
- graphscope/flex/rest/api/service_api.py +1316 -0
- graphscope/flex/rest/api/stored_procedure_api.py +1454 -0
- graphscope/flex/rest/api/utils_api.py +310 -0
- graphscope/flex/rest/api_client.py +789 -0
- graphscope/flex/rest/api_response.py +21 -0
- graphscope/flex/rest/configuration.py +451 -0
- graphscope/flex/rest/exceptions.py +200 -0
- graphscope/flex/rest/models/__init__.py +82 -0
- graphscope/flex/rest/models/base_edge_type.py +102 -0
- graphscope/flex/rest/models/base_edge_type_vertex_type_pair_relations_inner.py +108 -0
- graphscope/flex/rest/models/base_edge_type_vertex_type_pair_relations_inner_x_csr_params.py +98 -0
- graphscope/flex/rest/models/base_property_meta.py +105 -0
- graphscope/flex/rest/models/base_vertex_type.py +96 -0
- graphscope/flex/rest/models/base_vertex_type_x_csr_params.py +88 -0
- graphscope/flex/rest/models/column_mapping.py +94 -0
- graphscope/flex/rest/models/column_mapping_column.py +90 -0
- graphscope/flex/rest/models/create_alert_receiver_request.py +103 -0
- graphscope/flex/rest/models/create_alert_rule_request.py +112 -0
- graphscope/flex/rest/models/create_dataloading_job_response.py +88 -0
- graphscope/flex/rest/models/create_edge_type.py +114 -0
- graphscope/flex/rest/models/create_graph_request.py +106 -0
- graphscope/flex/rest/models/create_graph_response.py +88 -0
- graphscope/flex/rest/models/create_graph_schema_request.py +106 -0
- graphscope/flex/rest/models/create_property_meta.py +105 -0
- graphscope/flex/rest/models/create_stored_proc_request.py +101 -0
- graphscope/flex/rest/models/create_stored_proc_response.py +88 -0
- graphscope/flex/rest/models/create_vertex_type.py +108 -0
- graphscope/flex/rest/models/dataloading_job_config.py +136 -0
- graphscope/flex/rest/models/dataloading_job_config_edges_inner.py +92 -0
- graphscope/flex/rest/models/dataloading_job_config_loading_config.py +104 -0
- graphscope/flex/rest/models/dataloading_job_config_loading_config_format.py +90 -0
- graphscope/flex/rest/models/dataloading_job_config_vertices_inner.py +88 -0
- graphscope/flex/rest/models/dataloading_mr_job_config.py +88 -0
- graphscope/flex/rest/models/date_type.py +88 -0
- graphscope/flex/rest/models/edge_mapping.py +122 -0
- graphscope/flex/rest/models/edge_mapping_type_triplet.py +92 -0
- graphscope/flex/rest/models/error.py +90 -0
- graphscope/flex/rest/models/get_alert_message_response.py +123 -0
- graphscope/flex/rest/models/get_alert_receiver_response.py +107 -0
- graphscope/flex/rest/models/get_alert_rule_response.py +114 -0
- graphscope/flex/rest/models/get_edge_type.py +116 -0
- graphscope/flex/rest/models/get_graph_response.py +139 -0
- graphscope/flex/rest/models/get_graph_schema_response.py +106 -0
- graphscope/flex/rest/models/get_pod_log_response.py +88 -0
- graphscope/flex/rest/models/get_property_meta.py +107 -0
- graphscope/flex/rest/models/get_resource_usage_response.py +105 -0
- graphscope/flex/rest/models/get_storage_usage_response.py +88 -0
- graphscope/flex/rest/models/get_stored_proc_response.py +130 -0
- graphscope/flex/rest/models/get_vertex_type.py +110 -0
- graphscope/flex/rest/models/gs_data_type.py +152 -0
- graphscope/flex/rest/models/job_status.py +107 -0
- graphscope/flex/rest/models/long_text.py +93 -0
- graphscope/flex/rest/models/node_status.py +94 -0
- graphscope/flex/rest/models/parameter.py +96 -0
- graphscope/flex/rest/models/pod_status.py +108 -0
- graphscope/flex/rest/models/primitive_type.py +95 -0
- graphscope/flex/rest/models/resource_usage.py +92 -0
- graphscope/flex/rest/models/running_deployment_info.py +128 -0
- graphscope/flex/rest/models/running_deployment_status.py +124 -0
- graphscope/flex/rest/models/schema_mapping.py +106 -0
- graphscope/flex/rest/models/service_status.py +112 -0
- graphscope/flex/rest/models/service_status_sdk_endpoints.py +94 -0
- graphscope/flex/rest/models/start_service_request.py +88 -0
- graphscope/flex/rest/models/stored_procedure_meta.py +126 -0
- graphscope/flex/rest/models/string_type.py +92 -0
- graphscope/flex/rest/models/string_type_string.py +124 -0
- graphscope/flex/rest/models/temporal_type.py +92 -0
- graphscope/flex/rest/models/temporal_type_temporal.py +138 -0
- graphscope/flex/rest/models/time_stamp_type.py +88 -0
- graphscope/flex/rest/models/update_alert_message_status_request.py +97 -0
- graphscope/flex/rest/models/update_stored_proc_request.py +88 -0
- graphscope/flex/rest/models/upload_file_response.py +90 -0
- graphscope/flex/rest/models/vertex_mapping.py +100 -0
- graphscope/flex/rest/py.typed +0 -0
- graphscope/flex/rest/rest.py +258 -0
- graphscope/gsctl/V6D_VERSION +1 -0
- graphscope/gsctl/VERSION +1 -0
- graphscope/gsctl/__init__.py +22 -0
- graphscope/gsctl/commands/__init__.py +148 -0
- graphscope/gsctl/commands/common.py +200 -0
- graphscope/gsctl/commands/dev.py +448 -0
- graphscope/gsctl/commands/insight/__init__.py +17 -0
- graphscope/gsctl/commands/insight/glob.py +234 -0
- graphscope/gsctl/commands/insight/graph.py +205 -0
- graphscope/gsctl/commands/interactive/__init__.py +17 -0
- graphscope/gsctl/commands/interactive/glob.py +280 -0
- graphscope/gsctl/commands/interactive/graph.py +259 -0
- graphscope/gsctl/config.py +221 -0
- graphscope/gsctl/gsctl.py +51 -0
- graphscope/gsctl/impl/__init__.py +64 -0
- graphscope/gsctl/impl/alert.py +135 -0
- graphscope/gsctl/impl/common.py +53 -0
- graphscope/gsctl/impl/datasource.py +80 -0
- graphscope/gsctl/impl/deployment.py +62 -0
- graphscope/gsctl/impl/graph.py +150 -0
- graphscope/gsctl/impl/job.py +63 -0
- graphscope/gsctl/impl/service.py +62 -0
- graphscope/gsctl/impl/stored_procedure.py +92 -0
- graphscope/gsctl/impl/utils.py +38 -0
- graphscope/gsctl/scripts/install_deps.sh +969 -0
- graphscope/gsctl/tests/__init__.py +17 -0
- graphscope/gsctl/tests/test_graphscope_insight.py +401 -0
- graphscope/gsctl/tests/test_interactive.py +516 -0
- graphscope/gsctl/utils.py +337 -0
- graphscope/gsctl/version.py +31 -0
- gsctl-0.29.0a20250114.dist-info/METADATA +20 -0
- gsctl-0.29.0a20250114.dist-info/RECORD +117 -0
- gsctl-0.29.0a20250114.dist-info/WHEEL +6 -0
- gsctl-0.29.0a20250114.dist-info/entry_points.txt +3 -0
- gsctl-0.29.0a20250114.dist-info/top_level.txt +1 -0
@@ -0,0 +1,259 @@
|
|
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 click
|
20
|
+
import yaml
|
21
|
+
|
22
|
+
from graphscope.gsctl.config import get_current_context
|
23
|
+
from graphscope.gsctl.impl import create_stored_procedure
|
24
|
+
from graphscope.gsctl.impl import delete_stored_procedure_by_id
|
25
|
+
from graphscope.gsctl.impl import get_datasource_by_id
|
26
|
+
from graphscope.gsctl.impl import get_graph_name_by_id
|
27
|
+
from graphscope.gsctl.impl import list_graphs
|
28
|
+
from graphscope.gsctl.impl import list_service_status
|
29
|
+
from graphscope.gsctl.impl import list_stored_procedures
|
30
|
+
from graphscope.gsctl.impl import restart_service
|
31
|
+
from graphscope.gsctl.impl import start_service
|
32
|
+
from graphscope.gsctl.impl import stop_service
|
33
|
+
from graphscope.gsctl.impl import switch_context
|
34
|
+
from graphscope.gsctl.utils import TreeDisplay
|
35
|
+
from graphscope.gsctl.utils import err
|
36
|
+
from graphscope.gsctl.utils import info
|
37
|
+
from graphscope.gsctl.utils import is_valid_file_path
|
38
|
+
from graphscope.gsctl.utils import read_yaml_file
|
39
|
+
from graphscope.gsctl.utils import succ
|
40
|
+
from graphscope.gsctl.utils import terminal_display
|
41
|
+
|
42
|
+
|
43
|
+
@click.group()
|
44
|
+
def cli():
|
45
|
+
pass
|
46
|
+
|
47
|
+
|
48
|
+
@cli.group()
|
49
|
+
def create():
|
50
|
+
"""Create stored procedure from file"""
|
51
|
+
pass
|
52
|
+
|
53
|
+
|
54
|
+
@cli.group()
|
55
|
+
def delete():
|
56
|
+
"""Delete stored procedure by id"""
|
57
|
+
pass
|
58
|
+
|
59
|
+
|
60
|
+
@cli.group()
|
61
|
+
def desc():
|
62
|
+
"""Show stored procedure's details by id"""
|
63
|
+
pass
|
64
|
+
|
65
|
+
|
66
|
+
@cli.group()
|
67
|
+
def service():
|
68
|
+
"""Start, stop, and restart the database service"""
|
69
|
+
pass
|
70
|
+
|
71
|
+
|
72
|
+
@cli.group()
|
73
|
+
def use():
|
74
|
+
"""Switch back to the global scope"""
|
75
|
+
pass
|
76
|
+
|
77
|
+
|
78
|
+
@cli.command()
|
79
|
+
def ls(): # noqa: F811
|
80
|
+
"""Display schema and stored procedure information"""
|
81
|
+
tree = TreeDisplay()
|
82
|
+
# context
|
83
|
+
current_context = get_current_context()
|
84
|
+
try:
|
85
|
+
graphs = list_graphs()
|
86
|
+
using_graph = None
|
87
|
+
for g in graphs:
|
88
|
+
if g.id == current_context.context:
|
89
|
+
using_graph = g
|
90
|
+
break
|
91
|
+
# schema
|
92
|
+
tree.create_graph_node(using_graph)
|
93
|
+
# data source mapping
|
94
|
+
datasource_mapping = get_datasource_by_id(using_graph.id)
|
95
|
+
tree.create_datasource_mapping_node(using_graph, datasource_mapping)
|
96
|
+
# stored procedure
|
97
|
+
stored_procedures = list_stored_procedures(using_graph.id)
|
98
|
+
tree.create_stored_procedure_node(using_graph, stored_procedures)
|
99
|
+
except Exception as e:
|
100
|
+
err(f"Failed to display graph information: {str(e)}")
|
101
|
+
else:
|
102
|
+
tree.show(graph_identifier=current_context.context)
|
103
|
+
|
104
|
+
|
105
|
+
@create.command()
|
106
|
+
@click.option(
|
107
|
+
"-f",
|
108
|
+
"--filename",
|
109
|
+
required=True,
|
110
|
+
help="Path of yaml file",
|
111
|
+
)
|
112
|
+
def storedproc(filename):
|
113
|
+
"""Create a stored procedure from file"""
|
114
|
+
if not is_valid_file_path(filename):
|
115
|
+
err(f"Invalid file: {filename}")
|
116
|
+
return
|
117
|
+
current_context = get_current_context()
|
118
|
+
graph_identifier = current_context.context
|
119
|
+
try:
|
120
|
+
stored_procedure = read_yaml_file(filename)
|
121
|
+
create_stored_procedure(graph_identifier, stored_procedure)
|
122
|
+
except Exception as e:
|
123
|
+
err(f"Failed to create stored procedure: {str(e)}")
|
124
|
+
else:
|
125
|
+
succ(f"Create stored procedure {stored_procedure['name']} successfully.")
|
126
|
+
|
127
|
+
|
128
|
+
@delete.command()
|
129
|
+
@click.argument("identifier", required=True)
|
130
|
+
def storedproc(identifier): # noqa: F811
|
131
|
+
"""Delete a stored procedure, see identifier with `ls` command"""
|
132
|
+
current_context = get_current_context()
|
133
|
+
graph_identifier = current_context.context
|
134
|
+
try:
|
135
|
+
if click.confirm("Do you want to continue?"):
|
136
|
+
delete_stored_procedure_by_id(graph_identifier, identifier)
|
137
|
+
succ(f"Delete stored procedure {identifier} successfully.")
|
138
|
+
except Exception as e:
|
139
|
+
err(f"Failed to delete stored procedure: {str(e)}")
|
140
|
+
|
141
|
+
|
142
|
+
@desc.command()
|
143
|
+
@click.argument("identifier", required=True)
|
144
|
+
def storedproc(identifier): # noqa: F811
|
145
|
+
"""Show details of stored procedure, see identifier with `ls` command"""
|
146
|
+
current_context = get_current_context()
|
147
|
+
graph_id = current_context.context
|
148
|
+
try:
|
149
|
+
stored_procedures = list_stored_procedures(graph_id)
|
150
|
+
except Exception as e:
|
151
|
+
err(f"Failed to list stored procedures: {str(e)}")
|
152
|
+
else:
|
153
|
+
if not stored_procedures:
|
154
|
+
info(f"No stored procedures found on {graph_id}.")
|
155
|
+
return
|
156
|
+
specific_stored_procedure_exist = False
|
157
|
+
for stored_procedure in stored_procedures:
|
158
|
+
if identifier == stored_procedure.id:
|
159
|
+
info(yaml.dump(stored_procedure.to_dict()))
|
160
|
+
specific_stored_procedure_exist = True
|
161
|
+
break
|
162
|
+
if not specific_stored_procedure_exist:
|
163
|
+
err(f"Stored Procedure {identifier} not found on {graph_id}.")
|
164
|
+
|
165
|
+
|
166
|
+
@service.command
|
167
|
+
def stop(): # noqa: F811
|
168
|
+
"""Stop current database service"""
|
169
|
+
try:
|
170
|
+
stop_service()
|
171
|
+
except Exception as e:
|
172
|
+
err(f"Failed to stop service: {str(e)}")
|
173
|
+
else:
|
174
|
+
succ("Service stopped.")
|
175
|
+
|
176
|
+
|
177
|
+
@service.command
|
178
|
+
def start(): # noqa: F811
|
179
|
+
"""Start current database service"""
|
180
|
+
try:
|
181
|
+
current_context = get_current_context()
|
182
|
+
graph_identifier = current_context.context
|
183
|
+
|
184
|
+
status = list_service_status()
|
185
|
+
for s in status:
|
186
|
+
if s.graph_id == graph_identifier:
|
187
|
+
if s.status != "Running":
|
188
|
+
info(f"Starting service on graph {graph_identifier}...")
|
189
|
+
start_service(graph_identifier)
|
190
|
+
succ("Service restarted.")
|
191
|
+
else:
|
192
|
+
info("Service is running...")
|
193
|
+
except Exception as e:
|
194
|
+
err(f"Failed to start service: {str(e)}")
|
195
|
+
|
196
|
+
|
197
|
+
@service.command
|
198
|
+
def restart(): # noqa: F811
|
199
|
+
"""Start current database service"""
|
200
|
+
try:
|
201
|
+
restart_service()
|
202
|
+
except Exception as e:
|
203
|
+
err(f"Failed to restart service: {str(e)}")
|
204
|
+
else:
|
205
|
+
succ("Service restarted.")
|
206
|
+
|
207
|
+
|
208
|
+
@service.command
|
209
|
+
def status(): # noqa: F811
|
210
|
+
"""Display current service status"""
|
211
|
+
|
212
|
+
def _construct_and_display_data(status):
|
213
|
+
current_context = get_current_context()
|
214
|
+
graph_identifier = current_context.context
|
215
|
+
graph_name = current_context.graph_name
|
216
|
+
|
217
|
+
head = [
|
218
|
+
"STATUS",
|
219
|
+
"SERVING_GRAPH(IDENTIFIER)",
|
220
|
+
"CYPHER_ENDPOINT",
|
221
|
+
"HQPS_ENDPOINT",
|
222
|
+
"GREMLIN_ENDPOINT",
|
223
|
+
]
|
224
|
+
data = [head]
|
225
|
+
for s in status:
|
226
|
+
if s.graph_id == graph_identifier:
|
227
|
+
if s.status == "Stopped":
|
228
|
+
data.append(
|
229
|
+
[s.status, f"{graph_name}(id={s.graph_id})", "-", "-", "-"]
|
230
|
+
)
|
231
|
+
else:
|
232
|
+
data.append(
|
233
|
+
[
|
234
|
+
s.status,
|
235
|
+
f"{graph_name}(id={s.graph_id})",
|
236
|
+
s.sdk_endpoints.cypher,
|
237
|
+
s.sdk_endpoints.hqps,
|
238
|
+
s.sdk_endpoints.gremlin,
|
239
|
+
]
|
240
|
+
)
|
241
|
+
terminal_display(data)
|
242
|
+
|
243
|
+
try:
|
244
|
+
status = list_service_status()
|
245
|
+
except Exception as e:
|
246
|
+
err(f"Failed to list service status: {str(e)}")
|
247
|
+
else:
|
248
|
+
_construct_and_display_data(status)
|
249
|
+
|
250
|
+
|
251
|
+
@use.command(name="GLOBAL")
|
252
|
+
def _global():
|
253
|
+
"""Switch back to the global scope"""
|
254
|
+
switch_context("global")
|
255
|
+
click.secho("Using GLOBAL", fg="green")
|
256
|
+
|
257
|
+
|
258
|
+
if __name__ == "__main__":
|
259
|
+
cli()
|
@@ -0,0 +1,221 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
#
|
4
|
+
# Copyright 2023 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
|
+
"""Global configuration"""
|
20
|
+
|
21
|
+
import os
|
22
|
+
import random
|
23
|
+
import time
|
24
|
+
from string import ascii_letters
|
25
|
+
|
26
|
+
from graphscope.gsctl.utils import read_yaml_file
|
27
|
+
from graphscope.gsctl.utils import write_yaml_file
|
28
|
+
|
29
|
+
GS_CONFIG_DEFAULT_LOCATION = os.environ.get("GSCONFIG", os.path.expanduser("~/.gsctl"))
|
30
|
+
|
31
|
+
logo = """
|
32
|
+
______ __ _____
|
33
|
+
/ ____/________ _____ / /_ / ___/_________ ____ ___
|
34
|
+
/ / __/ ___/ __ `/ __ \/ __ \\\__ \/ ___/ __ \/ __ \/ _ \\
|
35
|
+
/ /_/ / / / /_/ / /_/ / / / /__/ / /__/ /_/ / /_/ / __/
|
36
|
+
\____/_/ \__,_/ .___/_/ /_/____/\___/\____/ .___/\___/
|
37
|
+
/_/ /_/
|
38
|
+
""" # noqa: W605
|
39
|
+
|
40
|
+
|
41
|
+
class Context(object):
|
42
|
+
def __init__(
|
43
|
+
self,
|
44
|
+
coordinator_endpoint,
|
45
|
+
flex,
|
46
|
+
name=None,
|
47
|
+
timestamp=time.time(),
|
48
|
+
context="global",
|
49
|
+
graph_name=None,
|
50
|
+
):
|
51
|
+
if name is None:
|
52
|
+
name = "context_" + "".join(random.choices(ascii_letters, k=8))
|
53
|
+
|
54
|
+
self.name = name
|
55
|
+
self.flex = flex
|
56
|
+
self.coordinator_endpoint = coordinator_endpoint
|
57
|
+
# switch to specific graph after `using graph`
|
58
|
+
self.context = context
|
59
|
+
self.graph_name = graph_name
|
60
|
+
self.timestamp = timestamp
|
61
|
+
|
62
|
+
def switch_context(self, context: str):
|
63
|
+
self.context = context
|
64
|
+
if self.context == "global":
|
65
|
+
self.graph_name = None
|
66
|
+
|
67
|
+
def set_graph_name(self, graph_name: str):
|
68
|
+
self.graph_name = graph_name
|
69
|
+
|
70
|
+
def to_dict(self) -> dict:
|
71
|
+
return {
|
72
|
+
"name": self.name,
|
73
|
+
"graph_name": str(self.graph_name),
|
74
|
+
"flex": self.flex,
|
75
|
+
"coordinator_endpoint": self.coordinator_endpoint,
|
76
|
+
"context": self.context,
|
77
|
+
"timestamp": self.timestamp,
|
78
|
+
}
|
79
|
+
|
80
|
+
@classmethod
|
81
|
+
def from_dict(cls, dikt):
|
82
|
+
return Context(
|
83
|
+
coordinator_endpoint=dikt.get("coordinator_endpoint"),
|
84
|
+
flex=dikt.get("flex"),
|
85
|
+
name=dikt.get("name"),
|
86
|
+
timestamp=dikt.get("timestamp"),
|
87
|
+
context=dikt.get("context"),
|
88
|
+
graph_name=dikt.get("graph_name", None),
|
89
|
+
)
|
90
|
+
|
91
|
+
def is_expired(self, validity_period=86400) -> bool:
|
92
|
+
current_timestamp = time.time()
|
93
|
+
if current_timestamp - self.timestamp > validity_period:
|
94
|
+
return True
|
95
|
+
return False
|
96
|
+
|
97
|
+
def reset_timestamp(self):
|
98
|
+
self.timestamp = time.time()
|
99
|
+
|
100
|
+
|
101
|
+
class GSConfig(object):
|
102
|
+
def __init__(self, contexts, current_context: str):
|
103
|
+
self._contexts = contexts
|
104
|
+
self._current_context = current_context
|
105
|
+
|
106
|
+
def current_context(self) -> Context:
|
107
|
+
if self._current_context is None:
|
108
|
+
return None
|
109
|
+
if self._current_context not in self._contexts:
|
110
|
+
raise RuntimeError(
|
111
|
+
f"Failed to get current context: {self._current_context}"
|
112
|
+
)
|
113
|
+
return self._contexts[self._current_context]
|
114
|
+
|
115
|
+
def set_and_write(self, context: Context):
|
116
|
+
# treat the same endpoint with same services as the same coordinator
|
117
|
+
for _, v in self._contexts.items():
|
118
|
+
if (
|
119
|
+
context.coordinator_endpoint == v.coordinator_endpoint
|
120
|
+
and context.flex == v.flex
|
121
|
+
):
|
122
|
+
# reset to global context
|
123
|
+
v.switch_context("global")
|
124
|
+
contexts = [v.to_dict() for _, v in self._contexts.items()]
|
125
|
+
write_yaml_file(
|
126
|
+
{"contexts": contexts, "current-context": self._current_context},
|
127
|
+
GS_CONFIG_DEFAULT_LOCATION,
|
128
|
+
)
|
129
|
+
return
|
130
|
+
|
131
|
+
# set
|
132
|
+
self._current_context = context.name
|
133
|
+
self._contexts[context.name] = context
|
134
|
+
|
135
|
+
# write
|
136
|
+
contexts = [v.to_dict() for _, v in self._contexts.items()]
|
137
|
+
write_yaml_file(
|
138
|
+
{"contexts": contexts, "current-context": self._current_context},
|
139
|
+
GS_CONFIG_DEFAULT_LOCATION,
|
140
|
+
)
|
141
|
+
|
142
|
+
def update_and_write(self, context: Context):
|
143
|
+
if context.name not in self._contexts:
|
144
|
+
raise RuntimeError(f"Failed to get context: {context.name}")
|
145
|
+
|
146
|
+
# update
|
147
|
+
self._contexts[context.name] = context
|
148
|
+
|
149
|
+
# write
|
150
|
+
contexts = [v.to_dict() for _, v in self._contexts.items()]
|
151
|
+
write_yaml_file(
|
152
|
+
{"contexts": contexts, "current-context": self._current_context},
|
153
|
+
GS_CONFIG_DEFAULT_LOCATION,
|
154
|
+
)
|
155
|
+
|
156
|
+
def remove_and_write(self, current_context: Context):
|
157
|
+
# remove
|
158
|
+
del self._contexts[current_context.name]
|
159
|
+
self._current_context = None
|
160
|
+
|
161
|
+
# write
|
162
|
+
contexts = [v.to_dict() for _, v in self._contexts.items()]
|
163
|
+
write_yaml_file(
|
164
|
+
{"contexts": contexts, "current-context": self._current_context},
|
165
|
+
GS_CONFIG_DEFAULT_LOCATION,
|
166
|
+
)
|
167
|
+
|
168
|
+
|
169
|
+
class GSConfigLoader(object):
|
170
|
+
def __init__(self, config_file):
|
171
|
+
self._config_file = config_file
|
172
|
+
|
173
|
+
def _parse_config(self, config_dict):
|
174
|
+
if not config_dict:
|
175
|
+
return {}, None
|
176
|
+
|
177
|
+
current_context = config_dict["current-context"]
|
178
|
+
if current_context is None:
|
179
|
+
return {}, None
|
180
|
+
|
181
|
+
contexts = {}
|
182
|
+
current_context_exists = False
|
183
|
+
for c in config_dict["contexts"]:
|
184
|
+
if current_context == c["name"]:
|
185
|
+
current_context_exists = True
|
186
|
+
contexts[c["name"]] = Context.from_dict(c)
|
187
|
+
|
188
|
+
if not current_context_exists:
|
189
|
+
raise RuntimeError(
|
190
|
+
"Current context {0} is not exists in config file {1}".format(
|
191
|
+
current_context, GS_CONFIG_DEFAULT_LOCATION
|
192
|
+
)
|
193
|
+
)
|
194
|
+
|
195
|
+
return contexts, current_context
|
196
|
+
|
197
|
+
def load_config(self):
|
198
|
+
config_dict = read_yaml_file(self._config_file)
|
199
|
+
contexts, current_context = self._parse_config(config_dict)
|
200
|
+
return GSConfig(contexts, current_context)
|
201
|
+
|
202
|
+
|
203
|
+
def load_gs_config():
|
204
|
+
"""Loads cluster and context information from gs-config file
|
205
|
+
and stores them in Config.
|
206
|
+
"""
|
207
|
+
config_file = GS_CONFIG_DEFAULT_LOCATION
|
208
|
+
|
209
|
+
# create config file is not exists
|
210
|
+
if not os.path.exists(config_file):
|
211
|
+
workdir = os.path.dirname(config_file)
|
212
|
+
os.makedirs(workdir, exist_ok=True)
|
213
|
+
write_yaml_file({}, config_file)
|
214
|
+
|
215
|
+
loader = GSConfigLoader(config_file)
|
216
|
+
return loader.load_config()
|
217
|
+
|
218
|
+
|
219
|
+
def get_current_context():
|
220
|
+
config = load_gs_config()
|
221
|
+
return config.current_context()
|
@@ -0,0 +1,51 @@
|
|
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 os
|
20
|
+
import sys
|
21
|
+
|
22
|
+
import click
|
23
|
+
|
24
|
+
try:
|
25
|
+
import graphscope
|
26
|
+
from graphscope.gsctl.commands import get_command_collection
|
27
|
+
from graphscope.gsctl.config import get_current_context
|
28
|
+
except ModuleNotFoundError:
|
29
|
+
# if graphscope is not installed, only basic functions or utilities
|
30
|
+
# can be used, e.g. install dependencies
|
31
|
+
graphscope = None
|
32
|
+
|
33
|
+
|
34
|
+
def cli():
|
35
|
+
if graphscope is None:
|
36
|
+
sys.path.insert(
|
37
|
+
0, os.path.join(os.path.dirname(os.path.realpath(__file__)), "commands")
|
38
|
+
)
|
39
|
+
from dev import cli as dev_cli
|
40
|
+
|
41
|
+
dev_cli()
|
42
|
+
|
43
|
+
context = get_current_context()
|
44
|
+
# get the specified commands under the FLEX architecture
|
45
|
+
commands = get_command_collection(context)
|
46
|
+
# serve the command
|
47
|
+
commands()
|
48
|
+
|
49
|
+
|
50
|
+
if __name__ == "__main__":
|
51
|
+
cli()
|
@@ -0,0 +1,64 @@
|
|
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 graphscope.gsctl.impl.alert import create_alert_receiver
|
20
|
+
from graphscope.gsctl.impl.alert import delete_alert_message_in_batch
|
21
|
+
from graphscope.gsctl.impl.alert import delete_alert_receiver_by_id
|
22
|
+
from graphscope.gsctl.impl.alert import delete_alert_rule_by_id
|
23
|
+
from graphscope.gsctl.impl.alert import list_alert_messages
|
24
|
+
from graphscope.gsctl.impl.alert import list_alert_receivers
|
25
|
+
from graphscope.gsctl.impl.alert import list_alert_rules
|
26
|
+
from graphscope.gsctl.impl.alert import update_alert_message_in_batch
|
27
|
+
from graphscope.gsctl.impl.alert import update_alert_receiver_by_id
|
28
|
+
from graphscope.gsctl.impl.alert import update_alert_rule_by_id
|
29
|
+
from graphscope.gsctl.impl.common import connect_coordinator
|
30
|
+
from graphscope.gsctl.impl.common import disconnect_coordinator
|
31
|
+
from graphscope.gsctl.impl.datasource import bind_datasource_in_batch
|
32
|
+
from graphscope.gsctl.impl.datasource import get_datasource_by_id
|
33
|
+
from graphscope.gsctl.impl.datasource import unbind_edge_datasource
|
34
|
+
from graphscope.gsctl.impl.datasource import unbind_vertex_datasource
|
35
|
+
from graphscope.gsctl.impl.deployment import get_deployment_pod_log
|
36
|
+
from graphscope.gsctl.impl.deployment import get_deployment_resource_usage
|
37
|
+
from graphscope.gsctl.impl.deployment import get_deployment_status
|
38
|
+
from graphscope.gsctl.impl.deployment import get_storage_usage
|
39
|
+
from graphscope.gsctl.impl.graph import create_edge_type
|
40
|
+
from graphscope.gsctl.impl.graph import create_graph
|
41
|
+
from graphscope.gsctl.impl.graph import create_vertex_type
|
42
|
+
from graphscope.gsctl.impl.graph import delete_edge_type_by_name
|
43
|
+
from graphscope.gsctl.impl.graph import delete_graph_by_id
|
44
|
+
from graphscope.gsctl.impl.graph import delete_vertex_type_by_name
|
45
|
+
from graphscope.gsctl.impl.graph import get_graph_by_id
|
46
|
+
from graphscope.gsctl.impl.graph import get_graph_id_by_name
|
47
|
+
from graphscope.gsctl.impl.graph import get_graph_name_by_id
|
48
|
+
from graphscope.gsctl.impl.graph import import_schema
|
49
|
+
from graphscope.gsctl.impl.graph import list_graphs
|
50
|
+
from graphscope.gsctl.impl.job import delete_job_by_id
|
51
|
+
from graphscope.gsctl.impl.job import get_job_by_id
|
52
|
+
from graphscope.gsctl.impl.job import list_jobs
|
53
|
+
from graphscope.gsctl.impl.job import submit_dataloading_job
|
54
|
+
from graphscope.gsctl.impl.service import list_service_status
|
55
|
+
from graphscope.gsctl.impl.service import restart_service
|
56
|
+
from graphscope.gsctl.impl.service import start_service
|
57
|
+
from graphscope.gsctl.impl.service import stop_service
|
58
|
+
from graphscope.gsctl.impl.stored_procedure import create_stored_procedure
|
59
|
+
from graphscope.gsctl.impl.stored_procedure import delete_stored_procedure_by_id
|
60
|
+
from graphscope.gsctl.impl.stored_procedure import get_stored_procedure_by_id
|
61
|
+
from graphscope.gsctl.impl.stored_procedure import list_stored_procedures
|
62
|
+
from graphscope.gsctl.impl.stored_procedure import update_stored_procedure_by_id
|
63
|
+
from graphscope.gsctl.impl.utils import switch_context
|
64
|
+
from graphscope.gsctl.impl.utils import upload_file
|