kaqing 2.0.110__py3-none-any.whl → 2.0.184__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.

Files changed (204) hide show
  1. adam/__init__.py +0 -2
  2. adam/app_session.py +9 -12
  3. adam/apps.py +18 -4
  4. adam/batch.py +5 -5
  5. adam/checks/check_utils.py +16 -46
  6. adam/checks/cpu.py +7 -1
  7. adam/checks/cpu_metrics.py +52 -0
  8. adam/checks/disk.py +2 -3
  9. adam/columns/columns.py +3 -1
  10. adam/columns/cpu.py +3 -1
  11. adam/columns/cpu_metrics.py +22 -0
  12. adam/columns/memory.py +3 -4
  13. adam/commands/__init__.py +24 -0
  14. adam/commands/alter_tables.py +33 -48
  15. adam/commands/app/__init__.py +0 -0
  16. adam/commands/app/app.py +38 -0
  17. adam/commands/{app_ping.py → app/app_ping.py} +7 -13
  18. adam/commands/app/show_app_actions.py +49 -0
  19. adam/commands/{show → app}/show_app_id.py +8 -11
  20. adam/commands/{show → app}/show_app_queues.py +7 -14
  21. adam/commands/app/utils_app.py +98 -0
  22. adam/commands/audit/audit.py +27 -31
  23. adam/commands/audit/audit_repair_tables.py +14 -18
  24. adam/commands/audit/audit_run.py +16 -23
  25. adam/commands/audit/show_last10.py +4 -17
  26. adam/commands/audit/show_slow10.py +4 -17
  27. adam/commands/audit/show_top10.py +4 -16
  28. adam/commands/audit/utils_show_top10.py +15 -3
  29. adam/commands/bash/__init__.py +5 -0
  30. adam/commands/bash/bash.py +36 -0
  31. adam/commands/bash/bash_completer.py +93 -0
  32. adam/commands/bash/utils_bash.py +16 -0
  33. adam/commands/cat.py +36 -0
  34. adam/commands/cd.py +11 -95
  35. adam/commands/check.py +15 -24
  36. adam/commands/cli_commands.py +2 -3
  37. adam/commands/clipboard_copy.py +86 -0
  38. adam/commands/code.py +57 -0
  39. adam/commands/command.py +198 -40
  40. adam/commands/commands_utils.py +12 -27
  41. adam/commands/cql/cql_completions.py +27 -10
  42. adam/commands/cql/cqlsh.py +12 -30
  43. adam/commands/cql/utils_cql.py +297 -0
  44. adam/commands/deploy/code_start.py +7 -10
  45. adam/commands/deploy/code_stop.py +4 -21
  46. adam/commands/deploy/code_utils.py +3 -3
  47. adam/commands/deploy/deploy.py +4 -27
  48. adam/commands/deploy/deploy_frontend.py +14 -17
  49. adam/commands/deploy/deploy_pg_agent.py +3 -6
  50. adam/commands/deploy/deploy_pod.py +65 -73
  51. adam/commands/deploy/deploy_utils.py +14 -24
  52. adam/commands/deploy/undeploy.py +4 -27
  53. adam/commands/deploy/undeploy_frontend.py +4 -7
  54. adam/commands/deploy/undeploy_pg_agent.py +6 -8
  55. adam/commands/deploy/undeploy_pod.py +11 -12
  56. adam/commands/devices/__init__.py +0 -0
  57. adam/commands/devices/device.py +123 -0
  58. adam/commands/devices/device_app.py +163 -0
  59. adam/commands/devices/device_auit_log.py +49 -0
  60. adam/commands/devices/device_cass.py +179 -0
  61. adam/commands/devices/device_export.py +84 -0
  62. adam/commands/devices/device_postgres.py +150 -0
  63. adam/commands/devices/devices.py +25 -0
  64. adam/commands/download_file.py +47 -0
  65. adam/commands/exit.py +1 -4
  66. adam/commands/export/__init__.py +0 -0
  67. adam/commands/export/clean_up_all_export_sessions.py +37 -0
  68. adam/commands/export/clean_up_export_sessions.py +39 -0
  69. adam/commands/export/download_export_session.py +39 -0
  70. adam/commands/export/drop_export_database.py +39 -0
  71. adam/commands/export/drop_export_databases.py +37 -0
  72. adam/commands/export/export.py +53 -0
  73. adam/commands/export/export_databases.py +245 -0
  74. adam/commands/export/export_select.py +59 -0
  75. adam/commands/export/export_select_x.py +54 -0
  76. adam/commands/export/export_sessions.py +209 -0
  77. adam/commands/export/export_use.py +49 -0
  78. adam/commands/export/exporter.py +332 -0
  79. adam/commands/export/import_files.py +44 -0
  80. adam/commands/export/import_session.py +44 -0
  81. adam/commands/export/importer.py +81 -0
  82. adam/commands/export/importer_athena.py +177 -0
  83. adam/commands/export/importer_sqlite.py +67 -0
  84. adam/commands/export/show_column_counts.py +45 -0
  85. adam/commands/export/show_export_databases.py +38 -0
  86. adam/commands/export/show_export_session.py +39 -0
  87. adam/commands/export/show_export_sessions.py +37 -0
  88. adam/commands/export/utils_export.py +343 -0
  89. adam/commands/find_files.py +51 -0
  90. adam/commands/find_processes.py +76 -0
  91. adam/commands/head.py +36 -0
  92. adam/commands/help.py +5 -3
  93. adam/commands/intermediate_command.py +49 -0
  94. adam/commands/issues.py +11 -43
  95. adam/commands/kubectl.py +38 -0
  96. adam/commands/login.py +22 -24
  97. adam/commands/logs.py +3 -6
  98. adam/commands/ls.py +11 -116
  99. adam/commands/medusa/medusa.py +4 -22
  100. adam/commands/medusa/medusa_backup.py +20 -27
  101. adam/commands/medusa/medusa_restore.py +38 -37
  102. adam/commands/medusa/medusa_show_backupjobs.py +16 -18
  103. adam/commands/medusa/medusa_show_restorejobs.py +13 -18
  104. adam/commands/nodetool.py +11 -17
  105. adam/commands/param_get.py +11 -14
  106. adam/commands/param_set.py +8 -12
  107. adam/commands/postgres/postgres.py +45 -46
  108. adam/commands/postgres/postgres_databases.py +269 -0
  109. adam/commands/postgres/postgres_ls.py +4 -8
  110. adam/commands/postgres/postgres_preview.py +5 -9
  111. adam/commands/postgres/psql_completions.py +4 -3
  112. adam/commands/postgres/utils_postgres.py +70 -0
  113. adam/commands/preview_table.py +8 -44
  114. adam/commands/pwd.py +14 -46
  115. adam/commands/reaper/reaper.py +4 -27
  116. adam/commands/reaper/reaper_forward.py +49 -56
  117. adam/commands/reaper/reaper_forward_session.py +6 -0
  118. adam/commands/reaper/reaper_forward_stop.py +10 -16
  119. adam/commands/reaper/reaper_restart.py +7 -14
  120. adam/commands/reaper/reaper_run_abort.py +8 -33
  121. adam/commands/reaper/reaper_runs.py +43 -58
  122. adam/commands/reaper/reaper_runs_abort.py +29 -49
  123. adam/commands/reaper/reaper_schedule_activate.py +9 -32
  124. adam/commands/reaper/reaper_schedule_start.py +9 -32
  125. adam/commands/reaper/reaper_schedule_stop.py +9 -32
  126. adam/commands/reaper/reaper_schedules.py +4 -14
  127. adam/commands/reaper/reaper_status.py +8 -16
  128. adam/commands/reaper/utils_reaper.py +194 -0
  129. adam/commands/repair/repair.py +4 -22
  130. adam/commands/repair/repair_log.py +5 -11
  131. adam/commands/repair/repair_run.py +27 -34
  132. adam/commands/repair/repair_scan.py +32 -38
  133. adam/commands/repair/repair_stop.py +5 -11
  134. adam/commands/report.py +27 -29
  135. adam/commands/restart.py +25 -26
  136. adam/commands/rollout.py +19 -24
  137. adam/commands/shell.py +12 -4
  138. adam/commands/show/show.py +10 -25
  139. adam/commands/show/show_adam.py +3 -3
  140. adam/commands/show/show_cassandra_repairs.py +35 -0
  141. adam/commands/show/show_cassandra_status.py +33 -51
  142. adam/commands/show/show_cassandra_version.py +5 -18
  143. adam/commands/show/show_commands.py +20 -25
  144. adam/commands/show/show_host.py +1 -1
  145. adam/commands/show/show_login.py +20 -27
  146. adam/commands/show/show_params.py +2 -5
  147. adam/commands/show/show_processes.py +15 -19
  148. adam/commands/show/show_storage.py +10 -20
  149. adam/commands/watch.py +26 -29
  150. adam/config.py +5 -14
  151. adam/embedded_params.py +1 -1
  152. adam/log.py +4 -4
  153. adam/pod_exec_result.py +6 -3
  154. adam/repl.py +69 -115
  155. adam/repl_commands.py +52 -19
  156. adam/repl_state.py +161 -40
  157. adam/sql/sql_completer.py +52 -27
  158. adam/sql/sql_state_machine.py +131 -19
  159. adam/sso/authn_ad.py +6 -8
  160. adam/sso/authn_okta.py +4 -6
  161. adam/sso/cred_cache.py +3 -5
  162. adam/sso/idp.py +9 -12
  163. adam/utils.py +511 -9
  164. adam/utils_athena.py +145 -0
  165. adam/utils_audits.py +12 -103
  166. adam/utils_issues.py +32 -0
  167. adam/utils_k8s/app_clusters.py +28 -0
  168. adam/utils_k8s/app_pods.py +36 -0
  169. adam/utils_k8s/cassandra_clusters.py +30 -19
  170. adam/utils_k8s/cassandra_nodes.py +3 -3
  171. adam/utils_k8s/custom_resources.py +16 -17
  172. adam/utils_k8s/ingresses.py +2 -2
  173. adam/utils_k8s/jobs.py +7 -11
  174. adam/utils_k8s/k8s.py +87 -0
  175. adam/utils_k8s/kube_context.py +2 -2
  176. adam/utils_k8s/pods.py +89 -78
  177. adam/utils_k8s/secrets.py +4 -4
  178. adam/utils_k8s/service_accounts.py +5 -4
  179. adam/utils_k8s/services.py +2 -2
  180. adam/utils_k8s/statefulsets.py +1 -12
  181. adam/utils_local.py +4 -0
  182. adam/utils_net.py +4 -4
  183. adam/utils_repl/__init__.py +0 -0
  184. adam/utils_repl/automata_completer.py +48 -0
  185. adam/utils_repl/repl_completer.py +46 -0
  186. adam/utils_repl/state_machine.py +173 -0
  187. adam/utils_sqlite.py +137 -0
  188. adam/version.py +1 -1
  189. {kaqing-2.0.110.dist-info → kaqing-2.0.184.dist-info}/METADATA +1 -1
  190. kaqing-2.0.184.dist-info/RECORD +244 -0
  191. adam/commands/app.py +0 -67
  192. adam/commands/bash.py +0 -150
  193. adam/commands/cp.py +0 -95
  194. adam/commands/cql/cql_utils.py +0 -112
  195. adam/commands/devices.py +0 -118
  196. adam/commands/postgres/postgres_context.py +0 -239
  197. adam/commands/postgres/postgres_utils.py +0 -31
  198. adam/commands/reaper/reaper_session.py +0 -159
  199. adam/commands/show/show_app_actions.py +0 -56
  200. adam/commands/show/show_repairs.py +0 -47
  201. kaqing-2.0.110.dist-info/RECORD +0 -187
  202. {kaqing-2.0.110.dist-info → kaqing-2.0.184.dist-info}/WHEEL +0 -0
  203. {kaqing-2.0.110.dist-info → kaqing-2.0.184.dist-info}/entry_points.txt +0 -0
  204. {kaqing-2.0.110.dist-info → kaqing-2.0.184.dist-info}/top_level.txt +0 -0
adam/commands/command.py CHANGED
@@ -1,11 +1,12 @@
1
1
  from abc import abstractmethod
2
+ from collections.abc import Callable
2
3
  import copy
3
4
  import subprocess
4
5
  import sys
6
+ from typing import Union
5
7
 
6
- from adam.commands.command_helpers import ClusterCommandHelper
7
8
  from adam.repl_state import ReplState, RequiredState
8
- from adam.utils import lines_to_tabular, log, log2
9
+ from adam.utils import is_lambda, log2
9
10
 
10
11
  repl_cmds: list['Command'] = []
11
12
 
@@ -28,10 +29,30 @@ class Command:
28
29
 
29
30
  return None
30
31
 
31
- def completion(self, state: ReplState, leaf: dict[str, any] = None) -> dict[str, any]:
32
- if not self.validate_state(state, show_err=False):
32
+ def completion(self, state: ReplState, leaf: dict[str, any] = None, pods: tuple[list[str], str] = None) -> dict[str, any]:
33
+ # pods is a tuple of list of pod names and the current pod repl is on
34
+ if not pods:
35
+ return self._completion(state, leaf)
36
+
37
+ c = {}
38
+
39
+ pod_names = pods[0]
40
+ pod = pods[1]
41
+
42
+ if pod:
43
+ c |= self._completion(state, leaf)
44
+
45
+ c |= {f'@{p}': self._completion(state, leaf, to_validate=False) for p in pod_names if p != pod}
46
+
47
+ return c
48
+
49
+ def _completion(self, state: ReplState, leaf: dict[str, any] = None, to_validate = True) -> dict[str, any]:
50
+ if to_validate and not self.validate_state(state, show_err=False):
33
51
  return {}
34
52
 
53
+ if is_lambda(leaf):
54
+ leaf = leaf()
55
+
35
56
  d = leaf
36
57
  for t in reversed(self.command().split(' ')):
37
58
  d = {t: d}
@@ -41,7 +62,10 @@ class Command:
41
62
  def required(self) -> RequiredState:
42
63
  return None
43
64
 
44
- def validate_state(self, state: ReplState, show_err=True):
65
+ def validate(self, args: list[str], state: ReplState, apply = True):
66
+ return ValidateStateHandler(self, args, state, apply = apply)
67
+
68
+ def validate_state(self, state: ReplState, show_err = True):
45
69
  return state.validate(self.required(), show_err=show_err)
46
70
 
47
71
  def help(self, _: ReplState) -> str:
@@ -56,6 +80,9 @@ class Command:
56
80
  return a
57
81
 
58
82
  def apply_state(self, args: list[str], state: ReplState, resolve_pg = True, args_to_check = 6) -> tuple[ReplState, list[str]]:
83
+ """
84
+ Applies any contextual arguments such as namespace or statefulset to the ReplState and returns any non-contextual arguments.
85
+ """
59
86
  return state.apply_args(args, cmd=self.command_tokens(), resolve_pg=resolve_pg, args_to_check=args_to_check)
60
87
 
61
88
  def command_tokens(self):
@@ -87,17 +114,50 @@ class Command:
87
114
  args.extend(['--help'])
88
115
  subprocess.run(args)
89
116
 
90
- def extract_options(args: list[str], names: list[str]):
91
- found: list[str] = []
117
+ def extract_options(args: list[str], trailing: Union[str, list[str]] = [], sequence: list[str] = [], options: list[str] = []):
118
+ found_options: list[str] = []
119
+ found_trailing = None
120
+ found_sequence = None
121
+
122
+ if trailing is None:
123
+ trailing = []
124
+ elif isinstance(trailing, str):
125
+ trailing = [trailing]
126
+
127
+ if options is None:
128
+ options = []
129
+ elif isinstance(options, str):
130
+ options = [options]
131
+
132
+ if args and trailing:
133
+ while args[-1] in trailing:
134
+ found_trailing = True
135
+ args = args[:-1]
136
+
137
+ if args and sequence:
138
+ args, found_sequence = Command.extract_option_sequence(args, sequence)
92
139
 
93
140
  new_args: list[str] = []
94
- for arg in args:
95
- if arg in names:
96
- found.append(arg)
97
- else:
98
- new_args.append(arg)
141
+ if args:
142
+ for arg in args:
143
+ if arg in options:
144
+ found_options.append(arg)
145
+ else:
146
+ new_args.append(arg)
147
+
148
+ return new_args, found_trailing, found_sequence, found_options
149
+
150
+ def extract_option_sequence(args, sequence):
151
+ len_sub = len(sequence)
152
+ len_main = len(args)
153
+ for i in range(len_main - len_sub + 1):
154
+ if args[i:i+len_sub] == sequence:
155
+ new_args = copy.copy(args)
156
+ del new_args[i:i+len_sub]
99
157
 
100
- return new_args, found
158
+ return new_args, True
159
+
160
+ return new_args, False
101
161
 
102
162
  def print_chain(cmd: 'Command'):
103
163
  print(f'{cmd.command()}', end = '')
@@ -106,31 +166,129 @@ class Command:
106
166
  cmd = s
107
167
  print()
108
168
 
109
- def intermediate_run(self, cmd: str, state: ReplState, args: list[str], cmds: list['Command'], separator='\t', display_help=True):
110
- state, _ = self.apply_state(args, state)
111
-
112
- if state.in_repl:
113
- if display_help:
114
- log(lines_to_tabular([c.help(state) for c in cmds], separator=separator))
115
-
116
- return 'command-missing'
169
+ class InvalidStateException(Exception):
170
+ def __init__(self, state: ReplState):
171
+ super().__init__(f'Invalid state')
172
+
173
+ class ValidateStateHandler:
174
+ def __init__(self, cmd: Command, args: list[str], state: ReplState, apply = True):
175
+ self.cmd = cmd
176
+ self.args = args
177
+ self.state = state
178
+ self.apply = apply
179
+
180
+ def __enter__(self) -> tuple[list[str], ReplState]:
181
+ state = self.state
182
+ args = self.args
183
+ if self.apply:
184
+ state, args = self.cmd.apply_state(args, state)
117
185
  else:
118
- # head with the Chain of Responsibility pattern
119
- cmds = Command.chain(cmds)
120
- if not cmds.run(cmd, state):
121
- if display_help:
122
- log2('* Command is missing.')
123
- Command.display_help()
124
- return 'command-missing'
125
-
126
- return state
127
-
128
- def intermediate_help(super_help: str, cmd: str, cmd_list: list['Command'], separator='\t', show_cluster_help=False):
129
- log(super_help)
130
- log()
131
- log('Sub-Commands:')
132
-
133
- log(lines_to_tabular([c.help(ReplState()).replace(f'{cmd} ', ' ', 1) for c in cmd_list], separator=separator))
134
- if show_cluster_help:
135
- log()
136
- ClusterCommandHelper.cluster_help()
186
+ args = args[len(self.cmd.command_tokens()):]
187
+
188
+ if not self.cmd.validate_state(state):
189
+ raise InvalidStateException(state)
190
+
191
+ return args, state
192
+
193
+ def __exit__(self, exc_type, exc_val, exc_tb):
194
+ return False
195
+
196
+ class InvalidArgumentsException(Exception):
197
+ def __init__(self):
198
+ super().__init__(f'Invalid arguments')
199
+
200
+ class ValidateArgCountHandler:
201
+ def __init__(self, args: list[str], state: ReplState, at_least: int = 1, exactly: int = 1,
202
+ name: str = None, msg: Callable[[], None] = None, default: Union[str, list[str]] = None,
203
+ separator: str = None):
204
+ self.args = args
205
+ self.state = state
206
+ self.at_least = at_least
207
+ self.exactly = exactly
208
+ self.name = name
209
+ self.msg = msg
210
+ self.default = default
211
+ self.separator = separator
212
+
213
+ def __enter__(self) -> Union[tuple[list[str], ReplState], tuple[str, ReplState]]:
214
+ if self.exactly > 0 and len(self.args) != self.exactly or len(self.args) < self.at_least:
215
+ if self.default:
216
+ v = self.default
217
+ if isinstance(v, list):
218
+ v = ' '.join(v)
219
+
220
+ return v
221
+
222
+ if self.state.in_repl:
223
+ if self.msg:
224
+ self.msg()
225
+ elif self.name:
226
+ log2(f'{self.name} is required.')
227
+ elif self.name:
228
+ log2(f'* {self.name} is missing.')
229
+
230
+ Command.display_help()
231
+
232
+ raise InvalidArgumentsException()
233
+
234
+ if self.separator == ' ':
235
+ return self.args
236
+
237
+ # join and re-split with separator
238
+ args_to_return = ' '.join(self.args)
239
+ if self.separator:
240
+ args_to_return = [arg.strip(' ') for arg in args_to_return.split(self.separator)]
241
+
242
+ return args_to_return
243
+
244
+ def __exit__(self, exc_type, exc_val, exc_tb):
245
+ return False
246
+
247
+ class ExtractOptionsHandler:
248
+ def __init__(self, args: list[str], options: list[str] = None):
249
+ self.args = args
250
+ self.options = options
251
+
252
+ def __enter__(self) -> tuple[list[str], list[str]]:
253
+ args, _, _, options = Command.extract_options(self.args, options=self.options)
254
+ return args, options
255
+
256
+ def __exit__(self, exc_type, exc_val, exc_tb):
257
+ return False
258
+
259
+ class ExtractTrailingOptionsHandler:
260
+ def __init__(self, args: list[str], trailing: list[str] = None):
261
+ self.args = args
262
+ self.trailing = trailing
263
+
264
+ def __enter__(self) -> tuple[list[str], list[str]]:
265
+ args, trailing, _, _ = Command.extract_options(self.args, trailing=self.trailing)
266
+ return args, trailing
267
+
268
+ def __exit__(self, exc_type, exc_val, exc_tb):
269
+ return False
270
+
271
+ class ExtractAllOptionsHandler:
272
+ def __init__(self, args: list[str], trailing: list[str] = None, sequence: list[str] = None, options: list[str] = None):
273
+ self.args = args
274
+ self.trailing = trailing
275
+ self.sequence = sequence
276
+ self.options = options
277
+
278
+ def __enter__(self) -> tuple[list[str], list[str]]:
279
+ return Command.extract_options(self.args, trailing=self.trailing, sequence=self.sequence, options=self.options)
280
+
281
+ def __exit__(self, exc_type, exc_val, exc_tb):
282
+ return False
283
+
284
+ class ExtractSequenceOptionsHandler:
285
+ def __init__(self, args: list[str], sequence: list[str]):
286
+ self.args = args
287
+ self.sequence = sequence
288
+
289
+ def __enter__(self) -> tuple[list[str], list[str]]:
290
+ args, _, sequence, _ = Command.extract_options(self.args, sequence=self.sequence)
291
+ return args, sequence
292
+
293
+ def __exit__(self, exc_type, exc_val, exc_tb):
294
+ return False
@@ -1,15 +1,14 @@
1
- from concurrent.futures import ThreadPoolExecutor
2
1
  from kubernetes import client
3
2
  from typing import List
4
3
 
5
4
  from adam.checks.check_utils import run_checks
6
5
  from adam.columns.columns import Columns, collect_checks
7
- from adam.commands.issues import Issues
6
+ from adam.utils_issues import IssuesUtils
8
7
  from adam.utils_k8s.cassandra_nodes import CassandraNodes
9
8
  from adam.utils_k8s.pods import Pods
10
9
  from adam.utils_k8s.statefulsets import StatefulSets
11
10
  from adam.repl_state import ReplState
12
- from adam.utils import duration, lines_to_tabular, log, log2
11
+ from adam.utils import SORT, duration, tabulize, log, log2
13
12
 
14
13
  def show_pods(pods: List[client.V1Pod], ns: str, show_namespace = True, show_host_id = True):
15
14
  if len(pods) == 0:
@@ -20,18 +19,10 @@ def show_pods(pods: List[client.V1Pod], ns: str, show_namespace = True, show_hos
20
19
  if show_host_id:
21
20
  names = [pod.metadata.name for pod in pods]
22
21
 
23
- def get_host_id_with_pod(pod, ns):
24
- return (CassandraNodes.get_host_id(pod, ns), pod)
25
-
26
- def body(executor: ThreadPoolExecutor, pod, ns, show_out):
27
- if executor:
28
- return executor.submit(get_host_id_with_pod, pod, ns)
29
-
30
- id = CassandraNodes.get_host_id(pod, ns)
31
-
32
- return (id, pod)
33
-
34
- host_ids_by_pod = {pod: id for id, pod in Pods.on_pods(names, ns, body, action='get-host-id', show_out=False)}
22
+ msg = 'd`Retrieving|Retrived {size} host ids'
23
+ with Pods.parallelize(names, msg=msg, action = 'get-host-id') as exec:
24
+ host_pods = exec.map(lambda pod: (CassandraNodes.get_host_id(pod, ns), pod))
25
+ host_ids_by_pod = {pod: id for id, pod in host_pods}
35
26
 
36
27
  def line(pod: client.V1Pod):
37
28
  pod_cnt = len(pod.status.container_statuses)
@@ -57,9 +48,7 @@ def show_pods(pods: List[client.V1Pod], ns: str, show_namespace = True, show_hos
57
48
  line += f"@{ns}"
58
49
  return line + f" {ready}/{pod_cnt} {status}"
59
50
 
60
- pod_names = [line(pod) for pod in pods]
61
-
62
- log(lines_to_tabular(pod_names, 'HOST_ID POD_NAME READY POD_STATUS' if show_host_id else 'POD_NAME READY POD_STATUS'))
51
+ tabulize(pods, line, header='HOST_ID POD_NAME READY POD_STATUS' if show_host_id else 'POD_NAME READY POD_STATUS')
63
52
 
64
53
  def show_rollout(sts: str, ns: str):
65
54
  restarted, rollingout = StatefulSets.restarted_at(sts, ns)
@@ -70,18 +59,14 @@ def show_rollout(sts: str, ns: str):
70
59
  else:
71
60
  log2(f'Cluster has completed rollout {d} ago.')
72
61
 
73
- def show_table(state: ReplState, pods: list[str], cols: str, header: str, show_output=False):
62
+ def show_table(state: ReplState, pods: list[str], cols: str, header: str, show_out=False):
74
63
  columns = Columns.create_columns(cols)
75
64
 
76
- results = run_checks(cluster=state.sts, pod=state.pod, namespace=state.namespace, checks=collect_checks(columns), show_output=show_output)
65
+ results = run_checks(cluster=state.sts, pod=state.pod, namespace=state.namespace, checks=collect_checks(columns), show_out=show_out)
77
66
 
78
67
  def line(pod_name: str):
79
- cells = [c.pod_value(results, pod_name) for c in columns]
80
- return ','.join(cells)
81
-
82
- lines = [line(pod) for pod in pods]
83
- lines.sort()
68
+ return
84
69
 
85
- log(lines_to_tabular(lines, header, separator=','))
70
+ tabulize(pods, lambda p: ','.join([c.pod_value(results, p) for c in columns]), header=header, separator=',', sorted=SORT)
86
71
 
87
- Issues.show(results, state.in_repl)
72
+ IssuesUtils.show(results, state.in_repl)
@@ -1,15 +1,32 @@
1
- from adam.commands.cql.cql_utils import cassandra_table_names
1
+ from adam.commands.cql.utils_cql import cassandra_keyspaces, cassandra_table_names
2
+ from adam.commands.export.export_sessions import ExportSessions
3
+ from adam.commands.export.export_databases import ExportDatabases
2
4
  from adam.config import Config
3
5
  from adam.repl_state import ReplState
4
- from adam.sql.sql_completer import SqlCompleter
6
+ from adam.sql.sql_completer import SqlCompleter, SqlVariant
7
+ from adam.utils import log_timing
5
8
 
6
9
  def cql_completions(state: ReplState) -> dict[str, any]:
7
10
  ps = Config().get('cql.alter-tables.gc-grace-periods', '3600,86400,864000,7776000').split(',')
8
- return {
9
- 'describe': {
10
- 'keyspaces': None,
11
- 'table': {t: None for t in cassandra_table_names(state)},
12
- 'tables': None},
13
- } | SqlCompleter(lambda: cassandra_table_names(state), table_props=lambda: {
14
- 'GC_GRACE_SECONDS': ps
15
- }, variant='cql').completions_for_nesting()
11
+ # warm up caches
12
+ with log_timing('cassandra_keyspaces'):
13
+ cassandra_keyspaces(state)
14
+ with log_timing('cassandra_table_names'):
15
+ cassandra_table_names(state)
16
+ with log_timing('ExportDatabases.database_names'):
17
+ ExportDatabases.database_names()
18
+
19
+ expandables = {
20
+ 'keyspaces': lambda: cassandra_keyspaces(state),
21
+ 'table-props': lambda: {
22
+ 'GC_GRACE_SECONDS': ps
23
+ },
24
+ 'export-dbs': lambda: ExportDatabases.database_names(),
25
+ 'export-sessions': lambda: ExportSessions.export_session_names(state.sts, state.pod, state.namespace),
26
+ 'export-sessions-incomplete': lambda: ExportSessions.export_session_names(state.sts, state.pod, state.namespace, export_state='pending_import'),
27
+ }
28
+
29
+ return SqlCompleter(
30
+ lambda: cassandra_table_names(state),
31
+ expandables=expandables,
32
+ variant=SqlVariant.CQL).completions_for_nesting()
@@ -1,11 +1,13 @@
1
1
  import click
2
2
 
3
+ from adam.commands import extract_trailing_options
3
4
  from adam.commands.command import Command
4
5
  from adam.commands.command_helpers import ClusterOrPodCommandHelper
5
6
  from adam.commands.cql.cql_completions import cql_completions
6
- from .cql_utils import run_cql, cassandra_table_names
7
+ from adam.commands.cql.utils_cql import cassandra
8
+ from adam.utils_k8s.statefulsets import StatefulSets
7
9
  from adam.repl_state import ReplState, RequiredState
8
- from adam.utils import log, log2
10
+ from adam.utils import log
9
11
 
10
12
  class Cqlsh(Command):
11
13
  COMMAND = 'cql'
@@ -29,32 +31,10 @@ class Cqlsh(Command):
29
31
  if not(args := self.args(cmd)):
30
32
  return super().run(cmd, state)
31
33
 
32
- state, args = self.apply_state(args, state)
33
- if not self.validate_state(state):
34
- return state
35
-
36
- background = False
37
- opts = []
38
- cqls = []
39
- for index, arg in enumerate(args):
40
- if arg.startswith('--'):
41
- opts.append(arg)
42
- elif index == len(args) -1 and arg == '&':
43
- background = True
44
- elif arg != '-e':
45
- cqls.append(arg)
46
- if not cqls:
47
- if state.in_repl:
48
- log2('Please enter cql statement. e.g. select host_id from system.local')
49
- else:
50
- log2('* CQL statement is missing.')
51
- log2()
52
- Command.display_help()
53
-
54
- return 'no-cql'
55
-
56
- cql = ' '.join(cqls)
57
- return run_cql(state, cql, opts, show_out=True, background=background)
34
+ with self.validate(args, state) as (args, state):
35
+ with extract_trailing_options(args, '&') as (args, backgrounded):
36
+ with cassandra(state) as pods:
37
+ pods.cql(args, backgrounded=backgrounded)
58
38
 
59
39
  def completion(self, state: ReplState) -> dict[str, any]:
60
40
  if state.device != state.C:
@@ -62,12 +42,14 @@ class Cqlsh(Command):
62
42
  return {}
63
43
 
64
44
  if state.sts or state.pod:
65
- return {Cqlsh.COMMAND: None} | cql_completions(state)
45
+ c = cql_completions(state)
46
+ return c | \
47
+ {f'@{p}': c for p in StatefulSets.pod_names(state.sts, state.namespace)}
66
48
 
67
49
  return {}
68
50
 
69
51
  def help(self, _: ReplState) -> str:
70
- return f'[{Cqlsh.COMMAND}] <cql-statements>\t run cqlsh with queries'
52
+ return f'<cql-statements> [&]\t run cqlsh with queries'
71
53
 
72
54
  class CqlCommandHelper(click.Command):
73
55
  def get_help(self, ctx: click.Context):