kaqing 1.98.15__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/app_session.py +1 -1
- adam/apps.py +2 -2
- adam/batch.py +30 -31
- 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/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/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/__init__.py +0 -0
- adam/commands/{frontend → deploy}/code_start.py +1 -1
- adam/commands/{frontend → deploy}/code_stop.py +1 -1
- adam/commands/{frontend → deploy}/code_utils.py +2 -2
- adam/commands/deploy/deploy.py +48 -0
- adam/commands/deploy/deploy_frontend.py +52 -0
- adam/commands/deploy/deploy_pg_agent.py +38 -0
- adam/commands/deploy/deploy_pod.py +110 -0
- adam/commands/deploy/deploy_utils.py +29 -0
- adam/commands/deploy/undeploy.py +48 -0
- adam/commands/deploy/undeploy_frontend.py +41 -0
- adam/commands/deploy/undeploy_pg_agent.py +42 -0
- adam/commands/deploy/undeploy_pod.py +51 -0
- 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/{frontend/teardown_frontend.py → export/clean_up_export_sessions.py} +9 -11
- 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 +9 -5
- 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_context.py +248 -0
- adam/commands/postgres/postgres_preview.py +0 -1
- 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 +2 -7
- 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/shell.py +33 -0
- 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_commands.py +4 -1
- 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 +132 -117
- adam/repl_commands.py +62 -18
- 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/authenticator.py +1 -1
- adam/sso/authn_ad.py +36 -56
- adam/sso/authn_okta.py +6 -32
- adam/sso/cred_cache.py +1 -1
- adam/sso/idp.py +74 -9
- adam/sso/idp_login.py +2 -2
- adam/sso/idp_session.py +10 -7
- adam/utils.py +85 -4
- 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/utils_k8s/config_maps.py +34 -0
- adam/utils_k8s/deployment.py +56 -0
- adam/{k8s_utils → utils_k8s}/jobs.py +1 -1
- adam/{k8s_utils → utils_k8s}/kube_context.py +1 -1
- adam/utils_k8s/pods.py +342 -0
- adam/{k8s_utils → utils_k8s}/secrets.py +4 -0
- adam/utils_k8s/service_accounts.py +169 -0
- adam/{k8s_utils → utils_k8s}/statefulsets.py +5 -4
- adam/{k8s_utils → utils_k8s}/volumes.py +9 -0
- adam/utils_net.py +24 -0
- adam/utils_repl/__init__.py +0 -0
- adam/utils_repl/automata_completer.py +48 -0
- adam/utils_repl/repl_completer.py +46 -0
- adam/utils_repl/state_machine.py +173 -0
- adam/utils_sqlite.py +101 -0
- adam/version.py +1 -1
- {kaqing-1.98.15.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
- adam/commands/frontend/setup.py +0 -60
- adam/commands/frontend/setup_frontend.py +0 -58
- adam/commands/frontend/teardown.py +0 -61
- adam/commands/postgres/postgres_session.py +0 -225
- adam/commands/user_entry.py +0 -77
- adam/k8s_utils/pods.py +0 -211
- kaqing-1.98.15.dist-info/RECORD +0 -160
- /adam/commands/{frontend → audit}/__init__.py +0 -0
- /adam/{k8s_utils → commands/bash}/__init__.py +0 -0
- /adam/{medusa_show_restorejobs.py → commands/cql/__init__.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}/services.py +0 -0
- {kaqing-1.98.15.dist-info → kaqing-2.0.145.dist-info}/WHEEL +0 -0
- {kaqing-1.98.15.dist-info → kaqing-2.0.145.dist-info}/entry_points.txt +0 -0
- {kaqing-1.98.15.dist-info → kaqing-2.0.145.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from adam.commands.audit.utils_show_top10 import extract_limit_and_duration
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.repl_state import ReplState
|
|
4
|
+
from adam.utils import log2
|
|
5
|
+
from adam.utils_athena import Athena
|
|
6
|
+
from adam.utils_audits import Audits
|
|
7
|
+
|
|
8
|
+
class ShowSlow10(Command):
|
|
9
|
+
COMMAND = 'show slow'
|
|
10
|
+
|
|
11
|
+
# the singleton pattern
|
|
12
|
+
def __new__(cls, *args, **kwargs):
|
|
13
|
+
if not hasattr(cls, 'instance'): cls.instance = super(ShowSlow10, 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 ShowSlow10.COMMAND
|
|
22
|
+
|
|
23
|
+
def required(self):
|
|
24
|
+
return ReplState.L
|
|
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
|
+
if not self.validate_state(state):
|
|
32
|
+
return state
|
|
33
|
+
|
|
34
|
+
limit, date_condition = extract_limit_and_duration(args)
|
|
35
|
+
|
|
36
|
+
query = '\n '.join([
|
|
37
|
+
"SELECT * FROM audit",
|
|
38
|
+
f"WHERE drive <> 'z' and ({date_condition})",
|
|
39
|
+
f"ORDER BY CAST(duration AS REAL) DESC LIMIT {limit};"])
|
|
40
|
+
log2(query)
|
|
41
|
+
log2()
|
|
42
|
+
Athena.run_query(query)
|
|
43
|
+
|
|
44
|
+
return state
|
|
45
|
+
|
|
46
|
+
def completion(self, _: ReplState):
|
|
47
|
+
return {}
|
|
48
|
+
|
|
49
|
+
def help(self, _: ReplState):
|
|
50
|
+
return f'{ShowSlow10.COMMAND} [limit]\t show slow <limit> audit lines'
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from adam.commands.audit.utils_show_top10 import extract_limit_and_duration
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.repl_state import ReplState
|
|
4
|
+
from adam.utils import log2
|
|
5
|
+
from adam.utils_athena import Athena
|
|
6
|
+
|
|
7
|
+
class ShowTop10(Command):
|
|
8
|
+
COMMAND = 'show top'
|
|
9
|
+
|
|
10
|
+
# the singleton pattern
|
|
11
|
+
def __new__(cls, *args, **kwargs):
|
|
12
|
+
if not hasattr(cls, 'instance'): cls.instance = super(ShowTop10, cls).__new__(cls)
|
|
13
|
+
|
|
14
|
+
return cls.instance
|
|
15
|
+
|
|
16
|
+
def __init__(self, successor: Command=None):
|
|
17
|
+
super().__init__(successor)
|
|
18
|
+
|
|
19
|
+
def command(self):
|
|
20
|
+
return ShowTop10.COMMAND
|
|
21
|
+
|
|
22
|
+
def required(self):
|
|
23
|
+
return ReplState.L
|
|
24
|
+
|
|
25
|
+
def run(self, cmd: str, state: ReplState):
|
|
26
|
+
if not(args := self.args(cmd)):
|
|
27
|
+
return super().run(cmd, state)
|
|
28
|
+
|
|
29
|
+
state, args = self.apply_state(args, state)
|
|
30
|
+
if not self.validate_state(state):
|
|
31
|
+
return state
|
|
32
|
+
|
|
33
|
+
limit, date_condition = extract_limit_and_duration(args)
|
|
34
|
+
query = '\n '.join([
|
|
35
|
+
"SELECT min(c) AS cluster, line, COUNT(*) AS cnt, avg(CAST(duration AS REAL)) AS duration",
|
|
36
|
+
f"FROM audit WHERE drive <> 'z' and ({date_condition})",
|
|
37
|
+
f"GROUP BY line ORDER BY cnt DESC LIMIT {limit};"])
|
|
38
|
+
log2(query)
|
|
39
|
+
log2()
|
|
40
|
+
Athena.run_query(query)
|
|
41
|
+
|
|
42
|
+
return state
|
|
43
|
+
|
|
44
|
+
def completion(self, _: ReplState):
|
|
45
|
+
return {}
|
|
46
|
+
|
|
47
|
+
def help(self, _: ReplState):
|
|
48
|
+
return f'{ShowTop10.COMMAND} [limit]\t show top <limit> audit lines'
|
|
@@ -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
|
+
}}
|
|
@@ -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'
|