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,148 @@
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 sys
20
+
21
+ import click
22
+
23
+ from graphscope.gsctl.commands.common import cli as common
24
+ from graphscope.gsctl.commands.dev import cli as dev
25
+ from graphscope.gsctl.commands.insight.glob import cli as insight
26
+ from graphscope.gsctl.commands.insight.graph import cli as insight_graph
27
+ from graphscope.gsctl.commands.interactive.glob import cli as interactive
28
+ from graphscope.gsctl.commands.interactive.graph import cli as interactive_graph
29
+ from graphscope.gsctl.config import Context
30
+ from graphscope.gsctl.config import load_gs_config
31
+ from graphscope.gsctl.config import logo
32
+ from graphscope.gsctl.impl import connect_coordinator
33
+ from graphscope.gsctl.utils import err
34
+ from graphscope.gsctl.utils import info
35
+
36
+ usage_message = """
37
+ Currently, `gsctl` hasn't connect to any service. Try to deploy a GraphScope
38
+ instance with:
39
+
40
+ gsctl instance deploy --type interactive
41
+
42
+ See more detailed information at https://graphscope.io/docs/utilities/gs.
43
+ """
44
+
45
+ interactive_usage_message = """
46
+ Currently in the global scope of Interactive instance, run `gsctl ls -l` to
47
+ display all resources in database and switch to a specific graph scope with:
48
+
49
+ gsctl use GRAPH <graph_id>
50
+
51
+ See more detailed information at https://graphscope.io/docs/utilities/gs.
52
+ """
53
+
54
+
55
+ def is_interactive_mode(flex):
56
+ return (
57
+ flex["engine"] == "Hiactor"
58
+ and flex["storage"] == "MutableCSR"
59
+ and flex["frontend"] == "Cypher/Gremlin"
60
+ )
61
+
62
+
63
+ def is_insight_mode(flex):
64
+ return (
65
+ flex["engine"] == "Gaia"
66
+ and flex["storage"] == "MutablePersistent"
67
+ and flex["frontend"] == "Cypher/Gremlin"
68
+ )
69
+
70
+
71
+ def get_command_collection(context: Context):
72
+ # default commands
73
+ commands = click.CommandCollection(sources=[common, dev])
74
+
75
+ # treat gsctl as an utility script, providing helper functions or utilities
76
+ # e.g. initialize and manage cluster, install the dependencies required to
77
+ # build graphscope locally.
78
+ if context is None:
79
+ if len(sys.argv) == 1:
80
+ info(logo, fg="green", bold=True)
81
+ info(usage_message, fg="red")
82
+ return commands
83
+
84
+ if context.is_expired():
85
+ try:
86
+ # connect to coordinator and reset the timestamp
87
+ response = connect_coordinator(context.coordinator_endpoint)
88
+ flex = {
89
+ "engine": response.engine,
90
+ "storage": response.storage,
91
+ "frontend": response.frontend,
92
+ }
93
+ except Exception as e:
94
+ err(
95
+ "Failed to connect to coordinator at {0}: {1}".format(
96
+ context.coordinator_endpoint, str(e)
97
+ )
98
+ )
99
+ info(
100
+ "Please check the availability of the service, fall back to the default commands."
101
+ )
102
+ return commands
103
+ else:
104
+ # check consistency
105
+ if flex != context.flex:
106
+ raise RuntimeError(
107
+ f"Instance changed: {context.flex} -> {flex}, please close and reconnect to the coordinator"
108
+ )
109
+ context.reset_timestamp()
110
+ config = load_gs_config()
111
+ config.update_and_write(context)
112
+
113
+ if is_interactive_mode(context.flex):
114
+ if context.context == "global":
115
+ if len(sys.argv) < 2 or sys.argv[1] != "use":
116
+ info(interactive_usage_message, fg="green")
117
+ commands = click.CommandCollection(sources=[common, interactive])
118
+ else:
119
+ if len(sys.argv) < 2 or sys.argv[1] != "use":
120
+ info(
121
+ f"Using GRAPH {context.graph_name}(id={context.context}).",
122
+ fg="green",
123
+ bold=True,
124
+ )
125
+ info(
126
+ "Run `gsctl use GLOBAL` to switch back to GLOBAL context.\n",
127
+ fg="green",
128
+ )
129
+ commands = click.CommandCollection(sources=[common, interactive_graph])
130
+ elif is_insight_mode(context.flex):
131
+ if context.context == "global":
132
+ if len(sys.argv) < 2 or sys.argv[1] != "use":
133
+ info("Using GLOBAL.", fg="green", bold=True)
134
+ info(
135
+ "Run `gsctl use GRAPH <graph_identifier>` to switch to a specific graph context.\n"
136
+ )
137
+ commands = click.CommandCollection(sources=[common, insight])
138
+ else:
139
+ if len(sys.argv) < 2 or sys.argv[1] != "use":
140
+ info(
141
+ f"Using GRAPH {context.graph_name}(id={context.context}).",
142
+ fg="green",
143
+ bold=True,
144
+ )
145
+ info("Run `gsctl use GLOBAL` to switch back to GLOBAL context.\n")
146
+ commands = click.CommandCollection(sources=[common, insight_graph])
147
+
148
+ return commands
@@ -0,0 +1,200 @@
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
+ """Group of commands used by all products under the FLEX architecture"""
20
+
21
+ import click
22
+
23
+ from graphscope.gsctl.config import Context
24
+ from graphscope.gsctl.config import get_current_context
25
+ from graphscope.gsctl.config import load_gs_config
26
+ from graphscope.gsctl.impl import connect_coordinator
27
+ from graphscope.gsctl.impl import disconnect_coordinator
28
+ from graphscope.gsctl.utils import err
29
+ from graphscope.gsctl.utils import info
30
+ from graphscope.gsctl.utils import succ
31
+ from graphscope.gsctl.version import __version__
32
+
33
+
34
+ @click.group()
35
+ def cli():
36
+ # nothing happens
37
+ pass
38
+
39
+
40
+ @cli.command()
41
+ def version():
42
+ """Print the client version information"""
43
+ info(__version__)
44
+
45
+
46
+ @cli.command()
47
+ @click.option(
48
+ "-c",
49
+ "--coordinator-endpoint",
50
+ help="Coordinator endpoint, e.g. http://127.0.0.1:9527",
51
+ )
52
+ def connect(coordinator_endpoint):
53
+ """Connect to a launched coordinator.
54
+
55
+ By default, it will read context from ~/.gsctl. If '--coordinator-endpoint'
56
+ is specified, use it as the current context and override the configuration file.
57
+ """
58
+ if coordinator_endpoint is None:
59
+ context = get_current_context()
60
+ if context is None:
61
+ err(
62
+ "No available context found, try to connect by `gsctl connect --coordinator-endpoint <addr>`."
63
+ )
64
+ return
65
+ coordinator_endpoint = context.coordinator_endpoint
66
+ # connect
67
+ try:
68
+ resp = connect_coordinator(coordinator_endpoint)
69
+ except Exception as e:
70
+ err(f"Unable to connect to server: {str(e)}")
71
+ else:
72
+ serving_mode = "frontend: {0}, engine: {1}, storage: {2}".format(
73
+ resp.frontend, resp.engine, resp.storage
74
+ )
75
+ succ(
76
+ f"Connected to {coordinator_endpoint}, coordinator is serving with {serving_mode} mode.\n"
77
+ )
78
+ info("Try 'gsctl --help' for help.")
79
+
80
+
81
+ @cli.command()
82
+ def close():
83
+ """Disconnect from coordinator."""
84
+ try:
85
+ context = disconnect_coordinator()
86
+ except Exception as e:
87
+ err(f"Disconnect from coordinator failed: {str(e)}")
88
+ else:
89
+ if context is not None:
90
+ info(f"Disconnecting from the context: {context.to_dict()}")
91
+ succ("Coordinator service disconnected.\n")
92
+ info("Try 'gsctl --help' for help.")
93
+
94
+
95
+ disclaimer = """
96
+ Disclaimer: The `estimate` command serves as an estimator for various kinds of GraphScope resources.
97
+ - GAE memory usage estimator:
98
+ It would do a rough estimation of the total memory usage of the GAE.
99
+ The actual memory usage may vary vastly due to the complexity of the graph algorithms and the data distribution.
100
+
101
+ Here's some assumption when estimating the memory usage:
102
+ 1. Assuming the graph is a simple graph, e.g. only has 1 label and at most 1 property for each label.
103
+ 2. Assuming the graph algorithm has a fixed amount of memory consumption, e.g. PageRank, SSSP, CC;
104
+ It should not generate a huge amount of intermediate result, like K-Hop, Louvain.
105
+ 3. Assuming the vertex map type is global vertex map
106
+
107
+ Users should take this estimation as a reference and a starting point for tuning,
108
+ and adjust the memory allocation according to the actual situation.
109
+ """
110
+
111
+
112
+ def estimate_gae_memory_usage_for_graph(
113
+ v_num, e_num, v_file_size, e_file_size, partition
114
+ ):
115
+ """
116
+ The estimation is based on the following formulas:
117
+ let #V = number of vertices, #E = number of edges,
118
+ assuming load_factor of hashmap is 0.41, sizeof(inner_id) = sizeof(edge_id) = sizeof(vertex_id) = 8 bytes,
119
+ where vertex_id is the primary key of the vertex, default to int64,
120
+ it could be string though, in that case, the memory usage will grow.
121
+ Graph:
122
+ 1. vertex
123
+ - vertex map: #V * (sizeof(vertex_id) + sizeof(inner_id)) * (1 / load_factor)
124
+ - vertex table: size of vertex files in uncompressed CSV format, unit is GB
125
+ 2. edge
126
+ - CSR + CSC: 2 * #E * (sizeof(inner_id) + sizeof(edge_id))
127
+ - offset array: #V * sizeof(size_t)
128
+ - edge table: size of vertex files in uncompressed CSV format, unit is GB
129
+ 3. additional data structure when graph is partitioned, assuming 10% of vertices will be outer vertices
130
+ - outer vertex ID to local ID map: 0.1 * #V * (sizeof(vertex_id) + sizeof(inner_id)) * (1 / load_factor)
131
+ - local ID to outer vertex ID array: 0.1 * #V * sizeof(size_t)
132
+
133
+ This is the minimum usage of the GAE with 1 partition, the actual memory usage would be larger than this estimation.
134
+ """
135
+ gb = 1024 * 1024 * 1024
136
+ # vertex map
137
+ vertex_map = v_num * (8 + 8) * (1 / 0.41) / gb
138
+ # vertex table
139
+ vertex_table = v_file_size
140
+ # edge
141
+ edge = 2 * e_num * (8 + 8) / gb
142
+ # offset array
143
+ offset_array = v_num * 8 / gb
144
+ # edge table
145
+ edge_table = e_file_size
146
+ additional = 0.1 * v_num * (8 + 8) * (1 / 0.41) / gb + 0.1 * v_num * 8 / gb
147
+ if partition == 1:
148
+ additional = 0
149
+ per_partition = (
150
+ vertex_map
151
+ + (vertex_table + edge_table + edge + offset_array) / partition
152
+ + additional
153
+ )
154
+ return per_partition
155
+
156
+
157
+ def estimate_gae_memory_usage_for_algorithm(v_num):
158
+ """
159
+ Simple algorithms like PageRank or CC will have 1 slot for result for each vertex.
160
+ Formula: #V * sizeof(double)
161
+ """
162
+ gb = 1024 * 1024 * 1024
163
+ usage = v_num * 8 / gb
164
+ return usage
165
+
166
+
167
+ @cli.command()
168
+ @click.option(
169
+ "-g",
170
+ "--engine",
171
+ type=click.Choice(["gae"], case_sensitive=False),
172
+ help="Engine type",
173
+ required=True,
174
+ )
175
+ @click.option("-v", "--v-num", type=int, help="Number of vertices")
176
+ @click.option("-e", "--e-num", type=int, help="Number of edges")
177
+ @click.option("-vf", "--v-file-size", type=float, help="Size of vertex files in GB")
178
+ @click.option("-ef", "--e-file-size", type=float, help="Size of edge files in GB")
179
+ @click.option("-p", "--partition", type=int, help="Number of partitions", default=1)
180
+ def estimate(engine, v_num, e_num, v_file_size, e_file_size, partition):
181
+ """Estimate the resources requirement for various kinds of GraphScope components"""
182
+ if engine == "gae":
183
+ if v_num is None or e_num is None or v_file_size is None or e_file_size is None:
184
+ err("Please provide the required parameters.")
185
+ return
186
+ partition_usage = estimate_gae_memory_usage_for_graph(
187
+ v_num, e_num, v_file_size, e_file_size, partition
188
+ )
189
+ algorithm_usage = estimate_gae_memory_usage_for_algorithm(v_num)
190
+ memory_usage = partition_usage + algorithm_usage
191
+ info(disclaimer)
192
+ succ(
193
+ f"The estimated memory usage is {memory_usage:.2f} GB per pod for {partition} pods.\n"
194
+ )
195
+ else:
196
+ err(f"Estimating usage of engine {engine} is not supported yet.")
197
+
198
+
199
+ if __name__ == "__main__":
200
+ cli()