kaqing 1.77.0__py3-none-any.whl → 2.0.171__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.
Files changed (308) hide show
  1. adam/__init__.py +1 -0
  2. adam/app_session.py +182 -0
  3. {walker → adam}/apps.py +8 -24
  4. {walker → adam}/batch.py +54 -97
  5. {walker → adam}/checks/check.py +3 -3
  6. {walker → adam}/checks/check_result.py +1 -1
  7. adam/checks/check_utils.py +65 -0
  8. {walker → adam}/checks/compactionstats.py +6 -6
  9. {walker → adam}/checks/cpu.py +14 -8
  10. adam/checks/cpu_metrics.py +52 -0
  11. {walker → adam}/checks/disk.py +6 -6
  12. {walker → adam}/checks/gossip.py +5 -5
  13. {walker → adam}/checks/memory.py +7 -7
  14. {walker → adam}/checks/status.py +5 -5
  15. {walker → adam}/cli.py +3 -3
  16. {walker → adam}/columns/column.py +1 -1
  17. adam/columns/columns.py +45 -0
  18. {walker → adam}/columns/compactions.py +5 -5
  19. {walker → adam}/columns/cpu.py +6 -4
  20. adam/columns/cpu_metrics.py +22 -0
  21. {walker → adam}/columns/dir_data.py +3 -3
  22. {walker → adam}/columns/dir_snapshots.py +3 -3
  23. {walker → adam}/columns/gossip.py +5 -5
  24. {walker → adam}/columns/host_id.py +3 -3
  25. {walker → adam}/columns/memory.py +3 -3
  26. {walker → adam}/columns/node_address.py +3 -3
  27. {walker → adam}/columns/node_load.py +3 -3
  28. {walker → adam}/columns/node_owns.py +3 -3
  29. {walker → adam}/columns/node_status.py +3 -3
  30. {walker → adam}/columns/node_tokens.py +3 -3
  31. {walker → adam}/columns/node_utils.py +2 -2
  32. {walker → adam}/columns/pod_name.py +2 -2
  33. {walker → adam}/columns/volume_cassandra.py +4 -4
  34. {walker → adam}/columns/volume_root.py +3 -3
  35. adam/commands/__init__.py +15 -0
  36. adam/commands/alter_tables.py +81 -0
  37. adam/commands/app_cmd.py +38 -0
  38. {walker → adam}/commands/app_ping.py +10 -16
  39. adam/commands/audit/audit.py +84 -0
  40. adam/commands/audit/audit_repair_tables.py +74 -0
  41. adam/commands/audit/audit_run.py +50 -0
  42. adam/commands/audit/show_last10.py +48 -0
  43. adam/commands/audit/show_slow10.py +47 -0
  44. adam/commands/audit/show_top10.py +45 -0
  45. adam/commands/audit/utils_show_top10.py +59 -0
  46. adam/commands/bash/__init__.py +5 -0
  47. adam/commands/bash/bash.py +36 -0
  48. adam/commands/bash/bash_completer.py +93 -0
  49. adam/commands/bash/utils_bash.py +16 -0
  50. adam/commands/cat.py +50 -0
  51. adam/commands/cd.py +43 -0
  52. adam/commands/check.py +73 -0
  53. {walker → adam}/commands/cli_commands.py +7 -8
  54. adam/commands/code.py +57 -0
  55. adam/commands/command.py +190 -0
  56. {walker → adam}/commands/command_helpers.py +1 -1
  57. {walker → adam}/commands/commands_utils.py +15 -25
  58. adam/commands/cp.py +89 -0
  59. adam/commands/cql/cql_completions.py +33 -0
  60. {walker/commands → adam/commands/cql}/cqlsh.py +20 -35
  61. adam/commands/cql/utils_cql.py +343 -0
  62. {walker/commands/frontend → adam/commands/deploy}/code_start.py +11 -14
  63. adam/commands/deploy/code_stop.py +40 -0
  64. {walker/commands/frontend → adam/commands/deploy}/code_utils.py +7 -9
  65. adam/commands/deploy/deploy.py +25 -0
  66. adam/commands/deploy/deploy_frontend.py +49 -0
  67. adam/commands/deploy/deploy_pg_agent.py +35 -0
  68. adam/commands/deploy/deploy_pod.py +108 -0
  69. adam/commands/deploy/deploy_utils.py +29 -0
  70. adam/commands/deploy/undeploy.py +25 -0
  71. adam/commands/deploy/undeploy_frontend.py +38 -0
  72. adam/commands/deploy/undeploy_pg_agent.py +39 -0
  73. adam/commands/deploy/undeploy_pod.py +48 -0
  74. adam/commands/devices/device.py +118 -0
  75. adam/commands/devices/device_app.py +173 -0
  76. adam/commands/devices/device_auit_log.py +49 -0
  77. adam/commands/devices/device_cass.py +185 -0
  78. adam/commands/devices/device_export.py +86 -0
  79. adam/commands/devices/device_postgres.py +144 -0
  80. adam/commands/devices/devices.py +25 -0
  81. {walker → adam}/commands/exit.py +3 -6
  82. adam/commands/export/clean_up_all_export_sessions.py +37 -0
  83. adam/commands/export/clean_up_export_sessions.py +51 -0
  84. adam/commands/export/drop_export_database.py +55 -0
  85. adam/commands/export/drop_export_databases.py +43 -0
  86. adam/commands/export/export.py +53 -0
  87. adam/commands/export/export_databases.py +170 -0
  88. adam/commands/export/export_handlers.py +71 -0
  89. adam/commands/export/export_select.py +81 -0
  90. adam/commands/export/export_select_x.py +54 -0
  91. adam/commands/export/export_use.py +52 -0
  92. adam/commands/export/exporter.py +352 -0
  93. adam/commands/export/import_session.py +40 -0
  94. adam/commands/export/importer.py +67 -0
  95. adam/commands/export/importer_athena.py +80 -0
  96. adam/commands/export/importer_sqlite.py +47 -0
  97. adam/commands/export/show_column_counts.py +54 -0
  98. adam/commands/export/show_export_databases.py +36 -0
  99. adam/commands/export/show_export_session.py +48 -0
  100. adam/commands/export/show_export_sessions.py +44 -0
  101. adam/commands/export/utils_export.py +314 -0
  102. {walker → adam}/commands/help.py +17 -12
  103. adam/commands/intermediate_command.py +49 -0
  104. adam/commands/issues.py +43 -0
  105. adam/commands/kubectl.py +38 -0
  106. adam/commands/login.py +70 -0
  107. {walker → adam}/commands/logs.py +8 -10
  108. adam/commands/ls.py +41 -0
  109. adam/commands/medusa/medusa.py +27 -0
  110. adam/commands/medusa/medusa_backup.py +57 -0
  111. adam/commands/medusa/medusa_restore.py +83 -0
  112. adam/commands/medusa/medusa_show_backupjobs.py +51 -0
  113. adam/commands/medusa/medusa_show_restorejobs.py +47 -0
  114. {walker → adam}/commands/nodetool.py +17 -21
  115. {walker → adam}/commands/param_get.py +15 -16
  116. adam/commands/param_set.py +43 -0
  117. adam/commands/postgres/postgres.py +104 -0
  118. adam/commands/postgres/postgres_context.py +274 -0
  119. {walker → adam}/commands/postgres/postgres_ls.py +7 -11
  120. {walker → adam}/commands/postgres/postgres_preview.py +8 -13
  121. adam/commands/postgres/psql_completions.py +10 -0
  122. adam/commands/postgres/utils_postgres.py +66 -0
  123. adam/commands/preview_table.py +37 -0
  124. adam/commands/pwd.py +47 -0
  125. adam/commands/reaper/reaper.py +35 -0
  126. adam/commands/reaper/reaper_forward.py +93 -0
  127. adam/commands/reaper/reaper_forward_session.py +6 -0
  128. {walker → adam}/commands/reaper/reaper_forward_stop.py +13 -19
  129. {walker → adam}/commands/reaper/reaper_restart.py +10 -17
  130. adam/commands/reaper/reaper_run_abort.py +46 -0
  131. adam/commands/reaper/reaper_runs.py +82 -0
  132. adam/commands/reaper/reaper_runs_abort.py +63 -0
  133. adam/commands/reaper/reaper_schedule_activate.py +45 -0
  134. adam/commands/reaper/reaper_schedule_start.py +45 -0
  135. adam/commands/reaper/reaper_schedule_stop.py +45 -0
  136. {walker → adam}/commands/reaper/reaper_schedules.py +6 -16
  137. {walker → adam}/commands/reaper/reaper_status.py +11 -19
  138. adam/commands/reaper/utils_reaper.py +196 -0
  139. adam/commands/repair/repair.py +26 -0
  140. {walker → adam}/commands/repair/repair_log.py +7 -10
  141. adam/commands/repair/repair_run.py +70 -0
  142. adam/commands/repair/repair_scan.py +71 -0
  143. {walker → adam}/commands/repair/repair_stop.py +8 -11
  144. adam/commands/report.py +61 -0
  145. adam/commands/restart.py +60 -0
  146. {walker → adam}/commands/rollout.py +25 -30
  147. adam/commands/shell.py +34 -0
  148. adam/commands/show/show.py +39 -0
  149. walker/commands/show/show_version.py → adam/commands/show/show_adam.py +14 -10
  150. adam/commands/show/show_app_actions.py +57 -0
  151. {walker → adam}/commands/show/show_app_id.py +12 -15
  152. {walker → adam}/commands/show/show_app_queues.py +9 -12
  153. adam/commands/show/show_cassandra_repairs.py +38 -0
  154. adam/commands/show/show_cassandra_status.py +124 -0
  155. {walker → adam}/commands/show/show_cassandra_version.py +6 -16
  156. adam/commands/show/show_commands.py +59 -0
  157. walker/commands/show/show_storage.py → adam/commands/show/show_host.py +11 -13
  158. adam/commands/show/show_login.py +62 -0
  159. {walker → adam}/commands/show/show_params.py +4 -4
  160. adam/commands/show/show_processes.py +51 -0
  161. adam/commands/show/show_storage.py +42 -0
  162. adam/commands/watch.py +82 -0
  163. {walker → adam}/config.py +10 -22
  164. {walker → adam}/embedded_apps.py +1 -1
  165. adam/embedded_params.py +2 -0
  166. adam/log.py +47 -0
  167. {walker → adam}/pod_exec_result.py +10 -2
  168. adam/repl.py +182 -0
  169. adam/repl_commands.py +124 -0
  170. adam/repl_state.py +458 -0
  171. adam/sql/__init__.py +0 -0
  172. adam/sql/sql_completer.py +120 -0
  173. adam/sql/sql_state_machine.py +618 -0
  174. adam/sql/term_completer.py +76 -0
  175. adam/sso/__init__.py +0 -0
  176. {walker → adam}/sso/authenticator.py +5 -1
  177. adam/sso/authn_ad.py +170 -0
  178. {walker → adam}/sso/authn_okta.py +39 -22
  179. adam/sso/cred_cache.py +60 -0
  180. adam/sso/id_token.py +23 -0
  181. adam/sso/idp.py +143 -0
  182. adam/sso/idp_login.py +50 -0
  183. adam/sso/idp_session.py +55 -0
  184. adam/sso/sso_config.py +63 -0
  185. adam/utils.py +679 -0
  186. adam/utils_app.py +98 -0
  187. adam/utils_athena.py +145 -0
  188. adam/utils_audits.py +106 -0
  189. adam/utils_issues.py +32 -0
  190. adam/utils_k8s/__init__.py +0 -0
  191. adam/utils_k8s/app_clusters.py +28 -0
  192. adam/utils_k8s/app_pods.py +33 -0
  193. adam/utils_k8s/cassandra_clusters.py +36 -0
  194. adam/utils_k8s/cassandra_nodes.py +33 -0
  195. adam/utils_k8s/config_maps.py +34 -0
  196. {walker/k8s_utils → adam/utils_k8s}/custom_resources.py +7 -2
  197. adam/utils_k8s/deployment.py +56 -0
  198. {walker/k8s_utils → adam/utils_k8s}/ingresses.py +3 -4
  199. {walker/k8s_utils → adam/utils_k8s}/jobs.py +3 -3
  200. adam/utils_k8s/k8s.py +87 -0
  201. {walker/k8s_utils → adam/utils_k8s}/kube_context.py +4 -4
  202. adam/utils_k8s/pods.py +290 -0
  203. {walker/k8s_utils → adam/utils_k8s}/secrets.py +8 -4
  204. adam/utils_k8s/service_accounts.py +170 -0
  205. {walker/k8s_utils → adam/utils_k8s}/services.py +3 -4
  206. {walker/k8s_utils → adam/utils_k8s}/statefulsets.py +6 -16
  207. {walker/k8s_utils → adam/utils_k8s}/volumes.py +10 -1
  208. adam/utils_net.py +24 -0
  209. adam/utils_repl/__init__.py +0 -0
  210. adam/utils_repl/automata_completer.py +48 -0
  211. adam/utils_repl/repl_completer.py +46 -0
  212. adam/utils_repl/state_machine.py +173 -0
  213. adam/utils_sqlite.py +109 -0
  214. adam/version.py +5 -0
  215. {kaqing-1.77.0.dist-info → kaqing-2.0.171.dist-info}/METADATA +1 -1
  216. kaqing-2.0.171.dist-info/RECORD +236 -0
  217. kaqing-2.0.171.dist-info/entry_points.txt +3 -0
  218. kaqing-2.0.171.dist-info/top_level.txt +1 -0
  219. kaqing-1.77.0.dist-info/RECORD +0 -159
  220. kaqing-1.77.0.dist-info/entry_points.txt +0 -3
  221. kaqing-1.77.0.dist-info/top_level.txt +0 -1
  222. walker/__init__.py +0 -3
  223. walker/app_session.py +0 -168
  224. walker/checks/check_utils.py +0 -97
  225. walker/columns/columns.py +0 -43
  226. walker/commands/add_user.py +0 -68
  227. walker/commands/app.py +0 -67
  228. walker/commands/bash.py +0 -87
  229. walker/commands/cd.py +0 -115
  230. walker/commands/check.py +0 -68
  231. walker/commands/command.py +0 -104
  232. walker/commands/cp.py +0 -95
  233. walker/commands/cql_utils.py +0 -53
  234. walker/commands/devices.py +0 -89
  235. walker/commands/frontend/code_stop.py +0 -57
  236. walker/commands/frontend/setup.py +0 -60
  237. walker/commands/frontend/setup_frontend.py +0 -58
  238. walker/commands/frontend/teardown.py +0 -61
  239. walker/commands/frontend/teardown_frontend.py +0 -42
  240. walker/commands/issues.py +0 -69
  241. walker/commands/login.py +0 -72
  242. walker/commands/ls.py +0 -145
  243. walker/commands/medusa/medusa.py +0 -69
  244. walker/commands/medusa/medusa_backup.py +0 -61
  245. walker/commands/medusa/medusa_restore.py +0 -86
  246. walker/commands/medusa/medusa_show_backupjobs.py +0 -52
  247. walker/commands/medusa/medusa_show_restorejobs.py +0 -52
  248. walker/commands/param_set.py +0 -44
  249. walker/commands/postgres/postgres.py +0 -113
  250. walker/commands/postgres/postgres_session.py +0 -225
  251. walker/commands/preview_table.py +0 -98
  252. walker/commands/processes.py +0 -53
  253. walker/commands/pwd.py +0 -64
  254. walker/commands/reaper/reaper.py +0 -78
  255. walker/commands/reaper/reaper_forward.py +0 -100
  256. walker/commands/reaper/reaper_run_abort.py +0 -65
  257. walker/commands/reaper/reaper_runs.py +0 -97
  258. walker/commands/reaper/reaper_runs_abort.py +0 -83
  259. walker/commands/reaper/reaper_schedule_activate.py +0 -64
  260. walker/commands/reaper/reaper_schedule_start.py +0 -64
  261. walker/commands/reaper/reaper_schedule_stop.py +0 -64
  262. walker/commands/reaper/reaper_session.py +0 -159
  263. walker/commands/repair/repair.py +0 -68
  264. walker/commands/repair/repair_run.py +0 -72
  265. walker/commands/repair/repair_scan.py +0 -79
  266. walker/commands/report.py +0 -57
  267. walker/commands/restart.py +0 -61
  268. walker/commands/show/show.py +0 -72
  269. walker/commands/show/show_app_actions.py +0 -53
  270. walker/commands/show/show_cassandra_status.py +0 -35
  271. walker/commands/show/show_commands.py +0 -58
  272. walker/commands/show/show_processes.py +0 -35
  273. walker/commands/show/show_repairs.py +0 -47
  274. walker/commands/status.py +0 -128
  275. walker/commands/storage.py +0 -52
  276. walker/commands/user_entry.py +0 -69
  277. walker/commands/watch.py +0 -85
  278. walker/embedded_params.py +0 -2
  279. walker/k8s_utils/cassandra_clusters.py +0 -48
  280. walker/k8s_utils/cassandra_nodes.py +0 -26
  281. walker/k8s_utils/pods.py +0 -211
  282. walker/repl.py +0 -165
  283. walker/repl_commands.py +0 -58
  284. walker/repl_state.py +0 -211
  285. walker/sso/authn_ad.py +0 -94
  286. walker/sso/idp.py +0 -150
  287. walker/sso/idp_login.py +0 -29
  288. walker/sso/sso_config.py +0 -45
  289. walker/utils.py +0 -194
  290. walker/version.py +0 -5
  291. {walker → adam}/checks/__init__.py +0 -0
  292. {walker → adam}/checks/check_context.py +0 -0
  293. {walker → adam}/checks/issue.py +0 -0
  294. {walker → adam}/cli_group.py +0 -0
  295. {walker → adam}/columns/__init__.py +0 -0
  296. {walker/commands → adam/commands/audit}/__init__.py +0 -0
  297. {walker/commands/frontend → adam/commands/cql}/__init__.py +0 -0
  298. {walker/commands/medusa → adam/commands/deploy}/__init__.py +0 -0
  299. {walker/commands/postgres → adam/commands/devices}/__init__.py +0 -0
  300. {walker/commands/reaper → adam/commands/export}/__init__.py +0 -0
  301. {walker/commands/repair → adam/commands/medusa}/__init__.py +0 -0
  302. {walker → adam}/commands/nodetool_commands.py +0 -0
  303. {walker/commands/show → adam/commands/postgres}/__init__.py +0 -0
  304. {walker/k8s_utils → adam/commands/reaper}/__init__.py +0 -0
  305. {walker/sso → adam/commands/repair}/__init__.py +0 -0
  306. /walker/medusa_show_restorejobs.py → /adam/commands/show/__init__.py +0 -0
  307. {walker → adam}/repl_session.py +0 -0
  308. {kaqing-1.77.0.dist-info → kaqing-2.0.171.dist-info}/WHEEL +0 -0
@@ -0,0 +1,53 @@
1
+ from adam.commands import extract_options
2
+ from adam.commands.command import Command
3
+ from adam.commands.cql.utils_cql import cassandra_keyspaces, cassandra_table_names
4
+ from adam.commands.export.export_databases import ExportDatabases
5
+ from adam.commands.export.export_handlers import export
6
+ 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
+
11
+ class ExportTables(Command):
12
+ COMMAND = 'export'
13
+
14
+ # the singleton pattern
15
+ def __new__(cls, *args, **kwargs):
16
+ if not hasattr(cls, 'instance'): cls.instance = super(ExportTables, cls).__new__(cls)
17
+
18
+ return cls.instance
19
+
20
+ def __init__(self, successor: Command=None):
21
+ super().__init__(successor)
22
+
23
+ def command(self):
24
+ return ExportTables.COMMAND
25
+
26
+ def required(self):
27
+ return RequiredState.CLUSTER_OR_POD
28
+
29
+ def run(self, cmd: str, state: ReplState):
30
+ if not(args := self.args(cmd)):
31
+ return super().run(cmd, state)
32
+
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)
37
+
38
+ 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
+ return {}
51
+
52
+ def help(self, _: ReplState):
53
+ 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,170 @@
1
+ import os
2
+ import boto3
3
+
4
+ from adam.commands.export.utils_export import ExportTableStatus
5
+ from adam.config import Config
6
+ from adam.utils import lines_to_tabular, log, log2, ing
7
+ from adam.utils_athena import Athena
8
+ from adam.utils_k8s.statefulsets import StatefulSets
9
+ from adam.utils_sqlite import SQLite
10
+
11
+ LIKE = 'e%_%'
12
+
13
+ class ExportDatabases:
14
+ def run_query(query: str, database: str, show_query=False) -> int:
15
+ cnt: int = 0
16
+
17
+ if show_query:
18
+ log2(query)
19
+
20
+ if database.startswith('s'):
21
+ cnt += SQLite.run_query(query, database=database)
22
+ else:
23
+ cnt += Athena.run_query(query, database=database)
24
+
25
+ return cnt
26
+
27
+ def sessions_from_dbs(dbs: list[str]):
28
+
29
+ sessions = set()
30
+
31
+ for db in dbs:
32
+ sessions.add(db.split('_')[0])
33
+
34
+ return list(sessions)
35
+
36
+ def drop_export_dbs(db: str = None):
37
+ dbs: list[str] = []
38
+
39
+ if not db or db.startswith('s'):
40
+ dbs.extend(ExportDatabases.drop_sqlite_dbs(db))
41
+ if not db or db.startswith('e'):
42
+ dbs.extend(ExportDatabases.drop_athena_dbs(db))
43
+
44
+ return dbs
45
+
46
+ def drop_sqlite_dbs(db: str = None):
47
+ dbs = SQLite.database_names(db)
48
+ if dbs:
49
+ with ing(f'Droping {len(dbs)} SQLite databases'):
50
+ try:
51
+ for db in dbs:
52
+ file_path = f'{SQLite.local_db_dir()}/{db}'
53
+ try:
54
+ os.remove(file_path)
55
+ except OSError as e:
56
+ pass
57
+ except:
58
+ pass
59
+
60
+ return dbs
61
+
62
+ def drop_athena_dbs(db: str = None):
63
+ dbs = Athena.database_names(f'{db}_%' if db else LIKE)
64
+ if dbs:
65
+ with ing(f'Droping {len(dbs)} Athena databases'):
66
+ for db in dbs:
67
+ query = f'DROP DATABASE {db} CASCADE'
68
+ if Config().is_debug():
69
+ log2(query)
70
+ Athena.query(query)
71
+
72
+ with ing(f'Deleting s3 folder: export'):
73
+ try:
74
+ if not db:
75
+ db = ''
76
+
77
+ s3 = boto3.resource('s3')
78
+ bucket = s3.Bucket(Config().get('export.bucket', 'c3.ops--qing'))
79
+ bucket.objects.filter(Prefix=f'export/{db}').delete()
80
+ except:
81
+ pass
82
+
83
+ return dbs
84
+
85
+ def display_export_db(export_session: str):
86
+ if not export_session:
87
+ return
88
+
89
+ Athena.clear_cache()
90
+
91
+ keyspaces = {}
92
+ for table in ExportDatabases.table_names(export_session):
93
+ keyspace = table.split('.')[0]
94
+ if keyspace in keyspaces:
95
+ keyspaces[keyspace] += 1
96
+ else:
97
+ keyspaces[keyspace] = 1
98
+
99
+ log(lines_to_tabular([f'{k},{v}' for k, v in keyspaces.items()], header='SCHEMA,# of TABLES', separator=','))
100
+
101
+ def disply_export_session(sts: str, pod: str, namespace: str, session: str):
102
+ if not pod:
103
+ pod = StatefulSets.pod_names(sts, namespace)[0]
104
+
105
+ if not pod:
106
+ return
107
+
108
+ tables, _ = ExportTableStatus.from_session(sts, pod, namespace, session)
109
+ log()
110
+ 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'))
111
+
112
+ def database_names():
113
+ return ExportDatabases.copy_database_names() + ExportDatabases.export_database_names()
114
+
115
+ def copy_database_names():
116
+ return list({n.split('_')[0] for n in SQLite.database_names()})
117
+
118
+ def export_database_names():
119
+ return list({n.split('_')[0] for n in Athena.database_names(LIKE)})
120
+
121
+ def database_names_with_keyspace_cnt(importer: str = None):
122
+ r = {}
123
+
124
+ names = []
125
+ if not importer:
126
+ names = SQLite.database_names() + Athena.database_names(LIKE)
127
+ elif importer == 'athena':
128
+ names = Athena.database_names(LIKE)
129
+ else:
130
+ names = SQLite.database_names()
131
+
132
+ for n in names:
133
+ tokens = n.split('_')
134
+ name = tokens[0]
135
+ keyspace = None
136
+ if len(tokens) > 1:
137
+ keyspace = tokens[1].replace('.db', '')
138
+
139
+ if keyspace == 'root':
140
+ continue
141
+
142
+ if name in r:
143
+ r[name] += 1
144
+ else:
145
+ r[name] = 1
146
+
147
+ return r
148
+
149
+ def table_names(session: str):
150
+ tables = []
151
+
152
+ for session in ExportDatabases._session_database_names(session):
153
+ if session.startswith('s'):
154
+ for table in SQLite.table_names(database=session):
155
+ tables.append(f'{SQLite.keyspace(session)}.{table}')
156
+ else:
157
+ for table in Athena.table_names(database=session, function='export'):
158
+ tables.append(f'{session}.{table}')
159
+
160
+ return tables
161
+
162
+ def _session_database_names(db: str):
163
+ eprefix = db
164
+ if '_' in db:
165
+ eprefix = db.split('_')[0]
166
+
167
+ if db.startswith('s'):
168
+ return SQLite.database_names(prefix=f'{eprefix}_')
169
+ else:
170
+ return Athena.database_names(like=f'{eprefix}_%')
@@ -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)
@@ -0,0 +1,81 @@
1
+ from adam.commands.command import Command
2
+ from adam.commands.export.export_databases import ExportDatabases
3
+ from adam.repl_state import ReplState, RequiredState
4
+ from adam.sql.sql_completer import SqlCompleter, SqlVariant
5
+ from adam.utils import log2
6
+ from adam.utils_athena import Athena
7
+
8
+ class ExportSelect(Command):
9
+ COMMAND = '.select'
10
+
11
+ # the singleton pattern
12
+ def __new__(cls, *args, **kwargs):
13
+ if not hasattr(cls, 'instance'): cls.instance = super(ExportSelect, cls).__new__(cls)
14
+
15
+ return cls.instance
16
+
17
+ def __init__(self, successor: Command=None):
18
+ super().__init__(successor)
19
+
20
+ def command(self):
21
+ return ExportSelect.COMMAND
22
+
23
+ def required(self):
24
+ return RequiredState.EXPORT_DB
25
+
26
+ def run(self, cmd: str, state: ReplState):
27
+ if not(args := self.args(cmd)):
28
+ return super().run(cmd, state)
29
+
30
+ with self.validate(args, state) as (args, state):
31
+ if not state.export_session:
32
+ if state.in_repl:
33
+ if state.device == ReplState.C:
34
+ log2("Select an export database first with 'use' command.")
35
+ else:
36
+ log2('cd to an export database first.')
37
+ else:
38
+ log2('* export database is missing.')
39
+
40
+ Command.display_help()
41
+
42
+ return 'command-missing'
43
+
44
+ if not args:
45
+ if state.in_repl:
46
+ log2('Use a SQL statement.')
47
+ else:
48
+ log2('* SQL statement is missing.')
49
+
50
+ Command.display_help()
51
+
52
+ return 'command-missing'
53
+
54
+ query = ' '.join(args)
55
+
56
+ ExportDatabases.run_query(f'select {query}', database=state.export_session)
57
+
58
+ return state
59
+
60
+ def completion(self, state: ReplState):
61
+ if not state.export_session:
62
+ return {}
63
+
64
+ db = state.export_session
65
+
66
+ # warm up the caches first time when x: drive is accessed
67
+ ExportDatabases.table_names(db)
68
+ Athena.column_names(database=db, function='export')
69
+ Athena.column_names(partition_cols_only=True, database=db, function='export')
70
+
71
+ return {ExportSelect.COMMAND: SqlCompleter(
72
+ lambda: ExportDatabases.table_names(db),
73
+ dml='select',
74
+ expandables={
75
+ 'columns':lambda table: Athena.column_names(database=db, function='export'),
76
+ },
77
+ variant=SqlVariant.ATHENA
78
+ )}
79
+
80
+ def help(self, _: ReplState):
81
+ return f'.<sql-select-statements>\t run queries on export database'
@@ -0,0 +1,54 @@
1
+ from adam.commands.command import Command
2
+ from adam.commands.export.export_databases import ExportDatabases
3
+ from adam.repl_state import ReplState, RequiredState
4
+ from adam.sql.sql_completer import SqlCompleter, SqlVariant
5
+ from adam.utils_athena import Athena
6
+
7
+ # No action body, only for a help entry and auto-completion
8
+ class ExportSelectX(Command):
9
+ COMMAND = 'select_on_x'
10
+
11
+ # the singleton pattern
12
+ def __new__(cls, *args, **kwargs):
13
+ if not hasattr(cls, 'instance'): cls.instance = super(ExportSelectX, cls).__new__(cls)
14
+
15
+ return cls.instance
16
+
17
+ def __init__(self, successor: Command=None):
18
+ super().__init__(successor)
19
+
20
+ def command(self):
21
+ return ExportSelectX.COMMAND
22
+
23
+ def required(self):
24
+ return RequiredState.EXPORT_DB
25
+
26
+ def completion(self, state: ReplState):
27
+ completions = {}
28
+
29
+ if state.device == ReplState.X:
30
+ completions = {'drop': SqlCompleter(
31
+ lambda: ExportDatabases.table_names(state.export_session),
32
+ dml='drop',
33
+ expandables={
34
+ 'export-dbs': lambda: ExportDatabases.database_names(),
35
+ 'columns':lambda _: Athena.column_names(database=state.export_session, function='export'),
36
+ },
37
+ variant=SqlVariant.ATHENA
38
+ )}
39
+
40
+ if state.export_session:
41
+ completions |= {'select': SqlCompleter(
42
+ lambda: ExportDatabases.table_names(state.export_session),
43
+ dml='select',
44
+ expandables={
45
+ 'export-dbs': lambda: ExportDatabases.database_names(),
46
+ 'columns':lambda _: Athena.column_names(database=state.export_session, function='export'),
47
+ },
48
+ variant=SqlVariant.ATHENA
49
+ )}
50
+
51
+ return completions
52
+
53
+ def help(self, _: ReplState):
54
+ return f'<sql-select-statements>\t run queries on export database'
@@ -0,0 +1,52 @@
1
+ from adam.commands.command import Command
2
+ from adam.commands.export.export_databases import ExportDatabases
3
+ from adam.repl_state import ReplState
4
+ from adam.utils import log2
5
+ from adam.utils_athena import Athena
6
+ from adam.utils_sqlite import SQLite
7
+
8
+ class ExportUse(Command):
9
+ COMMAND = 'use'
10
+
11
+ # the singleton pattern
12
+ def __new__(cls, *args, **kwargs):
13
+ if not hasattr(cls, 'instance'): cls.instance = super(ExportUse, cls).__new__(cls)
14
+
15
+ return cls.instance
16
+
17
+ def __init__(self, successor: Command=None):
18
+ super().__init__(successor)
19
+
20
+ def command(self):
21
+ return ExportUse.COMMAND
22
+
23
+ def required(self):
24
+ return [ReplState.C, ReplState.X]
25
+
26
+ def run(self, cmd: str, state: ReplState):
27
+ if not(args := self.args(cmd)):
28
+ return super().run(cmd, state)
29
+
30
+ with self.validate(args, state) as (args, state):
31
+ if not args:
32
+ state.export_session = None
33
+
34
+ log2('Export database is unset.')
35
+
36
+ return state
37
+
38
+ state.export_session = args[0]
39
+ if state.export_session.startswith('e'):
40
+ Athena.clear_cache()
41
+ else:
42
+ SQLite.clear_cache()
43
+
44
+ ExportDatabases.display_export_db(state.export_session)
45
+
46
+ return state
47
+
48
+ def completion(self, state: ReplState):
49
+ return super().completion(state, {n: None for n in ExportDatabases.database_names()})
50
+
51
+ def help(self, _: ReplState):
52
+ return f'{ExportUse.COMMAND} <export-database-name>\t use export database'