kaqing 2.0.145__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 +22 -23
- 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 -13
- adam/commands/audit/utils_show_top10.py +2 -3
- adam/commands/bash/__init__.py +5 -0
- adam/commands/bash/bash.py +7 -104
- adam/commands/bash/utils_bash.py +16 -0
- adam/commands/cat.py +13 -19
- adam/commands/cd.py +8 -10
- adam/commands/check.py +20 -21
- adam/commands/cli_commands.py +2 -3
- adam/commands/code.py +20 -23
- adam/commands/command.py +120 -39
- adam/commands/commands_utils.py +8 -17
- adam/commands/cp.py +33 -39
- adam/commands/cql/cql_completions.py +9 -4
- adam/commands/cql/cqlsh.py +10 -30
- adam/commands/cql/{cql_utils.py → utils_cql.py} +149 -15
- 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 +64 -68
- adam/commands/deploy/undeploy.py +4 -27
- adam/commands/deploy/undeploy_frontend.py +4 -7
- adam/commands/deploy/undeploy_pg_agent.py +4 -7
- adam/commands/deploy/undeploy_pod.py +9 -12
- adam/commands/devices/device.py +93 -2
- adam/commands/devices/device_app.py +37 -10
- adam/commands/devices/device_auit_log.py +8 -2
- adam/commands/devices/device_cass.py +47 -7
- adam/commands/devices/device_export.py +2 -2
- adam/commands/devices/device_postgres.py +41 -6
- 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 +18 -7
- adam/commands/export/drop_export_database.py +15 -18
- adam/commands/export/drop_export_databases.py +6 -9
- adam/commands/export/export.py +8 -38
- adam/commands/export/export_databases.py +16 -12
- adam/commands/export/export_handlers.py +71 -0
- adam/commands/export/export_select.py +33 -24
- adam/commands/export/export_use.py +12 -15
- adam/commands/export/exporter.py +37 -48
- adam/commands/export/import_session.py +4 -32
- adam/commands/export/importer_athena.py +4 -7
- adam/commands/export/importer_sqlite.py +19 -27
- adam/commands/export/show_column_counts.py +13 -22
- adam/commands/export/show_export_databases.py +3 -6
- adam/commands/export/show_export_session.py +10 -13
- adam/commands/export/show_export_sessions.py +8 -11
- adam/commands/export/utils_export.py +24 -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 +8 -9
- 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 +29 -37
- adam/commands/postgres/postgres_context.py +47 -23
- 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 +13 -16
- 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 -26
- 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 +4 -16
- adam/embedded_params.py +1 -1
- adam/log.py +4 -4
- adam/pod_exec_result.py +3 -3
- adam/repl.py +29 -32
- adam/repl_commands.py +11 -11
- adam/repl_state.py +52 -26
- adam/sql/sql_completer.py +4 -6
- adam/sql/sql_state_machine.py +21 -14
- 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 +393 -33
- adam/utils_athena.py +14 -13
- adam/utils_audits.py +12 -12
- 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 +21 -18
- 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 +14 -76
- 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_repl/state_machine.py +3 -3
- adam/utils_sqlite.py +78 -42
- adam/version.py +1 -1
- {kaqing-2.0.145.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/export/clean_up_export_session.py +0 -53
- 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
- kaqing-2.0.145.dist-info/RECORD +0 -227
- {kaqing-2.0.145.dist-info → kaqing-2.0.172.dist-info}/WHEEL +0 -0
- {kaqing-2.0.145.dist-info → kaqing-2.0.172.dist-info}/entry_points.txt +0 -0
- {kaqing-2.0.145.dist-info → kaqing-2.0.172.dist-info}/top_level.txt +0 -0
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
from adam.commands.bash.
|
|
2
|
-
from adam.commands.command import Command
|
|
1
|
+
from adam.commands.bash.bash_completer import BashCompleter
|
|
2
|
+
from adam.commands.command import Command, InvalidState
|
|
3
3
|
from adam.commands.commands_utils import show_pods, show_rollout
|
|
4
|
+
from adam.commands.cql.utils_cql import cassandra, cassandra_table_names
|
|
4
5
|
from adam.commands.devices.device import Device
|
|
5
6
|
from adam.config import Config
|
|
6
7
|
from adam.repl_state import ReplState
|
|
7
|
-
from adam.utils import lines_to_tabular, log, log2
|
|
8
|
+
from adam.utils import lines_to_tabular, log, log2, wait_log
|
|
8
9
|
from adam.utils_k8s.cassandra_clusters import CassandraClusters
|
|
9
10
|
from adam.utils_k8s.custom_resources import CustomResources
|
|
10
11
|
from adam.utils_k8s.kube_context import KubeContext
|
|
@@ -41,7 +42,7 @@ class DeviceCass(Command, Device):
|
|
|
41
42
|
|
|
42
43
|
def ls(self, cmd: str, state: ReplState):
|
|
43
44
|
if state.pod:
|
|
44
|
-
return
|
|
45
|
+
return self.bash(state, state, cmd.split(' '))
|
|
45
46
|
elif state.sts and state.namespace:
|
|
46
47
|
show_pods(StatefulSets.pods(state.sts, state.namespace), state.namespace, show_namespace=not KubeContext.in_cluster_namespace())
|
|
47
48
|
show_rollout(state.sts, state.namespace)
|
|
@@ -57,6 +58,18 @@ class DeviceCass(Command, Device):
|
|
|
57
58
|
else:
|
|
58
59
|
return {cmd: {n: None for n in StatefulSets.list_sts_names()}}
|
|
59
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
|
+
|
|
60
73
|
def show_statefulsets(self):
|
|
61
74
|
ss = StatefulSets.list_sts_names()
|
|
62
75
|
if len(ss) == 0:
|
|
@@ -101,7 +114,7 @@ class DeviceCass(Command, Device):
|
|
|
101
114
|
if dir in names:
|
|
102
115
|
state.pod = names[dir]
|
|
103
116
|
else:
|
|
104
|
-
|
|
117
|
+
state.pod = dir
|
|
105
118
|
|
|
106
119
|
def cd_completion(self, cmd: str, state: ReplState, default: dict = {}):
|
|
107
120
|
if state.pod:
|
|
@@ -140,6 +153,33 @@ class DeviceCass(Command, Device):
|
|
|
140
153
|
if auto_enter == 'first-pod':
|
|
141
154
|
state.pod = f'{state.sts}-0'
|
|
142
155
|
if KubeContext().in_cluster_namespace:
|
|
143
|
-
|
|
156
|
+
wait_log(f'Moving to the only Cassandra cluster: {state.sts}...')
|
|
144
157
|
else:
|
|
145
|
-
|
|
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
|
+
|
|
@@ -3,7 +3,7 @@ from adam.commands.devices.device import Device
|
|
|
3
3
|
from adam.commands.export.export_databases import ExportDatabases
|
|
4
4
|
from adam.config import Config
|
|
5
5
|
from adam.repl_state import ReplState
|
|
6
|
-
from adam.utils import lines_to_tabular, log, log2
|
|
6
|
+
from adam.utils import lines_to_tabular, log, log2, wait_log
|
|
7
7
|
|
|
8
8
|
class DeviceExport(Command, Device):
|
|
9
9
|
COMMAND = f'{ReplState.X}:'
|
|
@@ -78,7 +78,7 @@ class DeviceExport(Command, Device):
|
|
|
78
78
|
def enter(self, state: ReplState):
|
|
79
79
|
if auto_enter := Config().get('repl.x.auto-enter', 'no'):
|
|
80
80
|
if auto_enter == 'latest':
|
|
81
|
-
|
|
81
|
+
wait_log(f'Moving to the latest export database...')
|
|
82
82
|
if dbs := ExportDatabases.database_names():
|
|
83
83
|
state.export_session = sorted(dbs)[-1]
|
|
84
84
|
else:
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
from adam.commands.
|
|
1
|
+
from adam.commands.bash.bash_completer import BashCompleter
|
|
2
|
+
from adam.commands.command import Command, InvalidState
|
|
2
3
|
from adam.commands.devices.device import Device
|
|
3
4
|
from adam.commands.postgres.postgres_context import PostgresContext
|
|
4
|
-
from adam.commands.postgres.
|
|
5
|
-
from adam.config import Config
|
|
5
|
+
from adam.commands.postgres.utils_postgres import pg_database_names, pg_table_names, postgres
|
|
6
6
|
from adam.repl_state import ReplState
|
|
7
|
-
from adam.utils import lines_to_tabular, log
|
|
7
|
+
from adam.utils import lines_to_tabular, log, log2, wait_log
|
|
8
|
+
from adam.utils_k8s.pods import Pods
|
|
8
9
|
|
|
9
10
|
class DevicePostgres(Command, Device):
|
|
10
11
|
COMMAND = f'{ReplState.P}:'
|
|
@@ -45,6 +46,12 @@ class DevicePostgres(Command, Device):
|
|
|
45
46
|
else:
|
|
46
47
|
self.show_pg_hosts(state)
|
|
47
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
|
+
|
|
48
55
|
def show_pg_hosts(self, state: ReplState):
|
|
49
56
|
if state.namespace:
|
|
50
57
|
def line(pg: PostgresContext):
|
|
@@ -105,5 +112,33 @@ class DevicePostgres(Command, Device):
|
|
|
105
112
|
|
|
106
113
|
return False, None
|
|
107
114
|
|
|
108
|
-
def enter(self,
|
|
109
|
-
|
|
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: [])}
|
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'
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
from adam.commands.command import Command
|
|
2
2
|
from adam.commands.export.exporter import Exporter
|
|
3
3
|
from adam.repl_state import ReplState, RequiredState
|
|
4
|
+
from adam.utils import log, log2
|
|
4
5
|
|
|
5
6
|
class CleanUpExportSessions(Command):
|
|
6
|
-
COMMAND = 'clean up
|
|
7
|
+
COMMAND = 'clean up export sessions'
|
|
7
8
|
|
|
8
9
|
# the singleton pattern
|
|
9
10
|
def __new__(cls, *args, **kwargs):
|
|
@@ -24,17 +25,27 @@ class CleanUpExportSessions(Command):
|
|
|
24
25
|
if not(args := self.args(cmd)):
|
|
25
26
|
return super().run(cmd, state)
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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.')
|
|
30
42
|
|
|
31
|
-
if Exporter.clean_up_all_sessions(state.sts, state.pod, state.namespace):
|
|
32
43
|
Exporter.clear_export_session_cache()
|
|
33
44
|
|
|
34
|
-
|
|
45
|
+
return state
|
|
35
46
|
|
|
36
47
|
def completion(self, _: ReplState):
|
|
37
48
|
return {}
|
|
38
49
|
|
|
39
50
|
def help(self, _: ReplState):
|
|
40
|
-
return f'{CleanUpExportSessions.COMMAND}
|
|
51
|
+
return f'{CleanUpExportSessions.COMMAND} <export-session-name>\t clean up export session'
|
|
@@ -27,29 +27,26 @@ class DropExportDatabase(Command):
|
|
|
27
27
|
if not(args := self.args(cmd)):
|
|
28
28
|
return super().run(cmd, state)
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
else:
|
|
39
|
-
log2('* Database name is missing.')
|
|
40
|
-
Command.display_help()
|
|
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()
|
|
41
38
|
|
|
42
|
-
|
|
39
|
+
return 'command-missing'
|
|
43
40
|
|
|
44
|
-
|
|
41
|
+
Exporter.drop_databases(state.sts, state.pod, state.namespace, args[0])
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
SQLite.clear_cache()
|
|
44
|
+
Athena.clear_cache()
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
if state.export_session == args[0]:
|
|
47
|
+
state.export_session = None
|
|
51
48
|
|
|
52
|
-
|
|
49
|
+
return state
|
|
53
50
|
|
|
54
51
|
def completion(self, _: ReplState):
|
|
55
52
|
return {}
|
|
@@ -26,18 +26,15 @@ class DropExportDatabases(Command):
|
|
|
26
26
|
if not(args := self.args(cmd)):
|
|
27
27
|
return super().run(cmd, state)
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return state
|
|
32
|
-
|
|
33
|
-
Exporter.drop_databases(state.sts, state.pod, state.namespace)
|
|
29
|
+
with self.validate(args, state) as (args, state):
|
|
30
|
+
Exporter.drop_databases(state.sts, state.pod, state.namespace)
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
SQLite.clear_cache()
|
|
33
|
+
Athena.clear_cache()
|
|
37
34
|
|
|
38
|
-
|
|
35
|
+
state.export_session = None
|
|
39
36
|
|
|
40
|
-
|
|
37
|
+
return state
|
|
41
38
|
|
|
42
39
|
def completion(self, _: ReplState):
|
|
43
40
|
return {}
|
adam/commands/export/export.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
from adam.commands import extract_options
|
|
1
2
|
from adam.commands.command import Command
|
|
2
|
-
from adam.commands.cql.
|
|
3
|
+
from adam.commands.cql.utils_cql import cassandra_keyspaces, cassandra_table_names
|
|
3
4
|
from adam.commands.export.export_databases import ExportDatabases
|
|
4
|
-
from adam.commands.export.
|
|
5
|
-
from adam.commands.export.utils_export import ExportSpec
|
|
5
|
+
from adam.commands.export.export_handlers import export
|
|
6
6
|
from adam.repl_state import ReplState, RequiredState
|
|
7
7
|
from adam.sql.sql_completer import SqlCompleter, SqlVariant
|
|
8
8
|
from adam.utils import log
|
|
@@ -30,40 +30,10 @@ class ExportTables(Command):
|
|
|
30
30
|
if not(args := self.args(cmd)):
|
|
31
31
|
return super().run(cmd, state)
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
# --export-only for testing only
|
|
38
|
-
args, export_only = Command.extract_options(args, ['--export-only'])
|
|
39
|
-
|
|
40
|
-
if not state.pod:
|
|
41
|
-
state.push()
|
|
42
|
-
state.pod = StatefulSets.pod_names(state.sts, state.namespace)[0]
|
|
43
|
-
|
|
44
|
-
export_session = state.export_session
|
|
45
|
-
spec: ExportSpec = None
|
|
46
|
-
try:
|
|
47
|
-
statuses, spec = Exporter.export_tables(args, state, export_only=export_only)
|
|
48
|
-
if not statuses:
|
|
49
|
-
return state
|
|
50
|
-
|
|
51
|
-
Exporter.clear_export_session_cache()
|
|
52
|
-
|
|
53
|
-
if spec.importer == 'csv' or export_only:
|
|
54
|
-
ExportDatabases.disply_export_session(state.sts, state.pod, state.namespace, spec.session)
|
|
55
|
-
else:
|
|
56
|
-
log()
|
|
57
|
-
ExportDatabases.display_export_db(state.export_session)
|
|
58
|
-
|
|
59
|
-
finally:
|
|
60
|
-
state.pop()
|
|
61
|
-
|
|
62
|
-
# if exporting to csv, do not bind the new session id to repl state
|
|
63
|
-
if spec and spec.importer == 'csv':
|
|
64
|
-
state.export_session = export_session
|
|
65
|
-
|
|
66
|
-
return state
|
|
33
|
+
with self.validate(args, state) as (args, state):
|
|
34
|
+
with extract_options(args, '--export-only') as (args, export_only):
|
|
35
|
+
with export(state) as exporter:
|
|
36
|
+
return exporter.export(args, export_only=export_only)
|
|
67
37
|
|
|
68
38
|
def completion(self, state: ReplState):
|
|
69
39
|
def sc():
|
|
@@ -74,7 +44,7 @@ class ExportTables(Command):
|
|
|
74
44
|
'export-dbs': lambda: ExportDatabases.database_names(),
|
|
75
45
|
}, variant=SqlVariant.CQL)
|
|
76
46
|
|
|
77
|
-
if state
|
|
47
|
+
if super().completion(state):
|
|
78
48
|
return {f'@{p}': {ExportTables.COMMAND: sc()} for p in StatefulSets.pod_names(state.sts, state.namespace)}
|
|
79
49
|
|
|
80
50
|
return {}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
from collections.abc import Callable
|
|
1
2
|
import os
|
|
2
3
|
import boto3
|
|
3
4
|
|
|
4
5
|
from adam.commands.export.utils_export import ExportTableStatus
|
|
5
6
|
from adam.config import Config
|
|
6
|
-
from adam.
|
|
7
|
+
from adam.repl_session import ReplSession
|
|
8
|
+
from adam.utils import debug, lines_to_tabular, log, log2, ing, log_exc
|
|
7
9
|
from adam.utils_athena import Athena
|
|
8
10
|
from adam.utils_k8s.statefulsets import StatefulSets
|
|
9
11
|
from adam.utils_sqlite import SQLite
|
|
@@ -11,16 +13,23 @@ from adam.utils_sqlite import SQLite
|
|
|
11
13
|
LIKE = 'e%_%'
|
|
12
14
|
|
|
13
15
|
class ExportDatabases:
|
|
14
|
-
def run_query(query: str, database: str, show_query=False) -> int:
|
|
16
|
+
def run_query(query: str, database: str, show_query=False, output: Callable[[str], str] = None) -> int:
|
|
15
17
|
cnt: int = 0
|
|
16
18
|
|
|
17
19
|
if show_query:
|
|
18
20
|
log2(query)
|
|
19
21
|
|
|
22
|
+
log_file = None
|
|
20
23
|
if database.startswith('s'):
|
|
21
|
-
|
|
24
|
+
cnt0, log_file = SQLite.run_query(query, database=database, output=output)
|
|
25
|
+
cnt += cnt0
|
|
22
26
|
else:
|
|
23
|
-
|
|
27
|
+
cnt0, log_file = Athena.run_query(query, database=database, output=output)
|
|
28
|
+
cnt += cnt0
|
|
29
|
+
|
|
30
|
+
if Config().get('repl.history.push-cat-log-file', True):
|
|
31
|
+
if log_file and ReplSession().prompt_session:
|
|
32
|
+
ReplSession().prompt_session.history.append_string(f':sh cat {log_file}')
|
|
24
33
|
|
|
25
34
|
return cnt
|
|
26
35
|
|
|
@@ -47,15 +56,13 @@ class ExportDatabases:
|
|
|
47
56
|
dbs = SQLite.database_names(db)
|
|
48
57
|
if dbs:
|
|
49
58
|
with ing(f'Droping {len(dbs)} SQLite databases'):
|
|
50
|
-
|
|
59
|
+
with log_exc():
|
|
51
60
|
for db in dbs:
|
|
52
61
|
file_path = f'{SQLite.local_db_dir()}/{db}'
|
|
53
62
|
try:
|
|
54
63
|
os.remove(file_path)
|
|
55
64
|
except OSError as e:
|
|
56
65
|
pass
|
|
57
|
-
except:
|
|
58
|
-
pass
|
|
59
66
|
|
|
60
67
|
return dbs
|
|
61
68
|
|
|
@@ -65,20 +72,17 @@ class ExportDatabases:
|
|
|
65
72
|
with ing(f'Droping {len(dbs)} Athena databases'):
|
|
66
73
|
for db in dbs:
|
|
67
74
|
query = f'DROP DATABASE {db} CASCADE'
|
|
68
|
-
|
|
69
|
-
log2(query)
|
|
75
|
+
debug(query)
|
|
70
76
|
Athena.query(query)
|
|
71
77
|
|
|
72
78
|
with ing(f'Deleting s3 folder: export'):
|
|
73
|
-
|
|
79
|
+
with log_exc():
|
|
74
80
|
if not db:
|
|
75
81
|
db = ''
|
|
76
82
|
|
|
77
83
|
s3 = boto3.resource('s3')
|
|
78
84
|
bucket = s3.Bucket(Config().get('export.bucket', 'c3.ops--qing'))
|
|
79
85
|
bucket.objects.filter(Prefix=f'export/{db}').delete()
|
|
80
|
-
except:
|
|
81
|
-
pass
|
|
82
86
|
|
|
83
87
|
return dbs
|
|
84
88
|
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.export.export_databases import ExportDatabases
|
|
3
|
+
from adam.commands.export.exporter import Exporter
|
|
4
|
+
from adam.commands.export.utils_export import ExportSpec, state_with_pod
|
|
5
|
+
from adam.repl_state import ReplState
|
|
6
|
+
from adam.utils import log, log2
|
|
7
|
+
|
|
8
|
+
class ExportService:
|
|
9
|
+
def __init__(self, handler: 'ExporterHandler'):
|
|
10
|
+
self.handler = handler
|
|
11
|
+
|
|
12
|
+
def export(self, args: list[str], export_only=False):
|
|
13
|
+
state = self.handler.state
|
|
14
|
+
export_session = state.export_session
|
|
15
|
+
spec: ExportSpec = None
|
|
16
|
+
try:
|
|
17
|
+
with state_with_pod(state) as state:
|
|
18
|
+
# --export-only for testing only
|
|
19
|
+
statuses, spec = Exporter.export_tables(args, state, export_only=export_only)
|
|
20
|
+
if not statuses:
|
|
21
|
+
return state
|
|
22
|
+
|
|
23
|
+
Exporter.clear_export_session_cache()
|
|
24
|
+
|
|
25
|
+
if spec.importer == 'csv' or export_only:
|
|
26
|
+
ExportDatabases.disply_export_session(state.sts, state.pod, state.namespace, spec.session)
|
|
27
|
+
else:
|
|
28
|
+
log()
|
|
29
|
+
ExportDatabases.display_export_db(state.export_session)
|
|
30
|
+
finally:
|
|
31
|
+
# if exporting to csv, do not bind the new session id to repl state
|
|
32
|
+
if spec and spec.importer == 'csv':
|
|
33
|
+
state.export_session = export_session
|
|
34
|
+
|
|
35
|
+
return state
|
|
36
|
+
|
|
37
|
+
def import_sesion(self, args: list[str]):
|
|
38
|
+
state = self.handler.state
|
|
39
|
+
|
|
40
|
+
if not args:
|
|
41
|
+
if state.in_repl:
|
|
42
|
+
log2('Specify export session name.')
|
|
43
|
+
else:
|
|
44
|
+
log2('* Export session name is missing.')
|
|
45
|
+
|
|
46
|
+
Command.display_help()
|
|
47
|
+
|
|
48
|
+
return 'command-missing'
|
|
49
|
+
|
|
50
|
+
with state_with_pod(state) as state:
|
|
51
|
+
tables, _ = Exporter.import_session(args, state)
|
|
52
|
+
if tables:
|
|
53
|
+
Exporter.clear_export_session_cache()
|
|
54
|
+
|
|
55
|
+
log()
|
|
56
|
+
ExportDatabases.display_export_db(state.export_session)
|
|
57
|
+
|
|
58
|
+
return state
|
|
59
|
+
|
|
60
|
+
class ExporterHandler:
|
|
61
|
+
def __init__(self, state: ReplState):
|
|
62
|
+
self.state = state
|
|
63
|
+
|
|
64
|
+
def __enter__(self):
|
|
65
|
+
return ExportService(self)
|
|
66
|
+
|
|
67
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
68
|
+
return False
|
|
69
|
+
|
|
70
|
+
def export(state: ReplState):
|
|
71
|
+
return ExporterHandler(state)
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from adam.commands import extract_trailing_options
|
|
1
3
|
from adam.commands.command import Command
|
|
2
4
|
from adam.commands.export.export_databases import ExportDatabases
|
|
5
|
+
from adam.config import Config
|
|
3
6
|
from adam.repl_state import ReplState, RequiredState
|
|
4
7
|
from adam.sql.sql_completer import SqlCompleter, SqlVariant
|
|
5
8
|
from adam.utils import log2
|
|
6
9
|
from adam.utils_athena import Athena
|
|
7
|
-
from adam.utils_sqlite import SQLite
|
|
8
10
|
|
|
9
11
|
class ExportSelect(Command):
|
|
10
12
|
COMMAND = '.select'
|
|
@@ -28,38 +30,45 @@ class ExportSelect(Command):
|
|
|
28
30
|
if not(args := self.args(cmd)):
|
|
29
31
|
return super().run(cmd, state)
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
with self.validate(args, state) as (args, state):
|
|
34
|
+
with extract_trailing_options(args, '&') as (args, backgrounded):
|
|
35
|
+
if not state.export_session:
|
|
36
|
+
if state.in_repl:
|
|
37
|
+
if state.device == ReplState.C:
|
|
38
|
+
log2("Select an export database first with 'use' command.")
|
|
39
|
+
else:
|
|
40
|
+
log2('cd to an export database first.')
|
|
41
|
+
else:
|
|
42
|
+
log2('* export database is missing.')
|
|
34
43
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
Command.display_help()
|
|
45
|
+
|
|
46
|
+
return 'command-missing'
|
|
47
|
+
|
|
48
|
+
if not args:
|
|
49
|
+
if state.in_repl:
|
|
50
|
+
log2('Use a SQL statement.')
|
|
51
|
+
else:
|
|
52
|
+
log2('* SQL statement is missing.')
|
|
43
53
|
|
|
44
|
-
|
|
54
|
+
Command.display_help()
|
|
45
55
|
|
|
46
|
-
|
|
56
|
+
return 'command-missing'
|
|
47
57
|
|
|
48
|
-
|
|
49
|
-
if state.in_repl:
|
|
50
|
-
log2('Use a SQL statement.')
|
|
51
|
-
else:
|
|
52
|
-
log2('* SQL statement is missing.')
|
|
58
|
+
query = ' '.join(args)
|
|
53
59
|
|
|
54
|
-
|
|
60
|
+
def output(out: str):
|
|
61
|
+
log_prefix = Config().get('export.log-prefix', '/tmp/qing')
|
|
62
|
+
log_file = f'{log_prefix}-{datetime.now().strftime("%d%H%M%S")}-sqlite.log'
|
|
55
63
|
|
|
56
|
-
|
|
64
|
+
with open(log_file, 'w') as f:
|
|
65
|
+
f.write(out)
|
|
57
66
|
|
|
58
|
-
|
|
67
|
+
return log_file
|
|
59
68
|
|
|
60
|
-
|
|
69
|
+
ExportDatabases.run_query(f'select {query}', database=state.export_session, output=output if backgrounded else None)
|
|
61
70
|
|
|
62
|
-
|
|
71
|
+
return state
|
|
63
72
|
|
|
64
73
|
def completion(self, state: ReplState):
|
|
65
74
|
if not state.export_session:
|