kaqing 2.0.14__py3-none-any.whl → 2.0.145__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of kaqing might be problematic. Click here for more details.
- adam/apps.py +2 -2
- adam/batch.py +13 -3
- adam/checks/check_utils.py +4 -4
- adam/checks/compactionstats.py +1 -1
- adam/checks/cpu.py +2 -2
- adam/checks/disk.py +1 -1
- adam/checks/gossip.py +1 -1
- adam/checks/memory.py +3 -3
- adam/checks/status.py +1 -1
- adam/commands/alter_tables.py +81 -0
- adam/commands/app.py +3 -3
- adam/commands/app_ping.py +2 -2
- adam/commands/audit/audit.py +86 -0
- adam/commands/audit/audit_repair_tables.py +77 -0
- adam/commands/audit/audit_run.py +58 -0
- adam/commands/audit/show_last10.py +51 -0
- adam/commands/audit/show_slow10.py +50 -0
- adam/commands/audit/show_top10.py +48 -0
- adam/commands/audit/utils_show_top10.py +59 -0
- adam/commands/bash/__init__.py +0 -0
- adam/commands/bash/bash.py +133 -0
- adam/commands/bash/bash_completer.py +93 -0
- adam/commands/cat.py +56 -0
- adam/commands/cd.py +12 -82
- adam/commands/check.py +6 -0
- adam/commands/cli_commands.py +3 -3
- adam/commands/code.py +60 -0
- adam/commands/command.py +48 -12
- adam/commands/commands_utils.py +4 -5
- adam/commands/cql/__init__.py +0 -0
- adam/commands/cql/cql_completions.py +28 -0
- adam/commands/cql/cql_utils.py +209 -0
- adam/commands/{cqlsh.py → cql/cqlsh.py} +15 -10
- adam/commands/deploy/code_utils.py +2 -2
- adam/commands/deploy/deploy.py +8 -21
- adam/commands/deploy/deploy_frontend.py +1 -1
- adam/commands/deploy/deploy_pg_agent.py +3 -3
- adam/commands/deploy/deploy_pod.py +28 -27
- adam/commands/deploy/deploy_utils.py +16 -26
- adam/commands/deploy/undeploy.py +8 -21
- adam/commands/deploy/undeploy_frontend.py +1 -1
- adam/commands/deploy/undeploy_pg_agent.py +5 -3
- adam/commands/deploy/undeploy_pod.py +12 -10
- adam/commands/devices/__init__.py +0 -0
- adam/commands/devices/device.py +27 -0
- adam/commands/devices/device_app.py +146 -0
- adam/commands/devices/device_auit_log.py +43 -0
- adam/commands/devices/device_cass.py +145 -0
- adam/commands/devices/device_export.py +86 -0
- adam/commands/devices/device_postgres.py +109 -0
- adam/commands/devices/devices.py +25 -0
- adam/commands/export/__init__.py +0 -0
- adam/commands/export/clean_up_export_session.py +53 -0
- adam/commands/export/clean_up_export_sessions.py +40 -0
- adam/commands/export/drop_export_database.py +58 -0
- adam/commands/export/drop_export_databases.py +46 -0
- adam/commands/export/export.py +83 -0
- adam/commands/export/export_databases.py +170 -0
- adam/commands/export/export_select.py +85 -0
- adam/commands/export/export_select_x.py +54 -0
- adam/commands/export/export_use.py +55 -0
- adam/commands/export/exporter.py +364 -0
- adam/commands/export/import_session.py +68 -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 +63 -0
- adam/commands/export/show_export_databases.py +39 -0
- adam/commands/export/show_export_session.py +51 -0
- adam/commands/export/show_export_sessions.py +47 -0
- adam/commands/export/utils_export.py +291 -0
- adam/commands/help.py +12 -7
- adam/commands/issues.py +6 -0
- adam/commands/kubectl.py +41 -0
- adam/commands/login.py +7 -4
- adam/commands/logs.py +2 -1
- adam/commands/ls.py +4 -107
- adam/commands/medusa/medusa.py +2 -26
- adam/commands/medusa/medusa_backup.py +2 -2
- adam/commands/medusa/medusa_restore.py +3 -4
- adam/commands/medusa/medusa_show_backupjobs.py +4 -3
- adam/commands/medusa/medusa_show_restorejobs.py +3 -3
- adam/commands/nodetool.py +9 -4
- adam/commands/param_set.py +1 -1
- adam/commands/postgres/postgres.py +42 -43
- adam/commands/postgres/{postgres_session.py → postgres_context.py} +43 -42
- adam/commands/postgres/postgres_utils.py +31 -0
- adam/commands/postgres/psql_completions.py +10 -0
- adam/commands/preview_table.py +18 -40
- adam/commands/pwd.py +2 -28
- adam/commands/reaper/reaper.py +4 -24
- adam/commands/reaper/reaper_restart.py +1 -1
- adam/commands/reaper/reaper_session.py +2 -2
- adam/commands/repair/repair.py +3 -27
- adam/commands/repair/repair_log.py +1 -1
- adam/commands/repair/repair_run.py +2 -2
- adam/commands/repair/repair_scan.py +1 -1
- adam/commands/repair/repair_stop.py +1 -1
- adam/commands/report.py +6 -0
- adam/commands/restart.py +2 -2
- adam/commands/rollout.py +1 -1
- adam/commands/show/show.py +11 -26
- adam/commands/show/show_app_actions.py +3 -0
- adam/commands/show/show_app_id.py +1 -1
- adam/commands/show/show_app_queues.py +3 -2
- adam/commands/show/show_cassandra_status.py +3 -3
- adam/commands/show/show_cassandra_version.py +3 -3
- adam/commands/show/show_host.py +33 -0
- adam/commands/show/show_login.py +3 -0
- adam/commands/show/show_processes.py +1 -1
- adam/commands/show/show_repairs.py +2 -2
- adam/commands/show/show_storage.py +1 -1
- adam/commands/watch.py +1 -1
- adam/config.py +16 -3
- adam/embedded_params.py +1 -1
- adam/pod_exec_result.py +10 -2
- adam/repl.py +127 -117
- adam/repl_commands.py +51 -16
- adam/repl_state.py +276 -55
- adam/sql/__init__.py +0 -0
- adam/sql/sql_completer.py +120 -0
- adam/sql/sql_state_machine.py +617 -0
- adam/sql/term_completer.py +76 -0
- adam/sso/authn_ad.py +1 -1
- adam/sso/cred_cache.py +1 -1
- adam/sso/idp.py +1 -1
- adam/utils.py +83 -2
- adam/utils_athena.py +145 -0
- adam/utils_audits.py +102 -0
- adam/utils_k8s/__init__.py +0 -0
- adam/utils_k8s/app_clusters.py +33 -0
- adam/utils_k8s/app_pods.py +31 -0
- adam/{k8s_utils → utils_k8s}/cassandra_clusters.py +6 -21
- adam/{k8s_utils → utils_k8s}/cassandra_nodes.py +12 -5
- adam/{k8s_utils → utils_k8s}/deployment.py +2 -2
- adam/{k8s_utils → utils_k8s}/kube_context.py +1 -1
- adam/{k8s_utils → utils_k8s}/pods.py +119 -26
- adam/{k8s_utils → utils_k8s}/secrets.py +4 -0
- adam/{k8s_utils → utils_k8s}/statefulsets.py +5 -4
- 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 +101 -0
- adam/version.py +1 -1
- {kaqing-2.0.14.dist-info → kaqing-2.0.145.dist-info}/METADATA +1 -1
- kaqing-2.0.145.dist-info/RECORD +227 -0
- adam/commands/bash.py +0 -87
- adam/commands/cql_utils.py +0 -53
- adam/commands/devices.py +0 -89
- kaqing-2.0.14.dist-info/RECORD +0 -167
- /adam/{k8s_utils → commands/audit}/__init__.py +0 -0
- /adam/{k8s_utils → utils_k8s}/config_maps.py +0 -0
- /adam/{k8s_utils → utils_k8s}/custom_resources.py +0 -0
- /adam/{k8s_utils → utils_k8s}/ingresses.py +0 -0
- /adam/{k8s_utils → utils_k8s}/jobs.py +0 -0
- /adam/{k8s_utils → utils_k8s}/service_accounts.py +0 -0
- /adam/{k8s_utils → utils_k8s}/services.py +0 -0
- /adam/{k8s_utils → utils_k8s}/volumes.py +0 -0
- {kaqing-2.0.14.dist-info → kaqing-2.0.145.dist-info}/WHEEL +0 -0
- {kaqing-2.0.14.dist-info → kaqing-2.0.145.dist-info}/entry_points.txt +0 -0
- {kaqing-2.0.14.dist-info → kaqing-2.0.145.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from datetime import datetime, timedelta
|
|
2
|
+
|
|
3
|
+
from adam.utils_audits import Audits
|
|
4
|
+
from adam.utils_repl.automata_completer import AutomataCompleter
|
|
5
|
+
from adam.utils_repl.state_machine import StateMachine
|
|
6
|
+
|
|
7
|
+
def extract_limit_and_duration(args: list[str]) -> tuple[int, datetime]:
|
|
8
|
+
limit = 10
|
|
9
|
+
_from = datetime.now() - timedelta(days=30)
|
|
10
|
+
if args:
|
|
11
|
+
try:
|
|
12
|
+
limit = int(args[0])
|
|
13
|
+
except:
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
if len(args) > 2 and args[1] == 'over':
|
|
17
|
+
if args[2] == 'day':
|
|
18
|
+
_from = datetime.now() - timedelta(days=1)
|
|
19
|
+
|
|
20
|
+
return (limit, Audits.date_from(_from))
|
|
21
|
+
|
|
22
|
+
def limit_and_duration_completion():
|
|
23
|
+
return {'10': {'over': {
|
|
24
|
+
'day': None,
|
|
25
|
+
'month': None
|
|
26
|
+
}}}
|
|
27
|
+
|
|
28
|
+
SHOW_TOP10_SPEC = [
|
|
29
|
+
' > show > show',
|
|
30
|
+
'show > last|slow|top > show_top ^ last,slow,top',
|
|
31
|
+
'show_top > word > show_top_n ^ 10',
|
|
32
|
+
'show_top_n > over > show_top_n_over ^ over',
|
|
33
|
+
'show_top_n_over > day|month > show_top_n_over$ ^ day,month',
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
SHOW_TOP10_KEYWORDS = [
|
|
37
|
+
'show',
|
|
38
|
+
'top',
|
|
39
|
+
'last',
|
|
40
|
+
'slow',
|
|
41
|
+
'over',
|
|
42
|
+
'day',
|
|
43
|
+
'month'
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
class ShowTop10StateMachine(StateMachine[str]):
|
|
47
|
+
def spec(self) -> str:
|
|
48
|
+
return SHOW_TOP10_SPEC
|
|
49
|
+
|
|
50
|
+
def keywords(self) -> list[str]:
|
|
51
|
+
return SHOW_TOP10_KEYWORDS
|
|
52
|
+
|
|
53
|
+
def show_top10_completions_for_nesting():
|
|
54
|
+
return {
|
|
55
|
+
'show': {
|
|
56
|
+
'last': AutomataCompleter(ShowTop10StateMachine(), first_term='show last'),
|
|
57
|
+
'slow': AutomataCompleter(ShowTop10StateMachine(), first_term='show slow'),
|
|
58
|
+
'top': AutomataCompleter(ShowTop10StateMachine(), first_term='show top'),
|
|
59
|
+
}}
|
|
File without changes
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
from typing import Callable
|
|
2
|
+
|
|
3
|
+
from adam.commands.bash.bash_completer import BashCompleter
|
|
4
|
+
from adam.commands.command import Command
|
|
5
|
+
from adam.utils_k8s.app_clusters import AppClusters
|
|
6
|
+
from adam.utils_k8s.app_pods import AppPods
|
|
7
|
+
from adam.utils_k8s.cassandra_clusters import CassandraClusters
|
|
8
|
+
from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
9
|
+
from adam.pod_exec_result import PodExecResult
|
|
10
|
+
from adam.repl_state import BashSession, ReplState, RequiredState
|
|
11
|
+
from adam.utils_k8s.pods import Pods
|
|
12
|
+
from adam.utils_k8s.statefulsets import StatefulSets
|
|
13
|
+
from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
14
|
+
|
|
15
|
+
class Bash(Command):
|
|
16
|
+
COMMAND = 'bash'
|
|
17
|
+
|
|
18
|
+
# the singleton pattern
|
|
19
|
+
def __new__(cls, *args, **kwargs):
|
|
20
|
+
if not hasattr(cls, 'instance'): cls.instance = super(Bash, cls).__new__(cls)
|
|
21
|
+
|
|
22
|
+
return cls.instance
|
|
23
|
+
|
|
24
|
+
def __init__(self, successor: Command=None):
|
|
25
|
+
super().__init__(successor)
|
|
26
|
+
|
|
27
|
+
def command(self):
|
|
28
|
+
return Bash.COMMAND
|
|
29
|
+
|
|
30
|
+
def required(self):
|
|
31
|
+
return [RequiredState.CLUSTER_OR_POD, RequiredState.APP_APP, ReplState.P]
|
|
32
|
+
|
|
33
|
+
def run(self, cmd: str, s0: ReplState):
|
|
34
|
+
if not(args := self.args(cmd)):
|
|
35
|
+
return super().run(cmd, s0)
|
|
36
|
+
|
|
37
|
+
state, args = self.apply_state(args, s0, args_to_check=2)
|
|
38
|
+
if not self.validate_state(state):
|
|
39
|
+
return state
|
|
40
|
+
|
|
41
|
+
def _run(state_changed: bool, cli: Callable[[str], None]):
|
|
42
|
+
if state.in_repl:
|
|
43
|
+
if state_changed:
|
|
44
|
+
r = self.exec_with_dir(state, args)
|
|
45
|
+
else:
|
|
46
|
+
r = self.exec_with_dir(s0, args)
|
|
47
|
+
|
|
48
|
+
if not r:
|
|
49
|
+
state.exit_bash()
|
|
50
|
+
|
|
51
|
+
return 'inconsistent pwd'
|
|
52
|
+
|
|
53
|
+
return r
|
|
54
|
+
else:
|
|
55
|
+
cli(' '.join(args))
|
|
56
|
+
|
|
57
|
+
return state
|
|
58
|
+
|
|
59
|
+
if state.device == ReplState.A:
|
|
60
|
+
def cli(command: str):
|
|
61
|
+
if state.app_pod:
|
|
62
|
+
AppPods.exec(state.app_pod, state.namespace, command, show_out=True)
|
|
63
|
+
elif state.app_app:
|
|
64
|
+
AppClusters.exec(AppPods.pod_names(state.namespace, state.app_env, state.app_app), state.namespace, command, action='bash', show_out=True)
|
|
65
|
+
|
|
66
|
+
return _run(s0.app_env != state.app_env or s0.app_app != state.app_app or s0.app_pod != state.app_pod, cli)
|
|
67
|
+
elif state.device == ReplState.P:
|
|
68
|
+
def cli(command: str):
|
|
69
|
+
Pods.exec(state.app_pod, 'ops', state.namespace, command, show_out=True)
|
|
70
|
+
|
|
71
|
+
return _run(s0.pg_path != state.pg_path, cli)
|
|
72
|
+
|
|
73
|
+
def cli(command: str):
|
|
74
|
+
if state.pod:
|
|
75
|
+
CassandraNodes.exec(state.pod, state.namespace, command, show_out=True)
|
|
76
|
+
elif state.sts:
|
|
77
|
+
CassandraClusters.exec(state.sts, state.namespace, command, action='bash', show_out=True)
|
|
78
|
+
|
|
79
|
+
return _run(s0.sts != state.sts or s0.pod != state.pod, cli)
|
|
80
|
+
|
|
81
|
+
def exec_with_dir(self, state: ReplState, args: list[str]) -> list[PodExecResult]:
|
|
82
|
+
session_just_created = False
|
|
83
|
+
if not args:
|
|
84
|
+
session_just_created = True
|
|
85
|
+
session = BashSession(state.device)
|
|
86
|
+
state.enter_bash(session)
|
|
87
|
+
|
|
88
|
+
if state.bash_session:
|
|
89
|
+
if args != ['pwd']:
|
|
90
|
+
if args:
|
|
91
|
+
args.append('&&')
|
|
92
|
+
args.extend(['pwd', '>', f'/tmp/.qing-{state.bash_session.session_id}'])
|
|
93
|
+
|
|
94
|
+
if not session_just_created:
|
|
95
|
+
if pwd := state.bash_session.pwd(state):
|
|
96
|
+
args = ['cd', pwd, '&&'] + args
|
|
97
|
+
|
|
98
|
+
command = ' '.join(args)
|
|
99
|
+
|
|
100
|
+
rs = []
|
|
101
|
+
|
|
102
|
+
if state.device == ReplState.A:
|
|
103
|
+
if state.app_pod:
|
|
104
|
+
rs = [AppPods.exec(state.app_pod, state.namespace, command,
|
|
105
|
+
show_out=not session_just_created, shell='bash')]
|
|
106
|
+
elif state.app_app:
|
|
107
|
+
rs = AppClusters.exec(AppPods.pod_names(state.namespace, state.app_env, state.app_app), state.namespace, command, action='bash',
|
|
108
|
+
show_out=not session_just_created, shell='bash')
|
|
109
|
+
elif state.device == ReplState.P:
|
|
110
|
+
rs = [Pods.exec(state.app_pod, 'ops', state.namespace, command,
|
|
111
|
+
show_out=not session_just_created, shell='bash')]
|
|
112
|
+
else:
|
|
113
|
+
if state.pod:
|
|
114
|
+
rs = [CassandraNodes.exec(state.pod, state.namespace, command,
|
|
115
|
+
show_out=not session_just_created, shell='bash')]
|
|
116
|
+
elif state.sts:
|
|
117
|
+
rs = CassandraClusters.exec(state.sts, state.namespace, command, action='bash',
|
|
118
|
+
show_out=not session_just_created, shell='bash')
|
|
119
|
+
|
|
120
|
+
return rs
|
|
121
|
+
|
|
122
|
+
def completion(self, state: ReplState):
|
|
123
|
+
if state.device == ReplState.A and state.app_app:
|
|
124
|
+
return { Bash.COMMAND: BashCompleter(lambda: []) } | \
|
|
125
|
+
{f'@{p}': {Bash.COMMAND: BashCompleter(lambda: [])} for p in AppPods.pod_names(state.namespace, state.app_env, state.app_app)}
|
|
126
|
+
elif state.sts:
|
|
127
|
+
return { Bash.COMMAND: BashCompleter(lambda: []) } | \
|
|
128
|
+
{f'@{p}': {Bash.COMMAND: BashCompleter(lambda: [])} for p in StatefulSets.pod_names(state.sts, state.namespace)}
|
|
129
|
+
|
|
130
|
+
return {}
|
|
131
|
+
|
|
132
|
+
def help(self, _: ReplState):
|
|
133
|
+
return f'{Bash.COMMAND} [pod-name] [bash-commands] [&]\t run bash on the Cassandra nodes'
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
from typing import Callable
|
|
2
|
+
from prompt_toolkit.completion import WordCompleter
|
|
3
|
+
|
|
4
|
+
from adam.utils_repl.automata_completer import AutomataCompleter
|
|
5
|
+
from adam.utils_repl.state_machine import State, StateMachine
|
|
6
|
+
|
|
7
|
+
BASH_SPEC = [
|
|
8
|
+
# <command> ::= <simple_command> | <pipeline> | <conditional_command>
|
|
9
|
+
# <simple_command> ::= <word> <argument>* <redirection>*
|
|
10
|
+
# <pipeline> ::= <command> '|' <command>
|
|
11
|
+
# <conditional_command> ::= <command> '&&' <command> | <command> '||' <command>
|
|
12
|
+
# <word> ::= <letter> <letter_or_digit>*
|
|
13
|
+
# <argument> ::= <word>
|
|
14
|
+
# <redirection> ::= '>' <filename> | '<' <filename>
|
|
15
|
+
# <filename> ::= <word>
|
|
16
|
+
# <letter> ::= 'a' | 'b' | ... | 'z' | 'A' | 'B' | ... | 'Z'
|
|
17
|
+
# <digit> ::= '0' | '1' | ... | '9'
|
|
18
|
+
# <letter_or_digit> ::= <letter> | <digit>
|
|
19
|
+
|
|
20
|
+
' > word > cmd ^ hosts',
|
|
21
|
+
'cmd > word > cmd ^ |,>,2>,<,&,&&,||',
|
|
22
|
+
'- > pipe > cmd_pipe',
|
|
23
|
+
'- > _rdr0_ > cmd_rdr0',
|
|
24
|
+
'- > _rdr1_ > cmd_rdr1',
|
|
25
|
+
'- > _rdr2_ > cmd_rdr2',
|
|
26
|
+
'- > & > cmd_bg ^ |,>,2>,<,&,&&,||',
|
|
27
|
+
'- > &&|_or_ > nocmd',
|
|
28
|
+
'cmd_a > word > cmd',
|
|
29
|
+
'cmd_pipe > word > cmd',
|
|
30
|
+
'cmd_rdr0 > word > cmd_rdr0_f',
|
|
31
|
+
'cmd_rdr1 > word > cmd_rdr1_f',
|
|
32
|
+
'cmd_rdr2 > word > cmd_rdr2_f',
|
|
33
|
+
'cmd_rdr1_f > pipe > cmd_pipe ^ |,2>,<,&,&&,||',
|
|
34
|
+
'- > _rdr2_ > cmd_rdr2',
|
|
35
|
+
'- > _rdr0_ > cmd_rdr0',
|
|
36
|
+
'cmd_rdr2_f > pipe > cmd_pipe ^ |,<,&,&&,||',
|
|
37
|
+
'- > _rdr0_ > cmd_rdr0',
|
|
38
|
+
'- > & > cmd_bg ^ |,>,2>,<,&,&&,||',
|
|
39
|
+
'- > &&|_or_ > nocmd',
|
|
40
|
+
'cmd_rdr0_f > pipe > cmd_pipe ^ |,&,&&,||',
|
|
41
|
+
'- > & > cmd_bg ^ |,>,2>,<,&,&&,||',
|
|
42
|
+
'- > &&|_or_ > cmd',
|
|
43
|
+
'cmd_bg > &&|_or_ > nocmd ^ &&,||',
|
|
44
|
+
'nocmd > word > cmd',
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
BASH_KEYWORDS = [
|
|
48
|
+
'&',
|
|
49
|
+
'&&',
|
|
50
|
+
'|',
|
|
51
|
+
'||',
|
|
52
|
+
'>',
|
|
53
|
+
'2>',
|
|
54
|
+
'>>',
|
|
55
|
+
'<',
|
|
56
|
+
'hosts'
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
class BashStateMachine(StateMachine[str]):
|
|
60
|
+
def spec(self) -> str:
|
|
61
|
+
return BASH_SPEC
|
|
62
|
+
|
|
63
|
+
def keywords(self) -> list[str]:
|
|
64
|
+
return BASH_KEYWORDS
|
|
65
|
+
|
|
66
|
+
class BashCompleter(AutomataCompleter[str]):
|
|
67
|
+
def __init__(self,
|
|
68
|
+
hosts: Callable[[], list[str]],
|
|
69
|
+
debug = False):
|
|
70
|
+
super().__init__(BashStateMachine(debug=debug), '', debug=debug)
|
|
71
|
+
|
|
72
|
+
self.hosts = hosts
|
|
73
|
+
self.debug = debug
|
|
74
|
+
|
|
75
|
+
def suggestions_completer(self, state: State, suggestions: str) -> list[str]:
|
|
76
|
+
if not suggestions:
|
|
77
|
+
return None
|
|
78
|
+
|
|
79
|
+
terms = []
|
|
80
|
+
for suggestion in suggestions.split(','):
|
|
81
|
+
terms.extend(self._terms(state, suggestion))
|
|
82
|
+
|
|
83
|
+
return WordCompleter(terms)
|
|
84
|
+
|
|
85
|
+
def _terms(self, _: State, word: str) -> list[str]:
|
|
86
|
+
terms = []
|
|
87
|
+
|
|
88
|
+
if word == 'hosts':
|
|
89
|
+
terms.extend(self.hosts())
|
|
90
|
+
else:
|
|
91
|
+
terms.append(word)
|
|
92
|
+
|
|
93
|
+
return terms
|
adam/commands/cat.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from adam.commands.bash.bash import Bash
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.repl_state import ReplState, RequiredState
|
|
4
|
+
from adam.utils import log2
|
|
5
|
+
from adam.utils_k8s.app_pods import AppPods
|
|
6
|
+
from adam.utils_k8s.statefulsets import StatefulSets
|
|
7
|
+
|
|
8
|
+
class Cat(Command):
|
|
9
|
+
COMMAND = 'cat'
|
|
10
|
+
|
|
11
|
+
# the singleton pattern
|
|
12
|
+
def __new__(cls, *args, **kwargs):
|
|
13
|
+
if not hasattr(cls, 'instance'): cls.instance = super(Cat, cls).__new__(cls)
|
|
14
|
+
|
|
15
|
+
return cls.instance
|
|
16
|
+
|
|
17
|
+
def __init__(self, successor: Command=None):
|
|
18
|
+
super().__init__(successor)
|
|
19
|
+
|
|
20
|
+
def command(self):
|
|
21
|
+
return Cat.COMMAND
|
|
22
|
+
|
|
23
|
+
def required(self):
|
|
24
|
+
return [RequiredState.CLUSTER_OR_POD, RequiredState.APP_APP, ReplState.P]
|
|
25
|
+
|
|
26
|
+
def run(self, cmd: str, state: ReplState):
|
|
27
|
+
if not(args := self.args(cmd)):
|
|
28
|
+
return super().run(cmd, state)
|
|
29
|
+
|
|
30
|
+
state, args = self.apply_state(args, state)
|
|
31
|
+
|
|
32
|
+
if len(args) < 1:
|
|
33
|
+
if state.in_repl:
|
|
34
|
+
log2('File is required.')
|
|
35
|
+
log2()
|
|
36
|
+
else:
|
|
37
|
+
log2('* File is missing.')
|
|
38
|
+
Command.display_help()
|
|
39
|
+
|
|
40
|
+
return 'command-missing'
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
return Bash().run('bash ' + cmd, state)
|
|
44
|
+
|
|
45
|
+
def completion(self, state: ReplState):
|
|
46
|
+
if state.device == ReplState.A and state.app_app:
|
|
47
|
+
return super().completion(state) | \
|
|
48
|
+
{f'@{p}': {Cat.COMMAND: None} for p in AppPods.pod_names(state.namespace, state.app_env, state.app_app)}
|
|
49
|
+
elif state.device == ReplState.C and state.sts:
|
|
50
|
+
return super().completion(state) | \
|
|
51
|
+
{f'@{p}': {Cat.COMMAND: None} for p in StatefulSets.pod_names(state.sts, state.namespace)}
|
|
52
|
+
|
|
53
|
+
return {}
|
|
54
|
+
|
|
55
|
+
def help(self, _: ReplState):
|
|
56
|
+
return f'{Cat.COMMAND} file [&]\t run cat command on the Cassandra nodes'
|
adam/commands/cd.py
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
from adam.commands.command import Command
|
|
2
|
-
from adam.commands.
|
|
3
|
-
from adam.
|
|
4
|
-
from adam.k8s_utils.kube_context import KubeContext
|
|
5
|
-
from adam.k8s_utils.statefulsets import StatefulSets
|
|
2
|
+
from adam.commands.devices.device import Device
|
|
3
|
+
from adam.commands.devices.devices import Devices
|
|
6
4
|
from adam.repl_state import ReplState
|
|
7
|
-
from adam.utils import log2
|
|
8
|
-
from adam.apps import Apps
|
|
9
5
|
|
|
10
6
|
class Cd(Command):
|
|
11
7
|
COMMAND = 'cd'
|
|
@@ -22,94 +18,28 @@ class Cd(Command):
|
|
|
22
18
|
def command(self):
|
|
23
19
|
return Cd.COMMAND
|
|
24
20
|
|
|
21
|
+
def required(self):
|
|
22
|
+
return ReplState.NON_L
|
|
23
|
+
|
|
25
24
|
def run(self, cmd: str, state: ReplState):
|
|
26
25
|
if not(args := self.args(cmd)):
|
|
27
26
|
return super().run(cmd, state)
|
|
28
27
|
|
|
28
|
+
if not self.validate_state(state):
|
|
29
|
+
return state
|
|
30
|
+
|
|
29
31
|
if len(args) < 2:
|
|
30
32
|
return state
|
|
31
33
|
|
|
34
|
+
device: Device = Devices.device(state)
|
|
32
35
|
arg = args[1]
|
|
33
36
|
for dir in arg.split('/'):
|
|
34
|
-
|
|
35
|
-
if dir == '':
|
|
36
|
-
state.pg_path = None
|
|
37
|
-
else:
|
|
38
|
-
session = PostgresSession(state.namespace, state.pg_path)
|
|
39
|
-
# patch up state.namespace from pg cd
|
|
40
|
-
if not state.namespace and (ns := session.find_namespace(arg)):
|
|
41
|
-
state.namespace = ns
|
|
42
|
-
state.pg_path = session.directory(arg)
|
|
43
|
-
elif state.device == ReplState.A:
|
|
44
|
-
if dir == '':
|
|
45
|
-
state.app_env = None
|
|
46
|
-
state.app_app = None
|
|
47
|
-
elif dir == '..':
|
|
48
|
-
if state.app_app:
|
|
49
|
-
state.app_app = None
|
|
50
|
-
else:
|
|
51
|
-
state.app_env = None
|
|
52
|
-
else:
|
|
53
|
-
if not state.app_env:
|
|
54
|
-
tks = dir.split('@')
|
|
55
|
-
if len(tks) > 1:
|
|
56
|
-
state.namespace = tks[1]
|
|
57
|
-
|
|
58
|
-
state.app_env = dir.split('@')[0]
|
|
59
|
-
else:
|
|
60
|
-
state.app_app = dir
|
|
61
|
-
else:
|
|
62
|
-
if dir == '':
|
|
63
|
-
state.sts = None
|
|
64
|
-
state.pod = None
|
|
65
|
-
elif dir == '..':
|
|
66
|
-
if state.pod:
|
|
67
|
-
state.pod = None
|
|
68
|
-
else:
|
|
69
|
-
state.sts = None
|
|
70
|
-
else:
|
|
71
|
-
if not state.sts:
|
|
72
|
-
ss_and_ns = dir.split('@')
|
|
73
|
-
state.sts = ss_and_ns[0]
|
|
74
|
-
state.namespace = ss_and_ns[1]
|
|
75
|
-
elif not state.pod:
|
|
76
|
-
p, _ = KubeContext.is_pod_name(dir)
|
|
77
|
-
if p:
|
|
78
|
-
state.pod = p
|
|
79
|
-
else:
|
|
80
|
-
names = CassandraClusters.pod_names_by_host_id(state.sts, state.namespace);
|
|
81
|
-
if dir in names:
|
|
82
|
-
state.pod = names[dir]
|
|
83
|
-
else:
|
|
84
|
-
log2('Not a valid pod name or host id.')
|
|
37
|
+
device.cd(dir, state)
|
|
85
38
|
|
|
86
39
|
return state
|
|
87
40
|
|
|
88
41
|
def completion(self, state: ReplState):
|
|
89
|
-
|
|
90
|
-
pg = PostgresSession(state.namespace, state.pg_path) if state.pg_path else None
|
|
91
|
-
if pg and pg.db:
|
|
92
|
-
return {Cd.COMMAND: {'..': None}}
|
|
93
|
-
elif pg and pg.host:
|
|
94
|
-
return {Cd.COMMAND: {'..': None} | {p['name']: None for p in pg.databases()}}
|
|
95
|
-
else:
|
|
96
|
-
return {Cd.COMMAND: {p: None for p in PostgresSession.hosts(state.namespace)}}
|
|
97
|
-
elif state.device == ReplState.A:
|
|
98
|
-
if state.app_app:
|
|
99
|
-
return {Cd.COMMAND: {'..': None}}
|
|
100
|
-
elif state.app_env:
|
|
101
|
-
return {Cd.COMMAND: {'..': None} | {app[0].split('-')[1]: None for app in Apps.apps(state.app_env)}}
|
|
102
|
-
else:
|
|
103
|
-
return {Cd.COMMAND: {'..': None} | {env[0]: None for env in Apps.envs()}}
|
|
104
|
-
else:
|
|
105
|
-
if state.pod:
|
|
106
|
-
return {Cd.COMMAND: {'..': None}}
|
|
107
|
-
elif state.sts:
|
|
108
|
-
return {Cd.COMMAND: {'..': None} | {p: None for p in StatefulSets.pod_names(state.sts, state.namespace)}}
|
|
109
|
-
else:
|
|
110
|
-
return {Cd.COMMAND: {p: None for p in StatefulSets.list_sts_names()}}
|
|
111
|
-
|
|
112
|
-
return {}
|
|
42
|
+
return Devices.device(state).cd_completion(Cd.COMMAND, state, default = {})
|
|
113
43
|
|
|
114
44
|
def help(self, _: ReplState):
|
|
115
|
-
return f'{Cd.COMMAND} <path> | .. \t move around'
|
|
45
|
+
return f'{Cd.COMMAND} <path> | .. \t move around on the operational device hierarchy'
|
adam/commands/check.py
CHANGED
|
@@ -23,11 +23,17 @@ class Check(Issues):
|
|
|
23
23
|
def command(self):
|
|
24
24
|
return Check.COMMAND
|
|
25
25
|
|
|
26
|
+
def required(self):
|
|
27
|
+
return ReplState.NON_L
|
|
28
|
+
|
|
26
29
|
def run(self, cmd: str, state: ReplState):
|
|
27
30
|
if not(args := self.args(cmd)):
|
|
28
31
|
return super().run(cmd, state)
|
|
29
32
|
|
|
30
33
|
state, args = self.apply_state(args, state)
|
|
34
|
+
if not self.validate_state(state):
|
|
35
|
+
return state
|
|
36
|
+
|
|
31
37
|
args, show = Command.extract_options(args, ['-s', '--show'])
|
|
32
38
|
|
|
33
39
|
if not args:
|
adam/commands/cli_commands.py
CHANGED
|
@@ -3,9 +3,9 @@ import re
|
|
|
3
3
|
|
|
4
4
|
from adam.commands.reaper.reaper_session import ReaperSession
|
|
5
5
|
from adam.config import Config
|
|
6
|
-
from adam.
|
|
7
|
-
from adam.
|
|
8
|
-
from adam.
|
|
6
|
+
from adam.utils_k8s.kube_context import KubeContext
|
|
7
|
+
from adam.utils_k8s.secrets import Secrets
|
|
8
|
+
from adam.utils_k8s.statefulsets import StatefulSets
|
|
9
9
|
from adam.repl_state import ReplState
|
|
10
10
|
|
|
11
11
|
class CliCommands:
|
adam/commands/code.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import code
|
|
2
|
+
from functools import partial
|
|
3
|
+
|
|
4
|
+
from adam.commands.command import Command
|
|
5
|
+
from adam.commands.cql.cql_utils 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
|
+
state, args = self.apply_state(args, state)
|
|
33
|
+
if not self.validate_state(state):
|
|
34
|
+
return state
|
|
35
|
+
|
|
36
|
+
sts = state.sts
|
|
37
|
+
pod = state.pod
|
|
38
|
+
pods = StatefulSets.pod_names(state.sts, state.namespace)
|
|
39
|
+
tables = cassandra_table_names(state)
|
|
40
|
+
cql = partial(run_cql, state, show_out=True)
|
|
41
|
+
|
|
42
|
+
my_local = globals() | locals()
|
|
43
|
+
# my_local = globals() | {'StatefulSets': StatefulSets} | locals()
|
|
44
|
+
lines = [
|
|
45
|
+
'sts: StatefulSet name',
|
|
46
|
+
'pod: Pod name',
|
|
47
|
+
'pods: Pod names in the current StatefulSet',
|
|
48
|
+
'tables: Cassandra tables names in the current StatefulSet',
|
|
49
|
+
"cql('select...'): run cql statement"
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
code.interact(local=my_local, banner=lines_to_tabular(lines, header='Variables', separator=':'))
|
|
53
|
+
|
|
54
|
+
return state
|
|
55
|
+
|
|
56
|
+
def completion(self, state: ReplState):
|
|
57
|
+
return super().completion(state)
|
|
58
|
+
|
|
59
|
+
def help(self, _: ReplState):
|
|
60
|
+
return f'{Code.COMMAND} \t invoke interactive Python shell'
|
adam/commands/command.py
CHANGED
|
@@ -3,8 +3,9 @@ import copy
|
|
|
3
3
|
import subprocess
|
|
4
4
|
import sys
|
|
5
5
|
|
|
6
|
-
from adam.
|
|
6
|
+
from adam.commands.command_helpers import ClusterCommandHelper
|
|
7
7
|
from adam.repl_state import ReplState, RequiredState
|
|
8
|
+
from adam.utils import is_lambda, lines_to_tabular, log, log2
|
|
8
9
|
|
|
9
10
|
repl_cmds: list['Command'] = []
|
|
10
11
|
|
|
@@ -22,14 +23,18 @@ class Command:
|
|
|
22
23
|
# Do not do child of child!!!
|
|
23
24
|
@abstractmethod
|
|
24
25
|
def run(self, cmd: str, state: ReplState):
|
|
25
|
-
Config().debug(cmd)
|
|
26
26
|
if self._successor:
|
|
27
27
|
return self._successor.run(cmd, state)
|
|
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,12 +44,11 @@ class Command:
|
|
|
39
44
|
def required(self) -> RequiredState:
|
|
40
45
|
return None
|
|
41
46
|
|
|
42
|
-
def validate_state(self, state: ReplState,
|
|
43
|
-
return state.validate(self.required(),
|
|
47
|
+
def validate_state(self, state: ReplState, show_err=True):
|
|
48
|
+
return state.validate(self.required(), show_err=show_err)
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
pass
|
|
50
|
+
def help(self, _: ReplState) -> str:
|
|
51
|
+
return None
|
|
48
52
|
|
|
49
53
|
def args(self, cmd: str):
|
|
50
54
|
a = list(filter(None, cmd.split(' ')))
|
|
@@ -54,8 +58,11 @@ class Command:
|
|
|
54
58
|
|
|
55
59
|
return a
|
|
56
60
|
|
|
57
|
-
def apply_state(self, args: list[str], state: ReplState, resolve_pg = True) -> tuple[ReplState, list[str]]:
|
|
58
|
-
|
|
61
|
+
def apply_state(self, args: list[str], state: ReplState, resolve_pg = True, args_to_check = 6) -> tuple[ReplState, list[str]]:
|
|
62
|
+
"""
|
|
63
|
+
Applies any contextual arguments such as namespace or statefulset to the ReplState and returns any non-contextual arguments.
|
|
64
|
+
"""
|
|
65
|
+
return state.apply_args(args, cmd=self.command_tokens(), resolve_pg=resolve_pg, args_to_check=args_to_check)
|
|
59
66
|
|
|
60
67
|
def command_tokens(self):
|
|
61
68
|
return self.command().split(' ')
|
|
@@ -103,4 +110,33 @@ class Command:
|
|
|
103
110
|
while s := cmd._successor:
|
|
104
111
|
print(f'-> {s.command()}', end = '')
|
|
105
112
|
cmd = s
|
|
106
|
-
print()
|
|
113
|
+
print()
|
|
114
|
+
|
|
115
|
+
def intermediate_run(self, cmd: str, state: ReplState, args: list[str], cmds: list['Command'], separator='\t', display_help=True):
|
|
116
|
+
state, _ = self.apply_state(args, state)
|
|
117
|
+
|
|
118
|
+
if state.in_repl:
|
|
119
|
+
if display_help:
|
|
120
|
+
log(lines_to_tabular([c.help(state) for c in cmds], separator=separator))
|
|
121
|
+
|
|
122
|
+
return 'command-missing'
|
|
123
|
+
else:
|
|
124
|
+
# head with the Chain of Responsibility pattern
|
|
125
|
+
cmds = Command.chain(cmds)
|
|
126
|
+
if not cmds.run(cmd, state):
|
|
127
|
+
if display_help:
|
|
128
|
+
log2('* Command is missing.')
|
|
129
|
+
Command.display_help()
|
|
130
|
+
return 'command-missing'
|
|
131
|
+
|
|
132
|
+
return state
|
|
133
|
+
|
|
134
|
+
def intermediate_help(super_help: str, cmd: str, cmd_list: list['Command'], separator='\t', show_cluster_help=False):
|
|
135
|
+
log(super_help)
|
|
136
|
+
log()
|
|
137
|
+
log('Sub-Commands:')
|
|
138
|
+
|
|
139
|
+
log(lines_to_tabular([c.help(ReplState()).replace(f'{cmd} ', ' ', 1) for c in cmd_list], separator=separator))
|
|
140
|
+
if show_cluster_help:
|
|
141
|
+
log()
|
|
142
|
+
ClusterCommandHelper.cluster_help()
|
adam/commands/commands_utils.py
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
from concurrent.futures import ThreadPoolExecutor
|
|
2
|
-
import time
|
|
3
2
|
from kubernetes import client
|
|
4
3
|
from typing import List
|
|
5
4
|
|
|
6
5
|
from adam.checks.check_utils import run_checks
|
|
7
6
|
from adam.columns.columns import Columns, collect_checks
|
|
8
7
|
from adam.commands.issues import Issues
|
|
9
|
-
from adam.
|
|
10
|
-
from adam.
|
|
11
|
-
from adam.
|
|
8
|
+
from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
9
|
+
from adam.utils_k8s.pods import Pods
|
|
10
|
+
from adam.utils_k8s.statefulsets import StatefulSets
|
|
12
11
|
from adam.repl_state import ReplState
|
|
13
|
-
from adam.utils import
|
|
12
|
+
from adam.utils import duration, lines_to_tabular, log, log2
|
|
14
13
|
|
|
15
14
|
def show_pods(pods: List[client.V1Pod], ns: str, show_namespace = True, show_host_id = True):
|
|
16
15
|
if len(pods) == 0:
|
|
File without changes
|