kaqing 2.0.115__py3-none-any.whl → 2.0.172__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of kaqing might be problematic. Click here for more details.
- adam/__init__.py +0 -2
- adam/app_session.py +8 -11
- adam/batch.py +3 -3
- adam/checks/check_utils.py +14 -46
- adam/checks/cpu.py +7 -1
- adam/checks/cpu_metrics.py +52 -0
- adam/checks/disk.py +2 -3
- adam/columns/columns.py +3 -1
- adam/columns/cpu.py +3 -1
- adam/columns/cpu_metrics.py +22 -0
- adam/columns/memory.py +3 -4
- adam/commands/__init__.py +18 -0
- adam/commands/alter_tables.py +43 -47
- adam/commands/audit/audit.py +24 -25
- adam/commands/audit/audit_repair_tables.py +14 -17
- adam/commands/audit/audit_run.py +15 -23
- adam/commands/audit/show_last10.py +10 -13
- adam/commands/audit/show_slow10.py +10 -13
- adam/commands/audit/show_top10.py +10 -14
- adam/commands/audit/utils_show_top10.py +2 -3
- adam/commands/bash/__init__.py +5 -0
- adam/commands/bash/bash.py +8 -96
- adam/commands/bash/utils_bash.py +16 -0
- adam/commands/cat.py +14 -19
- adam/commands/cd.py +12 -100
- adam/commands/check.py +20 -21
- adam/commands/cli_commands.py +2 -3
- adam/commands/code.py +20 -23
- adam/commands/command.py +123 -39
- adam/commands/commands_utils.py +8 -17
- adam/commands/cp.py +33 -39
- adam/commands/cql/cql_completions.py +28 -10
- adam/commands/cql/cqlsh.py +10 -30
- adam/commands/cql/utils_cql.py +343 -0
- adam/commands/deploy/code_start.py +7 -10
- adam/commands/deploy/code_stop.py +4 -21
- adam/commands/deploy/code_utils.py +3 -3
- adam/commands/deploy/deploy.py +4 -27
- adam/commands/deploy/deploy_frontend.py +14 -17
- adam/commands/deploy/deploy_pg_agent.py +2 -5
- adam/commands/deploy/deploy_pod.py +65 -73
- adam/commands/deploy/deploy_utils.py +14 -24
- adam/commands/deploy/undeploy.py +4 -27
- adam/commands/deploy/undeploy_frontend.py +4 -7
- adam/commands/deploy/undeploy_pg_agent.py +5 -7
- adam/commands/deploy/undeploy_pod.py +11 -12
- adam/commands/devices/__init__.py +0 -0
- adam/commands/devices/device.py +118 -0
- adam/commands/devices/device_app.py +173 -0
- adam/commands/devices/device_auit_log.py +49 -0
- adam/commands/devices/device_cass.py +185 -0
- adam/commands/devices/device_export.py +86 -0
- adam/commands/devices/device_postgres.py +144 -0
- adam/commands/devices/devices.py +25 -0
- adam/commands/exit.py +1 -4
- adam/commands/export/clean_up_all_export_sessions.py +37 -0
- adam/commands/export/clean_up_export_sessions.py +51 -0
- adam/commands/export/drop_export_database.py +55 -0
- adam/commands/export/drop_export_databases.py +43 -0
- adam/commands/export/export.py +19 -26
- adam/commands/export/export_databases.py +174 -0
- adam/commands/export/export_handlers.py +71 -0
- adam/commands/export/export_select.py +48 -22
- adam/commands/export/export_select_x.py +54 -0
- adam/commands/export/export_use.py +19 -23
- adam/commands/export/exporter.py +353 -0
- adam/commands/export/import_session.py +40 -0
- adam/commands/export/importer.py +67 -0
- adam/commands/export/importer_athena.py +77 -0
- adam/commands/export/importer_sqlite.py +39 -0
- adam/commands/export/show_column_counts.py +54 -0
- adam/commands/export/show_export_databases.py +36 -0
- adam/commands/export/show_export_session.py +48 -0
- adam/commands/export/show_export_sessions.py +44 -0
- adam/commands/export/utils_export.py +223 -162
- adam/commands/help.py +1 -1
- adam/commands/intermediate_command.py +49 -0
- adam/commands/issues.py +11 -43
- adam/commands/kubectl.py +3 -6
- adam/commands/login.py +22 -24
- adam/commands/logs.py +3 -6
- adam/commands/ls.py +11 -128
- adam/commands/medusa/medusa.py +4 -22
- adam/commands/medusa/medusa_backup.py +20 -24
- adam/commands/medusa/medusa_restore.py +29 -33
- adam/commands/medusa/medusa_show_backupjobs.py +14 -18
- adam/commands/medusa/medusa_show_restorejobs.py +11 -18
- adam/commands/nodetool.py +6 -15
- adam/commands/param_get.py +11 -12
- adam/commands/param_set.py +9 -10
- adam/commands/postgres/postgres.py +41 -34
- adam/commands/postgres/postgres_context.py +57 -24
- adam/commands/postgres/postgres_ls.py +4 -8
- adam/commands/postgres/postgres_preview.py +5 -9
- adam/commands/postgres/psql_completions.py +1 -1
- adam/commands/postgres/utils_postgres.py +66 -0
- adam/commands/preview_table.py +5 -44
- adam/commands/pwd.py +14 -47
- adam/commands/reaper/reaper.py +4 -27
- adam/commands/reaper/reaper_forward.py +48 -55
- adam/commands/reaper/reaper_forward_session.py +6 -0
- adam/commands/reaper/reaper_forward_stop.py +10 -16
- adam/commands/reaper/reaper_restart.py +7 -14
- adam/commands/reaper/reaper_run_abort.py +11 -30
- adam/commands/reaper/reaper_runs.py +42 -57
- adam/commands/reaper/reaper_runs_abort.py +29 -49
- adam/commands/reaper/reaper_schedule_activate.py +11 -30
- adam/commands/reaper/reaper_schedule_start.py +10 -29
- adam/commands/reaper/reaper_schedule_stop.py +10 -29
- adam/commands/reaper/reaper_schedules.py +4 -14
- adam/commands/reaper/reaper_status.py +8 -16
- adam/commands/reaper/utils_reaper.py +196 -0
- adam/commands/repair/repair.py +4 -22
- adam/commands/repair/repair_log.py +5 -11
- adam/commands/repair/repair_run.py +27 -34
- adam/commands/repair/repair_scan.py +32 -38
- adam/commands/repair/repair_stop.py +5 -11
- adam/commands/report.py +27 -29
- adam/commands/restart.py +25 -26
- adam/commands/rollout.py +19 -24
- adam/commands/shell.py +10 -4
- adam/commands/show/show.py +10 -25
- adam/commands/show/show_cassandra_repairs.py +35 -0
- adam/commands/show/show_cassandra_status.py +32 -43
- adam/commands/show/show_cassandra_version.py +5 -18
- adam/commands/show/show_commands.py +19 -24
- adam/commands/show/show_host.py +1 -1
- adam/commands/show/show_login.py +20 -27
- adam/commands/show/show_processes.py +15 -19
- adam/commands/show/show_storage.py +10 -20
- adam/commands/watch.py +26 -29
- adam/config.py +5 -14
- adam/embedded_params.py +1 -1
- adam/log.py +4 -4
- adam/pod_exec_result.py +3 -3
- adam/repl.py +40 -103
- adam/repl_commands.py +32 -16
- adam/repl_state.py +57 -28
- adam/sql/sql_completer.py +44 -28
- adam/sql/sql_state_machine.py +89 -28
- adam/sso/authn_ad.py +6 -8
- adam/sso/authn_okta.py +4 -6
- adam/sso/cred_cache.py +3 -5
- adam/sso/idp.py +9 -12
- adam/utils.py +435 -6
- adam/utils_athena.py +57 -37
- adam/utils_audits.py +12 -14
- adam/utils_issues.py +32 -0
- adam/utils_k8s/app_clusters.py +13 -18
- adam/utils_k8s/app_pods.py +2 -0
- adam/utils_k8s/cassandra_clusters.py +22 -19
- adam/utils_k8s/cassandra_nodes.py +2 -2
- adam/utils_k8s/custom_resources.py +16 -17
- adam/utils_k8s/ingresses.py +2 -2
- adam/utils_k8s/jobs.py +7 -11
- adam/utils_k8s/k8s.py +87 -0
- adam/utils_k8s/pods.py +40 -77
- adam/utils_k8s/secrets.py +4 -4
- adam/utils_k8s/service_accounts.py +5 -4
- adam/utils_k8s/services.py +2 -2
- adam/utils_k8s/statefulsets.py +1 -12
- adam/utils_net.py +4 -4
- adam/utils_repl/__init__.py +0 -0
- adam/utils_repl/automata_completer.py +48 -0
- adam/utils_repl/repl_completer.py +46 -0
- adam/utils_repl/state_machine.py +173 -0
- adam/utils_sqlite.py +137 -0
- adam/version.py +1 -1
- {kaqing-2.0.115.dist-info → kaqing-2.0.172.dist-info}/METADATA +1 -1
- kaqing-2.0.172.dist-info/RECORD +230 -0
- adam/commands/app.py +0 -67
- adam/commands/app_ping.py +0 -44
- adam/commands/cql/cql_utils.py +0 -204
- adam/commands/devices.py +0 -147
- adam/commands/export/export_on_x.py +0 -76
- adam/commands/export/export_rmdbs.py +0 -65
- adam/commands/postgres/postgres_utils.py +0 -31
- adam/commands/reaper/reaper_session.py +0 -159
- adam/commands/show/show_app_actions.py +0 -56
- adam/commands/show/show_app_id.py +0 -47
- adam/commands/show/show_app_queues.py +0 -45
- adam/commands/show/show_repairs.py +0 -47
- adam/utils_export.py +0 -42
- kaqing-2.0.115.dist-info/RECORD +0 -203
- {kaqing-2.0.115.dist-info → kaqing-2.0.172.dist-info}/WHEEL +0 -0
- {kaqing-2.0.115.dist-info → kaqing-2.0.172.dist-info}/entry_points.txt +0 -0
- {kaqing-2.0.115.dist-info → kaqing-2.0.172.dist-info}/top_level.txt +0 -0
adam/commands/command.py
CHANGED
|
@@ -2,10 +2,10 @@ from abc import abstractmethod
|
|
|
2
2
|
import copy
|
|
3
3
|
import subprocess
|
|
4
4
|
import sys
|
|
5
|
+
from typing import Union
|
|
5
6
|
|
|
6
|
-
from adam.commands.command_helpers import ClusterCommandHelper
|
|
7
7
|
from adam.repl_state import ReplState, RequiredState
|
|
8
|
-
from adam.utils import
|
|
8
|
+
from adam.utils import is_lambda
|
|
9
9
|
|
|
10
10
|
repl_cmds: list['Command'] = []
|
|
11
11
|
|
|
@@ -32,6 +32,9 @@ class Command:
|
|
|
32
32
|
if not self.validate_state(state, show_err=False):
|
|
33
33
|
return {}
|
|
34
34
|
|
|
35
|
+
if is_lambda(leaf):
|
|
36
|
+
leaf = leaf()
|
|
37
|
+
|
|
35
38
|
d = leaf
|
|
36
39
|
for t in reversed(self.command().split(' ')):
|
|
37
40
|
d = {t: d}
|
|
@@ -41,7 +44,10 @@ class Command:
|
|
|
41
44
|
def required(self) -> RequiredState:
|
|
42
45
|
return None
|
|
43
46
|
|
|
44
|
-
def
|
|
47
|
+
def validate(self, args: list[str], state: ReplState, apply = True):
|
|
48
|
+
return ValidateHandler(self, args, state, apply = apply)
|
|
49
|
+
|
|
50
|
+
def validate_state(self, state: ReplState, show_err = True):
|
|
45
51
|
return state.validate(self.required(), show_err=show_err)
|
|
46
52
|
|
|
47
53
|
def help(self, _: ReplState) -> str:
|
|
@@ -90,17 +96,50 @@ class Command:
|
|
|
90
96
|
args.extend(['--help'])
|
|
91
97
|
subprocess.run(args)
|
|
92
98
|
|
|
93
|
-
def extract_options(args: list[str],
|
|
94
|
-
|
|
99
|
+
def extract_options(args: list[str], trailing: Union[str, list[str]] = [], sequence: list[str] = [], options: list[str] = []):
|
|
100
|
+
found_options: list[str] = []
|
|
101
|
+
found_trailing = None
|
|
102
|
+
found_sequence = None
|
|
103
|
+
|
|
104
|
+
if trailing is None:
|
|
105
|
+
trailing = []
|
|
106
|
+
elif isinstance(trailing, str):
|
|
107
|
+
trailing = [trailing]
|
|
108
|
+
|
|
109
|
+
if options is None:
|
|
110
|
+
options = []
|
|
111
|
+
elif isinstance(options, str):
|
|
112
|
+
options = [options]
|
|
113
|
+
|
|
114
|
+
if args and trailing:
|
|
115
|
+
while args[-1] in trailing:
|
|
116
|
+
found_trailing = True
|
|
117
|
+
args = args[:-1]
|
|
118
|
+
|
|
119
|
+
if args and sequence:
|
|
120
|
+
args, found_sequence = Command.extract_option_sequence(args, sequence)
|
|
95
121
|
|
|
96
122
|
new_args: list[str] = []
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
123
|
+
if args:
|
|
124
|
+
for arg in args:
|
|
125
|
+
if arg in options:
|
|
126
|
+
found_options.append(arg)
|
|
127
|
+
else:
|
|
128
|
+
new_args.append(arg)
|
|
129
|
+
|
|
130
|
+
return new_args, found_trailing, found_sequence, found_options
|
|
102
131
|
|
|
103
|
-
|
|
132
|
+
def extract_option_sequence(args, sequence):
|
|
133
|
+
len_sub = len(sequence)
|
|
134
|
+
len_main = len(args)
|
|
135
|
+
for i in range(len_main - len_sub + 1):
|
|
136
|
+
if args[i:i+len_sub] == sequence:
|
|
137
|
+
new_args = copy.copy(args)
|
|
138
|
+
del new_args[i:i+len_sub]
|
|
139
|
+
|
|
140
|
+
return new_args, True
|
|
141
|
+
|
|
142
|
+
return new_args, False
|
|
104
143
|
|
|
105
144
|
def print_chain(cmd: 'Command'):
|
|
106
145
|
print(f'{cmd.command()}', end = '')
|
|
@@ -109,31 +148,76 @@ class Command:
|
|
|
109
148
|
cmd = s
|
|
110
149
|
print()
|
|
111
150
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
151
|
+
class InvalidState(Exception):
|
|
152
|
+
def __init__(self, state: ReplState):
|
|
153
|
+
super().__init__(f'Invalid state')
|
|
154
|
+
|
|
155
|
+
class ValidateHandler:
|
|
156
|
+
def __init__(self, cmd: Command, args: list[str], state: ReplState, apply = True):
|
|
157
|
+
self.cmd = cmd
|
|
158
|
+
self.args = args
|
|
159
|
+
self.state = state
|
|
160
|
+
self.apply = apply
|
|
161
|
+
|
|
162
|
+
def __enter__(self) -> tuple[list[str], ReplState]:
|
|
163
|
+
state = self.state
|
|
164
|
+
args = self.args
|
|
165
|
+
if self.apply:
|
|
166
|
+
state, args = self.cmd.apply_state(args, state)
|
|
167
|
+
|
|
168
|
+
if not self.cmd.validate_state(state):
|
|
169
|
+
raise InvalidState(state)
|
|
170
|
+
|
|
171
|
+
return args, state
|
|
172
|
+
|
|
173
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
174
|
+
return False
|
|
175
|
+
|
|
176
|
+
class ExtractOptionsHandler:
|
|
177
|
+
def __init__(self, args: list[str], options: list[str] = None):
|
|
178
|
+
self.args = args
|
|
179
|
+
self.options = options
|
|
180
|
+
|
|
181
|
+
def __enter__(self) -> tuple[list[str], list[str]]:
|
|
182
|
+
args, _, _, options = Command.extract_options(self.args, options=self.options)
|
|
183
|
+
return args, options
|
|
184
|
+
|
|
185
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
186
|
+
return False
|
|
187
|
+
|
|
188
|
+
class ExtractTrailingOptionsHandler:
|
|
189
|
+
def __init__(self, args: list[str], trailing: list[str] = None):
|
|
190
|
+
self.args = args
|
|
191
|
+
self.trailing = trailing
|
|
192
|
+
|
|
193
|
+
def __enter__(self) -> tuple[list[str], list[str]]:
|
|
194
|
+
args, trailing, _, _ = Command.extract_options(self.args, trailing=self.trailing)
|
|
195
|
+
return args, trailing
|
|
196
|
+
|
|
197
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
198
|
+
return False
|
|
199
|
+
|
|
200
|
+
class ExtractAllOptionsHandler:
|
|
201
|
+
def __init__(self, args: list[str], trailing: list[str] = None, sequence: list[str] = None, options: list[str] = None):
|
|
202
|
+
self.args = args
|
|
203
|
+
self.trailing = trailing
|
|
204
|
+
self.sequence = sequence
|
|
205
|
+
self.options = options
|
|
206
|
+
|
|
207
|
+
def __enter__(self) -> tuple[list[str], list[str]]:
|
|
208
|
+
return Command.extract_options(self.args, trailing=self.trailing, sequence=self.sequence, options=self.options)
|
|
209
|
+
|
|
210
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
211
|
+
return False
|
|
212
|
+
|
|
213
|
+
class ExtractSequenceOptionsHandler:
|
|
214
|
+
def __init__(self, args: list[str], sequence: list[str]):
|
|
215
|
+
self.args = args
|
|
216
|
+
self.sequence = sequence
|
|
217
|
+
|
|
218
|
+
def __enter__(self) -> tuple[list[str], list[str]]:
|
|
219
|
+
args, _, sequence, _ = Command.extract_options(self.args, sequence=self.sequence)
|
|
220
|
+
return args, sequence
|
|
221
|
+
|
|
222
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
223
|
+
return False
|
adam/commands/commands_utils.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
from concurrent.futures import ThreadPoolExecutor
|
|
2
1
|
from kubernetes import client
|
|
3
2
|
from typing import List
|
|
4
3
|
|
|
5
4
|
from adam.checks.check_utils import run_checks
|
|
6
5
|
from adam.columns.columns import Columns, collect_checks
|
|
7
|
-
from adam.
|
|
6
|
+
from adam.utils_issues import IssuesUtils
|
|
8
7
|
from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
9
8
|
from adam.utils_k8s.pods import Pods
|
|
10
9
|
from adam.utils_k8s.statefulsets import StatefulSets
|
|
@@ -20,18 +19,10 @@ def show_pods(pods: List[client.V1Pod], ns: str, show_namespace = True, show_hos
|
|
|
20
19
|
if show_host_id:
|
|
21
20
|
names = [pod.metadata.name for pod in pods]
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if executor:
|
|
28
|
-
return executor.submit(get_host_id_with_pod, pod, ns)
|
|
29
|
-
|
|
30
|
-
id = CassandraNodes.get_host_id(pod, ns)
|
|
31
|
-
|
|
32
|
-
return (id, pod)
|
|
33
|
-
|
|
34
|
-
host_ids_by_pod = {pod: id for id, pod in Pods.on_pods(names, ns, body, action='get-host-id', show_out=False)}
|
|
22
|
+
msg = 'd`Retrieving|Retrived {size} host ids'
|
|
23
|
+
with Pods.parallelize(names, msg=msg, action = 'get-host-id') as exec:
|
|
24
|
+
host_pods = exec.map(lambda pod: (CassandraNodes.get_host_id(pod, ns), pod))
|
|
25
|
+
host_ids_by_pod = {pod: id for id, pod in host_pods}
|
|
35
26
|
|
|
36
27
|
def line(pod: client.V1Pod):
|
|
37
28
|
pod_cnt = len(pod.status.container_statuses)
|
|
@@ -70,10 +61,10 @@ def show_rollout(sts: str, ns: str):
|
|
|
70
61
|
else:
|
|
71
62
|
log2(f'Cluster has completed rollout {d} ago.')
|
|
72
63
|
|
|
73
|
-
def show_table(state: ReplState, pods: list[str], cols: str, header: str,
|
|
64
|
+
def show_table(state: ReplState, pods: list[str], cols: str, header: str, show_out=False):
|
|
74
65
|
columns = Columns.create_columns(cols)
|
|
75
66
|
|
|
76
|
-
results = run_checks(cluster=state.sts, pod=state.pod, namespace=state.namespace, checks=collect_checks(columns),
|
|
67
|
+
results = run_checks(cluster=state.sts, pod=state.pod, namespace=state.namespace, checks=collect_checks(columns), show_out=show_out)
|
|
77
68
|
|
|
78
69
|
def line(pod_name: str):
|
|
79
70
|
cells = [c.pod_value(results, pod_name) for c in columns]
|
|
@@ -84,4 +75,4 @@ def show_table(state: ReplState, pods: list[str], cols: str, header: str, show_o
|
|
|
84
75
|
|
|
85
76
|
log(lines_to_tabular(lines, header, separator=','))
|
|
86
77
|
|
|
87
|
-
|
|
78
|
+
IssuesUtils.show(results, state.in_repl)
|
adam/commands/cp.py
CHANGED
|
@@ -29,47 +29,41 @@ class ClipboardCopy(Command):
|
|
|
29
29
|
if not(args := self.args(cmd)):
|
|
30
30
|
return super().run(cmd, state)
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
log2(f' {value}')
|
|
65
|
-
|
|
66
|
-
return 'value-copied'
|
|
32
|
+
with self.validate(args, state) as (args, state):
|
|
33
|
+
if len(args) < 1:
|
|
34
|
+
if state.in_repl:
|
|
35
|
+
log2('Key is required.')
|
|
36
|
+
log2()
|
|
37
|
+
log2('Keys:')
|
|
38
|
+
log2(lines_to_tabular([f'{k},{v}' for k, v in CliCommands.values(state, collapse=True).items()], separator=','))
|
|
39
|
+
else:
|
|
40
|
+
log2('* Key is missing.')
|
|
41
|
+
Command.display_help()
|
|
42
|
+
|
|
43
|
+
return 'command-missing'
|
|
44
|
+
|
|
45
|
+
key = args[0]
|
|
46
|
+
if not key in CliCommands.values(state):
|
|
47
|
+
if state.in_repl:
|
|
48
|
+
log2('Key is required.')
|
|
49
|
+
log2()
|
|
50
|
+
log2('Keys:')
|
|
51
|
+
log2(lines_to_tabular([f'{k},{v}' for k, v in CliCommands.values(state, collapse=True).items()], separator=','))
|
|
52
|
+
else:
|
|
53
|
+
log2('* Invalid key')
|
|
54
|
+
Command.display_help()
|
|
55
|
+
|
|
56
|
+
return 'command-invalid'
|
|
57
|
+
|
|
58
|
+
value = CliCommands.values(state)[key]
|
|
59
|
+
pyperclip.copy(value)
|
|
60
|
+
log2('The following line has been copied to clipboard. Use <Ctrl-V> to use it.')
|
|
61
|
+
log2(f' {value}')
|
|
62
|
+
|
|
63
|
+
return 'value-copied'
|
|
67
64
|
|
|
68
65
|
def completion(self, state: ReplState):
|
|
69
|
-
|
|
70
|
-
return {ClipboardCopy.COMMAND: {key: None for key in CliCommands.values(state).keys()}}
|
|
71
|
-
|
|
72
|
-
return {}
|
|
66
|
+
return super().completion(state, lambda: {key: None for key in CliCommands.values(state).keys()})
|
|
73
67
|
|
|
74
68
|
def help(self, _: ReplState):
|
|
75
69
|
return f"{ClipboardCopy.COMMAND} <key>\t copy a value to clipboard for conveninence"
|
|
@@ -1,15 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
import time
|
|
2
|
+
from adam.commands.cql.utils_cql import cassandra_keyspaces, cassandra_table_names
|
|
3
|
+
from adam.commands.export.exporter import Exporter
|
|
4
|
+
from adam.commands.export.export_databases import ExportDatabases
|
|
2
5
|
from adam.config import Config
|
|
3
6
|
from adam.repl_state import ReplState
|
|
4
|
-
from adam.sql.sql_completer import SqlCompleter
|
|
7
|
+
from adam.sql.sql_completer import SqlCompleter, SqlVariant
|
|
8
|
+
from adam.utils import log_timing
|
|
5
9
|
|
|
6
10
|
def cql_completions(state: ReplState) -> dict[str, any]:
|
|
7
11
|
ps = Config().get('cql.alter-tables.gc-grace-periods', '3600,86400,864000,7776000').split(',')
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
# warm up caches
|
|
13
|
+
with log_timing('cassandra_keyspaces'):
|
|
14
|
+
cassandra_keyspaces(state)
|
|
15
|
+
with log_timing('cassandra_table_names'):
|
|
16
|
+
cassandra_table_names(state)
|
|
17
|
+
with log_timing('ExportDatabases.database_names'):
|
|
18
|
+
ExportDatabases.database_names()
|
|
19
|
+
|
|
20
|
+
expandables = {
|
|
21
|
+
'keyspaces': lambda: cassandra_keyspaces(state),
|
|
22
|
+
'table-props': lambda: {
|
|
23
|
+
'GC_GRACE_SECONDS': ps
|
|
24
|
+
},
|
|
25
|
+
'export-dbs': lambda: ExportDatabases.database_names(),
|
|
26
|
+
'export-sessions': lambda: Exporter.export_session_names(state.sts, state.pod, state.namespace),
|
|
27
|
+
'export-sessions-incomplete': lambda: Exporter.export_session_names(state.sts, state.pod, state.namespace, export_state='pending_import'),
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return SqlCompleter(
|
|
31
|
+
lambda: cassandra_table_names(state),
|
|
32
|
+
expandables=expandables,
|
|
33
|
+
variant=SqlVariant.CQL).completions_for_nesting()
|
adam/commands/cql/cqlsh.py
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import click
|
|
2
2
|
|
|
3
|
+
from adam.commands import extract_trailing_options
|
|
3
4
|
from adam.commands.command import Command
|
|
4
5
|
from adam.commands.command_helpers import ClusterOrPodCommandHelper
|
|
5
6
|
from adam.commands.cql.cql_completions import cql_completions
|
|
7
|
+
from adam.commands.cql.utils_cql import cassandra
|
|
6
8
|
from adam.utils_k8s.statefulsets import StatefulSets
|
|
7
|
-
from .cql_utils import run_cql
|
|
8
9
|
from adam.repl_state import ReplState, RequiredState
|
|
9
|
-
from adam.utils import log
|
|
10
|
+
from adam.utils import log
|
|
10
11
|
|
|
11
12
|
class Cqlsh(Command):
|
|
12
13
|
COMMAND = 'cql'
|
|
@@ -30,32 +31,10 @@ class Cqlsh(Command):
|
|
|
30
31
|
if not(args := self.args(cmd)):
|
|
31
32
|
return super().run(cmd, state)
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
background = False
|
|
38
|
-
opts = []
|
|
39
|
-
cqls = []
|
|
40
|
-
for index, arg in enumerate(args):
|
|
41
|
-
if arg.startswith('--'):
|
|
42
|
-
opts.append(arg)
|
|
43
|
-
elif index == len(args) -1 and arg == '&':
|
|
44
|
-
background = True
|
|
45
|
-
elif arg != '-e':
|
|
46
|
-
cqls.append(arg)
|
|
47
|
-
if not cqls:
|
|
48
|
-
if state.in_repl:
|
|
49
|
-
log2('Please enter cql statement. e.g. select host_id from system.local')
|
|
50
|
-
else:
|
|
51
|
-
log2('* CQL statement is missing.')
|
|
52
|
-
log2()
|
|
53
|
-
Command.display_help()
|
|
54
|
-
|
|
55
|
-
return 'no-cql'
|
|
56
|
-
|
|
57
|
-
cql = ' '.join(cqls)
|
|
58
|
-
return run_cql(state, cql, opts, show_out=True, background=background)
|
|
34
|
+
with self.validate(args, state) as (args, state):
|
|
35
|
+
with extract_trailing_options(args, '&') as (args, backgrounded):
|
|
36
|
+
with cassandra(state) as pods:
|
|
37
|
+
pods.cql(args, background=backgrounded)
|
|
59
38
|
|
|
60
39
|
def completion(self, state: ReplState) -> dict[str, any]:
|
|
61
40
|
if state.device != state.C:
|
|
@@ -63,8 +42,9 @@ class Cqlsh(Command):
|
|
|
63
42
|
return {}
|
|
64
43
|
|
|
65
44
|
if state.sts or state.pod:
|
|
66
|
-
|
|
67
|
-
|
|
45
|
+
c = cql_completions(state)
|
|
46
|
+
return c | \
|
|
47
|
+
{f'@{p}': c for p in StatefulSets.pod_names(state.sts, state.namespace)}
|
|
68
48
|
|
|
69
49
|
return {}
|
|
70
50
|
|