kaqing 2.0.115__py3-none-any.whl → 2.0.172__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of kaqing might be problematic. Click here for more details.

Files changed (187) hide show
  1. adam/__init__.py +0 -2
  2. adam/app_session.py +8 -11
  3. adam/batch.py +3 -3
  4. adam/checks/check_utils.py +14 -46
  5. adam/checks/cpu.py +7 -1
  6. adam/checks/cpu_metrics.py +52 -0
  7. adam/checks/disk.py +2 -3
  8. adam/columns/columns.py +3 -1
  9. adam/columns/cpu.py +3 -1
  10. adam/columns/cpu_metrics.py +22 -0
  11. adam/columns/memory.py +3 -4
  12. adam/commands/__init__.py +18 -0
  13. adam/commands/alter_tables.py +43 -47
  14. adam/commands/audit/audit.py +24 -25
  15. adam/commands/audit/audit_repair_tables.py +14 -17
  16. adam/commands/audit/audit_run.py +15 -23
  17. adam/commands/audit/show_last10.py +10 -13
  18. adam/commands/audit/show_slow10.py +10 -13
  19. adam/commands/audit/show_top10.py +10 -14
  20. adam/commands/audit/utils_show_top10.py +2 -3
  21. adam/commands/bash/__init__.py +5 -0
  22. adam/commands/bash/bash.py +8 -96
  23. adam/commands/bash/utils_bash.py +16 -0
  24. adam/commands/cat.py +14 -19
  25. adam/commands/cd.py +12 -100
  26. adam/commands/check.py +20 -21
  27. adam/commands/cli_commands.py +2 -3
  28. adam/commands/code.py +20 -23
  29. adam/commands/command.py +123 -39
  30. adam/commands/commands_utils.py +8 -17
  31. adam/commands/cp.py +33 -39
  32. adam/commands/cql/cql_completions.py +28 -10
  33. adam/commands/cql/cqlsh.py +10 -30
  34. adam/commands/cql/utils_cql.py +343 -0
  35. adam/commands/deploy/code_start.py +7 -10
  36. adam/commands/deploy/code_stop.py +4 -21
  37. adam/commands/deploy/code_utils.py +3 -3
  38. adam/commands/deploy/deploy.py +4 -27
  39. adam/commands/deploy/deploy_frontend.py +14 -17
  40. adam/commands/deploy/deploy_pg_agent.py +2 -5
  41. adam/commands/deploy/deploy_pod.py +65 -73
  42. adam/commands/deploy/deploy_utils.py +14 -24
  43. adam/commands/deploy/undeploy.py +4 -27
  44. adam/commands/deploy/undeploy_frontend.py +4 -7
  45. adam/commands/deploy/undeploy_pg_agent.py +5 -7
  46. adam/commands/deploy/undeploy_pod.py +11 -12
  47. adam/commands/devices/__init__.py +0 -0
  48. adam/commands/devices/device.py +118 -0
  49. adam/commands/devices/device_app.py +173 -0
  50. adam/commands/devices/device_auit_log.py +49 -0
  51. adam/commands/devices/device_cass.py +185 -0
  52. adam/commands/devices/device_export.py +86 -0
  53. adam/commands/devices/device_postgres.py +144 -0
  54. adam/commands/devices/devices.py +25 -0
  55. adam/commands/exit.py +1 -4
  56. adam/commands/export/clean_up_all_export_sessions.py +37 -0
  57. adam/commands/export/clean_up_export_sessions.py +51 -0
  58. adam/commands/export/drop_export_database.py +55 -0
  59. adam/commands/export/drop_export_databases.py +43 -0
  60. adam/commands/export/export.py +19 -26
  61. adam/commands/export/export_databases.py +174 -0
  62. adam/commands/export/export_handlers.py +71 -0
  63. adam/commands/export/export_select.py +48 -22
  64. adam/commands/export/export_select_x.py +54 -0
  65. adam/commands/export/export_use.py +19 -23
  66. adam/commands/export/exporter.py +353 -0
  67. adam/commands/export/import_session.py +40 -0
  68. adam/commands/export/importer.py +67 -0
  69. adam/commands/export/importer_athena.py +77 -0
  70. adam/commands/export/importer_sqlite.py +39 -0
  71. adam/commands/export/show_column_counts.py +54 -0
  72. adam/commands/export/show_export_databases.py +36 -0
  73. adam/commands/export/show_export_session.py +48 -0
  74. adam/commands/export/show_export_sessions.py +44 -0
  75. adam/commands/export/utils_export.py +223 -162
  76. adam/commands/help.py +1 -1
  77. adam/commands/intermediate_command.py +49 -0
  78. adam/commands/issues.py +11 -43
  79. adam/commands/kubectl.py +3 -6
  80. adam/commands/login.py +22 -24
  81. adam/commands/logs.py +3 -6
  82. adam/commands/ls.py +11 -128
  83. adam/commands/medusa/medusa.py +4 -22
  84. adam/commands/medusa/medusa_backup.py +20 -24
  85. adam/commands/medusa/medusa_restore.py +29 -33
  86. adam/commands/medusa/medusa_show_backupjobs.py +14 -18
  87. adam/commands/medusa/medusa_show_restorejobs.py +11 -18
  88. adam/commands/nodetool.py +6 -15
  89. adam/commands/param_get.py +11 -12
  90. adam/commands/param_set.py +9 -10
  91. adam/commands/postgres/postgres.py +41 -34
  92. adam/commands/postgres/postgres_context.py +57 -24
  93. adam/commands/postgres/postgres_ls.py +4 -8
  94. adam/commands/postgres/postgres_preview.py +5 -9
  95. adam/commands/postgres/psql_completions.py +1 -1
  96. adam/commands/postgres/utils_postgres.py +66 -0
  97. adam/commands/preview_table.py +5 -44
  98. adam/commands/pwd.py +14 -47
  99. adam/commands/reaper/reaper.py +4 -27
  100. adam/commands/reaper/reaper_forward.py +48 -55
  101. adam/commands/reaper/reaper_forward_session.py +6 -0
  102. adam/commands/reaper/reaper_forward_stop.py +10 -16
  103. adam/commands/reaper/reaper_restart.py +7 -14
  104. adam/commands/reaper/reaper_run_abort.py +11 -30
  105. adam/commands/reaper/reaper_runs.py +42 -57
  106. adam/commands/reaper/reaper_runs_abort.py +29 -49
  107. adam/commands/reaper/reaper_schedule_activate.py +11 -30
  108. adam/commands/reaper/reaper_schedule_start.py +10 -29
  109. adam/commands/reaper/reaper_schedule_stop.py +10 -29
  110. adam/commands/reaper/reaper_schedules.py +4 -14
  111. adam/commands/reaper/reaper_status.py +8 -16
  112. adam/commands/reaper/utils_reaper.py +196 -0
  113. adam/commands/repair/repair.py +4 -22
  114. adam/commands/repair/repair_log.py +5 -11
  115. adam/commands/repair/repair_run.py +27 -34
  116. adam/commands/repair/repair_scan.py +32 -38
  117. adam/commands/repair/repair_stop.py +5 -11
  118. adam/commands/report.py +27 -29
  119. adam/commands/restart.py +25 -26
  120. adam/commands/rollout.py +19 -24
  121. adam/commands/shell.py +10 -4
  122. adam/commands/show/show.py +10 -25
  123. adam/commands/show/show_cassandra_repairs.py +35 -0
  124. adam/commands/show/show_cassandra_status.py +32 -43
  125. adam/commands/show/show_cassandra_version.py +5 -18
  126. adam/commands/show/show_commands.py +19 -24
  127. adam/commands/show/show_host.py +1 -1
  128. adam/commands/show/show_login.py +20 -27
  129. adam/commands/show/show_processes.py +15 -19
  130. adam/commands/show/show_storage.py +10 -20
  131. adam/commands/watch.py +26 -29
  132. adam/config.py +5 -14
  133. adam/embedded_params.py +1 -1
  134. adam/log.py +4 -4
  135. adam/pod_exec_result.py +3 -3
  136. adam/repl.py +40 -103
  137. adam/repl_commands.py +32 -16
  138. adam/repl_state.py +57 -28
  139. adam/sql/sql_completer.py +44 -28
  140. adam/sql/sql_state_machine.py +89 -28
  141. adam/sso/authn_ad.py +6 -8
  142. adam/sso/authn_okta.py +4 -6
  143. adam/sso/cred_cache.py +3 -5
  144. adam/sso/idp.py +9 -12
  145. adam/utils.py +435 -6
  146. adam/utils_athena.py +57 -37
  147. adam/utils_audits.py +12 -14
  148. adam/utils_issues.py +32 -0
  149. adam/utils_k8s/app_clusters.py +13 -18
  150. adam/utils_k8s/app_pods.py +2 -0
  151. adam/utils_k8s/cassandra_clusters.py +22 -19
  152. adam/utils_k8s/cassandra_nodes.py +2 -2
  153. adam/utils_k8s/custom_resources.py +16 -17
  154. adam/utils_k8s/ingresses.py +2 -2
  155. adam/utils_k8s/jobs.py +7 -11
  156. adam/utils_k8s/k8s.py +87 -0
  157. adam/utils_k8s/pods.py +40 -77
  158. adam/utils_k8s/secrets.py +4 -4
  159. adam/utils_k8s/service_accounts.py +5 -4
  160. adam/utils_k8s/services.py +2 -2
  161. adam/utils_k8s/statefulsets.py +1 -12
  162. adam/utils_net.py +4 -4
  163. adam/utils_repl/__init__.py +0 -0
  164. adam/utils_repl/automata_completer.py +48 -0
  165. adam/utils_repl/repl_completer.py +46 -0
  166. adam/utils_repl/state_machine.py +173 -0
  167. adam/utils_sqlite.py +137 -0
  168. adam/version.py +1 -1
  169. {kaqing-2.0.115.dist-info → kaqing-2.0.172.dist-info}/METADATA +1 -1
  170. kaqing-2.0.172.dist-info/RECORD +230 -0
  171. adam/commands/app.py +0 -67
  172. adam/commands/app_ping.py +0 -44
  173. adam/commands/cql/cql_utils.py +0 -204
  174. adam/commands/devices.py +0 -147
  175. adam/commands/export/export_on_x.py +0 -76
  176. adam/commands/export/export_rmdbs.py +0 -65
  177. adam/commands/postgres/postgres_utils.py +0 -31
  178. adam/commands/reaper/reaper_session.py +0 -159
  179. adam/commands/show/show_app_actions.py +0 -56
  180. adam/commands/show/show_app_id.py +0 -47
  181. adam/commands/show/show_app_queues.py +0 -45
  182. adam/commands/show/show_repairs.py +0 -47
  183. adam/utils_export.py +0 -42
  184. kaqing-2.0.115.dist-info/RECORD +0 -203
  185. {kaqing-2.0.115.dist-info → kaqing-2.0.172.dist-info}/WHEEL +0 -0
  186. {kaqing-2.0.115.dist-info → kaqing-2.0.172.dist-info}/entry_points.txt +0 -0
  187. {kaqing-2.0.115.dist-info → kaqing-2.0.172.dist-info}/top_level.txt +0 -0
@@ -1,5 +1,3 @@
1
- import concurrent
2
-
3
1
  from adam.commands.command import Command
4
2
  from adam.config import Config
5
3
  from adam.repl_state import ReplState
@@ -30,29 +28,23 @@ class AuditRun(Command):
30
28
  if not(args := self.args(cmd)):
31
29
  return super().run(cmd, state)
32
30
 
33
- state, args = self.apply_state(args, state)
34
- if not self.validate_state(state):
35
- return state
36
-
37
- meta: AuditMeta = Audits.get_meta()
38
- clusters = Audits.find_new_clusters(meta.cluster_last_checked)
39
- Audits.put_meta(Audits.ADD_CLUSTERS, meta, clusters=clusters)
40
- if clusters:
41
- log2(f'Added {len(clusters)} new clusters.')
42
- tables = Config().get('audit.athena.repair-cluster-tables', 'cluster').split(',')
43
- with concurrent.futures.ThreadPoolExecutor(max_workers=Config().get('audit.workers', 3)) as executor:
44
- for table in tables:
45
- executor.submit(Athena.run_query, f'MSCK REPAIR TABLE {table}', None,)
46
- else:
47
- log2(f'No new clusters were found.')
31
+ with self.validate(args, state) as (args, state):
32
+ meta: AuditMeta = Audits.get_meta()
33
+ clusters = Audits.find_new_clusters(meta.cluster_last_checked)
34
+ Audits.put_meta(Audits.ADD_CLUSTERS, meta, clusters=clusters)
35
+ if clusters:
36
+ log2(f'Added {len(clusters)} new clusters.')
37
+ tables = Config().get('audit.athena.repair-cluster-tables', 'cluster').split(',')
38
+ with Audits.offload() as exec:
39
+ for table in tables:
40
+ exec.submit(Athena.query, f'MSCK REPAIR TABLE {table}', None,)
41
+ else:
42
+ log2(f'No new clusters were found.')
48
43
 
49
- return state
44
+ return state
50
45
 
51
46
  def completion(self, state: ReplState):
52
- if state.device == ReplState.L:
53
- return super().completion(state)
54
-
55
- return {}
47
+ return super().completion(state)
56
48
 
57
49
  def help(self, _: ReplState):
58
- return f"{AuditRun.COMMAND} \t run"
50
+ return f"{AuditRun.COMMAND}\t run"
@@ -27,21 +27,18 @@ class ShowLast10(Command):
27
27
  if not(args := self.args(cmd)):
28
28
  return super().run(cmd, state)
29
29
 
30
- state, args = self.apply_state(args, state)
31
- if not self.validate_state(state):
32
- return state
33
-
34
- limit, date_condition = extract_limit_and_duration(args)
30
+ with self.validate(args, state) as (args, state):
31
+ limit, date_condition = extract_limit_and_duration(args)
35
32
 
36
- query = '\n '.join([
37
- "SELECT * FROM audit",
38
- f"WHERE drive <> 'z' and ({date_condition})",
39
- f"ORDER BY ts DESC LIMIT {limit};"])
40
- log2(query)
41
- log2()
42
- Athena.run_query(query)
33
+ query = '\n '.join([
34
+ "SELECT * FROM audit",
35
+ f"WHERE drive <> 'z' and ({date_condition})",
36
+ f"ORDER BY ts DESC LIMIT {limit};"])
37
+ log2(query)
38
+ log2()
39
+ Athena.run_query(query)
43
40
 
44
- return state
41
+ return state
45
42
 
46
43
  def completion(self, _: ReplState):
47
44
 
@@ -27,21 +27,18 @@ class ShowSlow10(Command):
27
27
  if not(args := self.args(cmd)):
28
28
  return super().run(cmd, state)
29
29
 
30
- state, args = self.apply_state(args, state)
31
- if not self.validate_state(state):
32
- return state
33
-
34
- limit, date_condition = extract_limit_and_duration(args)
30
+ with self.validate(args, state) as (args, state):
31
+ limit, date_condition = extract_limit_and_duration(args)
35
32
 
36
- query = '\n '.join([
37
- "SELECT * FROM audit",
38
- f"WHERE drive <> 'z' and ({date_condition})",
39
- f"ORDER BY CAST(duration AS REAL) DESC LIMIT {limit};"])
40
- log2(query)
41
- log2()
42
- Athena.run_query(query)
33
+ query = '\n '.join([
34
+ "SELECT * FROM audit",
35
+ f"WHERE drive <> 'z' and ({date_condition})",
36
+ f"ORDER BY CAST(duration AS REAL) DESC LIMIT {limit};"])
37
+ log2(query)
38
+ log2()
39
+ Athena.run_query(query)
43
40
 
44
- return state
41
+ return state
45
42
 
46
43
  def completion(self, _: ReplState):
47
44
  return {}
@@ -3,7 +3,6 @@ from adam.commands.command import Command
3
3
  from adam.repl_state import ReplState
4
4
  from adam.utils import log2
5
5
  from adam.utils_athena import Athena
6
- from adam.utils_audits import Audits
7
6
 
8
7
  class ShowTop10(Command):
9
8
  COMMAND = 'show top'
@@ -27,20 +26,17 @@ class ShowTop10(Command):
27
26
  if not(args := self.args(cmd)):
28
27
  return super().run(cmd, state)
29
28
 
30
- state, args = self.apply_state(args, state)
31
- if not self.validate_state(state):
32
- return state
33
-
34
- limit, date_condition = extract_limit_and_duration(args)
35
- query = '\n '.join([
36
- "SELECT min(c) AS cluster, line, COUNT(*) AS cnt, avg(CAST(duration AS REAL)) AS duration",
37
- f"FROM audit WHERE drive <> 'z' and ({date_condition})",
38
- f"GROUP BY line ORDER BY cnt DESC LIMIT {limit};"])
39
- log2(query)
40
- log2()
41
- Athena.run_query(query)
29
+ with self.validate(args, state) as (args, state):
30
+ limit, date_condition = extract_limit_and_duration(args)
31
+ query = '\n '.join([
32
+ "SELECT min(c) AS cluster, line, COUNT(*) AS cnt, avg(CAST(duration AS REAL)) AS duration",
33
+ f"FROM audit WHERE drive <> 'z' and ({date_condition})",
34
+ f"GROUP BY line ORDER BY cnt DESC LIMIT {limit};"])
35
+ log2(query)
36
+ log2()
37
+ Athena.run_query(query)
42
38
 
43
- return state
39
+ return state
44
40
 
45
41
  def completion(self, _: ReplState):
46
42
  return {}
@@ -1,5 +1,6 @@
1
1
  from datetime import datetime, timedelta
2
2
 
3
+ from adam.utils import log_exc
3
4
  from adam.utils_audits import Audits
4
5
  from adam.utils_repl.automata_completer import AutomataCompleter
5
6
  from adam.utils_repl.state_machine import StateMachine
@@ -8,10 +9,8 @@ def extract_limit_and_duration(args: list[str]) -> tuple[int, datetime]:
8
9
  limit = 10
9
10
  _from = datetime.now() - timedelta(days=30)
10
11
  if args:
11
- try:
12
+ with log_exc():
12
13
  limit = int(args[0])
13
- except:
14
- pass
15
14
 
16
15
  if len(args) > 2 and args[1] == 'over':
17
16
  if args[2] == 'day':
@@ -0,0 +1,5 @@
1
+ from adam.commands.bash.utils_bash import BashHandler
2
+ from adam.repl_state import ReplState
3
+
4
+ def bash(s0: ReplState, s1: ReplState):
5
+ return BashHandler(s0, s1)
@@ -1,15 +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.statefulsets import StatefulSets
12
- from build.lib.adam.utils_k8s.cassandra_nodes import CassandraNodes
3
+ from adam.commands.devices.devices import Devices
4
+ from adam.repl_state import ReplState, RequiredState
13
5
 
14
6
  class Bash(Command):
15
7
  COMMAND = 'bash'
@@ -27,98 +19,18 @@ class Bash(Command):
27
19
  return Bash.COMMAND
28
20
 
29
21
  def required(self):
30
- return [RequiredState.CLUSTER_OR_POD, RequiredState.APP_APP]
22
+ return [RequiredState.CLUSTER_OR_POD, RequiredState.APP_APP, ReplState.P]
31
23
 
32
24
  def run(self, cmd: str, s0: ReplState):
33
25
  if not(args := self.args(cmd)):
34
26
  return super().run(cmd, s0)
35
27
 
36
- state, args = self.apply_state(args, s0, args_to_check=2)
37
- if not self.validate_state(state):
38
- return state
39
-
40
- def _run(state_changed: bool, cli: Callable[[str], None]):
41
- if state.in_repl:
42
- if state_changed:
43
- r = self.exec_with_dir(state, args)
44
- else:
45
- r = self.exec_with_dir(s0, args)
46
-
47
- if not r:
48
- state.exit_bash()
49
-
50
- return 'inconsistent pwd'
51
-
52
- return r
53
- else:
54
- cli(' '.join(args))
55
-
56
- return state
57
-
58
- if state.device == ReplState.A:
59
- def cli(command: str):
60
- if state.app_pod:
61
- AppPods.exec(state.app_pod, state.namespace, command, show_out=True)
62
- elif state.app_app:
63
- AppClusters.exec(AppPods.pod_names(state.namespace, state.app_env, state.app_app), state.namespace, command, action='bash', show_out=True)
64
-
65
- return _run(s0.app_env != state.app_env or s0.app_app != state.app_app or s0.app_pod != state.app_pod, cli)
66
-
67
- def cli(command: str):
68
- if state.pod:
69
- CassandraNodes.exec(state.pod, state.namespace, command, show_out=True)
70
- elif state.sts:
71
- CassandraClusters.exec(state.sts, state.namespace, command, action='bash', show_out=True)
72
-
73
- return _run(s0.sts != state.sts or s0.pod != state.pod, cli)
74
-
75
- def exec_with_dir(self, state: ReplState, args: list[str]) -> list[PodExecResult]:
76
- session_just_created = False
77
- if not args:
78
- session_just_created = True
79
- session = BashSession(state.device)
80
- state.enter_bash(session)
81
-
82
- if state.bash_session:
83
- if args != ['pwd']:
84
- if args:
85
- args.append('&&')
86
- args.extend(['pwd', '>', f'/tmp/.qing-{state.bash_session.session_id}'])
87
-
88
- if not session_just_created:
89
- if pwd := state.bash_session.pwd(state):
90
- args = ['cd', pwd, '&&'] + args
91
-
92
- command = ' '.join(args)
93
-
94
- rs = []
95
-
96
- if state.device == ReplState.A:
97
- if state.app_pod:
98
- rs = [AppPods.exec(state.app_pod, state.namespace, command,
99
- show_out=not session_just_created, shell='bash')]
100
- elif state.app_app:
101
- rs = AppClusters.exec(AppPods.pod_names(state.namespace, state.app_env, state.app_app), state.namespace, command, action='bash',
102
- show_out=not session_just_created, shell='bash')
103
- else:
104
- if state.pod:
105
- rs = [CassandraNodes.exec(state.pod, state.namespace, command,
106
- show_out=not session_just_created, shell='bash')]
107
- elif state.sts:
108
- rs = CassandraClusters.exec(state.sts, state.namespace, command, action='bash',
109
- show_out=not session_just_created, shell='bash')
110
-
111
- return rs
28
+ with self.validate(args, s0) as (args, s1):
29
+ with bash(s0, s1) as exec:
30
+ return exec(args)
112
31
 
113
32
  def completion(self, state: ReplState):
114
- if state.device == ReplState.A and state.app_app:
115
- return { Bash.COMMAND: BashCompleter(lambda: []) } | \
116
- {f'@{p}': {Bash.COMMAND: BashCompleter(lambda: [])} for p in AppPods.pod_names(state.namespace, state.app_env, state.app_app)}
117
- elif state.sts:
118
- return { Bash.COMMAND: BashCompleter(lambda: []) } | \
119
- {f'@{p}': {Bash.COMMAND: BashCompleter(lambda: [])} for p in StatefulSets.pod_names(state.sts, state.namespace)}
120
-
121
- return {}
33
+ return Devices.device(state).bash_completion(Bash.COMMAND, state, default = {})
122
34
 
123
35
  def help(self, _: ReplState):
124
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,5 +1,5 @@
1
- from adam.commands.bash.bash import Bash
2
1
  from adam.commands.command import Command
2
+ from adam.commands.devices.devices import Devices
3
3
  from adam.repl_state import ReplState, RequiredState
4
4
  from adam.utils import log2
5
5
  from adam.utils_k8s.app_pods import AppPods
@@ -21,33 +21,28 @@ class Cat(Command):
21
21
  return Cat.COMMAND
22
22
 
23
23
  def required(self):
24
- return [RequiredState.CLUSTER_OR_POD, RequiredState.APP_APP]
24
+ return [RequiredState.CLUSTER_OR_POD, RequiredState.APP_APP, ReplState.P]
25
25
 
26
26
  def run(self, cmd: str, state: ReplState):
27
27
  if not(args := self.args(cmd)):
28
28
  return super().run(cmd, state)
29
29
 
30
- state, args = self.apply_state(args, state)
30
+ with self.validate(args, state) as (args, state):
31
+ if len(args) < 1:
32
+ if state.in_repl:
33
+ log2('File is required.')
34
+ log2()
35
+ else:
36
+ log2('* File is missing.')
37
+ Command.display_help()
31
38
 
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
+ return 'command-missing'
39
40
 
40
- return 'command-missing'
41
-
42
- return Bash().run('bash ' + cmd, state)
41
+ return Devices.device(state).cat(cmd, state)
43
42
 
44
43
  def completion(self, state: ReplState):
45
- if state.device == ReplState.A and state.app_app:
46
- return super().completion(state) | \
47
- {f'@{p}': {Cat.COMMAND: None} for p in AppPods.pod_names(state.namespace, state.app_env, state.app_app)}
48
- elif state.device == ReplState.C and state.sts:
49
- return super().completion(state) | \
50
- {f'@{p}': {Cat.COMMAND: None} for p in StatefulSets.pod_names(state.sts, state.namespace)}
44
+ if super().completion(state):
45
+ return Devices.device(state).cat_completion(Cat.COMMAND, state, default={})
51
46
 
52
47
  return {}
53
48
 
adam/commands/cd.py CHANGED
@@ -1,13 +1,7 @@
1
1
  from adam.commands.command import Command
2
- from adam.commands.postgres.postgres_utils import pg_database_names
3
- from adam.commands.postgres.postgres_context import PostgresContext
4
- from adam.utils_k8s.app_pods import AppPods
5
- from adam.utils_k8s.cassandra_clusters import CassandraClusters
6
- from adam.utils_k8s.kube_context import KubeContext
7
- from adam.utils_k8s.statefulsets import StatefulSets
2
+ from adam.commands.devices.device import Device
3
+ from adam.commands.devices.devices import Devices
8
4
  from adam.repl_state import ReplState
9
- from adam.utils import log2
10
- from adam.apps import Apps
11
5
 
12
6
  class Cd(Command):
13
7
  COMMAND = 'cd'
@@ -31,101 +25,19 @@ class Cd(Command):
31
25
  if not(args := self.args(cmd)):
32
26
  return super().run(cmd, state)
33
27
 
34
- if not self.validate_state(state):
35
- return state
36
-
37
- if len(args) < 2:
38
- return state
28
+ with self.validate(args, state, apply=False) as (args, state):
29
+ if len(args) < 2:
30
+ return state
39
31
 
40
- arg = args[1]
41
- for dir in arg.split('/'):
42
- if state.device == ReplState.P:
43
- if dir == '':
44
- state.pg_path = None
45
- else:
46
- context: PostgresContext = PostgresContext.apply(state.namespace, state.pg_path, arg=dir)
47
- # patch up state.namespace from pg cd
48
- if not state.namespace and context.namespace:
49
- state.namespace = context.namespace
50
- state.pg_path = context.path()
51
- elif state.device == ReplState.A:
52
- if dir == '':
53
- state.app_env = None
54
- state.app_app = None
55
- state.app_pod = None
56
- elif dir == '..':
57
- if state.app_pod:
58
- state.app_pod = None
59
- elif state.app_app:
60
- state.app_app = None
61
- else:
62
- state.app_env = None
63
- else:
64
- if state.app_app:
65
- state.app_pod = dir
66
- elif not state.app_env:
67
- tks = dir.split('@')
68
- if len(tks) > 1:
69
- state.namespace = tks[1]
32
+ device: Device = Devices.device(state)
33
+ arg = args[1]
34
+ for dir in arg.split('/'):
35
+ device.cd(dir, state)
70
36
 
71
- state.app_env = dir.split('@')[0]
72
- else:
73
- state.app_app = dir
74
- elif state.device == ReplState.L:
75
- pass
76
- else:
77
- if dir == '':
78
- state.sts = None
79
- state.pod = None
80
- elif dir == '..':
81
- if state.pod:
82
- state.pod = None
83
- else:
84
- state.sts = None
85
- else:
86
- if not state.sts:
87
- ss_and_ns = dir.split('@')
88
- state.sts = ss_and_ns[0]
89
- if len(ss_and_ns) > 1:
90
- state.namespace = ss_and_ns[1]
91
- elif not state.pod:
92
- p, _ = KubeContext.is_pod_name(dir)
93
- if p:
94
- state.pod = p
95
- else:
96
- names = CassandraClusters.pod_names_by_host_id(state.sts, state.namespace);
97
- if dir in names:
98
- state.pod = names[dir]
99
- else:
100
- log2('Not a valid pod name or host id.')
101
-
102
- return state
37
+ return state
103
38
 
104
39
  def completion(self, state: ReplState):
105
- if state.device == ReplState.P:
106
- pg: PostgresContext = PostgresContext.apply(state.namespace, state.pg_path) if state.pg_path else None
107
- if pg and pg.db:
108
- return {Cd.COMMAND: {'..': None}}
109
- elif pg and pg.host:
110
- return {Cd.COMMAND: {'..': None} | {p: None for p in pg_database_names(state.namespace, pg.path())}}
111
- else:
112
- return {Cd.COMMAND: {p: None for p in PostgresContext.hosts(state.namespace)}}
113
- elif state.device == ReplState.A:
114
- if state.app_app:
115
- return {Cd.COMMAND: {'..': None} | {pod: None for pod in AppPods.pod_names(state.namespace, state.app_env, state.app_app)}}
116
- elif state.app_env:
117
- return {Cd.COMMAND: {'..': None} | {app[0].split('-')[1]: None for app in Apps.apps(state.app_env)}}
118
- else:
119
- return {Cd.COMMAND: {'..': None} | {env[0]: None for env in Apps.envs()}}
120
- elif state.device == ReplState.C:
121
- if state.pod:
122
- return {Cd.COMMAND: {'..': None}}
123
- elif state.sts:
124
- return {Cd.COMMAND: {'..': None} | {p: None for p in StatefulSets.pod_names(state.sts, state.namespace)}}
125
- else:
126
- return {Cd.COMMAND: {p: None for p in StatefulSets.list_sts_names()}}
127
-
128
- return {}
40
+ return Devices.device(state).cd_completion(Cd.COMMAND, state, default = {})
129
41
 
130
42
  def help(self, _: ReplState):
131
- return f'{Cd.COMMAND} <path> | .. \t move around'
43
+ return f'{Cd.COMMAND} <path> | .. \t move around on the operational device hierarchy'
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
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
10
  from adam.utils import lines_to_tabular, log
11
+ from adam.utils_issues import IssuesUtils
10
12
 
11
13
  class Check(Issues):
12
14
  COMMAND = 'check'
@@ -30,36 +32,33 @@ 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
+ if not args:
38
+ if state.in_repl:
39
+ log(lines_to_tabular([check.help() for check in all_checks()], separator=':'))
40
+ else:
41
+ log('* Check name is missing.')
42
+ Command.display_help()
36
43
 
37
- args, show = Command.extract_options(args, ['-s', '--show'])
44
+ return 'arg missing'
38
45
 
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'
46
+ checks = checks_from_csv(args[0])
47
+ if not checks:
48
+ return 'invalid check name'
46
49
 
47
- checks = checks_from_csv(args[0])
48
- if not checks:
49
- return 'invalid check name'
50
+ results = run_checks(state.sts, state.namespace, state.pod, checks=checks, show_out=show_out)
50
51
 
51
- results = run_checks(state.sts, state.namespace, state.pod, checks=checks, show_output=show)
52
+ issues = CheckResult.collect_issues(results)
53
+ IssuesUtils.show_issues(issues, in_repl=state.in_repl)
52
54
 
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'
55
+ return issues if issues else 'no issues found'
57
56
 
58
57
  def completion(self, _: ReplState):
59
- return {Check.COMMAND: {check.name(): None for check in all_checks()}}
58
+ return {Check.COMMAND: {check.name(): {'-s': None} for check in all_checks()}}
60
59
 
61
60
  def help(self, _: ReplState):
62
- return f'{Check.COMMAND} <check-name>\t run a single check'
61
+ return f'{Check.COMMAND} <check-name> [-s]\t run a single check'
63
62
 
64
63
  class CheckCommandHelper(click.Command):
65
64
  def get_help(self, ctx: click.Context):
@@ -1,7 +1,7 @@
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
6
  from adam.utils_k8s.kube_context import KubeContext
7
7
  from adam.utils_k8s.secrets import Secrets
@@ -66,8 +66,7 @@ class CliCommands:
66
66
  return key.replace(f'{state.namespace}-', '').replace('-k8spg-cs-001', '')
67
67
  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
68
 
69
- if r := ReaperSession.create(state):
70
- reaper = r.reaper_spec(state)
69
+ if reaper := Reapers.reaper_spec(state):
71
70
  d |= {
72
71
  'reaper-exec': reaper["exec"],
73
72
  'reaper-forward': reaper["forward"],
adam/commands/code.py CHANGED
@@ -2,7 +2,7 @@ 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
7
  from adam.utils import lines_to_tabular
8
8
  from adam.utils_k8s.statefulsets import StatefulSets
@@ -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=lines_to_tabular(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)