kaqing 2.0.14__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 (228) hide show
  1. adam/__init__.py +0 -2
  2. adam/app_session.py +9 -12
  3. adam/apps.py +20 -6
  4. adam/batch.py +16 -6
  5. adam/checks/check_utils.py +19 -49
  6. adam/checks/compactionstats.py +1 -1
  7. adam/checks/cpu.py +9 -3
  8. adam/checks/cpu_metrics.py +52 -0
  9. adam/checks/disk.py +3 -4
  10. adam/checks/gossip.py +1 -1
  11. adam/checks/memory.py +3 -3
  12. adam/checks/status.py +1 -1
  13. adam/columns/columns.py +3 -1
  14. adam/columns/cpu.py +3 -1
  15. adam/columns/cpu_metrics.py +22 -0
  16. adam/columns/memory.py +3 -4
  17. adam/commands/__init__.py +24 -0
  18. adam/commands/alter_tables.py +66 -0
  19. adam/commands/app/app.py +38 -0
  20. adam/commands/{app_ping.py → app/app_ping.py} +8 -14
  21. adam/commands/app/show_app_actions.py +49 -0
  22. adam/commands/{show → app}/show_app_id.py +9 -12
  23. adam/commands/{show → app}/show_app_queues.py +8 -14
  24. adam/commands/app/utils_app.py +106 -0
  25. adam/commands/audit/__init__.py +0 -0
  26. adam/commands/audit/audit.py +67 -0
  27. adam/commands/audit/audit_repair_tables.py +72 -0
  28. adam/commands/audit/audit_run.py +50 -0
  29. adam/commands/audit/completions_l.py +15 -0
  30. adam/commands/audit/show_last10.py +36 -0
  31. adam/commands/audit/show_slow10.py +36 -0
  32. adam/commands/audit/show_top10.py +36 -0
  33. adam/commands/audit/utils_show_top10.py +71 -0
  34. adam/commands/bash/__init__.py +5 -0
  35. adam/commands/bash/bash.py +36 -0
  36. adam/commands/bash/bash_completer.py +93 -0
  37. adam/commands/bash/utils_bash.py +16 -0
  38. adam/commands/cat.py +36 -0
  39. adam/commands/cd.py +14 -88
  40. adam/commands/check.py +18 -21
  41. adam/commands/cli_commands.py +11 -7
  42. adam/commands/clipboard_copy.py +87 -0
  43. adam/commands/code.py +57 -0
  44. adam/commands/command.py +220 -19
  45. adam/commands/commands_utils.py +28 -31
  46. adam/commands/cql/__init__.py +0 -0
  47. adam/commands/cql/completions_c.py +28 -0
  48. adam/commands/{cqlsh.py → cql/cqlsh.py} +13 -32
  49. adam/commands/cql/utils_cql.py +305 -0
  50. adam/commands/deploy/code_start.py +7 -10
  51. adam/commands/deploy/code_stop.py +4 -21
  52. adam/commands/deploy/code_utils.py +5 -5
  53. adam/commands/deploy/deploy.py +4 -40
  54. adam/commands/deploy/deploy_frontend.py +15 -18
  55. adam/commands/deploy/deploy_pg_agent.py +4 -7
  56. adam/commands/deploy/deploy_pod.py +74 -77
  57. adam/commands/deploy/deploy_utils.py +16 -26
  58. adam/commands/deploy/undeploy.py +4 -40
  59. adam/commands/deploy/undeploy_frontend.py +5 -8
  60. adam/commands/deploy/undeploy_pg_agent.py +7 -8
  61. adam/commands/deploy/undeploy_pod.py +16 -17
  62. adam/commands/devices/__init__.py +0 -0
  63. adam/commands/devices/device.py +149 -0
  64. adam/commands/devices/device_app.py +163 -0
  65. adam/commands/devices/device_auit_log.py +49 -0
  66. adam/commands/devices/device_cass.py +179 -0
  67. adam/commands/devices/device_export.py +87 -0
  68. adam/commands/devices/device_postgres.py +160 -0
  69. adam/commands/devices/devices.py +25 -0
  70. adam/commands/download_file.py +47 -0
  71. adam/commands/exit.py +1 -4
  72. adam/commands/export/__init__.py +0 -0
  73. adam/commands/export/clean_up_all_export_sessions.py +37 -0
  74. adam/commands/export/clean_up_export_sessions.py +39 -0
  75. adam/commands/export/completions_x.py +11 -0
  76. adam/commands/export/download_export_session.py +40 -0
  77. adam/commands/export/drop_export_database.py +39 -0
  78. adam/commands/export/drop_export_databases.py +37 -0
  79. adam/commands/export/export.py +37 -0
  80. adam/commands/export/export_databases.py +246 -0
  81. adam/commands/export/export_select.py +34 -0
  82. adam/commands/export/export_sessions.py +209 -0
  83. adam/commands/export/export_use.py +49 -0
  84. adam/commands/export/export_x_select.py +48 -0
  85. adam/commands/export/exporter.py +332 -0
  86. adam/commands/export/import_files.py +44 -0
  87. adam/commands/export/import_session.py +44 -0
  88. adam/commands/export/importer.py +81 -0
  89. adam/commands/export/importer_athena.py +148 -0
  90. adam/commands/export/importer_sqlite.py +67 -0
  91. adam/commands/export/show_column_counts.py +45 -0
  92. adam/commands/export/show_export_databases.py +39 -0
  93. adam/commands/export/show_export_session.py +39 -0
  94. adam/commands/export/show_export_sessions.py +37 -0
  95. adam/commands/export/utils_export.py +344 -0
  96. adam/commands/find_files.py +51 -0
  97. adam/commands/find_processes.py +76 -0
  98. adam/commands/head.py +36 -0
  99. adam/commands/help.py +14 -9
  100. adam/commands/intermediate_command.py +52 -0
  101. adam/commands/issues.py +14 -40
  102. adam/commands/kubectl.py +38 -0
  103. adam/commands/login.py +26 -25
  104. adam/commands/logs.py +5 -7
  105. adam/commands/ls.py +11 -115
  106. adam/commands/medusa/medusa.py +4 -46
  107. adam/commands/medusa/medusa_backup.py +22 -29
  108. adam/commands/medusa/medusa_restore.py +51 -49
  109. adam/commands/medusa/medusa_show_backupjobs.py +20 -21
  110. adam/commands/medusa/medusa_show_restorejobs.py +16 -21
  111. adam/commands/medusa/utils_medusa.py +15 -0
  112. adam/commands/nodetool.py +8 -17
  113. adam/commands/param_get.py +11 -14
  114. adam/commands/param_set.py +9 -13
  115. adam/commands/postgres/completions_p.py +22 -0
  116. adam/commands/postgres/postgres.py +49 -73
  117. adam/commands/postgres/postgres_databases.py +270 -0
  118. adam/commands/postgres/postgres_ls.py +4 -8
  119. adam/commands/postgres/postgres_preview.py +5 -9
  120. adam/commands/postgres/utils_postgres.py +79 -0
  121. adam/commands/preview_table.py +10 -69
  122. adam/commands/pwd.py +14 -43
  123. adam/commands/reaper/reaper.py +6 -49
  124. adam/commands/reaper/reaper_forward.py +49 -56
  125. adam/commands/reaper/reaper_forward_session.py +6 -0
  126. adam/commands/reaper/reaper_forward_stop.py +10 -16
  127. adam/commands/reaper/reaper_restart.py +8 -15
  128. adam/commands/reaper/reaper_run_abort.py +8 -33
  129. adam/commands/reaper/reaper_runs.py +43 -58
  130. adam/commands/reaper/reaper_runs_abort.py +29 -49
  131. adam/commands/reaper/reaper_schedule_activate.py +14 -33
  132. adam/commands/reaper/reaper_schedule_start.py +9 -33
  133. adam/commands/reaper/reaper_schedule_stop.py +9 -33
  134. adam/commands/reaper/reaper_schedules.py +4 -14
  135. adam/commands/reaper/reaper_status.py +8 -16
  136. adam/commands/reaper/utils_reaper.py +203 -0
  137. adam/commands/repair/repair.py +4 -46
  138. adam/commands/repair/repair_log.py +6 -12
  139. adam/commands/repair/repair_run.py +29 -36
  140. adam/commands/repair/repair_scan.py +33 -41
  141. adam/commands/repair/repair_stop.py +6 -13
  142. adam/commands/report.py +25 -21
  143. adam/commands/restart.py +27 -28
  144. adam/commands/rollout.py +20 -25
  145. adam/commands/shell.py +12 -4
  146. adam/commands/show/show.py +15 -46
  147. adam/commands/show/show_adam.py +3 -3
  148. adam/commands/show/show_cassandra_repairs.py +37 -0
  149. adam/commands/show/show_cassandra_status.py +48 -52
  150. adam/commands/show/show_cassandra_version.py +5 -18
  151. adam/commands/show/show_cli_commands.py +56 -0
  152. adam/commands/show/show_host.py +33 -0
  153. adam/commands/show/show_login.py +23 -27
  154. adam/commands/show/show_params.py +2 -5
  155. adam/commands/show/show_processes.py +18 -21
  156. adam/commands/show/show_storage.py +11 -20
  157. adam/commands/watch.py +27 -30
  158. adam/config.py +8 -6
  159. adam/embedded_params.py +1 -1
  160. adam/log.py +4 -4
  161. adam/pod_exec_result.py +13 -5
  162. adam/repl.py +136 -120
  163. adam/repl_commands.py +66 -24
  164. adam/repl_session.py +8 -1
  165. adam/repl_state.py +343 -73
  166. adam/sql/__init__.py +0 -0
  167. adam/sql/lark_completer.py +284 -0
  168. adam/sql/lark_parser.py +604 -0
  169. adam/sql/sql_completer.py +118 -0
  170. adam/sql/sql_state_machine.py +630 -0
  171. adam/sql/term_completer.py +76 -0
  172. adam/sso/authn_ad.py +7 -9
  173. adam/sso/authn_okta.py +4 -6
  174. adam/sso/cred_cache.py +4 -6
  175. adam/sso/idp.py +10 -13
  176. adam/utils.py +539 -11
  177. adam/utils_athena.py +145 -0
  178. adam/utils_audits.py +102 -0
  179. adam/utils_issues.py +32 -0
  180. adam/utils_k8s/__init__.py +0 -0
  181. adam/utils_k8s/app_clusters.py +28 -0
  182. adam/utils_k8s/app_pods.py +36 -0
  183. adam/utils_k8s/cassandra_clusters.py +44 -0
  184. adam/{k8s_utils → utils_k8s}/cassandra_nodes.py +12 -5
  185. adam/{k8s_utils → utils_k8s}/custom_resources.py +16 -17
  186. adam/{k8s_utils → utils_k8s}/deployment.py +2 -2
  187. adam/{k8s_utils → utils_k8s}/ingresses.py +2 -2
  188. adam/{k8s_utils → utils_k8s}/jobs.py +7 -11
  189. adam/utils_k8s/k8s.py +96 -0
  190. adam/{k8s_utils → utils_k8s}/kube_context.py +3 -3
  191. adam/{k8s_utils → utils_k8s}/pods.py +132 -83
  192. adam/{k8s_utils → utils_k8s}/secrets.py +7 -3
  193. adam/{k8s_utils → utils_k8s}/service_accounts.py +5 -4
  194. adam/{k8s_utils → utils_k8s}/services.py +2 -2
  195. adam/{k8s_utils → utils_k8s}/statefulsets.py +9 -16
  196. adam/utils_local.py +4 -0
  197. adam/utils_net.py +24 -0
  198. adam/utils_repl/__init__.py +0 -0
  199. adam/utils_repl/appendable_completer.py +6 -0
  200. adam/utils_repl/automata_completer.py +48 -0
  201. adam/utils_repl/repl_completer.py +172 -0
  202. adam/utils_repl/state_machine.py +173 -0
  203. adam/utils_sqlite.py +137 -0
  204. adam/version.py +1 -1
  205. {kaqing-2.0.14.dist-info → kaqing-2.0.189.dist-info}/METADATA +1 -1
  206. kaqing-2.0.189.dist-info/RECORD +253 -0
  207. kaqing-2.0.189.dist-info/top_level.txt +2 -0
  208. teddy/__init__.py +0 -0
  209. teddy/lark_parser.py +436 -0
  210. teddy/lark_parser2.py +618 -0
  211. adam/commands/app.py +0 -67
  212. adam/commands/bash.py +0 -87
  213. adam/commands/cp.py +0 -95
  214. adam/commands/cql_utils.py +0 -53
  215. adam/commands/devices.py +0 -89
  216. adam/commands/postgres/postgres_session.py +0 -247
  217. adam/commands/reaper/reaper_session.py +0 -159
  218. adam/commands/show/show_app_actions.py +0 -53
  219. adam/commands/show/show_commands.py +0 -61
  220. adam/commands/show/show_repairs.py +0 -47
  221. adam/k8s_utils/cassandra_clusters.py +0 -48
  222. kaqing-2.0.14.dist-info/RECORD +0 -167
  223. kaqing-2.0.14.dist-info/top_level.txt +0 -1
  224. /adam/{k8s_utils → commands/app}/__init__.py +0 -0
  225. /adam/{k8s_utils → utils_k8s}/config_maps.py +0 -0
  226. /adam/{k8s_utils → utils_k8s}/volumes.py +0 -0
  227. {kaqing-2.0.14.dist-info → kaqing-2.0.189.dist-info}/WHEEL +0 -0
  228. {kaqing-2.0.14.dist-info → kaqing-2.0.189.dist-info}/entry_points.txt +0 -0
adam/commands/rollout.py CHANGED
@@ -2,9 +2,10 @@ import datetime
2
2
  from kubernetes import client
3
3
  from kubernetes.client.rest import ApiException
4
4
 
5
+ from adam.commands import extract_options
5
6
  from adam.commands.command import Command
6
7
  from adam.commands.watch import Watch
7
- from adam.k8s_utils.statefulsets import StatefulSets
8
+ from adam.utils_k8s.statefulsets import StatefulSets
8
9
  from adam.config import Config
9
10
  from adam.repl_state import ReplState, RequiredState
10
11
  from adam.utils import duration, log2
@@ -31,32 +32,28 @@ class RollOut(Command):
31
32
  if not(args := self.args(cmd)):
32
33
  return super().run(cmd, state)
33
34
 
34
- state, args = self.apply_state(args, state)
35
- if not self.validate_state(state):
36
- return state
35
+ with self.validate(args, state) as (args, state):
36
+ with extract_options(args, '--force') as (args, forced):
37
+ restarted, rollingout = StatefulSets.restarted_at(state.sts, state.namespace)
38
+ if rollingout and not forced:
39
+ log2(f"* Cluster is being rolled out for {duration(restarted)}. Please wait until it's done or use --force.")
37
40
 
38
- args, forced = Command.extract_options(args, '--force')
41
+ return state
39
42
 
40
- restarted, rollingout = StatefulSets.restarted_at(state.sts, state.namespace)
41
- if rollingout and not forced:
42
- log2(f"* Cluster is being rolled out for {duration(restarted)}. Please wait until it's done or use --force.")
43
+ self.rolling_restart(state.sts, state.namespace)
43
44
 
44
- return state
45
+ auto_watch = False
46
+ if (auto_watch_cmds := Config().get('watch.auto', 'rollout')):
47
+ cmds = [c.strip(' ') for c in auto_watch_cmds.split(',')]
48
+ if self.command() in cmds:
49
+ auto_watch = True
50
+ log2('Rolling out cluster with auto watch...')
51
+ Watch().run('watch', state)
45
52
 
46
- self.rolling_restart(state.sts, state.namespace)
53
+ if not auto_watch:
54
+ log2('Rolling out cluster...')
47
55
 
48
- auto_watch = False
49
- if (auto_watch_cmds := Config().get('watch.auto', 'rollout')):
50
- cmds = [c.strip(' ') for c in auto_watch_cmds.split(',')]
51
- if self.command() in cmds:
52
- auto_watch = True
53
- log2('Rolling out cluster with auto watch...')
54
- Watch().run('watch', state)
55
-
56
- if not auto_watch:
57
- log2('Rolling out cluster...')
58
-
59
- return state
56
+ return state
60
57
 
61
58
  def rolling_restart(self, statefulset, namespace):
62
59
  # kubectl rollout restart statefulset <statefulset-name>
@@ -82,9 +79,7 @@ class RollOut(Command):
82
79
  log2("Exception when calling AppsV1Api->read_namespaced_statefulset_status: %s\n" % e)
83
80
 
84
81
  def completion(self, state: ReplState):
85
- if state.pod:
86
- return {}
87
- elif state.sts:
82
+ if super().completion(state):
88
83
  return {RollOut.COMMAND: None}
89
84
 
90
85
  return {}
adam/commands/shell.py CHANGED
@@ -1,7 +1,9 @@
1
1
  import os
2
2
 
3
+ from adam.commands import validate_args
3
4
  from adam.commands.command import Command
4
5
  from adam.repl_state import ReplState
6
+ from adam.utils import log2
5
7
 
6
8
  class Shell(Command):
7
9
  COMMAND = ':sh'
@@ -18,13 +20,19 @@ class Shell(Command):
18
20
  def command(self):
19
21
  return Shell.COMMAND
20
22
 
21
- def run(self, cmd: str, s0: ReplState):
23
+ def run(self, cmd: str, state: ReplState):
22
24
  if not(args := self.args(cmd)):
23
- return super().run(cmd, s0)
25
+ return super().run(cmd, state)
24
26
 
25
- _, args = self.apply_state(args, s0)
27
+ with self.validate(args, state) as (args, _):
28
+ with validate_args(args, state, at_least=0) as args_str:
29
+ if args_str:
30
+ os.system(args_str)
31
+ log2()
32
+ else:
33
+ os.system('QING_DROPPED=true bash')
26
34
 
27
- os.system('QING_DROPPED=true bash')
35
+ return state
28
36
 
29
37
  def completion(self, state: ReplState):
30
38
  return super().completion(state)
@@ -1,23 +1,23 @@
1
1
  import click
2
2
 
3
- from adam.commands.command import Command
4
- from adam.commands.command_helpers import ClusterCommandHelper
5
- from adam.commands.show.show_app_actions import ShowAppActions
6
- from adam.commands.show.show_app_queues import ShowAppQueues
3
+ from adam.commands.app.show_app_actions import ShowAppActions
4
+ from adam.commands.app.show_app_id import ShowAppId
5
+ from adam.commands.app.show_app_queues import ShowAppQueues
6
+ from adam.commands.intermediate_command import IntermediateCommand
7
+ from adam.commands.medusa.medusa_show_backupjobs import MedusaShowBackupJobs
8
+ from adam.commands.medusa.medusa_show_restorejobs import MedusaShowRestoreJobs
9
+ from adam.commands.show.show_host import ShowHost
7
10
  from adam.commands.show.show_login import ShowLogin
8
11
  from .show_params import ShowParams
9
- from .show_app_id import ShowAppId
10
12
  from .show_cassandra_status import ShowCassandraStatus
11
13
  from .show_cassandra_version import ShowCassandraVersion
12
- from .show_commands import ShowKubectlCommands
14
+ from .show_cli_commands import ShowKubectlCommands
13
15
  from .show_processes import ShowProcesses
14
- from .show_repairs import ShowRepairs
16
+ from .show_cassandra_repairs import ShowCassandraRepairs
15
17
  from .show_storage import ShowStorage
16
18
  from .show_adam import ShowAdam
17
- from adam.repl_state import ReplState
18
- from adam.utils import lines_to_tabular, log, log2
19
19
 
20
- class Show(Command):
20
+ class Show(IntermediateCommand):
21
21
  COMMAND = 'show'
22
22
 
23
23
  # the singleton pattern
@@ -26,45 +26,14 @@ class Show(Command):
26
26
 
27
27
  return cls.instance
28
28
 
29
- def __init__(self, successor: Command=None):
30
- super().__init__(successor)
31
-
32
29
  def command(self):
33
30
  return Show.COMMAND
34
31
 
35
- def run(self, cmd: str, state: ReplState):
36
- if not(args := self.args(cmd)):
37
- return super().run(cmd, state)
38
-
39
- state, args = self.apply_state(args, state)
40
-
41
- if state.in_repl:
42
- log(lines_to_tabular([c.help(ReplState()) for c in Show.cmd_list()], separator='\t'))
43
-
44
- return 'command-missing'
45
- else:
46
- # head with the Chain of Responsibility pattern
47
- cmds = Command.chain(Show.cmd_list())
48
- if not cmds.run(cmd, state):
49
- log2('* Command is missing.')
50
- Command.display_help()
51
-
52
- def cmd_list():
53
- return [ShowAppActions(), ShowAppId(), ShowAppQueues(), ShowLogin(), ShowKubectlCommands(), ShowParams(), ShowProcesses(), ShowRepairs(),
54
- ShowStorage(), ShowAdam(), ShowCassandraStatus(), ShowCassandraVersion()]
55
-
56
- def completion(self, state: ReplState):
57
- return super().completion(state)
58
-
59
- def help(self, _: ReplState):
60
- return f"{Show.COMMAND}\t show kubectl commands"
32
+ def cmd_list(self):
33
+ return [ShowAppActions(), ShowAppId(), ShowAppQueues(), ShowHost(), ShowLogin(), ShowKubectlCommands(),
34
+ ShowParams(), ShowProcesses(), ShowCassandraRepairs(), ShowStorage(), ShowAdam(),
35
+ ShowCassandraStatus(), ShowCassandraVersion(), MedusaShowRestoreJobs(), MedusaShowBackupJobs()]
61
36
 
62
37
  class ShowCommandHelper(click.Command):
63
38
  def get_help(self, ctx: click.Context):
64
- log(super().get_help(ctx))
65
- log()
66
- log('Catogories:')
67
-
68
- log(lines_to_tabular([c.help(ReplState()).replace(f'{Show.COMMAND} ', ' ', 1) for c in Show.cmd_list()], separator=':'))
69
- log()
70
- ClusterCommandHelper.cluster_help()
39
+ IntermediateCommand.intermediate_help(super().get_help(ctx), Show.COMMAND, Show().cmd_list(), show_cluster_help=True)
@@ -1,7 +1,7 @@
1
1
  import sys
2
2
  import os
3
3
 
4
- from adam.utils import lines_to_tabular, log2
4
+ from adam.utils import tabulize, log2
5
5
 
6
6
  current_dir = os.path.dirname(os.path.abspath(__file__))
7
7
 
@@ -34,10 +34,10 @@ class ShowAdam(Command):
34
34
 
35
35
  package = os.path.dirname(os.path.abspath(__file__))
36
36
  package = package.split('/adam/')[0] + '/adam'
37
- log2(lines_to_tabular([
37
+ tabulize([
38
38
  f'version\t{__version__}',
39
39
  f'source\t{package}'
40
- ], separator='\t'))
40
+ ], separator='\t', to=2)
41
41
 
42
42
  return state
43
43
 
@@ -0,0 +1,37 @@
1
+ from adam.commands import extract_trailing_options
2
+ from adam.commands.command import Command
3
+ from adam.commands.cql.utils_cql import cassandra
4
+ from adam.repl_state import ReplState, RequiredState
5
+
6
+ class ShowCassandraRepairs(Command):
7
+ COMMAND = 'show cassandra repairs'
8
+
9
+ # the singleton pattern
10
+ def __new__(cls, *args, **kwargs):
11
+ if not hasattr(cls, 'instance'): cls.instance = super(ShowCassandraRepairs, cls).__new__(cls)
12
+
13
+ return cls.instance
14
+
15
+ def __init__(self, successor: Command=None):
16
+ super().__init__(successor)
17
+
18
+ def command(self):
19
+ return ShowCassandraRepairs.COMMAND
20
+
21
+ def required(self):
22
+ return RequiredState.CLUSTER_OR_POD
23
+
24
+ def run(self, cmd: str, state: ReplState):
25
+ if not(args := self.args(cmd)):
26
+ return super().run(cmd, state)
27
+
28
+ with self.validate(args, state) as (args, state):
29
+ with extract_trailing_options(args, '&') as (args, backgrounded):
30
+ with cassandra(state) as pods:
31
+ return pods.nodetool('repair_admin list', backgrounded=backgrounded)
32
+
33
+ def completion(self, state: ReplState):
34
+ return super().completion(state, {'&': None})
35
+
36
+ def help(self, _: ReplState):
37
+ return f'{ShowCassandraRepairs.COMMAND}\t show Cassandra repairs'
@@ -1,3 +1,4 @@
1
+ from datetime import datetime
1
2
  import sys
2
3
 
3
4
  from adam.checks.check_result import CheckResult
@@ -5,14 +6,15 @@ from adam.checks.check_utils import run_checks
5
6
  from adam.checks.compactionstats import CompactionStats
6
7
  from adam.checks.gossip import Gossip
7
8
  from adam.columns.columns import Columns
9
+ from adam.commands import extract_options, extract_trailing_options
8
10
  from adam.commands.command import Command
9
- from adam.commands.issues import Issues
11
+ from adam.commands.cql.utils_cql import cassandra
10
12
  from adam.config import Config
11
- from adam.k8s_utils.cassandra_nodes import CassandraNodes
12
- from adam.k8s_utils.secrets import Secrets
13
- from adam.k8s_utils.statefulsets import StatefulSets
13
+ from adam.repl_session import ReplSession
14
+ from adam.utils_issues import IssuesUtils
15
+ from adam.utils_k8s.statefulsets import StatefulSets
14
16
  from adam.repl_state import ReplState, RequiredState
15
- from adam.utils import lines_to_tabular, log, log2
17
+ from adam.utils import SORT, tabulize, log2, log_exc
16
18
  from adam.checks.status import parse_nodetool_status
17
19
 
18
20
  class ShowCassandraStatus(Command):
@@ -37,51 +39,44 @@ class ShowCassandraStatus(Command):
37
39
  if not(args := self.args(cmd)):
38
40
  return super().run(cmd, state)
39
41
 
40
- state, args = self.apply_state(args, state)
41
- if not self.validate_state(state):
42
- return state
42
+ with self.validate(args, state) as (args, state):
43
+ with extract_trailing_options(args, '&') as (args, backgrounded):
44
+ with extract_options(args, ['-s', '--show']) as (args, show_out):
45
+ if state.namespace and state.pod:
46
+ self.show_single_pod(state, show_out=show_out, backgrounded=backgrounded)
47
+ elif state.namespace and state.sts:
48
+ self.merge(state, Config().get('nodetool.samples', sys.maxsize), show_output=show_out, backgrounded=backgrounded)
43
49
 
44
- args, show_output = Command.extract_options(args, ['-s', '--show'])
50
+ return state
45
51
 
46
- if state.namespace and state.pod:
47
- # self.show_table(state, [state.pod], state.namespace, show_output=show_output)
48
- self.show_single_pod(state.sts, state.pod, state.namespace, show_output=show_output)
49
- elif state.namespace and state.sts:
50
- self.merge(state.sts, StatefulSets.pod_names(state.sts, state.namespace), state.namespace, Config().get('nodetool.samples', sys.maxsize), show_output=show_output)
51
-
52
- return state
53
-
54
- def show_single_pod(self, statefulset: str, pod_name: str, ns: str, show_output = False):
55
- pod_name = pod_name.split('(')[0]
56
- user, pw = Secrets.get_user_pass(pod_name, ns)
57
- try:
58
- result = CassandraNodes.exec(pod_name, ns, f"nodetool -u {user} -pw {pw} status", show_out=False)
59
- status = parse_nodetool_status(result.stdout)
60
- check_results = run_checks(cluster=statefulset, namespace=ns, checks=[CompactionStats(), Gossip()], show_output=show_output)
61
- self.show_table(status, check_results)
62
- except Exception as e:
63
- log2(e)
52
+ def show_single_pod(self, state: ReplState, show_out = False, backgrounded = False):
53
+ with log_exc(True):
54
+ with cassandra(state) as pods:
55
+ result = pods.nodetool('status', show_out=False)
56
+ status = parse_nodetool_status(result.stdout)
57
+ check_results = run_checks(cluster=state.sts, namespace=state.namespace, checks=[CompactionStats(), Gossip()], show_out=show_out)
58
+ self.show_table(status, check_results, backgrounded=backgrounded)
64
59
 
65
- def merge(self, statefulset: str, pod_names: list[str], ns: str, samples: int, show_output=False):
60
+ def merge(self, state: ReplState, samples: int, show_output=False, backgrounded = False):
66
61
  statuses: list[list[dict]] = []
62
+
63
+ pod_names = StatefulSets.pod_names(state.sts, state.namespace)
67
64
  for pod_name in pod_names:
68
65
  pod_name = pod_name.split('(')[0]
69
- user, pw = Secrets.get_user_pass(pod_name, ns)
70
66
 
71
- try:
72
- result = CassandraNodes.exec(pod_name, ns, f"nodetool -u {user} -pw {pw} status", show_out=False)
73
- status = parse_nodetool_status(result.stdout)
74
- if status:
75
- statuses.append(status)
76
- if samples <= len(statuses) and len(pod_names) != len(statuses):
77
- break
78
- except Exception as e:
79
- log2(e)
67
+ with log_exc(True):
68
+ with cassandra(state, pod=pod_name) as pods:
69
+ result = pods.nodetool('status', show_out=False)
70
+ status = parse_nodetool_status(result.stdout)
71
+ if status:
72
+ statuses.append(status)
73
+ if samples <= len(statuses) and len(pod_names) != len(statuses):
74
+ break
80
75
 
81
76
  combined_status = self.merge_status(statuses)
82
77
  log2(f'Showing merged status from {len(statuses)}/{len(pod_names)} nodes...')
83
- check_results = run_checks(cluster=statefulset, namespace=ns, checks=[CompactionStats(), Gossip()], show_output=show_output)
84
- self.show_table(combined_status, check_results)
78
+ check_results = run_checks(cluster=state.sts, namespace=state.namespace, checks=[CompactionStats(), Gossip()], show_out=show_output)
79
+ self.show_table(combined_status, check_results, backgrounded=backgrounded)
85
80
 
86
81
  return combined_status
87
82
 
@@ -102,27 +97,28 @@ class ShowCassandraStatus(Command):
102
97
 
103
98
  return combined
104
99
 
105
- def show_table(self, status: list[dict[str, any]], check_results: list[CheckResult]):
100
+ def show_table(self, status: list[dict[str, any]], check_results: list[CheckResult], backgrounded=False):
106
101
  cols = Config().get('status.columns', 'status,address,load,tokens,owns,host_id,gossip,compactions')
107
102
  header = Config().get('status.header', '--,Address,Load,Tokens,Owns,Host ID,GOSSIP,COMPACTIONS')
108
103
  columns = Columns.create_columns(cols)
109
104
 
110
- def line(status: dict):
111
- cells = [c.host_value(check_results, status) for c in columns]
112
- return ','.join(cells)
105
+ r = tabulize(status, lambda s: ','.join([c.host_value(check_results, s) for c in columns]), header=header, separator=',', sorted=SORT, to = 0 if backgrounded else 1)
113
106
 
114
- lines = [line(d) for d in status]
115
- lines.sort()
107
+ if backgrounded:
108
+ log_prefix = Config().get('log-prefix', '/tmp/qing')
109
+ log_file = f'{log_prefix}-{datetime.now().strftime("%d%H%M%S")}.log'
116
110
 
117
- log(lines_to_tabular(lines, header, separator=','))
111
+ with open(log_file, 'w') as f:
112
+ f.write(r)
118
113
 
119
- Issues.show(check_results)
114
+ ReplSession().append_history(f':sh cat {log_file}')
120
115
 
121
- def completion(self, state: ReplState):
122
- if state.sts:
123
- return super().completion(state)
116
+ r = log_file
124
117
 
125
- return {}
118
+ IssuesUtils.show(check_results)
119
+
120
+ def completion(self, state: ReplState):
121
+ return super().completion(state, {'-s': {'&': None}, '&': None})
126
122
 
127
123
  def help(self, _: ReplState):
128
124
  return f'{ShowCassandraStatus.COMMAND} [-s]\t show merged nodetool status -s show commands on nodes'
@@ -1,7 +1,5 @@
1
1
  from adam.commands.command import Command
2
- from adam.k8s_utils.cassandra_clusters import CassandraClusters
3
- from adam.k8s_utils.cassandra_nodes import CassandraNodes
4
- from adam.k8s_utils.secrets import Secrets
2
+ from adam.commands.cql.utils_cql import cassandra
5
3
  from adam.repl_state import ReplState, RequiredState
6
4
 
7
5
  class ShowCassandraVersion(Command):
@@ -26,23 +24,12 @@ class ShowCassandraVersion(Command):
26
24
  if not(args := self.args(cmd)):
27
25
  return super().run(cmd, state)
28
26
 
29
- state, _ = state.apply_args(args)
30
- if not self.validate_state(state):
31
- return state
32
-
33
- user, pw = Secrets.get_user_pass(state.sts if state.sts else state.pod, state.namespace, secret_path='cql.secret')
34
- command = f'cqlsh -u {user} -p {pw} -e "show version"'
35
-
36
- if state.pod:
37
- return CassandraNodes.exec(state.pod, state.namespace, command)
38
- else:
39
- return CassandraClusters.exec(state.sts, state.namespace, command, action='cql')
27
+ with self.validate(args, state) as (_, state):
28
+ with cassandra(state) as pods:
29
+ return pods.cql('show version', show_out=True, on_any=True)
40
30
 
41
31
  def completion(self, state: ReplState):
42
- if state.sts:
43
- return super().completion(state)
44
-
45
- return {}
32
+ return super().completion(state)
46
33
 
47
34
  def help(self, _: ReplState):
48
35
  return f'{ShowCassandraVersion.COMMAND}\t show Cassandra version'
@@ -0,0 +1,56 @@
1
+ from adam.commands.command import Command
2
+ from adam.commands.cli_commands import CliCommands
3
+ from adam.repl_state import ReplState, RequiredState
4
+ from adam.utils import tabulize, log
5
+
6
+ class ShowKubectlCommands(Command):
7
+ COMMAND = 'show cli-commands'
8
+
9
+ # the singleton pattern
10
+ def __new__(cls, *args, **kwargs):
11
+ if not hasattr(cls, 'instance'): cls.instance = super(ShowKubectlCommands, cls).__new__(cls)
12
+
13
+ return cls.instance
14
+
15
+ def __init__(self, successor: Command=None):
16
+ super().__init__(successor)
17
+
18
+ def command(self):
19
+ return ShowKubectlCommands.COMMAND
20
+
21
+ def required(self):
22
+ return RequiredState.CLUSTER_OR_POD
23
+
24
+ def run(self, cmd: str, state: ReplState):
25
+ if not (args := self.args(cmd)):
26
+ return super().run(cmd, state)
27
+
28
+ with self.validate(args, state) as (args, state):
29
+ v = CliCommands.values(state, collapse=True)
30
+ # node-exec-?, nodetool-?, cql-?, reaper-exec, reaper-forward, reaper-ui, reaper-username, reaper-password
31
+ cmds = [
32
+ f'bash,{v["node-exec-?"]}',
33
+ f'nodetool,{v["nodetool-?"]}',
34
+ f'cql,{v["cql-?"]}',
35
+ ]
36
+
37
+ if 'reaper-exec' in v:
38
+ cmds += [
39
+ f'reaper,{v["reaper-exec"]}',
40
+ f',{v["reaper-forward"]} * should be run from your laptop',
41
+ f',{v["reaper-ui"]}',
42
+ f',{v["reaper-username"]}',
43
+ f',{v["reaper-password"]}',
44
+ ]
45
+
46
+ cmds += [f'{k},{v0}' for k, v0 in v.items() if k.startswith('pg-')]
47
+
48
+ tabulize(cmds, separator=',')
49
+
50
+ return cmds
51
+
52
+ def completion(self, state: ReplState):
53
+ return super().completion(state)
54
+
55
+ def help(self, _: ReplState):
56
+ return f"{ShowKubectlCommands.COMMAND}\t show kubectl commands"
@@ -0,0 +1,33 @@
1
+ from adam.commands.command import Command
2
+ from adam.repl_state import ReplState
3
+ from adam.utils import log
4
+ from adam.utils_net import get_my_host
5
+
6
+ class ShowHost(Command):
7
+ COMMAND = 'show host'
8
+
9
+ # the singleton pattern
10
+ def __new__(cls, *args, **kwargs):
11
+ if not hasattr(cls, 'instance'): cls.instance = super(ShowHost, cls).__new__(cls)
12
+
13
+ return cls.instance
14
+
15
+ def __init__(self, successor: Command=None):
16
+ super().__init__(successor)
17
+
18
+ def command(self):
19
+ return ShowHost.COMMAND
20
+
21
+ def run(self, cmd: str, state: ReplState):
22
+ if not self.args(cmd):
23
+ return super().run(cmd, state)
24
+
25
+ log(get_my_host())
26
+
27
+ return state
28
+
29
+ def completion(self, state: ReplState):
30
+ return super().completion(state)
31
+
32
+ def help(self, _: ReplState):
33
+ return f'{ShowHost.COMMAND}\t show host'
@@ -1,13 +1,11 @@
1
1
  import time
2
- import traceback
3
2
 
4
3
  from adam.apps import Apps
5
- from adam.config import Config
6
4
  from adam.sso.idp import Idp
7
5
  from adam.sso.idp_login import IdpLogin
8
6
  from adam.commands.command import Command
9
7
  from adam.repl_state import ReplState
10
- from adam.utils import duration, lines_to_tabular, log, log2
8
+ from adam.utils import duration, tabulize, log, log2, log_exc
11
9
 
12
10
  class ShowLogin(Command):
13
11
  COMMAND = 'show login'
@@ -24,34 +22,32 @@ class ShowLogin(Command):
24
22
  def command(self):
25
23
  return ShowLogin.COMMAND
26
24
 
25
+ def required(self):
26
+ return ReplState.NON_L
27
+
27
28
  def run(self, cmd: str, state: ReplState):
28
29
  if not(args := self.args(cmd)):
29
30
  return super().run(cmd, state)
30
31
 
31
- state, args = self.apply_state(args, state)
32
-
33
- login: IdpLogin = None
34
- try:
35
- if not(host := Apps.app_host('c3', 'c3', state.namespace)):
36
- log2('Cannot locate ingress for app.')
37
- return state
38
-
39
- login = Idp.login(host, use_token_from_env=True)
40
- if login and login.id_token_obj:
41
- it = login.id_token_obj
42
- lines = [
43
- f'email\t{it.email}',
44
- f'user\t{it.username}',
45
- f'IDP expires in\t{duration(time.time(), it.exp)}',
46
- f'IDP Groups\t{",".join(it.groups)}'
47
- ]
48
- log(lines_to_tabular(lines, separator='\t'))
49
- except Exception as e:
50
- log2(e)
51
- if Config().is_debug():
52
- log2(traceback.format_exc())
53
-
54
- return state
32
+ with self.validate(args, state) as (args, state):
33
+ login: IdpLogin = None
34
+ with log_exc(True):
35
+ if not(host := Apps.app_host('c3', 'c3', state.namespace)):
36
+ log2('Cannot locate ingress for app.')
37
+ return state
38
+
39
+ login = Idp.login(host, use_token_from_env=True)
40
+ if login and login.id_token_obj:
41
+ it = login.id_token_obj
42
+ lines = [
43
+ f'email\t{it.email}',
44
+ f'user\t{it.username}',
45
+ f'IDP expires in\t{duration(time.time(), it.exp)}',
46
+ f'IDP Groups\t{",".join(it.groups)}'
47
+ ]
48
+ tabulize(lines, separator='\t')
49
+
50
+ return state
55
51
 
56
52
  def completion(self, state: ReplState):
57
53
  return super().completion(state)
@@ -1,7 +1,7 @@
1
1
  from adam.commands.command import Command
2
2
  from adam.config import Config
3
3
  from adam.repl_state import ReplState
4
- from adam.utils import lines_to_tabular, log
4
+ from adam.utils import tabulize
5
5
 
6
6
  class ShowParams(Command):
7
7
  COMMAND = 'show params'
@@ -22,10 +22,7 @@ class ShowParams(Command):
22
22
  if not self.args(cmd):
23
23
  return super().run(cmd, state)
24
24
 
25
- lines = [f'{key}\t{Config().get(key, None)}' for key in Config().keys()]
26
- log(lines_to_tabular(lines, separator='\t'))
27
-
28
- return lines
25
+ return tabulize(Config().keys(), lambda k: f'{k}\t{Config().get(k, None)}', separator='\t')
29
26
 
30
27
  def completion(self, state: ReplState):
31
28
  return super().completion(state)