kaqing 2.0.145__py3-none-any.whl → 2.0.189__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 (209) 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 +4 -4
  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 +106 -0
  22. adam/commands/audit/audit.py +21 -40
  23. adam/commands/audit/audit_repair_tables.py +14 -19
  24. adam/commands/audit/audit_run.py +14 -22
  25. adam/commands/audit/completions_l.py +15 -0
  26. adam/commands/audit/show_last10.py +4 -19
  27. adam/commands/audit/show_slow10.py +4 -18
  28. adam/commands/audit/show_top10.py +4 -16
  29. adam/commands/audit/utils_show_top10.py +15 -3
  30. adam/commands/bash/__init__.py +5 -0
  31. adam/commands/bash/bash.py +7 -104
  32. adam/commands/bash/utils_bash.py +16 -0
  33. adam/commands/cat.py +7 -27
  34. adam/commands/cd.py +7 -11
  35. adam/commands/check.py +15 -24
  36. adam/commands/cli_commands.py +8 -4
  37. adam/commands/clipboard_copy.py +87 -0
  38. adam/commands/code.py +21 -24
  39. adam/commands/command.py +207 -42
  40. adam/commands/commands_utils.py +25 -27
  41. adam/commands/cql/completions_c.py +28 -0
  42. adam/commands/cql/cqlsh.py +9 -33
  43. adam/commands/cql/{cql_utils.py → utils_cql.py} +111 -15
  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 +64 -68
  51. adam/commands/deploy/undeploy.py +4 -27
  52. adam/commands/deploy/undeploy_frontend.py +4 -7
  53. adam/commands/deploy/undeploy_pg_agent.py +5 -8
  54. adam/commands/deploy/undeploy_pod.py +9 -12
  55. adam/commands/devices/device.py +124 -2
  56. adam/commands/devices/device_app.py +41 -24
  57. adam/commands/devices/device_auit_log.py +10 -4
  58. adam/commands/devices/device_cass.py +48 -14
  59. adam/commands/devices/device_export.py +13 -12
  60. adam/commands/devices/device_postgres.py +105 -54
  61. adam/commands/download_file.py +47 -0
  62. adam/commands/exit.py +1 -4
  63. adam/commands/export/clean_up_all_export_sessions.py +37 -0
  64. adam/commands/export/clean_up_export_sessions.py +9 -10
  65. adam/commands/export/completions_x.py +11 -0
  66. adam/commands/export/download_export_session.py +40 -0
  67. adam/commands/export/drop_export_database.py +7 -26
  68. adam/commands/export/drop_export_databases.py +5 -14
  69. adam/commands/export/export.py +6 -52
  70. adam/commands/export/export_databases.py +108 -32
  71. adam/commands/export/export_select.py +8 -59
  72. adam/commands/export/export_sessions.py +209 -0
  73. adam/commands/export/export_use.py +14 -20
  74. adam/commands/export/export_x_select.py +48 -0
  75. adam/commands/export/exporter.py +135 -167
  76. adam/commands/export/import_files.py +44 -0
  77. adam/commands/export/import_session.py +11 -35
  78. adam/commands/export/importer.py +19 -5
  79. adam/commands/export/importer_athena.py +112 -44
  80. adam/commands/export/importer_sqlite.py +42 -22
  81. adam/commands/export/show_column_counts.py +13 -31
  82. adam/commands/export/show_export_databases.py +7 -7
  83. adam/commands/export/show_export_session.py +8 -20
  84. adam/commands/export/show_export_sessions.py +6 -16
  85. adam/commands/export/utils_export.py +64 -11
  86. adam/commands/find_files.py +51 -0
  87. adam/commands/find_processes.py +76 -0
  88. adam/commands/head.py +36 -0
  89. adam/commands/help.py +2 -2
  90. adam/commands/intermediate_command.py +52 -0
  91. adam/commands/issues.py +11 -43
  92. adam/commands/kubectl.py +3 -6
  93. adam/commands/login.py +22 -24
  94. adam/commands/logs.py +3 -6
  95. adam/commands/ls.py +9 -10
  96. adam/commands/medusa/medusa.py +4 -22
  97. adam/commands/medusa/medusa_backup.py +20 -27
  98. adam/commands/medusa/medusa_restore.py +49 -46
  99. adam/commands/medusa/medusa_show_backupjobs.py +16 -18
  100. adam/commands/medusa/medusa_show_restorejobs.py +13 -18
  101. adam/commands/medusa/utils_medusa.py +15 -0
  102. adam/commands/nodetool.py +7 -21
  103. adam/commands/param_get.py +11 -14
  104. adam/commands/param_set.py +8 -12
  105. adam/commands/postgres/completions_p.py +22 -0
  106. adam/commands/postgres/postgres.py +34 -57
  107. adam/commands/postgres/postgres_databases.py +270 -0
  108. adam/commands/postgres/postgres_ls.py +4 -8
  109. adam/commands/postgres/postgres_preview.py +5 -9
  110. adam/commands/postgres/utils_postgres.py +79 -0
  111. adam/commands/preview_table.py +8 -45
  112. adam/commands/pwd.py +13 -16
  113. adam/commands/reaper/reaper.py +4 -27
  114. adam/commands/reaper/reaper_forward.py +49 -56
  115. adam/commands/reaper/reaper_forward_session.py +6 -0
  116. adam/commands/reaper/reaper_forward_stop.py +10 -16
  117. adam/commands/reaper/reaper_restart.py +7 -14
  118. adam/commands/reaper/reaper_run_abort.py +8 -33
  119. adam/commands/reaper/reaper_runs.py +43 -58
  120. adam/commands/reaper/reaper_runs_abort.py +29 -49
  121. adam/commands/reaper/reaper_schedule_activate.py +14 -33
  122. adam/commands/reaper/reaper_schedule_start.py +9 -33
  123. adam/commands/reaper/reaper_schedule_stop.py +9 -33
  124. adam/commands/reaper/reaper_schedules.py +4 -14
  125. adam/commands/reaper/reaper_status.py +8 -16
  126. adam/commands/reaper/utils_reaper.py +203 -0
  127. adam/commands/repair/repair.py +4 -22
  128. adam/commands/repair/repair_log.py +5 -11
  129. adam/commands/repair/repair_run.py +27 -34
  130. adam/commands/repair/repair_scan.py +32 -40
  131. adam/commands/repair/repair_stop.py +5 -12
  132. adam/commands/report.py +27 -29
  133. adam/commands/restart.py +25 -26
  134. adam/commands/rollout.py +19 -24
  135. adam/commands/shell.py +12 -4
  136. adam/commands/show/show.py +11 -27
  137. adam/commands/show/show_adam.py +3 -3
  138. adam/commands/show/show_cassandra_repairs.py +37 -0
  139. adam/commands/show/show_cassandra_status.py +47 -51
  140. adam/commands/show/show_cassandra_version.py +5 -18
  141. adam/commands/show/show_cli_commands.py +56 -0
  142. adam/commands/show/show_host.py +1 -1
  143. adam/commands/show/show_login.py +20 -27
  144. adam/commands/show/show_params.py +2 -5
  145. adam/commands/show/show_processes.py +18 -21
  146. adam/commands/show/show_storage.py +11 -20
  147. adam/commands/watch.py +26 -29
  148. adam/config.py +5 -16
  149. adam/embedded_params.py +1 -1
  150. adam/log.py +4 -4
  151. adam/pod_exec_result.py +3 -3
  152. adam/repl.py +45 -39
  153. adam/repl_commands.py +26 -19
  154. adam/repl_session.py +8 -1
  155. adam/repl_state.py +85 -36
  156. adam/sql/lark_completer.py +284 -0
  157. adam/sql/lark_parser.py +604 -0
  158. adam/sql/sql_completer.py +4 -6
  159. adam/sql/sql_state_machine.py +29 -16
  160. adam/sso/authn_ad.py +6 -8
  161. adam/sso/authn_okta.py +4 -6
  162. adam/sso/cred_cache.py +3 -5
  163. adam/sso/idp.py +9 -12
  164. adam/utils.py +484 -37
  165. adam/utils_athena.py +19 -19
  166. adam/utils_audits.py +12 -12
  167. adam/utils_issues.py +32 -0
  168. adam/utils_k8s/app_clusters.py +14 -19
  169. adam/utils_k8s/app_pods.py +7 -2
  170. adam/utils_k8s/cassandra_clusters.py +30 -19
  171. adam/utils_k8s/cassandra_nodes.py +2 -2
  172. adam/utils_k8s/custom_resources.py +16 -17
  173. adam/utils_k8s/ingresses.py +2 -2
  174. adam/utils_k8s/jobs.py +7 -11
  175. adam/utils_k8s/k8s.py +96 -0
  176. adam/utils_k8s/kube_context.py +2 -2
  177. adam/utils_k8s/pods.py +37 -81
  178. adam/utils_k8s/secrets.py +4 -4
  179. adam/utils_k8s/service_accounts.py +5 -4
  180. adam/utils_k8s/services.py +2 -2
  181. adam/utils_k8s/statefulsets.py +6 -14
  182. adam/utils_local.py +4 -0
  183. adam/utils_repl/appendable_completer.py +6 -0
  184. adam/utils_repl/repl_completer.py +128 -2
  185. adam/utils_repl/state_machine.py +3 -3
  186. adam/utils_sqlite.py +78 -42
  187. adam/version.py +1 -1
  188. {kaqing-2.0.145.dist-info → kaqing-2.0.189.dist-info}/METADATA +1 -1
  189. kaqing-2.0.189.dist-info/RECORD +253 -0
  190. kaqing-2.0.189.dist-info/top_level.txt +2 -0
  191. teddy/__init__.py +0 -0
  192. teddy/lark_parser.py +436 -0
  193. teddy/lark_parser2.py +618 -0
  194. adam/commands/app.py +0 -67
  195. adam/commands/cp.py +0 -95
  196. adam/commands/cql/cql_completions.py +0 -28
  197. adam/commands/export/clean_up_export_session.py +0 -53
  198. adam/commands/export/export_select_x.py +0 -54
  199. adam/commands/postgres/postgres_context.py +0 -248
  200. adam/commands/postgres/postgres_utils.py +0 -31
  201. adam/commands/postgres/psql_completions.py +0 -10
  202. adam/commands/reaper/reaper_session.py +0 -159
  203. adam/commands/show/show_app_actions.py +0 -56
  204. adam/commands/show/show_commands.py +0 -61
  205. adam/commands/show/show_repairs.py +0 -47
  206. kaqing-2.0.145.dist-info/RECORD +0 -227
  207. kaqing-2.0.145.dist-info/top_level.txt +0 -1
  208. {kaqing-2.0.145.dist-info → kaqing-2.0.189.dist-info}/WHEEL +0 -0
  209. {kaqing-2.0.145.dist-info → kaqing-2.0.189.dist-info}/entry_points.txt +0 -0
@@ -1,16 +1,7 @@
1
- from typing import Callable
2
-
3
- from adam.commands.bash.bash_completer import BashCompleter
1
+ from adam.commands.bash import bash
4
2
  from adam.commands.command import Command
5
- from adam.utils_k8s.app_clusters import AppClusters
6
- from adam.utils_k8s.app_pods import AppPods
7
- from adam.utils_k8s.cassandra_clusters import CassandraClusters
8
- from adam.utils_k8s.cassandra_nodes import CassandraNodes
9
- from adam.pod_exec_result import PodExecResult
10
- from adam.repl_state import BashSession, ReplState, RequiredState
11
- from adam.utils_k8s.pods import Pods
12
- from adam.utils_k8s.statefulsets import StatefulSets
13
- from adam.utils_k8s.cassandra_nodes import CassandraNodes
3
+ from adam.commands.devices.devices import Devices
4
+ from adam.repl_state import ReplState, RequiredState
14
5
 
15
6
  class Bash(Command):
16
7
  COMMAND = 'bash'
@@ -34,100 +25,12 @@ class Bash(Command):
34
25
  if not(args := self.args(cmd)):
35
26
  return super().run(cmd, s0)
36
27
 
37
- state, args = self.apply_state(args, s0, args_to_check=2)
38
- if not self.validate_state(state):
39
- return state
40
-
41
- def _run(state_changed: bool, cli: Callable[[str], None]):
42
- if state.in_repl:
43
- if state_changed:
44
- r = self.exec_with_dir(state, args)
45
- else:
46
- r = self.exec_with_dir(s0, args)
47
-
48
- if not r:
49
- state.exit_bash()
50
-
51
- return 'inconsistent pwd'
52
-
53
- return r
54
- else:
55
- cli(' '.join(args))
56
-
57
- return state
58
-
59
- if state.device == ReplState.A:
60
- def cli(command: str):
61
- if state.app_pod:
62
- AppPods.exec(state.app_pod, state.namespace, command, show_out=True)
63
- elif state.app_app:
64
- AppClusters.exec(AppPods.pod_names(state.namespace, state.app_env, state.app_app), state.namespace, command, action='bash', show_out=True)
65
-
66
- return _run(s0.app_env != state.app_env or s0.app_app != state.app_app or s0.app_pod != state.app_pod, cli)
67
- elif state.device == ReplState.P:
68
- def cli(command: str):
69
- Pods.exec(state.app_pod, 'ops', state.namespace, command, show_out=True)
70
-
71
- return _run(s0.pg_path != state.pg_path, cli)
72
-
73
- def cli(command: str):
74
- if state.pod:
75
- CassandraNodes.exec(state.pod, state.namespace, command, show_out=True)
76
- elif state.sts:
77
- CassandraClusters.exec(state.sts, state.namespace, command, action='bash', show_out=True)
78
-
79
- return _run(s0.sts != state.sts or s0.pod != state.pod, cli)
80
-
81
- def exec_with_dir(self, state: ReplState, args: list[str]) -> list[PodExecResult]:
82
- session_just_created = False
83
- if not args:
84
- session_just_created = True
85
- session = BashSession(state.device)
86
- state.enter_bash(session)
87
-
88
- if state.bash_session:
89
- if args != ['pwd']:
90
- if args:
91
- args.append('&&')
92
- args.extend(['pwd', '>', f'/tmp/.qing-{state.bash_session.session_id}'])
93
-
94
- if not session_just_created:
95
- if pwd := state.bash_session.pwd(state):
96
- args = ['cd', pwd, '&&'] + args
97
-
98
- command = ' '.join(args)
99
-
100
- rs = []
101
-
102
- if state.device == ReplState.A:
103
- if state.app_pod:
104
- rs = [AppPods.exec(state.app_pod, state.namespace, command,
105
- show_out=not session_just_created, shell='bash')]
106
- elif state.app_app:
107
- rs = AppClusters.exec(AppPods.pod_names(state.namespace, state.app_env, state.app_app), state.namespace, command, action='bash',
108
- show_out=not session_just_created, shell='bash')
109
- elif state.device == ReplState.P:
110
- rs = [Pods.exec(state.app_pod, 'ops', state.namespace, command,
111
- show_out=not session_just_created, shell='bash')]
112
- else:
113
- if state.pod:
114
- rs = [CassandraNodes.exec(state.pod, state.namespace, command,
115
- show_out=not session_just_created, shell='bash')]
116
- elif state.sts:
117
- rs = CassandraClusters.exec(state.sts, state.namespace, command, action='bash',
118
- show_out=not session_just_created, shell='bash')
119
-
120
- return rs
28
+ with self.validate(args, s0) as (args, s1):
29
+ with bash(s0, s1) as exec:
30
+ return exec(args)
121
31
 
122
32
  def completion(self, state: ReplState):
123
- if state.device == ReplState.A and state.app_app:
124
- return { Bash.COMMAND: BashCompleter(lambda: []) } | \
125
- {f'@{p}': {Bash.COMMAND: BashCompleter(lambda: [])} for p in AppPods.pod_names(state.namespace, state.app_env, state.app_app)}
126
- elif state.sts:
127
- return { Bash.COMMAND: BashCompleter(lambda: []) } | \
128
- {f'@{p}': {Bash.COMMAND: BashCompleter(lambda: [])} for p in StatefulSets.pod_names(state.sts, state.namespace)}
129
-
130
- return {}
33
+ return super().completion(state, {c : {'&': None} for c in ['ls', 'cat', 'head']}, pods=Devices.device(state).pods(state, '-'))
131
34
 
132
35
  def help(self, _: ReplState):
133
36
  return f'{Bash.COMMAND} [pod-name] [bash-commands] [&]\t run bash on the Cassandra nodes'
@@ -0,0 +1,16 @@
1
+ from adam.commands.devices.devices import Devices
2
+ from adam.repl_state import ReplState
3
+
4
+ class BashHandler:
5
+ def __init__(self, s0: ReplState, s1: ReplState):
6
+ self.s0 = s0
7
+ self.s1 = s1
8
+
9
+ def __enter__(self):
10
+ return self.exec
11
+
12
+ def __exit__(self, exc_type, exc_val, exc_tb):
13
+ return False
14
+
15
+ def exec(self, args: list[str]):
16
+ return Devices.device(self.s1).bash(self.s0, self.s1, args)
adam/commands/cat.py CHANGED
@@ -1,9 +1,7 @@
1
- from adam.commands.bash.bash import Bash
1
+ from adam.commands import validate_args
2
2
  from adam.commands.command import Command
3
+ from adam.commands.devices.devices import Devices
3
4
  from adam.repl_state import ReplState, RequiredState
4
- from adam.utils import log2
5
- from adam.utils_k8s.app_pods import AppPods
6
- from adam.utils_k8s.statefulsets import StatefulSets
7
5
 
8
6
  class Cat(Command):
9
7
  COMMAND = 'cat'
@@ -27,30 +25,12 @@ class Cat(Command):
27
25
  if not(args := self.args(cmd)):
28
26
  return super().run(cmd, state)
29
27
 
30
- state, args = self.apply_state(args, state)
31
-
32
- if len(args) < 1:
33
- if state.in_repl:
34
- log2('File is required.')
35
- log2()
36
- else:
37
- log2('* File is missing.')
38
- Command.display_help()
39
-
40
- return 'command-missing'
41
-
42
-
43
- return Bash().run('bash ' + cmd, state)
28
+ with self.validate(args, state) as (args, state):
29
+ with validate_args(args, state, name='file'):
30
+ return Devices.device(state).bash(state, state, cmd.split(' '))
44
31
 
45
32
  def completion(self, state: ReplState):
46
- if state.device == ReplState.A and state.app_app:
47
- return super().completion(state) | \
48
- {f'@{p}': {Cat.COMMAND: None} for p in AppPods.pod_names(state.namespace, state.app_env, state.app_app)}
49
- elif state.device == ReplState.C and state.sts:
50
- return super().completion(state) | \
51
- {f'@{p}': {Cat.COMMAND: None} for p in StatefulSets.pod_names(state.sts, state.namespace)}
52
-
53
- 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')
54
34
 
55
35
  def help(self, _: ReplState):
56
- 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/cd.py CHANGED
@@ -1,3 +1,4 @@
1
+ from adam.commands import validate_args
1
2
  from adam.commands.command import Command
2
3
  from adam.commands.devices.device import Device
3
4
  from adam.commands.devices.devices import Devices
@@ -25,18 +26,13 @@ class Cd(Command):
25
26
  if not(args := self.args(cmd)):
26
27
  return super().run(cmd, state)
27
28
 
28
- if not self.validate_state(state):
29
- return state
29
+ with self.validate(args, state, apply=False) as (args, state):
30
+ with validate_args(args, state, name='directory') as arg_str:
31
+ device: Device = Devices.device(state)
32
+ for dir in arg_str.split('/'):
33
+ device.cd(dir, state)
30
34
 
31
- if len(args) < 2:
32
- return state
33
-
34
- device: Device = Devices.device(state)
35
- arg = args[1]
36
- for dir in arg.split('/'):
37
- device.cd(dir, state)
38
-
39
- return state
35
+ return state
40
36
 
41
37
  def completion(self, state: ReplState):
42
38
  return Devices.device(state).cd_completion(Cd.COMMAND, state, default = {})
adam/commands/check.py CHANGED
@@ -2,11 +2,13 @@ import click
2
2
 
3
3
  from adam.checks.check_result import CheckResult
4
4
  from adam.checks.check_utils import all_checks, checks_from_csv, run_checks
5
+ from adam.commands import extract_options, validate_args
5
6
  from adam.commands.command import Command
6
7
  from adam.commands.command_helpers import ClusterOrPodCommandHelper
7
8
  from adam.commands.issues import Issues
8
9
  from adam.repl_state import ReplState
9
- from adam.utils import lines_to_tabular, log
10
+ from adam.utils import tabulize, log
11
+ from adam.utils_issues import IssuesUtils
10
12
 
11
13
  class Check(Issues):
12
14
  COMMAND = 'check'
@@ -30,36 +32,25 @@ class Check(Issues):
30
32
  if not(args := self.args(cmd)):
31
33
  return super().run(cmd, state)
32
34
 
33
- state, args = self.apply_state(args, state)
34
- if not self.validate_state(state):
35
- return state
35
+ with self.validate(args, state) as (args, state):
36
+ with extract_options(args, ['-s', '--show']) as (args, show_out):
37
+ with validate_args(args, state, name='check name', msg=lambda: tabulize([check.help() for check in all_checks()], separator=':')) as arg:
38
+ checks = checks_from_csv(args[0])
39
+ if not checks:
40
+ return 'invalid check name'
36
41
 
37
- args, show = Command.extract_options(args, ['-s', '--show'])
42
+ results = run_checks(state.sts, state.namespace, state.pod, checks=checks, show_out=show_out)
38
43
 
39
- if not args:
40
- if state.in_repl:
41
- log(lines_to_tabular([check.help() for check in all_checks()], separator=':'))
42
- else:
43
- log('* Check name is missing.')
44
- Command.display_help()
45
- return 'arg missing'
44
+ issues = CheckResult.collect_issues(results)
45
+ IssuesUtils.show_issues(issues, in_repl=state.in_repl)
46
46
 
47
- checks = checks_from_csv(args[0])
48
- if not checks:
49
- return 'invalid check name'
50
-
51
- results = run_checks(state.sts, state.namespace, state.pod, checks=checks, show_output=show)
52
-
53
- issues = CheckResult.collect_issues(results)
54
- Issues.show_issues(issues, in_repl=state.in_repl)
55
-
56
- return issues if issues else 'no issues found'
47
+ return issues if issues else 'no issues found'
57
48
 
58
49
  def completion(self, _: ReplState):
59
- return {Check.COMMAND: {check.name(): None for check in all_checks()}}
50
+ return {Check.COMMAND: {check.name(): {'-s': None} for check in all_checks()}}
60
51
 
61
52
  def help(self, _: ReplState):
62
- return f'{Check.COMMAND} <check-name>\t run a single check'
53
+ return f'{Check.COMMAND} <check-name> [-s]\t run a single check'
63
54
 
64
55
  class CheckCommandHelper(click.Command):
65
56
  def get_help(self, ctx: click.Context):
@@ -1,16 +1,21 @@
1
1
  import functools
2
2
  import re
3
3
 
4
- from adam.commands.reaper.reaper_session import ReaperSession
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
 
@@ -66,8 +71,7 @@ class CliCommands:
66
71
  return key.replace(f'{state.namespace}-', '').replace('-k8spg-cs-001', '')
67
72
  d |= {f'pg-{reduce_key(k)}': f'PGPASSWORD={v["postgres-admin-password"]} psql -h {v["postgres-db-endpoint"]} -p {v["postgres-db-port"]} -U {v["postgres-admin-username"]} postgres' for k, v in data.items()}
68
73
 
69
- if r := ReaperSession.create(state):
70
- reaper = r.reaper_spec(state)
74
+ if reaper := Reapers.reaper_spec(state):
71
75
  d |= {
72
76
  'reaper-exec': reaper["exec"],
73
77
  'reaper-forward': reaper["forward"],
@@ -0,0 +1,87 @@
1
+ from functools import partial
2
+ import click
3
+ import pyperclip
4
+
5
+ from adam.commands import validate_args
6
+ from adam.commands.command import Command, InvalidArgumentsException
7
+ from adam.commands.command_helpers import ClusterOrPodCommandHelper
8
+ from adam.commands.cli_commands import CliCommands
9
+ from adam.config import Config
10
+ from adam.repl_state import ReplState, RequiredState
11
+ from adam.utils import tabulize, log, log2
12
+
13
+ class ClipboardCopy(Command):
14
+ COMMAND = 'cli cp'
15
+
16
+ # the singleton pattern
17
+ def __new__(cls, *args, **kwargs):
18
+ if not hasattr(cls, 'instance'): cls.instance = super(ClipboardCopy, cls).__new__(cls)
19
+
20
+ return cls.instance
21
+
22
+ def __init__(self, successor: Command=None):
23
+ super().__init__(successor)
24
+
25
+ def command(self):
26
+ return ClipboardCopy.COMMAND
27
+
28
+ def required(self):
29
+ return RequiredState.CLUSTER_OR_POD
30
+
31
+ def run(self, cmd: str, state: ReplState):
32
+ if not(args := self.args(cmd)):
33
+ return super().run(cmd, state)
34
+
35
+ with self.validate(args, state) as (args, state):
36
+ def display_keys(missing = False):
37
+ if missing:
38
+ log2('Key is required.')
39
+ else:
40
+ log2('Key is invalid.')
41
+ log2()
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)
47
+
48
+ with validate_args(args, state, name='key', msg=partial(display_keys, True)) as key:
49
+ if not key in CliCommands.values(state):
50
+ if state.in_repl:
51
+ display_keys(False)
52
+ else:
53
+ log2('* Invalid key')
54
+ Command.display_help()
55
+
56
+ raise InvalidArgumentsException()
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 state
64
+
65
+ def completion(self, state: ReplState):
66
+ return super().completion(state, lambda: {key: None for key in CliCommands.values(state).keys()}, auto_key='cli.cp-auto-complete')
67
+
68
+ def help(self, _: ReplState):
69
+ return f"{ClipboardCopy.COMMAND} <key>\t copy a value to clipboard for conveninence"
70
+
71
+ class CopyCommandHelper(click.Command):
72
+ def lines(self):
73
+ return [
74
+ 'node-exec-?: kubectl exec command to the Cassandra pod',
75
+ 'reaper-exec: kubectl exec command to the Reaper pod',
76
+ 'reaper-forward: kubectl port-forward command to the Reaper pod',
77
+ 'reaper-ui: uri to Reaper ui',
78
+ 'reaper-username: Reaper user name',
79
+ 'reaper-password: Reaper password',
80
+ ]
81
+
82
+ def get_help(self, ctx: click.Context):
83
+ log(super().get_help(ctx))
84
+ log()
85
+ tabulize(self.lines(), header='KEY:DESC', separator=':')
86
+ log()
87
+ ClusterOrPodCommandHelper.cluter_or_pod_help()
adam/commands/code.py CHANGED
@@ -2,9 +2,9 @@ import code
2
2
  from functools import partial
3
3
 
4
4
  from adam.commands.command import Command
5
- from adam.commands.cql.cql_utils import cassandra_table_names, run_cql
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):
@@ -29,29 +29,26 @@ class Code(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
32
+ with self.validate(args, state) as (args, state):
33
+ sts = state.sts
34
+ pod = state.pod
35
+ pods = StatefulSets.pod_names(state.sts, state.namespace)
36
+ tables = cassandra_table_names(state)
37
+ cql = partial(run_cql, state, show_out=True)
38
+
39
+ my_local = globals() | locals()
40
+ # my_local = globals() | {'StatefulSets': StatefulSets} | locals()
41
+ lines = [
42
+ 'sts: StatefulSet name',
43
+ 'pod: Pod name',
44
+ 'pods: Pod names in the current StatefulSet',
45
+ 'tables: Cassandra tables names in the current StatefulSet',
46
+ "cql('select...'): run cql statement"
47
+ ]
48
+
49
+ code.interact(local=my_local, banner=tabulize(lines, header='Variables', separator=':'))
35
50
 
36
- sts = state.sts
37
- pod = state.pod
38
- pods = StatefulSets.pod_names(state.sts, state.namespace)
39
- tables = cassandra_table_names(state)
40
- cql = partial(run_cql, state, show_out=True)
41
-
42
- my_local = globals() | locals()
43
- # my_local = globals() | {'StatefulSets': StatefulSets} | locals()
44
- lines = [
45
- 'sts: StatefulSet name',
46
- 'pod: Pod name',
47
- 'pods: Pod names in the current StatefulSet',
48
- 'tables: Cassandra tables names in the current StatefulSet',
49
- "cql('select...'): run cql statement"
50
- ]
51
-
52
- code.interact(local=my_local, banner=lines_to_tabular(lines, header='Variables', separator=':'))
53
-
54
- return state
51
+ return state
55
52
 
56
53
  def completion(self, state: ReplState):
57
54
  return super().completion(state)