kaqing 1.77.0__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 +1 -0
- adam/app_session.py +182 -0
- {walker → adam}/apps.py +8 -24
- {walker → adam}/batch.py +54 -97
- {walker → adam}/checks/check.py +3 -3
- {walker → adam}/checks/check_result.py +1 -1
- adam/checks/check_utils.py +65 -0
- {walker → adam}/checks/compactionstats.py +6 -6
- {walker → adam}/checks/cpu.py +14 -8
- adam/checks/cpu_metrics.py +52 -0
- {walker → adam}/checks/disk.py +6 -6
- {walker → adam}/checks/gossip.py +5 -5
- {walker → adam}/checks/memory.py +7 -7
- {walker → adam}/checks/status.py +5 -5
- {walker → adam}/cli.py +3 -3
- {walker → adam}/columns/column.py +1 -1
- adam/columns/columns.py +45 -0
- {walker → adam}/columns/compactions.py +5 -5
- {walker → adam}/columns/cpu.py +6 -4
- adam/columns/cpu_metrics.py +22 -0
- {walker → adam}/columns/dir_data.py +3 -3
- {walker → adam}/columns/dir_snapshots.py +3 -3
- {walker → adam}/columns/gossip.py +5 -5
- {walker → adam}/columns/host_id.py +3 -3
- {walker → adam}/columns/memory.py +3 -3
- {walker → adam}/columns/node_address.py +3 -3
- {walker → adam}/columns/node_load.py +3 -3
- {walker → adam}/columns/node_owns.py +3 -3
- {walker → adam}/columns/node_status.py +3 -3
- {walker → adam}/columns/node_tokens.py +3 -3
- {walker → adam}/columns/node_utils.py +2 -2
- {walker → adam}/columns/pod_name.py +2 -2
- {walker → adam}/columns/volume_cassandra.py +4 -4
- {walker → adam}/columns/volume_root.py +3 -3
- adam/commands/__init__.py +15 -0
- adam/commands/alter_tables.py +81 -0
- adam/commands/app_cmd.py +38 -0
- {walker → adam}/commands/app_ping.py +10 -16
- adam/commands/audit/audit.py +84 -0
- adam/commands/audit/audit_repair_tables.py +74 -0
- 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 +43 -0
- adam/commands/check.py +73 -0
- {walker → adam}/commands/cli_commands.py +7 -8
- adam/commands/code.py +57 -0
- adam/commands/command.py +190 -0
- {walker → adam}/commands/command_helpers.py +1 -1
- {walker → adam}/commands/commands_utils.py +15 -25
- adam/commands/cp.py +89 -0
- adam/commands/cql/cql_completions.py +33 -0
- {walker/commands → adam/commands/cql}/cqlsh.py +20 -35
- adam/commands/cql/utils_cql.py +343 -0
- {walker/commands/frontend → adam/commands/deploy}/code_start.py +11 -14
- adam/commands/deploy/code_stop.py +40 -0
- {walker/commands/frontend → adam/commands/deploy}/code_utils.py +7 -9
- adam/commands/deploy/deploy.py +25 -0
- adam/commands/deploy/deploy_frontend.py +49 -0
- adam/commands/deploy/deploy_pg_agent.py +35 -0
- adam/commands/deploy/deploy_pod.py +108 -0
- adam/commands/deploy/deploy_utils.py +29 -0
- adam/commands/deploy/undeploy.py +25 -0
- adam/commands/deploy/undeploy_frontend.py +38 -0
- adam/commands/deploy/undeploy_pg_agent.py +39 -0
- adam/commands/deploy/undeploy_pod.py +48 -0
- adam/commands/devices/device.py +118 -0
- adam/commands/devices/device_app.py +173 -0
- adam/commands/devices/device_auit_log.py +49 -0
- adam/commands/devices/device_cass.py +185 -0
- adam/commands/devices/device_export.py +86 -0
- adam/commands/devices/device_postgres.py +144 -0
- adam/commands/devices/devices.py +25 -0
- {walker → adam}/commands/exit.py +3 -6
- 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
- {walker → adam}/commands/help.py +17 -12
- adam/commands/intermediate_command.py +49 -0
- adam/commands/issues.py +43 -0
- adam/commands/kubectl.py +38 -0
- adam/commands/login.py +70 -0
- {walker → adam}/commands/logs.py +8 -10
- adam/commands/ls.py +41 -0
- adam/commands/medusa/medusa.py +27 -0
- adam/commands/medusa/medusa_backup.py +57 -0
- adam/commands/medusa/medusa_restore.py +83 -0
- adam/commands/medusa/medusa_show_backupjobs.py +51 -0
- adam/commands/medusa/medusa_show_restorejobs.py +47 -0
- {walker → adam}/commands/nodetool.py +17 -21
- {walker → adam}/commands/param_get.py +15 -16
- adam/commands/param_set.py +43 -0
- adam/commands/postgres/postgres.py +104 -0
- adam/commands/postgres/postgres_context.py +274 -0
- {walker → adam}/commands/postgres/postgres_ls.py +7 -11
- {walker → adam}/commands/postgres/postgres_preview.py +8 -13
- adam/commands/postgres/psql_completions.py +10 -0
- adam/commands/postgres/utils_postgres.py +66 -0
- adam/commands/preview_table.py +37 -0
- adam/commands/pwd.py +47 -0
- adam/commands/reaper/reaper.py +35 -0
- adam/commands/reaper/reaper_forward.py +93 -0
- adam/commands/reaper/reaper_forward_session.py +6 -0
- {walker → adam}/commands/reaper/reaper_forward_stop.py +13 -19
- {walker → adam}/commands/reaper/reaper_restart.py +10 -17
- adam/commands/reaper/reaper_run_abort.py +46 -0
- adam/commands/reaper/reaper_runs.py +82 -0
- adam/commands/reaper/reaper_runs_abort.py +63 -0
- adam/commands/reaper/reaper_schedule_activate.py +45 -0
- adam/commands/reaper/reaper_schedule_start.py +45 -0
- adam/commands/reaper/reaper_schedule_stop.py +45 -0
- {walker → adam}/commands/reaper/reaper_schedules.py +6 -16
- {walker → adam}/commands/reaper/reaper_status.py +11 -19
- adam/commands/reaper/utils_reaper.py +196 -0
- adam/commands/repair/repair.py +26 -0
- {walker → adam}/commands/repair/repair_log.py +7 -10
- adam/commands/repair/repair_run.py +70 -0
- adam/commands/repair/repair_scan.py +71 -0
- {walker → adam}/commands/repair/repair_stop.py +8 -11
- adam/commands/report.py +61 -0
- adam/commands/restart.py +60 -0
- {walker → adam}/commands/rollout.py +25 -30
- adam/commands/shell.py +34 -0
- adam/commands/show/show.py +39 -0
- walker/commands/show/show_version.py → adam/commands/show/show_adam.py +14 -10
- adam/commands/show/show_app_actions.py +57 -0
- {walker → adam}/commands/show/show_app_id.py +12 -15
- {walker → adam}/commands/show/show_app_queues.py +9 -12
- adam/commands/show/show_cassandra_repairs.py +38 -0
- adam/commands/show/show_cassandra_status.py +124 -0
- {walker → adam}/commands/show/show_cassandra_version.py +6 -16
- adam/commands/show/show_commands.py +59 -0
- walker/commands/show/show_storage.py → adam/commands/show/show_host.py +11 -13
- adam/commands/show/show_login.py +62 -0
- {walker → adam}/commands/show/show_params.py +4 -4
- adam/commands/show/show_processes.py +51 -0
- adam/commands/show/show_storage.py +42 -0
- adam/commands/watch.py +82 -0
- {walker → adam}/config.py +10 -22
- {walker → adam}/embedded_apps.py +1 -1
- adam/embedded_params.py +2 -0
- adam/log.py +47 -0
- {walker → adam}/pod_exec_result.py +10 -2
- adam/repl.py +182 -0
- adam/repl_commands.py +124 -0
- adam/repl_state.py +458 -0
- adam/sql/__init__.py +0 -0
- adam/sql/sql_completer.py +120 -0
- adam/sql/sql_state_machine.py +618 -0
- adam/sql/term_completer.py +76 -0
- adam/sso/__init__.py +0 -0
- {walker → adam}/sso/authenticator.py +5 -1
- adam/sso/authn_ad.py +170 -0
- {walker → adam}/sso/authn_okta.py +39 -22
- adam/sso/cred_cache.py +60 -0
- adam/sso/id_token.py +23 -0
- adam/sso/idp.py +143 -0
- adam/sso/idp_login.py +50 -0
- adam/sso/idp_session.py +55 -0
- adam/sso/sso_config.py +63 -0
- adam/utils.py +679 -0
- adam/utils_app.py +98 -0
- adam/utils_athena.py +145 -0
- adam/utils_audits.py +106 -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 +33 -0
- adam/utils_k8s/cassandra_clusters.py +36 -0
- adam/utils_k8s/cassandra_nodes.py +33 -0
- adam/utils_k8s/config_maps.py +34 -0
- {walker/k8s_utils → adam/utils_k8s}/custom_resources.py +7 -2
- adam/utils_k8s/deployment.py +56 -0
- {walker/k8s_utils → adam/utils_k8s}/ingresses.py +3 -4
- {walker/k8s_utils → adam/utils_k8s}/jobs.py +3 -3
- adam/utils_k8s/k8s.py +87 -0
- {walker/k8s_utils → adam/utils_k8s}/kube_context.py +4 -4
- adam/utils_k8s/pods.py +290 -0
- {walker/k8s_utils → adam/utils_k8s}/secrets.py +8 -4
- adam/utils_k8s/service_accounts.py +170 -0
- {walker/k8s_utils → adam/utils_k8s}/services.py +3 -4
- {walker/k8s_utils → adam/utils_k8s}/statefulsets.py +6 -16
- {walker/k8s_utils → adam/utils_k8s}/volumes.py +10 -1
- 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 +109 -0
- adam/version.py +5 -0
- {kaqing-1.77.0.dist-info → kaqing-2.0.171.dist-info}/METADATA +1 -1
- kaqing-2.0.171.dist-info/RECORD +236 -0
- kaqing-2.0.171.dist-info/entry_points.txt +3 -0
- kaqing-2.0.171.dist-info/top_level.txt +1 -0
- kaqing-1.77.0.dist-info/RECORD +0 -159
- kaqing-1.77.0.dist-info/entry_points.txt +0 -3
- kaqing-1.77.0.dist-info/top_level.txt +0 -1
- walker/__init__.py +0 -3
- walker/app_session.py +0 -168
- walker/checks/check_utils.py +0 -97
- walker/columns/columns.py +0 -43
- walker/commands/add_user.py +0 -68
- walker/commands/app.py +0 -67
- walker/commands/bash.py +0 -87
- walker/commands/cd.py +0 -115
- walker/commands/check.py +0 -68
- walker/commands/command.py +0 -104
- walker/commands/cp.py +0 -95
- walker/commands/cql_utils.py +0 -53
- walker/commands/devices.py +0 -89
- walker/commands/frontend/code_stop.py +0 -57
- walker/commands/frontend/setup.py +0 -60
- walker/commands/frontend/setup_frontend.py +0 -58
- walker/commands/frontend/teardown.py +0 -61
- walker/commands/frontend/teardown_frontend.py +0 -42
- walker/commands/issues.py +0 -69
- walker/commands/login.py +0 -72
- walker/commands/ls.py +0 -145
- walker/commands/medusa/medusa.py +0 -69
- walker/commands/medusa/medusa_backup.py +0 -61
- walker/commands/medusa/medusa_restore.py +0 -86
- walker/commands/medusa/medusa_show_backupjobs.py +0 -52
- walker/commands/medusa/medusa_show_restorejobs.py +0 -52
- walker/commands/param_set.py +0 -44
- walker/commands/postgres/postgres.py +0 -113
- walker/commands/postgres/postgres_session.py +0 -225
- walker/commands/preview_table.py +0 -98
- walker/commands/processes.py +0 -53
- walker/commands/pwd.py +0 -64
- walker/commands/reaper/reaper.py +0 -78
- walker/commands/reaper/reaper_forward.py +0 -100
- walker/commands/reaper/reaper_run_abort.py +0 -65
- walker/commands/reaper/reaper_runs.py +0 -97
- walker/commands/reaper/reaper_runs_abort.py +0 -83
- walker/commands/reaper/reaper_schedule_activate.py +0 -64
- walker/commands/reaper/reaper_schedule_start.py +0 -64
- walker/commands/reaper/reaper_schedule_stop.py +0 -64
- walker/commands/reaper/reaper_session.py +0 -159
- walker/commands/repair/repair.py +0 -68
- walker/commands/repair/repair_run.py +0 -72
- walker/commands/repair/repair_scan.py +0 -79
- walker/commands/report.py +0 -57
- walker/commands/restart.py +0 -61
- walker/commands/show/show.py +0 -72
- walker/commands/show/show_app_actions.py +0 -53
- walker/commands/show/show_cassandra_status.py +0 -35
- walker/commands/show/show_commands.py +0 -58
- walker/commands/show/show_processes.py +0 -35
- walker/commands/show/show_repairs.py +0 -47
- walker/commands/status.py +0 -128
- walker/commands/storage.py +0 -52
- walker/commands/user_entry.py +0 -69
- walker/commands/watch.py +0 -85
- walker/embedded_params.py +0 -2
- walker/k8s_utils/cassandra_clusters.py +0 -48
- walker/k8s_utils/cassandra_nodes.py +0 -26
- walker/k8s_utils/pods.py +0 -211
- walker/repl.py +0 -165
- walker/repl_commands.py +0 -58
- walker/repl_state.py +0 -211
- walker/sso/authn_ad.py +0 -94
- walker/sso/idp.py +0 -150
- walker/sso/idp_login.py +0 -29
- walker/sso/sso_config.py +0 -45
- walker/utils.py +0 -194
- walker/version.py +0 -5
- {walker → adam}/checks/__init__.py +0 -0
- {walker → adam}/checks/check_context.py +0 -0
- {walker → adam}/checks/issue.py +0 -0
- {walker → adam}/cli_group.py +0 -0
- {walker → adam}/columns/__init__.py +0 -0
- {walker/commands → adam/commands/audit}/__init__.py +0 -0
- {walker/commands/frontend → adam/commands/cql}/__init__.py +0 -0
- {walker/commands/medusa → adam/commands/deploy}/__init__.py +0 -0
- {walker/commands/postgres → adam/commands/devices}/__init__.py +0 -0
- {walker/commands/reaper → adam/commands/export}/__init__.py +0 -0
- {walker/commands/repair → adam/commands/medusa}/__init__.py +0 -0
- {walker → adam}/commands/nodetool_commands.py +0 -0
- {walker/commands/show → adam/commands/postgres}/__init__.py +0 -0
- {walker/k8s_utils → adam/commands/reaper}/__init__.py +0 -0
- {walker/sso → adam/commands/repair}/__init__.py +0 -0
- /walker/medusa_show_restorejobs.py → /adam/commands/show/__init__.py +0 -0
- {walker → adam}/repl_session.py +0 -0
- {kaqing-1.77.0.dist-info → kaqing-2.0.171.dist-info}/WHEEL +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 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
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
import copy
|
|
3
|
+
import subprocess
|
|
4
|
+
import sys
|
|
5
|
+
from typing import Union
|
|
6
|
+
|
|
7
|
+
from adam.repl_state import ReplState, RequiredState
|
|
8
|
+
from adam.utils import is_lambda
|
|
9
|
+
|
|
10
|
+
repl_cmds: list['Command'] = []
|
|
11
|
+
|
|
12
|
+
class Command:
|
|
13
|
+
"""Abstract base class for commands"""
|
|
14
|
+
def __init__(self, successor: 'Command'=None):
|
|
15
|
+
if not hasattr(self, '_successor'):
|
|
16
|
+
self._successor = successor
|
|
17
|
+
|
|
18
|
+
@abstractmethod
|
|
19
|
+
def command(self) -> str:
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
# The chain of responsibility pattern
|
|
23
|
+
# Do not do child of child!!!
|
|
24
|
+
@abstractmethod
|
|
25
|
+
def run(self, cmd: str, state: ReplState):
|
|
26
|
+
if self._successor:
|
|
27
|
+
return self._successor.run(cmd, state)
|
|
28
|
+
|
|
29
|
+
return None
|
|
30
|
+
|
|
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
|
+
|
|
38
|
+
d = leaf
|
|
39
|
+
for t in reversed(self.command().split(' ')):
|
|
40
|
+
d = {t: d}
|
|
41
|
+
|
|
42
|
+
return d
|
|
43
|
+
|
|
44
|
+
def required(self) -> RequiredState:
|
|
45
|
+
return None
|
|
46
|
+
|
|
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)
|
|
52
|
+
|
|
53
|
+
def help(self, _: ReplState) -> str:
|
|
54
|
+
return None
|
|
55
|
+
|
|
56
|
+
def args(self, cmd: str):
|
|
57
|
+
a = list(filter(None, cmd.split(' ')))
|
|
58
|
+
spec = self.command_tokens()
|
|
59
|
+
if spec != a[:len(spec)]:
|
|
60
|
+
return None
|
|
61
|
+
|
|
62
|
+
return a
|
|
63
|
+
|
|
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
|
+
"""
|
|
68
|
+
return state.apply_args(args, cmd=self.command_tokens(), resolve_pg=resolve_pg, args_to_check=args_to_check)
|
|
69
|
+
|
|
70
|
+
def command_tokens(self):
|
|
71
|
+
return self.command().split(' ')
|
|
72
|
+
|
|
73
|
+
# build a chain-of-responsibility chain
|
|
74
|
+
def chain(cl: list['Command']):
|
|
75
|
+
global repl_cmds
|
|
76
|
+
repl_cmds.extend(cl)
|
|
77
|
+
|
|
78
|
+
cmds = cl[0]
|
|
79
|
+
cmd = cmds
|
|
80
|
+
for successor in cl[1:]:
|
|
81
|
+
cmd._successor = successor
|
|
82
|
+
cmd = successor
|
|
83
|
+
|
|
84
|
+
return cmds
|
|
85
|
+
|
|
86
|
+
def command_to_completion(self):
|
|
87
|
+
# COMMAND = 'reaper activate schedule'
|
|
88
|
+
d = None
|
|
89
|
+
for t in reversed(self.command().split(' ')):
|
|
90
|
+
d = {t: d}
|
|
91
|
+
|
|
92
|
+
return d
|
|
93
|
+
|
|
94
|
+
def display_help():
|
|
95
|
+
args = copy.copy(sys.argv)
|
|
96
|
+
args.extend(['--help'])
|
|
97
|
+
subprocess.run(args)
|
|
98
|
+
|
|
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]
|
|
112
|
+
|
|
113
|
+
new_args: list[str] = []
|
|
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)
|
|
119
|
+
else:
|
|
120
|
+
new_args.append(arg)
|
|
121
|
+
|
|
122
|
+
return new_args, found_trailing, found_options
|
|
123
|
+
|
|
124
|
+
def print_chain(cmd: 'Command'):
|
|
125
|
+
print(f'{cmd.command()}', end = '')
|
|
126
|
+
while s := cmd._successor:
|
|
127
|
+
print(f'-> {s.command()}', end = '')
|
|
128
|
+
cmd = s
|
|
129
|
+
print()
|
|
130
|
+
|
|
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
|
|
@@ -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
|
-
from
|
|
7
|
-
from
|
|
8
|
-
from
|
|
9
|
-
from
|
|
10
|
-
from
|
|
11
|
-
from
|
|
12
|
-
from
|
|
13
|
-
from
|
|
4
|
+
from adam.checks.check_utils import run_checks
|
|
5
|
+
from adam.columns.columns import Columns, collect_checks
|
|
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
|
|
10
|
+
from adam.repl_state import ReplState
|
|
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
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import click
|
|
2
|
+
import pyperclip
|
|
3
|
+
|
|
4
|
+
from adam.commands.command import Command
|
|
5
|
+
from adam.commands.command_helpers import ClusterOrPodCommandHelper
|
|
6
|
+
from adam.commands.cli_commands import CliCommands
|
|
7
|
+
from adam.repl_state import ReplState, RequiredState
|
|
8
|
+
from adam.utils import lines_to_tabular, log, log2
|
|
9
|
+
|
|
10
|
+
class ClipboardCopy(Command):
|
|
11
|
+
COMMAND = 'cp'
|
|
12
|
+
|
|
13
|
+
# the singleton pattern
|
|
14
|
+
def __new__(cls, *args, **kwargs):
|
|
15
|
+
if not hasattr(cls, 'instance'): cls.instance = super(ClipboardCopy, 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 ClipboardCopy.COMMAND
|
|
24
|
+
|
|
25
|
+
def required(self):
|
|
26
|
+
return RequiredState.CLUSTER_OR_POD
|
|
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
|
+
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'
|
|
64
|
+
|
|
65
|
+
def completion(self, state: ReplState):
|
|
66
|
+
return super().completion(state, lambda: {key: None for key in CliCommands.values(state).keys()})
|
|
67
|
+
|
|
68
|
+
def help(self, _: ReplState):
|
|
69
|
+
return f"{ClipboardCopy.COMMAND} <key>\t copy a value to clipboard for conveninence"
|
|
70
|
+
|
|
71
|
+
class CopyCommandHelper(click.Command):
|
|
72
|
+
def lines(self):
|
|
73
|
+
return [
|
|
74
|
+
'node-exec-?: kubectl exec command to the Cassandra pod',
|
|
75
|
+
'reaper-exec: kubectl exec command to the Reaper pod',
|
|
76
|
+
'reaper-forward: kubectl port-forward command to the Reaper pod',
|
|
77
|
+
'reaper-ui: uri to Reaper ui',
|
|
78
|
+
'reaper-username: Reaper user name',
|
|
79
|
+
'reaper-password: Reaper password',
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
def get_help(self, ctx: click.Context):
|
|
83
|
+
log(super().get_help(ctx))
|
|
84
|
+
log()
|
|
85
|
+
log('Keys:')
|
|
86
|
+
|
|
87
|
+
log(lines_to_tabular(self.lines(), separator=':'))
|
|
88
|
+
log()
|
|
89
|
+
ClusterOrPodCommandHelper.cluter_or_pod_help()
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
|
6
|
+
from adam.repl_state import ReplState
|
|
7
|
+
from adam.sql.sql_completer import SqlCompleter, SqlVariant
|
|
8
|
+
from adam.utils import log_timing
|
|
9
|
+
|
|
10
|
+
def cql_completions(state: ReplState) -> dict[str, any]:
|
|
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()
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import click
|
|
2
2
|
|
|
3
|
-
from
|
|
4
|
-
from
|
|
5
|
-
from
|
|
6
|
-
from
|
|
7
|
-
from
|
|
3
|
+
from adam.commands import extract_trailing_options
|
|
4
|
+
from adam.commands.command import Command
|
|
5
|
+
from adam.commands.command_helpers import ClusterOrPodCommandHelper
|
|
6
|
+
from adam.commands.cql.cql_completions import cql_completions
|
|
7
|
+
from adam.commands.cql.utils_cql import cassandra
|
|
8
|
+
from adam.utils_k8s.statefulsets import StatefulSets
|
|
9
|
+
from adam.repl_state import ReplState, RequiredState
|
|
10
|
+
from adam.utils import log
|
|
8
11
|
|
|
9
12
|
class Cqlsh(Command):
|
|
10
13
|
COMMAND = 'cql'
|
|
@@ -28,43 +31,25 @@ class Cqlsh(Command):
|
|
|
28
31
|
if not(args := self.args(cmd)):
|
|
29
32
|
return super().run(cmd, state)
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
opts = []
|
|
36
|
-
cqls = []
|
|
37
|
-
for arg in args:
|
|
38
|
-
if arg.startswith('--'):
|
|
39
|
-
opts.append(arg)
|
|
40
|
-
elif arg != '-e':
|
|
41
|
-
cqls.append(arg)
|
|
42
|
-
if not cqls:
|
|
43
|
-
if state.in_repl:
|
|
44
|
-
log2('Please enter cql statement. e.g. select host_id from system.local')
|
|
45
|
-
else:
|
|
46
|
-
log2('* CQL statement is missing.')
|
|
47
|
-
log2()
|
|
48
|
-
Command.display_help()
|
|
49
|
-
|
|
50
|
-
return 'no-cql'
|
|
51
|
-
|
|
52
|
-
cql = ' '.join(cqls)
|
|
53
|
-
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, background=backgrounded)
|
|
54
38
|
|
|
55
39
|
def completion(self, state: ReplState) -> dict[str, any]:
|
|
40
|
+
if state.device != state.C:
|
|
41
|
+
# conflicts with psql completions
|
|
42
|
+
return {}
|
|
43
|
+
|
|
56
44
|
if state.sts or state.pod:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
'select': None,
|
|
61
|
-
'update': None,
|
|
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):
|