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.
Files changed (194) hide show
  1. adam/app_session.py +5 -10
  2. adam/apps.py +18 -4
  3. adam/batch.py +7 -7
  4. adam/checks/check_utils.py +3 -1
  5. adam/checks/disk.py +2 -3
  6. adam/columns/memory.py +3 -4
  7. adam/commands/__init__.py +15 -6
  8. adam/commands/alter_tables.py +26 -41
  9. adam/commands/app/__init__.py +0 -0
  10. adam/commands/{app_cmd.py → app/app.py} +2 -2
  11. adam/commands/{show → app}/show_app_actions.py +7 -15
  12. adam/commands/{show → app}/show_app_queues.py +1 -4
  13. adam/{utils_app.py → commands/app/utils_app.py} +9 -1
  14. adam/commands/audit/audit.py +9 -26
  15. adam/commands/audit/audit_repair_tables.py +5 -7
  16. adam/commands/audit/audit_run.py +1 -1
  17. adam/commands/audit/completions_l.py +15 -0
  18. adam/commands/audit/show_last10.py +2 -14
  19. adam/commands/audit/show_slow10.py +2 -13
  20. adam/commands/audit/show_top10.py +2 -11
  21. adam/commands/audit/utils_show_top10.py +15 -3
  22. adam/commands/bash/bash.py +1 -1
  23. adam/commands/bash/utils_bash.py +1 -1
  24. adam/commands/cassandra/__init__.py +0 -0
  25. adam/commands/cassandra/download_cassandra_log.py +45 -0
  26. adam/commands/cassandra/nodetool.py +64 -0
  27. adam/commands/cassandra/nodetool_commands.py +120 -0
  28. adam/commands/cassandra/restart_cluster.py +47 -0
  29. adam/commands/cassandra/restart_node.py +51 -0
  30. adam/commands/cassandra/restart_nodes.py +47 -0
  31. adam/commands/cassandra/rollout.py +88 -0
  32. adam/commands/cat.py +5 -19
  33. adam/commands/cd.py +7 -9
  34. adam/commands/check.py +10 -18
  35. adam/commands/cli_commands.py +6 -1
  36. adam/commands/{cp.py → clipboard_copy.py} +34 -36
  37. adam/commands/code.py +2 -2
  38. adam/commands/command.py +139 -22
  39. adam/commands/commands_utils.py +14 -12
  40. adam/commands/cql/alter_tables.py +66 -0
  41. adam/commands/cql/completions_c.py +29 -0
  42. adam/commands/cql/cqlsh.py +3 -7
  43. adam/commands/cql/utils_cql.py +23 -61
  44. adam/commands/debug/__init__.py +0 -0
  45. adam/commands/debug/debug.py +22 -0
  46. adam/commands/debug/debug_completes.py +35 -0
  47. adam/commands/debug/debug_timings.py +35 -0
  48. adam/commands/deploy/deploy_pg_agent.py +2 -2
  49. adam/commands/deploy/deploy_pod.py +2 -4
  50. adam/commands/deploy/undeploy_pg_agent.py +2 -2
  51. adam/commands/devices/device.py +40 -9
  52. adam/commands/devices/device_app.py +19 -29
  53. adam/commands/devices/device_auit_log.py +3 -3
  54. adam/commands/devices/device_cass.py +17 -23
  55. adam/commands/devices/device_export.py +12 -11
  56. adam/commands/devices/device_postgres.py +79 -63
  57. adam/commands/devices/devices.py +1 -1
  58. adam/commands/download_cassandra_log.py +45 -0
  59. adam/commands/download_file.py +47 -0
  60. adam/commands/export/clean_up_all_export_sessions.py +3 -3
  61. adam/commands/export/clean_up_export_sessions.py +7 -19
  62. adam/commands/export/completions_x.py +11 -0
  63. adam/commands/export/download_export_session.py +40 -0
  64. adam/commands/export/drop_export_database.py +6 -22
  65. adam/commands/export/drop_export_databases.py +3 -9
  66. adam/commands/export/export.py +1 -17
  67. adam/commands/export/export_databases.py +109 -32
  68. adam/commands/export/export_select.py +8 -55
  69. adam/commands/export/export_sessions.py +211 -0
  70. adam/commands/export/export_use.py +13 -16
  71. adam/commands/export/export_x_select.py +48 -0
  72. adam/commands/export/exporter.py +176 -167
  73. adam/commands/export/import_files.py +44 -0
  74. adam/commands/export/import_session.py +10 -6
  75. adam/commands/export/importer.py +24 -9
  76. adam/commands/export/importer_athena.py +114 -44
  77. adam/commands/export/importer_sqlite.py +45 -23
  78. adam/commands/export/show_column_counts.py +11 -20
  79. adam/commands/export/show_export_databases.py +5 -2
  80. adam/commands/export/show_export_session.py +6 -15
  81. adam/commands/export/show_export_sessions.py +4 -11
  82. adam/commands/export/utils_export.py +79 -27
  83. adam/commands/find_files.py +51 -0
  84. adam/commands/find_processes.py +76 -0
  85. adam/commands/generate_report.py +52 -0
  86. adam/commands/head.py +36 -0
  87. adam/commands/help.py +2 -2
  88. adam/commands/intermediate_command.py +6 -3
  89. adam/commands/login.py +3 -6
  90. adam/commands/ls.py +2 -2
  91. adam/commands/medusa/medusa_backup.py +13 -16
  92. adam/commands/medusa/medusa_restore.py +26 -37
  93. adam/commands/medusa/medusa_show_backupjobs.py +7 -7
  94. adam/commands/medusa/medusa_show_restorejobs.py +6 -6
  95. adam/commands/medusa/utils_medusa.py +15 -0
  96. adam/commands/nodetool.py +3 -8
  97. adam/commands/os/__init__.py +0 -0
  98. adam/commands/os/cat.py +36 -0
  99. adam/commands/os/download_file.py +47 -0
  100. adam/commands/os/find_files.py +51 -0
  101. adam/commands/os/find_processes.py +76 -0
  102. adam/commands/os/head.py +36 -0
  103. adam/commands/os/shell.py +41 -0
  104. adam/commands/param_get.py +10 -12
  105. adam/commands/param_set.py +7 -10
  106. adam/commands/postgres/completions_p.py +22 -0
  107. adam/commands/postgres/postgres.py +25 -40
  108. adam/commands/postgres/postgres_databases.py +269 -0
  109. adam/commands/postgres/utils_postgres.py +33 -20
  110. adam/commands/preview_table.py +4 -2
  111. adam/commands/pwd.py +4 -6
  112. adam/commands/reaper/reaper_forward.py +2 -2
  113. adam/commands/reaper/reaper_run_abort.py +4 -10
  114. adam/commands/reaper/reaper_runs.py +3 -3
  115. adam/commands/reaper/reaper_schedule_activate.py +12 -12
  116. adam/commands/reaper/reaper_schedule_start.py +7 -12
  117. adam/commands/reaper/reaper_schedule_stop.py +7 -12
  118. adam/commands/reaper/utils_reaper.py +13 -6
  119. adam/commands/repair/repair_log.py +1 -4
  120. adam/commands/repair/repair_run.py +3 -8
  121. adam/commands/repair/repair_scan.py +1 -6
  122. adam/commands/repair/repair_stop.py +1 -5
  123. adam/commands/restart_cluster.py +47 -0
  124. adam/commands/restart_node.py +51 -0
  125. adam/commands/restart_nodes.py +47 -0
  126. adam/commands/shell.py +9 -2
  127. adam/commands/show/show.py +4 -4
  128. adam/commands/show/show_adam.py +3 -3
  129. adam/commands/show/show_cassandra_repairs.py +5 -6
  130. adam/commands/show/show_cassandra_status.py +29 -29
  131. adam/commands/show/show_cassandra_version.py +1 -4
  132. adam/commands/show/{show_commands.py → show_cli_commands.py} +3 -6
  133. adam/commands/show/show_login.py +3 -9
  134. adam/commands/show/show_params.py +2 -5
  135. adam/commands/show/show_processes.py +15 -16
  136. adam/commands/show/show_storage.py +9 -8
  137. adam/config.py +4 -5
  138. adam/embedded_params.py +1 -1
  139. adam/log.py +4 -4
  140. adam/repl.py +26 -18
  141. adam/repl_commands.py +32 -20
  142. adam/repl_session.py +9 -1
  143. adam/repl_state.py +39 -10
  144. adam/sql/async_executor.py +44 -0
  145. adam/sql/lark_completer.py +286 -0
  146. adam/sql/lark_parser.py +604 -0
  147. adam/sql/qingl.lark +1076 -0
  148. adam/sql/sql_completer.py +4 -6
  149. adam/sql/sql_state_machine.py +25 -13
  150. adam/sso/authn_ad.py +2 -5
  151. adam/sso/authn_okta.py +2 -4
  152. adam/sso/cred_cache.py +2 -5
  153. adam/sso/idp.py +8 -11
  154. adam/utils.py +299 -105
  155. adam/utils_athena.py +18 -18
  156. adam/utils_audits.py +3 -7
  157. adam/utils_issues.py +2 -2
  158. adam/utils_k8s/app_clusters.py +4 -4
  159. adam/utils_k8s/app_pods.py +8 -6
  160. adam/utils_k8s/cassandra_clusters.py +16 -5
  161. adam/utils_k8s/cassandra_nodes.py +7 -6
  162. adam/utils_k8s/custom_resources.py +11 -17
  163. adam/utils_k8s/jobs.py +7 -11
  164. adam/utils_k8s/k8s.py +14 -5
  165. adam/utils_k8s/kube_context.py +3 -6
  166. adam/{pod_exec_result.py → utils_k8s/pod_exec_result.py} +4 -4
  167. adam/utils_k8s/pods.py +98 -36
  168. adam/utils_k8s/statefulsets.py +5 -2
  169. adam/utils_local.py +42 -0
  170. adam/utils_repl/appendable_completer.py +6 -0
  171. adam/utils_repl/repl_completer.py +45 -2
  172. adam/utils_repl/state_machine.py +3 -3
  173. adam/utils_sqlite.py +58 -30
  174. adam/version.py +1 -1
  175. {kaqing-2.0.171.dist-info → kaqing-2.0.204.dist-info}/METADATA +1 -1
  176. kaqing-2.0.204.dist-info/RECORD +277 -0
  177. kaqing-2.0.204.dist-info/top_level.txt +2 -0
  178. teddy/__init__.py +0 -0
  179. teddy/lark_parser.py +436 -0
  180. teddy/lark_parser2.py +618 -0
  181. adam/commands/cql/cql_completions.py +0 -33
  182. adam/commands/export/export_handlers.py +0 -71
  183. adam/commands/export/export_select_x.py +0 -54
  184. adam/commands/logs.py +0 -37
  185. adam/commands/postgres/postgres_context.py +0 -274
  186. adam/commands/postgres/psql_completions.py +0 -10
  187. adam/commands/report.py +0 -61
  188. adam/commands/restart.py +0 -60
  189. kaqing-2.0.171.dist-info/RECORD +0 -236
  190. kaqing-2.0.171.dist-info/top_level.txt +0 -1
  191. /adam/commands/{app_ping.py → app/app_ping.py} +0 -0
  192. /adam/commands/{show → app}/show_app_id.py +0 -0
  193. {kaqing-2.0.171.dist-info → kaqing-2.0.204.dist-info}/WHEEL +0 -0
  194. {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, InvalidState
2
+ from adam.commands.command import Command
3
3
  from adam.commands.devices.device import Device
4
- from adam.commands.postgres.postgres_context import PostgresContext
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 lines_to_tabular, log, log2, wait_log
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 ls(self, cmd: str, state: ReplState):
40
- if state.pg_path:
41
- pg: PostgresContext = PostgresContext.apply(state.namespace, state.pg_path)
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 cat(self, cmd: str, state: ReplState):
50
- if state.pod:
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
- return InvalidState()
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
- def line(pg: PostgresContext):
58
- return f'{pg.path()},{pg.endpoint()}:{pg.port()},{pg.username()},{pg.password()}'
59
-
60
- lines = [line(PostgresContext.apply(state.namespace, pg)) for pg in PostgresContext.hosts(state.namespace)]
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
- def line(pg: PostgresContext):
65
- return f'{pg.path()},{pg.namespace},{pg.endpoint()}:{pg.port()},{pg.username()},{pg.password()}'
66
-
67
- lines = [line(PostgresContext.apply(state.namespace, pg)) for pg in PostgresContext.hosts(state.namespace)]
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
- else:
81
- context: PostgresContext = PostgresContext.apply(state.namespace, state.pg_path, arg=dir)
82
- # patch up state.namespace from pg cd
83
- if not state.namespace and context.namespace:
84
- state.namespace = context.namespace
85
- state.pg_path = context.path()
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
- pg: PostgresContext = PostgresContext.apply(state.namespace, state.pg_path) if state.pg_path else None
89
- if pg and pg.db:
90
- return {cmd: {'..': None}}
91
- elif pg and pg.host:
92
- return {cmd: {'..': None} | {p: None for p in pg_database_names(state.namespace, pg.path())}}
93
- else:
94
- return {cmd: {p: None for p in PostgresContext.hosts(state.namespace)}}
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
- pg: PostgresContext = PostgresContext.apply(state.namespace, state.pg_path)
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
- if pg.host:
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
- pg: PostgresContext = PostgresContext.apply(state.namespace, state.pg_path)
110
- if pg.db:
111
- return True, chain.run(f'pg {cmd}', state)
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
- pg = PostgresContext.apply(state.namespace, state.pg_path)
120
- lines = [db["name"] for db in pg.tables() if db["schema"] == PostgresContext.default_schema()]
121
- log(lines_to_tabular(lines, separator=','))
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
- PostgresContext.apply(state.namespace, state.pg_path).run_sql(f'select * from {table} limit {rows}')
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 = PostgresContext.pod_and_container(s1.namespace)
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)
@@ -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 device(state: ReplState) -> Device:
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.exporter import Exporter
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
- if Exporter.clean_up_all_sessions(state.sts, state.pod, state.namespace):
29
- Exporter.clear_export_session_cache()
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.exporter import Exporter
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
- if not args:
30
- if state.in_repl:
31
- log2('Specify export session name.')
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
- Command.display_help()
36
-
37
- return 'command-missing'
38
-
39
- sessions = [arg.strip(' ') for arg in ' '.join(args).split(',')]
40
- csv_cnt, log_cnt = Exporter.clean_up_sessions(state.sts, state.pod, state.namespace, sessions)
41
- log(f'Removed {csv_cnt} csv and {log_cnt} log files.')
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>\t clean up export session'
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.exporter import Exporter
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
- if not len(args):
32
- if state.in_repl:
33
- log2('Database name is required.')
34
- log2()
35
- else:
36
- log2('* Database name is missing.')
37
- Command.display_help()
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 'command-missing'
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.exporter import Exporter
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
- Exporter.drop_databases(state.sts, state.pod, state.namespace)
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
 
@@ -1,12 +1,7 @@
1
1
  from adam.commands import extract_options
2
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
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):