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,9 +1,9 @@
1
+ from adam.commands import extract_options, validate_args
1
2
  from adam.commands.command import Command
2
- from adam.commands.cql.cql_utils import tables as get_tables, run_cql
3
+ from adam.commands.cql.utils_cql import cassandra, cassandra_tables as get_tables
3
4
  from adam.config import Config
4
- from adam.pod_exec_result import PodExecResult
5
5
  from adam.repl_state import ReplState, RequiredState
6
- from adam.utils import log2
6
+ from adam.utils import log2, log_exc
7
7
 
8
8
  class AlterTables(Command):
9
9
  COMMAND = 'alter tables with'
@@ -27,66 +27,40 @@ class AlterTables(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
- if not args:
35
- if state.in_repl:
36
- log2('Please enter gc grace in seconds. e.g. alter gc-grace-seconds 3600')
37
- else:
38
- log2('* gc grace second is missing.')
39
- log2()
40
- Command.display_help()
41
-
42
- return 'missing-arg'
43
-
44
- args, include_reaper = Command.extract_options(args, '--include-reaper')
45
- arg_str = ' '.join(args)
46
-
47
- # r: list[PodExecResult] = run_cql(state, 'describe tables', show_out=False, on_any=True)
48
- # if not r:
49
- # log2('No pod is available')
50
- # return 'no-pod'
51
-
52
- excludes = [e.strip(' \r\n') for e in Config().get(
53
- 'cql.alter-tables.excludes',
54
- 'system_auth,system_traces,reaper_db,system_distributed,system_views,system,system_schema,system_virtual_schema').split(',')]
55
- batching = Config().get('cql.alter-tables.batching', True)
56
- tables = get_tables(state, on_any=True)
57
- for k, v in tables.items():
58
- if k not in excludes or k == 'reaper_db' and include_reaper:
59
- if batching:
60
- # alter table <table_name> with GC_GRACE_SECONDS = <timeout>;
61
- cql = ';\n'.join([f'alter table {k}.{t} with {arg_str}' for t in v])
62
- try:
63
- run_cql(state, cql, [], show_out=Config().is_debug(), on_any=True)
64
- except Exception as e:
65
- log2(e)
66
- continue
67
- else:
68
- for t in v:
69
- try:
70
- # alter table <table_name> with GC_GRACE_SECONDS = <timeout>;
71
- cql = f'alter table {k}.{t} with {arg_str}'
72
- run_cql(state, cql, [], show_out=Config().is_debug(), on_any=True)
73
- except Exception as e:
74
- log2(e)
75
- continue
76
-
77
- log2(f'{len(v)} tables altered in {k}.')
78
-
79
- # do not continue to cql route
80
- return state
81
-
82
- def completion(self, state: ReplState) -> dict[str, any]:
83
- if state.sts:
84
- ps = Config().get('cql.alter-tables.gc-grace-periods', '3600,86400,864000,7776000').split(',')
85
- return super().completion(state, {
86
- 'GC_GRACE_SECONDS': {'=': {p.strip(' \r\n'): {'--include-reaper': None} for p in ps}},
87
- })
88
-
30
+ with self.validate(args, state) as (args, state):
31
+ with extract_options(args, '--include-reaper') as (args, include_reaper):
32
+ with validate_args(args, state, name='gc grace in seconds') as arg_str:
33
+ excludes = [e.strip(' \r\n') for e in Config().get(
34
+ 'cql.alter-tables.excludes',
35
+ 'system_auth,system_traces,reaper_db,system_distributed,system_views,system,system_schema,system_virtual_schema').split(',')]
36
+ batching = Config().get('cql.alter-tables.batching', True)
37
+ tables = get_tables(state, on_any=True)
38
+ for k, v in tables.items():
39
+ if k not in excludes or k == 'reaper_db' and include_reaper:
40
+ if batching:
41
+ # alter table <table_name> with GC_GRACE_SECONDS = <timeout>;
42
+ cql = ';\n'.join([f'alter table {k}.{t} with {arg_str}' for t in v])
43
+ with log_exc(True):
44
+ with cassandra(state) as pods:
45
+ pods.cql(cql, show_out=Config().is_debug(), show_query=not Config().is_debug(), on_any=True)
46
+ continue
47
+ else:
48
+ for t in v:
49
+ with log_exc(True):
50
+ # alter table <table_name> with GC_GRACE_SECONDS = <timeout>;
51
+ cql = f'alter table {k}.{t} with {arg_str}'
52
+ with cassandra(state) as pods:
53
+ pods.cql(show_out=Config().is_debug(), show_query=not Config().is_debug(), on_any=True)
54
+ continue
55
+
56
+ log2(f'{len(v)} tables altered in {k}.')
57
+
58
+ # do not continue to cql route
59
+ return state
60
+
61
+ def completion(self, _: ReplState) -> dict[str, any]:
62
+ # auto completion is taken care of by sql completer
89
63
  return {}
90
64
 
91
65
  def help(self, _: ReplState) -> str:
92
- return f'{AlterTables.COMMAND} <param = value> [--include-reaper] \t alter on all tables'
66
+ return f'{AlterTables.COMMAND} <param = value> [--include-reaper] \t alter schema on all tables'
@@ -0,0 +1,38 @@
1
+ from adam.commands import app, extract_options
2
+ from adam.commands.command import Command
3
+ from adam.repl_state import ReplState, RequiredState
4
+
5
+ class App(Command):
6
+ COMMAND = 'app'
7
+
8
+ # the singleton pattern
9
+ def __new__(cls, *args, **kwargs):
10
+ if not hasattr(cls, 'instance'): cls.instance = super(App, cls).__new__(cls)
11
+
12
+ return cls.instance
13
+
14
+ def __init__(self, successor: Command=None):
15
+ super().__init__(successor)
16
+
17
+ def command(self):
18
+ return App.COMMAND
19
+
20
+ def required(self):
21
+ return RequiredState.APP_APP
22
+
23
+ def run(self, cmd: str, state: ReplState):
24
+ if not(args := self.args(cmd)):
25
+ return super().run(cmd, state)
26
+
27
+ with self.validate(args, state) as (args, state):
28
+ with extract_options(args, '--force') as (args, forced):
29
+ with app(state) as http:
30
+ http.post(args, forced=forced)
31
+
32
+ return state
33
+
34
+ def completion(self, state: ReplState):
35
+ return super().completion(state, {'--force': None})
36
+
37
+ def help(self, _: ReplState):
38
+ return f"<AppType>.<AppAction> <args> [--force]\t post app action; check with 'show app actions' command"
@@ -1,6 +1,6 @@
1
+ from adam.commands import app, extract_options
1
2
  from adam.commands.command import Command
2
3
  from adam.repl_state import ReplState, RequiredState
3
- from adam.app_session import AppSession
4
4
 
5
5
  class AppPing(Command):
6
6
  COMMAND = 'app ping'
@@ -18,27 +18,21 @@ class AppPing(Command):
18
18
  return AppPing.COMMAND
19
19
 
20
20
  def required(self):
21
- return RequiredState.CLUSTER_OR_POD
21
+ return RequiredState.APP_APP
22
22
 
23
23
  def run(self, cmd: str, state: ReplState):
24
24
  if not(args := self.args(cmd)):
25
25
  return super().run(cmd, state)
26
26
 
27
- state, args = self.apply_state(args, state)
28
- if not self.validate_state(state, app_required=RequiredState.APP_APP):
29
- return state
27
+ with self.validate(args, state) as (args, state):
28
+ with extract_options(args, '--force') as (args, forced):
29
+ with app(state) as http:
30
+ http.post(['Echo.echoStatic'], forced=forced)
30
31
 
31
- _, forced = Command.extract_options(args, '--force')
32
-
33
- AppSession.run(state.app_env, state.app_app, state.namespace, 'Echo', 'echoStatic', forced= forced)
34
-
35
- return state
32
+ return state
36
33
 
37
34
  def completion(self, state: ReplState):
38
- if state.app_app:
39
- return super().completion(state, {'--force': None})
40
-
41
- return {}
35
+ return super().completion(state, {'--force': None})
42
36
 
43
37
  def help(self, _: ReplState):
44
38
  return f"{AppPing.COMMAND} [--force]\t ping app server with Echo.echoStatic()"
@@ -0,0 +1,49 @@
1
+ from adam.app_session import AppSession
2
+ from adam.apps import AppAction, Apps
3
+ from adam.commands.command import Command
4
+ from adam.config import Config
5
+ from adam.repl_state import ReplState
6
+ from adam.utils import tabulize, log
7
+
8
+ class ShowAppActions(Command):
9
+ COMMAND = 'show app actions'
10
+
11
+ # the singleton pattern
12
+ def __new__(cls, *args, **kwargs):
13
+ if not hasattr(cls, 'instance'): cls.instance = super(ShowAppActions, cls).__new__(cls)
14
+
15
+ return cls.instance
16
+
17
+ def __init__(self, successor: Command=None):
18
+ super().__init__(successor)
19
+
20
+ def command(self):
21
+ return ShowAppActions.COMMAND
22
+
23
+ def required(self):
24
+ return ReplState.A
25
+
26
+ def run(self, cmd: str, state: ReplState):
27
+ if not (args := self.args(cmd)):
28
+ return super().run(cmd, state)
29
+
30
+ with self.validate(args, state) as (args, state):
31
+ actions = []
32
+ for typ in Apps().app_types():
33
+ actions.extend(typ.actions)
34
+
35
+ lines = tabulize(actions, lambda a: str(a), header='ACTION,ARGS,DESCRIPTION', separator=',')
36
+ log()
37
+
38
+ app_session: AppSession = AppSession.create(state.app_env or 'c3', state.app_app or 'c3')
39
+ endpoint = Config().get('app.console-endpoint', 'https://{host}/{env}/{app}/static/console/index.html')
40
+ endpoint = endpoint.replace('{host}', app_session.host).replace('{env}', app_session.env).replace('{app}', state.app_app or 'c3')
41
+ tabulize([f'CONSOLE:,{endpoint}'], separator=',')
42
+
43
+ return lines
44
+
45
+ def completion(self, state: ReplState):
46
+ return super().completion(state)
47
+
48
+ def help(self, _: ReplState):
49
+ return f"{ShowAppActions.COMMAND}\t show app actions"
@@ -1,5 +1,5 @@
1
1
  from adam.commands.command import Command
2
- from adam.k8s_utils.custom_resources import CustomResources
2
+ from adam.utils_k8s.custom_resources import CustomResources
3
3
  from adam.repl_state import ReplState, RequiredState
4
4
  from adam.utils import log
5
5
 
@@ -25,20 +25,17 @@ class ShowAppId(Command):
25
25
  if not(args := self.args(cmd)):
26
26
  return super().run(cmd, state)
27
27
 
28
- state, _ = state.apply_args(args)
29
- if not self.validate_state(state):
30
- return state
28
+ with self.validate(args, state) as (args, state):
29
+ c3_app_id = 'Unknown'
31
30
 
32
- c3_app_id = 'Unknown'
31
+ apps = CustomResources.get_app_ids()
32
+ cr_name = CustomResources.get_cr_name(state.sts if state.sts else state.pod, namespace=state.namespace)
33
+ if cr_name in apps:
34
+ c3_app_id = (apps[cr_name])
33
35
 
34
- apps = CustomResources.get_app_ids()
35
- cr_name = CustomResources.get_cr_name(state.sts if state.sts else state.pod, namespace=state.namespace)
36
- if cr_name in apps:
37
- c3_app_id = (apps[cr_name])
36
+ log(c3_app_id)
38
37
 
39
- log(c3_app_id)
40
-
41
- return c3_app_id
38
+ return c3_app_id
42
39
 
43
40
  def completion(self, state: ReplState):
44
41
  return super().completion(state)
@@ -1,6 +1,6 @@
1
+ from adam.commands import app, extract_options
1
2
  from adam.commands.command import Command
2
3
  from adam.repl_state import ReplState, RequiredState
3
- from adam.app_session import AppSession
4
4
 
5
5
  class ShowAppQueues(Command):
6
6
  COMMAND = 'show app queues'
@@ -18,27 +18,21 @@ class ShowAppQueues(Command):
18
18
  return ShowAppQueues.COMMAND
19
19
 
20
20
  def required(self):
21
- return RequiredState.CLUSTER_OR_POD
21
+ return RequiredState.APP_APP
22
22
 
23
23
  def run(self, cmd: str, state: ReplState):
24
24
  if not(args := self.args(cmd)):
25
25
  return super().run(cmd, state)
26
26
 
27
- state, args = self.apply_state(args, state)
28
- if not self.validate_state(state, app_required=RequiredState.APP_APP):
29
- return state
27
+ with self.validate(args, state) as (_, state):
28
+ with extract_options(args, '--force') as (args, forced):
29
+ with app(state) as http:
30
+ http.post(['InvalidationQueue.countAll'], forced=forced)
30
31
 
31
- _, forced = Command.extract_options(args, '--force')
32
-
33
- AppSession.run(state.app_env, state.app_app, state.namespace, 'InvalidationQueue', 'countAll', forced= forced)
34
-
35
- return state
32
+ return state
36
33
 
37
34
  def completion(self, state: ReplState):
38
- if state.app_app:
39
- return super().completion(state, {'--force': None})
40
-
41
- return {}
35
+ return super().completion(state, {'--force': None})
42
36
 
43
37
  def help(self, _: ReplState):
44
38
  return f"{ShowAppQueues.COMMAND} [--force]\t show invalidation queue counts"
@@ -0,0 +1,98 @@
1
+ import json
2
+ from typing import Union
3
+
4
+ from adam.app_session import AppSession
5
+ from adam.apps import Apps
6
+ from adam.pod_exec_result import PodExecResult
7
+ from adam.repl_state import ReplState
8
+ from adam.utils import log2
9
+ from adam.utils_k8s.app_clusters import AppClusters
10
+ from adam.utils_k8s.app_pods import AppPods
11
+
12
+ class AppRestHandler:
13
+ def __init__(self, state: ReplState, forced = False):
14
+ self.state = state
15
+ self.forced = forced
16
+
17
+ def __enter__(self):
18
+ return self.post
19
+
20
+ def __exit__(self, exc_type, exc_val, exc_tb):
21
+ return False
22
+
23
+ def post(self, args: list[str]) -> Union[ReplState, str]:
24
+ if not args:
25
+ return 'arg missing'
26
+
27
+ t_f = args[0].split('.')
28
+ if len(t_f) < 2:
29
+ return 'arg missing'
30
+
31
+ state = self.state
32
+
33
+ payload, valid = Apps().payload(t_f[0], t_f[1], args[1:] if len(args) > 1 else [])
34
+ if not valid:
35
+ log2('Missing one or more action arguments.')
36
+ return state
37
+
38
+ if payload:
39
+ try:
40
+ payload = json.loads(payload)
41
+ except json.decoder.JSONDecodeError as e:
42
+ log2(f'Invalid json argument: {e}')
43
+ return state
44
+
45
+ AppSession.run(state.app_env, state.app_app, state.namespace, t_f[0], t_f[1], payload=payload, forced=self.forced)
46
+
47
+ return state
48
+
49
+ class AppPodService:
50
+ def __init__(self, handler: 'AppHandler'):
51
+ self.handler = handler
52
+
53
+ def exec(self, command: str, show_out = True) -> Union[PodExecResult, list[PodExecResult]]:
54
+ state = self.handler.state
55
+
56
+ if state.app_pod:
57
+ return AppPods.exec(state.app_pod, state.namespace, command, show_out=show_out, shell='bash')
58
+ elif state.app_app:
59
+ pods = AppPods.pod_names(state.namespace, state.app_env, state.app_app)
60
+ return AppClusters.exec(pods, state.namespace, command, action='bash', show_out=show_out, shell='bash')
61
+
62
+ return []
63
+
64
+ def post(self, args: list[str], forced=False) -> Union[ReplState, str]:
65
+ state = self.handler.state
66
+
67
+ if not args:
68
+ return 'arg missing'
69
+
70
+ t_f = args[0].split('.')
71
+ if len(t_f) < 2:
72
+ return 'arg missing'
73
+
74
+ payload, valid = Apps().payload(t_f[0], t_f[1], args[1:] if len(args) > 1 else [])
75
+ if not valid:
76
+ log2('Missing one or more action arguments.')
77
+ return state
78
+
79
+ if payload:
80
+ try:
81
+ payload = json.loads(payload)
82
+ except json.decoder.JSONDecodeError as e:
83
+ log2(f'Invalid json argument: {e}')
84
+ return state
85
+
86
+ AppSession.run(state.app_env, state.app_app, state.namespace, t_f[0], t_f[1], payload=payload, forced=forced)
87
+
88
+ return state
89
+
90
+ class AppHandler:
91
+ def __init__(self, state: ReplState):
92
+ self.state = state
93
+
94
+ def __enter__(self):
95
+ return AppPodService(self)
96
+
97
+ def __exit__(self, exc_type, exc_val, exc_tb):
98
+ return False
@@ -0,0 +1,81 @@
1
+ import click
2
+
3
+ from adam.commands import validate_args
4
+ from adam.commands.audit.audit_repair_tables import AuditRepairTables
5
+ from adam.commands.audit.audit_run import AuditRun
6
+ from adam.commands.audit.show_last10 import ShowLast10
7
+ from adam.commands.audit.show_slow10 import ShowSlow10
8
+ from adam.commands.audit.show_top10 import ShowTop10
9
+ from adam.commands.audit.utils_show_top10 import show_top10_completions_for_nesting
10
+ from adam.commands.command import Command
11
+ from adam.commands.intermediate_command import IntermediateCommand
12
+ from adam.repl_state import ReplState
13
+ from adam.sql.sql_completer import SqlCompleter, SqlVariant
14
+ from adam.utils import log2, wait_log
15
+ from adam.utils_athena import Athena
16
+
17
+ class Audit(IntermediateCommand):
18
+ COMMAND = 'audit'
19
+
20
+ # the singleton pattern
21
+ def __new__(cls, *args, **kwargs):
22
+ if not hasattr(cls, 'instance'): cls.instance = super(Audit, cls).__new__(cls)
23
+
24
+ return cls.instance
25
+
26
+ def __init__(self, successor: Command=None):
27
+ super().__init__(successor)
28
+ self.schema_read = False
29
+
30
+ def command(self):
31
+ return Audit.COMMAND
32
+
33
+ def required(self):
34
+ return ReplState.L
35
+
36
+ def run(self, cmd: str, state: ReplState):
37
+ if not(args := self.args(cmd)):
38
+ return super().run(cmd, state)
39
+
40
+ with self.validate(args, state) as (args, state):
41
+ r = None
42
+ if len(args) > 0:
43
+ r = self.intermediate_run(cmd, state, args, self.cmd_list(), display_help=False)
44
+
45
+ if not r or isinstance(r, str) and r == 'command-missing':
46
+ with validate_args(args, state, default='select * from audit order by ts desc limit 10') as sql:
47
+ log2(sql)
48
+ Athena.run_query(sql)
49
+
50
+ return state
51
+
52
+ def completion(self, state: ReplState):
53
+ if state.device == ReplState.L:
54
+ if not self.schema_read:
55
+ wait_log(f'Inspecting audit database schema...')
56
+ self.schema_read = True
57
+ # warm up the caches first time when l: drive is accessed
58
+ Athena.table_names()
59
+ Athena.column_names()
60
+ Athena.column_names(partition_cols_only=True)
61
+
62
+ return super().completion(state) | show_top10_completions_for_nesting() | SqlCompleter(
63
+ lambda: Athena.table_names(),
64
+ expandables={
65
+ 'columns': lambda table: Athena.column_names(),
66
+ 'partition_columns': lambda table: Athena.column_names(partition_cols_only=True)
67
+ },
68
+ variant=SqlVariant.ATHENA
69
+ ).completions_for_nesting()
70
+
71
+ return {}
72
+
73
+ def cmd_list(self):
74
+ return [AuditRepairTables(), AuditRun(), ShowLast10(), ShowSlow10(), ShowTop10()]
75
+
76
+ def help(self, _: ReplState):
77
+ return f'[{Audit.COMMAND}] [<sql-statements>]\t run SQL queries on Authena audit database'
78
+
79
+ class AuditCommandHelper(click.Command):
80
+ def get_help(self, ctx: click.Context):
81
+ IntermediateCommand.intermediate_help(super().get_help(ctx), Audit.COMMAND, Audit().cmd_list(), show_cluster_help=False)
@@ -0,0 +1,72 @@
1
+ import time
2
+
3
+ from adam.commands import validate_args
4
+ from adam.commands.command import Command
5
+ from adam.config import Config
6
+ from adam.repl_state import ReplState
7
+ from adam.utils import log, log2
8
+ from adam.utils_athena import Athena
9
+ from adam.utils_audits import AuditMeta, Audits
10
+
11
+ class AuditRepairTables(Command):
12
+ COMMAND = 'audit repair'
13
+
14
+ # the singleton pattern
15
+ def __new__(cls, *args, **kwargs):
16
+ if not hasattr(cls, 'instance'): cls.instance = super(AuditRepairTables, cls).__new__(cls)
17
+
18
+ return cls.instance
19
+
20
+ def __init__(self, successor: Command=None):
21
+ super().__init__(successor)
22
+ self.auto_repaired = False
23
+
24
+ def command(self):
25
+ return AuditRepairTables.COMMAND
26
+
27
+ def required(self):
28
+ return ReplState.L
29
+
30
+ def run(self, cmd: str, state: ReplState):
31
+ if not(args := self.args(cmd)):
32
+ return super().run(cmd, state)
33
+
34
+ with self.validate(args, state) as (args, state):
35
+ with validate_args(args, state, default=Config().get('audit.athena.repair-partition-tables', 'audit').split(',')) as tables:
36
+ meta = Audits.get_meta()
37
+ self.repair(tables, meta)
38
+
39
+ return state
40
+
41
+ def completion(self, state: ReplState):
42
+ # trigger auto repair if on l: drive
43
+ if state.device == ReplState.L:
44
+ if not self.auto_repaired:
45
+ if hours := Config().get('audit.athena.auto-repair.elapsed_hours', 12):
46
+ with Audits.offload() as exec:
47
+ exec.submit(lambda: self.auto_repair(hours))
48
+
49
+ return super().completion(state)
50
+
51
+ return {}
52
+
53
+ def auto_repair(self, hours: int):
54
+ self.auto_repaired = True
55
+
56
+ meta: AuditMeta = Audits.get_meta()
57
+ if meta.partitions_last_checked + hours * 60 * 60 < time.time():
58
+ tables = Config().get('audit.athena.repair-partition-tables', 'audit').split(',')
59
+ self.repair(tables, meta, show_sql=True)
60
+ log2(f'Audit tables have been auto-repaired.')
61
+
62
+ def repair(self, tables: list[str], meta: AuditMeta, show_sql = False):
63
+ with Audits.offload() as exec:
64
+ for table in tables:
65
+ if show_sql:
66
+ log(f'MSCK REPAIR TABLE {table}')
67
+
68
+ exec.submit(Athena.query, f'MSCK REPAIR TABLE {table}', None,)
69
+ exec.submit(Audits.put_meta, Audits.PARTITIONS_ADDED, meta,)
70
+
71
+ def help(self, _: ReplState):
72
+ return f"{AuditRepairTables.COMMAND}\t run MSCK REPAIR command for new partition discovery"
@@ -0,0 +1,50 @@
1
+ from adam.commands.command import Command
2
+ from adam.config import Config
3
+ from adam.repl_state import ReplState
4
+ from adam.utils import log2
5
+ from adam.utils_athena import Athena
6
+ from adam.utils_audits import AuditMeta, Audits
7
+
8
+ class AuditRun(Command):
9
+ COMMAND = 'audit run'
10
+
11
+ # the singleton pattern
12
+ def __new__(cls, *args, **kwargs):
13
+ if not hasattr(cls, 'instance'): cls.instance = super(AuditRun, cls).__new__(cls)
14
+
15
+ return cls.instance
16
+
17
+ def __init__(self, successor: Command=None):
18
+ super().__init__(successor)
19
+ self.auto_repaired = False
20
+
21
+ def command(self):
22
+ return AuditRun.COMMAND
23
+
24
+ def required(self):
25
+ return ReplState.L
26
+
27
+ def run(self, cmd: str, state: ReplState):
28
+ if not(args := self.args(cmd)):
29
+ return super().run(cmd, state)
30
+
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.')
43
+
44
+ return state
45
+
46
+ def completion(self, state: ReplState):
47
+ return super().completion(state)
48
+
49
+ def help(self, _: ReplState):
50
+ return f"{AuditRun.COMMAND}\t run"
@@ -0,0 +1,37 @@
1
+ from adam.commands.audit.utils_show_top10 import run_configured_query
2
+ from adam.commands.command import Command
3
+ from adam.repl_state import ReplState
4
+
5
+ class ShowLast10(Command):
6
+ COMMAND = 'show last'
7
+
8
+ # the singleton pattern
9
+ def __new__(cls, *args, **kwargs):
10
+ if not hasattr(cls, 'instance'): cls.instance = super(ShowLast10, cls).__new__(cls)
11
+
12
+ return cls.instance
13
+
14
+ def __init__(self, successor: Command=None):
15
+ super().__init__(successor)
16
+
17
+ def command(self):
18
+ return ShowLast10.COMMAND
19
+
20
+ def required(self):
21
+ return ReplState.L
22
+
23
+ def run(self, cmd: str, state: ReplState):
24
+ if not(args := self.args(cmd)):
25
+ return super().run(cmd, state)
26
+
27
+ with self.validate(args, state) as (args, state):
28
+ run_configured_query('audit.queries.last10', args)
29
+
30
+ return state
31
+
32
+ def completion(self, _: ReplState):
33
+
34
+ return {}
35
+
36
+ def help(self, _: ReplState):
37
+ return f'{ShowLast10.COMMAND} [limit]\t show last <limit> audit lines'