kaqing 2.0.174__py3-none-any.whl → 2.0.188__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 (138) hide show
  1. adam/app_session.py +2 -2
  2. adam/apps.py +18 -4
  3. adam/batch.py +1 -1
  4. adam/checks/check_utils.py +3 -1
  5. adam/commands/__init__.py +4 -2
  6. adam/commands/app/__init__.py +0 -0
  7. adam/commands/app/app.py +38 -0
  8. adam/commands/app/app_ping.py +38 -0
  9. adam/commands/app/show_app_actions.py +49 -0
  10. adam/commands/app/show_app_id.py +44 -0
  11. adam/commands/app/show_app_queues.py +38 -0
  12. adam/commands/app/utils_app.py +106 -0
  13. adam/commands/audit/audit.py +9 -27
  14. adam/commands/audit/audit_repair_tables.py +5 -7
  15. adam/commands/audit/audit_run.py +1 -1
  16. adam/commands/audit/completions_l.py +15 -0
  17. adam/commands/audit/show_last10.py +2 -14
  18. adam/commands/audit/show_slow10.py +2 -13
  19. adam/commands/audit/show_top10.py +2 -11
  20. adam/commands/audit/utils_show_top10.py +14 -1
  21. adam/commands/bash/bash.py +1 -1
  22. adam/commands/cat.py +3 -7
  23. adam/commands/check.py +2 -2
  24. adam/commands/cli_commands.py +6 -1
  25. adam/commands/{cp.py → clipboard_copy.py} +18 -12
  26. adam/commands/code.py +2 -2
  27. adam/commands/command.py +61 -11
  28. adam/commands/commands_utils.py +19 -12
  29. adam/commands/cql/completions_c.py +28 -0
  30. adam/commands/cql/cqlsh.py +3 -7
  31. adam/commands/cql/utils_cql.py +22 -58
  32. adam/commands/deploy/deploy_pg_agent.py +2 -2
  33. adam/commands/deploy/undeploy_pg_agent.py +2 -2
  34. adam/commands/devices/device.py +39 -8
  35. adam/commands/devices/device_app.py +18 -28
  36. adam/commands/devices/device_auit_log.py +3 -3
  37. adam/commands/devices/device_cass.py +16 -22
  38. adam/commands/devices/device_export.py +6 -3
  39. adam/commands/devices/device_postgres.py +79 -63
  40. adam/commands/download_file.py +47 -0
  41. adam/commands/export/clean_up_all_export_sessions.py +3 -3
  42. adam/commands/export/clean_up_export_sessions.py +5 -10
  43. adam/commands/export/completions_x.py +11 -0
  44. adam/commands/export/download_export_session.py +40 -0
  45. adam/commands/export/export.py +0 -16
  46. adam/commands/export/export_databases.py +26 -9
  47. adam/commands/export/export_select.py +9 -58
  48. adam/commands/export/export_sessions.py +90 -5
  49. adam/commands/export/export_use.py +13 -10
  50. adam/commands/export/export_x_select.py +48 -0
  51. adam/commands/export/exporter.py +60 -22
  52. adam/commands/export/import_files.py +44 -0
  53. adam/commands/export/import_session.py +8 -4
  54. adam/commands/export/importer.py +7 -0
  55. adam/commands/export/importer_athena.py +101 -34
  56. adam/commands/export/importer_sqlite.py +30 -5
  57. adam/commands/export/show_column_counts.py +11 -11
  58. adam/commands/export/show_export_databases.py +5 -3
  59. adam/commands/export/show_export_session.py +5 -6
  60. adam/commands/export/show_export_sessions.py +4 -11
  61. adam/commands/export/utils_export.py +42 -14
  62. adam/commands/find_files.py +51 -0
  63. adam/commands/find_processes.py +76 -0
  64. adam/commands/head.py +36 -0
  65. adam/commands/help.py +2 -2
  66. adam/commands/intermediate_command.py +6 -3
  67. adam/commands/ls.py +1 -1
  68. adam/commands/medusa/medusa_backup.py +12 -14
  69. adam/commands/medusa/medusa_restore.py +20 -15
  70. adam/commands/medusa/medusa_show_backupjobs.py +6 -4
  71. adam/commands/medusa/medusa_show_restorejobs.py +5 -3
  72. adam/commands/medusa/utils_medusa.py +15 -0
  73. adam/commands/nodetool.py +3 -8
  74. adam/commands/param_get.py +2 -3
  75. adam/commands/param_set.py +1 -1
  76. adam/commands/postgres/completions_p.py +22 -0
  77. adam/commands/postgres/postgres.py +14 -21
  78. adam/commands/postgres/postgres_databases.py +270 -0
  79. adam/commands/postgres/utils_postgres.py +29 -20
  80. adam/commands/preview_table.py +3 -1
  81. adam/commands/pwd.py +3 -3
  82. adam/commands/reaper/reaper_forward.py +2 -2
  83. adam/commands/reaper/reaper_runs.py +3 -3
  84. adam/commands/reaper/reaper_schedule_activate.py +6 -2
  85. adam/commands/reaper/reaper_schedule_start.py +1 -2
  86. adam/commands/reaper/reaper_schedule_stop.py +1 -2
  87. adam/commands/reaper/utils_reaper.py +13 -6
  88. adam/commands/repair/repair_scan.py +0 -2
  89. adam/commands/repair/repair_stop.py +0 -1
  90. adam/commands/shell.py +7 -5
  91. adam/commands/show/show.py +1 -1
  92. adam/commands/show/show_adam.py +3 -3
  93. adam/commands/show/show_cassandra_repairs.py +5 -3
  94. adam/commands/show/show_cassandra_status.py +27 -20
  95. adam/commands/show/{show_commands.py → show_cli_commands.py} +2 -2
  96. adam/commands/show/show_login.py +2 -2
  97. adam/commands/show/show_params.py +2 -5
  98. adam/commands/show/show_processes.py +15 -14
  99. adam/commands/show/show_storage.py +9 -8
  100. adam/config.py +1 -0
  101. adam/embedded_params.py +1 -1
  102. adam/repl.py +16 -9
  103. adam/repl_commands.py +16 -9
  104. adam/repl_session.py +8 -1
  105. adam/repl_state.py +33 -10
  106. adam/sql/lark_completer.py +284 -0
  107. adam/sql/lark_parser.py +604 -0
  108. adam/sql/sql_state_machine.py +8 -2
  109. adam/utils.py +116 -29
  110. adam/utils_athena.py +7 -8
  111. adam/utils_issues.py +2 -2
  112. adam/utils_k8s/app_clusters.py +2 -2
  113. adam/utils_k8s/app_pods.py +5 -2
  114. adam/utils_k8s/cassandra_clusters.py +11 -3
  115. adam/utils_k8s/cassandra_nodes.py +2 -2
  116. adam/utils_k8s/k8s.py +9 -0
  117. adam/utils_k8s/kube_context.py +2 -2
  118. adam/utils_k8s/pods.py +23 -5
  119. adam/utils_k8s/statefulsets.py +5 -2
  120. adam/utils_local.py +4 -0
  121. adam/utils_repl/appendable_completer.py +6 -0
  122. adam/utils_repl/repl_completer.py +128 -2
  123. adam/utils_sqlite.py +2 -2
  124. adam/version.py +1 -1
  125. {kaqing-2.0.174.dist-info → kaqing-2.0.188.dist-info}/METADATA +1 -1
  126. kaqing-2.0.188.dist-info/RECORD +253 -0
  127. kaqing-2.0.188.dist-info/top_level.txt +2 -0
  128. teddy/__init__.py +0 -0
  129. teddy/lark_parser.py +436 -0
  130. teddy/lark_parser2.py +618 -0
  131. adam/commands/cql/cql_completions.py +0 -32
  132. adam/commands/export/export_select_x.py +0 -54
  133. adam/commands/postgres/postgres_context.py +0 -272
  134. adam/commands/postgres/psql_completions.py +0 -10
  135. kaqing-2.0.174.dist-info/RECORD +0 -230
  136. kaqing-2.0.174.dist-info/top_level.txt +0 -1
  137. {kaqing-2.0.174.dist-info → kaqing-2.0.188.dist-info}/WHEEL +0 -0
  138. {kaqing-2.0.174.dist-info → kaqing-2.0.188.dist-info}/entry_points.txt +0 -0
adam/commands/cat.py CHANGED
@@ -2,7 +2,6 @@ from adam.commands import validate_args
2
2
  from adam.commands.command import Command
3
3
  from adam.commands.devices.devices import Devices
4
4
  from adam.repl_state import ReplState, RequiredState
5
- from adam.utils import log2
6
5
 
7
6
  class Cat(Command):
8
7
  COMMAND = 'cat'
@@ -28,13 +27,10 @@ class Cat(Command):
28
27
 
29
28
  with self.validate(args, state) as (args, state):
30
29
  with validate_args(args, state, name='file'):
31
- return Devices.device(state).cat(cmd, state)
30
+ return Devices.device(state).bash(state, state, cmd.split(' '))
32
31
 
33
32
  def completion(self, state: ReplState):
34
- if super().completion(state):
35
- return Devices.device(state).cat_completion(Cat.COMMAND, state, default={})
36
-
37
- return {}
33
+ return super().completion(state, lambda: {f: None for f in Devices.device(state).files(state)}, pods=Devices.device(state).pods(state, '-'), auto='jit')
38
34
 
39
35
  def help(self, _: ReplState):
40
- return f'{Cat.COMMAND} file [&]\t run cat command on the Cassandra nodes'
36
+ return f'{Cat.COMMAND} file [&]\t run cat command on the pod'
adam/commands/check.py CHANGED
@@ -7,7 +7,7 @@ from adam.commands.command import Command
7
7
  from adam.commands.command_helpers import ClusterOrPodCommandHelper
8
8
  from adam.commands.issues import Issues
9
9
  from adam.repl_state import ReplState
10
- from adam.utils import lines_to_tabular, log
10
+ from adam.utils import tabulize, log
11
11
  from adam.utils_issues import IssuesUtils
12
12
 
13
13
  class Check(Issues):
@@ -34,7 +34,7 @@ class Check(Issues):
34
34
 
35
35
  with self.validate(args, state) as (args, state):
36
36
  with extract_options(args, ['-s', '--show']) as (args, show_out):
37
- with validate_args(args, state, name='check name', msg=lambda:log(lines_to_tabular([check.help() for check in all_checks()], separator=':'))) as arg:
37
+ with validate_args(args, state, name='check name', msg=lambda: tabulize([check.help() for check in all_checks()], separator=':')) as arg:
38
38
  checks = checks_from_csv(args[0])
39
39
  if not checks:
40
40
  return 'invalid check name'
@@ -3,14 +3,19 @@ import re
3
3
 
4
4
  from adam.commands.reaper.utils_reaper import Reapers
5
5
  from adam.config import Config
6
+ from adam.utils import log_timing
6
7
  from adam.utils_k8s.kube_context import KubeContext
7
8
  from adam.utils_k8s.secrets import Secrets
8
9
  from adam.utils_k8s.statefulsets import StatefulSets
9
10
  from adam.repl_state import ReplState
10
11
 
11
12
  class CliCommands:
12
- @functools.lru_cache()
13
13
  def values(state: ReplState, collapse = False):
14
+ with log_timing('CliCommands.values'):
15
+ return CliCommands._values(state, collapse)
16
+
17
+ @functools.lru_cache()
18
+ def _values(state: ReplState, collapse = False):
14
19
  # node-exec-?, nodetool-?, cql-?, reaper-exec, reaper-forward, reaper-ui, reaper-usernae, reaper-password
15
20
  d = {}
16
21
 
@@ -1,3 +1,4 @@
1
+ from functools import partial
1
2
  import click
2
3
  import pyperclip
3
4
 
@@ -5,11 +6,12 @@ from adam.commands import validate_args
5
6
  from adam.commands.command import Command, InvalidArgumentsException
6
7
  from adam.commands.command_helpers import ClusterOrPodCommandHelper
7
8
  from adam.commands.cli_commands import CliCommands
9
+ from adam.config import Config
8
10
  from adam.repl_state import ReplState, RequiredState
9
- from adam.utils import lines_to_tabular, log, log2
11
+ from adam.utils import tabulize, log, log2
10
12
 
11
13
  class ClipboardCopy(Command):
12
- COMMAND = 'cp'
14
+ COMMAND = 'cli cp'
13
15
 
14
16
  # the singleton pattern
15
17
  def __new__(cls, *args, **kwargs):
@@ -31,16 +33,22 @@ class ClipboardCopy(Command):
31
33
  return super().run(cmd, state)
32
34
 
33
35
  with self.validate(args, state) as (args, state):
34
- def display_keys():
35
- log2('Key is required.')
36
+ def display_keys(missing = False):
37
+ if missing:
38
+ log2('Key is required.')
39
+ else:
40
+ log2('Key is invalid.')
36
41
  log2()
37
- log2('Keys:')
38
- log2(lines_to_tabular([f'{k},{v}' for k, v in CliCommands.values(state, collapse=True).items()], separator=','))
42
+ tabulize(CliCommands.values(state, collapse=True).items(),
43
+ lambda a: f'{a[0]},{a[1]}',
44
+ header='KEY,VALUE',
45
+ separator=',',
46
+ to=2)
39
47
 
40
- with validate_args(args, state, name='key', msg=display_keys) as key:
48
+ with validate_args(args, state, name='key', msg=partial(display_keys, True)) as key:
41
49
  if not key in CliCommands.values(state):
42
50
  if state.in_repl:
43
- display_keys()
51
+ display_keys(False)
44
52
  else:
45
53
  log2('* Invalid key')
46
54
  Command.display_help()
@@ -55,7 +63,7 @@ class ClipboardCopy(Command):
55
63
  return state
56
64
 
57
65
  def completion(self, state: ReplState):
58
- return super().completion(state, lambda: {key: None for key in CliCommands.values(state).keys()})
66
+ return super().completion(state, lambda: {key: None for key in CliCommands.values(state).keys()}, auto_key='cli.cp-auto-complete')
59
67
 
60
68
  def help(self, _: ReplState):
61
69
  return f"{ClipboardCopy.COMMAND} <key>\t copy a value to clipboard for conveninence"
@@ -74,8 +82,6 @@ class CopyCommandHelper(click.Command):
74
82
  def get_help(self, ctx: click.Context):
75
83
  log(super().get_help(ctx))
76
84
  log()
77
- log('Keys:')
78
-
79
- log(lines_to_tabular(self.lines(), separator=':'))
85
+ tabulize(self.lines(), header='KEY:DESC', separator=':')
80
86
  log()
81
87
  ClusterOrPodCommandHelper.cluter_or_pod_help()
adam/commands/code.py CHANGED
@@ -4,7 +4,7 @@ from functools import partial
4
4
  from adam.commands.command import Command
5
5
  from adam.commands.cql.utils_cql import cassandra_table_names, run_cql
6
6
  from adam.repl_state import ReplState, RequiredState
7
- from adam.utils import lines_to_tabular
7
+ from adam.utils import tabulize
8
8
  from adam.utils_k8s.statefulsets import StatefulSets
9
9
 
10
10
  class Code(Command):
@@ -46,7 +46,7 @@ class Code(Command):
46
46
  "cql('select...'): run cql statement"
47
47
  ]
48
48
 
49
- code.interact(local=my_local, banner=lines_to_tabular(lines, header='Variables', separator=':'))
49
+ code.interact(local=my_local, banner=tabulize(lines, header='Variables', separator=':'))
50
50
 
51
51
  return state
52
52
 
adam/commands/command.py CHANGED
@@ -5,8 +5,10 @@ import subprocess
5
5
  import sys
6
6
  from typing import Union
7
7
 
8
+ from adam.config import Config
8
9
  from adam.repl_state import ReplState, RequiredState
9
- from adam.utils import is_lambda, log2
10
+ from adam.sql.lark_completer import LarkCompleter
11
+ from adam.utils import log2
10
12
 
11
13
  repl_cmds: list['Command'] = []
12
14
 
@@ -29,12 +31,38 @@ class Command:
29
31
 
30
32
  return None
31
33
 
32
- def completion(self, state: ReplState, leaf: dict[str, any] = None) -> dict[str, any]:
33
- if not self.validate_state(state, show_err=False):
34
+ def completion(self, state: ReplState, leaf: dict[str, any] = None, pods: tuple[list[str], str] = None, auto: str = 'on', auto_key: str = None) -> dict[str, any]:
35
+ # pods is a tuple of list of pod names and the current pod repl is on
36
+ if not pods:
37
+ return self._completion(state, leaf, auto=auto, auto_key=auto_key)
38
+
39
+ c = {}
40
+
41
+ pod_names = pods[0]
42
+ pod = pods[1]
43
+
44
+ if pod:
45
+ c |= self._completion(state, leaf, auto=auto, auto_key=auto_key)
46
+
47
+ c |= {f'@{p}': self._completion(state, leaf, to_validate=False, auto=auto, auto_key=auto_key) for p in pod_names if p != pod}
48
+
49
+ return c
50
+
51
+ def _completion(self, state: ReplState, leaf: dict[str, any] = None, to_validate = True, auto: str = 'on', auto_key: str = None) -> dict[str, any]:
52
+ if to_validate and not self.validate_state(state, show_err=False):
34
53
  return {}
35
54
 
36
- if is_lambda(leaf):
37
- leaf = leaf()
55
+ if callable(leaf):
56
+ if auto_key:
57
+ auto_key = f'auto-complete.{auto_key}'
58
+ auto = Config().get(auto_key, 'off')
59
+
60
+ if auto == 'on':
61
+ leaf = leaf()
62
+ elif auto in ['lazy', 'jit']:
63
+ leaf = LarkCompleter.from_lambda(auto_key, leaf, auto=auto)
64
+ else:
65
+ leaf = None
38
66
 
39
67
  d = leaf
40
68
  for t in reversed(self.command().split(' ')):
@@ -113,7 +141,7 @@ class Command:
113
141
  options = [options]
114
142
 
115
143
  if args and trailing:
116
- while args[-1] in trailing:
144
+ while args and args[-1] in trailing:
117
145
  found_trailing = True
118
146
  args = args[:-1]
119
147
 
@@ -131,6 +159,8 @@ class Command:
131
159
  return new_args, found_trailing, found_sequence, found_options
132
160
 
133
161
  def extract_option_sequence(args, sequence):
162
+ new_args = args
163
+
134
164
  len_sub = len(sequence)
135
165
  len_main = len(args)
136
166
  for i in range(len_main - len_sub + 1):
@@ -181,15 +211,27 @@ class InvalidArgumentsException(Exception):
181
211
  super().__init__(f'Invalid arguments')
182
212
 
183
213
  class ValidateArgCountHandler:
184
- def __init__(self, args: list[str], state: ReplState, count_at_least: int = 1, name: str = None, msg: Callable[[], None] = None):
214
+ def __init__(self, args: list[str], state: ReplState, at_least: int = 1, exactly: int = 1,
215
+ name: str = None, msg: Callable[[], None] = None, default: Union[str, list[str]] = None,
216
+ separator: str = None):
185
217
  self.args = args
186
218
  self.state = state
187
- self.count_at_least = count_at_least
219
+ self.at_least = at_least
220
+ self.exactly = exactly
188
221
  self.name = name
189
222
  self.msg = msg
223
+ self.default = default
224
+ self.separator = separator
225
+
226
+ def __enter__(self) -> Union[tuple[list[str], ReplState], tuple[str, ReplState]]:
227
+ if self.exactly > 0 and len(self.args) != self.exactly or len(self.args) < self.at_least:
228
+ if self.default:
229
+ v = self.default
230
+ if isinstance(v, list):
231
+ v = ' '.join(v)
232
+
233
+ return v
190
234
 
191
- def __enter__(self) -> tuple[list[str], ReplState]:
192
- if len(self.args) < self.count_at_least:
193
235
  if self.state.in_repl:
194
236
  if self.msg:
195
237
  self.msg()
@@ -202,7 +244,15 @@ class ValidateArgCountHandler:
202
244
 
203
245
  raise InvalidArgumentsException()
204
246
 
205
- return ' '.join(self.args)
247
+ if self.separator == ' ':
248
+ return self.args
249
+
250
+ # join and re-split with separator
251
+ args_to_return = ' '.join(self.args)
252
+ if self.separator:
253
+ args_to_return = [arg.strip(' ') for arg in args_to_return.split(self.separator)]
254
+
255
+ return args_to_return
206
256
 
207
257
  def __exit__(self, exc_type, exc_val, exc_tb):
208
258
  return False
@@ -1,14 +1,17 @@
1
+ from datetime import datetime
1
2
  from kubernetes import client
2
3
  from typing import List
3
4
 
4
5
  from adam.checks.check_utils import run_checks
5
6
  from adam.columns.columns import Columns, collect_checks
7
+ from adam.config import Config
8
+ from adam.repl_session import ReplSession
6
9
  from adam.utils_issues import IssuesUtils
7
10
  from adam.utils_k8s.cassandra_nodes import CassandraNodes
8
11
  from adam.utils_k8s.pods import Pods
9
12
  from adam.utils_k8s.statefulsets import StatefulSets
10
13
  from adam.repl_state import ReplState
11
- from adam.utils import duration, lines_to_tabular, log, log2
14
+ from adam.utils import SORT, duration, tabulize, log, log2
12
15
 
13
16
  def show_pods(pods: List[client.V1Pod], ns: str, show_namespace = True, show_host_id = True):
14
17
  if len(pods) == 0:
@@ -48,9 +51,7 @@ def show_pods(pods: List[client.V1Pod], ns: str, show_namespace = True, show_hos
48
51
  line += f"@{ns}"
49
52
  return line + f" {ready}/{pod_cnt} {status}"
50
53
 
51
- pod_names = [line(pod) for pod in pods]
52
-
53
- log(lines_to_tabular(pod_names, 'HOST_ID POD_NAME READY POD_STATUS' if show_host_id else 'POD_NAME READY POD_STATUS'))
54
+ tabulize(pods, line, header='HOST_ID POD_NAME READY POD_STATUS' if show_host_id else 'POD_NAME READY POD_STATUS')
54
55
 
55
56
  def show_rollout(sts: str, ns: str):
56
57
  restarted, rollingout = StatefulSets.restarted_at(sts, ns)
@@ -61,18 +62,24 @@ def show_rollout(sts: str, ns: str):
61
62
  else:
62
63
  log2(f'Cluster has completed rollout {d} ago.')
63
64
 
64
- def show_table(state: ReplState, pods: list[str], cols: str, header: str, show_out=False):
65
+ def show_table(state: ReplState, pods: list[str], cols: str, header: str, show_out=False, backgrounded = False):
65
66
  columns = Columns.create_columns(cols)
66
67
 
67
68
  results = run_checks(cluster=state.sts, pod=state.pod, namespace=state.namespace, checks=collect_checks(columns), show_out=show_out)
68
69
 
69
- def line(pod_name: str):
70
- cells = [c.pod_value(results, pod_name) for c in columns]
71
- return ','.join(cells)
70
+ r = tabulize(pods, lambda p: ','.join([c.pod_value(results, p) for c in columns]), header=header, separator=',', sorted=SORT, to = 0 if backgrounded else 1)
71
+
72
+ if backgrounded:
73
+ log_prefix = Config().get('log-prefix', '/tmp/qing')
74
+ log_file = f'{log_prefix}-{datetime.now().strftime("%d%H%M%S")}.log'
75
+
76
+ with open(log_file, 'w') as f:
77
+ f.write(r)
78
+
79
+ ReplSession().append_history(f':sh cat {log_file}')
72
80
 
73
- lines = [line(pod) for pod in pods]
74
- lines.sort()
81
+ r = log_file
75
82
 
76
- log(lines_to_tabular(lines, header, separator=','))
83
+ IssuesUtils.show(results, state.in_repl)
77
84
 
78
- IssuesUtils.show(results, state.in_repl)
85
+ return r
@@ -0,0 +1,28 @@
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
4
+ from adam.config import Config
5
+ from adam.repl_state import ReplState
6
+ from adam.sql.lark_completer import LarkCompleter
7
+ from adam.utils import log_timing
8
+ from adam.utils_k8s.statefulsets import StatefulSets
9
+
10
+ def completions_c(state: ReplState) -> dict[str, any]:
11
+ ps = Config().get('cql.alter-tables.gc-grace-periods', '3600,86400,864000,7776000').split(',')
12
+
13
+ with log_timing('lark.completions'):
14
+ return LarkCompleter(
15
+ expandables = {
16
+ 'tables': lambda x: cassandra_table_names(state),
17
+ 'keyspaces': lambda x: cassandra_keyspaces(state.with_no_pod()),
18
+ 'table-props': lambda x: {
19
+ 'GC_GRACE_SECONDS': ps
20
+ },
21
+ 'export-database-types': lambda x: ['athena', 'sqlite', 'csv'],
22
+ 'export-databases': lambda x: ExportDatabases.database_names(),
23
+ 'export-sessions': lambda x: ExportSessions.export_session_names(state.sts, state.pod, state.namespace),
24
+ 'export-sessions-incomplete': lambda x: ExportSessions.export_session_names(state.sts, state.pod, state.namespace, export_state='pending_import'),
25
+ 'hosts': lambda x: [f'@{p}' for p in StatefulSets.pod_names(state.sts, state.namespace)],
26
+ },
27
+ variant=ReplState.C
28
+ ).completions_for_nesting()
@@ -3,9 +3,8 @@ import click
3
3
  from adam.commands import extract_trailing_options
4
4
  from adam.commands.command import Command
5
5
  from adam.commands.command_helpers import ClusterOrPodCommandHelper
6
- from adam.commands.cql.cql_completions import cql_completions
6
+ from adam.commands.cql.completions_c import completions_c
7
7
  from adam.commands.cql.utils_cql import cassandra
8
- from adam.utils_k8s.statefulsets import StatefulSets
9
8
  from adam.repl_state import ReplState, RequiredState
10
9
  from adam.utils import log
11
10
 
@@ -34,17 +33,14 @@ class Cqlsh(Command):
34
33
  with self.validate(args, state) as (args, state):
35
34
  with extract_trailing_options(args, '&') as (args, backgrounded):
36
35
  with cassandra(state) as pods:
37
- pods.cql(args, background=backgrounded)
36
+ pods.cql(args, backgrounded=backgrounded)
38
37
 
39
38
  def completion(self, state: ReplState) -> dict[str, any]:
40
39
  if state.device != state.C:
41
- # conflicts with psql completions
42
40
  return {}
43
41
 
44
42
  if state.sts or state.pod:
45
- c = cql_completions(state)
46
- return c | \
47
- {f'@{p}': c for p in StatefulSets.pod_names(state.sts, state.namespace)}
43
+ return completions_c(state)
48
44
 
49
45
  return {}
50
46
 
@@ -12,6 +12,14 @@ from adam.repl_state import ReplState
12
12
  from adam.utils import log2, log_timing, wait_log
13
13
  from adam.utils_k8s.statefulsets import StatefulSets
14
14
 
15
+ def cd_dirs(state: ReplState) -> list[str]:
16
+ if state.pod:
17
+ return [".."]
18
+ elif state.sts:
19
+ return [".."] + StatefulSets.pod_names(state.sts, state.namespace)
20
+ else:
21
+ return StatefulSets.list_sts_names()
22
+
15
23
  @functools.lru_cache()
16
24
  def cassandra_keyspaces(state: ReplState, on_any=True):
17
25
  if state.pod:
@@ -47,7 +55,7 @@ def table_spec(state: ReplState, table: str, on_any=False) -> 'TableSpec':
47
55
 
48
56
  return parse_cql_desc_table(r.stdout if state.pod else r[0].stdout)
49
57
 
50
- def run_cql(state: ReplState, cql: str, opts: list = [], show_out = False, show_query = False, use_single_quotes = False, on_any = False, background=False, log_file=None) -> list[PodExecResult]:
58
+ def run_cql(state: ReplState, cql: str, opts: list = [], show_out = False, show_query = False, use_single_quotes = False, on_any = False, backgrounded=False, log_file=None) -> list[PodExecResult]:
51
59
  if show_query:
52
60
  log2(cql)
53
61
 
@@ -61,7 +69,7 @@ def run_cql(state: ReplState, cql: str, opts: list = [], show_out = False, show_
61
69
 
62
70
  with log_timing(cql):
63
71
  with cassandra(state) as pods:
64
- return pods.exec(command, action='cql', show_out=show_out, on_any=on_any, background=background, log_file=log_file)
72
+ return pods.exec(command, action='cql', show_out=show_out, on_any=on_any, backgrounded=backgrounded, log_file=log_file)
65
73
 
66
74
  def parse_cql_desc_tables(out: str):
67
75
  # Keyspace data_endpoint_auth
@@ -215,68 +223,24 @@ def parse_cql_desc_table(out: str) -> TableSpec:
215
223
 
216
224
  return TableSpec(columns)
217
225
 
218
- class CqlShHandler:
219
- def __init__(self, state: ReplState, opts: list = [], show_out = False, show_query = False, use_single_quotes = False, on_any = False, background=False):
220
- self.state = state
221
- self.opts = opts
222
- self.show_out = show_out
223
- self.show_query = show_query
224
- self.use_single_quotes = use_single_quotes
225
- self.on_any = on_any
226
- self.backgroud = background
227
-
228
- def __enter__(self):
229
- return self.query
230
-
231
- def __exit__(self, exc_type, exc_val, exc_tb):
232
- return False
233
-
234
- def query(self, args: list[str], log_file: str = None):
235
- query: str = args
236
- background = self.backgroud
237
- show_out = self.show_out
238
-
239
- if isinstance(query, list):
240
- opts = []
241
- cqls = []
242
- for index, arg in enumerate(args):
243
- if arg.startswith('--'):
244
- opts.append(arg)
245
- elif arg != '-e':
246
- cqls.append(arg)
247
- if not cqls:
248
- if self.state.in_repl:
249
- log2('Please enter cql statement. e.g. select host_id from system.local')
250
- else:
251
- log2('* CQL statement is missing.')
252
- log2()
253
- Command.display_help()
254
-
255
- return 'no-cql'
256
-
257
- query = ' '.join(cqls)
258
- show_out = True
259
-
260
- return run_cql(self.state, query, opts=self.opts, show_out=show_out, show_query=self.show_query, use_single_quotes=self.use_single_quotes, on_any=self.on_any, background=background, log_file=log_file)
261
-
262
226
  class CassandraPodService:
263
227
  def __init__(self, handler: 'CassandraExecHandler'):
264
228
  self.handler = handler
265
229
 
266
- def exec(self, command: str, action='bash', show_out = True, on_any = False, throw_err = False, shell = '/bin/sh', background = False, log_file = None) -> Union[PodExecResult, list[PodExecResult]]:
230
+ def exec(self, command: str, action='bash', show_out = True, on_any = False, throw_err = False, shell = '/bin/sh', backgrounded = False, log_file = None) -> Union[PodExecResult, list[PodExecResult]]:
267
231
  state = self.handler.state
268
232
  pod = self.handler.pod
269
233
 
270
234
  if pod:
271
235
  return CassandraNodes.exec(pod, state.namespace, command,
272
- show_out=show_out, throw_err=throw_err, shell=shell, background=background, log_file=log_file)
236
+ show_out=show_out, throw_err=throw_err, shell=shell, backgrounded=backgrounded, log_file=log_file)
273
237
  elif state.sts:
274
238
  return CassandraClusters.exec(state.sts, state.namespace, command, action=action,
275
- show_out=show_out, on_any=on_any, shell=shell, background=background, log_file=log_file)
239
+ show_out=show_out, on_any=on_any, shell=shell, backgrounded=backgrounded, log_file=log_file)
276
240
 
277
241
  return []
278
242
 
279
- def cql(self, args: list[str], opts: list = [], show_out = False, show_query = False, use_single_quotes = False, on_any = False, background=False, log_file: str = None):
243
+ def cql(self, args: list[str], opts: list = [], show_out = False, show_query = False, use_single_quotes = False, on_any = False, backgrounded=False, log_file: str = None):
280
244
  state = self.handler.state
281
245
  query: str = args
282
246
 
@@ -301,18 +265,18 @@ class CassandraPodService:
301
265
  query = ' '.join(cqls)
302
266
  show_out = True
303
267
 
304
- return run_cql(state, query, opts=opts, show_out=show_out, show_query=show_query, use_single_quotes=use_single_quotes, on_any=on_any, background=background, log_file=log_file)
268
+ return run_cql(state, query, opts=opts, show_out=show_out, show_query=show_query, use_single_quotes=use_single_quotes, on_any=on_any, backgrounded=backgrounded, log_file=log_file)
305
269
 
306
- def display_table(self, cols: str, header: str, show_out = True):
270
+ def display_table(self, cols: str, header: str, show_out = True, backgrounded = False):
307
271
  state = self.handler.state
308
272
 
309
273
  if state.pod:
310
- show_table(state, [state.pod], cols, header, show_out=show_out)
274
+ return show_table(state, [state.pod], cols, header, show_out=show_out, backgrounded = backgrounded)
311
275
  elif state.sts:
312
276
  pod_names = [pod.metadata.name for pod in StatefulSets.pods(state.sts, state.namespace)]
313
- show_table(state, pod_names, cols, header, show_out=show_out)
277
+ return show_table(state, pod_names, cols, header, show_out=show_out, backgrounded = backgrounded)
314
278
 
315
- def nodetool(self, args: str, show_out = True) -> Union[PodExecResult, list[PodExecResult]]:
279
+ def nodetool(self, args: str, status = False, show_out = True, backgrounded = False) -> Union[PodExecResult, list[PodExecResult]]:
316
280
  state = self.handler.state
317
281
  pod = self.handler.pod
318
282
 
@@ -320,9 +284,9 @@ class CassandraPodService:
320
284
  command = f"nodetool -u {user} -pw {pw} {args}"
321
285
 
322
286
  if pod:
323
- return CassandraNodes.exec(pod, state.namespace, command, show_out=show_out)
287
+ return CassandraNodes.exec(pod, state.namespace, command, show_out=show_out, backgrounded=backgrounded)
324
288
  else:
325
- return CassandraClusters.exec(state.sts, state.namespace, command, action='nodetool', show_out=show_out)
289
+ return CassandraClusters.exec(state.sts, state.namespace, command, action='nodetool.status' if status else 'nodetool', show_out=show_out, backgrounded=backgrounded)
326
290
 
327
291
  class CassandraExecHandler:
328
292
  def __init__(self, state: ReplState, pod: str = None):
@@ -338,4 +302,4 @@ class CassandraExecHandler:
338
302
  return False
339
303
 
340
304
  def cassandra(state: ReplState, pod: str=None):
341
- return CassandraExecHandler(state, pod=pod)
305
+ return CassandraExecHandler(state, pod=pod)
@@ -1,5 +1,5 @@
1
1
  from adam.commands.command import Command
2
- from adam.commands.postgres.postgres_context import PostgresContext
2
+ from adam.commands.postgres.postgres_databases import PostgresDatabases
3
3
  from adam.config import Config
4
4
  from adam.repl_state import ReplState, RequiredState
5
5
 
@@ -26,7 +26,7 @@ class DeployPgAgent(Command):
26
26
  return super().run(cmd, state)
27
27
 
28
28
  with self.validate(args, state) as (args, state):
29
- PostgresContext.deploy_pg_agent(Config().get('pg.agent.name', 'ops-pg-agent'), state.namespace)
29
+ PostgresDatabases.deploy_pg_agent(Config().get('pg.agent.name', 'ops-pg-agent'), state.namespace)
30
30
 
31
31
  def completion(self, state: ReplState):
32
32
  return super().completion(state)
@@ -1,5 +1,5 @@
1
1
  from adam.commands.command import Command
2
- from adam.commands.postgres.postgres_context import PostgresContext
2
+ from adam.commands.postgres.postgres_databases import PostgresDatabases
3
3
  from adam.config import Config
4
4
  from adam.repl_state import ReplState, RequiredState
5
5
  from adam.utils import ing
@@ -28,7 +28,7 @@ class UndeployPgAgent(Command):
28
28
 
29
29
  with self.validate(args, state) as (args, state):
30
30
  with ing('Deleting pod'):
31
- PostgresContext.undeploy_pg_agent(Config().get('pg.agent.name', 'ops-pg-agent'), state.namespace)
31
+ PostgresDatabases.undeploy_pg_agent(Config().get('pg.agent.name', 'ops-pg-agent'), state.namespace)
32
32
 
33
33
  return state
34
34
 
@@ -5,20 +5,35 @@ from adam.config import Config
5
5
  from adam.pod_exec_result import PodExecResult
6
6
  from adam.repl_state import BashSession, ReplState
7
7
  from adam.utils import log2
8
+ from adam.utils_k8s.pods import Pods
8
9
 
9
10
  class Device:
10
- @abstractmethod
11
- def ls(self, cmd: str, state: ReplState):
12
- pass
11
+ def pods(self, state: ReplState, me: str = None) -> tuple[list[str], str]:
12
+ return self.pod_names(state), me if me else self.pod(state)
13
13
 
14
- def ls_completion(self, cmd: str, state: ReplState, default: dict = {}):
15
- return default
14
+ def default_pod(self, state: ReplState) -> tuple[list[str], str]:
15
+ if me := self.pod(state):
16
+ return me
17
+
18
+ if pods := self.pod_names(state):
19
+ return pods[0]
20
+
21
+ return None
22
+
23
+ def pod(self, state: ReplState) -> str:
24
+ return None
25
+
26
+ def pod_names(self, state: ReplState) -> list[str]:
27
+ return []
28
+
29
+ def default_container(self, state: ReplState) -> str:
30
+ return None
16
31
 
17
32
  @abstractmethod
18
- def cat(self, cmd: str, state: ReplState):
33
+ def ls(self, cmd: str, state: ReplState):
19
34
  pass
20
35
 
21
- def cat_completion(self, cmd: str, state: ReplState, default: dict = {}):
36
+ def ls_completion(self, cmd: str, state: ReplState, default: dict = {}):
22
37
  return default
23
38
 
24
39
  def cd(self, dir: str, state: ReplState):
@@ -27,6 +42,9 @@ class Device:
27
42
  def cd_completion(self, cmd: str, state: ReplState, default: dict = {}):
28
43
  return default
29
44
 
45
+ def direct_dirs(self, cmd: str, state: ReplState, default: dict = {}) -> list[str]:
46
+ return []
47
+
30
48
  @abstractmethod
31
49
  def pwd(self, state: ReplState):
32
50
  pass
@@ -115,4 +133,17 @@ class Device:
115
133
  pass
116
134
 
117
135
  def bash_completion(self, cmd: str, state: ReplState, default: dict = {}):
118
- return default
136
+ return default
137
+
138
+ def files(self, state: ReplState):
139
+ r: PodExecResult = Pods.exec(self.default_pod(state), self.default_container(state), state.namespace, f'find -maxdepth 1 -type f', show_out=Config().is_debug(), shell='bash')
140
+
141
+ log_files = []
142
+ for line in r.stdout.split('\n'):
143
+ line = line.strip(' \r')
144
+ if line:
145
+ if line.startswith('./'):
146
+ line = line[2:]
147
+ log_files.append(line)
148
+
149
+ return log_files