kaqing 2.0.14__py3-none-any.whl → 2.0.189__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 +9 -12
- adam/apps.py +20 -6
- adam/batch.py +16 -6
- adam/checks/check_utils.py +19 -49
- adam/checks/compactionstats.py +1 -1
- adam/checks/cpu.py +9 -3
- adam/checks/cpu_metrics.py +52 -0
- adam/checks/disk.py +3 -4
- adam/checks/gossip.py +1 -1
- adam/checks/memory.py +3 -3
- adam/checks/status.py +1 -1
- 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 +24 -0
- adam/commands/alter_tables.py +66 -0
- adam/commands/app/app.py +38 -0
- adam/commands/{app_ping.py → app/app_ping.py} +8 -14
- adam/commands/app/show_app_actions.py +49 -0
- adam/commands/{show → app}/show_app_id.py +9 -12
- adam/commands/{show → app}/show_app_queues.py +8 -14
- adam/commands/app/utils_app.py +106 -0
- adam/commands/audit/__init__.py +0 -0
- adam/commands/audit/audit.py +67 -0
- adam/commands/audit/audit_repair_tables.py +72 -0
- adam/commands/audit/audit_run.py +50 -0
- adam/commands/audit/completions_l.py +15 -0
- adam/commands/audit/show_last10.py +36 -0
- adam/commands/audit/show_slow10.py +36 -0
- adam/commands/audit/show_top10.py +36 -0
- adam/commands/audit/utils_show_top10.py +71 -0
- adam/commands/bash/__init__.py +5 -0
- adam/commands/bash/bash.py +36 -0
- adam/commands/bash/bash_completer.py +93 -0
- adam/commands/bash/utils_bash.py +16 -0
- adam/commands/cat.py +36 -0
- adam/commands/cd.py +14 -88
- adam/commands/check.py +18 -21
- adam/commands/cli_commands.py +11 -7
- adam/commands/clipboard_copy.py +87 -0
- adam/commands/code.py +57 -0
- adam/commands/command.py +220 -19
- adam/commands/commands_utils.py +28 -31
- adam/commands/cql/__init__.py +0 -0
- adam/commands/cql/completions_c.py +28 -0
- adam/commands/{cqlsh.py → cql/cqlsh.py} +13 -32
- adam/commands/cql/utils_cql.py +305 -0
- adam/commands/deploy/code_start.py +7 -10
- adam/commands/deploy/code_stop.py +4 -21
- adam/commands/deploy/code_utils.py +5 -5
- adam/commands/deploy/deploy.py +4 -40
- adam/commands/deploy/deploy_frontend.py +15 -18
- adam/commands/deploy/deploy_pg_agent.py +4 -7
- adam/commands/deploy/deploy_pod.py +74 -77
- adam/commands/deploy/deploy_utils.py +16 -26
- adam/commands/deploy/undeploy.py +4 -40
- adam/commands/deploy/undeploy_frontend.py +5 -8
- adam/commands/deploy/undeploy_pg_agent.py +7 -8
- adam/commands/deploy/undeploy_pod.py +16 -17
- adam/commands/devices/__init__.py +0 -0
- adam/commands/devices/device.py +149 -0
- adam/commands/devices/device_app.py +163 -0
- adam/commands/devices/device_auit_log.py +49 -0
- adam/commands/devices/device_cass.py +179 -0
- adam/commands/devices/device_export.py +87 -0
- adam/commands/devices/device_postgres.py +160 -0
- adam/commands/devices/devices.py +25 -0
- adam/commands/download_file.py +47 -0
- adam/commands/exit.py +1 -4
- adam/commands/export/__init__.py +0 -0
- adam/commands/export/clean_up_all_export_sessions.py +37 -0
- adam/commands/export/clean_up_export_sessions.py +39 -0
- adam/commands/export/completions_x.py +11 -0
- adam/commands/export/download_export_session.py +40 -0
- adam/commands/export/drop_export_database.py +39 -0
- adam/commands/export/drop_export_databases.py +37 -0
- adam/commands/export/export.py +37 -0
- adam/commands/export/export_databases.py +246 -0
- adam/commands/export/export_select.py +34 -0
- adam/commands/export/export_sessions.py +209 -0
- adam/commands/export/export_use.py +49 -0
- adam/commands/export/export_x_select.py +48 -0
- adam/commands/export/exporter.py +332 -0
- adam/commands/export/import_files.py +44 -0
- adam/commands/export/import_session.py +44 -0
- adam/commands/export/importer.py +81 -0
- adam/commands/export/importer_athena.py +148 -0
- adam/commands/export/importer_sqlite.py +67 -0
- adam/commands/export/show_column_counts.py +45 -0
- adam/commands/export/show_export_databases.py +39 -0
- adam/commands/export/show_export_session.py +39 -0
- adam/commands/export/show_export_sessions.py +37 -0
- adam/commands/export/utils_export.py +344 -0
- adam/commands/find_files.py +51 -0
- adam/commands/find_processes.py +76 -0
- adam/commands/head.py +36 -0
- adam/commands/help.py +14 -9
- adam/commands/intermediate_command.py +52 -0
- adam/commands/issues.py +14 -40
- adam/commands/kubectl.py +38 -0
- adam/commands/login.py +26 -25
- adam/commands/logs.py +5 -7
- adam/commands/ls.py +11 -115
- adam/commands/medusa/medusa.py +4 -46
- adam/commands/medusa/medusa_backup.py +22 -29
- adam/commands/medusa/medusa_restore.py +51 -49
- adam/commands/medusa/medusa_show_backupjobs.py +20 -21
- adam/commands/medusa/medusa_show_restorejobs.py +16 -21
- adam/commands/medusa/utils_medusa.py +15 -0
- adam/commands/nodetool.py +8 -17
- adam/commands/param_get.py +11 -14
- adam/commands/param_set.py +9 -13
- adam/commands/postgres/completions_p.py +22 -0
- adam/commands/postgres/postgres.py +49 -73
- adam/commands/postgres/postgres_databases.py +270 -0
- adam/commands/postgres/postgres_ls.py +4 -8
- adam/commands/postgres/postgres_preview.py +5 -9
- adam/commands/postgres/utils_postgres.py +79 -0
- adam/commands/preview_table.py +10 -69
- adam/commands/pwd.py +14 -43
- adam/commands/reaper/reaper.py +6 -49
- adam/commands/reaper/reaper_forward.py +49 -56
- adam/commands/reaper/reaper_forward_session.py +6 -0
- adam/commands/reaper/reaper_forward_stop.py +10 -16
- adam/commands/reaper/reaper_restart.py +8 -15
- adam/commands/reaper/reaper_run_abort.py +8 -33
- adam/commands/reaper/reaper_runs.py +43 -58
- adam/commands/reaper/reaper_runs_abort.py +29 -49
- adam/commands/reaper/reaper_schedule_activate.py +14 -33
- adam/commands/reaper/reaper_schedule_start.py +9 -33
- adam/commands/reaper/reaper_schedule_stop.py +9 -33
- adam/commands/reaper/reaper_schedules.py +4 -14
- adam/commands/reaper/reaper_status.py +8 -16
- adam/commands/reaper/utils_reaper.py +203 -0
- adam/commands/repair/repair.py +4 -46
- adam/commands/repair/repair_log.py +6 -12
- adam/commands/repair/repair_run.py +29 -36
- adam/commands/repair/repair_scan.py +33 -41
- adam/commands/repair/repair_stop.py +6 -13
- adam/commands/report.py +25 -21
- adam/commands/restart.py +27 -28
- adam/commands/rollout.py +20 -25
- adam/commands/shell.py +12 -4
- adam/commands/show/show.py +15 -46
- adam/commands/show/show_adam.py +3 -3
- adam/commands/show/show_cassandra_repairs.py +37 -0
- adam/commands/show/show_cassandra_status.py +48 -52
- adam/commands/show/show_cassandra_version.py +5 -18
- adam/commands/show/show_cli_commands.py +56 -0
- adam/commands/show/show_host.py +33 -0
- adam/commands/show/show_login.py +23 -27
- adam/commands/show/show_params.py +2 -5
- adam/commands/show/show_processes.py +18 -21
- adam/commands/show/show_storage.py +11 -20
- adam/commands/watch.py +27 -30
- adam/config.py +8 -6
- adam/embedded_params.py +1 -1
- adam/log.py +4 -4
- adam/pod_exec_result.py +13 -5
- adam/repl.py +136 -120
- adam/repl_commands.py +66 -24
- adam/repl_session.py +8 -1
- adam/repl_state.py +343 -73
- adam/sql/__init__.py +0 -0
- adam/sql/lark_completer.py +284 -0
- adam/sql/lark_parser.py +604 -0
- adam/sql/sql_completer.py +118 -0
- adam/sql/sql_state_machine.py +630 -0
- adam/sql/term_completer.py +76 -0
- adam/sso/authn_ad.py +7 -9
- adam/sso/authn_okta.py +4 -6
- adam/sso/cred_cache.py +4 -6
- adam/sso/idp.py +10 -13
- adam/utils.py +539 -11
- adam/utils_athena.py +145 -0
- adam/utils_audits.py +102 -0
- adam/utils_issues.py +32 -0
- adam/utils_k8s/__init__.py +0 -0
- adam/utils_k8s/app_clusters.py +28 -0
- adam/utils_k8s/app_pods.py +36 -0
- adam/utils_k8s/cassandra_clusters.py +44 -0
- adam/{k8s_utils → utils_k8s}/cassandra_nodes.py +12 -5
- adam/{k8s_utils → utils_k8s}/custom_resources.py +16 -17
- adam/{k8s_utils → utils_k8s}/deployment.py +2 -2
- adam/{k8s_utils → utils_k8s}/ingresses.py +2 -2
- adam/{k8s_utils → utils_k8s}/jobs.py +7 -11
- adam/utils_k8s/k8s.py +96 -0
- adam/{k8s_utils → utils_k8s}/kube_context.py +3 -3
- adam/{k8s_utils → utils_k8s}/pods.py +132 -83
- adam/{k8s_utils → utils_k8s}/secrets.py +7 -3
- adam/{k8s_utils → utils_k8s}/service_accounts.py +5 -4
- adam/{k8s_utils → utils_k8s}/services.py +2 -2
- adam/{k8s_utils → utils_k8s}/statefulsets.py +9 -16
- adam/utils_local.py +4 -0
- adam/utils_net.py +24 -0
- adam/utils_repl/__init__.py +0 -0
- adam/utils_repl/appendable_completer.py +6 -0
- adam/utils_repl/automata_completer.py +48 -0
- adam/utils_repl/repl_completer.py +172 -0
- adam/utils_repl/state_machine.py +173 -0
- adam/utils_sqlite.py +137 -0
- adam/version.py +1 -1
- {kaqing-2.0.14.dist-info → kaqing-2.0.189.dist-info}/METADATA +1 -1
- kaqing-2.0.189.dist-info/RECORD +253 -0
- kaqing-2.0.189.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/app.py +0 -67
- adam/commands/bash.py +0 -87
- adam/commands/cp.py +0 -95
- adam/commands/cql_utils.py +0 -53
- adam/commands/devices.py +0 -89
- adam/commands/postgres/postgres_session.py +0 -247
- adam/commands/reaper/reaper_session.py +0 -159
- adam/commands/show/show_app_actions.py +0 -53
- adam/commands/show/show_commands.py +0 -61
- adam/commands/show/show_repairs.py +0 -47
- adam/k8s_utils/cassandra_clusters.py +0 -48
- kaqing-2.0.14.dist-info/RECORD +0 -167
- kaqing-2.0.14.dist-info/top_level.txt +0 -1
- /adam/{k8s_utils → commands/app}/__init__.py +0 -0
- /adam/{k8s_utils → utils_k8s}/config_maps.py +0 -0
- /adam/{k8s_utils → utils_k8s}/volumes.py +0 -0
- {kaqing-2.0.14.dist-info → kaqing-2.0.189.dist-info}/WHEEL +0 -0
- {kaqing-2.0.14.dist-info → kaqing-2.0.189.dist-info}/entry_points.txt +0 -0
|
@@ -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'
|
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>'
|
|
File without changes
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.export.export_sessions import export_session
|
|
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
|
+
with export_session(state) as sessions:
|
|
29
|
+
sessions.clean_up_all()
|
|
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,39 @@
|
|
|
1
|
+
from adam.commands import validate_args
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.commands.export.export_sessions import export_session
|
|
4
|
+
from adam.repl_state import ReplState, RequiredState
|
|
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
|
+
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)
|
|
32
|
+
|
|
33
|
+
return state
|
|
34
|
+
|
|
35
|
+
def completion(self, _: ReplState):
|
|
36
|
+
return {}
|
|
37
|
+
|
|
38
|
+
def help(self, _: ReplState):
|
|
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'
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from adam.commands import validate_args
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.commands.export.export_databases import export_db
|
|
4
|
+
from adam.repl_state import ReplState
|
|
5
|
+
|
|
6
|
+
class DropExportDatabase(Command):
|
|
7
|
+
COMMAND = 'drop export database'
|
|
8
|
+
|
|
9
|
+
# the singleton pattern
|
|
10
|
+
def __new__(cls, *args, **kwargs):
|
|
11
|
+
if not hasattr(cls, 'instance'): cls.instance = super(DropExportDatabase, 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 DropExportDatabase.COMMAND
|
|
20
|
+
|
|
21
|
+
def required(self):
|
|
22
|
+
return [ReplState.C, ReplState.X]
|
|
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='database name') as db:
|
|
30
|
+
with export_db(state) as dbs:
|
|
31
|
+
dbs.drop(args[0])
|
|
32
|
+
|
|
33
|
+
return state
|
|
34
|
+
|
|
35
|
+
def completion(self, _: ReplState):
|
|
36
|
+
return {}
|
|
37
|
+
|
|
38
|
+
def help(self, _: ReplState):
|
|
39
|
+
return f'{DropExportDatabase.COMMAND} <export-database-name>\t drop export database'
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.export.export_databases import export_db
|
|
3
|
+
from adam.repl_state import ReplState
|
|
4
|
+
|
|
5
|
+
class DropExportDatabases(Command):
|
|
6
|
+
COMMAND = 'drop all export databases'
|
|
7
|
+
|
|
8
|
+
# the singleton pattern
|
|
9
|
+
def __new__(cls, *args, **kwargs):
|
|
10
|
+
if not hasattr(cls, 'instance'): cls.instance = super(DropExportDatabases, 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 DropExportDatabases.COMMAND
|
|
19
|
+
|
|
20
|
+
def required(self):
|
|
21
|
+
return [ReplState.C, ReplState.X]
|
|
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
|
+
with export_db(state) as dbs:
|
|
29
|
+
dbs.drop_all()
|
|
30
|
+
|
|
31
|
+
return state
|
|
32
|
+
|
|
33
|
+
def completion(self, _: ReplState):
|
|
34
|
+
return {}
|
|
35
|
+
|
|
36
|
+
def help(self, _: ReplState):
|
|
37
|
+
return f'{DropExportDatabases.COMMAND}\t drop all export databases'
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from adam.commands import extract_options
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.commands.export.exporter import export
|
|
4
|
+
from adam.repl_state import ReplState, RequiredState
|
|
5
|
+
|
|
6
|
+
class ExportTables(Command):
|
|
7
|
+
COMMAND = 'export'
|
|
8
|
+
|
|
9
|
+
# the singleton pattern
|
|
10
|
+
def __new__(cls, *args, **kwargs):
|
|
11
|
+
if not hasattr(cls, 'instance'): cls.instance = super(ExportTables, 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 ExportTables.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 extract_options(args, '--export-only') as (args, export_only):
|
|
30
|
+
with export(state) as exporter:
|
|
31
|
+
return exporter.export(args, export_only=export_only)
|
|
32
|
+
|
|
33
|
+
def completion(self, state: ReplState):
|
|
34
|
+
return {}
|
|
35
|
+
|
|
36
|
+
def help(self, _: ReplState):
|
|
37
|
+
return f'{ExportTables.COMMAND} [* [in KEYSPACE]] | [TABLE] [as target-name] [with consistency <level>]\t export tables to Sqlite, Athena or CSV file'
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
import os
|
|
4
|
+
import boto3
|
|
5
|
+
|
|
6
|
+
from adam.commands.export.export_sessions import ExportSessions
|
|
7
|
+
from adam.commands.export.importer import Importer
|
|
8
|
+
from adam.config import Config
|
|
9
|
+
from adam.repl_session import ReplSession
|
|
10
|
+
from adam.repl_state import ReplState
|
|
11
|
+
from adam.utils import debug, log_timing, tabulize, log2, ing, log_exc
|
|
12
|
+
from adam.utils_athena import Athena
|
|
13
|
+
from adam.utils_sqlite import SQLite
|
|
14
|
+
|
|
15
|
+
LIKE = 'e%_%'
|
|
16
|
+
|
|
17
|
+
class ExportDatabases:
|
|
18
|
+
def run_query(query: str, database: str, show_query=False, output: Callable[[str], str] = None) -> int:
|
|
19
|
+
cnt: int = 0
|
|
20
|
+
|
|
21
|
+
if show_query:
|
|
22
|
+
log2(query)
|
|
23
|
+
|
|
24
|
+
log_file = None
|
|
25
|
+
if database.startswith('s'):
|
|
26
|
+
cnt0, log_file = SQLite.run_query(query, database=database, output=output)
|
|
27
|
+
cnt += cnt0
|
|
28
|
+
else:
|
|
29
|
+
cnt0, log_file = Athena.run_query(query, database=database, output=output)
|
|
30
|
+
cnt += cnt0
|
|
31
|
+
|
|
32
|
+
if Config().get('repl.history.push-cat-log-file', True):
|
|
33
|
+
if log_file and ReplSession().prompt_session:
|
|
34
|
+
ReplSession().prompt_session.history.append_string(f':sh cat {log_file}')
|
|
35
|
+
|
|
36
|
+
return cnt
|
|
37
|
+
|
|
38
|
+
def sessions_from_dbs(dbs: list[str]):
|
|
39
|
+
|
|
40
|
+
sessions = set()
|
|
41
|
+
|
|
42
|
+
for db in dbs:
|
|
43
|
+
sessions.add(db.split('_')[0])
|
|
44
|
+
|
|
45
|
+
return list(sessions)
|
|
46
|
+
|
|
47
|
+
def drop_export_dbs(db: str = None):
|
|
48
|
+
dbs: list[str] = []
|
|
49
|
+
|
|
50
|
+
if not db or db.startswith('s'):
|
|
51
|
+
dbs.extend(ExportDatabases.drop_sqlite_dbs(db))
|
|
52
|
+
if not db or db.startswith('e'):
|
|
53
|
+
dbs.extend(ExportDatabases.drop_athena_dbs(db))
|
|
54
|
+
|
|
55
|
+
return dbs
|
|
56
|
+
|
|
57
|
+
def drop_sqlite_dbs(db: str = None):
|
|
58
|
+
dbs = SQLite.database_names(db)
|
|
59
|
+
if dbs:
|
|
60
|
+
with ing(f'Droping {len(dbs)} SQLite databases'):
|
|
61
|
+
with log_exc():
|
|
62
|
+
for db in dbs:
|
|
63
|
+
file_path = f'{SQLite.local_db_dir()}/{db}'
|
|
64
|
+
try:
|
|
65
|
+
os.remove(file_path)
|
|
66
|
+
except OSError as e:
|
|
67
|
+
pass
|
|
68
|
+
|
|
69
|
+
return dbs
|
|
70
|
+
|
|
71
|
+
def drop_athena_dbs(db: str = None):
|
|
72
|
+
dbs = Athena.database_names(f'{db}_%' if db else LIKE)
|
|
73
|
+
if dbs:
|
|
74
|
+
with ing(f'Droping {len(dbs)} Athena databases'):
|
|
75
|
+
for db in dbs:
|
|
76
|
+
query = f'DROP DATABASE {db} CASCADE'
|
|
77
|
+
debug(query)
|
|
78
|
+
Athena.query(query)
|
|
79
|
+
|
|
80
|
+
with ing(f'Deleting s3 folder: export'):
|
|
81
|
+
with log_exc():
|
|
82
|
+
if not db:
|
|
83
|
+
db = ''
|
|
84
|
+
|
|
85
|
+
s3 = boto3.resource('s3')
|
|
86
|
+
bucket = s3.Bucket(Config().get('export.bucket', 'c3.ops--qing'))
|
|
87
|
+
bucket.objects.filter(Prefix=f'export/{db}').delete()
|
|
88
|
+
|
|
89
|
+
return dbs
|
|
90
|
+
|
|
91
|
+
def show_database(database: str):
|
|
92
|
+
if not database:
|
|
93
|
+
return
|
|
94
|
+
|
|
95
|
+
ExportDatabases.clear_cache()
|
|
96
|
+
|
|
97
|
+
keyspaces = {}
|
|
98
|
+
for table in ExportDatabases.table_names(database):
|
|
99
|
+
keyspace = table.split('.')[0]
|
|
100
|
+
if keyspace in keyspaces:
|
|
101
|
+
keyspaces[keyspace] += 1
|
|
102
|
+
else:
|
|
103
|
+
keyspaces[keyspace] = 1
|
|
104
|
+
|
|
105
|
+
tabulize(keyspaces.items(), lambda a: f'{a[0]},{a[1]}', header='SCHEMA,# of TABLES', separator=',')
|
|
106
|
+
|
|
107
|
+
def database_names():
|
|
108
|
+
return ExportDatabases.copy_database_names() + ExportDatabases.export_database_names()
|
|
109
|
+
|
|
110
|
+
def copy_database_names():
|
|
111
|
+
return list({n.split('_')[0] for n in SQLite.database_names()})
|
|
112
|
+
|
|
113
|
+
def export_database_names():
|
|
114
|
+
with log_timing('ExportDatabases.Athena.database_names'):
|
|
115
|
+
return list({n.split('_')[0] for n in Athena.database_names(LIKE)})
|
|
116
|
+
|
|
117
|
+
def database_names_with_keyspace_cnt(importer: str = None):
|
|
118
|
+
r = {}
|
|
119
|
+
|
|
120
|
+
names = []
|
|
121
|
+
if not importer:
|
|
122
|
+
names = SQLite.database_names() + Athena.database_names(LIKE)
|
|
123
|
+
elif importer == 'athena':
|
|
124
|
+
names = Athena.database_names(LIKE)
|
|
125
|
+
else:
|
|
126
|
+
names = SQLite.database_names()
|
|
127
|
+
|
|
128
|
+
for n in names:
|
|
129
|
+
tokens = n.split('_')
|
|
130
|
+
name = tokens[0]
|
|
131
|
+
keyspace = None
|
|
132
|
+
if len(tokens) > 1:
|
|
133
|
+
keyspace = tokens[1].replace('.db', '')
|
|
134
|
+
|
|
135
|
+
if keyspace == 'root':
|
|
136
|
+
continue
|
|
137
|
+
|
|
138
|
+
if name in r:
|
|
139
|
+
r[name] += 1
|
|
140
|
+
else:
|
|
141
|
+
r[name] = 1
|
|
142
|
+
|
|
143
|
+
return r
|
|
144
|
+
|
|
145
|
+
def table_names(session: str):
|
|
146
|
+
tables = []
|
|
147
|
+
|
|
148
|
+
for session in ExportDatabases._session_database_names(session):
|
|
149
|
+
if session.startswith('s'):
|
|
150
|
+
for table in SQLite.table_names(database=session):
|
|
151
|
+
tables.append(f'{SQLite.keyspace(session)}.{table}')
|
|
152
|
+
else:
|
|
153
|
+
for table in Athena.table_names(database=session, function='export'):
|
|
154
|
+
tables.append(f'{session}.{table}')
|
|
155
|
+
|
|
156
|
+
return tables
|
|
157
|
+
|
|
158
|
+
def _session_database_names(db: str):
|
|
159
|
+
eprefix = db
|
|
160
|
+
if '_' in db:
|
|
161
|
+
eprefix = db.split('_')[0]
|
|
162
|
+
|
|
163
|
+
if db.startswith('s'):
|
|
164
|
+
return SQLite.database_names(prefix=f'{eprefix}_')
|
|
165
|
+
else:
|
|
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)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.export.completions_x import completions_x
|
|
3
|
+
from adam.repl_state import ReplState, RequiredState
|
|
4
|
+
|
|
5
|
+
# No action body, only for a help entry and auto-completion
|
|
6
|
+
class ExportSelect(Command):
|
|
7
|
+
COMMAND = 'select_on_x'
|
|
8
|
+
|
|
9
|
+
# the singleton pattern
|
|
10
|
+
def __new__(cls, *args, **kwargs):
|
|
11
|
+
if not hasattr(cls, 'instance'): cls.instance = super(ExportSelect, 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 ExportSelect.COMMAND
|
|
20
|
+
|
|
21
|
+
def required(self):
|
|
22
|
+
return RequiredState.EXPORT_DB
|
|
23
|
+
|
|
24
|
+
def completion(self, state: ReplState):
|
|
25
|
+
if state.device != ReplState.X:
|
|
26
|
+
return {}
|
|
27
|
+
|
|
28
|
+
if state.export_session:
|
|
29
|
+
return completions_x(state)
|
|
30
|
+
|
|
31
|
+
return {}
|
|
32
|
+
|
|
33
|
+
def help(self, _: ReplState):
|
|
34
|
+
return f'<sql-select-statements>\t run queries on export database'
|