kaqing 2.0.52__py3-none-any.whl → 2.0.184__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 (223) 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 +15 -19
  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 +37 -63
  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 +98 -0
  25. adam/commands/audit/audit.py +81 -0
  26. adam/commands/audit/audit_repair_tables.py +72 -0
  27. adam/commands/audit/audit_run.py +50 -0
  28. adam/commands/audit/show_last10.py +37 -0
  29. adam/commands/audit/show_slow10.py +36 -0
  30. adam/commands/audit/show_top10.py +36 -0
  31. adam/commands/audit/utils_show_top10.py +71 -0
  32. adam/commands/bash/__init__.py +5 -0
  33. adam/commands/bash/bash.py +36 -0
  34. adam/commands/bash/bash_completer.py +93 -0
  35. adam/commands/bash/utils_bash.py +16 -0
  36. adam/commands/cat.py +36 -0
  37. adam/commands/cd.py +14 -89
  38. adam/commands/check.py +18 -21
  39. adam/commands/cli_commands.py +5 -6
  40. adam/commands/clipboard_copy.py +86 -0
  41. adam/commands/code.py +57 -0
  42. adam/commands/command.py +197 -35
  43. adam/commands/commands_utils.py +15 -31
  44. adam/commands/cql/cql_completions.py +29 -8
  45. adam/commands/cql/cqlsh.py +12 -27
  46. adam/commands/cql/utils_cql.py +297 -0
  47. adam/commands/deploy/code_start.py +7 -10
  48. adam/commands/deploy/code_stop.py +4 -21
  49. adam/commands/deploy/code_utils.py +5 -5
  50. adam/commands/deploy/deploy.py +4 -21
  51. adam/commands/deploy/deploy_frontend.py +14 -17
  52. adam/commands/deploy/deploy_pg_agent.py +3 -6
  53. adam/commands/deploy/deploy_pod.py +71 -79
  54. adam/commands/deploy/deploy_utils.py +16 -26
  55. adam/commands/deploy/undeploy.py +4 -21
  56. adam/commands/deploy/undeploy_frontend.py +4 -7
  57. adam/commands/deploy/undeploy_pg_agent.py +6 -8
  58. adam/commands/deploy/undeploy_pod.py +15 -16
  59. adam/commands/devices/__init__.py +0 -0
  60. adam/commands/devices/device.py +123 -0
  61. adam/commands/devices/device_app.py +163 -0
  62. adam/commands/devices/device_auit_log.py +49 -0
  63. adam/commands/devices/device_cass.py +179 -0
  64. adam/commands/devices/device_export.py +84 -0
  65. adam/commands/devices/device_postgres.py +150 -0
  66. adam/commands/devices/devices.py +25 -0
  67. adam/commands/download_file.py +47 -0
  68. adam/commands/exit.py +1 -4
  69. adam/commands/export/__init__.py +0 -0
  70. adam/commands/export/clean_up_all_export_sessions.py +37 -0
  71. adam/commands/export/clean_up_export_sessions.py +39 -0
  72. adam/commands/export/download_export_session.py +39 -0
  73. adam/commands/export/drop_export_database.py +39 -0
  74. adam/commands/export/drop_export_databases.py +37 -0
  75. adam/commands/export/export.py +53 -0
  76. adam/commands/export/export_databases.py +245 -0
  77. adam/commands/export/export_select.py +59 -0
  78. adam/commands/export/export_select_x.py +54 -0
  79. adam/commands/export/export_sessions.py +209 -0
  80. adam/commands/export/export_use.py +49 -0
  81. adam/commands/export/exporter.py +332 -0
  82. adam/commands/export/import_files.py +44 -0
  83. adam/commands/export/import_session.py +44 -0
  84. adam/commands/export/importer.py +81 -0
  85. adam/commands/export/importer_athena.py +177 -0
  86. adam/commands/export/importer_sqlite.py +67 -0
  87. adam/commands/export/show_column_counts.py +45 -0
  88. adam/commands/export/show_export_databases.py +38 -0
  89. adam/commands/export/show_export_session.py +39 -0
  90. adam/commands/export/show_export_sessions.py +37 -0
  91. adam/commands/export/utils_export.py +343 -0
  92. adam/commands/find_files.py +51 -0
  93. adam/commands/find_processes.py +76 -0
  94. adam/commands/head.py +36 -0
  95. adam/commands/help.py +14 -9
  96. adam/commands/intermediate_command.py +49 -0
  97. adam/commands/issues.py +14 -40
  98. adam/commands/kubectl.py +38 -0
  99. adam/commands/login.py +26 -25
  100. adam/commands/logs.py +5 -7
  101. adam/commands/ls.py +11 -110
  102. adam/commands/medusa/medusa.py +4 -22
  103. adam/commands/medusa/medusa_backup.py +22 -29
  104. adam/commands/medusa/medusa_restore.py +40 -39
  105. adam/commands/medusa/medusa_show_backupjobs.py +19 -20
  106. adam/commands/medusa/medusa_show_restorejobs.py +15 -20
  107. adam/commands/nodetool.py +11 -15
  108. adam/commands/param_get.py +11 -14
  109. adam/commands/param_set.py +8 -12
  110. adam/commands/postgres/postgres.py +45 -46
  111. adam/commands/postgres/postgres_databases.py +269 -0
  112. adam/commands/postgres/postgres_ls.py +4 -8
  113. adam/commands/postgres/postgres_preview.py +5 -9
  114. adam/commands/postgres/psql_completions.py +4 -3
  115. adam/commands/postgres/utils_postgres.py +70 -0
  116. adam/commands/preview_table.py +10 -61
  117. adam/commands/pwd.py +14 -43
  118. adam/commands/reaper/reaper.py +4 -24
  119. adam/commands/reaper/reaper_forward.py +49 -56
  120. adam/commands/reaper/reaper_forward_session.py +6 -0
  121. adam/commands/reaper/reaper_forward_stop.py +10 -16
  122. adam/commands/reaper/reaper_restart.py +8 -15
  123. adam/commands/reaper/reaper_run_abort.py +8 -33
  124. adam/commands/reaper/reaper_runs.py +43 -58
  125. adam/commands/reaper/reaper_runs_abort.py +29 -49
  126. adam/commands/reaper/reaper_schedule_activate.py +9 -32
  127. adam/commands/reaper/reaper_schedule_start.py +9 -32
  128. adam/commands/reaper/reaper_schedule_stop.py +9 -32
  129. adam/commands/reaper/reaper_schedules.py +4 -14
  130. adam/commands/reaper/reaper_status.py +8 -16
  131. adam/commands/reaper/utils_reaper.py +194 -0
  132. adam/commands/repair/repair.py +4 -22
  133. adam/commands/repair/repair_log.py +6 -12
  134. adam/commands/repair/repair_run.py +29 -36
  135. adam/commands/repair/repair_scan.py +33 -39
  136. adam/commands/repair/repair_stop.py +6 -12
  137. adam/commands/report.py +25 -21
  138. adam/commands/restart.py +27 -28
  139. adam/commands/rollout.py +20 -25
  140. adam/commands/shell.py +12 -4
  141. adam/commands/show/show.py +11 -23
  142. adam/commands/show/show_adam.py +3 -3
  143. adam/commands/show/show_cassandra_repairs.py +35 -0
  144. adam/commands/show/show_cassandra_status.py +34 -52
  145. adam/commands/show/show_cassandra_version.py +5 -18
  146. adam/commands/show/show_commands.py +20 -25
  147. adam/commands/show/show_host.py +33 -0
  148. adam/commands/show/show_login.py +23 -27
  149. adam/commands/show/show_params.py +2 -5
  150. adam/commands/show/show_processes.py +16 -20
  151. adam/commands/show/show_storage.py +10 -20
  152. adam/commands/watch.py +27 -30
  153. adam/config.py +7 -15
  154. adam/embedded_params.py +1 -1
  155. adam/log.py +4 -4
  156. adam/pod_exec_result.py +13 -5
  157. adam/repl.py +126 -119
  158. adam/repl_commands.py +63 -29
  159. adam/repl_state.py +320 -71
  160. adam/sql/sql_completer.py +98 -383
  161. adam/sql/sql_state_machine.py +630 -0
  162. adam/sql/term_completer.py +14 -4
  163. adam/sso/authn_ad.py +6 -8
  164. adam/sso/authn_okta.py +4 -6
  165. adam/sso/cred_cache.py +4 -6
  166. adam/sso/idp.py +10 -13
  167. adam/utils.py +511 -10
  168. adam/utils_athena.py +145 -0
  169. adam/utils_audits.py +102 -0
  170. adam/utils_issues.py +32 -0
  171. adam/utils_k8s/__init__.py +0 -0
  172. adam/utils_k8s/app_clusters.py +28 -0
  173. adam/utils_k8s/app_pods.py +36 -0
  174. adam/utils_k8s/cassandra_clusters.py +44 -0
  175. adam/{k8s_utils → utils_k8s}/cassandra_nodes.py +11 -4
  176. adam/{k8s_utils → utils_k8s}/custom_resources.py +16 -17
  177. adam/{k8s_utils → utils_k8s}/deployment.py +2 -2
  178. adam/{k8s_utils → utils_k8s}/ingresses.py +2 -2
  179. adam/{k8s_utils → utils_k8s}/jobs.py +7 -11
  180. adam/utils_k8s/k8s.py +87 -0
  181. adam/{k8s_utils → utils_k8s}/kube_context.py +2 -2
  182. adam/{k8s_utils → utils_k8s}/pods.py +109 -74
  183. adam/{k8s_utils → utils_k8s}/secrets.py +7 -3
  184. adam/{k8s_utils → utils_k8s}/service_accounts.py +5 -4
  185. adam/{k8s_utils → utils_k8s}/services.py +2 -2
  186. adam/{k8s_utils → utils_k8s}/statefulsets.py +3 -14
  187. adam/utils_local.py +4 -0
  188. adam/utils_net.py +24 -0
  189. adam/utils_repl/__init__.py +0 -0
  190. adam/utils_repl/automata_completer.py +48 -0
  191. adam/utils_repl/repl_completer.py +46 -0
  192. adam/utils_repl/state_machine.py +173 -0
  193. adam/utils_sqlite.py +137 -0
  194. adam/version.py +1 -1
  195. {kaqing-2.0.52.dist-info → kaqing-2.0.184.dist-info}/METADATA +1 -1
  196. kaqing-2.0.184.dist-info/RECORD +244 -0
  197. adam/commands/app.py +0 -67
  198. adam/commands/bash.py +0 -87
  199. adam/commands/cp.py +0 -95
  200. adam/commands/cql/cql_table_completer.py +0 -8
  201. adam/commands/cql/cql_utils.py +0 -109
  202. adam/commands/describe/describe.py +0 -46
  203. adam/commands/describe/describe_keyspace.py +0 -60
  204. adam/commands/describe/describe_keyspaces.py +0 -50
  205. adam/commands/describe/describe_table.py +0 -60
  206. adam/commands/describe/describe_tables.py +0 -50
  207. adam/commands/devices.py +0 -89
  208. adam/commands/postgres/postgres_session.py +0 -240
  209. adam/commands/postgres/postgres_utils.py +0 -31
  210. adam/commands/postgres/psql_table_completer.py +0 -11
  211. adam/commands/reaper/reaper_session.py +0 -159
  212. adam/commands/show/show_app_actions.py +0 -53
  213. adam/commands/show/show_repairs.py +0 -47
  214. adam/k8s_utils/cassandra_clusters.py +0 -35
  215. adam/sql/sql_utils.py +0 -5
  216. kaqing-2.0.52.dist-info/RECORD +0 -184
  217. /adam/commands/{describe → app}/__init__.py +0 -0
  218. /adam/{k8s_utils → commands/audit}/__init__.py +0 -0
  219. /adam/{k8s_utils → utils_k8s}/config_maps.py +0 -0
  220. /adam/{k8s_utils → utils_k8s}/volumes.py +0 -0
  221. {kaqing-2.0.52.dist-info → kaqing-2.0.184.dist-info}/WHEEL +0 -0
  222. {kaqing-2.0.52.dist-info → kaqing-2.0.184.dist-info}/entry_points.txt +0 -0
  223. {kaqing-2.0.52.dist-info → kaqing-2.0.184.dist-info}/top_level.txt +0 -0
@@ -1,39 +1,29 @@
1
- from typing import Callable
2
1
  from adam.app_session import AppSession
3
- from adam.k8s_utils.ingresses import Ingresses
4
- from adam.k8s_utils.services import Services
5
- from adam.utils import log2
2
+ from adam.utils import ing
3
+ from adam.utils_k8s.ingresses import Ingresses
4
+ from adam.utils_k8s.services import Services
6
5
 
7
6
  def deploy_frontend(name: str, namespace: str, label_selector: str):
8
7
  app_session: AppSession = AppSession.create('c3', 'c3', namespace)
9
8
  port = 7678
10
9
  labels = gen_labels(label_selector)
11
- creating('service', lambda: Services.create_service(name, namespace, port, labels, labels=labels))
12
- creating('ingress', lambda: Ingresses.create_ingress(name, namespace, app_session.host, '/c3/c3/ops($|/)', port, annotations={
13
- 'kubernetes.io/ingress.class': 'nginx',
14
- 'nginx.ingress.kubernetes.io/use-regex': 'true',
15
- 'nginx.ingress.kubernetes.io/rewrite-target': '/'
16
- }, labels=labels))
10
+ with ing('Creating service'):
11
+ Services.create_service(name, namespace, port, labels, labels=labels)
12
+ with ing('Creating ingress'):
13
+ Ingresses.create_ingress(name, namespace, app_session.host, '/c3/c3/ops($|/)', port, annotations={
14
+ 'kubernetes.io/ingress.class': 'nginx',
15
+ 'nginx.ingress.kubernetes.io/use-regex': 'true',
16
+ 'nginx.ingress.kubernetes.io/rewrite-target': '/'
17
+ }, labels=labels)
17
18
 
18
19
  return f'https://{app_session.host}/c3/c3/ops'
19
20
 
20
21
  def undeploy_frontend(namespace: str, label_selector: str):
21
- deleting('ingress', lambda: Ingresses.delete_ingresses(namespace, label_selector=label_selector))
22
- deleting('service', lambda: Services.delete_services(namespace, label_selector=label_selector))
22
+ with ing('Deleting ingress'):
23
+ Ingresses.delete_ingresses(namespace, label_selector=label_selector)
24
+ with ing('Deleting service'):
25
+ Services.delete_services(namespace, label_selector=label_selector)
23
26
 
24
27
  def gen_labels(label_selector: str):
25
28
  kv = label_selector.split('=')
26
- return {kv[0]: kv[1]}
27
-
28
- def creating(name: str, body: Callable[[], None]):
29
- log2(f'Creating {name}...', nl=False)
30
- body()
31
- log2(' OK')
32
-
33
- def deleting(name: str, body: Callable[[], None]):
34
- try:
35
- log2(f'Deleting {name}...', nl=False)
36
- body()
37
- log2(' OK')
38
- except Exception as e:
39
- log2(e)
29
+ return {kv[0]: kv[1]}
@@ -1,14 +1,12 @@
1
1
  import click
2
2
 
3
- from adam.commands.command import Command
4
3
  from adam.commands.deploy.undeploy_frontend import UndeployFrontend
5
4
  from adam.commands.deploy.undeploy_pg_agent import UndeployPgAgent
6
5
  from adam.commands.deploy.undeploy_pod import UndeployPod
7
- from adam.repl_state import ReplState
6
+ from adam.commands.intermediate_command import IntermediateCommand
8
7
 
9
- class Undeploy(Command):
8
+ class Undeploy(IntermediateCommand):
10
9
  COMMAND = 'undeploy'
11
- reaper_login = None
12
10
 
13
11
  # the singleton pattern
14
12
  def __new__(cls, *args, **kwargs):
@@ -16,27 +14,12 @@ class Undeploy(Command):
16
14
 
17
15
  return cls.instance
18
16
 
19
- def __init__(self, successor: Command=None):
20
- super().__init__(successor)
21
-
22
17
  def command(self):
23
18
  return Undeploy.COMMAND
24
19
 
25
- def run(self, cmd: str, state: ReplState):
26
- if not(args := self.args(cmd)):
27
- return super().run(cmd, state)
28
-
29
- return super().intermediate_run(cmd, state, args, Undeploy.cmd_list())
30
-
31
- def cmd_list():
20
+ def cmd_list(self):
32
21
  return [UndeployFrontend(), UndeployPod(), UndeployPgAgent()]
33
22
 
34
- def completion(self, state: ReplState):
35
- if state.sts:
36
- return super().completion(state)
37
-
38
- return {}
39
-
40
23
  class UndeployCommandHelper(click.Command):
41
24
  def get_help(self, ctx: click.Context):
42
- Command.intermediate_help(super().get_help(ctx), Undeploy.COMMAND, Undeploy.cmd_list())
25
+ IntermediateCommand.intermediate_help(super().get_help(ctx), Undeploy.COMMAND, Undeploy().cmd_list())
@@ -25,14 +25,11 @@ class UndeployFrontend(Command):
25
25
  if not(args := self.args(cmd)):
26
26
  return super().run(cmd, state)
27
27
 
28
- state, args = self.apply_state(args, state)
29
- if not self.validate_state(state):
30
- return state
31
-
32
- label_selector = Config().get('pod.label-selector', 'run=ops')
33
- undeploy_frontend(state.namespace, label_selector)
28
+ with self.validate(args, state) as (args, state):
29
+ label_selector = Config().get('pod.label-selector', 'run=ops')
30
+ undeploy_frontend(state.namespace, label_selector)
34
31
 
35
- return state
32
+ return state
36
33
 
37
34
  def completion(self, state: ReplState):
38
35
  return super().completion(state)
@@ -1,8 +1,8 @@
1
1
  from adam.commands.command import Command
2
- from adam.commands.deploy.deploy_utils import deleting
3
- from adam.commands.postgres.postgres_session import PostgresSession
2
+ from adam.commands.postgres.postgres_databases import PostgresDatabases
4
3
  from adam.config import Config
5
4
  from adam.repl_state import ReplState, RequiredState
5
+ from adam.utils import ing
6
6
 
7
7
  class UndeployPgAgent(Command):
8
8
  COMMAND = 'undeploy pg-agent'
@@ -26,13 +26,11 @@ class UndeployPgAgent(Command):
26
26
  if not(args := self.args(cmd)):
27
27
  return super().run(cmd, state)
28
28
 
29
- state, args = self.apply_state(args, state)
30
- if not self.validate_state(state):
31
- return state
32
-
33
- deleting('pod', lambda: PostgresSession.undeploy_pg_agent(Config().get('pg.agent.name', 'ops-pg-agent'), state.namespace))
29
+ with self.validate(args, state) as (args, state):
30
+ with ing('Deleting pod'):
31
+ PostgresDatabases.undeploy_pg_agent(Config().get('pg.agent.name', 'ops-pg-agent'), state.namespace)
34
32
 
35
- return state
33
+ return state
36
34
 
37
35
  def completion(self, state: ReplState):
38
36
  return super().completion(state)
@@ -1,10 +1,11 @@
1
1
  from adam.commands.command import Command
2
- from adam.commands.deploy.deploy_utils import undeploy_frontend, deleting
2
+ from adam.commands.deploy.deploy_utils import undeploy_frontend
3
3
  from adam.config import Config
4
- from adam.k8s_utils.config_maps import ConfigMaps
5
- from adam.k8s_utils.deployment import Deployments
6
- from adam.k8s_utils.pods import Pods
7
- from adam.k8s_utils.service_accounts import ServiceAccounts
4
+ from adam.utils import ing
5
+ from adam.utils_k8s.config_maps import ConfigMaps
6
+ from adam.utils_k8s.deployment import Deployments
7
+ from adam.utils_k8s.pods import Pods
8
+ from adam.utils_k8s.service_accounts import ServiceAccounts
8
9
  from adam.repl_state import ReplState, RequiredState
9
10
 
10
11
  class UndeployPod(Command):
@@ -29,18 +30,16 @@ class UndeployPod(Command):
29
30
  if not(args := self.args(cmd)):
30
31
  return super().run(cmd, state)
31
32
 
32
- state, args = self.apply_state(args, state)
33
- if not self.validate_state(state):
34
- return state
35
-
36
- label_selector = Config().get('pod.label-selector', 'run=ops')
37
- deleting('service account', lambda: ServiceAccounts.delete(state.namespace, label_selector=label_selector))
38
- deleting('config map', lambda: ConfigMaps.delete_with_selector(state.namespace, label_selector))
39
- deleting('deployment', lambda: Deployments.delete_with_selector(state.namespace, label_selector, grace_period_seconds=0))
40
- deleting('pod', lambda: Pods.delete_with_selector(state.namespace, label_selector, grace_period_seconds=0))
41
- undeploy_frontend(state.namespace, label_selector)
33
+ with self.validate(args, state) as (args, state):
34
+ label_selector = Config().get('pod.label-selector', 'run=ops')
35
+ with ing('Deleting service account'):
36
+ ServiceAccounts.delete(state.namespace, label_selector=label_selector)
37
+ with ing('Deleting config map'): ConfigMaps.delete_with_selector(state.namespace, label_selector)
38
+ with ing('Deleting deployment'): Deployments.delete_with_selector(state.namespace, label_selector, grace_period_seconds=0)
39
+ with ing('Deleting pod'): Pods.delete_with_selector(state.namespace, label_selector, grace_period_seconds=0)
40
+ undeploy_frontend(state.namespace, label_selector)
42
41
 
43
- return state
42
+ return state
44
43
 
45
44
  def completion(self, state: ReplState):
46
45
  return super().completion(state)
File without changes
@@ -0,0 +1,123 @@
1
+ from abc import abstractmethod
2
+
3
+ from adam.commands.command import Command
4
+ from adam.config import Config
5
+ from adam.pod_exec_result import PodExecResult
6
+ from adam.repl_state import BashSession, ReplState
7
+ from adam.utils import log2
8
+
9
+ class Device:
10
+ def pods(self, state: ReplState) -> tuple[list[str], str]:
11
+ return self.pod_names(state), self.pod(state)
12
+
13
+ def pod(self, state: ReplState) -> str:
14
+ return None
15
+
16
+ def pod_names(self, state: ReplState) -> list[str]:
17
+ return []
18
+
19
+ def default_container(self, state: ReplState) -> str:
20
+ return None
21
+
22
+ @abstractmethod
23
+ def ls(self, cmd: str, state: ReplState):
24
+ pass
25
+
26
+ def ls_completion(self, cmd: str, state: ReplState, default: dict = {}):
27
+ return default
28
+
29
+ def cd(self, dir: str, state: ReplState):
30
+ pass
31
+
32
+ def cd_completion(self, cmd: str, state: ReplState, default: dict = {}):
33
+ return default
34
+
35
+ @abstractmethod
36
+ def pwd(self, state: ReplState):
37
+ pass
38
+
39
+ def try_fallback_action(self, chain: Command, state: ReplState, cmd: str):
40
+ return False, None
41
+
42
+ def enter(self, state: ReplState):
43
+ pass
44
+
45
+ def preview(self, table: str, state: ReplState):
46
+ if not table:
47
+ if state.in_repl:
48
+ log2('Table is required.')
49
+ log2()
50
+ log2('Tables:')
51
+ self.show_tables(state)
52
+ else:
53
+ log2('* Table is missing.')
54
+ self.show_tables(state)
55
+
56
+ Command.display_help()
57
+
58
+ return 'command-missing'
59
+
60
+ rows = Config().get('preview.rows', 10)
61
+ self.show_table_preview(state, table, rows)
62
+
63
+ return state
64
+
65
+ @abstractmethod
66
+ def show_tables(self, state: ReplState):
67
+ pass
68
+
69
+ @abstractmethod
70
+ def show_table_preview(self, state: ReplState, table: str, rows: int):
71
+ pass
72
+
73
+ def bash(self, s0: ReplState, s1: ReplState, args: list[str]):
74
+ if s1.in_repl:
75
+ if self.bash_target_changed(s0, s1):
76
+ r = self._exec_with_dir(s1, args)
77
+ else:
78
+ r = self._exec_with_dir(s0, args)
79
+
80
+ if not r:
81
+ s1.exit_bash()
82
+
83
+ return 'inconsistent pwd'
84
+
85
+ return r
86
+ else:
87
+ self.exec_no_dir(' '.join(args), s1)
88
+
89
+ return s1
90
+
91
+ def _exec_with_dir(self, state: ReplState, args: list[str]) -> list[PodExecResult]:
92
+ session_just_created = False
93
+ if not args:
94
+ session_just_created = True
95
+ session = BashSession(state.device)
96
+ state.enter_bash(session)
97
+
98
+ if state.bash_session:
99
+ if args != ['pwd']:
100
+ if args:
101
+ args.append('&&')
102
+ args.extend(['pwd', '>', f'/tmp/.qing-{state.bash_session.session_id}'])
103
+
104
+ if not session_just_created:
105
+ if pwd := state.bash_session.pwd(state):
106
+ args = ['cd', pwd, '&&'] + args
107
+
108
+ return self.exec_with_dir(' '.join(args), session_just_created, state)
109
+
110
+ @abstractmethod
111
+ def bash_target_changed(self, s0: ReplState, s1: ReplState):
112
+ pass
113
+
114
+ @abstractmethod
115
+ def exec_no_dir(self, command: str, state: ReplState):
116
+ pass
117
+
118
+ @abstractmethod
119
+ def exec_with_dir(self, command: str, session_just_created: bool, state: ReplState):
120
+ pass
121
+
122
+ def bash_completion(self, cmd: str, state: ReplState, default: dict = {}):
123
+ return default
@@ -0,0 +1,163 @@
1
+ from adam.apps import Apps
2
+ from adam.commands import app
3
+ from adam.commands.bash.bash_completer import BashCompleter
4
+ from adam.commands.command import Command, InvalidStateException
5
+ from adam.commands.devices.device import Device
6
+ from adam.config import Config
7
+ from adam.repl_state import ReplState
8
+ from adam.utils import tabulize, log, wait_log
9
+ from adam.utils_k8s.app_pods import AppPods
10
+ from adam.utils_k8s.ingresses import Ingresses
11
+
12
+ class DeviceApp(Command, Device):
13
+ COMMAND = f'{ReplState.A}:'
14
+
15
+ # the singleton pattern
16
+ def __new__(cls, *args, **kwargs):
17
+ if not hasattr(cls, 'instance'): cls.instance = super(DeviceApp, cls).__new__(cls)
18
+
19
+ return cls.instance
20
+
21
+ def __init__(self, successor: Command=None):
22
+ super().__init__(successor)
23
+
24
+ def command(self):
25
+ return DeviceApp.COMMAND
26
+
27
+ def run(self, cmd: str, state: ReplState):
28
+ if not self.args(cmd):
29
+ return super().run(cmd, state)
30
+
31
+ state.device = ReplState.A
32
+
33
+ return state
34
+
35
+ def completion(self, state: ReplState):
36
+ return super().completion(state)
37
+
38
+ def help(self, _: ReplState):
39
+ return f'{DeviceApp.COMMAND}\t move to App Operations device'
40
+
41
+ def pod(self, state: ReplState) -> str:
42
+ return state.app_pod
43
+
44
+ def pod_names(self, state: ReplState) -> list[str]:
45
+ return AppPods.pod_names(state.namespace, state.app_env, state.app_app)
46
+
47
+ def default_container(self, state: ReplState) -> str:
48
+ return Config().get('app.container-name', 'c3-server')
49
+
50
+ def ls(self, cmd: str, state: ReplState):
51
+ if state.app_pod:
52
+ return self.bash(state, state, cmd.split(' '))
53
+ elif state.app_app:
54
+ tabulize(self.pod_names(state), header='POD_NAME')
55
+ elif state.app_env:
56
+ def line(n: str, ns: str):
57
+ host = Ingresses.get_host(Config().get('app.login.ingress', '{app_id}-k8singr-appleader-001').replace('{app_id}', f'{ns}-{n}'), ns)
58
+ if not host:
59
+ return None
60
+
61
+ endpoint = Config().get('app.login.url', 'https://{host}/{env}/{app}').replace('{host}', host).replace('{env}', state.app_env).replace('{app}', 'c3')
62
+ if not endpoint:
63
+ return None
64
+
65
+ return f"{n.split('-')[1]},{Ingresses.get_host(f'{ns}-{n}-k8singr-appleader-001', ns)},{endpoint}"
66
+
67
+ svcs = [l for l in [line(n, ns) for n, ns in Apps.apps(state.app_env)] if l]
68
+
69
+ tabulize(svcs, header='APP,HOST,ENDPOINT', separator=',')
70
+ else:
71
+ tabulize(Apps.envs(), lambda a: a[0], header='ENV', separator=',')
72
+
73
+ def ls_completion(self, cmd, state, default: dict = {}):
74
+ if state.app_app:
75
+ return super().completion(state) | {f'@{p}': {cmd: None} for p in self.pod_names(state)}
76
+
77
+ return default
78
+
79
+ def cd(self, dir: str, state: ReplState):
80
+ if dir == '':
81
+ state.app_env = None
82
+ state.app_app = None
83
+ state.app_pod = None
84
+ elif dir == '..':
85
+ if state.app_pod:
86
+ state.app_pod = None
87
+ elif state.app_app:
88
+ state.app_app = None
89
+ else:
90
+ state.app_env = None
91
+ else:
92
+ if state.app_app:
93
+ state.app_pod = dir
94
+ elif not state.app_env:
95
+ tks = dir.split('@')
96
+ if len(tks) > 1:
97
+ state.namespace = tks[1]
98
+
99
+ state.app_env = dir.split('@')[0]
100
+ else:
101
+ state.app_app = dir
102
+
103
+ def cd_completion(self, cmd: str, state: ReplState, default: dict = {}):
104
+ if state.app_app:
105
+ return {cmd: {'..': None} | {pod: None for pod in self.pod_names(state)}}
106
+ elif state.app_env:
107
+ return {cmd: {'..': None} | {app[0].split('-')[1]: None for app in Apps.apps(state.app_env)}}
108
+ else:
109
+ return {cmd: {'..': None} | {env[0]: None for env in Apps.envs()}}
110
+
111
+ def pwd(self, state: ReplState):
112
+ words = []
113
+
114
+ if state.app_env:
115
+ words.append(f'env/{state.app_env}')
116
+ if state.app_app:
117
+ words.append(f'app/{state.app_app}')
118
+
119
+ return '\t'.join([f'{ReplState.X}:>'] + (words if words else ['/']))
120
+
121
+ def try_fallback_action(self, chain: Command, state: ReplState, cmd: str):
122
+ if state.app_app:
123
+ return True, chain.run(f'app {cmd}', state)
124
+
125
+ return False, None
126
+
127
+ def enter(self, state: ReplState):
128
+ if not state.app_env:
129
+ if auto_enter := Config().get('repl.a.auto-enter', 'c3/c3/*'):
130
+ if auto_enter != 'no':
131
+ ea = auto_enter.split('/')
132
+ state.app_env = ea[0]
133
+ if len(ea) > 2:
134
+ state.app_app = ea[1]
135
+ state.app_pod = ea[2]
136
+ if state.app_pod == '*':
137
+ if (pods := self.pod_names(state)):
138
+ state.app_pod = pods[0]
139
+ wait_log(f'Moving to {state.app_env}/{state.app_app}/{state.app_pod}...')
140
+ else:
141
+ wait_log(f'No pods found, moving to {state.app_env}/{state.app_app}...')
142
+ else:
143
+ wait_log(f'Moving to {state.app_env}/{state.app_app}/{state.app_pod}...')
144
+ elif len(ea) > 1:
145
+ state.app_app = ea[1]
146
+ wait_log(f'Moving to {state.app_env}/{state.app_app}...')
147
+ else:
148
+ wait_log(f'Moving to {state.app_env}...')
149
+
150
+ def bash_target_changed(self, s0: ReplState, s1: ReplState):
151
+ return s0.app_env != s1.app_env or s0.app_app != s1.app_app or s0.app_pod != s1.app_pod
152
+
153
+ def exec_no_dir(self, command: str, state: ReplState):
154
+ with app(state) as pods:
155
+ return pods.exec(command)
156
+
157
+ def exec_with_dir(self, command: str, session_just_created: bool, state: ReplState):
158
+ with app(state) as pods:
159
+ return pods.exec(command, not session_just_created)
160
+
161
+ def bash_completion(self, cmd: str, state: ReplState, default: dict = {}):
162
+ return {cmd: BashCompleter(lambda: [])} | \
163
+ {f'@{p}': {cmd: BashCompleter(lambda: [])} for p in self.pod_names(state)}
@@ -0,0 +1,49 @@
1
+ from adam.commands.command import Command
2
+ from adam.commands.devices.device import Device
3
+ from adam.repl_state import ReplState
4
+ from adam.utils import tabulize, log
5
+ from adam.utils_athena import Athena
6
+
7
+ class DeviceAuditLog(Command, Device):
8
+ COMMAND = f'{ReplState.L}:'
9
+
10
+ # the singleton pattern
11
+ def __new__(cls, *args, **kwargs):
12
+ if not hasattr(cls, 'instance'): cls.instance = super(DeviceAuditLog, cls).__new__(cls)
13
+
14
+ return cls.instance
15
+
16
+ def __init__(self, successor: Command=None):
17
+ super().__init__(successor)
18
+
19
+ def command(self):
20
+ return DeviceAuditLog.COMMAND
21
+
22
+ def run(self, cmd: str, state: ReplState):
23
+ if not self.args(cmd):
24
+ return super().run(cmd, state)
25
+
26
+ state.device = ReplState.L
27
+
28
+ return state
29
+
30
+ def completion(self, state: ReplState):
31
+ return super().completion(state)
32
+
33
+ def help(self, _: ReplState):
34
+ return f'{DeviceAuditLog.COMMAND}\t move to Audit Log Operations device'
35
+
36
+ def ls(self, cmd: str, _: ReplState):
37
+ tabulize(Athena.table_names(), header='NAME', separator=',')
38
+
39
+ def pwd(self, _: ReplState):
40
+ return '\t'.join([f'{ReplState.L}:>', '/'])
41
+
42
+ def try_fallback_action(self, chain: Command, state: ReplState, cmd: str):
43
+ return True, chain.run(f'audit {cmd}', state)
44
+
45
+ def show_tables(self, _: ReplState):
46
+ tabulize(Athena.table_names(), separator=',')
47
+
48
+ def show_table_preview(self, _: ReplState, table: str, rows: int):
49
+ Athena.run_query(f'select * from {table} limit {rows}')