kaqing 2.0.171__py3-none-any.whl → 2.0.204__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.
Files changed (194) hide show
  1. adam/app_session.py +5 -10
  2. adam/apps.py +18 -4
  3. adam/batch.py +7 -7
  4. adam/checks/check_utils.py +3 -1
  5. adam/checks/disk.py +2 -3
  6. adam/columns/memory.py +3 -4
  7. adam/commands/__init__.py +15 -6
  8. adam/commands/alter_tables.py +26 -41
  9. adam/commands/app/__init__.py +0 -0
  10. adam/commands/{app_cmd.py → app/app.py} +2 -2
  11. adam/commands/{show → app}/show_app_actions.py +7 -15
  12. adam/commands/{show → app}/show_app_queues.py +1 -4
  13. adam/{utils_app.py → commands/app/utils_app.py} +9 -1
  14. adam/commands/audit/audit.py +9 -26
  15. adam/commands/audit/audit_repair_tables.py +5 -7
  16. adam/commands/audit/audit_run.py +1 -1
  17. adam/commands/audit/completions_l.py +15 -0
  18. adam/commands/audit/show_last10.py +2 -14
  19. adam/commands/audit/show_slow10.py +2 -13
  20. adam/commands/audit/show_top10.py +2 -11
  21. adam/commands/audit/utils_show_top10.py +15 -3
  22. adam/commands/bash/bash.py +1 -1
  23. adam/commands/bash/utils_bash.py +1 -1
  24. adam/commands/cassandra/__init__.py +0 -0
  25. adam/commands/cassandra/download_cassandra_log.py +45 -0
  26. adam/commands/cassandra/nodetool.py +64 -0
  27. adam/commands/cassandra/nodetool_commands.py +120 -0
  28. adam/commands/cassandra/restart_cluster.py +47 -0
  29. adam/commands/cassandra/restart_node.py +51 -0
  30. adam/commands/cassandra/restart_nodes.py +47 -0
  31. adam/commands/cassandra/rollout.py +88 -0
  32. adam/commands/cat.py +5 -19
  33. adam/commands/cd.py +7 -9
  34. adam/commands/check.py +10 -18
  35. adam/commands/cli_commands.py +6 -1
  36. adam/commands/{cp.py → clipboard_copy.py} +34 -36
  37. adam/commands/code.py +2 -2
  38. adam/commands/command.py +139 -22
  39. adam/commands/commands_utils.py +14 -12
  40. adam/commands/cql/alter_tables.py +66 -0
  41. adam/commands/cql/completions_c.py +29 -0
  42. adam/commands/cql/cqlsh.py +3 -7
  43. adam/commands/cql/utils_cql.py +23 -61
  44. adam/commands/debug/__init__.py +0 -0
  45. adam/commands/debug/debug.py +22 -0
  46. adam/commands/debug/debug_completes.py +35 -0
  47. adam/commands/debug/debug_timings.py +35 -0
  48. adam/commands/deploy/deploy_pg_agent.py +2 -2
  49. adam/commands/deploy/deploy_pod.py +2 -4
  50. adam/commands/deploy/undeploy_pg_agent.py +2 -2
  51. adam/commands/devices/device.py +40 -9
  52. adam/commands/devices/device_app.py +19 -29
  53. adam/commands/devices/device_auit_log.py +3 -3
  54. adam/commands/devices/device_cass.py +17 -23
  55. adam/commands/devices/device_export.py +12 -11
  56. adam/commands/devices/device_postgres.py +79 -63
  57. adam/commands/devices/devices.py +1 -1
  58. adam/commands/download_cassandra_log.py +45 -0
  59. adam/commands/download_file.py +47 -0
  60. adam/commands/export/clean_up_all_export_sessions.py +3 -3
  61. adam/commands/export/clean_up_export_sessions.py +7 -19
  62. adam/commands/export/completions_x.py +11 -0
  63. adam/commands/export/download_export_session.py +40 -0
  64. adam/commands/export/drop_export_database.py +6 -22
  65. adam/commands/export/drop_export_databases.py +3 -9
  66. adam/commands/export/export.py +1 -17
  67. adam/commands/export/export_databases.py +109 -32
  68. adam/commands/export/export_select.py +8 -55
  69. adam/commands/export/export_sessions.py +211 -0
  70. adam/commands/export/export_use.py +13 -16
  71. adam/commands/export/export_x_select.py +48 -0
  72. adam/commands/export/exporter.py +176 -167
  73. adam/commands/export/import_files.py +44 -0
  74. adam/commands/export/import_session.py +10 -6
  75. adam/commands/export/importer.py +24 -9
  76. adam/commands/export/importer_athena.py +114 -44
  77. adam/commands/export/importer_sqlite.py +45 -23
  78. adam/commands/export/show_column_counts.py +11 -20
  79. adam/commands/export/show_export_databases.py +5 -2
  80. adam/commands/export/show_export_session.py +6 -15
  81. adam/commands/export/show_export_sessions.py +4 -11
  82. adam/commands/export/utils_export.py +79 -27
  83. adam/commands/find_files.py +51 -0
  84. adam/commands/find_processes.py +76 -0
  85. adam/commands/generate_report.py +52 -0
  86. adam/commands/head.py +36 -0
  87. adam/commands/help.py +2 -2
  88. adam/commands/intermediate_command.py +6 -3
  89. adam/commands/login.py +3 -6
  90. adam/commands/ls.py +2 -2
  91. adam/commands/medusa/medusa_backup.py +13 -16
  92. adam/commands/medusa/medusa_restore.py +26 -37
  93. adam/commands/medusa/medusa_show_backupjobs.py +7 -7
  94. adam/commands/medusa/medusa_show_restorejobs.py +6 -6
  95. adam/commands/medusa/utils_medusa.py +15 -0
  96. adam/commands/nodetool.py +3 -8
  97. adam/commands/os/__init__.py +0 -0
  98. adam/commands/os/cat.py +36 -0
  99. adam/commands/os/download_file.py +47 -0
  100. adam/commands/os/find_files.py +51 -0
  101. adam/commands/os/find_processes.py +76 -0
  102. adam/commands/os/head.py +36 -0
  103. adam/commands/os/shell.py +41 -0
  104. adam/commands/param_get.py +10 -12
  105. adam/commands/param_set.py +7 -10
  106. adam/commands/postgres/completions_p.py +22 -0
  107. adam/commands/postgres/postgres.py +25 -40
  108. adam/commands/postgres/postgres_databases.py +269 -0
  109. adam/commands/postgres/utils_postgres.py +33 -20
  110. adam/commands/preview_table.py +4 -2
  111. adam/commands/pwd.py +4 -6
  112. adam/commands/reaper/reaper_forward.py +2 -2
  113. adam/commands/reaper/reaper_run_abort.py +4 -10
  114. adam/commands/reaper/reaper_runs.py +3 -3
  115. adam/commands/reaper/reaper_schedule_activate.py +12 -12
  116. adam/commands/reaper/reaper_schedule_start.py +7 -12
  117. adam/commands/reaper/reaper_schedule_stop.py +7 -12
  118. adam/commands/reaper/utils_reaper.py +13 -6
  119. adam/commands/repair/repair_log.py +1 -4
  120. adam/commands/repair/repair_run.py +3 -8
  121. adam/commands/repair/repair_scan.py +1 -6
  122. adam/commands/repair/repair_stop.py +1 -5
  123. adam/commands/restart_cluster.py +47 -0
  124. adam/commands/restart_node.py +51 -0
  125. adam/commands/restart_nodes.py +47 -0
  126. adam/commands/shell.py +9 -2
  127. adam/commands/show/show.py +4 -4
  128. adam/commands/show/show_adam.py +3 -3
  129. adam/commands/show/show_cassandra_repairs.py +5 -6
  130. adam/commands/show/show_cassandra_status.py +29 -29
  131. adam/commands/show/show_cassandra_version.py +1 -4
  132. adam/commands/show/{show_commands.py → show_cli_commands.py} +3 -6
  133. adam/commands/show/show_login.py +3 -9
  134. adam/commands/show/show_params.py +2 -5
  135. adam/commands/show/show_processes.py +15 -16
  136. adam/commands/show/show_storage.py +9 -8
  137. adam/config.py +4 -5
  138. adam/embedded_params.py +1 -1
  139. adam/log.py +4 -4
  140. adam/repl.py +26 -18
  141. adam/repl_commands.py +32 -20
  142. adam/repl_session.py +9 -1
  143. adam/repl_state.py +39 -10
  144. adam/sql/async_executor.py +44 -0
  145. adam/sql/lark_completer.py +286 -0
  146. adam/sql/lark_parser.py +604 -0
  147. adam/sql/qingl.lark +1076 -0
  148. adam/sql/sql_completer.py +4 -6
  149. adam/sql/sql_state_machine.py +25 -13
  150. adam/sso/authn_ad.py +2 -5
  151. adam/sso/authn_okta.py +2 -4
  152. adam/sso/cred_cache.py +2 -5
  153. adam/sso/idp.py +8 -11
  154. adam/utils.py +299 -105
  155. adam/utils_athena.py +18 -18
  156. adam/utils_audits.py +3 -7
  157. adam/utils_issues.py +2 -2
  158. adam/utils_k8s/app_clusters.py +4 -4
  159. adam/utils_k8s/app_pods.py +8 -6
  160. adam/utils_k8s/cassandra_clusters.py +16 -5
  161. adam/utils_k8s/cassandra_nodes.py +7 -6
  162. adam/utils_k8s/custom_resources.py +11 -17
  163. adam/utils_k8s/jobs.py +7 -11
  164. adam/utils_k8s/k8s.py +14 -5
  165. adam/utils_k8s/kube_context.py +3 -6
  166. adam/{pod_exec_result.py → utils_k8s/pod_exec_result.py} +4 -4
  167. adam/utils_k8s/pods.py +98 -36
  168. adam/utils_k8s/statefulsets.py +5 -2
  169. adam/utils_local.py +42 -0
  170. adam/utils_repl/appendable_completer.py +6 -0
  171. adam/utils_repl/repl_completer.py +45 -2
  172. adam/utils_repl/state_machine.py +3 -3
  173. adam/utils_sqlite.py +58 -30
  174. adam/version.py +1 -1
  175. {kaqing-2.0.171.dist-info → kaqing-2.0.204.dist-info}/METADATA +1 -1
  176. kaqing-2.0.204.dist-info/RECORD +277 -0
  177. kaqing-2.0.204.dist-info/top_level.txt +2 -0
  178. teddy/__init__.py +0 -0
  179. teddy/lark_parser.py +436 -0
  180. teddy/lark_parser2.py +618 -0
  181. adam/commands/cql/cql_completions.py +0 -33
  182. adam/commands/export/export_handlers.py +0 -71
  183. adam/commands/export/export_select_x.py +0 -54
  184. adam/commands/logs.py +0 -37
  185. adam/commands/postgres/postgres_context.py +0 -274
  186. adam/commands/postgres/psql_completions.py +0 -10
  187. adam/commands/report.py +0 -61
  188. adam/commands/restart.py +0 -60
  189. kaqing-2.0.171.dist-info/RECORD +0 -236
  190. kaqing-2.0.171.dist-info/top_level.txt +0 -1
  191. /adam/commands/{app_ping.py → app/app_ping.py} +0 -0
  192. /adam/commands/{show → app}/show_app_id.py +0 -0
  193. {kaqing-2.0.171.dist-info → kaqing-2.0.204.dist-info}/WHEEL +0 -0
  194. {kaqing-2.0.171.dist-info → kaqing-2.0.204.dist-info}/entry_points.txt +0 -0
adam/app_session.py CHANGED
@@ -1,16 +1,14 @@
1
1
  import json
2
2
  import threading
3
3
  import time
4
- import traceback
5
4
  import requests
6
5
  from urllib.parse import urlparse
7
6
 
8
7
  from adam.log import Log
9
- from adam.repl_state import ReplState
10
8
  from adam.sso.idp import Idp
11
9
  from adam.sso.idp_login import IdpLogin
12
10
  from adam.config import Config
13
- from adam.utils import debug, json_to_csv, lines_to_tabular, log, log2
11
+ from adam.utils import debug, debug_trace, json_to_csv, tabulize, log2, log_exc
14
12
  from adam.apps import Apps
15
13
 
16
14
  class AppLogin:
@@ -63,12 +61,9 @@ class AppSession:
63
61
  if r.status_code >= 200 and r.status_code < 300 or r.status_code == 400:
64
62
  try:
65
63
  js = r.json()
66
- try:
64
+ with log_exc(js):
67
65
  header, lines = json_to_csv(js, delimiter='\t')
68
- log(lines_to_tabular(lines, header=header, separator='\t'))
69
- except Exception as e:
70
- # traceback.print_exc(e)
71
- log(js)
66
+ tabulize(lines, header=header, separator='\t')
72
67
  except:
73
68
  if urlparse(r.url).hostname != urlparse(uri).hostname and not retried:
74
69
  app_login = app_session.login(idp_uri=app_login.idp_uri, forced=forced, use_token_from_env=False, use_cached_creds=False)
@@ -147,7 +142,7 @@ class AppSession:
147
142
  debug(f'{r.text}')
148
143
 
149
144
  self.app_login = AppLogin(session, app_access_token, idp_uri)
150
- except Exception:
145
+ except Exception as e:
151
146
  try:
152
147
  need = urlparse(r.url).hostname
153
148
  if idp_login.idp_uri:
@@ -160,7 +155,7 @@ class AppSession:
160
155
  log2(f"Invalid username/password.")
161
156
  break
162
157
  finally:
163
- debug(traceback.format_exc())
158
+ debug_trace()
164
159
 
165
160
  if 'res_text' in locals():
166
161
  Log.log_to_file(res_text)
adam/apps.py CHANGED
@@ -12,7 +12,8 @@ from adam.utils_k8s.services import Services
12
12
  from adam.utils import copy_config_file
13
13
 
14
14
  class AppAction:
15
- def __init__(self, name: str, payload: str = None, args: dict[str, str] = None, help: str = None):
15
+ def __init__(self, typ: str, name: str, payload: str = None, args: dict[str, str] = None, help: str = None):
16
+ self.typ = typ
16
17
  self.name = name
17
18
  self.payload = payload
18
19
  self.args = args
@@ -33,6 +34,19 @@ class AppAction:
33
34
 
34
35
  return args
35
36
 
37
+ def __str__(self):
38
+ line = None
39
+
40
+ args = ','.join(self.arguments())
41
+ if args:
42
+ line = f'{self.typ}.{self.name},{args}'
43
+ else:
44
+ line = f'{self.typ}.{self.name},'
45
+ if self.help:
46
+ line = f'{line},{self.help}'
47
+
48
+ return line
49
+
36
50
  class AppType:
37
51
  all_types: list['AppType'] = []
38
52
 
@@ -62,12 +76,12 @@ class AppType:
62
76
  aa: AppAction = None
63
77
 
64
78
  if isinstance(v, str):
65
- aa = AppAction(k, help=v)
79
+ aa = AppAction(typ, k, help=v)
66
80
  elif isinstance(v, dict):
67
81
  args = {k: v1 for k, v1 in v.items()}
68
- aa = AppAction(k, payload=v['payload'], args=args, help=v['help'])
82
+ aa = AppAction(typ, k, payload=v['payload'], args=args, help=v['help'])
69
83
  else:
70
- aa = AppAction(k)
84
+ aa = AppAction(typ, k)
71
85
 
72
86
  app_actions.append(aa)
73
87
 
adam/batch.py CHANGED
@@ -3,7 +3,7 @@ import click
3
3
  from adam.commands.audit.audit import Audit, AuditCommandHelper
4
4
  from adam.commands.bash.bash import Bash
5
5
  from adam.commands.check import Check, CheckCommandHelper
6
- from adam.commands.cp import ClipboardCopy, CopyCommandHelper
6
+ from adam.commands.clipboard_copy import ClipboardCopy, CopyCommandHelper
7
7
  from adam.commands.command import Command
8
8
  from adam.commands.command_helpers import ClusterCommandHelper, ClusterOrPodCommandHelper, PodCommandHelper
9
9
  from adam.commands.cql.cqlsh import CqlCommandHelper, Cqlsh
@@ -11,7 +11,7 @@ from adam.commands.deploy.deploy import Deploy, DeployCommandHelper
11
11
  from adam.commands.deploy.undeploy import Undeploy, UndeployCommandHelper
12
12
  from adam.commands.issues import Issues
13
13
  from adam.commands.login import Login
14
- from adam.commands.logs import Logs
14
+ from adam.commands.download_cassandra_log import DownloadCassandraLog
15
15
  from adam.commands.ls import Ls
16
16
  from adam.commands.medusa.medusa import Medusa
17
17
  from adam.commands.nodetool import NodeTool, NodeToolCommandHelper
@@ -19,8 +19,8 @@ from adam.commands.postgres.postgres import Postgres, PostgresCommandHelper
19
19
  from adam.commands.preview_table import PreviewTable
20
20
  from adam.commands.reaper.reaper import Reaper, ReaperCommandHelper
21
21
  from adam.commands.repair.repair import Repair, RepairCommandHelper
22
- from adam.commands.report import Report
23
- from adam.commands.restart import Restart
22
+ from adam.commands.generate_report import GenerateReport
23
+ from adam.commands.restart_nodes import RestartNodes
24
24
  from adam.commands.rollout import RollOut
25
25
  from adam.commands.show.show import Show, ShowCommandHelper
26
26
  from adam.commands.watch import Watch
@@ -128,7 +128,7 @@ def login(kubeconfig: str, config: str, param: list[str], namespace: str, pod: s
128
128
  @click.option('--pod', '-p', required=False, metavar='pod', help='Kubernetes pod name')
129
129
  @click.argument('extra_args', nargs=-1, metavar='<pod>', type=click.UNPROCESSED)
130
130
  def logs(kubeconfig: str, config: str, param: list[str], namespace: str, pod: str, extra_args):
131
- run_command(Logs(), kubeconfig, config, param, None, namespace, pod, extra_args)
131
+ run_command(DownloadCassandraLog(), kubeconfig, config, param, None, namespace, pod, extra_args)
132
132
 
133
133
 
134
134
  @cli.command(context_settings=dict(ignore_unknown_options=True, allow_extra_args=True), cls=ClusterCommandHelper, help='List statefulset or pods.')
@@ -221,7 +221,7 @@ def repair(kubeconfig: str, config: str, param: list[str], cluster: str, namespa
221
221
  @click.option('--show', '-s', is_flag=True, help='show output from Cassandra nodes')
222
222
  @click.argument('extra_args', nargs=-1, metavar='[cluster|pod]', type=click.UNPROCESSED)
223
223
  def report(kubeconfig: str, config: str, param: list[str], cluster: str, namespace: str, pod: str, show: bool, extra_args):
224
- run_command(Report(), kubeconfig, config, param, cluster, namespace, pod, ('-s',) + extra_args if show else extra_args)
224
+ run_command(GenerateReport(), kubeconfig, config, param, cluster, namespace, pod, ('-s',) + extra_args if show else extra_args)
225
225
 
226
226
 
227
227
  @cli.command(context_settings=dict(ignore_unknown_options=True, allow_extra_args=True), cls=ClusterOrPodCommandHelper, help='Restart Cassandra Cluster or Node')
@@ -234,7 +234,7 @@ def report(kubeconfig: str, config: str, param: list[str], cluster: str, namespa
234
234
  @click.option('--force', is_flag=True, help='need for restarting the whole cluster')
235
235
  @click.argument('extra_args', nargs=-1, metavar='<cluster|pod>', type=click.UNPROCESSED)
236
236
  def restart(kubeconfig: str, config: str, param: list[str], cluster: str, namespace: str, pod: str, force: bool, extra_args):
237
- run_command(Restart(), kubeconfig, config, param, cluster, namespace, pod, ('--force',) + extra_args if force else extra_args)
237
+ run_command(RestartNodes(), kubeconfig, config, param, cluster, namespace, pod, ('--force',) + extra_args if force else extra_args)
238
238
 
239
239
 
240
240
  @cli.command(context_settings=dict(ignore_unknown_options=True, allow_extra_args=True), cls=ClusterOrPodCommandHelper, help='Rolling restart Cassandra Cluster.')
@@ -47,7 +47,9 @@ def run_checks(cluster: str = None, namespace: str = None, pod: str = None, chec
47
47
  if not pod or pod == pod_name:
48
48
  sts_ns_pods.append((sts, ns, pod_name))
49
49
 
50
- with parallelize(sts_ns_pods, Config().action_workers('issues', 30), msg='d`Running|Ran checks on {size} pods') as exec:
50
+ with parallelize(sts_ns_pods,
51
+ Config().action_workers('issues', 30),
52
+ msg='d`Running|Ran checks on {size} pods') as exec:
51
53
  return exec.map(lambda sts_ns_pod: run_checks_on_pod(checks, sts_ns_pod[0], sts_ns_pod[1], sts_ns_pod[2], show_out))
52
54
 
53
55
  def run_checks_on_pod(checks: list[Check], cluster: str = None, namespace: str = None, pod: str = None, show_out=True):
adam/checks/disk.py CHANGED
@@ -6,6 +6,7 @@ from adam.checks.check_context import CheckContext
6
6
  from adam.checks.check_result import CheckResult
7
7
  from adam.checks.issue import Issue
8
8
  from adam.config import Config
9
+ from adam.utils import log_exc
9
10
  from adam.utils_k8s.cassandra_nodes import CassandraNodes
10
11
 
11
12
  class Disk(Check):
@@ -87,10 +88,8 @@ class Disk(Check):
87
88
 
88
89
  ss_size = 0.0
89
90
  if ss_out:
90
- try:
91
+ with log_exc():
91
92
  ss_size = round(float(ss_out.strip(' \r\n')) / 1024 / 1024, 2)
92
- except:
93
- pass
94
93
 
95
94
  def parse_du_out(l: str, default: str = None):
96
95
  groups = re.match(r'^(\S+)\s+(\S+)$', l.strip('\r'))
adam/columns/memory.py CHANGED
@@ -3,6 +3,7 @@ from kubernetes.utils import parse_quantity
3
3
  from adam.checks.check_result import CheckResult
4
4
  from adam.checks.memory import Memory as MemoryCheck
5
5
  from adam.columns.column import Column
6
+ from adam.utils import log_exc
6
7
 
7
8
  class Memory(Column):
8
9
  def name(self):
@@ -18,7 +19,5 @@ class Memory(Column):
18
19
  return f"{Memory.to_g(mem['used'])}/{Memory.to_g(mem['limit'])}"
19
20
 
20
21
  def to_g(v: str):
21
- try:
22
- return f'{round(parse_quantity(v) / 1024 / 1024 / 1024, 2)}G'
23
- except:
24
- return v
22
+ with log_exc():
23
+ return f'{round(parse_quantity(v) / 1024 / 1024 / 1024, 2)}G'
adam/commands/__init__.py CHANGED
@@ -1,15 +1,24 @@
1
- from adam.commands.command import ExtractAllOptionsHandler, ExtractOptionsHandler, ExtractTrailingOptionsHandler
1
+ from collections.abc import Callable
2
+ from adam.commands.command import ExtractAllOptionsHandler, ExtractOptionsHandler, ExtractSequenceOptionsHandler, ExtractTrailingOptionsHandler, ValidateArgCountHandler
2
3
  from adam.repl_state import ReplState
3
- from adam.utils_app import AppHandler
4
+ from adam.commands.app.utils_app import AppHandler
4
5
 
5
6
  def app(state: ReplState) -> AppHandler:
6
7
  return AppHandler(state)
7
8
 
8
- def extract_options(args: list[str], options = None):
9
+ def extract_options(args: list[str], options: list[str]):
9
10
  return ExtractOptionsHandler(args, options = options)
10
11
 
11
- def extract_trailing_options(args: list[str], trailing = None):
12
+ def extract_trailing_options(args: list[str], trailing: list[str]):
12
13
  return ExtractTrailingOptionsHandler(args, trailing = trailing)
13
14
 
14
- def extract_all_options(args: list[str], trailing = None, options = None):
15
- return ExtractAllOptionsHandler(args, trailing = trailing, options = options)
15
+ def extract_all_options(args: list[str], trailing = None, sequence = None, options = None):
16
+ return ExtractAllOptionsHandler(args, trailing = trailing, sequence = sequence, options = options)
17
+
18
+ def extract_sequence(args: list[str], sequence: list[str]):
19
+ return ExtractSequenceOptionsHandler(args, sequence = sequence)
20
+
21
+ def validate_args(args: list[str], state: ReplState, at_least: int = 1, exactly: int = -1,
22
+ name: str = None, msg: Callable[[], None] = None, default: str = None,
23
+ separator=None):
24
+ return ValidateArgCountHandler(args, state, at_least=at_least, exactly=exactly, name=name, msg=msg, default=default, separator=separator)
@@ -1,9 +1,9 @@
1
- from adam.commands import extract_options
1
+ from adam.commands import extract_options, validate_args
2
2
  from adam.commands.command import Command
3
3
  from adam.commands.cql.utils_cql import cassandra, cassandra_tables as get_tables
4
4
  from adam.config import Config
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'
@@ -29,49 +29,34 @@ class AlterTables(Command):
29
29
 
30
30
  with self.validate(args, state) as (args, state):
31
31
  with extract_options(args, '--include-reaper') as (args, include_reaper):
32
- if not args:
33
- if state.in_repl:
34
- log2('Please enter gc grace in seconds. e.g. alter gc-grace-seconds 3600')
35
- else:
36
- log2('* gc grace second is missing.')
37
- log2()
38
- Command.display_help()
39
-
40
- return 'missing-arg'
41
-
42
- arg_str = ' '.join(args)
43
-
44
- excludes = [e.strip(' \r\n') for e in Config().get(
45
- 'cql.alter-tables.excludes',
46
- 'system_auth,system_traces,reaper_db,system_distributed,system_views,system,system_schema,system_virtual_schema').split(',')]
47
- batching = Config().get('cql.alter-tables.batching', True)
48
- tables = get_tables(state, on_any=True)
49
- for k, v in tables.items():
50
- if k not in excludes or k == 'reaper_db' and include_reaper:
51
- if batching:
52
- # alter table <table_name> with GC_GRACE_SECONDS = <timeout>;
53
- cql = ';\n'.join([f'alter table {k}.{t} with {arg_str}' for t in v])
54
- try:
55
- with cassandra(state) as pods:
56
- pods.cql(cql, show_out=Config().is_debug(), show_query=not Config().is_debug(), on_any=True)
57
- except Exception as e:
58
- log2(e)
59
- continue
60
- else:
61
- for t in v:
62
- try:
63
- # alter table <table_name> with GC_GRACE_SECONDS = <timeout>;
64
- cql = f'alter table {k}.{t} with {arg_str}'
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):
65
44
  with cassandra(state) as pods:
66
- pods.cql(show_out=Config().is_debug(), show_query=not Config().is_debug(), on_any=True)
67
- except Exception as e:
68
- log2(e)
45
+ pods.cql(cql, show_out=Config().is_debug(), show_query=not Config().is_debug(), on_any=True)
69
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
70
55
 
71
- log2(f'{len(v)} tables altered in {k}.')
56
+ log2(f'{len(v)} tables altered in {k}.')
72
57
 
73
- # do not continue to cql route
74
- return state
58
+ # do not continue to cql route
59
+ return state
75
60
 
76
61
  def completion(self, _: ReplState) -> dict[str, any]:
77
62
  # auto completion is taken care of by sql completer
File without changes
@@ -31,8 +31,8 @@ class App(Command):
31
31
 
32
32
  return state
33
33
 
34
- def completion(self, state: ReplState):
35
- return super().completion(state, {'--force': None})
34
+ def completion(self, _: ReplState):
35
+ return {}
36
36
 
37
37
  def help(self, _: ReplState):
38
38
  return f"<AppType>.<AppAction> <args> [--force]\t post app action; check with 'show app actions' command"
@@ -1,9 +1,9 @@
1
1
  from adam.app_session import AppSession
2
- from adam.apps import AppAction, Apps
2
+ from adam.apps import Apps
3
3
  from adam.commands.command import Command
4
4
  from adam.config import Config
5
5
  from adam.repl_state import ReplState
6
- from adam.utils import lines_to_tabular, log
6
+ from adam.utils import tabulize, log
7
7
 
8
8
  class ShowAppActions(Command):
9
9
  COMMAND = 'show app actions'
@@ -28,25 +28,17 @@ class ShowAppActions(Command):
28
28
  return super().run(cmd, state)
29
29
 
30
30
  with self.validate(args, state) as (args, state):
31
- lines = []
31
+ actions = []
32
32
  for typ in Apps().app_types():
33
- for action in typ.actions:
34
- a: AppAction = action
35
- args = ','.join(a.arguments())
36
- if args:
37
- line = f'{typ.name}.{a.name},{args}'
38
- else:
39
- line = f'{typ.name}.{a.name},'
40
- if a.help:
41
- line = f'{line},{a.help}'
42
- lines.append(line)
43
- log(lines_to_tabular(lines, 'ACTION,ARGS,DESCRIPTION', separator=','))
33
+ actions.extend(typ.actions)
34
+
35
+ lines = tabulize(actions, lambda a: str(a), header='ACTION,ARGS,DESCRIPTION', separator=',')
44
36
  log()
45
37
 
46
38
  app_session: AppSession = AppSession.create(state.app_env or 'c3', state.app_app or 'c3')
47
39
  endpoint = Config().get('app.console-endpoint', 'https://{host}/{env}/{app}/static/console/index.html')
48
40
  endpoint = endpoint.replace('{host}', app_session.host).replace('{env}', app_session.env).replace('{app}', state.app_app or 'c3')
49
- log(lines_to_tabular([f'CONSOLE:,{endpoint}'], separator=','))
41
+ tabulize([f'CONSOLE:,{endpoint}'], separator=',')
50
42
 
51
43
  return lines
52
44
 
@@ -32,10 +32,7 @@ class ShowAppQueues(Command):
32
32
  return state
33
33
 
34
34
  def completion(self, state: ReplState):
35
- if state.app_app:
36
- return super().completion(state, {'--force': None})
37
-
38
- return {}
35
+ return super().completion(state, {'--force': None})
39
36
 
40
37
  def help(self, _: ReplState):
41
38
  return f"{ShowAppQueues.COMMAND} [--force]\t show invalidation queue counts"
@@ -3,12 +3,20 @@ from typing import Union
3
3
 
4
4
  from adam.app_session import AppSession
5
5
  from adam.apps import Apps
6
- from adam.pod_exec_result import PodExecResult
6
+ from adam.utils_k8s.pod_exec_result import PodExecResult
7
7
  from adam.repl_state import ReplState
8
8
  from adam.utils import log2
9
9
  from adam.utils_k8s.app_clusters import AppClusters
10
10
  from adam.utils_k8s.app_pods import AppPods
11
11
 
12
+ def app_cd_dirs(state: ReplState):
13
+ if state.app_app:
14
+ return ['..'] + AppPods.pod_names(state.namespace, state.app_env, state.app_app)
15
+ elif state.app_env:
16
+ return ['..'] + [app[0].split('-')[1] for app in Apps.apps(state.app_env)]
17
+ else:
18
+ return [env[0] for env in Apps.envs()]
19
+
12
20
  class AppRestHandler:
13
21
  def __init__(self, state: ReplState, forced = False):
14
22
  self.state = state
@@ -1,5 +1,7 @@
1
1
  import click
2
2
 
3
+ from adam.commands import validate_args
4
+ from adam.commands.audit.completions_l import completions_l
3
5
  from adam.commands.audit.audit_repair_tables import AuditRepairTables
4
6
  from adam.commands.audit.audit_run import AuditRun
5
7
  from adam.commands.audit.show_last10 import ShowLast10
@@ -9,7 +11,7 @@ from adam.commands.audit.utils_show_top10 import show_top10_completions_for_nest
9
11
  from adam.commands.command import Command
10
12
  from adam.commands.intermediate_command import IntermediateCommand
11
13
  from adam.repl_state import ReplState
12
- from adam.sql.sql_completer import SqlCompleter, SqlVariant
14
+ from adam.sql.lark_completer import LarkCompleter
13
15
  from adam.utils import log2, wait_log
14
16
  from adam.utils_athena import Athena
15
17
 
@@ -42,36 +44,17 @@ class Audit(IntermediateCommand):
42
44
  r = self.intermediate_run(cmd, state, args, self.cmd_list(), display_help=False)
43
45
 
44
46
  if not r or isinstance(r, str) and r == 'command-missing':
45
- sql = 'select * from audit order by ts desc limit 10'
46
- if args:
47
- sql = ' '.join(args)
48
- else:
47
+ with validate_args(args, state, default='select * from audit order by ts desc limit 10') as sql:
49
48
  log2(sql)
50
-
51
- Athena.run_query(sql)
49
+ Athena.run_query(sql)
52
50
 
53
51
  return state
54
52
 
55
53
  def completion(self, state: ReplState):
56
- if state.device == ReplState.L:
57
- if not self.schema_read:
58
- wait_log(f'Inspecting audit database schema...')
59
- self.schema_read = True
60
- # warm up the caches first time when l: drive is accessed
61
- Athena.table_names()
62
- Athena.column_names()
63
- Athena.column_names(partition_cols_only=True)
64
-
65
- return super().completion(state) | show_top10_completions_for_nesting() | SqlCompleter(
66
- lambda: Athena.table_names(),
67
- expandables={
68
- 'columns': lambda table: Athena.column_names(),
69
- 'partition_columns': lambda table: Athena.column_names(partition_cols_only=True)
70
- },
71
- variant=SqlVariant.ATHENA
72
- ).completions_for_nesting()
73
-
74
- return {}
54
+ if state.device != ReplState.L:
55
+ return {}
56
+
57
+ return completions_l()
75
58
 
76
59
  def cmd_list(self):
77
60
  return [AuditRepairTables(), AuditRun(), ShowLast10(), ShowSlow10(), ShowTop10()]
@@ -1,5 +1,6 @@
1
1
  import time
2
2
 
3
+ from adam.commands import validate_args
3
4
  from adam.commands.command import Command
4
5
  from adam.config import Config
5
6
  from adam.repl_state import ReplState
@@ -31,12 +32,9 @@ class AuditRepairTables(Command):
31
32
  return super().run(cmd, state)
32
33
 
33
34
  with self.validate(args, state) as (args, state):
34
- tables = Config().get('audit.athena.repair-partition-tables', 'audit').split(',')
35
- if args:
36
- tables = args
37
-
38
- meta = Audits.get_meta()
39
- self.repair(tables, meta)
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)
40
38
 
41
39
  return state
42
40
 
@@ -48,7 +46,7 @@ class AuditRepairTables(Command):
48
46
  with Audits.offload() as exec:
49
47
  exec.submit(lambda: self.auto_repair(hours))
50
48
 
51
- return super().completion(state)
49
+ # return super().completion(state)
52
50
 
53
51
  return {}
54
52
 
@@ -44,7 +44,7 @@ class AuditRun(Command):
44
44
  return state
45
45
 
46
46
  def completion(self, state: ReplState):
47
- return super().completion(state)
47
+ return {}
48
48
 
49
49
  def help(self, _: ReplState):
50
50
  return f"{AuditRun.COMMAND}\t run"
@@ -0,0 +1,15 @@
1
+ from adam.repl_state import ReplState
2
+ from adam.sql.lark_completer import LarkCompleter
3
+ from adam.utils_athena import Athena
4
+
5
+ def completions_l():
6
+ return LarkCompleter(
7
+ expandables={
8
+ 'tables': lambda x: Athena.table_names(),
9
+ 'columns': lambda table: Athena.column_names(),
10
+ 'partition-columns': lambda table: Athena.column_names(partition_cols_only=True),
11
+ 'topn-counts': lambda x: ['10'],
12
+ 'topn-types': lambda x: ['last', 'slow', 'top'],
13
+ 'topn-windows': lambda x: ['day', 'month'],
14
+ }, variant=ReplState.L
15
+ ).completions_for_nesting()
@@ -1,9 +1,6 @@
1
- from adam.commands.audit.utils_show_top10 import extract_limit_and_duration
1
+ from adam.commands.audit.utils_show_top10 import run_configured_query
2
2
  from adam.commands.command import Command
3
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 Audits
7
4
 
8
5
  class ShowLast10(Command):
9
6
  COMMAND = 'show last'
@@ -28,20 +25,11 @@ class ShowLast10(Command):
28
25
  return super().run(cmd, state)
29
26
 
30
27
  with self.validate(args, state) as (args, state):
31
- limit, date_condition = extract_limit_and_duration(args)
32
-
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)
28
+ run_configured_query('audit.queries.last10', args)
40
29
 
41
30
  return state
42
31
 
43
32
  def completion(self, _: ReplState):
44
-
45
33
  return {}
46
34
 
47
35
  def help(self, _: ReplState):
@@ -1,9 +1,6 @@
1
- from adam.commands.audit.utils_show_top10 import extract_limit_and_duration
1
+ from adam.commands.audit.utils_show_top10 import run_configured_query
2
2
  from adam.commands.command import Command
3
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 Audits
7
4
 
8
5
  class ShowSlow10(Command):
9
6
  COMMAND = 'show slow'
@@ -28,15 +25,7 @@ class ShowSlow10(Command):
28
25
  return super().run(cmd, state)
29
26
 
30
27
  with self.validate(args, state) as (args, state):
31
- limit, date_condition = extract_limit_and_duration(args)
32
-
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)
28
+ run_configured_query('audit.queries.slow10', args)
40
29
 
41
30
  return state
42
31
 
@@ -1,8 +1,6 @@
1
- from adam.commands.audit.utils_show_top10 import extract_limit_and_duration
1
+ from adam.commands.audit.utils_show_top10 import run_configured_query
2
2
  from adam.commands.command import Command
3
3
  from adam.repl_state import ReplState
4
- from adam.utils import log2
5
- from adam.utils_athena import Athena
6
4
 
7
5
  class ShowTop10(Command):
8
6
  COMMAND = 'show top'
@@ -27,14 +25,7 @@ class ShowTop10(Command):
27
25
  return super().run(cmd, state)
28
26
 
29
27
  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)
28
+ run_configured_query('audit.queries.top10', args)
38
29
 
39
30
  return state
40
31
 
@@ -1,17 +1,29 @@
1
1
  from datetime import datetime, timedelta
2
2
 
3
+ from adam.config import Config
4
+ from adam.utils import log2, log_exc
5
+ from adam.utils_athena import Athena
3
6
  from adam.utils_audits import Audits
4
7
  from adam.utils_repl.automata_completer import AutomataCompleter
5
8
  from adam.utils_repl.state_machine import StateMachine
6
9
 
10
+ def run_configured_query(config_key: str, args: list[str]):
11
+ limit, date_condition = extract_limit_and_duration(args)
12
+ if query := Config().get(config_key, None):
13
+ query = '\n '.join(query.split('\n'))
14
+ query = query.replace('{date_condition}', date_condition)
15
+ query = query.replace('{limit}', str(limit))
16
+
17
+ log2(query)
18
+ log2()
19
+ Athena.run_query(query)
20
+
7
21
  def extract_limit_and_duration(args: list[str]) -> tuple[int, datetime]:
8
22
  limit = 10
9
23
  _from = datetime.now() - timedelta(days=30)
10
24
  if args:
11
- try:
25
+ with log_exc():
12
26
  limit = int(args[0])
13
- except:
14
- pass
15
27
 
16
28
  if len(args) > 2 and args[1] == 'over':
17
29
  if args[2] == 'day':