kaqing 2.0.115__py3-none-any.whl → 2.0.172__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 (187) hide show
  1. adam/__init__.py +0 -2
  2. adam/app_session.py +8 -11
  3. adam/batch.py +3 -3
  4. adam/checks/check_utils.py +14 -46
  5. adam/checks/cpu.py +7 -1
  6. adam/checks/cpu_metrics.py +52 -0
  7. adam/checks/disk.py +2 -3
  8. adam/columns/columns.py +3 -1
  9. adam/columns/cpu.py +3 -1
  10. adam/columns/cpu_metrics.py +22 -0
  11. adam/columns/memory.py +3 -4
  12. adam/commands/__init__.py +18 -0
  13. adam/commands/alter_tables.py +43 -47
  14. adam/commands/audit/audit.py +24 -25
  15. adam/commands/audit/audit_repair_tables.py +14 -17
  16. adam/commands/audit/audit_run.py +15 -23
  17. adam/commands/audit/show_last10.py +10 -13
  18. adam/commands/audit/show_slow10.py +10 -13
  19. adam/commands/audit/show_top10.py +10 -14
  20. adam/commands/audit/utils_show_top10.py +2 -3
  21. adam/commands/bash/__init__.py +5 -0
  22. adam/commands/bash/bash.py +8 -96
  23. adam/commands/bash/utils_bash.py +16 -0
  24. adam/commands/cat.py +14 -19
  25. adam/commands/cd.py +12 -100
  26. adam/commands/check.py +20 -21
  27. adam/commands/cli_commands.py +2 -3
  28. adam/commands/code.py +20 -23
  29. adam/commands/command.py +123 -39
  30. adam/commands/commands_utils.py +8 -17
  31. adam/commands/cp.py +33 -39
  32. adam/commands/cql/cql_completions.py +28 -10
  33. adam/commands/cql/cqlsh.py +10 -30
  34. adam/commands/cql/utils_cql.py +343 -0
  35. adam/commands/deploy/code_start.py +7 -10
  36. adam/commands/deploy/code_stop.py +4 -21
  37. adam/commands/deploy/code_utils.py +3 -3
  38. adam/commands/deploy/deploy.py +4 -27
  39. adam/commands/deploy/deploy_frontend.py +14 -17
  40. adam/commands/deploy/deploy_pg_agent.py +2 -5
  41. adam/commands/deploy/deploy_pod.py +65 -73
  42. adam/commands/deploy/deploy_utils.py +14 -24
  43. adam/commands/deploy/undeploy.py +4 -27
  44. adam/commands/deploy/undeploy_frontend.py +4 -7
  45. adam/commands/deploy/undeploy_pg_agent.py +5 -7
  46. adam/commands/deploy/undeploy_pod.py +11 -12
  47. adam/commands/devices/__init__.py +0 -0
  48. adam/commands/devices/device.py +118 -0
  49. adam/commands/devices/device_app.py +173 -0
  50. adam/commands/devices/device_auit_log.py +49 -0
  51. adam/commands/devices/device_cass.py +185 -0
  52. adam/commands/devices/device_export.py +86 -0
  53. adam/commands/devices/device_postgres.py +144 -0
  54. adam/commands/devices/devices.py +25 -0
  55. adam/commands/exit.py +1 -4
  56. adam/commands/export/clean_up_all_export_sessions.py +37 -0
  57. adam/commands/export/clean_up_export_sessions.py +51 -0
  58. adam/commands/export/drop_export_database.py +55 -0
  59. adam/commands/export/drop_export_databases.py +43 -0
  60. adam/commands/export/export.py +19 -26
  61. adam/commands/export/export_databases.py +174 -0
  62. adam/commands/export/export_handlers.py +71 -0
  63. adam/commands/export/export_select.py +48 -22
  64. adam/commands/export/export_select_x.py +54 -0
  65. adam/commands/export/export_use.py +19 -23
  66. adam/commands/export/exporter.py +353 -0
  67. adam/commands/export/import_session.py +40 -0
  68. adam/commands/export/importer.py +67 -0
  69. adam/commands/export/importer_athena.py +77 -0
  70. adam/commands/export/importer_sqlite.py +39 -0
  71. adam/commands/export/show_column_counts.py +54 -0
  72. adam/commands/export/show_export_databases.py +36 -0
  73. adam/commands/export/show_export_session.py +48 -0
  74. adam/commands/export/show_export_sessions.py +44 -0
  75. adam/commands/export/utils_export.py +223 -162
  76. adam/commands/help.py +1 -1
  77. adam/commands/intermediate_command.py +49 -0
  78. adam/commands/issues.py +11 -43
  79. adam/commands/kubectl.py +3 -6
  80. adam/commands/login.py +22 -24
  81. adam/commands/logs.py +3 -6
  82. adam/commands/ls.py +11 -128
  83. adam/commands/medusa/medusa.py +4 -22
  84. adam/commands/medusa/medusa_backup.py +20 -24
  85. adam/commands/medusa/medusa_restore.py +29 -33
  86. adam/commands/medusa/medusa_show_backupjobs.py +14 -18
  87. adam/commands/medusa/medusa_show_restorejobs.py +11 -18
  88. adam/commands/nodetool.py +6 -15
  89. adam/commands/param_get.py +11 -12
  90. adam/commands/param_set.py +9 -10
  91. adam/commands/postgres/postgres.py +41 -34
  92. adam/commands/postgres/postgres_context.py +57 -24
  93. adam/commands/postgres/postgres_ls.py +4 -8
  94. adam/commands/postgres/postgres_preview.py +5 -9
  95. adam/commands/postgres/psql_completions.py +1 -1
  96. adam/commands/postgres/utils_postgres.py +66 -0
  97. adam/commands/preview_table.py +5 -44
  98. adam/commands/pwd.py +14 -47
  99. adam/commands/reaper/reaper.py +4 -27
  100. adam/commands/reaper/reaper_forward.py +48 -55
  101. adam/commands/reaper/reaper_forward_session.py +6 -0
  102. adam/commands/reaper/reaper_forward_stop.py +10 -16
  103. adam/commands/reaper/reaper_restart.py +7 -14
  104. adam/commands/reaper/reaper_run_abort.py +11 -30
  105. adam/commands/reaper/reaper_runs.py +42 -57
  106. adam/commands/reaper/reaper_runs_abort.py +29 -49
  107. adam/commands/reaper/reaper_schedule_activate.py +11 -30
  108. adam/commands/reaper/reaper_schedule_start.py +10 -29
  109. adam/commands/reaper/reaper_schedule_stop.py +10 -29
  110. adam/commands/reaper/reaper_schedules.py +4 -14
  111. adam/commands/reaper/reaper_status.py +8 -16
  112. adam/commands/reaper/utils_reaper.py +196 -0
  113. adam/commands/repair/repair.py +4 -22
  114. adam/commands/repair/repair_log.py +5 -11
  115. adam/commands/repair/repair_run.py +27 -34
  116. adam/commands/repair/repair_scan.py +32 -38
  117. adam/commands/repair/repair_stop.py +5 -11
  118. adam/commands/report.py +27 -29
  119. adam/commands/restart.py +25 -26
  120. adam/commands/rollout.py +19 -24
  121. adam/commands/shell.py +10 -4
  122. adam/commands/show/show.py +10 -25
  123. adam/commands/show/show_cassandra_repairs.py +35 -0
  124. adam/commands/show/show_cassandra_status.py +32 -43
  125. adam/commands/show/show_cassandra_version.py +5 -18
  126. adam/commands/show/show_commands.py +19 -24
  127. adam/commands/show/show_host.py +1 -1
  128. adam/commands/show/show_login.py +20 -27
  129. adam/commands/show/show_processes.py +15 -19
  130. adam/commands/show/show_storage.py +10 -20
  131. adam/commands/watch.py +26 -29
  132. adam/config.py +5 -14
  133. adam/embedded_params.py +1 -1
  134. adam/log.py +4 -4
  135. adam/pod_exec_result.py +3 -3
  136. adam/repl.py +40 -103
  137. adam/repl_commands.py +32 -16
  138. adam/repl_state.py +57 -28
  139. adam/sql/sql_completer.py +44 -28
  140. adam/sql/sql_state_machine.py +89 -28
  141. adam/sso/authn_ad.py +6 -8
  142. adam/sso/authn_okta.py +4 -6
  143. adam/sso/cred_cache.py +3 -5
  144. adam/sso/idp.py +9 -12
  145. adam/utils.py +435 -6
  146. adam/utils_athena.py +57 -37
  147. adam/utils_audits.py +12 -14
  148. adam/utils_issues.py +32 -0
  149. adam/utils_k8s/app_clusters.py +13 -18
  150. adam/utils_k8s/app_pods.py +2 -0
  151. adam/utils_k8s/cassandra_clusters.py +22 -19
  152. adam/utils_k8s/cassandra_nodes.py +2 -2
  153. adam/utils_k8s/custom_resources.py +16 -17
  154. adam/utils_k8s/ingresses.py +2 -2
  155. adam/utils_k8s/jobs.py +7 -11
  156. adam/utils_k8s/k8s.py +87 -0
  157. adam/utils_k8s/pods.py +40 -77
  158. adam/utils_k8s/secrets.py +4 -4
  159. adam/utils_k8s/service_accounts.py +5 -4
  160. adam/utils_k8s/services.py +2 -2
  161. adam/utils_k8s/statefulsets.py +1 -12
  162. adam/utils_net.py +4 -4
  163. adam/utils_repl/__init__.py +0 -0
  164. adam/utils_repl/automata_completer.py +48 -0
  165. adam/utils_repl/repl_completer.py +46 -0
  166. adam/utils_repl/state_machine.py +173 -0
  167. adam/utils_sqlite.py +137 -0
  168. adam/version.py +1 -1
  169. {kaqing-2.0.115.dist-info → kaqing-2.0.172.dist-info}/METADATA +1 -1
  170. kaqing-2.0.172.dist-info/RECORD +230 -0
  171. adam/commands/app.py +0 -67
  172. adam/commands/app_ping.py +0 -44
  173. adam/commands/cql/cql_utils.py +0 -204
  174. adam/commands/devices.py +0 -147
  175. adam/commands/export/export_on_x.py +0 -76
  176. adam/commands/export/export_rmdbs.py +0 -65
  177. adam/commands/postgres/postgres_utils.py +0 -31
  178. adam/commands/reaper/reaper_session.py +0 -159
  179. adam/commands/show/show_app_actions.py +0 -56
  180. adam/commands/show/show_app_id.py +0 -47
  181. adam/commands/show/show_app_queues.py +0 -45
  182. adam/commands/show/show_repairs.py +0 -47
  183. adam/utils_export.py +0 -42
  184. kaqing-2.0.115.dist-info/RECORD +0 -203
  185. {kaqing-2.0.115.dist-info → kaqing-2.0.172.dist-info}/WHEEL +0 -0
  186. {kaqing-2.0.115.dist-info → kaqing-2.0.172.dist-info}/entry_points.txt +0 -0
  187. {kaqing-2.0.115.dist-info → kaqing-2.0.172.dist-info}/top_level.txt +0 -0
adam/commands/command.py CHANGED
@@ -2,10 +2,10 @@ from abc import abstractmethod
2
2
  import copy
3
3
  import subprocess
4
4
  import sys
5
+ from typing import Union
5
6
 
6
- from adam.commands.command_helpers import ClusterCommandHelper
7
7
  from adam.repl_state import ReplState, RequiredState
8
- from adam.utils import lines_to_tabular, log, log2
8
+ from adam.utils import is_lambda
9
9
 
10
10
  repl_cmds: list['Command'] = []
11
11
 
@@ -32,6 +32,9 @@ class Command:
32
32
  if not self.validate_state(state, show_err=False):
33
33
  return {}
34
34
 
35
+ if is_lambda(leaf):
36
+ leaf = leaf()
37
+
35
38
  d = leaf
36
39
  for t in reversed(self.command().split(' ')):
37
40
  d = {t: d}
@@ -41,7 +44,10 @@ class Command:
41
44
  def required(self) -> RequiredState:
42
45
  return None
43
46
 
44
- def validate_state(self, state: ReplState, show_err=True):
47
+ def validate(self, args: list[str], state: ReplState, apply = True):
48
+ return ValidateHandler(self, args, state, apply = apply)
49
+
50
+ def validate_state(self, state: ReplState, show_err = True):
45
51
  return state.validate(self.required(), show_err=show_err)
46
52
 
47
53
  def help(self, _: ReplState) -> str:
@@ -90,17 +96,50 @@ class Command:
90
96
  args.extend(['--help'])
91
97
  subprocess.run(args)
92
98
 
93
- def extract_options(args: list[str], names: list[str]):
94
- found: list[str] = []
99
+ def extract_options(args: list[str], trailing: Union[str, list[str]] = [], sequence: list[str] = [], options: list[str] = []):
100
+ found_options: list[str] = []
101
+ found_trailing = None
102
+ found_sequence = None
103
+
104
+ if trailing is None:
105
+ trailing = []
106
+ elif isinstance(trailing, str):
107
+ trailing = [trailing]
108
+
109
+ if options is None:
110
+ options = []
111
+ elif isinstance(options, str):
112
+ options = [options]
113
+
114
+ if args and trailing:
115
+ while args[-1] in trailing:
116
+ found_trailing = True
117
+ args = args[:-1]
118
+
119
+ if args and sequence:
120
+ args, found_sequence = Command.extract_option_sequence(args, sequence)
95
121
 
96
122
  new_args: list[str] = []
97
- for arg in args:
98
- if arg in names:
99
- found.append(arg)
100
- else:
101
- new_args.append(arg)
123
+ if args:
124
+ for arg in args:
125
+ if arg in options:
126
+ found_options.append(arg)
127
+ else:
128
+ new_args.append(arg)
129
+
130
+ return new_args, found_trailing, found_sequence, found_options
102
131
 
103
- return new_args, found
132
+ def extract_option_sequence(args, sequence):
133
+ len_sub = len(sequence)
134
+ len_main = len(args)
135
+ for i in range(len_main - len_sub + 1):
136
+ if args[i:i+len_sub] == sequence:
137
+ new_args = copy.copy(args)
138
+ del new_args[i:i+len_sub]
139
+
140
+ return new_args, True
141
+
142
+ return new_args, False
104
143
 
105
144
  def print_chain(cmd: 'Command'):
106
145
  print(f'{cmd.command()}', end = '')
@@ -109,31 +148,76 @@ class Command:
109
148
  cmd = s
110
149
  print()
111
150
 
112
- def intermediate_run(self, cmd: str, state: ReplState, args: list[str], cmds: list['Command'], separator='\t', display_help=True):
113
- state, _ = self.apply_state(args, state)
114
-
115
- if state.in_repl:
116
- if display_help:
117
- log(lines_to_tabular([c.help(state) for c in cmds], separator=separator))
118
-
119
- return 'command-missing'
120
- else:
121
- # head with the Chain of Responsibility pattern
122
- cmds = Command.chain(cmds)
123
- if not cmds.run(cmd, state):
124
- if display_help:
125
- log2('* Command is missing.')
126
- Command.display_help()
127
- return 'command-missing'
128
-
129
- return state
130
-
131
- def intermediate_help(super_help: str, cmd: str, cmd_list: list['Command'], separator='\t', show_cluster_help=False):
132
- log(super_help)
133
- log()
134
- log('Sub-Commands:')
135
-
136
- log(lines_to_tabular([c.help(ReplState()).replace(f'{cmd} ', ' ', 1) for c in cmd_list], separator=separator))
137
- if show_cluster_help:
138
- log()
139
- ClusterCommandHelper.cluster_help()
151
+ class InvalidState(Exception):
152
+ def __init__(self, state: ReplState):
153
+ super().__init__(f'Invalid state')
154
+
155
+ class ValidateHandler:
156
+ def __init__(self, cmd: Command, args: list[str], state: ReplState, apply = True):
157
+ self.cmd = cmd
158
+ self.args = args
159
+ self.state = state
160
+ self.apply = apply
161
+
162
+ def __enter__(self) -> tuple[list[str], ReplState]:
163
+ state = self.state
164
+ args = self.args
165
+ if self.apply:
166
+ state, args = self.cmd.apply_state(args, state)
167
+
168
+ if not self.cmd.validate_state(state):
169
+ raise InvalidState(state)
170
+
171
+ return args, state
172
+
173
+ def __exit__(self, exc_type, exc_val, exc_tb):
174
+ return False
175
+
176
+ class ExtractOptionsHandler:
177
+ def __init__(self, args: list[str], options: list[str] = None):
178
+ self.args = args
179
+ self.options = options
180
+
181
+ def __enter__(self) -> tuple[list[str], list[str]]:
182
+ args, _, _, options = Command.extract_options(self.args, options=self.options)
183
+ return args, options
184
+
185
+ def __exit__(self, exc_type, exc_val, exc_tb):
186
+ return False
187
+
188
+ class ExtractTrailingOptionsHandler:
189
+ def __init__(self, args: list[str], trailing: list[str] = None):
190
+ self.args = args
191
+ self.trailing = trailing
192
+
193
+ def __enter__(self) -> tuple[list[str], list[str]]:
194
+ args, trailing, _, _ = Command.extract_options(self.args, trailing=self.trailing)
195
+ return args, trailing
196
+
197
+ def __exit__(self, exc_type, exc_val, exc_tb):
198
+ return False
199
+
200
+ class ExtractAllOptionsHandler:
201
+ def __init__(self, args: list[str], trailing: list[str] = None, sequence: list[str] = None, options: list[str] = None):
202
+ self.args = args
203
+ self.trailing = trailing
204
+ self.sequence = sequence
205
+ self.options = options
206
+
207
+ def __enter__(self) -> tuple[list[str], list[str]]:
208
+ return Command.extract_options(self.args, trailing=self.trailing, sequence=self.sequence, options=self.options)
209
+
210
+ def __exit__(self, exc_type, exc_val, exc_tb):
211
+ return False
212
+
213
+ class ExtractSequenceOptionsHandler:
214
+ def __init__(self, args: list[str], sequence: list[str]):
215
+ self.args = args
216
+ self.sequence = sequence
217
+
218
+ def __enter__(self) -> tuple[list[str], list[str]]:
219
+ args, _, sequence, _ = Command.extract_options(self.args, sequence=self.sequence)
220
+ return args, sequence
221
+
222
+ def __exit__(self, exc_type, exc_val, exc_tb):
223
+ return False
@@ -1,10 +1,9 @@
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
@@ -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)
@@ -70,10 +61,10 @@ def show_rollout(sts: str, ns: str):
70
61
  else:
71
62
  log2(f'Cluster has completed rollout {d} ago.')
72
63
 
73
- def show_table(state: ReplState, pods: list[str], cols: str, header: str, show_output=False):
64
+ def show_table(state: ReplState, pods: list[str], cols: str, header: str, show_out=False):
74
65
  columns = Columns.create_columns(cols)
75
66
 
76
- results = run_checks(cluster=state.sts, pod=state.pod, namespace=state.namespace, checks=collect_checks(columns), show_output=show_output)
67
+ results = run_checks(cluster=state.sts, pod=state.pod, namespace=state.namespace, checks=collect_checks(columns), show_out=show_out)
77
68
 
78
69
  def line(pod_name: str):
79
70
  cells = [c.pod_value(results, pod_name) for c in columns]
@@ -84,4 +75,4 @@ def show_table(state: ReplState, pods: list[str], cols: str, header: str, show_o
84
75
 
85
76
  log(lines_to_tabular(lines, header, separator=','))
86
77
 
87
- Issues.show(results, state.in_repl)
78
+ IssuesUtils.show(results, state.in_repl)
adam/commands/cp.py CHANGED
@@ -29,47 +29,41 @@ class ClipboardCopy(Command):
29
29
  if not(args := self.args(cmd)):
30
30
  return super().run(cmd, state)
31
31
 
32
- state, args = self.apply_state(args, state)
33
- if not self.validate_state(state):
34
- return state
35
-
36
- if len(args) < 1:
37
- if state.in_repl:
38
- log2('Key is required.')
39
- log2()
40
- log2('Keys:')
41
- log2(lines_to_tabular([f'{k},{v}' for k, v in CliCommands.values(state, collapse=True).items()], separator=','))
42
- else:
43
- log2('* Key is missing.')
44
- Command.display_help()
45
-
46
- return 'command-missing'
47
-
48
- key = args[0]
49
- if not key in CliCommands.values(state):
50
- if state.in_repl:
51
- log2('Key is required.')
52
- log2()
53
- log2('Keys:')
54
- log2(lines_to_tabular([f'{k},{v}' for k, v in CliCommands.values(state, collapse=True).items()], separator=','))
55
- else:
56
- log2('* Invalid key')
57
- Command.display_help()
58
-
59
- return 'command-invalid'
60
-
61
- value = CliCommands.values(state)[key]
62
- pyperclip.copy(value)
63
- log2('The following line has been copied to clipboard. Use <Ctrl-V> to use it.')
64
- log2(f' {value}')
65
-
66
- return 'value-copied'
32
+ with self.validate(args, state) as (args, state):
33
+ if len(args) < 1:
34
+ if state.in_repl:
35
+ log2('Key is required.')
36
+ log2()
37
+ log2('Keys:')
38
+ log2(lines_to_tabular([f'{k},{v}' for k, v in CliCommands.values(state, collapse=True).items()], separator=','))
39
+ else:
40
+ log2('* Key is missing.')
41
+ Command.display_help()
42
+
43
+ return 'command-missing'
44
+
45
+ key = args[0]
46
+ if not key in CliCommands.values(state):
47
+ if state.in_repl:
48
+ log2('Key is required.')
49
+ log2()
50
+ log2('Keys:')
51
+ log2(lines_to_tabular([f'{k},{v}' for k, v in CliCommands.values(state, collapse=True).items()], separator=','))
52
+ else:
53
+ log2('* Invalid key')
54
+ Command.display_help()
55
+
56
+ return 'command-invalid'
57
+
58
+ value = CliCommands.values(state)[key]
59
+ pyperclip.copy(value)
60
+ log2('The following line has been copied to clipboard. Use <Ctrl-V> to use it.')
61
+ log2(f' {value}')
62
+
63
+ return 'value-copied'
67
64
 
68
65
  def completion(self, state: ReplState):
69
- if state.sts:
70
- return {ClipboardCopy.COMMAND: {key: None for key in CliCommands.values(state).keys()}}
71
-
72
- return {}
66
+ return super().completion(state, lambda: {key: None for key in CliCommands.values(state).keys()})
73
67
 
74
68
  def help(self, _: ReplState):
75
69
  return f"{ClipboardCopy.COMMAND} <key>\t copy a value to clipboard for conveninence"
@@ -1,15 +1,33 @@
1
- from adam.commands.cql.cql_utils import cassandra_table_names
1
+ import time
2
+ from adam.commands.cql.utils_cql import cassandra_keyspaces, cassandra_table_names
3
+ from adam.commands.export.exporter import Exporter
4
+ from adam.commands.export.export_databases import ExportDatabases
2
5
  from adam.config import Config
3
6
  from adam.repl_state import ReplState
4
- from adam.sql.sql_completer import SqlCompleter
7
+ from adam.sql.sql_completer import SqlCompleter, SqlVariant
8
+ from adam.utils import log_timing
5
9
 
6
10
  def cql_completions(state: ReplState) -> dict[str, any]:
7
11
  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()
12
+ # warm up caches
13
+ with log_timing('cassandra_keyspaces'):
14
+ cassandra_keyspaces(state)
15
+ with log_timing('cassandra_table_names'):
16
+ cassandra_table_names(state)
17
+ with log_timing('ExportDatabases.database_names'):
18
+ ExportDatabases.database_names()
19
+
20
+ expandables = {
21
+ 'keyspaces': lambda: cassandra_keyspaces(state),
22
+ 'table-props': lambda: {
23
+ 'GC_GRACE_SECONDS': ps
24
+ },
25
+ 'export-dbs': lambda: ExportDatabases.database_names(),
26
+ 'export-sessions': lambda: Exporter.export_session_names(state.sts, state.pod, state.namespace),
27
+ 'export-sessions-incomplete': lambda: Exporter.export_session_names(state.sts, state.pod, state.namespace, export_state='pending_import'),
28
+ }
29
+
30
+ return SqlCompleter(
31
+ lambda: cassandra_table_names(state),
32
+ expandables=expandables,
33
+ variant=SqlVariant.CQL).completions_for_nesting()
@@ -1,12 +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
7
+ from adam.commands.cql.utils_cql import cassandra
6
8
  from adam.utils_k8s.statefulsets import StatefulSets
7
- from .cql_utils import run_cql
8
9
  from adam.repl_state import ReplState, RequiredState
9
- from adam.utils import log, log2
10
+ from adam.utils import log
10
11
 
11
12
  class Cqlsh(Command):
12
13
  COMMAND = 'cql'
@@ -30,32 +31,10 @@ class Cqlsh(Command):
30
31
  if not(args := self.args(cmd)):
31
32
  return super().run(cmd, state)
32
33
 
33
- state, args = self.apply_state(args, state)
34
- if not self.validate_state(state):
35
- return state
36
-
37
- background = False
38
- opts = []
39
- cqls = []
40
- for index, arg in enumerate(args):
41
- if arg.startswith('--'):
42
- opts.append(arg)
43
- elif index == len(args) -1 and arg == '&':
44
- background = True
45
- elif arg != '-e':
46
- cqls.append(arg)
47
- if not cqls:
48
- if state.in_repl:
49
- log2('Please enter cql statement. e.g. select host_id from system.local')
50
- else:
51
- log2('* CQL statement is missing.')
52
- log2()
53
- Command.display_help()
54
-
55
- return 'no-cql'
56
-
57
- cql = ' '.join(cqls)
58
- 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, background=backgrounded)
59
38
 
60
39
  def completion(self, state: ReplState) -> dict[str, any]:
61
40
  if state.device != state.C:
@@ -63,8 +42,9 @@ class Cqlsh(Command):
63
42
  return {}
64
43
 
65
44
  if state.sts or state.pod:
66
- return cql_completions(state) | \
67
- {f'@{p}': cql_completions(state) for p in StatefulSets.pod_names(state.sts, state.namespace)}
45
+ c = cql_completions(state)
46
+ return c | \
47
+ {f'@{p}': c for p in StatefulSets.pod_names(state.sts, state.namespace)}
68
48
 
69
49
  return {}
70
50