kaqing 2.0.98__py3-none-any.whl → 2.0.171__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/__init__.py +0 -2
- adam/app_session.py +9 -7
- adam/batch.py +4 -18
- adam/checks/check_utils.py +14 -46
- adam/checks/cpu.py +7 -1
- adam/checks/cpu_metrics.py +52 -0
- adam/columns/columns.py +3 -1
- adam/columns/cpu.py +3 -1
- adam/columns/cpu_metrics.py +22 -0
- adam/commands/__init__.py +15 -0
- adam/commands/alter_tables.py +50 -61
- adam/commands/app_cmd.py +38 -0
- adam/commands/app_ping.py +8 -14
- adam/commands/audit/audit.py +43 -30
- adam/commands/audit/audit_repair_tables.py +26 -46
- adam/commands/audit/audit_run.py +50 -0
- adam/commands/audit/show_last10.py +48 -0
- adam/commands/audit/show_slow10.py +47 -0
- adam/commands/audit/show_top10.py +45 -0
- adam/commands/audit/utils_show_top10.py +59 -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 +50 -0
- adam/commands/cd.py +15 -91
- adam/commands/check.py +23 -18
- adam/commands/cli_commands.py +2 -3
- adam/commands/code.py +57 -0
- adam/commands/command.py +96 -40
- adam/commands/commands_utils.py +9 -19
- adam/commands/cp.py +33 -39
- adam/commands/cql/cql_completions.py +30 -8
- adam/commands/cql/cqlsh.py +12 -27
- 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 -21
- adam/commands/deploy/deploy_frontend.py +14 -17
- adam/commands/deploy/deploy_pg_agent.py +3 -6
- adam/commands/deploy/deploy_pod.py +67 -73
- adam/commands/deploy/deploy_utils.py +14 -24
- 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 +11 -12
- 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/__init__.py +0 -0
- 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 +53 -0
- adam/commands/export/export_databases.py +170 -0
- adam/commands/export/export_handlers.py +71 -0
- adam/commands/export/export_select.py +81 -0
- adam/commands/export/export_select_x.py +54 -0
- adam/commands/export/export_use.py +52 -0
- adam/commands/export/exporter.py +352 -0
- adam/commands/export/import_session.py +40 -0
- adam/commands/export/importer.py +67 -0
- adam/commands/export/importer_athena.py +80 -0
- adam/commands/export/importer_sqlite.py +47 -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 +314 -0
- adam/commands/help.py +10 -6
- adam/commands/intermediate_command.py +49 -0
- adam/commands/issues.py +14 -40
- adam/commands/kubectl.py +38 -0
- adam/commands/login.py +28 -24
- adam/commands/logs.py +4 -6
- adam/commands/ls.py +11 -116
- adam/commands/medusa/medusa.py +4 -22
- adam/commands/medusa/medusa_backup.py +20 -24
- adam/commands/medusa/medusa_restore.py +30 -32
- adam/commands/medusa/medusa_show_backupjobs.py +16 -17
- adam/commands/medusa/medusa_show_restorejobs.py +12 -17
- adam/commands/nodetool.py +11 -17
- adam/commands/param_get.py +11 -12
- adam/commands/param_set.py +9 -10
- adam/commands/postgres/postgres.py +43 -36
- adam/commands/postgres/{postgres_session.py → postgres_context.py} +80 -46
- adam/commands/postgres/postgres_ls.py +4 -8
- adam/commands/postgres/postgres_preview.py +5 -9
- adam/commands/postgres/psql_completions.py +2 -2
- adam/commands/postgres/utils_postgres.py +66 -0
- adam/commands/preview_table.py +8 -61
- adam/commands/pwd.py +14 -44
- adam/commands/reaper/reaper.py +4 -24
- 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 +4 -7
- adam/commands/repair/repair_run.py +27 -29
- adam/commands/repair/repair_scan.py +31 -34
- adam/commands/repair/repair_stop.py +4 -7
- adam/commands/report.py +25 -21
- adam/commands/restart.py +25 -26
- adam/commands/rollout.py +19 -24
- adam/commands/shell.py +5 -4
- adam/commands/show/show.py +6 -19
- adam/commands/show/show_app_actions.py +26 -22
- adam/commands/show/show_app_id.py +8 -11
- adam/commands/show/show_app_queues.py +7 -10
- adam/commands/show/{show_repairs.py → show_cassandra_repairs.py} +8 -17
- adam/commands/show/show_cassandra_status.py +29 -33
- adam/commands/show/show_cassandra_version.py +4 -14
- adam/commands/show/show_commands.py +19 -21
- adam/commands/show/show_host.py +1 -1
- adam/commands/show/show_login.py +26 -24
- adam/commands/show/show_processes.py +16 -18
- 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/pod_exec_result.py +7 -1
- adam/repl.py +95 -131
- adam/repl_commands.py +48 -20
- adam/repl_state.py +270 -61
- adam/sql/sql_completer.py +105 -63
- adam/sql/sql_state_machine.py +618 -0
- adam/sql/term_completer.py +3 -0
- adam/sso/authn_ad.py +6 -5
- adam/sso/authn_okta.py +3 -3
- adam/sso/cred_cache.py +3 -2
- adam/sso/idp.py +3 -3
- adam/utils.py +439 -3
- adam/utils_app.py +98 -0
- adam/utils_athena.py +140 -87
- adam/utils_audits.py +106 -0
- adam/utils_issues.py +32 -0
- adam/utils_k8s/app_clusters.py +28 -0
- adam/utils_k8s/app_pods.py +33 -0
- adam/utils_k8s/cassandra_clusters.py +22 -20
- adam/utils_k8s/cassandra_nodes.py +4 -4
- adam/utils_k8s/custom_resources.py +5 -0
- adam/utils_k8s/ingresses.py +2 -2
- adam/utils_k8s/k8s.py +87 -0
- adam/utils_k8s/pods.py +77 -68
- 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 +109 -0
- adam/version.py +1 -1
- {kaqing-2.0.98.dist-info → kaqing-2.0.171.dist-info}/METADATA +1 -1
- kaqing-2.0.171.dist-info/RECORD +236 -0
- adam/commands/app.py +0 -67
- adam/commands/bash.py +0 -92
- adam/commands/cql/cql_table_completer.py +0 -8
- adam/commands/cql/cql_utils.py +0 -115
- adam/commands/describe/describe.py +0 -47
- adam/commands/describe/describe_keyspace.py +0 -60
- adam/commands/describe/describe_keyspaces.py +0 -49
- adam/commands/describe/describe_schema.py +0 -49
- adam/commands/describe/describe_table.py +0 -60
- adam/commands/describe/describe_tables.py +0 -49
- adam/commands/devices.py +0 -118
- 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/sql/state_machine.py +0 -460
- kaqing-2.0.98.dist-info/RECORD +0 -191
- /adam/commands/{describe → devices}/__init__.py +0 -0
- {kaqing-2.0.98.dist-info → kaqing-2.0.171.dist-info}/WHEEL +0 -0
- {kaqing-2.0.98.dist-info → kaqing-2.0.171.dist-info}/entry_points.txt +0 -0
- {kaqing-2.0.98.dist-info → kaqing-2.0.171.dist-info}/top_level.txt +0 -0
adam/commands/cd.py
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
from adam.commands.command import Command
|
|
2
|
-
from adam.commands.
|
|
3
|
-
from adam.commands.
|
|
4
|
-
from adam.utils_k8s.cassandra_clusters import CassandraClusters
|
|
5
|
-
from adam.utils_k8s.kube_context import KubeContext
|
|
6
|
-
from adam.utils_k8s.statefulsets import StatefulSets
|
|
2
|
+
from adam.commands.devices.device import Device
|
|
3
|
+
from adam.commands.devices.devices import Devices
|
|
7
4
|
from adam.repl_state import ReplState
|
|
8
|
-
from adam.utils import log2
|
|
9
|
-
from adam.apps import Apps
|
|
10
5
|
|
|
11
6
|
class Cd(Command):
|
|
12
7
|
COMMAND = 'cd'
|
|
@@ -23,97 +18,26 @@ class Cd(Command):
|
|
|
23
18
|
def command(self):
|
|
24
19
|
return Cd.COMMAND
|
|
25
20
|
|
|
21
|
+
def required(self):
|
|
22
|
+
return ReplState.NON_L
|
|
23
|
+
|
|
26
24
|
def run(self, cmd: str, state: ReplState):
|
|
27
25
|
if not(args := self.args(cmd)):
|
|
28
26
|
return super().run(cmd, state)
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
arg = args[1]
|
|
34
|
-
for dir in arg.split('/'):
|
|
35
|
-
if state.device == ReplState.P:
|
|
36
|
-
if dir == '':
|
|
37
|
-
state.pg_path = None
|
|
38
|
-
else:
|
|
39
|
-
session = PostgresSession(state.namespace, state.pg_path)
|
|
40
|
-
# patch up state.namespace from pg cd
|
|
41
|
-
if not state.namespace and (ns := session.find_namespace(arg)):
|
|
42
|
-
state.namespace = ns
|
|
43
|
-
state.pg_path = session.directory(arg)
|
|
44
|
-
elif state.device == ReplState.A:
|
|
45
|
-
if dir == '':
|
|
46
|
-
state.app_env = None
|
|
47
|
-
state.app_app = None
|
|
48
|
-
elif dir == '..':
|
|
49
|
-
if state.app_app:
|
|
50
|
-
state.app_app = None
|
|
51
|
-
else:
|
|
52
|
-
state.app_env = None
|
|
53
|
-
else:
|
|
54
|
-
if not state.app_env:
|
|
55
|
-
tks = dir.split('@')
|
|
56
|
-
if len(tks) > 1:
|
|
57
|
-
state.namespace = tks[1]
|
|
28
|
+
with self.validate(args, state, apply=False) as (args, state):
|
|
29
|
+
if len(args) < 2:
|
|
30
|
+
return state
|
|
58
31
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
pass
|
|
64
|
-
else:
|
|
65
|
-
if dir == '':
|
|
66
|
-
state.sts = None
|
|
67
|
-
state.pod = None
|
|
68
|
-
elif dir == '..':
|
|
69
|
-
if state.pod:
|
|
70
|
-
state.pod = None
|
|
71
|
-
else:
|
|
72
|
-
state.sts = None
|
|
73
|
-
else:
|
|
74
|
-
if not state.sts:
|
|
75
|
-
ss_and_ns = dir.split('@')
|
|
76
|
-
state.sts = ss_and_ns[0]
|
|
77
|
-
if len(ss_and_ns) > 1:
|
|
78
|
-
state.namespace = ss_and_ns[1]
|
|
79
|
-
elif not state.pod:
|
|
80
|
-
p, _ = KubeContext.is_pod_name(dir)
|
|
81
|
-
if p:
|
|
82
|
-
state.pod = p
|
|
83
|
-
else:
|
|
84
|
-
names = CassandraClusters.pod_names_by_host_id(state.sts, state.namespace);
|
|
85
|
-
if dir in names:
|
|
86
|
-
state.pod = names[dir]
|
|
87
|
-
else:
|
|
88
|
-
log2('Not a valid pod name or host id.')
|
|
32
|
+
device: Device = Devices.device(state)
|
|
33
|
+
arg = args[1]
|
|
34
|
+
for dir in arg.split('/'):
|
|
35
|
+
device.cd(dir, state)
|
|
89
36
|
|
|
90
|
-
|
|
37
|
+
return state
|
|
91
38
|
|
|
92
39
|
def completion(self, state: ReplState):
|
|
93
|
-
|
|
94
|
-
pg = PostgresSession(state.namespace, state.pg_path) if state.pg_path else None
|
|
95
|
-
if pg and pg.db:
|
|
96
|
-
return {Cd.COMMAND: {'..': None}}
|
|
97
|
-
elif pg and pg.host:
|
|
98
|
-
return {Cd.COMMAND: {'..': None} | {p: None for p in pg_database_names(state.namespace, pg.directory())}}
|
|
99
|
-
else:
|
|
100
|
-
return {Cd.COMMAND: {p: None for p in PostgresSession.hosts(state.namespace)}}
|
|
101
|
-
elif state.device == ReplState.A:
|
|
102
|
-
if state.app_app:
|
|
103
|
-
return {Cd.COMMAND: {'..': None}}
|
|
104
|
-
elif state.app_env:
|
|
105
|
-
return {Cd.COMMAND: {'..': None} | {app[0].split('-')[1]: None for app in Apps.apps(state.app_env)}}
|
|
106
|
-
else:
|
|
107
|
-
return {Cd.COMMAND: {'..': None} | {env[0]: None for env in Apps.envs()}}
|
|
108
|
-
elif state.device == ReplState.C:
|
|
109
|
-
if state.pod:
|
|
110
|
-
return {Cd.COMMAND: {'..': None}}
|
|
111
|
-
elif state.sts:
|
|
112
|
-
return {Cd.COMMAND: {'..': None} | {p: None for p in StatefulSets.pod_names(state.sts, state.namespace)}}
|
|
113
|
-
else:
|
|
114
|
-
return {Cd.COMMAND: {p: None for p in StatefulSets.list_sts_names()}}
|
|
115
|
-
|
|
116
|
-
return {}
|
|
40
|
+
return Devices.device(state).cd_completion(Cd.COMMAND, state, default = {})
|
|
117
41
|
|
|
118
42
|
def help(self, _: ReplState):
|
|
119
|
-
return f'{Cd.COMMAND} <path> | .. \t move around'
|
|
43
|
+
return f'{Cd.COMMAND} <path> | .. \t move around on the operational device hierarchy'
|
adam/commands/check.py
CHANGED
|
@@ -2,11 +2,13 @@ import click
|
|
|
2
2
|
|
|
3
3
|
from adam.checks.check_result import CheckResult
|
|
4
4
|
from adam.checks.check_utils import all_checks, checks_from_csv, run_checks
|
|
5
|
+
from adam.commands import extract_options
|
|
5
6
|
from adam.commands.command import Command
|
|
6
7
|
from adam.commands.command_helpers import ClusterOrPodCommandHelper
|
|
7
8
|
from adam.commands.issues import Issues
|
|
8
9
|
from adam.repl_state import ReplState
|
|
9
10
|
from adam.utils import lines_to_tabular, log
|
|
11
|
+
from adam.utils_issues import IssuesUtils
|
|
10
12
|
|
|
11
13
|
class Check(Issues):
|
|
12
14
|
COMMAND = 'check'
|
|
@@ -23,37 +25,40 @@ class Check(Issues):
|
|
|
23
25
|
def command(self):
|
|
24
26
|
return Check.COMMAND
|
|
25
27
|
|
|
28
|
+
def required(self):
|
|
29
|
+
return ReplState.NON_L
|
|
30
|
+
|
|
26
31
|
def run(self, cmd: str, state: ReplState):
|
|
27
32
|
if not(args := self.args(cmd)):
|
|
28
33
|
return super().run(cmd, state)
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
with self.validate(args, state) as (args, state):
|
|
36
|
+
with extract_options(args, ['-s', '--show']) as (args, show_out):
|
|
37
|
+
if not args:
|
|
38
|
+
if state.in_repl:
|
|
39
|
+
log(lines_to_tabular([check.help() for check in all_checks()], separator=':'))
|
|
40
|
+
else:
|
|
41
|
+
log('* Check name is missing.')
|
|
42
|
+
Command.display_help()
|
|
32
43
|
|
|
33
|
-
|
|
34
|
-
if state.in_repl:
|
|
35
|
-
log(lines_to_tabular([check.help() for check in all_checks()], separator=':'))
|
|
36
|
-
else:
|
|
37
|
-
log('* Check name is missing.')
|
|
38
|
-
Command.display_help()
|
|
39
|
-
return 'arg missing'
|
|
44
|
+
return 'arg missing'
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
checks = checks_from_csv(args[0])
|
|
47
|
+
if not checks:
|
|
48
|
+
return 'invalid check name'
|
|
44
49
|
|
|
45
|
-
|
|
50
|
+
results = run_checks(state.sts, state.namespace, state.pod, checks=checks, show_out=show_out)
|
|
46
51
|
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
issues = CheckResult.collect_issues(results)
|
|
53
|
+
IssuesUtils.show_issues(issues, in_repl=state.in_repl)
|
|
49
54
|
|
|
50
|
-
|
|
55
|
+
return issues if issues else 'no issues found'
|
|
51
56
|
|
|
52
57
|
def completion(self, _: ReplState):
|
|
53
|
-
return {Check.COMMAND: {check.name(): None for check in all_checks()}}
|
|
58
|
+
return {Check.COMMAND: {check.name(): {'-s': None} for check in all_checks()}}
|
|
54
59
|
|
|
55
60
|
def help(self, _: ReplState):
|
|
56
|
-
return f'{Check.COMMAND} <check-name
|
|
61
|
+
return f'{Check.COMMAND} <check-name> [-s]\t run a single check'
|
|
57
62
|
|
|
58
63
|
class CheckCommandHelper(click.Command):
|
|
59
64
|
def get_help(self, ctx: click.Context):
|
adam/commands/cli_commands.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import functools
|
|
2
2
|
import re
|
|
3
3
|
|
|
4
|
-
from adam.commands.reaper.
|
|
4
|
+
from adam.commands.reaper.utils_reaper import Reapers
|
|
5
5
|
from adam.config import Config
|
|
6
6
|
from adam.utils_k8s.kube_context import KubeContext
|
|
7
7
|
from adam.utils_k8s.secrets import Secrets
|
|
@@ -66,8 +66,7 @@ class CliCommands:
|
|
|
66
66
|
return key.replace(f'{state.namespace}-', '').replace('-k8spg-cs-001', '')
|
|
67
67
|
d |= {f'pg-{reduce_key(k)}': f'PGPASSWORD={v["postgres-admin-password"]} psql -h {v["postgres-db-endpoint"]} -p {v["postgres-db-port"]} -U {v["postgres-admin-username"]} postgres' for k, v in data.items()}
|
|
68
68
|
|
|
69
|
-
if
|
|
70
|
-
reaper = r.reaper_spec(state)
|
|
69
|
+
if reaper := Reapers.reaper_spec(state):
|
|
71
70
|
d |= {
|
|
72
71
|
'reaper-exec': reaper["exec"],
|
|
73
72
|
'reaper-forward': reaper["forward"],
|
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 lines_to_tabular
|
|
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=lines_to_tabular(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
|
@@ -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
|
|
|
@@ -28,8 +28,13 @@ class Command:
|
|
|
28
28
|
|
|
29
29
|
return None
|
|
30
30
|
|
|
31
|
-
def completion(self,
|
|
32
|
-
|
|
31
|
+
def completion(self, state: ReplState, leaf: dict[str, any] = None) -> dict[str, any]:
|
|
32
|
+
if not self.validate_state(state, show_err=False):
|
|
33
|
+
return {}
|
|
34
|
+
|
|
35
|
+
if is_lambda(leaf):
|
|
36
|
+
leaf = leaf()
|
|
37
|
+
|
|
33
38
|
d = leaf
|
|
34
39
|
for t in reversed(self.command().split(' ')):
|
|
35
40
|
d = {t: d}
|
|
@@ -39,8 +44,11 @@ class Command:
|
|
|
39
44
|
def required(self) -> RequiredState:
|
|
40
45
|
return None
|
|
41
46
|
|
|
42
|
-
def
|
|
43
|
-
return
|
|
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):
|
|
51
|
+
return state.validate(self.required(), show_err=show_err)
|
|
44
52
|
|
|
45
53
|
def help(self, _: ReplState) -> str:
|
|
46
54
|
return None
|
|
@@ -54,6 +62,9 @@ class Command:
|
|
|
54
62
|
return a
|
|
55
63
|
|
|
56
64
|
def apply_state(self, args: list[str], state: ReplState, resolve_pg = True, args_to_check = 6) -> tuple[ReplState, list[str]]:
|
|
65
|
+
"""
|
|
66
|
+
Applies any contextual arguments such as namespace or statefulset to the ReplState and returns any non-contextual arguments.
|
|
67
|
+
"""
|
|
57
68
|
return state.apply_args(args, cmd=self.command_tokens(), resolve_pg=resolve_pg, args_to_check=args_to_check)
|
|
58
69
|
|
|
59
70
|
def command_tokens(self):
|
|
@@ -85,17 +96,30 @@ class Command:
|
|
|
85
96
|
args.extend(['--help'])
|
|
86
97
|
subprocess.run(args)
|
|
87
98
|
|
|
88
|
-
def extract_options(args: list[str],
|
|
89
|
-
|
|
99
|
+
def extract_options(args: list[str], trailing: Union[str, list[str]] = [], options: list[str] = []):
|
|
100
|
+
found_options: list[str] = []
|
|
101
|
+
found_trailing = None
|
|
102
|
+
|
|
103
|
+
if trailing is None:
|
|
104
|
+
trailing = []
|
|
105
|
+
elif isinstance(trailing, str):
|
|
106
|
+
trailing = [trailing]
|
|
107
|
+
|
|
108
|
+
if options is None:
|
|
109
|
+
options = []
|
|
110
|
+
elif isinstance(options, str):
|
|
111
|
+
options = [options]
|
|
90
112
|
|
|
91
113
|
new_args: list[str] = []
|
|
92
|
-
for arg in args:
|
|
93
|
-
if arg in
|
|
94
|
-
|
|
114
|
+
for index, arg in enumerate(args):
|
|
115
|
+
if index == len(args) - 1 and arg in trailing:
|
|
116
|
+
found_trailing = arg
|
|
117
|
+
elif arg in options:
|
|
118
|
+
found_options.append(arg)
|
|
95
119
|
else:
|
|
96
120
|
new_args.append(arg)
|
|
97
121
|
|
|
98
|
-
return new_args,
|
|
122
|
+
return new_args, found_trailing, found_options
|
|
99
123
|
|
|
100
124
|
def print_chain(cmd: 'Command'):
|
|
101
125
|
print(f'{cmd.command()}', end = '')
|
|
@@ -104,31 +128,63 @@ class Command:
|
|
|
104
128
|
cmd = s
|
|
105
129
|
print()
|
|
106
130
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
class InvalidState(Exception):
|
|
132
|
+
def __init__(self, state: ReplState):
|
|
133
|
+
super().__init__(f'Invalid state')
|
|
134
|
+
|
|
135
|
+
class ValidateHandler:
|
|
136
|
+
def __init__(self, cmd: Command, args: list[str], state: ReplState, apply = True):
|
|
137
|
+
self.cmd = cmd
|
|
138
|
+
self.args = args
|
|
139
|
+
self.state = state
|
|
140
|
+
self.apply = apply
|
|
141
|
+
|
|
142
|
+
def __enter__(self) -> tuple[list[str], ReplState]:
|
|
143
|
+
state = self.state
|
|
144
|
+
args = self.args
|
|
145
|
+
if self.apply:
|
|
146
|
+
state, args = self.cmd.apply_state(args, state)
|
|
147
|
+
|
|
148
|
+
if not self.cmd.validate_state(state):
|
|
149
|
+
raise InvalidState(state)
|
|
150
|
+
|
|
151
|
+
return args, state
|
|
152
|
+
|
|
153
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
154
|
+
return False
|
|
155
|
+
|
|
156
|
+
class ExtractOptionsHandler:
|
|
157
|
+
def __init__(self, args: list[str], options: list[str] = None):
|
|
158
|
+
self.args = args
|
|
159
|
+
self.options = options
|
|
160
|
+
|
|
161
|
+
def __enter__(self) -> tuple[list[str], list[str]]:
|
|
162
|
+
args, _, options = Command.extract_options(self.args, options=self.options)
|
|
163
|
+
return args, options
|
|
164
|
+
|
|
165
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
166
|
+
return False
|
|
167
|
+
|
|
168
|
+
class ExtractTrailingOptionsHandler:
|
|
169
|
+
def __init__(self, args: list[str], trailing: list[str] = None):
|
|
170
|
+
self.args = args
|
|
171
|
+
self.trailing = trailing
|
|
172
|
+
|
|
173
|
+
def __enter__(self) -> tuple[list[str], list[str]]:
|
|
174
|
+
args, trailing, _ = Command.extract_options(self.args, trailing=self.trailing)
|
|
175
|
+
return args, trailing
|
|
176
|
+
|
|
177
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
178
|
+
return False
|
|
179
|
+
|
|
180
|
+
class ExtractAllOptionsHandler:
|
|
181
|
+
def __init__(self, args: list[str], trailing: list[str] = None, options: list[str] = None):
|
|
182
|
+
self.args = args
|
|
183
|
+
self.trailing = trailing
|
|
184
|
+
self.options = options
|
|
185
|
+
|
|
186
|
+
def __enter__(self) -> tuple[list[str], list[str]]:
|
|
187
|
+
return Command.extract_options(self.args, options=self.options)
|
|
188
|
+
|
|
189
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
190
|
+
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.
|
|
6
|
+
from adam.utils_issues import IssuesUtils
|
|
9
7
|
from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
10
8
|
from adam.utils_k8s.pods import Pods
|
|
11
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 duration, lines_to_tabular, 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)
|
|
@@ -71,10 +61,10 @@ def show_rollout(sts: str, ns: str):
|
|
|
71
61
|
else:
|
|
72
62
|
log2(f'Cluster has completed rollout {d} ago.')
|
|
73
63
|
|
|
74
|
-
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):
|
|
75
65
|
columns = Columns.create_columns(cols)
|
|
76
66
|
|
|
77
|
-
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)
|
|
78
68
|
|
|
79
69
|
def line(pod_name: str):
|
|
80
70
|
cells = [c.pod_value(results, pod_name) for c in columns]
|
|
@@ -85,4 +75,4 @@ def show_table(state: ReplState, pods: list[str], cols: str, header: str, show_o
|
|
|
85
75
|
|
|
86
76
|
log(lines_to_tabular(lines, header, separator=','))
|
|
87
77
|
|
|
88
|
-
|
|
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,11 +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
|
|
5
|
+
from adam.config import Config
|
|
2
6
|
from adam.repl_state import ReplState
|
|
3
|
-
from adam.sql.sql_completer import SqlCompleter
|
|
7
|
+
from adam.sql.sql_completer import SqlCompleter, SqlVariant
|
|
8
|
+
from adam.utils import log_timing
|
|
4
9
|
|
|
5
10
|
def cql_completions(state: ReplState) -> dict[str, any]:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
ps = Config().get('cql.alter-tables.gc-grace-periods', '3600,86400,864000,7776000').split(',')
|
|
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()
|