kaqing 2.0.171__py3-none-any.whl → 2.0.203__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.
- adam/app_session.py +5 -10
- adam/apps.py +18 -4
- adam/batch.py +7 -7
- adam/checks/check_utils.py +3 -1
- adam/checks/disk.py +2 -3
- adam/columns/memory.py +3 -4
- adam/commands/__init__.py +15 -6
- adam/commands/alter_tables.py +26 -41
- adam/commands/app/__init__.py +0 -0
- adam/commands/{app_cmd.py → app/app.py} +2 -2
- adam/commands/{show → app}/show_app_actions.py +7 -15
- adam/commands/{show → app}/show_app_queues.py +1 -4
- adam/{utils_app.py → commands/app/utils_app.py} +9 -1
- adam/commands/audit/audit.py +9 -26
- adam/commands/audit/audit_repair_tables.py +5 -7
- adam/commands/audit/audit_run.py +1 -1
- adam/commands/audit/completions_l.py +15 -0
- adam/commands/audit/show_last10.py +2 -14
- adam/commands/audit/show_slow10.py +2 -13
- adam/commands/audit/show_top10.py +2 -11
- adam/commands/audit/utils_show_top10.py +15 -3
- adam/commands/bash/bash.py +1 -1
- adam/commands/bash/utils_bash.py +1 -1
- adam/commands/cassandra/__init__.py +0 -0
- adam/commands/cassandra/download_cassandra_log.py +45 -0
- adam/commands/cassandra/nodetool.py +64 -0
- adam/commands/cassandra/nodetool_commands.py +120 -0
- adam/commands/cassandra/restart_cluster.py +47 -0
- adam/commands/cassandra/restart_node.py +51 -0
- adam/commands/cassandra/restart_nodes.py +47 -0
- adam/commands/cassandra/rollout.py +88 -0
- adam/commands/cat.py +5 -19
- adam/commands/cd.py +7 -9
- adam/commands/check.py +10 -18
- adam/commands/cli_commands.py +6 -1
- adam/commands/{cp.py → clipboard_copy.py} +34 -36
- adam/commands/code.py +2 -2
- adam/commands/command.py +139 -22
- adam/commands/commands_utils.py +14 -12
- adam/commands/cql/alter_tables.py +66 -0
- adam/commands/cql/completions_c.py +29 -0
- adam/commands/cql/cqlsh.py +3 -7
- adam/commands/cql/utils_cql.py +23 -61
- adam/commands/debug/__init__.py +0 -0
- adam/commands/debug/debug.py +22 -0
- adam/commands/debug/debug_completes.py +35 -0
- adam/commands/debug/debug_timings.py +35 -0
- adam/commands/deploy/deploy_pg_agent.py +2 -2
- adam/commands/deploy/deploy_pod.py +2 -4
- adam/commands/deploy/undeploy_pg_agent.py +2 -2
- adam/commands/devices/device.py +40 -9
- adam/commands/devices/device_app.py +19 -29
- adam/commands/devices/device_auit_log.py +3 -3
- adam/commands/devices/device_cass.py +17 -23
- adam/commands/devices/device_export.py +12 -11
- adam/commands/devices/device_postgres.py +79 -63
- adam/commands/devices/devices.py +1 -1
- adam/commands/download_cassandra_log.py +45 -0
- adam/commands/download_file.py +47 -0
- adam/commands/export/clean_up_all_export_sessions.py +3 -3
- adam/commands/export/clean_up_export_sessions.py +7 -19
- adam/commands/export/completions_x.py +11 -0
- adam/commands/export/download_export_session.py +40 -0
- adam/commands/export/drop_export_database.py +6 -22
- adam/commands/export/drop_export_databases.py +3 -9
- adam/commands/export/export.py +1 -17
- adam/commands/export/export_databases.py +109 -32
- adam/commands/export/export_select.py +8 -55
- adam/commands/export/export_sessions.py +211 -0
- adam/commands/export/export_use.py +13 -16
- adam/commands/export/export_x_select.py +48 -0
- adam/commands/export/exporter.py +176 -167
- adam/commands/export/import_files.py +44 -0
- adam/commands/export/import_session.py +10 -6
- adam/commands/export/importer.py +24 -9
- adam/commands/export/importer_athena.py +114 -44
- adam/commands/export/importer_sqlite.py +45 -23
- adam/commands/export/show_column_counts.py +11 -20
- adam/commands/export/show_export_databases.py +5 -2
- adam/commands/export/show_export_session.py +6 -15
- adam/commands/export/show_export_sessions.py +4 -11
- adam/commands/export/utils_export.py +79 -27
- adam/commands/find_files.py +51 -0
- adam/commands/find_processes.py +76 -0
- adam/commands/generate_report.py +52 -0
- adam/commands/head.py +36 -0
- adam/commands/help.py +2 -2
- adam/commands/intermediate_command.py +6 -3
- adam/commands/login.py +3 -6
- adam/commands/ls.py +2 -2
- adam/commands/medusa/medusa_backup.py +13 -16
- adam/commands/medusa/medusa_restore.py +26 -37
- adam/commands/medusa/medusa_show_backupjobs.py +7 -7
- adam/commands/medusa/medusa_show_restorejobs.py +6 -6
- adam/commands/medusa/utils_medusa.py +15 -0
- adam/commands/nodetool.py +3 -8
- adam/commands/os/__init__.py +0 -0
- adam/commands/os/cat.py +36 -0
- adam/commands/os/download_file.py +47 -0
- adam/commands/os/find_files.py +51 -0
- adam/commands/os/find_processes.py +76 -0
- adam/commands/os/head.py +36 -0
- adam/commands/os/shell.py +41 -0
- adam/commands/param_get.py +10 -12
- adam/commands/param_set.py +7 -10
- adam/commands/postgres/completions_p.py +22 -0
- adam/commands/postgres/postgres.py +25 -40
- adam/commands/postgres/postgres_databases.py +269 -0
- adam/commands/postgres/utils_postgres.py +33 -20
- adam/commands/preview_table.py +4 -2
- adam/commands/pwd.py +4 -6
- adam/commands/reaper/reaper_forward.py +2 -2
- adam/commands/reaper/reaper_run_abort.py +4 -10
- adam/commands/reaper/reaper_runs.py +3 -3
- adam/commands/reaper/reaper_schedule_activate.py +12 -12
- adam/commands/reaper/reaper_schedule_start.py +7 -12
- adam/commands/reaper/reaper_schedule_stop.py +7 -12
- adam/commands/reaper/utils_reaper.py +13 -6
- adam/commands/repair/repair_log.py +1 -4
- adam/commands/repair/repair_run.py +3 -8
- adam/commands/repair/repair_scan.py +1 -6
- adam/commands/repair/repair_stop.py +1 -5
- adam/commands/restart_cluster.py +47 -0
- adam/commands/restart_node.py +51 -0
- adam/commands/restart_nodes.py +47 -0
- adam/commands/shell.py +9 -2
- adam/commands/show/show.py +4 -4
- adam/commands/show/show_adam.py +3 -3
- adam/commands/show/show_cassandra_repairs.py +5 -6
- adam/commands/show/show_cassandra_status.py +29 -29
- adam/commands/show/show_cassandra_version.py +1 -4
- adam/commands/show/{show_commands.py → show_cli_commands.py} +3 -6
- adam/commands/show/show_login.py +3 -9
- adam/commands/show/show_params.py +2 -5
- adam/commands/show/show_processes.py +15 -16
- adam/commands/show/show_storage.py +9 -8
- adam/config.py +4 -5
- adam/embedded_params.py +1 -1
- adam/log.py +4 -4
- adam/repl.py +26 -18
- adam/repl_commands.py +32 -20
- adam/repl_session.py +9 -1
- adam/repl_state.py +39 -10
- adam/sql/async_executor.py +44 -0
- adam/sql/lark_completer.py +286 -0
- adam/sql/lark_parser.py +604 -0
- adam/sql/qingl.lark +1076 -0
- adam/sql/sql_completer.py +4 -6
- adam/sql/sql_state_machine.py +25 -13
- adam/sso/authn_ad.py +2 -5
- adam/sso/authn_okta.py +2 -4
- adam/sso/cred_cache.py +2 -5
- adam/sso/idp.py +8 -11
- adam/utils.py +299 -105
- adam/utils_athena.py +18 -18
- adam/utils_audits.py +3 -7
- adam/utils_issues.py +2 -2
- adam/utils_k8s/app_clusters.py +4 -4
- adam/utils_k8s/app_pods.py +8 -6
- adam/utils_k8s/cassandra_clusters.py +16 -5
- adam/utils_k8s/cassandra_nodes.py +9 -6
- adam/utils_k8s/custom_resources.py +11 -17
- adam/utils_k8s/jobs.py +7 -11
- adam/utils_k8s/k8s.py +14 -5
- adam/utils_k8s/kube_context.py +3 -6
- adam/{pod_exec_result.py → utils_k8s/pod_exec_result.py} +4 -4
- adam/utils_k8s/pods.py +85 -23
- adam/utils_k8s/statefulsets.py +5 -2
- adam/utils_local.py +42 -0
- adam/utils_repl/appendable_completer.py +6 -0
- adam/utils_repl/repl_completer.py +45 -2
- adam/utils_repl/state_machine.py +3 -3
- adam/utils_sqlite.py +58 -30
- adam/version.py +1 -1
- {kaqing-2.0.171.dist-info → kaqing-2.0.203.dist-info}/METADATA +1 -1
- kaqing-2.0.203.dist-info/RECORD +277 -0
- kaqing-2.0.203.dist-info/top_level.txt +2 -0
- teddy/__init__.py +0 -0
- teddy/lark_parser.py +436 -0
- teddy/lark_parser2.py +618 -0
- adam/commands/cql/cql_completions.py +0 -33
- adam/commands/export/export_handlers.py +0 -71
- adam/commands/export/export_select_x.py +0 -54
- adam/commands/logs.py +0 -37
- adam/commands/postgres/postgres_context.py +0 -274
- adam/commands/postgres/psql_completions.py +0 -10
- adam/commands/report.py +0 -61
- adam/commands/restart.py +0 -60
- kaqing-2.0.171.dist-info/RECORD +0 -236
- kaqing-2.0.171.dist-info/top_level.txt +0 -1
- /adam/commands/{app_ping.py → app/app_ping.py} +0 -0
- /adam/commands/{show → app}/show_app_id.py +0 -0
- {kaqing-2.0.171.dist-info → kaqing-2.0.203.dist-info}/WHEEL +0 -0
- {kaqing-2.0.171.dist-info → kaqing-2.0.203.dist-info}/entry_points.txt +0 -0
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
from functools import partial
|
|
1
2
|
import click
|
|
2
3
|
import pyperclip
|
|
3
4
|
|
|
4
|
-
from adam.commands
|
|
5
|
+
from adam.commands import validate_args
|
|
6
|
+
from adam.commands.command import Command, InvalidArgumentsException
|
|
5
7
|
from adam.commands.command_helpers import ClusterOrPodCommandHelper
|
|
6
8
|
from adam.commands.cli_commands import CliCommands
|
|
9
|
+
from adam.config import Config
|
|
7
10
|
from adam.repl_state import ReplState, RequiredState
|
|
8
|
-
from adam.utils import
|
|
11
|
+
from adam.utils import tabulize, log, log2
|
|
9
12
|
|
|
10
13
|
class ClipboardCopy(Command):
|
|
11
|
-
COMMAND = 'cp'
|
|
14
|
+
COMMAND = 'cli cp'
|
|
12
15
|
|
|
13
16
|
# the singleton pattern
|
|
14
17
|
def __new__(cls, *args, **kwargs):
|
|
@@ -30,40 +33,37 @@ class ClipboardCopy(Command):
|
|
|
30
33
|
return super().run(cmd, state)
|
|
31
34
|
|
|
32
35
|
with self.validate(args, state) as (args, state):
|
|
33
|
-
|
|
34
|
-
if
|
|
36
|
+
def display_keys(missing = False):
|
|
37
|
+
if missing:
|
|
35
38
|
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
39
|
else:
|
|
40
|
-
log2('
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
40
|
+
log2('Key is invalid.')
|
|
41
|
+
log2()
|
|
42
|
+
tabulize(CliCommands.values(state, collapse=True).items(),
|
|
43
|
+
lambda a: f'{a[0]},{a[1]}',
|
|
44
|
+
header='KEY,VALUE',
|
|
45
|
+
separator=',',
|
|
46
|
+
to=2)
|
|
47
|
+
|
|
48
|
+
with validate_args(args, state, name='key', msg=partial(display_keys, True)) as key:
|
|
49
|
+
if not key in CliCommands.values(state):
|
|
50
|
+
if state.in_repl:
|
|
51
|
+
display_keys(False)
|
|
52
|
+
else:
|
|
53
|
+
log2('* Invalid key')
|
|
54
|
+
Command.display_help()
|
|
55
|
+
|
|
56
|
+
raise InvalidArgumentsException()
|
|
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 state
|
|
64
64
|
|
|
65
65
|
def completion(self, state: ReplState):
|
|
66
|
-
return super().completion(state, lambda: {key: None for key in CliCommands.values(state).keys()})
|
|
66
|
+
return super().completion(state, lambda: {key: None for key in CliCommands.values(state).keys()}, auto_key='cli.cp-auto-complete')
|
|
67
67
|
|
|
68
68
|
def help(self, _: ReplState):
|
|
69
69
|
return f"{ClipboardCopy.COMMAND} <key>\t copy a value to clipboard for conveninence"
|
|
@@ -82,8 +82,6 @@ class CopyCommandHelper(click.Command):
|
|
|
82
82
|
def get_help(self, ctx: click.Context):
|
|
83
83
|
log(super().get_help(ctx))
|
|
84
84
|
log()
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
log(lines_to_tabular(self.lines(), separator=':'))
|
|
85
|
+
tabulize(self.lines(), header='KEY:DESC', separator=':')
|
|
88
86
|
log()
|
|
89
87
|
ClusterOrPodCommandHelper.cluter_or_pod_help()
|
adam/commands/code.py
CHANGED
|
@@ -4,7 +4,7 @@ from functools import partial
|
|
|
4
4
|
from adam.commands.command import Command
|
|
5
5
|
from adam.commands.cql.utils_cql import cassandra_table_names, run_cql
|
|
6
6
|
from adam.repl_state import ReplState, RequiredState
|
|
7
|
-
from adam.utils import
|
|
7
|
+
from adam.utils import tabulize
|
|
8
8
|
from adam.utils_k8s.statefulsets import StatefulSets
|
|
9
9
|
|
|
10
10
|
class Code(Command):
|
|
@@ -46,7 +46,7 @@ class Code(Command):
|
|
|
46
46
|
"cql('select...'): run cql statement"
|
|
47
47
|
]
|
|
48
48
|
|
|
49
|
-
code.interact(local=my_local, banner=
|
|
49
|
+
code.interact(local=my_local, banner=tabulize(lines, header='Variables', separator=':'))
|
|
50
50
|
|
|
51
51
|
return state
|
|
52
52
|
|
adam/commands/command.py
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
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
6
|
from typing import Union
|
|
6
7
|
|
|
8
|
+
from adam.config import Config
|
|
7
9
|
from adam.repl_state import ReplState, RequiredState
|
|
8
|
-
from adam.
|
|
10
|
+
from adam.sql.lark_completer import LarkCompleter
|
|
11
|
+
from adam.utils import log2
|
|
9
12
|
|
|
10
13
|
repl_cmds: list['Command'] = []
|
|
11
14
|
|
|
@@ -28,12 +31,38 @@ class Command:
|
|
|
28
31
|
|
|
29
32
|
return None
|
|
30
33
|
|
|
31
|
-
def completion(self, state: ReplState, leaf: dict[str, any] = None) -> dict[str, any]:
|
|
32
|
-
|
|
34
|
+
def completion(self, state: ReplState, leaf: dict[str, any] = None, pods: tuple[list[str], str] = None, auto: str = 'on', auto_key: str = None) -> dict[str, any]:
|
|
35
|
+
# pods is a tuple of list of pod names and the current pod repl is on
|
|
36
|
+
if not pods:
|
|
37
|
+
return self._completion(state, leaf, auto=auto, auto_key=auto_key)
|
|
38
|
+
|
|
39
|
+
c = {}
|
|
40
|
+
|
|
41
|
+
pod_names = pods[0]
|
|
42
|
+
pod = pods[1]
|
|
43
|
+
|
|
44
|
+
if pod:
|
|
45
|
+
c |= self._completion(state, leaf, auto=auto, auto_key=auto_key)
|
|
46
|
+
|
|
47
|
+
c |= {f'@{p}': self._completion(state.with_pod(p), leaf, to_validate=False, auto=auto, auto_key=auto_key) for p in pod_names if p != pod}
|
|
48
|
+
|
|
49
|
+
return c
|
|
50
|
+
|
|
51
|
+
def _completion(self, state: ReplState, leaf: dict[str, any] = None, to_validate = True, auto: str = 'on', auto_key: str = None) -> dict[str, any]:
|
|
52
|
+
if to_validate and not self.validate_state(state, show_err=False):
|
|
33
53
|
return {}
|
|
34
54
|
|
|
35
|
-
if
|
|
36
|
-
|
|
55
|
+
if callable(leaf):
|
|
56
|
+
if auto_key:
|
|
57
|
+
auto_key = f'auto-complete.{auto_key}'
|
|
58
|
+
auto = Config().get(auto_key, 'off')
|
|
59
|
+
|
|
60
|
+
if auto == 'on':
|
|
61
|
+
leaf = leaf()
|
|
62
|
+
elif auto in ['lazy', 'jit']:
|
|
63
|
+
leaf = LarkCompleter.from_lambda(auto_key, leaf, auto=auto)
|
|
64
|
+
else:
|
|
65
|
+
leaf = None
|
|
37
66
|
|
|
38
67
|
d = leaf
|
|
39
68
|
for t in reversed(self.command().split(' ')):
|
|
@@ -45,7 +74,7 @@ class Command:
|
|
|
45
74
|
return None
|
|
46
75
|
|
|
47
76
|
def validate(self, args: list[str], state: ReplState, apply = True):
|
|
48
|
-
return
|
|
77
|
+
return ValidateStateHandler(self, args, state, apply = apply)
|
|
49
78
|
|
|
50
79
|
def validate_state(self, state: ReplState, show_err = True):
|
|
51
80
|
return state.validate(self.required(), show_err=show_err)
|
|
@@ -96,9 +125,10 @@ class Command:
|
|
|
96
125
|
args.extend(['--help'])
|
|
97
126
|
subprocess.run(args)
|
|
98
127
|
|
|
99
|
-
def extract_options(args: list[str], trailing: Union[str, list[str]] = [], options: list[str] = []):
|
|
128
|
+
def extract_options(args: list[str], trailing: Union[str, list[str]] = [], sequence: list[str] = [], options: list[str] = []):
|
|
100
129
|
found_options: list[str] = []
|
|
101
130
|
found_trailing = None
|
|
131
|
+
found_sequence = None
|
|
102
132
|
|
|
103
133
|
if trailing is None:
|
|
104
134
|
trailing = []
|
|
@@ -110,16 +140,37 @@ class Command:
|
|
|
110
140
|
elif isinstance(options, str):
|
|
111
141
|
options = [options]
|
|
112
142
|
|
|
143
|
+
if args and trailing:
|
|
144
|
+
while args and args[-1] in trailing:
|
|
145
|
+
found_trailing = True
|
|
146
|
+
args = args[:-1]
|
|
147
|
+
|
|
148
|
+
if args and sequence:
|
|
149
|
+
args, found_sequence = Command.extract_option_sequence(args, sequence)
|
|
150
|
+
|
|
113
151
|
new_args: list[str] = []
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
152
|
+
if args:
|
|
153
|
+
for arg in args:
|
|
154
|
+
if arg in options:
|
|
155
|
+
found_options.append(arg)
|
|
156
|
+
else:
|
|
157
|
+
new_args.append(arg)
|
|
158
|
+
|
|
159
|
+
return new_args, found_trailing, found_sequence, found_options
|
|
160
|
+
|
|
161
|
+
def extract_option_sequence(args, sequence):
|
|
162
|
+
new_args = args
|
|
163
|
+
|
|
164
|
+
len_sub = len(sequence)
|
|
165
|
+
len_main = len(args)
|
|
166
|
+
for i in range(len_main - len_sub + 1):
|
|
167
|
+
if args[i:i+len_sub] == sequence:
|
|
168
|
+
new_args = copy.copy(args)
|
|
169
|
+
del new_args[i:i+len_sub]
|
|
170
|
+
|
|
171
|
+
return new_args, True
|
|
121
172
|
|
|
122
|
-
return new_args,
|
|
173
|
+
return new_args, False
|
|
123
174
|
|
|
124
175
|
def print_chain(cmd: 'Command'):
|
|
125
176
|
print(f'{cmd.command()}', end = '')
|
|
@@ -128,11 +179,11 @@ class Command:
|
|
|
128
179
|
cmd = s
|
|
129
180
|
print()
|
|
130
181
|
|
|
131
|
-
class
|
|
182
|
+
class InvalidStateException(Exception):
|
|
132
183
|
def __init__(self, state: ReplState):
|
|
133
184
|
super().__init__(f'Invalid state')
|
|
134
185
|
|
|
135
|
-
class
|
|
186
|
+
class ValidateStateHandler:
|
|
136
187
|
def __init__(self, cmd: Command, args: list[str], state: ReplState, apply = True):
|
|
137
188
|
self.cmd = cmd
|
|
138
189
|
self.args = args
|
|
@@ -144,22 +195,75 @@ class ValidateHandler:
|
|
|
144
195
|
args = self.args
|
|
145
196
|
if self.apply:
|
|
146
197
|
state, args = self.cmd.apply_state(args, state)
|
|
198
|
+
else:
|
|
199
|
+
args = args[len(self.cmd.command_tokens()):]
|
|
147
200
|
|
|
148
201
|
if not self.cmd.validate_state(state):
|
|
149
|
-
raise
|
|
202
|
+
raise InvalidStateException(state)
|
|
150
203
|
|
|
151
204
|
return args, state
|
|
152
205
|
|
|
153
206
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
154
207
|
return False
|
|
155
208
|
|
|
209
|
+
class InvalidArgumentsException(Exception):
|
|
210
|
+
def __init__(self):
|
|
211
|
+
super().__init__(f'Invalid arguments')
|
|
212
|
+
|
|
213
|
+
class ValidateArgCountHandler:
|
|
214
|
+
def __init__(self, args: list[str], state: ReplState, at_least: int = 1, exactly: int = 1,
|
|
215
|
+
name: str = None, msg: Callable[[], None] = None, default: Union[str, list[str]] = None,
|
|
216
|
+
separator: str = None):
|
|
217
|
+
self.args = args
|
|
218
|
+
self.state = state
|
|
219
|
+
self.at_least = at_least
|
|
220
|
+
self.exactly = exactly
|
|
221
|
+
self.name = name
|
|
222
|
+
self.msg = msg
|
|
223
|
+
self.default = default
|
|
224
|
+
self.separator = separator
|
|
225
|
+
|
|
226
|
+
def __enter__(self) -> Union[tuple[list[str], ReplState], tuple[str, ReplState]]:
|
|
227
|
+
if self.exactly > 0 and len(self.args) != self.exactly or len(self.args) < self.at_least:
|
|
228
|
+
if self.default:
|
|
229
|
+
v = self.default
|
|
230
|
+
if isinstance(v, list):
|
|
231
|
+
v = ' '.join(v)
|
|
232
|
+
|
|
233
|
+
return v
|
|
234
|
+
|
|
235
|
+
if self.state.in_repl:
|
|
236
|
+
if self.msg:
|
|
237
|
+
self.msg()
|
|
238
|
+
elif self.name:
|
|
239
|
+
log2(f'{self.name} is required.')
|
|
240
|
+
elif self.name:
|
|
241
|
+
log2(f'* {self.name} is missing.')
|
|
242
|
+
|
|
243
|
+
Command.display_help()
|
|
244
|
+
|
|
245
|
+
raise InvalidArgumentsException()
|
|
246
|
+
|
|
247
|
+
if self.separator == ' ':
|
|
248
|
+
return self.args
|
|
249
|
+
|
|
250
|
+
# join and re-split with separator
|
|
251
|
+
args_to_return = ' '.join(self.args)
|
|
252
|
+
if self.separator:
|
|
253
|
+
args_to_return = [arg.strip(' ') for arg in args_to_return.split(self.separator)]
|
|
254
|
+
|
|
255
|
+
return args_to_return
|
|
256
|
+
|
|
257
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
258
|
+
return False
|
|
259
|
+
|
|
156
260
|
class ExtractOptionsHandler:
|
|
157
261
|
def __init__(self, args: list[str], options: list[str] = None):
|
|
158
262
|
self.args = args
|
|
159
263
|
self.options = options
|
|
160
264
|
|
|
161
265
|
def __enter__(self) -> tuple[list[str], list[str]]:
|
|
162
|
-
args, _, options = Command.extract_options(self.args, options=self.options)
|
|
266
|
+
args, _, _, options = Command.extract_options(self.args, options=self.options)
|
|
163
267
|
return args, options
|
|
164
268
|
|
|
165
269
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
@@ -171,20 +275,33 @@ class ExtractTrailingOptionsHandler:
|
|
|
171
275
|
self.trailing = trailing
|
|
172
276
|
|
|
173
277
|
def __enter__(self) -> tuple[list[str], list[str]]:
|
|
174
|
-
args, trailing, _ = Command.extract_options(self.args, trailing=self.trailing)
|
|
278
|
+
args, trailing, _, _ = Command.extract_options(self.args, trailing=self.trailing)
|
|
175
279
|
return args, trailing
|
|
176
280
|
|
|
177
281
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
178
282
|
return False
|
|
179
283
|
|
|
180
284
|
class ExtractAllOptionsHandler:
|
|
181
|
-
def __init__(self, args: list[str], trailing: list[str] = None, options: list[str] = None):
|
|
285
|
+
def __init__(self, args: list[str], trailing: list[str] = None, sequence: list[str] = None, options: list[str] = None):
|
|
182
286
|
self.args = args
|
|
183
287
|
self.trailing = trailing
|
|
288
|
+
self.sequence = sequence
|
|
184
289
|
self.options = options
|
|
185
290
|
|
|
186
291
|
def __enter__(self) -> tuple[list[str], list[str]]:
|
|
187
|
-
return Command.extract_options(self.args, options=self.options)
|
|
292
|
+
return Command.extract_options(self.args, trailing=self.trailing, sequence=self.sequence, options=self.options)
|
|
293
|
+
|
|
294
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
295
|
+
return False
|
|
296
|
+
|
|
297
|
+
class ExtractSequenceOptionsHandler:
|
|
298
|
+
def __init__(self, args: list[str], sequence: list[str]):
|
|
299
|
+
self.args = args
|
|
300
|
+
self.sequence = sequence
|
|
301
|
+
|
|
302
|
+
def __enter__(self) -> tuple[list[str], list[str]]:
|
|
303
|
+
args, _, sequence, _ = Command.extract_options(self.args, sequence=self.sequence)
|
|
304
|
+
return args, sequence
|
|
188
305
|
|
|
189
306
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
190
307
|
return False
|
adam/commands/commands_utils.py
CHANGED
|
@@ -8,7 +8,7 @@ from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
|
8
8
|
from adam.utils_k8s.pods import Pods
|
|
9
9
|
from adam.utils_k8s.statefulsets import StatefulSets
|
|
10
10
|
from adam.repl_state import ReplState
|
|
11
|
-
from adam.utils import duration,
|
|
11
|
+
from adam.utils import SORT, duration, kaqing_log_file, tabulize, log2
|
|
12
12
|
|
|
13
13
|
def show_pods(pods: List[client.V1Pod], ns: str, show_namespace = True, show_host_id = True):
|
|
14
14
|
if len(pods) == 0:
|
|
@@ -48,9 +48,7 @@ def show_pods(pods: List[client.V1Pod], ns: str, show_namespace = True, show_hos
|
|
|
48
48
|
line += f"@{ns}"
|
|
49
49
|
return line + f" {ready}/{pod_cnt} {status}"
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
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')
|
|
54
52
|
|
|
55
53
|
def show_rollout(sts: str, ns: str):
|
|
56
54
|
restarted, rollingout = StatefulSets.restarted_at(sts, ns)
|
|
@@ -61,18 +59,22 @@ def show_rollout(sts: str, ns: str):
|
|
|
61
59
|
else:
|
|
62
60
|
log2(f'Cluster has completed rollout {d} ago.')
|
|
63
61
|
|
|
64
|
-
def show_table(state: ReplState, pods: list[str], cols: str, header: str, show_out=False):
|
|
62
|
+
def show_table(state: ReplState, pods: list[str], cols: str, header: str, show_out=False, backgrounded = False):
|
|
65
63
|
columns = Columns.create_columns(cols)
|
|
66
64
|
|
|
67
65
|
results = run_checks(cluster=state.sts, pod=state.pod, namespace=state.namespace, checks=collect_checks(columns), show_out=show_out)
|
|
68
66
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
r = tabulize(pods, lambda p: ','.join([c.pod_value(results, p) for c in columns]), header=header, separator=',', sorted=SORT, to = 0 if backgrounded else 1)
|
|
68
|
+
|
|
69
|
+
if backgrounded:
|
|
70
|
+
r = write_to_kaqing_log_file(r)
|
|
71
|
+
|
|
72
|
+
IssuesUtils.show(results, state.in_repl)
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
lines.sort()
|
|
74
|
+
return r
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
def write_to_kaqing_log_file(r: str):
|
|
77
|
+
with kaqing_log_file() as f:
|
|
78
|
+
f.write(r)
|
|
77
79
|
|
|
78
|
-
|
|
80
|
+
return f.name
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from adam.commands import extract_options, validate_args
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.commands.cql.utils_cql import cassandra, cassandra_tables as get_tables
|
|
4
|
+
from adam.config import Config
|
|
5
|
+
from adam.repl_state import ReplState, RequiredState
|
|
6
|
+
from adam.utils import log2, log_exc
|
|
7
|
+
|
|
8
|
+
class AlterTables(Command):
|
|
9
|
+
COMMAND = 'alter tables with'
|
|
10
|
+
|
|
11
|
+
# the singleton pattern
|
|
12
|
+
def __new__(cls, *args, **kwargs):
|
|
13
|
+
if not hasattr(cls, 'instance'): cls.instance = super(AlterTables, cls).__new__(cls)
|
|
14
|
+
|
|
15
|
+
return cls.instance
|
|
16
|
+
|
|
17
|
+
def __init__(self, successor: Command=None):
|
|
18
|
+
super().__init__(successor)
|
|
19
|
+
|
|
20
|
+
def required(self):
|
|
21
|
+
return RequiredState.CLUSTER
|
|
22
|
+
|
|
23
|
+
def command(self):
|
|
24
|
+
return AlterTables.COMMAND
|
|
25
|
+
|
|
26
|
+
def run(self, cmd: str, state: ReplState):
|
|
27
|
+
if not(args := self.args(cmd)):
|
|
28
|
+
return super().run(cmd, state)
|
|
29
|
+
|
|
30
|
+
with self.validate(args, state) as (args, state):
|
|
31
|
+
with extract_options(args, '--include-reaper') as (args, include_reaper):
|
|
32
|
+
with validate_args(args, state, name='gc grace in seconds') as arg_str:
|
|
33
|
+
excludes = [e.strip(' \r\n') for e in Config().get(
|
|
34
|
+
'cql.alter-tables.excludes',
|
|
35
|
+
'system_auth,system_traces,reaper_db,system_distributed,system_views,system,system_schema,system_virtual_schema').split(',')]
|
|
36
|
+
batching = Config().get('cql.alter-tables.batching', True)
|
|
37
|
+
tables = get_tables(state, on_any=True)
|
|
38
|
+
for k, v in tables.items():
|
|
39
|
+
if k not in excludes or k == 'reaper_db' and include_reaper:
|
|
40
|
+
if batching:
|
|
41
|
+
# alter table <table_name> with GC_GRACE_SECONDS = <timeout>;
|
|
42
|
+
cql = ';\n'.join([f'alter table {k}.{t} with {arg_str}' for t in v])
|
|
43
|
+
with log_exc(True):
|
|
44
|
+
with cassandra(state) as pods:
|
|
45
|
+
pods.cql(cql, show_out=Config().is_debug(), show_query=not Config().is_debug(), on_any=True)
|
|
46
|
+
continue
|
|
47
|
+
else:
|
|
48
|
+
for t in v:
|
|
49
|
+
with log_exc(True):
|
|
50
|
+
# alter table <table_name> with GC_GRACE_SECONDS = <timeout>;
|
|
51
|
+
cql = f'alter table {k}.{t} with {arg_str}'
|
|
52
|
+
with cassandra(state) as pods:
|
|
53
|
+
pods.cql(show_out=Config().is_debug(), show_query=not Config().is_debug(), on_any=True)
|
|
54
|
+
continue
|
|
55
|
+
|
|
56
|
+
log2(f'{len(v)} tables altered in {k}.')
|
|
57
|
+
|
|
58
|
+
# do not continue to cql route
|
|
59
|
+
return state
|
|
60
|
+
|
|
61
|
+
def completion(self, _: ReplState) -> dict[str, any]:
|
|
62
|
+
# auto completion is taken care of by lark completer
|
|
63
|
+
return {}
|
|
64
|
+
|
|
65
|
+
def help(self, _: ReplState) -> str:
|
|
66
|
+
return f'{AlterTables.COMMAND} <param = value> [--include-reaper] \t alter schema on all tables'
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
|
5
|
+
from adam.repl_state import ReplState
|
|
6
|
+
from adam.sql.lark_completer import LarkCompleter
|
|
7
|
+
from adam.utils import log_timing
|
|
8
|
+
from adam.utils_k8s.statefulsets import StatefulSets
|
|
9
|
+
|
|
10
|
+
def completions_c(state: ReplState) -> dict[str, any]:
|
|
11
|
+
ps = Config().get('cql.alter-tables.gc-grace-periods', '3600,86400,864000,7776000').split(',')
|
|
12
|
+
|
|
13
|
+
with log_timing('lark.completions'):
|
|
14
|
+
return LarkCompleter(
|
|
15
|
+
expandables = {
|
|
16
|
+
'tables': lambda x: cassandra_table_names(state),
|
|
17
|
+
'keyspaces': lambda x: cassandra_keyspaces(state.with_no_pod()),
|
|
18
|
+
'table-props': lambda x: {
|
|
19
|
+
'GC_GRACE_SECONDS': ps
|
|
20
|
+
},
|
|
21
|
+
'table-props-value': lambda x: {'GC_GRACE_SECONDS': ps}[x],
|
|
22
|
+
'export-database-types': lambda x: ['athena', 'sqlite', 'csv'],
|
|
23
|
+
'export-databases': lambda x: ExportDatabases.database_names(),
|
|
24
|
+
'export-sessions': lambda x: ExportSessions.export_session_names(state.sts, state.pod, state.namespace),
|
|
25
|
+
'export-sessions-incomplete': lambda x: ExportSessions.export_session_names(state.sts, state.pod, state.namespace, export_state='pending_import'),
|
|
26
|
+
'hosts': lambda x: [f'@{p}' for p in StatefulSets.pod_names(state.sts, state.namespace)],
|
|
27
|
+
},
|
|
28
|
+
variant=ReplState.C
|
|
29
|
+
).completions_for_nesting()
|
adam/commands/cql/cqlsh.py
CHANGED
|
@@ -3,9 +3,8 @@ import click
|
|
|
3
3
|
from adam.commands import extract_trailing_options
|
|
4
4
|
from adam.commands.command import Command
|
|
5
5
|
from adam.commands.command_helpers import ClusterOrPodCommandHelper
|
|
6
|
-
from adam.commands.cql.
|
|
6
|
+
from adam.commands.cql.completions_c import completions_c
|
|
7
7
|
from adam.commands.cql.utils_cql import cassandra
|
|
8
|
-
from adam.utils_k8s.statefulsets import StatefulSets
|
|
9
8
|
from adam.repl_state import ReplState, RequiredState
|
|
10
9
|
from adam.utils import log
|
|
11
10
|
|
|
@@ -34,17 +33,14 @@ class Cqlsh(Command):
|
|
|
34
33
|
with self.validate(args, state) as (args, state):
|
|
35
34
|
with extract_trailing_options(args, '&') as (args, backgrounded):
|
|
36
35
|
with cassandra(state) as pods:
|
|
37
|
-
pods.cql(args,
|
|
36
|
+
pods.cql(args, backgrounded=backgrounded)
|
|
38
37
|
|
|
39
38
|
def completion(self, state: ReplState) -> dict[str, any]:
|
|
40
39
|
if state.device != state.C:
|
|
41
|
-
# conflicts with psql completions
|
|
42
40
|
return {}
|
|
43
41
|
|
|
44
42
|
if state.sts or state.pod:
|
|
45
|
-
|
|
46
|
-
return c | \
|
|
47
|
-
{f'@{p}': c for p in StatefulSets.pod_names(state.sts, state.namespace)}
|
|
43
|
+
return completions_c(state)
|
|
48
44
|
|
|
49
45
|
return {}
|
|
50
46
|
|