kaqing 2.0.115__py3-none-any.whl → 2.0.172__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/__init__.py +0 -2
- adam/app_session.py +8 -11
- adam/batch.py +3 -3
- adam/checks/check_utils.py +14 -46
- adam/checks/cpu.py +7 -1
- adam/checks/cpu_metrics.py +52 -0
- adam/checks/disk.py +2 -3
- adam/columns/columns.py +3 -1
- adam/columns/cpu.py +3 -1
- adam/columns/cpu_metrics.py +22 -0
- adam/columns/memory.py +3 -4
- adam/commands/__init__.py +18 -0
- adam/commands/alter_tables.py +43 -47
- adam/commands/audit/audit.py +24 -25
- adam/commands/audit/audit_repair_tables.py +14 -17
- adam/commands/audit/audit_run.py +15 -23
- adam/commands/audit/show_last10.py +10 -13
- adam/commands/audit/show_slow10.py +10 -13
- adam/commands/audit/show_top10.py +10 -14
- adam/commands/audit/utils_show_top10.py +2 -3
- adam/commands/bash/__init__.py +5 -0
- adam/commands/bash/bash.py +8 -96
- adam/commands/bash/utils_bash.py +16 -0
- adam/commands/cat.py +14 -19
- adam/commands/cd.py +12 -100
- adam/commands/check.py +20 -21
- adam/commands/cli_commands.py +2 -3
- adam/commands/code.py +20 -23
- adam/commands/command.py +123 -39
- adam/commands/commands_utils.py +8 -17
- adam/commands/cp.py +33 -39
- adam/commands/cql/cql_completions.py +28 -10
- adam/commands/cql/cqlsh.py +10 -30
- adam/commands/cql/utils_cql.py +343 -0
- adam/commands/deploy/code_start.py +7 -10
- adam/commands/deploy/code_stop.py +4 -21
- adam/commands/deploy/code_utils.py +3 -3
- adam/commands/deploy/deploy.py +4 -27
- adam/commands/deploy/deploy_frontend.py +14 -17
- adam/commands/deploy/deploy_pg_agent.py +2 -5
- adam/commands/deploy/deploy_pod.py +65 -73
- adam/commands/deploy/deploy_utils.py +14 -24
- adam/commands/deploy/undeploy.py +4 -27
- adam/commands/deploy/undeploy_frontend.py +4 -7
- adam/commands/deploy/undeploy_pg_agent.py +5 -7
- adam/commands/deploy/undeploy_pod.py +11 -12
- adam/commands/devices/__init__.py +0 -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
- adam/commands/exit.py +1 -4
- 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 +19 -26
- adam/commands/export/export_databases.py +174 -0
- adam/commands/export/export_handlers.py +71 -0
- adam/commands/export/export_select.py +48 -22
- adam/commands/export/export_select_x.py +54 -0
- adam/commands/export/export_use.py +19 -23
- adam/commands/export/exporter.py +353 -0
- adam/commands/export/import_session.py +40 -0
- adam/commands/export/importer.py +67 -0
- adam/commands/export/importer_athena.py +77 -0
- adam/commands/export/importer_sqlite.py +39 -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 +223 -162
- adam/commands/help.py +1 -1
- adam/commands/intermediate_command.py +49 -0
- adam/commands/issues.py +11 -43
- adam/commands/kubectl.py +3 -6
- adam/commands/login.py +22 -24
- adam/commands/logs.py +3 -6
- adam/commands/ls.py +11 -128
- adam/commands/medusa/medusa.py +4 -22
- adam/commands/medusa/medusa_backup.py +20 -24
- adam/commands/medusa/medusa_restore.py +29 -33
- adam/commands/medusa/medusa_show_backupjobs.py +14 -18
- adam/commands/medusa/medusa_show_restorejobs.py +11 -18
- adam/commands/nodetool.py +6 -15
- adam/commands/param_get.py +11 -12
- adam/commands/param_set.py +9 -10
- adam/commands/postgres/postgres.py +41 -34
- adam/commands/postgres/postgres_context.py +57 -24
- adam/commands/postgres/postgres_ls.py +4 -8
- adam/commands/postgres/postgres_preview.py +5 -9
- adam/commands/postgres/psql_completions.py +1 -1
- adam/commands/postgres/utils_postgres.py +66 -0
- adam/commands/preview_table.py +5 -44
- adam/commands/pwd.py +14 -47
- adam/commands/reaper/reaper.py +4 -27
- adam/commands/reaper/reaper_forward.py +48 -55
- adam/commands/reaper/reaper_forward_session.py +6 -0
- adam/commands/reaper/reaper_forward_stop.py +10 -16
- adam/commands/reaper/reaper_restart.py +7 -14
- adam/commands/reaper/reaper_run_abort.py +11 -30
- adam/commands/reaper/reaper_runs.py +42 -57
- adam/commands/reaper/reaper_runs_abort.py +29 -49
- adam/commands/reaper/reaper_schedule_activate.py +11 -30
- adam/commands/reaper/reaper_schedule_start.py +10 -29
- adam/commands/reaper/reaper_schedule_stop.py +10 -29
- adam/commands/reaper/reaper_schedules.py +4 -14
- adam/commands/reaper/reaper_status.py +8 -16
- adam/commands/reaper/utils_reaper.py +196 -0
- adam/commands/repair/repair.py +4 -22
- adam/commands/repair/repair_log.py +5 -11
- adam/commands/repair/repair_run.py +27 -34
- adam/commands/repair/repair_scan.py +32 -38
- adam/commands/repair/repair_stop.py +5 -11
- adam/commands/report.py +27 -29
- adam/commands/restart.py +25 -26
- adam/commands/rollout.py +19 -24
- adam/commands/shell.py +10 -4
- adam/commands/show/show.py +10 -25
- adam/commands/show/show_cassandra_repairs.py +35 -0
- adam/commands/show/show_cassandra_status.py +32 -43
- adam/commands/show/show_cassandra_version.py +5 -18
- adam/commands/show/show_commands.py +19 -24
- adam/commands/show/show_host.py +1 -1
- adam/commands/show/show_login.py +20 -27
- adam/commands/show/show_processes.py +15 -19
- adam/commands/show/show_storage.py +10 -20
- adam/commands/watch.py +26 -29
- adam/config.py +5 -14
- adam/embedded_params.py +1 -1
- adam/log.py +4 -4
- adam/pod_exec_result.py +3 -3
- adam/repl.py +40 -103
- adam/repl_commands.py +32 -16
- adam/repl_state.py +57 -28
- adam/sql/sql_completer.py +44 -28
- adam/sql/sql_state_machine.py +89 -28
- adam/sso/authn_ad.py +6 -8
- adam/sso/authn_okta.py +4 -6
- adam/sso/cred_cache.py +3 -5
- adam/sso/idp.py +9 -12
- adam/utils.py +435 -6
- adam/utils_athena.py +57 -37
- adam/utils_audits.py +12 -14
- adam/utils_issues.py +32 -0
- adam/utils_k8s/app_clusters.py +13 -18
- adam/utils_k8s/app_pods.py +2 -0
- adam/utils_k8s/cassandra_clusters.py +22 -19
- adam/utils_k8s/cassandra_nodes.py +2 -2
- adam/utils_k8s/custom_resources.py +16 -17
- adam/utils_k8s/ingresses.py +2 -2
- adam/utils_k8s/jobs.py +7 -11
- adam/utils_k8s/k8s.py +87 -0
- adam/utils_k8s/pods.py +40 -77
- adam/utils_k8s/secrets.py +4 -4
- adam/utils_k8s/service_accounts.py +5 -4
- adam/utils_k8s/services.py +2 -2
- adam/utils_k8s/statefulsets.py +1 -12
- adam/utils_net.py +4 -4
- adam/utils_repl/__init__.py +0 -0
- adam/utils_repl/automata_completer.py +48 -0
- adam/utils_repl/repl_completer.py +46 -0
- adam/utils_repl/state_machine.py +173 -0
- adam/utils_sqlite.py +137 -0
- adam/version.py +1 -1
- {kaqing-2.0.115.dist-info → kaqing-2.0.172.dist-info}/METADATA +1 -1
- kaqing-2.0.172.dist-info/RECORD +230 -0
- adam/commands/app.py +0 -67
- adam/commands/app_ping.py +0 -44
- adam/commands/cql/cql_utils.py +0 -204
- adam/commands/devices.py +0 -147
- adam/commands/export/export_on_x.py +0 -76
- adam/commands/export/export_rmdbs.py +0 -65
- adam/commands/postgres/postgres_utils.py +0 -31
- adam/commands/reaper/reaper_session.py +0 -159
- adam/commands/show/show_app_actions.py +0 -56
- adam/commands/show/show_app_id.py +0 -47
- adam/commands/show/show_app_queues.py +0 -45
- adam/commands/show/show_repairs.py +0 -47
- adam/utils_export.py +0 -42
- kaqing-2.0.115.dist-info/RECORD +0 -203
- {kaqing-2.0.115.dist-info → kaqing-2.0.172.dist-info}/WHEEL +0 -0
- {kaqing-2.0.115.dist-info → kaqing-2.0.172.dist-info}/entry_points.txt +0 -0
- {kaqing-2.0.115.dist-info → kaqing-2.0.172.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.devices.device import Device
|
|
3
|
+
from adam.repl_state import ReplState
|
|
4
|
+
from adam.utils import lines_to_tabular, log
|
|
5
|
+
from adam.utils_athena import Athena
|
|
6
|
+
|
|
7
|
+
class DeviceAuditLog(Command, Device):
|
|
8
|
+
COMMAND = f'{ReplState.L}:'
|
|
9
|
+
|
|
10
|
+
# the singleton pattern
|
|
11
|
+
def __new__(cls, *args, **kwargs):
|
|
12
|
+
if not hasattr(cls, 'instance'): cls.instance = super(DeviceAuditLog, 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 DeviceAuditLog.COMMAND
|
|
21
|
+
|
|
22
|
+
def run(self, cmd: str, state: ReplState):
|
|
23
|
+
if not self.args(cmd):
|
|
24
|
+
return super().run(cmd, state)
|
|
25
|
+
|
|
26
|
+
state.device = ReplState.L
|
|
27
|
+
|
|
28
|
+
return state
|
|
29
|
+
|
|
30
|
+
def completion(self, state: ReplState):
|
|
31
|
+
return super().completion(state)
|
|
32
|
+
|
|
33
|
+
def help(self, _: ReplState):
|
|
34
|
+
return f'{DeviceAuditLog.COMMAND}\t move to Audit Log Operations device'
|
|
35
|
+
|
|
36
|
+
def ls(self, cmd: str, _: ReplState):
|
|
37
|
+
log(lines_to_tabular(Athena.table_names(), 'NAME', separator=','))
|
|
38
|
+
|
|
39
|
+
def pwd(self, _: ReplState):
|
|
40
|
+
return '\t'.join([f'{ReplState.L}:>', '/'])
|
|
41
|
+
|
|
42
|
+
def try_fallback_action(self, chain: Command, state: ReplState, cmd: str):
|
|
43
|
+
return True, chain.run(f'audit {cmd}', state)
|
|
44
|
+
|
|
45
|
+
def show_tables(self, _: ReplState):
|
|
46
|
+
log(lines_to_tabular(Athena.table_names(), separator=','))
|
|
47
|
+
|
|
48
|
+
def show_table_preview(self, _: ReplState, table: str, rows: int):
|
|
49
|
+
Athena.run_query(f'select * from {table} limit {rows}')
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
from adam.commands.bash.bash_completer import BashCompleter
|
|
2
|
+
from adam.commands.command import Command, InvalidState
|
|
3
|
+
from adam.commands.commands_utils import show_pods, show_rollout
|
|
4
|
+
from adam.commands.cql.utils_cql import cassandra, cassandra_table_names
|
|
5
|
+
from adam.commands.devices.device import Device
|
|
6
|
+
from adam.config import Config
|
|
7
|
+
from adam.repl_state import ReplState
|
|
8
|
+
from adam.utils import lines_to_tabular, log, log2, wait_log
|
|
9
|
+
from adam.utils_k8s.cassandra_clusters import CassandraClusters
|
|
10
|
+
from adam.utils_k8s.custom_resources import CustomResources
|
|
11
|
+
from adam.utils_k8s.kube_context import KubeContext
|
|
12
|
+
from adam.utils_k8s.statefulsets import StatefulSets
|
|
13
|
+
|
|
14
|
+
class DeviceCass(Command, Device):
|
|
15
|
+
COMMAND = f'{ReplState.C}:'
|
|
16
|
+
|
|
17
|
+
# the singleton pattern
|
|
18
|
+
def __new__(cls, *args, **kwargs):
|
|
19
|
+
if not hasattr(cls, 'instance'): cls.instance = super(DeviceCass, cls).__new__(cls)
|
|
20
|
+
|
|
21
|
+
return cls.instance
|
|
22
|
+
|
|
23
|
+
def __init__(self, successor: Command=None):
|
|
24
|
+
super().__init__(successor)
|
|
25
|
+
|
|
26
|
+
def command(self):
|
|
27
|
+
return DeviceCass.COMMAND
|
|
28
|
+
|
|
29
|
+
def run(self, cmd: str, state: ReplState):
|
|
30
|
+
if not self.args(cmd):
|
|
31
|
+
return super().run(cmd, state)
|
|
32
|
+
|
|
33
|
+
state.device = ReplState.C
|
|
34
|
+
|
|
35
|
+
return state
|
|
36
|
+
|
|
37
|
+
def completion(self, state: ReplState):
|
|
38
|
+
return super().completion(state)
|
|
39
|
+
|
|
40
|
+
def help(self, _: ReplState):
|
|
41
|
+
return f'{DeviceCass.COMMAND}\t move to Cassandra Operations device'
|
|
42
|
+
|
|
43
|
+
def ls(self, cmd: str, state: ReplState):
|
|
44
|
+
if state.pod:
|
|
45
|
+
return self.bash(state, state, cmd.split(' '))
|
|
46
|
+
elif state.sts and state.namespace:
|
|
47
|
+
show_pods(StatefulSets.pods(state.sts, state.namespace), state.namespace, show_namespace=not KubeContext.in_cluster_namespace())
|
|
48
|
+
show_rollout(state.sts, state.namespace)
|
|
49
|
+
else:
|
|
50
|
+
self.show_statefulsets()
|
|
51
|
+
|
|
52
|
+
def ls_completion(self, cmd: str, state: ReplState, default: dict = {}):
|
|
53
|
+
def pod_names():
|
|
54
|
+
return [p for p in StatefulSets.pod_names(state.sts, state.namespace)]
|
|
55
|
+
|
|
56
|
+
if state.sts:
|
|
57
|
+
return super().completion(state) | {f'@{p}': {'ls': None} for p in pod_names()}
|
|
58
|
+
else:
|
|
59
|
+
return {cmd: {n: None for n in StatefulSets.list_sts_names()}}
|
|
60
|
+
|
|
61
|
+
def cat(self, cmd: str, state: ReplState):
|
|
62
|
+
if state.pod:
|
|
63
|
+
return self.bash(state, state, cmd.split(' '))
|
|
64
|
+
|
|
65
|
+
return InvalidState()
|
|
66
|
+
|
|
67
|
+
def cat_completion(self, cmd: str, state: ReplState, default: dict = {}):
|
|
68
|
+
if state.sts:
|
|
69
|
+
return {f'@{p}': {cmd: None} for p in StatefulSets.pod_names(state.sts, state.namespace)}
|
|
70
|
+
|
|
71
|
+
return default
|
|
72
|
+
|
|
73
|
+
def show_statefulsets(self):
|
|
74
|
+
ss = StatefulSets.list_sts_names()
|
|
75
|
+
if len(ss) == 0:
|
|
76
|
+
log2('No Cassandra clusters found.')
|
|
77
|
+
return
|
|
78
|
+
|
|
79
|
+
app_ids = CustomResources.get_app_ids()
|
|
80
|
+
list = []
|
|
81
|
+
for s in ss:
|
|
82
|
+
cr_name = CustomResources.get_cr_name(s)
|
|
83
|
+
app_id = 'Unknown'
|
|
84
|
+
if cr_name in app_ids:
|
|
85
|
+
app_id = app_ids[cr_name]
|
|
86
|
+
list.append(f"{s} {app_id}")
|
|
87
|
+
|
|
88
|
+
header = 'STATEFULSET_NAME@NAMESPACE APP_ID'
|
|
89
|
+
if KubeContext.in_cluster_namespace():
|
|
90
|
+
header = 'STATEFULSET_NAME APP_ID'
|
|
91
|
+
log(lines_to_tabular(list, header))
|
|
92
|
+
|
|
93
|
+
def cd(self, dir: str, state: ReplState):
|
|
94
|
+
if dir == '':
|
|
95
|
+
state.sts = None
|
|
96
|
+
state.pod = None
|
|
97
|
+
elif dir == '..':
|
|
98
|
+
if state.pod:
|
|
99
|
+
state.pod = None
|
|
100
|
+
else:
|
|
101
|
+
state.sts = None
|
|
102
|
+
else:
|
|
103
|
+
if not state.sts:
|
|
104
|
+
ss_and_ns = dir.split('@')
|
|
105
|
+
state.sts = ss_and_ns[0]
|
|
106
|
+
if len(ss_and_ns) > 1:
|
|
107
|
+
state.namespace = ss_and_ns[1]
|
|
108
|
+
elif not state.pod:
|
|
109
|
+
p, _ = KubeContext.is_pod_name(dir)
|
|
110
|
+
if p:
|
|
111
|
+
state.pod = p
|
|
112
|
+
else:
|
|
113
|
+
names = CassandraClusters.pod_names_by_host_id(state.sts, state.namespace);
|
|
114
|
+
if dir in names:
|
|
115
|
+
state.pod = names[dir]
|
|
116
|
+
else:
|
|
117
|
+
state.pod = dir
|
|
118
|
+
|
|
119
|
+
def cd_completion(self, cmd: str, state: ReplState, default: dict = {}):
|
|
120
|
+
if state.pod:
|
|
121
|
+
return {cmd: {'..': None}}
|
|
122
|
+
elif state.sts:
|
|
123
|
+
return {cmd: {'..': None} | {p: None for p in StatefulSets.pod_names(state.sts, state.namespace)}}
|
|
124
|
+
else:
|
|
125
|
+
return {cmd: {p: None for p in StatefulSets.list_sts_names()}}
|
|
126
|
+
|
|
127
|
+
def pwd(self, state: ReplState):
|
|
128
|
+
words = []
|
|
129
|
+
|
|
130
|
+
if state.sts:
|
|
131
|
+
words.append(f'sts/{state.sts}')
|
|
132
|
+
if state.pod:
|
|
133
|
+
words.append(f'pod/{state.pod}')
|
|
134
|
+
|
|
135
|
+
return '\t'.join([f'{ReplState.C}:>'] + (words if words else ['/']))
|
|
136
|
+
|
|
137
|
+
def try_fallback_action(self, chain: Command, state: ReplState, cmd: str):
|
|
138
|
+
if state.sts:
|
|
139
|
+
return True, chain.run(f'cql {cmd}', state)
|
|
140
|
+
|
|
141
|
+
return False, None
|
|
142
|
+
|
|
143
|
+
def enter(self, state: ReplState):
|
|
144
|
+
auto_enter = Config().get('repl.c.auto-enter', 'cluster')
|
|
145
|
+
if auto_enter and auto_enter in ['cluster', 'first-pod']:
|
|
146
|
+
sts = StatefulSets.list_sts_name_and_ns()
|
|
147
|
+
if not sts:
|
|
148
|
+
log2("No Cassandra clusters found.")
|
|
149
|
+
elif not state.sts and len(sts) == 1:
|
|
150
|
+
cluster = sts[0]
|
|
151
|
+
state.sts = cluster[0]
|
|
152
|
+
state.namespace = cluster[1]
|
|
153
|
+
if auto_enter == 'first-pod':
|
|
154
|
+
state.pod = f'{state.sts}-0'
|
|
155
|
+
if KubeContext().in_cluster_namespace:
|
|
156
|
+
wait_log(f'Moving to the only Cassandra cluster: {state.sts}...')
|
|
157
|
+
else:
|
|
158
|
+
wait_log(f'Moving to the only Cassandra cluster: {state.sts}@{state.namespace}...')
|
|
159
|
+
|
|
160
|
+
def show_tables(self, state: ReplState):
|
|
161
|
+
log(lines_to_tabular(cassandra_table_names(state), separator=','))
|
|
162
|
+
|
|
163
|
+
def show_table_preview(self, state: ReplState, table: str, rows: int):
|
|
164
|
+
with cassandra(state) as pods:
|
|
165
|
+
pods.cql(f'select * from {table} limit {rows}', show_out=True, use_single_quotes=True, on_any=True)
|
|
166
|
+
|
|
167
|
+
def bash_target_changed(self, s0: ReplState, s1: ReplState):
|
|
168
|
+
return s0.sts != s1.sts or s0.pod != s1.pod
|
|
169
|
+
|
|
170
|
+
def exec_no_dir(self, command: str, state: ReplState):
|
|
171
|
+
with cassandra(state) as pods:
|
|
172
|
+
return pods.exec(command, action='bash', show_out=True, shell='bash')
|
|
173
|
+
|
|
174
|
+
def exec_with_dir(self, command: str, session_just_created: bool, state: ReplState):
|
|
175
|
+
with cassandra(state) as pods:
|
|
176
|
+
return pods.exec(command, action='bash', show_out=not session_just_created, shell='bash')
|
|
177
|
+
|
|
178
|
+
def bash_completion(self, cmd: str, state: ReplState, default: dict = {}):
|
|
179
|
+
completions = {cmd: BashCompleter(lambda: [])}
|
|
180
|
+
|
|
181
|
+
if state.sts and state.namespace:
|
|
182
|
+
completions |= {f'@{p}': {cmd: BashCompleter(lambda: [])} for p in StatefulSets.pod_names(state.sts, state.namespace)}
|
|
183
|
+
|
|
184
|
+
return completions
|
|
185
|
+
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.devices.device import Device
|
|
3
|
+
from adam.commands.export.export_databases import ExportDatabases
|
|
4
|
+
from adam.config import Config
|
|
5
|
+
from adam.repl_state import ReplState
|
|
6
|
+
from adam.utils import lines_to_tabular, log, log2, wait_log
|
|
7
|
+
|
|
8
|
+
class DeviceExport(Command, Device):
|
|
9
|
+
COMMAND = f'{ReplState.X}:'
|
|
10
|
+
|
|
11
|
+
# the singleton pattern
|
|
12
|
+
def __new__(cls, *args, **kwargs):
|
|
13
|
+
if not hasattr(cls, 'instance'): cls.instance = super(DeviceExport, 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 DeviceExport.COMMAND
|
|
22
|
+
|
|
23
|
+
def run(self, cmd: str, state: ReplState):
|
|
24
|
+
if not self.args(cmd):
|
|
25
|
+
return super().run(cmd, state)
|
|
26
|
+
|
|
27
|
+
state.device = ReplState.X
|
|
28
|
+
|
|
29
|
+
return state
|
|
30
|
+
|
|
31
|
+
def completion(self, state: ReplState):
|
|
32
|
+
return super().completion(state)
|
|
33
|
+
|
|
34
|
+
def help(self, _: ReplState):
|
|
35
|
+
return f'{DeviceExport.COMMAND}\t move to Export Database Operations device'
|
|
36
|
+
|
|
37
|
+
def ls(self, cmd: str, state: ReplState):
|
|
38
|
+
if state.export_session:
|
|
39
|
+
self.show_export_tables(state.export_session)
|
|
40
|
+
else:
|
|
41
|
+
self.show_export_databases()
|
|
42
|
+
|
|
43
|
+
def show_export_databases(self, importer: str = None):
|
|
44
|
+
lines = [f'{k}\t{v}' for k, v in ExportDatabases.database_names_with_keyspace_cnt(importer).items()]
|
|
45
|
+
log(lines_to_tabular(lines, 'NAME\tKEYSPACES', separator='\t'))
|
|
46
|
+
|
|
47
|
+
def show_export_tables(self, export_session: str):
|
|
48
|
+
log(lines_to_tabular(ExportDatabases.table_names(export_session), 'NAME', separator=','))
|
|
49
|
+
|
|
50
|
+
def cd(self, dir: str, state: ReplState):
|
|
51
|
+
if dir in ['', '..']:
|
|
52
|
+
state.export_session = None
|
|
53
|
+
else:
|
|
54
|
+
state.export_session = dir
|
|
55
|
+
|
|
56
|
+
def cd_completion(self, cmd: str, state: ReplState, default: dict = {}):
|
|
57
|
+
if state.export_session:
|
|
58
|
+
return {cmd: {'..': None} | {n: None for n in ExportDatabases.database_names()}}
|
|
59
|
+
else:
|
|
60
|
+
return {cmd: {n: None for n in ExportDatabases.database_names()}}
|
|
61
|
+
|
|
62
|
+
def pwd(self, state: ReplState):
|
|
63
|
+
words = []
|
|
64
|
+
|
|
65
|
+
if state.export_session:
|
|
66
|
+
words.append(state.export_session)
|
|
67
|
+
|
|
68
|
+
return '\t'.join([f'{ReplState.X}:>'] + (words if words else ['/']))
|
|
69
|
+
|
|
70
|
+
def try_fallback_action(self, chain: Command, state: ReplState, cmd: str):
|
|
71
|
+
result = chain.run(f'.{cmd}', state)
|
|
72
|
+
if type(result) is ReplState:
|
|
73
|
+
if state.export_session and not result.export_session:
|
|
74
|
+
state.export_session = None
|
|
75
|
+
|
|
76
|
+
return True, result
|
|
77
|
+
|
|
78
|
+
def enter(self, state: ReplState):
|
|
79
|
+
if auto_enter := Config().get('repl.x.auto-enter', 'no'):
|
|
80
|
+
if auto_enter == 'latest':
|
|
81
|
+
wait_log(f'Moving to the latest export database...')
|
|
82
|
+
if dbs := ExportDatabases.database_names():
|
|
83
|
+
state.export_session = sorted(dbs)[-1]
|
|
84
|
+
else:
|
|
85
|
+
log2('No export database found.')
|
|
86
|
+
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
from adam.commands.bash.bash_completer import BashCompleter
|
|
2
|
+
from adam.commands.command import Command, InvalidState
|
|
3
|
+
from adam.commands.devices.device import Device
|
|
4
|
+
from adam.commands.postgres.postgres_context import PostgresContext
|
|
5
|
+
from adam.commands.postgres.utils_postgres import pg_database_names, pg_table_names, postgres
|
|
6
|
+
from adam.repl_state import ReplState
|
|
7
|
+
from adam.utils import lines_to_tabular, log, log2, wait_log
|
|
8
|
+
from adam.utils_k8s.pods import Pods
|
|
9
|
+
|
|
10
|
+
class DevicePostgres(Command, Device):
|
|
11
|
+
COMMAND = f'{ReplState.P}:'
|
|
12
|
+
|
|
13
|
+
# the singleton pattern
|
|
14
|
+
def __new__(cls, *args, **kwargs):
|
|
15
|
+
if not hasattr(cls, 'instance'): cls.instance = super(DevicePostgres, 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 DevicePostgres.COMMAND
|
|
24
|
+
|
|
25
|
+
def run(self, cmd: str, state: ReplState):
|
|
26
|
+
if not self.args(cmd):
|
|
27
|
+
return super().run(cmd, state)
|
|
28
|
+
|
|
29
|
+
state.device = ReplState.P
|
|
30
|
+
|
|
31
|
+
return state
|
|
32
|
+
|
|
33
|
+
def completion(self, state: ReplState):
|
|
34
|
+
return super().completion(state)
|
|
35
|
+
|
|
36
|
+
def help(self, _: ReplState):
|
|
37
|
+
return f'{DevicePostgres.COMMAND}\t move to Postgres Operations device'
|
|
38
|
+
|
|
39
|
+
def ls(self, cmd: str, state: ReplState):
|
|
40
|
+
if state.pg_path:
|
|
41
|
+
pg: PostgresContext = PostgresContext.apply(state.namespace, state.pg_path)
|
|
42
|
+
if pg.db:
|
|
43
|
+
self.show_pg_tables(pg)
|
|
44
|
+
else:
|
|
45
|
+
self.show_pg_databases(pg)
|
|
46
|
+
else:
|
|
47
|
+
self.show_pg_hosts(state)
|
|
48
|
+
|
|
49
|
+
def cat(self, cmd: str, state: ReplState):
|
|
50
|
+
if state.pod:
|
|
51
|
+
return self.bash(state, state, cmd.split(' '))
|
|
52
|
+
|
|
53
|
+
return InvalidState()
|
|
54
|
+
|
|
55
|
+
def show_pg_hosts(self, state: ReplState):
|
|
56
|
+
if state.namespace:
|
|
57
|
+
def line(pg: PostgresContext):
|
|
58
|
+
return f'{pg.path()},{pg.endpoint()}:{pg.port()},{pg.username()},{pg.password()}'
|
|
59
|
+
|
|
60
|
+
lines = [line(PostgresContext.apply(state.namespace, pg)) for pg in PostgresContext.hosts(state.namespace)]
|
|
61
|
+
|
|
62
|
+
log(lines_to_tabular(lines, 'NAME,ENDPOINT,USERNAME,PASSWORD', separator=','))
|
|
63
|
+
else:
|
|
64
|
+
def line(pg: PostgresContext):
|
|
65
|
+
return f'{pg.path()},{pg.namespace},{pg.endpoint()}:{pg.port()},{pg.username()},{pg.password()}'
|
|
66
|
+
|
|
67
|
+
lines = [line(PostgresContext.apply(state.namespace, pg)) for pg in PostgresContext.hosts(state.namespace)]
|
|
68
|
+
|
|
69
|
+
log(lines_to_tabular(lines, 'NAME,NAMESPACE,ENDPOINT,USERNAME,PASSWORD', separator=','))
|
|
70
|
+
|
|
71
|
+
def show_pg_databases(self, pg: PostgresContext):
|
|
72
|
+
log(lines_to_tabular(pg_database_names(pg.namespace, pg.path()), 'DATABASE', separator=','))
|
|
73
|
+
|
|
74
|
+
def show_pg_tables(self, pg: PostgresContext):
|
|
75
|
+
log(lines_to_tabular(pg_table_names(pg.namespace, pg.path()), 'NAME', separator=','))
|
|
76
|
+
|
|
77
|
+
def cd(self, dir: str, state: ReplState):
|
|
78
|
+
if dir == '':
|
|
79
|
+
state.pg_path = None
|
|
80
|
+
else:
|
|
81
|
+
context: PostgresContext = PostgresContext.apply(state.namespace, state.pg_path, arg=dir)
|
|
82
|
+
# patch up state.namespace from pg cd
|
|
83
|
+
if not state.namespace and context.namespace:
|
|
84
|
+
state.namespace = context.namespace
|
|
85
|
+
state.pg_path = context.path()
|
|
86
|
+
|
|
87
|
+
def cd_completion(self, cmd: str, state: ReplState, default: dict = {}):
|
|
88
|
+
pg: PostgresContext = PostgresContext.apply(state.namespace, state.pg_path) if state.pg_path else None
|
|
89
|
+
if pg and pg.db:
|
|
90
|
+
return {cmd: {'..': None}}
|
|
91
|
+
elif pg and pg.host:
|
|
92
|
+
return {cmd: {'..': None} | {p: None for p in pg_database_names(state.namespace, pg.path())}}
|
|
93
|
+
else:
|
|
94
|
+
return {cmd: {p: None for p in PostgresContext.hosts(state.namespace)}}
|
|
95
|
+
|
|
96
|
+
def pwd(self, state: ReplState):
|
|
97
|
+
words = []
|
|
98
|
+
|
|
99
|
+
pg: PostgresContext = PostgresContext.apply(state.namespace, state.pg_path)
|
|
100
|
+
|
|
101
|
+
if pg.host:
|
|
102
|
+
words.append(f'host/{pg.host}')
|
|
103
|
+
if pg.db:
|
|
104
|
+
words.append(f'database/{pg.db}')
|
|
105
|
+
|
|
106
|
+
return '\t'.join([f'{ReplState.P}:>'] + (words if words else ['/']))
|
|
107
|
+
|
|
108
|
+
def try_fallback_action(self, chain: Command, state: ReplState, cmd: str):
|
|
109
|
+
pg: PostgresContext = PostgresContext.apply(state.namespace, state.pg_path)
|
|
110
|
+
if pg.db:
|
|
111
|
+
return True, chain.run(f'pg {cmd}', state)
|
|
112
|
+
|
|
113
|
+
return False, None
|
|
114
|
+
|
|
115
|
+
def enter(self, _: ReplState):
|
|
116
|
+
wait_log('Inspecting postgres database instances...')
|
|
117
|
+
|
|
118
|
+
def show_tables(self, state: ReplState):
|
|
119
|
+
pg = PostgresContext.apply(state.namespace, state.pg_path)
|
|
120
|
+
lines = [db["name"] for db in pg.tables() if db["schema"] == PostgresContext.default_schema()]
|
|
121
|
+
log(lines_to_tabular(lines, separator=','))
|
|
122
|
+
|
|
123
|
+
def show_table_preview(self, state: ReplState, table: str, rows: int):
|
|
124
|
+
PostgresContext.apply(state.namespace, state.pg_path).run_sql(f'select * from {table} limit {rows}')
|
|
125
|
+
|
|
126
|
+
def bash(self, s0: ReplState, s1: ReplState, args: list[str]):
|
|
127
|
+
pod, container = PostgresContext.pod_and_container(s1.namespace)
|
|
128
|
+
log2(f'Running on {pod}(container:{container})...')
|
|
129
|
+
|
|
130
|
+
return super().bash(s0, s1, args)
|
|
131
|
+
|
|
132
|
+
def bash_target_changed(self, s0: ReplState, s1: ReplState):
|
|
133
|
+
return s0.pg_path != s1.pg_path
|
|
134
|
+
|
|
135
|
+
def exec_no_dir(self, command: str, state: ReplState):
|
|
136
|
+
with postgres(state) as pod:
|
|
137
|
+
return pod.exec(command, show_out=True)
|
|
138
|
+
|
|
139
|
+
def exec_with_dir(self, command: str, session_just_created: bool, state: ReplState):
|
|
140
|
+
with postgres(state) as pod:
|
|
141
|
+
return pod.exec(command, show_out=not session_just_created)
|
|
142
|
+
|
|
143
|
+
def bash_completion(self, cmd: str, state: ReplState, default: dict = {}):
|
|
144
|
+
return {cmd: BashCompleter(lambda: [])}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from adam.commands.devices.device import Device
|
|
2
|
+
from adam.commands.devices.device_app import DeviceApp
|
|
3
|
+
from adam.commands.devices.device_auit_log import DeviceAuditLog
|
|
4
|
+
from adam.commands.devices.device_cass import DeviceCass
|
|
5
|
+
from adam.commands.devices.device_export import DeviceExport
|
|
6
|
+
from adam.commands.devices.device_postgres import DevicePostgres
|
|
7
|
+
from adam.repl_state import ReplState
|
|
8
|
+
|
|
9
|
+
class Devices:
|
|
10
|
+
def device(state: ReplState) -> Device:
|
|
11
|
+
if state.device == ReplState.A:
|
|
12
|
+
return DeviceApp()
|
|
13
|
+
elif state.device == ReplState.C:
|
|
14
|
+
return DeviceCass()
|
|
15
|
+
elif state.device == ReplState.L:
|
|
16
|
+
return DeviceAuditLog()
|
|
17
|
+
elif state.device == ReplState.P:
|
|
18
|
+
return DevicePostgres()
|
|
19
|
+
elif state.device == ReplState.X:
|
|
20
|
+
return DeviceExport()
|
|
21
|
+
|
|
22
|
+
return DeviceCass()
|
|
23
|
+
|
|
24
|
+
def all():
|
|
25
|
+
return [DeviceApp(), DeviceCass(), DeviceAuditLog(), DevicePostgres(), DeviceExport()]
|
adam/commands/exit.py
CHANGED
|
@@ -23,10 +23,7 @@ class Exit(Command):
|
|
|
23
23
|
exit()
|
|
24
24
|
|
|
25
25
|
def completion(self, state: ReplState):
|
|
26
|
-
|
|
27
|
-
return {Exit.COMMAND: None}
|
|
28
|
-
|
|
29
|
-
return {}
|
|
26
|
+
return {Exit.COMMAND: None}
|
|
30
27
|
|
|
31
28
|
def help(self, _: ReplState):
|
|
32
29
|
return f'{Exit.COMMAND}\t exit kaqing <Ctrl-D>'
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.export.exporter import Exporter
|
|
3
|
+
from adam.repl_state import ReplState, RequiredState
|
|
4
|
+
|
|
5
|
+
class CleanUpAllExportSessions(Command):
|
|
6
|
+
COMMAND = 'clean up all export sessions'
|
|
7
|
+
|
|
8
|
+
# the singleton pattern
|
|
9
|
+
def __new__(cls, *args, **kwargs):
|
|
10
|
+
if not hasattr(cls, 'instance'): cls.instance = super(CleanUpAllExportSessions, cls).__new__(cls)
|
|
11
|
+
|
|
12
|
+
return cls.instance
|
|
13
|
+
|
|
14
|
+
def __init__(self, successor: Command=None):
|
|
15
|
+
super().__init__(successor)
|
|
16
|
+
|
|
17
|
+
def command(self):
|
|
18
|
+
return CleanUpAllExportSessions.COMMAND
|
|
19
|
+
|
|
20
|
+
def required(self):
|
|
21
|
+
return RequiredState.CLUSTER_OR_POD
|
|
22
|
+
|
|
23
|
+
def run(self, cmd: str, state: ReplState):
|
|
24
|
+
if not(args := self.args(cmd)):
|
|
25
|
+
return super().run(cmd, state)
|
|
26
|
+
|
|
27
|
+
with self.validate(args, state) as (args, state):
|
|
28
|
+
if Exporter.clean_up_all_sessions(state.sts, state.pod, state.namespace):
|
|
29
|
+
Exporter.clear_export_session_cache()
|
|
30
|
+
|
|
31
|
+
return state
|
|
32
|
+
|
|
33
|
+
def completion(self, _: ReplState):
|
|
34
|
+
return {}
|
|
35
|
+
|
|
36
|
+
def help(self, _: ReplState):
|
|
37
|
+
return f'{CleanUpAllExportSessions.COMMAND}\t clean up all export sessions'
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.export.exporter import Exporter
|
|
3
|
+
from adam.repl_state import ReplState, RequiredState
|
|
4
|
+
from adam.utils import log, log2
|
|
5
|
+
|
|
6
|
+
class CleanUpExportSessions(Command):
|
|
7
|
+
COMMAND = 'clean up export sessions'
|
|
8
|
+
|
|
9
|
+
# the singleton pattern
|
|
10
|
+
def __new__(cls, *args, **kwargs):
|
|
11
|
+
if not hasattr(cls, 'instance'): cls.instance = super(CleanUpExportSessions, cls).__new__(cls)
|
|
12
|
+
|
|
13
|
+
return cls.instance
|
|
14
|
+
|
|
15
|
+
def __init__(self, successor: Command=None):
|
|
16
|
+
super().__init__(successor)
|
|
17
|
+
|
|
18
|
+
def command(self):
|
|
19
|
+
return CleanUpExportSessions.COMMAND
|
|
20
|
+
|
|
21
|
+
def required(self):
|
|
22
|
+
return RequiredState.CLUSTER_OR_POD
|
|
23
|
+
|
|
24
|
+
def run(self, cmd: str, state: ReplState):
|
|
25
|
+
if not(args := self.args(cmd)):
|
|
26
|
+
return super().run(cmd, state)
|
|
27
|
+
|
|
28
|
+
with self.validate(args, state) as (args, state):
|
|
29
|
+
if not args:
|
|
30
|
+
if state.in_repl:
|
|
31
|
+
log2('Specify export session name.')
|
|
32
|
+
else:
|
|
33
|
+
log2('* Session name is missing.')
|
|
34
|
+
|
|
35
|
+
Command.display_help()
|
|
36
|
+
|
|
37
|
+
return 'command-missing'
|
|
38
|
+
|
|
39
|
+
sessions = [arg.strip(' ') for arg in ' '.join(args).split(',')]
|
|
40
|
+
csv_cnt, log_cnt = Exporter.clean_up_sessions(state.sts, state.pod, state.namespace, sessions)
|
|
41
|
+
log(f'Removed {csv_cnt} csv and {log_cnt} log files.')
|
|
42
|
+
|
|
43
|
+
Exporter.clear_export_session_cache()
|
|
44
|
+
|
|
45
|
+
return state
|
|
46
|
+
|
|
47
|
+
def completion(self, _: ReplState):
|
|
48
|
+
return {}
|
|
49
|
+
|
|
50
|
+
def help(self, _: ReplState):
|
|
51
|
+
return f'{CleanUpExportSessions.COMMAND} <export-session-name>\t clean up export session'
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.export.exporter import Exporter
|
|
3
|
+
from adam.repl_state import ReplState
|
|
4
|
+
from adam.utils import log2
|
|
5
|
+
from adam.utils_athena import Athena
|
|
6
|
+
from adam.utils_sqlite import SQLite
|
|
7
|
+
|
|
8
|
+
class DropExportDatabase(Command):
|
|
9
|
+
COMMAND = 'drop export database'
|
|
10
|
+
|
|
11
|
+
# the singleton pattern
|
|
12
|
+
def __new__(cls, *args, **kwargs):
|
|
13
|
+
if not hasattr(cls, 'instance'): cls.instance = super(DropExportDatabase, 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 DropExportDatabase.COMMAND
|
|
22
|
+
|
|
23
|
+
def required(self):
|
|
24
|
+
return [ReplState.C, ReplState.X]
|
|
25
|
+
|
|
26
|
+
def run(self, cmd: str, state: ReplState):
|
|
27
|
+
if not(args := self.args(cmd)):
|
|
28
|
+
return super().run(cmd, state)
|
|
29
|
+
|
|
30
|
+
with self.validate(args, state) as (args, state):
|
|
31
|
+
if not len(args):
|
|
32
|
+
if state.in_repl:
|
|
33
|
+
log2('Database name is required.')
|
|
34
|
+
log2()
|
|
35
|
+
else:
|
|
36
|
+
log2('* Database name is missing.')
|
|
37
|
+
Command.display_help()
|
|
38
|
+
|
|
39
|
+
return 'command-missing'
|
|
40
|
+
|
|
41
|
+
Exporter.drop_databases(state.sts, state.pod, state.namespace, args[0])
|
|
42
|
+
|
|
43
|
+
SQLite.clear_cache()
|
|
44
|
+
Athena.clear_cache()
|
|
45
|
+
|
|
46
|
+
if state.export_session == args[0]:
|
|
47
|
+
state.export_session = None
|
|
48
|
+
|
|
49
|
+
return state
|
|
50
|
+
|
|
51
|
+
def completion(self, _: ReplState):
|
|
52
|
+
return {}
|
|
53
|
+
|
|
54
|
+
def help(self, _: ReplState):
|
|
55
|
+
return f'{DropExportDatabase.COMMAND} <export-database-name>\t drop export database'
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.export.exporter import Exporter
|
|
3
|
+
from adam.repl_state import ReplState
|
|
4
|
+
from adam.utils_athena import Athena
|
|
5
|
+
from adam.utils_sqlite import SQLite
|
|
6
|
+
|
|
7
|
+
class DropExportDatabases(Command):
|
|
8
|
+
COMMAND = 'drop all export databases'
|
|
9
|
+
|
|
10
|
+
# the singleton pattern
|
|
11
|
+
def __new__(cls, *args, **kwargs):
|
|
12
|
+
if not hasattr(cls, 'instance'): cls.instance = super(DropExportDatabases, 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 DropExportDatabases.COMMAND
|
|
21
|
+
|
|
22
|
+
def required(self):
|
|
23
|
+
return [ReplState.C, ReplState.X]
|
|
24
|
+
|
|
25
|
+
def run(self, cmd: str, state: ReplState):
|
|
26
|
+
if not(args := self.args(cmd)):
|
|
27
|
+
return super().run(cmd, state)
|
|
28
|
+
|
|
29
|
+
with self.validate(args, state) as (args, state):
|
|
30
|
+
Exporter.drop_databases(state.sts, state.pod, state.namespace)
|
|
31
|
+
|
|
32
|
+
SQLite.clear_cache()
|
|
33
|
+
Athena.clear_cache()
|
|
34
|
+
|
|
35
|
+
state.export_session = None
|
|
36
|
+
|
|
37
|
+
return state
|
|
38
|
+
|
|
39
|
+
def completion(self, _: ReplState):
|
|
40
|
+
return {}
|
|
41
|
+
|
|
42
|
+
def help(self, _: ReplState):
|
|
43
|
+
return f'{DropExportDatabases.COMMAND}\t drop all export databases'
|