kaqing 2.0.172__py3-none-any.whl → 2.0.186__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 +2 -2
- adam/apps.py +18 -4
- adam/batch.py +1 -1
- adam/checks/check_utils.py +3 -1
- adam/commands/__init__.py +8 -2
- adam/commands/alter_tables.py +24 -35
- adam/commands/app/__init__.py +0 -0
- adam/commands/app/app.py +38 -0
- adam/commands/app/app_ping.py +38 -0
- adam/commands/app/show_app_actions.py +49 -0
- adam/commands/app/show_app_id.py +44 -0
- adam/commands/app/show_app_queues.py +38 -0
- adam/commands/app/utils_app.py +106 -0
- adam/commands/audit/audit.py +9 -27
- adam/commands/audit/audit_repair_tables.py +5 -7
- adam/commands/audit/audit_run.py +1 -1
- adam/commands/audit/completions_l.py +15 -0
- adam/commands/audit/show_last10.py +2 -14
- adam/commands/audit/show_slow10.py +2 -13
- adam/commands/audit/show_top10.py +2 -11
- adam/commands/audit/utils_show_top10.py +14 -1
- adam/commands/bash/bash.py +1 -1
- adam/commands/cat.py +5 -19
- adam/commands/cd.py +6 -8
- adam/commands/check.py +10 -18
- adam/commands/cli_commands.py +6 -1
- adam/commands/{cp.py → clipboard_copy.py} +34 -36
- adam/commands/code.py +2 -2
- adam/commands/command.py +94 -10
- adam/commands/commands_utils.py +19 -12
- adam/commands/cql/completions_c.py +28 -0
- adam/commands/cql/cqlsh.py +3 -7
- adam/commands/cql/utils_cql.py +22 -60
- adam/commands/deploy/deploy_pg_agent.py +2 -2
- adam/commands/deploy/undeploy_pg_agent.py +2 -2
- adam/commands/devices/device.py +39 -8
- adam/commands/devices/device_app.py +19 -29
- adam/commands/devices/device_auit_log.py +3 -3
- adam/commands/devices/device_cass.py +17 -23
- adam/commands/devices/device_export.py +12 -11
- adam/commands/devices/device_postgres.py +79 -63
- adam/commands/download_file.py +47 -0
- adam/commands/export/clean_up_all_export_sessions.py +3 -3
- adam/commands/export/clean_up_export_sessions.py +7 -19
- adam/commands/export/completions_x.py +11 -0
- adam/commands/export/download_export_session.py +40 -0
- adam/commands/export/drop_export_database.py +6 -22
- adam/commands/export/drop_export_databases.py +3 -9
- adam/commands/export/export.py +1 -17
- adam/commands/export/export_databases.py +93 -21
- adam/commands/export/export_select.py +8 -68
- adam/commands/export/export_sessions.py +209 -0
- adam/commands/export/export_use.py +13 -16
- adam/commands/export/export_x_select.py +48 -0
- adam/commands/export/exporter.py +108 -129
- adam/commands/export/import_files.py +44 -0
- adam/commands/export/import_session.py +10 -6
- adam/commands/export/importer.py +19 -5
- adam/commands/export/importer_athena.py +112 -41
- adam/commands/export/importer_sqlite.py +47 -19
- adam/commands/export/show_column_counts.py +11 -20
- adam/commands/export/show_export_databases.py +5 -2
- adam/commands/export/show_export_session.py +6 -15
- adam/commands/export/show_export_sessions.py +4 -11
- adam/commands/export/utils_export.py +46 -16
- adam/commands/find_files.py +51 -0
- adam/commands/find_processes.py +76 -0
- adam/commands/head.py +36 -0
- adam/commands/help.py +2 -2
- adam/commands/intermediate_command.py +6 -3
- adam/commands/ls.py +1 -1
- adam/commands/medusa/medusa_backup.py +13 -16
- adam/commands/medusa/medusa_restore.py +39 -32
- adam/commands/medusa/medusa_show_backupjobs.py +6 -4
- adam/commands/medusa/medusa_show_restorejobs.py +5 -3
- adam/commands/medusa/utils_medusa.py +15 -0
- adam/commands/nodetool.py +3 -8
- adam/commands/param_get.py +10 -12
- adam/commands/param_set.py +7 -10
- adam/commands/postgres/completions_p.py +22 -0
- adam/commands/postgres/postgres.py +25 -40
- adam/commands/postgres/postgres_databases.py +270 -0
- adam/commands/postgres/utils_postgres.py +33 -20
- adam/commands/preview_table.py +4 -2
- adam/commands/pwd.py +3 -3
- adam/commands/reaper/reaper_forward.py +2 -2
- adam/commands/reaper/reaper_run_abort.py +4 -10
- adam/commands/reaper/reaper_runs.py +3 -3
- adam/commands/reaper/reaper_schedule_activate.py +12 -12
- adam/commands/reaper/reaper_schedule_start.py +7 -12
- adam/commands/reaper/reaper_schedule_stop.py +7 -12
- adam/commands/reaper/utils_reaper.py +13 -6
- adam/commands/repair/repair_scan.py +0 -2
- adam/commands/repair/repair_stop.py +0 -1
- adam/commands/shell.py +7 -5
- adam/commands/show/show.py +1 -1
- adam/commands/show/show_adam.py +3 -3
- adam/commands/show/show_cassandra_repairs.py +5 -3
- adam/commands/show/show_cassandra_status.py +27 -20
- adam/commands/show/{show_commands.py → show_cli_commands.py} +2 -2
- adam/commands/show/show_login.py +2 -2
- adam/commands/show/show_params.py +2 -5
- adam/commands/show/show_processes.py +15 -14
- adam/commands/show/show_storage.py +9 -8
- adam/config.py +1 -0
- adam/embedded_params.py +1 -1
- adam/repl.py +20 -11
- adam/repl_commands.py +16 -9
- adam/repl_session.py +8 -1
- adam/repl_state.py +33 -10
- adam/sql/lark_completer.py +280 -0
- adam/sql/lark_parser.py +604 -0
- adam/sql/sql_state_machine.py +8 -2
- adam/utils.py +116 -29
- adam/utils_athena.py +7 -8
- adam/utils_issues.py +2 -2
- adam/utils_k8s/app_clusters.py +2 -2
- adam/utils_k8s/app_pods.py +5 -2
- adam/utils_k8s/cassandra_clusters.py +11 -3
- adam/utils_k8s/cassandra_nodes.py +2 -2
- adam/utils_k8s/k8s.py +14 -5
- adam/utils_k8s/kube_context.py +2 -2
- adam/utils_k8s/pods.py +23 -5
- adam/utils_k8s/statefulsets.py +5 -2
- adam/utils_local.py +4 -0
- adam/utils_repl/appendable_completer.py +6 -0
- adam/utils_repl/repl_completer.py +128 -2
- adam/utils_sqlite.py +14 -14
- adam/version.py +1 -1
- {kaqing-2.0.172.dist-info → kaqing-2.0.186.dist-info}/METADATA +1 -1
- kaqing-2.0.186.dist-info/RECORD +250 -0
- adam/commands/cql/cql_completions.py +0 -33
- adam/commands/export/export_handlers.py +0 -71
- adam/commands/export/export_select_x.py +0 -54
- adam/commands/postgres/postgres_context.py +0 -272
- adam/commands/postgres/psql_completions.py +0 -10
- kaqing-2.0.172.dist-info/RECORD +0 -230
- {kaqing-2.0.172.dist-info → kaqing-2.0.186.dist-info}/WHEEL +0 -0
- {kaqing-2.0.172.dist-info → kaqing-2.0.186.dist-info}/entry_points.txt +0 -0
- {kaqing-2.0.172.dist-info → kaqing-2.0.186.dist-info}/top_level.txt +0 -0
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
from adam.commands.bash.bash_completer import BashCompleter
|
|
2
|
-
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.command import Command
|
|
3
3
|
from adam.commands.devices.device import Device
|
|
4
|
-
from adam.commands.postgres.
|
|
4
|
+
from adam.commands.postgres.postgres_databases import PostgresDatabases, pg_path
|
|
5
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
|
|
8
|
-
from adam.utils_k8s.pods import Pods
|
|
7
|
+
from adam.utils import tabulize, log2, wait_log
|
|
9
8
|
|
|
10
9
|
class DevicePostgres(Command, Device):
|
|
11
10
|
COMMAND = f'{ReplState.P}:'
|
|
@@ -36,79 +35,98 @@ class DevicePostgres(Command, Device):
|
|
|
36
35
|
def help(self, _: ReplState):
|
|
37
36
|
return f'{DevicePostgres.COMMAND}\t move to Postgres Operations device'
|
|
38
37
|
|
|
39
|
-
def
|
|
40
|
-
|
|
41
|
-
|
|
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)
|
|
38
|
+
def pod(self, state: ReplState) -> str:
|
|
39
|
+
pod, _ = PostgresDatabases.pod_and_container(state.namespace)
|
|
40
|
+
return pod
|
|
48
41
|
|
|
49
|
-
def
|
|
50
|
-
|
|
51
|
-
return self.bash(state, state, cmd.split(' '))
|
|
42
|
+
def pod_names(self, state: ReplState) -> list[str]:
|
|
43
|
+
return [self.pod(state)]
|
|
52
44
|
|
|
53
|
-
|
|
45
|
+
def default_container(self, state: ReplState) -> str:
|
|
46
|
+
_, container = PostgresDatabases.pod_and_container(state.namespace)
|
|
47
|
+
return container
|
|
48
|
+
|
|
49
|
+
def ls(self, cmd: str, state: ReplState):
|
|
50
|
+
if state.pod_targetted:
|
|
51
|
+
self.bash(state, state, ['ls'])
|
|
52
|
+
return
|
|
53
|
+
|
|
54
|
+
with pg_path(state) as (host, database):
|
|
55
|
+
if database:
|
|
56
|
+
tabulize(pg_table_names(state), header='NAME', separator=',')
|
|
57
|
+
elif host:
|
|
58
|
+
tabulize(pg_database_names(state), header='DATABASE', separator=',')
|
|
59
|
+
else:
|
|
60
|
+
self.show_pg_hosts(state)
|
|
54
61
|
|
|
55
62
|
def show_pg_hosts(self, state: ReplState):
|
|
56
63
|
if state.namespace:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
log(lines_to_tabular(lines, 'NAME,ENDPOINT,USERNAME,PASSWORD', separator=','))
|
|
64
|
+
tabulize(PostgresDatabases.hosts(state),
|
|
65
|
+
lambda p: f'{p.host},{p.endpoint()}:{p.port()},{p.username()},{p.password()}',
|
|
66
|
+
header='NAME,ENDPOINT,USERNAME,PASSWORD',
|
|
67
|
+
separator=',')
|
|
63
68
|
else:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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=','))
|
|
69
|
+
tabulize(PostgresDatabases.hosts(state),
|
|
70
|
+
lambda p: f'{p.host},{p.namespace},{p.endpoint()}:{p.port()},{p.username()},{p.password()}',
|
|
71
|
+
header='NAME,NAMESPACE,ENDPOINT,USERNAME,PASSWORD',
|
|
72
|
+
separator=',')
|
|
76
73
|
|
|
77
74
|
def cd(self, dir: str, state: ReplState):
|
|
78
75
|
if dir == '':
|
|
79
76
|
state.pg_path = None
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if
|
|
84
|
-
|
|
85
|
-
|
|
77
|
+
return
|
|
78
|
+
|
|
79
|
+
with pg_path(state) as (host, database):
|
|
80
|
+
if dir == '..':
|
|
81
|
+
if database:
|
|
82
|
+
database = None
|
|
83
|
+
else:
|
|
84
|
+
host = None
|
|
85
|
+
else:
|
|
86
|
+
tks = dir.split('@')
|
|
87
|
+
if not host:
|
|
88
|
+
host = tks[0]
|
|
89
|
+
else:
|
|
90
|
+
database = tks[0]
|
|
91
|
+
|
|
92
|
+
if len(tks) > 1:
|
|
93
|
+
state.namespace = tks[1]
|
|
94
|
+
|
|
95
|
+
if database:
|
|
96
|
+
state.pg_path = f'{host}/{database}'
|
|
97
|
+
else:
|
|
98
|
+
state.pg_path = host
|
|
86
99
|
|
|
87
100
|
def cd_completion(self, cmd: str, state: ReplState, default: dict = {}):
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
101
|
+
return {cmd: {d: None for d in self.direct_dirs(cmd, state, default=default)}}
|
|
102
|
+
|
|
103
|
+
def direct_dirs(self, cmd: str, state: ReplState, default: dict = {}) -> list[str]:
|
|
104
|
+
with pg_path(state) as (host, database):
|
|
105
|
+
if database:
|
|
106
|
+
return ['..']
|
|
107
|
+
elif host:
|
|
108
|
+
return ['..'] + [p for p in pg_database_names(state)]
|
|
109
|
+
else:
|
|
110
|
+
return [p for p in PostgresDatabases.host_names(state.namespace)]
|
|
95
111
|
|
|
96
112
|
def pwd(self, state: ReplState):
|
|
97
113
|
words = []
|
|
98
114
|
|
|
99
|
-
|
|
115
|
+
with pg_path(state) as (host, database):
|
|
116
|
+
if host:
|
|
117
|
+
words.append(f'host/{host}')
|
|
118
|
+
if database:
|
|
119
|
+
words.append(f'database/{database}')
|
|
100
120
|
|
|
101
|
-
|
|
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 ['/']))
|
|
121
|
+
return '\t'.join([f'{ReplState.P}:>'] + (words if words else ['/']))
|
|
107
122
|
|
|
108
123
|
def try_fallback_action(self, chain: Command, state: ReplState, cmd: str):
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
124
|
+
with pg_path(state) as (_, database):
|
|
125
|
+
if not database:
|
|
126
|
+
database = PostgresDatabases.default_db()
|
|
127
|
+
|
|
128
|
+
if database:
|
|
129
|
+
return True, chain.run(f'pg {cmd}', state)
|
|
112
130
|
|
|
113
131
|
return False, None
|
|
114
132
|
|
|
@@ -116,15 +134,13 @@ class DevicePostgres(Command, Device):
|
|
|
116
134
|
wait_log('Inspecting postgres database instances...')
|
|
117
135
|
|
|
118
136
|
def show_tables(self, state: ReplState):
|
|
119
|
-
|
|
120
|
-
lines = [db["name"] for db in pg.tables() if db["schema"] == PostgresContext.default_schema()]
|
|
121
|
-
log(lines_to_tabular(lines, separator=','))
|
|
137
|
+
tabulize(PostgresDatabases.tables(state, default_schema=True), lambda d: d['name'], separator=',')
|
|
122
138
|
|
|
123
139
|
def show_table_preview(self, state: ReplState, table: str, rows: int):
|
|
124
|
-
|
|
140
|
+
PostgresDatabases.run_sql(state, f'select * from {table} limit {rows}')
|
|
125
141
|
|
|
126
142
|
def bash(self, s0: ReplState, s1: ReplState, args: list[str]):
|
|
127
|
-
pod, container =
|
|
143
|
+
pod, container = PostgresDatabases.pod_and_container(s1.namespace)
|
|
128
144
|
log2(f'Running on {pod}(container:{container})...')
|
|
129
145
|
|
|
130
146
|
return super().bash(s0, s1, args)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from adam.commands import validate_args
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.commands.devices.devices import Devices
|
|
4
|
+
from adam.config import Config
|
|
5
|
+
from adam.pod_exec_result import PodExecResult
|
|
6
|
+
from adam.repl_state import ReplState, RequiredState
|
|
7
|
+
from adam.utils import log2
|
|
8
|
+
from adam.utils_k8s.pods import Pods
|
|
9
|
+
|
|
10
|
+
class DownloadFile(Command):
|
|
11
|
+
COMMAND = 'download file'
|
|
12
|
+
|
|
13
|
+
# the singleton pattern
|
|
14
|
+
def __new__(cls, *args, **kwargs):
|
|
15
|
+
if not hasattr(cls, 'instance'): cls.instance = super(DownloadFile, 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 DownloadFile.COMMAND
|
|
24
|
+
|
|
25
|
+
def required(self):
|
|
26
|
+
return [RequiredState.CLUSTER_OR_POD, RequiredState.APP_APP, ReplState.P]
|
|
27
|
+
|
|
28
|
+
def run(self, cmd: str, state: ReplState):
|
|
29
|
+
if not(args := self.args(cmd)):
|
|
30
|
+
return super().run(cmd, state)
|
|
31
|
+
|
|
32
|
+
with self.validate(args, state) as (args, state):
|
|
33
|
+
with validate_args(args, state, name='file'):
|
|
34
|
+
to_file = Pods.download_file(Devices.device(state).pod(state),
|
|
35
|
+
Devices.device(state).default_container(state),
|
|
36
|
+
state.namespace,
|
|
37
|
+
args[0],
|
|
38
|
+
args[1] if len(args) > 1 else None)
|
|
39
|
+
log2(f'Downloaded to {to_file}.')
|
|
40
|
+
|
|
41
|
+
return state
|
|
42
|
+
|
|
43
|
+
def completion(self, state: ReplState):
|
|
44
|
+
return super().completion(state, lambda: {f: None for f in Devices.device(state).files(state)}, pods=Devices.device(state).pods(state, '-'), auto='jit')
|
|
45
|
+
|
|
46
|
+
def help(self, _: ReplState):
|
|
47
|
+
return f'{DownloadFile.COMMAND} from-file [to-file]\t download file from pod'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from adam.commands.command import Command
|
|
2
|
-
from adam.commands.export.
|
|
2
|
+
from adam.commands.export.export_sessions import export_session
|
|
3
3
|
from adam.repl_state import ReplState, RequiredState
|
|
4
4
|
|
|
5
5
|
class CleanUpAllExportSessions(Command):
|
|
@@ -25,8 +25,8 @@ class CleanUpAllExportSessions(Command):
|
|
|
25
25
|
return super().run(cmd, state)
|
|
26
26
|
|
|
27
27
|
with self.validate(args, state) as (args, state):
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
with export_session(state) as sessions:
|
|
29
|
+
sessions.clean_up_all()
|
|
30
30
|
|
|
31
31
|
return state
|
|
32
32
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
from adam.commands import validate_args
|
|
1
2
|
from adam.commands.command import Command
|
|
2
|
-
from adam.commands.export.
|
|
3
|
+
from adam.commands.export.export_sessions import export_session
|
|
3
4
|
from adam.repl_state import ReplState, RequiredState
|
|
4
|
-
from adam.utils import log, log2
|
|
5
5
|
|
|
6
6
|
class CleanUpExportSessions(Command):
|
|
7
7
|
COMMAND = 'clean up export sessions'
|
|
@@ -26,26 +26,14 @@ class CleanUpExportSessions(Command):
|
|
|
26
26
|
return super().run(cmd, state)
|
|
27
27
|
|
|
28
28
|
with self.validate(args, state) as (args, state):
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
else:
|
|
33
|
-
log2('* Session name is missing.')
|
|
29
|
+
with validate_args(args, state, name='export session', separator=',') as session_names:
|
|
30
|
+
with export_session(state) as sessions:
|
|
31
|
+
sessions.clean_up(session_names)
|
|
34
32
|
|
|
35
|
-
|
|
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
|
|
33
|
+
return state
|
|
46
34
|
|
|
47
35
|
def completion(self, _: ReplState):
|
|
48
36
|
return {}
|
|
49
37
|
|
|
50
38
|
def help(self, _: ReplState):
|
|
51
|
-
return f'{CleanUpExportSessions.COMMAND} <export-session-name
|
|
39
|
+
return f'{CleanUpExportSessions.COMMAND} <export-session-name,...>\t clean up export sessions'
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from adam.commands.export.export_databases import ExportDatabases
|
|
2
|
+
from adam.repl_state import ReplState
|
|
3
|
+
from adam.sql.lark_completer import LarkCompleter
|
|
4
|
+
from adam.utils_athena import Athena
|
|
5
|
+
|
|
6
|
+
def completions_x(state: ReplState):
|
|
7
|
+
return LarkCompleter(expandables={
|
|
8
|
+
'tables': lambda x: ExportDatabases.table_names(state.export_session),
|
|
9
|
+
'export-databases': lambda x: ExportDatabases.database_names(),
|
|
10
|
+
'columns': lambda x: Athena.column_names(database=state.export_session, function='export'),
|
|
11
|
+
}, variant=ReplState.X).completions_for_nesting()
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from adam.commands import validate_args
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.commands.export.export_sessions import ExportSessions, export_session
|
|
4
|
+
from adam.repl_state import ReplState, RequiredState
|
|
5
|
+
|
|
6
|
+
class DownloadExportSession(Command):
|
|
7
|
+
COMMAND = 'download export session'
|
|
8
|
+
|
|
9
|
+
# the singleton pattern
|
|
10
|
+
def __new__(cls, *args, **kwargs):
|
|
11
|
+
if not hasattr(cls, 'instance'): cls.instance = super(DownloadExportSession, 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 DownloadExportSession.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
|
+
with validate_args(args, state, name='export session') as session:
|
|
30
|
+
with export_session(state) as sessions:
|
|
31
|
+
sessions.download_session(session)
|
|
32
|
+
|
|
33
|
+
return state
|
|
34
|
+
|
|
35
|
+
def completion(self, state: ReplState):
|
|
36
|
+
return {}
|
|
37
|
+
# return super().completion(state, {session: None for session in ExportSessions.export_session_names(state.sts, state.pod, state.namespace, export_state='pending_import')})
|
|
38
|
+
|
|
39
|
+
def help(self, _: ReplState):
|
|
40
|
+
return f'{DownloadExportSession.COMMAND} <export-session-name>\t download csv files in export session'
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
from adam.commands import validate_args
|
|
1
2
|
from adam.commands.command import Command
|
|
2
|
-
from adam.commands.export.
|
|
3
|
+
from adam.commands.export.export_databases import export_db
|
|
3
4
|
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
5
|
|
|
8
6
|
class DropExportDatabase(Command):
|
|
9
7
|
COMMAND = 'drop export database'
|
|
@@ -28,25 +26,11 @@ class DropExportDatabase(Command):
|
|
|
28
26
|
return super().run(cmd, state)
|
|
29
27
|
|
|
30
28
|
with self.validate(args, state) as (args, state):
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
log2()
|
|
35
|
-
else:
|
|
36
|
-
log2('* Database name is missing.')
|
|
37
|
-
Command.display_help()
|
|
29
|
+
with validate_args(args, state, name='database name') as db:
|
|
30
|
+
with export_db(state) as dbs:
|
|
31
|
+
dbs.drop(args[0])
|
|
38
32
|
|
|
39
|
-
return
|
|
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
|
|
33
|
+
return state
|
|
50
34
|
|
|
51
35
|
def completion(self, _: ReplState):
|
|
52
36
|
return {}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
from adam.commands.command import Command
|
|
2
|
-
from adam.commands.export.
|
|
2
|
+
from adam.commands.export.export_databases import export_db
|
|
3
3
|
from adam.repl_state import ReplState
|
|
4
|
-
from adam.utils_athena import Athena
|
|
5
|
-
from adam.utils_sqlite import SQLite
|
|
6
4
|
|
|
7
5
|
class DropExportDatabases(Command):
|
|
8
6
|
COMMAND = 'drop all export databases'
|
|
@@ -27,12 +25,8 @@ class DropExportDatabases(Command):
|
|
|
27
25
|
return super().run(cmd, state)
|
|
28
26
|
|
|
29
27
|
with self.validate(args, state) as (args, state):
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
SQLite.clear_cache()
|
|
33
|
-
Athena.clear_cache()
|
|
34
|
-
|
|
35
|
-
state.export_session = None
|
|
28
|
+
with export_db(state) as dbs:
|
|
29
|
+
dbs.drop_all()
|
|
36
30
|
|
|
37
31
|
return state
|
|
38
32
|
|
adam/commands/export/export.py
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
from adam.commands import extract_options
|
|
2
2
|
from adam.commands.command import Command
|
|
3
|
-
from adam.commands.
|
|
4
|
-
from adam.commands.export.export_databases import ExportDatabases
|
|
5
|
-
from adam.commands.export.export_handlers import export
|
|
3
|
+
from adam.commands.export.exporter import export
|
|
6
4
|
from adam.repl_state import ReplState, RequiredState
|
|
7
|
-
from adam.sql.sql_completer import SqlCompleter, SqlVariant
|
|
8
|
-
from adam.utils import log
|
|
9
|
-
from adam.utils_k8s.statefulsets import StatefulSets
|
|
10
5
|
|
|
11
6
|
class ExportTables(Command):
|
|
12
7
|
COMMAND = 'export'
|
|
@@ -36,17 +31,6 @@ class ExportTables(Command):
|
|
|
36
31
|
return exporter.export(args, export_only=export_only)
|
|
37
32
|
|
|
38
33
|
def completion(self, state: ReplState):
|
|
39
|
-
def sc():
|
|
40
|
-
return SqlCompleter(lambda: cassandra_table_names(state), expandables={
|
|
41
|
-
'dml':'export',
|
|
42
|
-
'columns': lambda table: ['id', '*'],
|
|
43
|
-
'keyspaces': lambda: cassandra_keyspaces(state),
|
|
44
|
-
'export-dbs': lambda: ExportDatabases.database_names(),
|
|
45
|
-
}, variant=SqlVariant.CQL)
|
|
46
|
-
|
|
47
|
-
if super().completion(state):
|
|
48
|
-
return {f'@{p}': {ExportTables.COMMAND: sc()} for p in StatefulSets.pod_names(state.sts, state.namespace)}
|
|
49
|
-
|
|
50
34
|
return {}
|
|
51
35
|
|
|
52
36
|
def help(self, _: ReplState):
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
from collections.abc import Callable
|
|
2
|
+
from datetime import datetime
|
|
2
3
|
import os
|
|
3
4
|
import boto3
|
|
4
5
|
|
|
5
|
-
from adam.commands.export.
|
|
6
|
+
from adam.commands.export.export_sessions import ExportSessions
|
|
7
|
+
from adam.commands.export.importer import Importer
|
|
6
8
|
from adam.config import Config
|
|
7
9
|
from adam.repl_session import ReplSession
|
|
8
|
-
from adam.
|
|
10
|
+
from adam.repl_state import ReplState
|
|
11
|
+
from adam.utils import debug, log_timing, tabulize, log2, ing, log_exc
|
|
9
12
|
from adam.utils_athena import Athena
|
|
10
|
-
from adam.utils_k8s.statefulsets import StatefulSets
|
|
11
13
|
from adam.utils_sqlite import SQLite
|
|
12
14
|
|
|
13
15
|
LIKE = 'e%_%'
|
|
@@ -86,32 +88,21 @@ class ExportDatabases:
|
|
|
86
88
|
|
|
87
89
|
return dbs
|
|
88
90
|
|
|
89
|
-
def
|
|
90
|
-
if not
|
|
91
|
+
def show_database(database: str):
|
|
92
|
+
if not database:
|
|
91
93
|
return
|
|
92
94
|
|
|
93
|
-
|
|
95
|
+
ExportDatabases.clear_cache()
|
|
94
96
|
|
|
95
97
|
keyspaces = {}
|
|
96
|
-
for table in ExportDatabases.table_names(
|
|
98
|
+
for table in ExportDatabases.table_names(database):
|
|
97
99
|
keyspace = table.split('.')[0]
|
|
98
100
|
if keyspace in keyspaces:
|
|
99
101
|
keyspaces[keyspace] += 1
|
|
100
102
|
else:
|
|
101
103
|
keyspaces[keyspace] = 1
|
|
102
104
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
def disply_export_session(sts: str, pod: str, namespace: str, session: str):
|
|
106
|
-
if not pod:
|
|
107
|
-
pod = StatefulSets.pod_names(sts, namespace)[0]
|
|
108
|
-
|
|
109
|
-
if not pod:
|
|
110
|
-
return
|
|
111
|
-
|
|
112
|
-
tables, _ = ExportTableStatus.from_session(sts, pod, namespace, session)
|
|
113
|
-
log()
|
|
114
|
-
log(lines_to_tabular([f'{table.keyspace}\t{table.table}\t{table.target_table}\t{"export_completed_pending_import" if table.status == "pending_import" else table.status}' for table in tables], header='KEYSPACE\tTABLE\tTARGET_TABLE\tSTATUS', separator='\t'))
|
|
105
|
+
tabulize(keyspaces.items(), lambda a: f'{a[0]},{a[1]}', header='SCHEMA,# of TABLES', separator=',')
|
|
115
106
|
|
|
116
107
|
def database_names():
|
|
117
108
|
return ExportDatabases.copy_database_names() + ExportDatabases.export_database_names()
|
|
@@ -120,7 +111,8 @@ class ExportDatabases:
|
|
|
120
111
|
return list({n.split('_')[0] for n in SQLite.database_names()})
|
|
121
112
|
|
|
122
113
|
def export_database_names():
|
|
123
|
-
|
|
114
|
+
with log_timing('ExportDatabases.Athena.database_names'):
|
|
115
|
+
return list({n.split('_')[0] for n in Athena.database_names(LIKE)})
|
|
124
116
|
|
|
125
117
|
def database_names_with_keyspace_cnt(importer: str = None):
|
|
126
118
|
r = {}
|
|
@@ -171,4 +163,84 @@ class ExportDatabases:
|
|
|
171
163
|
if db.startswith('s'):
|
|
172
164
|
return SQLite.database_names(prefix=f'{eprefix}_')
|
|
173
165
|
else:
|
|
174
|
-
return Athena.database_names(like=f'{eprefix}_%')
|
|
166
|
+
return Athena.database_names(like=f'{eprefix}_%')
|
|
167
|
+
|
|
168
|
+
def drop_databases(sts: str, pod: str, namespace: str, database: str = None):
|
|
169
|
+
importer = None
|
|
170
|
+
if database:
|
|
171
|
+
importer = Importer.importer_from_session(database)
|
|
172
|
+
|
|
173
|
+
sessions_done = ExportSessions.export_session_names(sts, pod, namespace, importer=importer, export_state='done')
|
|
174
|
+
sessions = ExportDatabases.sessions_from_dbs(ExportDatabases.drop_export_dbs(database))
|
|
175
|
+
if sessions_done and sessions:
|
|
176
|
+
intersects = list(set(sessions_done) & set(sessions))
|
|
177
|
+
with ing(f'Cleaning up {len(intersects)} completed sessions'):
|
|
178
|
+
ExportSessions.clean_up_sessions(sts, pod, namespace, list(intersects))
|
|
179
|
+
ExportSessions.clear_export_session_cache()
|
|
180
|
+
|
|
181
|
+
def clear_cache(database: str = None):
|
|
182
|
+
if not database or database.startswith('s'):
|
|
183
|
+
SQLite.clear_cache()
|
|
184
|
+
if not database or database.startswith('e'):
|
|
185
|
+
Athena.clear_cache()
|
|
186
|
+
|
|
187
|
+
def show_databases(importer: str = None):
|
|
188
|
+
lines = [f'{k}\t{v}' for k, v in ExportDatabases.database_names_with_keyspace_cnt(importer).items()]
|
|
189
|
+
tabulize(lines, header='NAME\tKEYSPACES', separator='\t')
|
|
190
|
+
|
|
191
|
+
class ExportDatabaseService:
|
|
192
|
+
def __init__(self, handler: 'ExportDatabaseHandler'):
|
|
193
|
+
self.handler = handler
|
|
194
|
+
|
|
195
|
+
def sql(self, query: str, database: str = None, backgrounded = False):
|
|
196
|
+
if not database:
|
|
197
|
+
database = self.handler.state.export_session
|
|
198
|
+
|
|
199
|
+
def output(out: str):
|
|
200
|
+
log_prefix = Config().get('export.log-prefix', '/tmp/qing')
|
|
201
|
+
log_file = f'{log_prefix}-{datetime.now().strftime("%d%H%M%S")}-export.log'
|
|
202
|
+
|
|
203
|
+
with open(log_file, 'w') as f:
|
|
204
|
+
f.write(out)
|
|
205
|
+
|
|
206
|
+
return log_file
|
|
207
|
+
|
|
208
|
+
ExportDatabases.run_query(query, database, output = output if backgrounded else None, show_query = not backgrounded)
|
|
209
|
+
|
|
210
|
+
def drop(self, database: str):
|
|
211
|
+
state = self.handler.state
|
|
212
|
+
|
|
213
|
+
ExportDatabases.drop_databases(state.sts, state.pod, state.namespace, database)
|
|
214
|
+
ExportDatabases.clear_cache(database)
|
|
215
|
+
if state.export_session == database:
|
|
216
|
+
state.export_session = None
|
|
217
|
+
|
|
218
|
+
def drop_all(self):
|
|
219
|
+
state = self.handler.state
|
|
220
|
+
|
|
221
|
+
ExportDatabases.drop_databases(state.sts, state.pod, state.namespace)
|
|
222
|
+
ExportDatabases.clear_cache()
|
|
223
|
+
|
|
224
|
+
state.export_session = None
|
|
225
|
+
|
|
226
|
+
def show_databases(self, importer: str = None):
|
|
227
|
+
ExportDatabases.show_databases(importer)
|
|
228
|
+
|
|
229
|
+
def show_database(self, database: str = None):
|
|
230
|
+
if not database:
|
|
231
|
+
database = self.handler.state.export_session
|
|
232
|
+
|
|
233
|
+
ExportDatabases.show_database(database)
|
|
234
|
+
|
|
235
|
+
class ExportDatabaseHandler:
|
|
236
|
+
def __init__(self, state: ReplState = None):
|
|
237
|
+
self.state = state
|
|
238
|
+
|
|
239
|
+
def __enter__(self):
|
|
240
|
+
return ExportDatabaseService(self)
|
|
241
|
+
|
|
242
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
243
|
+
return False
|
|
244
|
+
|
|
245
|
+
def export_db(state: ReplState = None):
|
|
246
|
+
return ExportDatabaseHandler(state)
|