kaqing 2.0.52__py3-none-any.whl → 2.0.184__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 +9 -12
- adam/apps.py +20 -6
- adam/batch.py +15 -19
- adam/checks/check_utils.py +19 -49
- adam/checks/compactionstats.py +1 -1
- adam/checks/cpu.py +9 -3
- adam/checks/cpu_metrics.py +52 -0
- adam/checks/disk.py +3 -4
- adam/checks/gossip.py +1 -1
- adam/checks/memory.py +3 -3
- adam/checks/status.py +1 -1
- 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 +24 -0
- adam/commands/alter_tables.py +37 -63
- adam/commands/app/app.py +38 -0
- adam/commands/{app_ping.py → app/app_ping.py} +8 -14
- adam/commands/app/show_app_actions.py +49 -0
- adam/commands/{show → app}/show_app_id.py +9 -12
- adam/commands/{show → app}/show_app_queues.py +8 -14
- adam/commands/app/utils_app.py +98 -0
- adam/commands/audit/audit.py +81 -0
- adam/commands/audit/audit_repair_tables.py +72 -0
- adam/commands/audit/audit_run.py +50 -0
- adam/commands/audit/show_last10.py +37 -0
- adam/commands/audit/show_slow10.py +36 -0
- adam/commands/audit/show_top10.py +36 -0
- adam/commands/audit/utils_show_top10.py +71 -0
- adam/commands/bash/__init__.py +5 -0
- adam/commands/bash/bash.py +36 -0
- adam/commands/bash/bash_completer.py +93 -0
- adam/commands/bash/utils_bash.py +16 -0
- adam/commands/cat.py +36 -0
- adam/commands/cd.py +14 -89
- adam/commands/check.py +18 -21
- adam/commands/cli_commands.py +5 -6
- adam/commands/clipboard_copy.py +86 -0
- adam/commands/code.py +57 -0
- adam/commands/command.py +197 -35
- adam/commands/commands_utils.py +15 -31
- adam/commands/cql/cql_completions.py +29 -8
- adam/commands/cql/cqlsh.py +12 -27
- adam/commands/cql/utils_cql.py +297 -0
- adam/commands/deploy/code_start.py +7 -10
- adam/commands/deploy/code_stop.py +4 -21
- adam/commands/deploy/code_utils.py +5 -5
- adam/commands/deploy/deploy.py +4 -21
- adam/commands/deploy/deploy_frontend.py +14 -17
- adam/commands/deploy/deploy_pg_agent.py +3 -6
- adam/commands/deploy/deploy_pod.py +71 -79
- adam/commands/deploy/deploy_utils.py +16 -26
- adam/commands/deploy/undeploy.py +4 -21
- adam/commands/deploy/undeploy_frontend.py +4 -7
- adam/commands/deploy/undeploy_pg_agent.py +6 -8
- adam/commands/deploy/undeploy_pod.py +15 -16
- adam/commands/devices/__init__.py +0 -0
- adam/commands/devices/device.py +123 -0
- adam/commands/devices/device_app.py +163 -0
- adam/commands/devices/device_auit_log.py +49 -0
- adam/commands/devices/device_cass.py +179 -0
- adam/commands/devices/device_export.py +84 -0
- adam/commands/devices/device_postgres.py +150 -0
- adam/commands/devices/devices.py +25 -0
- adam/commands/download_file.py +47 -0
- adam/commands/exit.py +1 -4
- adam/commands/export/__init__.py +0 -0
- adam/commands/export/clean_up_all_export_sessions.py +37 -0
- adam/commands/export/clean_up_export_sessions.py +39 -0
- adam/commands/export/download_export_session.py +39 -0
- adam/commands/export/drop_export_database.py +39 -0
- adam/commands/export/drop_export_databases.py +37 -0
- adam/commands/export/export.py +53 -0
- adam/commands/export/export_databases.py +245 -0
- adam/commands/export/export_select.py +59 -0
- adam/commands/export/export_select_x.py +54 -0
- adam/commands/export/export_sessions.py +209 -0
- adam/commands/export/export_use.py +49 -0
- adam/commands/export/exporter.py +332 -0
- adam/commands/export/import_files.py +44 -0
- adam/commands/export/import_session.py +44 -0
- adam/commands/export/importer.py +81 -0
- adam/commands/export/importer_athena.py +177 -0
- adam/commands/export/importer_sqlite.py +67 -0
- adam/commands/export/show_column_counts.py +45 -0
- adam/commands/export/show_export_databases.py +38 -0
- adam/commands/export/show_export_session.py +39 -0
- adam/commands/export/show_export_sessions.py +37 -0
- adam/commands/export/utils_export.py +343 -0
- adam/commands/find_files.py +51 -0
- adam/commands/find_processes.py +76 -0
- adam/commands/head.py +36 -0
- adam/commands/help.py +14 -9
- adam/commands/intermediate_command.py +49 -0
- adam/commands/issues.py +14 -40
- adam/commands/kubectl.py +38 -0
- adam/commands/login.py +26 -25
- adam/commands/logs.py +5 -7
- adam/commands/ls.py +11 -110
- adam/commands/medusa/medusa.py +4 -22
- adam/commands/medusa/medusa_backup.py +22 -29
- adam/commands/medusa/medusa_restore.py +40 -39
- adam/commands/medusa/medusa_show_backupjobs.py +19 -20
- adam/commands/medusa/medusa_show_restorejobs.py +15 -20
- adam/commands/nodetool.py +11 -15
- adam/commands/param_get.py +11 -14
- adam/commands/param_set.py +8 -12
- adam/commands/postgres/postgres.py +45 -46
- adam/commands/postgres/postgres_databases.py +269 -0
- adam/commands/postgres/postgres_ls.py +4 -8
- adam/commands/postgres/postgres_preview.py +5 -9
- adam/commands/postgres/psql_completions.py +4 -3
- adam/commands/postgres/utils_postgres.py +70 -0
- adam/commands/preview_table.py +10 -61
- adam/commands/pwd.py +14 -43
- adam/commands/reaper/reaper.py +4 -24
- adam/commands/reaper/reaper_forward.py +49 -56
- adam/commands/reaper/reaper_forward_session.py +6 -0
- adam/commands/reaper/reaper_forward_stop.py +10 -16
- adam/commands/reaper/reaper_restart.py +8 -15
- adam/commands/reaper/reaper_run_abort.py +8 -33
- adam/commands/reaper/reaper_runs.py +43 -58
- adam/commands/reaper/reaper_runs_abort.py +29 -49
- adam/commands/reaper/reaper_schedule_activate.py +9 -32
- adam/commands/reaper/reaper_schedule_start.py +9 -32
- adam/commands/reaper/reaper_schedule_stop.py +9 -32
- adam/commands/reaper/reaper_schedules.py +4 -14
- adam/commands/reaper/reaper_status.py +8 -16
- adam/commands/reaper/utils_reaper.py +194 -0
- adam/commands/repair/repair.py +4 -22
- adam/commands/repair/repair_log.py +6 -12
- adam/commands/repair/repair_run.py +29 -36
- adam/commands/repair/repair_scan.py +33 -39
- adam/commands/repair/repair_stop.py +6 -12
- adam/commands/report.py +25 -21
- adam/commands/restart.py +27 -28
- adam/commands/rollout.py +20 -25
- adam/commands/shell.py +12 -4
- adam/commands/show/show.py +11 -23
- adam/commands/show/show_adam.py +3 -3
- adam/commands/show/show_cassandra_repairs.py +35 -0
- adam/commands/show/show_cassandra_status.py +34 -52
- adam/commands/show/show_cassandra_version.py +5 -18
- adam/commands/show/show_commands.py +20 -25
- adam/commands/show/show_host.py +33 -0
- adam/commands/show/show_login.py +23 -27
- adam/commands/show/show_params.py +2 -5
- adam/commands/show/show_processes.py +16 -20
- adam/commands/show/show_storage.py +10 -20
- adam/commands/watch.py +27 -30
- adam/config.py +7 -15
- adam/embedded_params.py +1 -1
- adam/log.py +4 -4
- adam/pod_exec_result.py +13 -5
- adam/repl.py +126 -119
- adam/repl_commands.py +63 -29
- adam/repl_state.py +320 -71
- adam/sql/sql_completer.py +98 -383
- adam/sql/sql_state_machine.py +630 -0
- adam/sql/term_completer.py +14 -4
- adam/sso/authn_ad.py +6 -8
- adam/sso/authn_okta.py +4 -6
- adam/sso/cred_cache.py +4 -6
- adam/sso/idp.py +10 -13
- adam/utils.py +511 -10
- adam/utils_athena.py +145 -0
- adam/utils_audits.py +102 -0
- adam/utils_issues.py +32 -0
- adam/utils_k8s/__init__.py +0 -0
- adam/utils_k8s/app_clusters.py +28 -0
- adam/utils_k8s/app_pods.py +36 -0
- adam/utils_k8s/cassandra_clusters.py +44 -0
- adam/{k8s_utils → utils_k8s}/cassandra_nodes.py +11 -4
- adam/{k8s_utils → utils_k8s}/custom_resources.py +16 -17
- adam/{k8s_utils → utils_k8s}/deployment.py +2 -2
- adam/{k8s_utils → utils_k8s}/ingresses.py +2 -2
- adam/{k8s_utils → utils_k8s}/jobs.py +7 -11
- adam/utils_k8s/k8s.py +87 -0
- adam/{k8s_utils → utils_k8s}/kube_context.py +2 -2
- adam/{k8s_utils → utils_k8s}/pods.py +109 -74
- adam/{k8s_utils → utils_k8s}/secrets.py +7 -3
- adam/{k8s_utils → utils_k8s}/service_accounts.py +5 -4
- adam/{k8s_utils → utils_k8s}/services.py +2 -2
- adam/{k8s_utils → utils_k8s}/statefulsets.py +3 -14
- adam/utils_local.py +4 -0
- adam/utils_net.py +24 -0
- 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.52.dist-info → kaqing-2.0.184.dist-info}/METADATA +1 -1
- kaqing-2.0.184.dist-info/RECORD +244 -0
- adam/commands/app.py +0 -67
- adam/commands/bash.py +0 -87
- adam/commands/cp.py +0 -95
- adam/commands/cql/cql_table_completer.py +0 -8
- adam/commands/cql/cql_utils.py +0 -109
- adam/commands/describe/describe.py +0 -46
- adam/commands/describe/describe_keyspace.py +0 -60
- adam/commands/describe/describe_keyspaces.py +0 -50
- adam/commands/describe/describe_table.py +0 -60
- adam/commands/describe/describe_tables.py +0 -50
- adam/commands/devices.py +0 -89
- adam/commands/postgres/postgres_session.py +0 -240
- adam/commands/postgres/postgres_utils.py +0 -31
- adam/commands/postgres/psql_table_completer.py +0 -11
- adam/commands/reaper/reaper_session.py +0 -159
- adam/commands/show/show_app_actions.py +0 -53
- adam/commands/show/show_repairs.py +0 -47
- adam/k8s_utils/cassandra_clusters.py +0 -35
- adam/sql/sql_utils.py +0 -5
- kaqing-2.0.52.dist-info/RECORD +0 -184
- /adam/commands/{describe → app}/__init__.py +0 -0
- /adam/{k8s_utils → commands/audit}/__init__.py +0 -0
- /adam/{k8s_utils → utils_k8s}/config_maps.py +0 -0
- /adam/{k8s_utils → utils_k8s}/volumes.py +0 -0
- {kaqing-2.0.52.dist-info → kaqing-2.0.184.dist-info}/WHEEL +0 -0
- {kaqing-2.0.52.dist-info → kaqing-2.0.184.dist-info}/entry_points.txt +0 -0
- {kaqing-2.0.52.dist-info → kaqing-2.0.184.dist-info}/top_level.txt +0 -0
adam/commands/code.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import code
|
|
2
|
+
from functools import partial
|
|
3
|
+
|
|
4
|
+
from adam.commands.command import Command
|
|
5
|
+
from adam.commands.cql.utils_cql import cassandra_table_names, run_cql
|
|
6
|
+
from adam.repl_state import ReplState, RequiredState
|
|
7
|
+
from adam.utils import tabulize
|
|
8
|
+
from adam.utils_k8s.statefulsets import StatefulSets
|
|
9
|
+
|
|
10
|
+
class Code(Command):
|
|
11
|
+
COMMAND = 'python'
|
|
12
|
+
|
|
13
|
+
# the singleton pattern
|
|
14
|
+
def __new__(cls, *args, **kwargs):
|
|
15
|
+
if not hasattr(cls, 'instance'): cls.instance = super(Code, cls).__new__(cls)
|
|
16
|
+
|
|
17
|
+
return cls.instance
|
|
18
|
+
|
|
19
|
+
def __init__(self, successor: Command=None):
|
|
20
|
+
super().__init__(successor)
|
|
21
|
+
|
|
22
|
+
def command(self):
|
|
23
|
+
return Code.COMMAND
|
|
24
|
+
|
|
25
|
+
def required(self):
|
|
26
|
+
return RequiredState.NAMESPACE
|
|
27
|
+
|
|
28
|
+
def run(self, cmd: str, state: ReplState):
|
|
29
|
+
if not(args := self.args(cmd)):
|
|
30
|
+
return super().run(cmd, state)
|
|
31
|
+
|
|
32
|
+
with self.validate(args, state) as (args, state):
|
|
33
|
+
sts = state.sts
|
|
34
|
+
pod = state.pod
|
|
35
|
+
pods = StatefulSets.pod_names(state.sts, state.namespace)
|
|
36
|
+
tables = cassandra_table_names(state)
|
|
37
|
+
cql = partial(run_cql, state, show_out=True)
|
|
38
|
+
|
|
39
|
+
my_local = globals() | locals()
|
|
40
|
+
# my_local = globals() | {'StatefulSets': StatefulSets} | locals()
|
|
41
|
+
lines = [
|
|
42
|
+
'sts: StatefulSet name',
|
|
43
|
+
'pod: Pod name',
|
|
44
|
+
'pods: Pod names in the current StatefulSet',
|
|
45
|
+
'tables: Cassandra tables names in the current StatefulSet',
|
|
46
|
+
"cql('select...'): run cql statement"
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
code.interact(local=my_local, banner=tabulize(lines, header='Variables', separator=':'))
|
|
50
|
+
|
|
51
|
+
return state
|
|
52
|
+
|
|
53
|
+
def completion(self, state: ReplState):
|
|
54
|
+
return super().completion(state)
|
|
55
|
+
|
|
56
|
+
def help(self, _: ReplState):
|
|
57
|
+
return f'{Code.COMMAND} \t invoke interactive Python shell'
|
adam/commands/command.py
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
from abc import abstractmethod
|
|
2
|
+
from collections.abc import Callable
|
|
2
3
|
import copy
|
|
3
4
|
import subprocess
|
|
4
5
|
import sys
|
|
5
|
-
from typing import
|
|
6
|
+
from typing import Union
|
|
6
7
|
|
|
7
|
-
from adam.commands.command_helpers import ClusterCommandHelper
|
|
8
8
|
from adam.repl_state import ReplState, RequiredState
|
|
9
|
-
from adam.utils import
|
|
9
|
+
from adam.utils import is_lambda, log2
|
|
10
10
|
|
|
11
11
|
repl_cmds: list['Command'] = []
|
|
12
12
|
|
|
@@ -29,8 +29,30 @@ class Command:
|
|
|
29
29
|
|
|
30
30
|
return None
|
|
31
31
|
|
|
32
|
-
def completion(self,
|
|
33
|
-
#
|
|
32
|
+
def completion(self, state: ReplState, leaf: dict[str, any] = None, pods: tuple[list[str], str] = None) -> dict[str, any]:
|
|
33
|
+
# pods is a tuple of list of pod names and the current pod repl is on
|
|
34
|
+
if not pods:
|
|
35
|
+
return self._completion(state, leaf)
|
|
36
|
+
|
|
37
|
+
c = {}
|
|
38
|
+
|
|
39
|
+
pod_names = pods[0]
|
|
40
|
+
pod = pods[1]
|
|
41
|
+
|
|
42
|
+
if pod:
|
|
43
|
+
c |= self._completion(state, leaf)
|
|
44
|
+
|
|
45
|
+
c |= {f'@{p}': self._completion(state, leaf, to_validate=False) for p in pod_names if p != pod}
|
|
46
|
+
|
|
47
|
+
return c
|
|
48
|
+
|
|
49
|
+
def _completion(self, state: ReplState, leaf: dict[str, any] = None, to_validate = True) -> dict[str, any]:
|
|
50
|
+
if to_validate and not self.validate_state(state, show_err=False):
|
|
51
|
+
return {}
|
|
52
|
+
|
|
53
|
+
if is_lambda(leaf):
|
|
54
|
+
leaf = leaf()
|
|
55
|
+
|
|
34
56
|
d = leaf
|
|
35
57
|
for t in reversed(self.command().split(' ')):
|
|
36
58
|
d = {t: d}
|
|
@@ -40,8 +62,11 @@ class Command:
|
|
|
40
62
|
def required(self) -> RequiredState:
|
|
41
63
|
return None
|
|
42
64
|
|
|
43
|
-
def
|
|
44
|
-
return
|
|
65
|
+
def validate(self, args: list[str], state: ReplState, apply = True):
|
|
66
|
+
return ValidateStateHandler(self, args, state, apply = apply)
|
|
67
|
+
|
|
68
|
+
def validate_state(self, state: ReplState, show_err = True):
|
|
69
|
+
return state.validate(self.required(), show_err=show_err)
|
|
45
70
|
|
|
46
71
|
def help(self, _: ReplState) -> str:
|
|
47
72
|
return None
|
|
@@ -54,8 +79,11 @@ class Command:
|
|
|
54
79
|
|
|
55
80
|
return a
|
|
56
81
|
|
|
57
|
-
def apply_state(self, args: list[str], state: ReplState, resolve_pg = True) -> tuple[ReplState, list[str]]:
|
|
58
|
-
|
|
82
|
+
def apply_state(self, args: list[str], state: ReplState, resolve_pg = True, args_to_check = 6) -> tuple[ReplState, list[str]]:
|
|
83
|
+
"""
|
|
84
|
+
Applies any contextual arguments such as namespace or statefulset to the ReplState and returns any non-contextual arguments.
|
|
85
|
+
"""
|
|
86
|
+
return state.apply_args(args, cmd=self.command_tokens(), resolve_pg=resolve_pg, args_to_check=args_to_check)
|
|
59
87
|
|
|
60
88
|
def command_tokens(self):
|
|
61
89
|
return self.command().split(' ')
|
|
@@ -86,17 +114,50 @@ class Command:
|
|
|
86
114
|
args.extend(['--help'])
|
|
87
115
|
subprocess.run(args)
|
|
88
116
|
|
|
89
|
-
def extract_options(args: list[str],
|
|
90
|
-
|
|
117
|
+
def extract_options(args: list[str], trailing: Union[str, list[str]] = [], sequence: list[str] = [], options: list[str] = []):
|
|
118
|
+
found_options: list[str] = []
|
|
119
|
+
found_trailing = None
|
|
120
|
+
found_sequence = None
|
|
121
|
+
|
|
122
|
+
if trailing is None:
|
|
123
|
+
trailing = []
|
|
124
|
+
elif isinstance(trailing, str):
|
|
125
|
+
trailing = [trailing]
|
|
126
|
+
|
|
127
|
+
if options is None:
|
|
128
|
+
options = []
|
|
129
|
+
elif isinstance(options, str):
|
|
130
|
+
options = [options]
|
|
131
|
+
|
|
132
|
+
if args and trailing:
|
|
133
|
+
while args[-1] in trailing:
|
|
134
|
+
found_trailing = True
|
|
135
|
+
args = args[:-1]
|
|
136
|
+
|
|
137
|
+
if args and sequence:
|
|
138
|
+
args, found_sequence = Command.extract_option_sequence(args, sequence)
|
|
91
139
|
|
|
92
140
|
new_args: list[str] = []
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
141
|
+
if args:
|
|
142
|
+
for arg in args:
|
|
143
|
+
if arg in options:
|
|
144
|
+
found_options.append(arg)
|
|
145
|
+
else:
|
|
146
|
+
new_args.append(arg)
|
|
147
|
+
|
|
148
|
+
return new_args, found_trailing, found_sequence, found_options
|
|
98
149
|
|
|
99
|
-
|
|
150
|
+
def extract_option_sequence(args, sequence):
|
|
151
|
+
len_sub = len(sequence)
|
|
152
|
+
len_main = len(args)
|
|
153
|
+
for i in range(len_main - len_sub + 1):
|
|
154
|
+
if args[i:i+len_sub] == sequence:
|
|
155
|
+
new_args = copy.copy(args)
|
|
156
|
+
del new_args[i:i+len_sub]
|
|
157
|
+
|
|
158
|
+
return new_args, True
|
|
159
|
+
|
|
160
|
+
return new_args, False
|
|
100
161
|
|
|
101
162
|
def print_chain(cmd: 'Command'):
|
|
102
163
|
print(f'{cmd.command()}', end = '')
|
|
@@ -105,28 +166,129 @@ class Command:
|
|
|
105
166
|
cmd = s
|
|
106
167
|
print()
|
|
107
168
|
|
|
108
|
-
|
|
109
|
-
|
|
169
|
+
class InvalidStateException(Exception):
|
|
170
|
+
def __init__(self, state: ReplState):
|
|
171
|
+
super().__init__(f'Invalid state')
|
|
110
172
|
|
|
111
|
-
|
|
112
|
-
|
|
173
|
+
class ValidateStateHandler:
|
|
174
|
+
def __init__(self, cmd: Command, args: list[str], state: ReplState, apply = True):
|
|
175
|
+
self.cmd = cmd
|
|
176
|
+
self.args = args
|
|
177
|
+
self.state = state
|
|
178
|
+
self.apply = apply
|
|
113
179
|
|
|
114
|
-
|
|
180
|
+
def __enter__(self) -> tuple[list[str], ReplState]:
|
|
181
|
+
state = self.state
|
|
182
|
+
args = self.args
|
|
183
|
+
if self.apply:
|
|
184
|
+
state, args = self.cmd.apply_state(args, state)
|
|
115
185
|
else:
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
186
|
+
args = args[len(self.cmd.command_tokens()):]
|
|
187
|
+
|
|
188
|
+
if not self.cmd.validate_state(state):
|
|
189
|
+
raise InvalidStateException(state)
|
|
190
|
+
|
|
191
|
+
return args, state
|
|
192
|
+
|
|
193
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
194
|
+
return False
|
|
195
|
+
|
|
196
|
+
class InvalidArgumentsException(Exception):
|
|
197
|
+
def __init__(self):
|
|
198
|
+
super().__init__(f'Invalid arguments')
|
|
199
|
+
|
|
200
|
+
class ValidateArgCountHandler:
|
|
201
|
+
def __init__(self, args: list[str], state: ReplState, at_least: int = 1, exactly: int = 1,
|
|
202
|
+
name: str = None, msg: Callable[[], None] = None, default: Union[str, list[str]] = None,
|
|
203
|
+
separator: str = None):
|
|
204
|
+
self.args = args
|
|
205
|
+
self.state = state
|
|
206
|
+
self.at_least = at_least
|
|
207
|
+
self.exactly = exactly
|
|
208
|
+
self.name = name
|
|
209
|
+
self.msg = msg
|
|
210
|
+
self.default = default
|
|
211
|
+
self.separator = separator
|
|
212
|
+
|
|
213
|
+
def __enter__(self) -> Union[tuple[list[str], ReplState], tuple[str, ReplState]]:
|
|
214
|
+
if self.exactly > 0 and len(self.args) != self.exactly or len(self.args) < self.at_least:
|
|
215
|
+
if self.default:
|
|
216
|
+
v = self.default
|
|
217
|
+
if isinstance(v, list):
|
|
218
|
+
v = ' '.join(v)
|
|
219
|
+
|
|
220
|
+
return v
|
|
221
|
+
|
|
222
|
+
if self.state.in_repl:
|
|
223
|
+
if self.msg:
|
|
224
|
+
self.msg()
|
|
225
|
+
elif self.name:
|
|
226
|
+
log2(f'{self.name} is required.')
|
|
227
|
+
elif self.name:
|
|
228
|
+
log2(f'* {self.name} is missing.')
|
|
229
|
+
|
|
120
230
|
Command.display_help()
|
|
121
231
|
|
|
122
|
-
|
|
232
|
+
raise InvalidArgumentsException()
|
|
233
|
+
|
|
234
|
+
if self.separator == ' ':
|
|
235
|
+
return self.args
|
|
236
|
+
|
|
237
|
+
# join and re-split with separator
|
|
238
|
+
args_to_return = ' '.join(self.args)
|
|
239
|
+
if self.separator:
|
|
240
|
+
args_to_return = [arg.strip(' ') for arg in args_to_return.split(self.separator)]
|
|
241
|
+
|
|
242
|
+
return args_to_return
|
|
243
|
+
|
|
244
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
245
|
+
return False
|
|
246
|
+
|
|
247
|
+
class ExtractOptionsHandler:
|
|
248
|
+
def __init__(self, args: list[str], options: list[str] = None):
|
|
249
|
+
self.args = args
|
|
250
|
+
self.options = options
|
|
251
|
+
|
|
252
|
+
def __enter__(self) -> tuple[list[str], list[str]]:
|
|
253
|
+
args, _, _, options = Command.extract_options(self.args, options=self.options)
|
|
254
|
+
return args, options
|
|
255
|
+
|
|
256
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
257
|
+
return False
|
|
258
|
+
|
|
259
|
+
class ExtractTrailingOptionsHandler:
|
|
260
|
+
def __init__(self, args: list[str], trailing: list[str] = None):
|
|
261
|
+
self.args = args
|
|
262
|
+
self.trailing = trailing
|
|
263
|
+
|
|
264
|
+
def __enter__(self) -> tuple[list[str], list[str]]:
|
|
265
|
+
args, trailing, _, _ = Command.extract_options(self.args, trailing=self.trailing)
|
|
266
|
+
return args, trailing
|
|
267
|
+
|
|
268
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
269
|
+
return False
|
|
270
|
+
|
|
271
|
+
class ExtractAllOptionsHandler:
|
|
272
|
+
def __init__(self, args: list[str], trailing: list[str] = None, sequence: list[str] = None, options: list[str] = None):
|
|
273
|
+
self.args = args
|
|
274
|
+
self.trailing = trailing
|
|
275
|
+
self.sequence = sequence
|
|
276
|
+
self.options = options
|
|
277
|
+
|
|
278
|
+
def __enter__(self) -> tuple[list[str], list[str]]:
|
|
279
|
+
return Command.extract_options(self.args, trailing=self.trailing, sequence=self.sequence, options=self.options)
|
|
280
|
+
|
|
281
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
282
|
+
return False
|
|
283
|
+
|
|
284
|
+
class ExtractSequenceOptionsHandler:
|
|
285
|
+
def __init__(self, args: list[str], sequence: list[str]):
|
|
286
|
+
self.args = args
|
|
287
|
+
self.sequence = sequence
|
|
123
288
|
|
|
124
|
-
def
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
log('Sub-Commands:')
|
|
289
|
+
def __enter__(self) -> tuple[list[str], list[str]]:
|
|
290
|
+
args, _, sequence, _ = Command.extract_options(self.args, sequence=self.sequence)
|
|
291
|
+
return args, sequence
|
|
128
292
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
log()
|
|
132
|
-
ClusterCommandHelper.cluster_help()
|
|
293
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
294
|
+
return False
|
adam/commands/commands_utils.py
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
from concurrent.futures import ThreadPoolExecutor
|
|
2
|
-
import time
|
|
3
1
|
from kubernetes import client
|
|
4
2
|
from typing import List
|
|
5
3
|
|
|
6
4
|
from adam.checks.check_utils import run_checks
|
|
7
5
|
from adam.columns.columns import Columns, collect_checks
|
|
8
|
-
from adam.
|
|
9
|
-
from adam.
|
|
10
|
-
from adam.
|
|
11
|
-
from adam.
|
|
6
|
+
from adam.utils_issues import IssuesUtils
|
|
7
|
+
from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
8
|
+
from adam.utils_k8s.pods import Pods
|
|
9
|
+
from adam.utils_k8s.statefulsets import StatefulSets
|
|
12
10
|
from adam.repl_state import ReplState
|
|
13
|
-
from adam.utils import
|
|
11
|
+
from adam.utils import SORT, duration, tabulize, log, log2
|
|
14
12
|
|
|
15
13
|
def show_pods(pods: List[client.V1Pod], ns: str, show_namespace = True, show_host_id = True):
|
|
16
14
|
if len(pods) == 0:
|
|
@@ -21,18 +19,10 @@ def show_pods(pods: List[client.V1Pod], ns: str, show_namespace = True, show_hos
|
|
|
21
19
|
if show_host_id:
|
|
22
20
|
names = [pod.metadata.name for pod in pods]
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if executor:
|
|
29
|
-
return executor.submit(get_host_id_with_pod, pod, ns)
|
|
30
|
-
|
|
31
|
-
id = CassandraNodes.get_host_id(pod, ns)
|
|
32
|
-
|
|
33
|
-
return (id, pod)
|
|
34
|
-
|
|
35
|
-
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}
|
|
36
26
|
|
|
37
27
|
def line(pod: client.V1Pod):
|
|
38
28
|
pod_cnt = len(pod.status.container_statuses)
|
|
@@ -58,9 +48,7 @@ def show_pods(pods: List[client.V1Pod], ns: str, show_namespace = True, show_hos
|
|
|
58
48
|
line += f"@{ns}"
|
|
59
49
|
return line + f" {ready}/{pod_cnt} {status}"
|
|
60
50
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
log(lines_to_tabular(pod_names, 'HOST_ID POD_NAME READY POD_STATUS' if show_host_id else 'POD_NAME READY POD_STATUS'))
|
|
51
|
+
tabulize(pods, line, header='HOST_ID POD_NAME READY POD_STATUS' if show_host_id else 'POD_NAME READY POD_STATUS')
|
|
64
52
|
|
|
65
53
|
def show_rollout(sts: str, ns: str):
|
|
66
54
|
restarted, rollingout = StatefulSets.restarted_at(sts, ns)
|
|
@@ -71,18 +59,14 @@ def show_rollout(sts: str, ns: str):
|
|
|
71
59
|
else:
|
|
72
60
|
log2(f'Cluster has completed rollout {d} ago.')
|
|
73
61
|
|
|
74
|
-
def show_table(state: ReplState, pods: list[str], cols: str, header: str,
|
|
62
|
+
def show_table(state: ReplState, pods: list[str], cols: str, header: str, show_out=False):
|
|
75
63
|
columns = Columns.create_columns(cols)
|
|
76
64
|
|
|
77
|
-
results = run_checks(cluster=state.sts, pod=state.pod, namespace=state.namespace, checks=collect_checks(columns),
|
|
65
|
+
results = run_checks(cluster=state.sts, pod=state.pod, namespace=state.namespace, checks=collect_checks(columns), show_out=show_out)
|
|
78
66
|
|
|
79
67
|
def line(pod_name: str):
|
|
80
|
-
|
|
81
|
-
return ','.join(cells)
|
|
82
|
-
|
|
83
|
-
lines = [line(pod) for pod in pods]
|
|
84
|
-
lines.sort()
|
|
68
|
+
return
|
|
85
69
|
|
|
86
|
-
|
|
70
|
+
tabulize(pods, lambda p: ','.join([c.pod_value(results, p) for c in columns]), header=header, separator=',', sorted=SORT)
|
|
87
71
|
|
|
88
|
-
|
|
72
|
+
IssuesUtils.show(results, state.in_repl)
|
|
@@ -1,11 +1,32 @@
|
|
|
1
|
-
from adam.commands.cql.
|
|
1
|
+
from adam.commands.cql.utils_cql import cassandra_keyspaces, cassandra_table_names
|
|
2
|
+
from adam.commands.export.export_sessions import ExportSessions
|
|
3
|
+
from adam.commands.export.export_databases import ExportDatabases
|
|
4
|
+
from adam.config import Config
|
|
2
5
|
from adam.repl_state import ReplState
|
|
3
|
-
from adam.sql.sql_completer import SqlCompleter
|
|
6
|
+
from adam.sql.sql_completer import SqlCompleter, SqlVariant
|
|
7
|
+
from adam.utils import log_timing
|
|
4
8
|
|
|
5
9
|
def cql_completions(state: ReplState) -> dict[str, any]:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
ps = Config().get('cql.alter-tables.gc-grace-periods', '3600,86400,864000,7776000').split(',')
|
|
11
|
+
# warm up caches
|
|
12
|
+
with log_timing('cassandra_keyspaces'):
|
|
13
|
+
cassandra_keyspaces(state)
|
|
14
|
+
with log_timing('cassandra_table_names'):
|
|
15
|
+
cassandra_table_names(state)
|
|
16
|
+
with log_timing('ExportDatabases.database_names'):
|
|
17
|
+
ExportDatabases.database_names()
|
|
18
|
+
|
|
19
|
+
expandables = {
|
|
20
|
+
'keyspaces': lambda: cassandra_keyspaces(state),
|
|
21
|
+
'table-props': lambda: {
|
|
22
|
+
'GC_GRACE_SECONDS': ps
|
|
23
|
+
},
|
|
24
|
+
'export-dbs': lambda: ExportDatabases.database_names(),
|
|
25
|
+
'export-sessions': lambda: ExportSessions.export_session_names(state.sts, state.pod, state.namespace),
|
|
26
|
+
'export-sessions-incomplete': lambda: ExportSessions.export_session_names(state.sts, state.pod, state.namespace, export_state='pending_import'),
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return SqlCompleter(
|
|
30
|
+
lambda: cassandra_table_names(state),
|
|
31
|
+
expandables=expandables,
|
|
32
|
+
variant=SqlVariant.CQL).completions_for_nesting()
|
adam/commands/cql/cqlsh.py
CHANGED
|
@@ -1,11 +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
|
|
6
|
-
from .
|
|
7
|
+
from adam.commands.cql.utils_cql import cassandra
|
|
8
|
+
from adam.utils_k8s.statefulsets import StatefulSets
|
|
7
9
|
from adam.repl_state import ReplState, RequiredState
|
|
8
|
-
from adam.utils import log
|
|
10
|
+
from adam.utils import log
|
|
9
11
|
|
|
10
12
|
class Cqlsh(Command):
|
|
11
13
|
COMMAND = 'cql'
|
|
@@ -29,29 +31,10 @@ class Cqlsh(Command):
|
|
|
29
31
|
if not(args := self.args(cmd)):
|
|
30
32
|
return super().run(cmd, state)
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
opts = []
|
|
37
|
-
cqls = []
|
|
38
|
-
for arg in args:
|
|
39
|
-
if arg.startswith('--'):
|
|
40
|
-
opts.append(arg)
|
|
41
|
-
elif arg != '-e':
|
|
42
|
-
cqls.append(arg)
|
|
43
|
-
if not cqls:
|
|
44
|
-
if state.in_repl:
|
|
45
|
-
log2('Please enter cql statement. e.g. select host_id from system.local')
|
|
46
|
-
else:
|
|
47
|
-
log2('* CQL statement is missing.')
|
|
48
|
-
log2()
|
|
49
|
-
Command.display_help()
|
|
50
|
-
|
|
51
|
-
return 'no-cql'
|
|
52
|
-
|
|
53
|
-
cql = ' '.join(cqls)
|
|
54
|
-
return run_cql(state, cql, opts, show_out=True)
|
|
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, backgrounded=backgrounded)
|
|
55
38
|
|
|
56
39
|
def completion(self, state: ReplState) -> dict[str, any]:
|
|
57
40
|
if state.device != state.C:
|
|
@@ -59,12 +42,14 @@ class Cqlsh(Command):
|
|
|
59
42
|
return {}
|
|
60
43
|
|
|
61
44
|
if state.sts or state.pod:
|
|
62
|
-
|
|
45
|
+
c = cql_completions(state)
|
|
46
|
+
return c | \
|
|
47
|
+
{f'@{p}': c for p in StatefulSets.pod_names(state.sts, state.namespace)}
|
|
63
48
|
|
|
64
49
|
return {}
|
|
65
50
|
|
|
66
51
|
def help(self, _: ReplState) -> str:
|
|
67
|
-
return f'
|
|
52
|
+
return f'<cql-statements> [&]\t run cqlsh with queries'
|
|
68
53
|
|
|
69
54
|
class CqlCommandHelper(click.Command):
|
|
70
55
|
def get_help(self, ctx: click.Context):
|