kaqing 2.0.171__py3-none-any.whl → 2.0.204__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.
- adam/app_session.py +5 -10
- adam/apps.py +18 -4
- adam/batch.py +7 -7
- adam/checks/check_utils.py +3 -1
- adam/checks/disk.py +2 -3
- adam/columns/memory.py +3 -4
- adam/commands/__init__.py +15 -6
- adam/commands/alter_tables.py +26 -41
- adam/commands/app/__init__.py +0 -0
- adam/commands/{app_cmd.py → app/app.py} +2 -2
- adam/commands/{show → app}/show_app_actions.py +7 -15
- adam/commands/{show → app}/show_app_queues.py +1 -4
- adam/{utils_app.py → commands/app/utils_app.py} +9 -1
- adam/commands/audit/audit.py +9 -26
- 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 +15 -3
- adam/commands/bash/bash.py +1 -1
- adam/commands/bash/utils_bash.py +1 -1
- adam/commands/cassandra/__init__.py +0 -0
- adam/commands/cassandra/download_cassandra_log.py +45 -0
- adam/commands/cassandra/nodetool.py +64 -0
- adam/commands/cassandra/nodetool_commands.py +120 -0
- adam/commands/cassandra/restart_cluster.py +47 -0
- adam/commands/cassandra/restart_node.py +51 -0
- adam/commands/cassandra/restart_nodes.py +47 -0
- adam/commands/cassandra/rollout.py +88 -0
- adam/commands/cat.py +5 -19
- adam/commands/cd.py +7 -9
- 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 +139 -22
- adam/commands/commands_utils.py +14 -12
- adam/commands/cql/alter_tables.py +66 -0
- adam/commands/cql/completions_c.py +29 -0
- adam/commands/cql/cqlsh.py +3 -7
- adam/commands/cql/utils_cql.py +23 -61
- adam/commands/debug/__init__.py +0 -0
- adam/commands/debug/debug.py +22 -0
- adam/commands/debug/debug_completes.py +35 -0
- adam/commands/debug/debug_timings.py +35 -0
- adam/commands/deploy/deploy_pg_agent.py +2 -2
- adam/commands/deploy/deploy_pod.py +2 -4
- adam/commands/deploy/undeploy_pg_agent.py +2 -2
- adam/commands/devices/device.py +40 -9
- 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/devices/devices.py +1 -1
- adam/commands/download_cassandra_log.py +45 -0
- 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 +109 -32
- adam/commands/export/export_select.py +8 -55
- adam/commands/export/export_sessions.py +211 -0
- adam/commands/export/export_use.py +13 -16
- adam/commands/export/export_x_select.py +48 -0
- adam/commands/export/exporter.py +176 -167
- adam/commands/export/import_files.py +44 -0
- adam/commands/export/import_session.py +10 -6
- adam/commands/export/importer.py +24 -9
- adam/commands/export/importer_athena.py +114 -44
- adam/commands/export/importer_sqlite.py +45 -23
- 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 +79 -27
- adam/commands/find_files.py +51 -0
- adam/commands/find_processes.py +76 -0
- adam/commands/generate_report.py +52 -0
- adam/commands/head.py +36 -0
- adam/commands/help.py +2 -2
- adam/commands/intermediate_command.py +6 -3
- adam/commands/login.py +3 -6
- adam/commands/ls.py +2 -2
- adam/commands/medusa/medusa_backup.py +13 -16
- adam/commands/medusa/medusa_restore.py +26 -37
- adam/commands/medusa/medusa_show_backupjobs.py +7 -7
- adam/commands/medusa/medusa_show_restorejobs.py +6 -6
- adam/commands/medusa/utils_medusa.py +15 -0
- adam/commands/nodetool.py +3 -8
- adam/commands/os/__init__.py +0 -0
- adam/commands/os/cat.py +36 -0
- adam/commands/os/download_file.py +47 -0
- adam/commands/os/find_files.py +51 -0
- adam/commands/os/find_processes.py +76 -0
- adam/commands/os/head.py +36 -0
- adam/commands/os/shell.py +41 -0
- 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 +269 -0
- adam/commands/postgres/utils_postgres.py +33 -20
- adam/commands/preview_table.py +4 -2
- adam/commands/pwd.py +4 -6
- 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_log.py +1 -4
- adam/commands/repair/repair_run.py +3 -8
- adam/commands/repair/repair_scan.py +1 -6
- adam/commands/repair/repair_stop.py +1 -5
- adam/commands/restart_cluster.py +47 -0
- adam/commands/restart_node.py +51 -0
- adam/commands/restart_nodes.py +47 -0
- adam/commands/shell.py +9 -2
- adam/commands/show/show.py +4 -4
- adam/commands/show/show_adam.py +3 -3
- adam/commands/show/show_cassandra_repairs.py +5 -6
- adam/commands/show/show_cassandra_status.py +29 -29
- adam/commands/show/show_cassandra_version.py +1 -4
- adam/commands/show/{show_commands.py → show_cli_commands.py} +3 -6
- adam/commands/show/show_login.py +3 -9
- adam/commands/show/show_params.py +2 -5
- adam/commands/show/show_processes.py +15 -16
- adam/commands/show/show_storage.py +9 -8
- adam/config.py +4 -5
- adam/embedded_params.py +1 -1
- adam/log.py +4 -4
- adam/repl.py +26 -18
- adam/repl_commands.py +32 -20
- adam/repl_session.py +9 -1
- adam/repl_state.py +39 -10
- adam/sql/async_executor.py +44 -0
- adam/sql/lark_completer.py +286 -0
- adam/sql/lark_parser.py +604 -0
- adam/sql/qingl.lark +1076 -0
- adam/sql/sql_completer.py +4 -6
- adam/sql/sql_state_machine.py +25 -13
- adam/sso/authn_ad.py +2 -5
- adam/sso/authn_okta.py +2 -4
- adam/sso/cred_cache.py +2 -5
- adam/sso/idp.py +8 -11
- adam/utils.py +299 -105
- adam/utils_athena.py +18 -18
- adam/utils_audits.py +3 -7
- adam/utils_issues.py +2 -2
- adam/utils_k8s/app_clusters.py +4 -4
- adam/utils_k8s/app_pods.py +8 -6
- adam/utils_k8s/cassandra_clusters.py +16 -5
- adam/utils_k8s/cassandra_nodes.py +7 -6
- adam/utils_k8s/custom_resources.py +11 -17
- adam/utils_k8s/jobs.py +7 -11
- adam/utils_k8s/k8s.py +14 -5
- adam/utils_k8s/kube_context.py +3 -6
- adam/{pod_exec_result.py → utils_k8s/pod_exec_result.py} +4 -4
- adam/utils_k8s/pods.py +98 -36
- adam/utils_k8s/statefulsets.py +5 -2
- adam/utils_local.py +42 -0
- adam/utils_repl/appendable_completer.py +6 -0
- adam/utils_repl/repl_completer.py +45 -2
- adam/utils_repl/state_machine.py +3 -3
- adam/utils_sqlite.py +58 -30
- adam/version.py +1 -1
- {kaqing-2.0.171.dist-info → kaqing-2.0.204.dist-info}/METADATA +1 -1
- kaqing-2.0.204.dist-info/RECORD +277 -0
- kaqing-2.0.204.dist-info/top_level.txt +2 -0
- teddy/__init__.py +0 -0
- teddy/lark_parser.py +436 -0
- teddy/lark_parser2.py +618 -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/logs.py +0 -37
- adam/commands/postgres/postgres_context.py +0 -274
- adam/commands/postgres/psql_completions.py +0 -10
- adam/commands/report.py +0 -61
- adam/commands/restart.py +0 -60
- kaqing-2.0.171.dist-info/RECORD +0 -236
- kaqing-2.0.171.dist-info/top_level.txt +0 -1
- /adam/commands/{app_ping.py → app/app_ping.py} +0 -0
- /adam/commands/{show → app}/show_app_id.py +0 -0
- {kaqing-2.0.171.dist-info → kaqing-2.0.204.dist-info}/WHEEL +0 -0
- {kaqing-2.0.171.dist-info → kaqing-2.0.204.dist-info}/entry_points.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)
|
adam/commands/devices/devices.py
CHANGED
|
@@ -7,7 +7,7 @@ from adam.commands.devices.device_postgres import DevicePostgres
|
|
|
7
7
|
from adam.repl_state import ReplState
|
|
8
8
|
|
|
9
9
|
class Devices:
|
|
10
|
-
def
|
|
10
|
+
def of(state: ReplState) -> Device:
|
|
11
11
|
if state.device == ReplState.A:
|
|
12
12
|
return DeviceApp()
|
|
13
13
|
elif state.device == ReplState.C:
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.devices.devices import Devices
|
|
3
|
+
from adam.config import Config
|
|
4
|
+
from adam.utils_k8s.pod_exec_result import PodExecResult
|
|
5
|
+
from adam.utils import log2
|
|
6
|
+
from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
7
|
+
from adam.repl_state import ReplState, RequiredState
|
|
8
|
+
from adam.utils_k8s.pods import Pods
|
|
9
|
+
|
|
10
|
+
class DownloadCassandraLog(Command):
|
|
11
|
+
COMMAND = 'download cassandra log'
|
|
12
|
+
|
|
13
|
+
# the singleton pattern
|
|
14
|
+
def __new__(cls, *args, **kwargs):
|
|
15
|
+
if not hasattr(cls, 'instance'): cls.instance = super(DownloadCassandraLog, 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 DownloadCassandraLog.COMMAND
|
|
24
|
+
|
|
25
|
+
def required(self):
|
|
26
|
+
return RequiredState.POD
|
|
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
|
+
path = Config().get('logs.path', '/c3/cassandra/logs/system.log')
|
|
34
|
+
r: PodExecResult = CassandraNodes.exec(state.pod, state.namespace, f'cat {path}', backgrounded=True, no_history=True)
|
|
35
|
+
|
|
36
|
+
to_file = Pods.download_file(state.pod, 'cassandra', state.namespace, path)
|
|
37
|
+
log2(f'Downloaded to {to_file}.')
|
|
38
|
+
|
|
39
|
+
return r
|
|
40
|
+
|
|
41
|
+
def completion(self, state: ReplState):
|
|
42
|
+
return super().completion(state, pods=Devices.of(state).pods(state, '-'), auto='jit')
|
|
43
|
+
|
|
44
|
+
def help(self, _: ReplState):
|
|
45
|
+
return f'{DownloadCassandraLog.COMMAND}\t download cassandra system log'
|
|
@@ -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.utils_k8s.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.of(state).pod(state),
|
|
35
|
+
Devices.of(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.of(state).files(state)}, pods=Devices.of(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):
|