kaqing 2.0.184__py3-none-any.whl → 2.0.227__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 (205) hide show
  1. adam/app_session.py +1 -1
  2. adam/batch.py +15 -15
  3. adam/checks/compactionstats.py +2 -1
  4. adam/checks/cpu.py +2 -1
  5. adam/checks/disk.py +6 -5
  6. adam/checks/gossip.py +2 -1
  7. adam/checks/memory.py +2 -1
  8. adam/checks/status.py +2 -1
  9. adam/commands/app/app.py +4 -4
  10. adam/commands/app/app_ping.py +2 -2
  11. adam/commands/{login.py → app/login.py} +2 -2
  12. adam/commands/app/show_app_actions.py +3 -3
  13. adam/commands/app/show_app_id.py +2 -2
  14. adam/commands/app/show_app_queues.py +2 -2
  15. adam/commands/{show → app}/show_login.py +3 -3
  16. adam/commands/app/utils_app.py +9 -1
  17. adam/commands/audit/audit.py +8 -24
  18. adam/commands/audit/audit_repair_tables.py +3 -3
  19. adam/commands/audit/audit_run.py +3 -3
  20. adam/commands/audit/completions_l.py +15 -0
  21. adam/commands/audit/show_last10.py +2 -3
  22. adam/commands/audit/show_slow10.py +2 -2
  23. adam/commands/audit/show_top10.py +2 -2
  24. adam/commands/bash/bash.py +3 -3
  25. adam/commands/bash/utils_bash.py +1 -1
  26. adam/commands/cassandra/download_cassandra_log.py +45 -0
  27. adam/commands/cassandra/restart_cluster.py +47 -0
  28. adam/commands/cassandra/restart_node.py +51 -0
  29. adam/commands/cassandra/restart_nodes.py +47 -0
  30. adam/commands/{rollout.py → cassandra/rollout.py} +3 -3
  31. adam/commands/{show → cassandra}/show_cassandra_repairs.py +7 -5
  32. adam/commands/{show → cassandra}/show_cassandra_status.py +24 -17
  33. adam/commands/{show → cassandra}/show_cassandra_version.py +2 -2
  34. adam/commands/cassandra/show_processes.py +50 -0
  35. adam/commands/cassandra/show_storage.py +44 -0
  36. adam/commands/{watch.py → cassandra/watch.py} +2 -2
  37. adam/commands/cli/__init__.py +0 -0
  38. adam/commands/{cli_commands.py → cli/cli_commands.py} +6 -1
  39. adam/commands/{clipboard_copy.py → cli/clipboard_copy.py} +4 -4
  40. adam/commands/{show/show_commands.py → cli/show_cli_commands.py} +5 -5
  41. adam/commands/code.py +2 -2
  42. adam/commands/command.py +54 -14
  43. adam/commands/commands_utils.py +14 -6
  44. adam/commands/config/__init__.py +0 -0
  45. adam/commands/{param_get.py → config/param_get.py} +2 -2
  46. adam/commands/{param_set.py → config/param_set.py} +2 -2
  47. adam/commands/{show → config}/show_params.py +3 -3
  48. adam/commands/{alter_tables.py → cql/alter_tables.py} +3 -3
  49. adam/commands/cql/completions_c.py +29 -0
  50. adam/commands/cql/cqlsh.py +4 -8
  51. adam/commands/cql/utils_cql.py +36 -17
  52. adam/commands/debug/__init__.py +0 -0
  53. adam/commands/debug/debug.py +22 -0
  54. adam/commands/debug/debug_completes.py +35 -0
  55. adam/commands/debug/debug_timings.py +35 -0
  56. adam/commands/debug/show_offloaded_completes.py +45 -0
  57. adam/commands/deploy/code_start.py +2 -2
  58. adam/commands/deploy/code_stop.py +2 -2
  59. adam/commands/deploy/deploy_frontend.py +2 -2
  60. adam/commands/deploy/deploy_pg_agent.py +2 -2
  61. adam/commands/deploy/deploy_pod.py +2 -2
  62. adam/commands/deploy/undeploy_frontend.py +2 -2
  63. adam/commands/deploy/undeploy_pg_agent.py +2 -2
  64. adam/commands/deploy/undeploy_pod.py +2 -2
  65. adam/commands/devices/device.py +37 -11
  66. adam/commands/devices/device_app.py +7 -7
  67. adam/commands/devices/device_auit_log.py +2 -2
  68. adam/commands/devices/device_cass.py +6 -6
  69. adam/commands/devices/device_export.py +7 -4
  70. adam/commands/devices/device_postgres.py +19 -9
  71. adam/commands/devices/devices.py +1 -1
  72. adam/commands/diag/__init__.py +0 -0
  73. adam/commands/{check.py → diag/check.py} +3 -3
  74. adam/commands/diag/generate_report.py +52 -0
  75. adam/commands/{issues.py → diag/issues.py} +3 -2
  76. adam/commands/exit.py +2 -2
  77. adam/commands/export/clean_up_all_export_sessions.py +2 -2
  78. adam/commands/export/clean_up_export_sessions.py +2 -2
  79. adam/commands/export/completions_x.py +11 -0
  80. adam/commands/export/download_export_session.py +5 -5
  81. adam/commands/export/drop_export_database.py +2 -2
  82. adam/commands/export/drop_export_databases.py +2 -2
  83. adam/commands/export/export.py +3 -19
  84. adam/commands/export/export_databases.py +20 -11
  85. adam/commands/export/export_select.py +9 -34
  86. adam/commands/export/export_sessions.py +13 -11
  87. adam/commands/export/export_use.py +6 -6
  88. adam/commands/export/export_x_select.py +48 -0
  89. adam/commands/export/exporter.py +140 -53
  90. adam/commands/export/import_files.py +3 -7
  91. adam/commands/export/import_session.py +2 -6
  92. adam/commands/export/importer.py +12 -13
  93. adam/commands/export/importer_athena.py +15 -35
  94. adam/commands/export/importer_sqlite.py +19 -8
  95. adam/commands/export/show_column_counts.py +11 -12
  96. adam/commands/export/show_export_databases.py +4 -4
  97. adam/commands/export/show_export_session.py +5 -5
  98. adam/commands/export/show_export_sessions.py +4 -4
  99. adam/commands/export/utils_export.py +40 -25
  100. adam/commands/fs/__init__.py +0 -0
  101. adam/commands/{cat.py → fs/cat.py} +4 -4
  102. adam/commands/fs/cat_local.py +42 -0
  103. adam/commands/{cd.py → fs/cd.py} +4 -4
  104. adam/commands/{download_file.py → fs/download_file.py} +7 -7
  105. adam/commands/{find_files.py → fs/find_files.py} +7 -7
  106. adam/commands/{find_processes.py → fs/find_processes.py} +14 -22
  107. adam/commands/{head.py → fs/head.py} +5 -5
  108. adam/commands/fs/head_local.py +46 -0
  109. adam/commands/{ls.py → fs/ls.py} +4 -4
  110. adam/commands/fs/ls_local.py +40 -0
  111. adam/commands/{pwd.py → fs/pwd.py} +2 -2
  112. adam/commands/fs/rm.py +18 -0
  113. adam/commands/fs/rm_downloads.py +39 -0
  114. adam/commands/fs/rm_logs.py +44 -0
  115. adam/commands/fs/rm_logs_local.py +38 -0
  116. adam/commands/{shell.py → fs/shell.py} +2 -2
  117. adam/commands/{show → fs}/show_adam.py +3 -3
  118. adam/commands/{show → fs}/show_host.py +2 -2
  119. adam/commands/fs/show_last_results.py +39 -0
  120. adam/commands/fs/tail.py +36 -0
  121. adam/commands/fs/tail_local.py +46 -0
  122. adam/commands/fs/utils_fs.py +192 -0
  123. adam/commands/help.py +2 -2
  124. adam/commands/intermediate_command.py +3 -0
  125. adam/commands/kubectl.py +2 -2
  126. adam/commands/medusa/medusa_backup.py +2 -2
  127. adam/commands/medusa/medusa_restore.py +4 -18
  128. adam/commands/medusa/medusa_show_backupjobs.py +2 -2
  129. adam/commands/medusa/medusa_show_restorejobs.py +2 -2
  130. adam/commands/medusa/utils_medusa.py +15 -0
  131. adam/commands/nodetool/__init__.py +0 -0
  132. adam/commands/nodetool/nodetool.py +87 -0
  133. adam/commands/nodetool/utils_nodetool.py +44 -0
  134. adam/commands/postgres/completions_p.py +22 -0
  135. adam/commands/postgres/postgres.py +10 -20
  136. adam/commands/postgres/postgres_databases.py +3 -3
  137. adam/commands/postgres/postgres_ls.py +3 -3
  138. adam/commands/postgres/postgres_preview.py +2 -2
  139. adam/commands/postgres/utils_postgres.py +12 -2
  140. adam/commands/preview_table.py +3 -4
  141. adam/commands/reaper/reaper_forward.py +2 -2
  142. adam/commands/reaper/reaper_forward_stop.py +2 -2
  143. adam/commands/reaper/reaper_restart.py +2 -2
  144. adam/commands/reaper/reaper_run_abort.py +2 -2
  145. adam/commands/reaper/reaper_runs.py +14 -12
  146. adam/commands/reaper/reaper_runs_abort.py +2 -2
  147. adam/commands/reaper/reaper_schedule_activate.py +8 -4
  148. adam/commands/reaper/reaper_schedule_start.py +3 -4
  149. adam/commands/reaper/reaper_schedule_stop.py +3 -4
  150. adam/commands/reaper/reaper_schedules.py +2 -2
  151. adam/commands/reaper/reaper_status.py +2 -2
  152. adam/commands/reaper/utils_reaper.py +41 -6
  153. adam/commands/repair/repair_log.py +2 -2
  154. adam/commands/repair/repair_run.py +2 -2
  155. adam/commands/repair/repair_scan.py +2 -4
  156. adam/commands/repair/repair_stop.py +2 -3
  157. adam/commands/{show/show.py → show.py} +12 -11
  158. adam/config.py +4 -5
  159. adam/embedded_params.py +1 -1
  160. adam/repl.py +24 -10
  161. adam/repl_commands.py +68 -45
  162. adam/repl_session.py +16 -1
  163. adam/repl_state.py +16 -1
  164. adam/sql/async_executor.py +62 -0
  165. adam/sql/lark_completer.py +286 -0
  166. adam/sql/lark_parser.py +604 -0
  167. adam/sql/qingl.lark +1075 -0
  168. adam/sso/cred_cache.py +2 -5
  169. adam/utils.py +259 -82
  170. adam/utils_async_job.py +73 -0
  171. adam/utils_k8s/app_clusters.py +11 -4
  172. adam/utils_k8s/app_pods.py +10 -5
  173. adam/utils_k8s/cassandra_clusters.py +19 -7
  174. adam/utils_k8s/cassandra_nodes.py +16 -6
  175. adam/utils_k8s/k8s.py +9 -0
  176. adam/utils_k8s/kube_context.py +1 -4
  177. adam/{pod_exec_result.py → utils_k8s/pod_exec_result.py} +8 -2
  178. adam/utils_k8s/pods.py +189 -29
  179. adam/utils_k8s/statefulsets.py +5 -2
  180. adam/utils_local.py +78 -2
  181. adam/utils_repl/appendable_completer.py +6 -0
  182. adam/utils_repl/repl_completer.py +51 -4
  183. adam/utils_sqlite.py +3 -8
  184. adam/version.py +1 -1
  185. {kaqing-2.0.184.dist-info → kaqing-2.0.227.dist-info}/METADATA +1 -1
  186. kaqing-2.0.227.dist-info/RECORD +280 -0
  187. kaqing-2.0.227.dist-info/top_level.txt +2 -0
  188. teddy/__init__.py +0 -0
  189. teddy/lark_parser.py +436 -0
  190. teddy/lark_parser2.py +618 -0
  191. adam/commands/cql/cql_completions.py +0 -32
  192. adam/commands/export/export_select_x.py +0 -54
  193. adam/commands/logs.py +0 -37
  194. adam/commands/nodetool.py +0 -69
  195. adam/commands/postgres/psql_completions.py +0 -11
  196. adam/commands/report.py +0 -61
  197. adam/commands/restart.py +0 -60
  198. adam/commands/show/show_processes.py +0 -49
  199. adam/commands/show/show_storage.py +0 -42
  200. kaqing-2.0.184.dist-info/RECORD +0 -244
  201. kaqing-2.0.184.dist-info/top_level.txt +0 -1
  202. /adam/commands/{show → cassandra}/__init__.py +0 -0
  203. /adam/commands/{nodetool_commands.py → nodetool/nodetool_commands.py} +0 -0
  204. {kaqing-2.0.184.dist-info → kaqing-2.0.227.dist-info}/WHEEL +0 -0
  205. {kaqing-2.0.184.dist-info → kaqing-2.0.227.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,47 @@
1
+ from adam.commands import extract_options, validate_args
2
+ from adam.commands.command import Command
3
+ from adam.utils_k8s.pods import Pods
4
+ from adam.utils_k8s.statefulsets import StatefulSets
5
+ from adam.repl_state import ReplState, RequiredState
6
+ from adam.utils import log2
7
+
8
+ class RestartNodes(Command):
9
+ COMMAND = 'restart nodes'
10
+
11
+ # the singleton pattern
12
+ def __new__(cls, *args, **kwargs):
13
+ if not hasattr(cls, 'instance'): cls.instance = super(RestartNodes, 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 RestartNodes.COMMAND
22
+
23
+ def required(self):
24
+ return RequiredState.CLUSTER
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, apply=False) as (args, state):
31
+ with extract_options(args, '--force') as (args, forced):
32
+ with validate_args(args, state, name='pod name'):
33
+ if not forced:
34
+ log2('Please add --force for restarting nodes.')
35
+
36
+ return 'force-needed'
37
+
38
+ for arg in args:
39
+ Pods.delete(arg, state.namespace)
40
+
41
+ return state
42
+
43
+ def completion(self, state: ReplState):
44
+ return super().completion(state, lambda: {p: {'--force': None} for p in StatefulSets.pod_names(state.sts, state.namespace)})
45
+
46
+ def help(self, state: ReplState):
47
+ return super().help(state, 'restart Cassandra nodes', args='<pod-name>... --force')
@@ -3,8 +3,8 @@ from kubernetes import client
3
3
  from kubernetes.client.rest import ApiException
4
4
 
5
5
  from adam.commands import extract_options
6
+ from adam.commands.cassandra.watch import Watch
6
7
  from adam.commands.command import Command
7
- from adam.commands.watch import Watch
8
8
  from adam.utils_k8s.statefulsets import StatefulSets
9
9
  from adam.config import Config
10
10
  from adam.repl_state import ReplState, RequiredState
@@ -84,5 +84,5 @@ class RollOut(Command):
84
84
 
85
85
  return {}
86
86
 
87
- def help(self, _: ReplState):
88
- return f'{RollOut.COMMAND} [--force]\t rollout all nodes'
87
+ def help(self, state: ReplState):
88
+ return super().help(state, 'rollout all nodes --force ignore current rolling out', args='[--force]')
@@ -1,3 +1,4 @@
1
+ from adam.commands import extract_trailing_options
1
2
  from adam.commands.command import Command
2
3
  from adam.commands.cql.utils_cql import cassandra
3
4
  from adam.repl_state import ReplState, RequiredState
@@ -25,11 +26,12 @@ class ShowCassandraRepairs(Command):
25
26
  return super().run(cmd, state)
26
27
 
27
28
  with self.validate(args, state) as (args, state):
28
- with cassandra(state) as pods:
29
- return pods.nodetool('repair_admin list')
29
+ with extract_trailing_options(args, '&') as (args, backgrounded):
30
+ with cassandra(state) as pods:
31
+ return pods.nodetool('repair_admin list', backgrounded=backgrounded)
30
32
 
31
33
  def completion(self, state: ReplState):
32
- return super().completion(state)
34
+ return super().completion(state, {'&': None})
33
35
 
34
- def help(self, _: ReplState):
35
- return f'{ShowCassandraRepairs.COMMAND}\t show Cassandra repairs'
36
+ def help(self, state: ReplState):
37
+ return super().help(state, 'show Cassandra repairs', args='[&]')
@@ -1,3 +1,4 @@
1
+ from datetime import datetime
1
2
  import sys
2
3
 
3
4
  from adam.checks.check_result import CheckResult
@@ -5,14 +6,16 @@ from adam.checks.check_utils import run_checks
5
6
  from adam.checks.compactionstats import CompactionStats
6
7
  from adam.checks.gossip import Gossip
7
8
  from adam.columns.columns import Columns
8
- from adam.commands import extract_options
9
+ from adam.commands import extract_options, extract_trailing_options
9
10
  from adam.commands.command import Command
11
+ from adam.commands.commands_utils import write_to_kaqing_log_file
10
12
  from adam.commands.cql.utils_cql import cassandra
11
13
  from adam.config import Config
14
+ from adam.repl_session import ReplSession
12
15
  from adam.utils_issues import IssuesUtils
13
16
  from adam.utils_k8s.statefulsets import StatefulSets
14
17
  from adam.repl_state import ReplState, RequiredState
15
- from adam.utils import SORT, tabulize, log, log2, log_exc
18
+ from adam.utils import SORT, log_dir, tabulize, log2, log_exc
16
19
  from adam.checks.status import parse_nodetool_status
17
20
 
18
21
  class ShowCassandraStatus(Command):
@@ -38,23 +41,24 @@ class ShowCassandraStatus(Command):
38
41
  return super().run(cmd, state)
39
42
 
40
43
  with self.validate(args, state) as (args, state):
41
- with extract_options(args, ['-s', '--show']) as (args, show_out):
42
- if state.namespace and state.pod:
43
- self.show_single_pod(state, show_out=show_out)
44
- elif state.namespace and state.sts:
45
- self.merge(state, Config().get('nodetool.samples', sys.maxsize), show_output=show_out)
44
+ with extract_trailing_options(args, '&') as (args, backgrounded):
45
+ with extract_options(args, ['-s', '--show']) as (args, show_out):
46
+ if state.namespace and state.pod:
47
+ self.show_single_pod(state, show_out=show_out, backgrounded=backgrounded)
48
+ elif state.namespace and state.sts:
49
+ self.merge(state, Config().get('nodetool.samples', sys.maxsize), show_output=show_out, backgrounded=backgrounded)
46
50
 
47
- return state
51
+ return state
48
52
 
49
- def show_single_pod(self, state: ReplState, show_out = False):
53
+ def show_single_pod(self, state: ReplState, show_out = False, backgrounded = False):
50
54
  with log_exc(True):
51
55
  with cassandra(state) as pods:
52
56
  result = pods.nodetool('status', show_out=False)
53
57
  status = parse_nodetool_status(result.stdout)
54
58
  check_results = run_checks(cluster=state.sts, namespace=state.namespace, checks=[CompactionStats(), Gossip()], show_out=show_out)
55
- self.show_table(status, check_results)
59
+ self.show_table(status, check_results, backgrounded=backgrounded)
56
60
 
57
- def merge(self, state: ReplState, samples: int, show_output=False):
61
+ def merge(self, state: ReplState, samples: int, show_output=False, backgrounded = False):
58
62
  statuses: list[list[dict]] = []
59
63
 
60
64
  pod_names = StatefulSets.pod_names(state.sts, state.namespace)
@@ -73,7 +77,7 @@ class ShowCassandraStatus(Command):
73
77
  combined_status = self.merge_status(statuses)
74
78
  log2(f'Showing merged status from {len(statuses)}/{len(pod_names)} nodes...')
75
79
  check_results = run_checks(cluster=state.sts, namespace=state.namespace, checks=[CompactionStats(), Gossip()], show_out=show_output)
76
- self.show_table(combined_status, check_results)
80
+ self.show_table(combined_status, check_results, backgrounded=backgrounded)
77
81
 
78
82
  return combined_status
79
83
 
@@ -94,17 +98,20 @@ class ShowCassandraStatus(Command):
94
98
 
95
99
  return combined
96
100
 
97
- def show_table(self, status: list[dict[str, any]], check_results: list[CheckResult]):
101
+ def show_table(self, status: list[dict[str, any]], check_results: list[CheckResult], backgrounded=False):
98
102
  cols = Config().get('status.columns', 'status,address,load,tokens,owns,host_id,gossip,compactions')
99
103
  header = Config().get('status.header', '--,Address,Load,Tokens,Owns,Host ID,GOSSIP,COMPACTIONS')
100
104
  columns = Columns.create_columns(cols)
101
105
 
102
- tabulize(status, lambda s: ','.join([c.host_value(check_results, s) for c in columns]), header=header, separator=',', sorted=SORT)
106
+ r = tabulize(status, lambda s: ','.join([c.host_value(check_results, s) for c in columns]), header=header, separator=',', sorted=SORT, to = 0 if backgrounded else 1)
107
+
108
+ if backgrounded:
109
+ r = write_to_kaqing_log_file(r)
103
110
 
104
111
  IssuesUtils.show(check_results)
105
112
 
106
113
  def completion(self, state: ReplState):
107
- return super().completion(state, {'-s': None})
114
+ return super().completion(state, {'-s': {'&': None}, '&': None})
108
115
 
109
- def help(self, _: ReplState):
110
- return f'{ShowCassandraStatus.COMMAND} [-s]\t show merged nodetool status -s show commands on nodes'
116
+ def help(self, state: ReplState):
117
+ return super().help(state, 'show merged nodetool status -s show processing details', args='[-s]')
@@ -31,5 +31,5 @@ class ShowCassandraVersion(Command):
31
31
  def completion(self, state: ReplState):
32
32
  return super().completion(state)
33
33
 
34
- def help(self, _: ReplState):
35
- return f'{ShowCassandraVersion.COMMAND}\t show Cassandra version'
34
+ def help(self, state: ReplState):
35
+ return super().help(state, 'show Cassandra version')
@@ -0,0 +1,50 @@
1
+ from adam.commands import extract_options, extract_sequence, extract_trailing_options
2
+ from adam.commands.command import Command
3
+ from adam.commands.cql.utils_cql import cassandra
4
+ from adam.config import Config
5
+ from adam.repl_state import ReplState, RequiredState
6
+
7
+ class ShowProcesses(Command):
8
+ COMMAND = 'show processes'
9
+
10
+ # the singleton pattern
11
+ def __new__(cls, *args, **kwargs):
12
+ if not hasattr(cls, 'instance'): cls.instance = super(ShowProcesses, 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 ShowProcesses.COMMAND
21
+
22
+ def required(self):
23
+ return RequiredState.CLUSTER_OR_POD
24
+
25
+ def run(self, cmd: str, state: ReplState):
26
+ if not(args := self.args(cmd)):
27
+ return super().run(cmd, state)
28
+
29
+ with self.validate(args, state) as (args, state):
30
+ with extract_trailing_options(args, '&') as (args, backgrounded):
31
+ with extract_options(args, ['-s', '--show']) as (args, show_out):
32
+ with extract_sequence(args, ['with', 'recipe', '=', 'mpstat']) as (_, recipe_qing):
33
+ cols = Config().get('processes.columns', 'pod,cpu-metrics,mem')
34
+ header = Config().get('processes.header', 'POD_NAME,M_CPU(USAGE/LIMIT),MEM/LIMIT')
35
+ if recipe_qing:
36
+ cols = Config().get('processes-mpstat.columns', 'pod,cpu,mem')
37
+ header = Config().get('processes-mpstat.header', 'POD_NAME,Q_CPU/TOTAL,MEM/LIMIT')
38
+
39
+ with cassandra(state) as pods:
40
+ pods.display_table(cols, header, show_out=show_out, backgrounded=backgrounded, msg='Checking processes')
41
+
42
+ return state
43
+
44
+ def completion(self, state: ReplState):
45
+ recipes = ['metrics', 'mpstat']
46
+ return super().completion(state, {'with': {'recipe': {'=': {r: {'-s': {'&': None}, '&': None} for r in recipes}}}, '-s': {'&': None}, '&': None})
47
+ # return super().completion(state, {'with': {'recipe': {'=': {'metrics': {'-s': {'&': None}, '&': None}, 'qing': {'-s': {'&': None}}}}}, '-s': {'&': None}, '&': None})
48
+
49
+ def help(self, state: ReplState):
50
+ return super().help(state, 'show process overview -s show processing details', args='[with recipe=metrics|mpstat] [-s]')
@@ -0,0 +1,44 @@
1
+ from adam.commands import extract_options, extract_trailing_options
2
+ from adam.commands.command import Command
3
+ from adam.commands.cql.utils_cql import cassandra
4
+ from adam.config import Config
5
+ from adam.repl_state import ReplState, RequiredState
6
+ from adam.utils import ing
7
+
8
+ class ShowStorage(Command):
9
+ COMMAND = 'show storage'
10
+
11
+ # the singleton pattern
12
+ def __new__(cls, *args, **kwargs):
13
+ if not hasattr(cls, 'instance'): cls.instance = super(ShowStorage, 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 ShowStorage.COMMAND
22
+
23
+ def required(self):
24
+ return RequiredState.CLUSTER_OR_POD
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
+ with extract_trailing_options(args, '&') as (args, backgrounded):
32
+ with extract_options(args, ['-s', '--show']) as (args, show_out):
33
+ cols = Config().get('storage.columns', 'pod,volume_root,volume_cassandra,snapshots,data,compactions')
34
+ header = Config().get('storage.header', 'POD_NAME,VOLUME /,VOLUME CASS,SNAPSHOTS,DATA,COMPACTIONS')
35
+ with cassandra(state) as pods:
36
+ pods.display_table(cols, header, show_out=show_out, backgrounded=backgrounded, msg='Checking storage')
37
+
38
+ return state
39
+
40
+ def completion(self, state: ReplState):
41
+ return super().completion(state, {'-s': {'&': None}, '&': None})
42
+
43
+ def help(self, state: ReplState):
44
+ return super().help(state, 'show storage overview -s show processing details', args='[-s]')
@@ -78,5 +78,5 @@ class Watch(Command):
78
78
 
79
79
  return {}
80
80
 
81
- def help(self, _: ReplState):
82
- return f'{Watch.COMMAND}\t watch Cassandra pod changes'
81
+ def help(self, state: ReplState):
82
+ return super().help(state, 'watch Cassandra pod changes')
File without changes
@@ -3,14 +3,19 @@ import re
3
3
 
4
4
  from adam.commands.reaper.utils_reaper import Reapers
5
5
  from adam.config import Config
6
+ from adam.utils import log_timing
6
7
  from adam.utils_k8s.kube_context import KubeContext
7
8
  from adam.utils_k8s.secrets import Secrets
8
9
  from adam.utils_k8s.statefulsets import StatefulSets
9
10
  from adam.repl_state import ReplState
10
11
 
11
12
  class CliCommands:
12
- @functools.lru_cache()
13
13
  def values(state: ReplState, collapse = False):
14
+ with log_timing('CliCommands.values'):
15
+ return CliCommands._values(state, collapse)
16
+
17
+ @functools.lru_cache()
18
+ def _values(state: ReplState, collapse = False):
14
19
  # node-exec-?, nodetool-?, cql-?, reaper-exec, reaper-forward, reaper-ui, reaper-usernae, reaper-password
15
20
  d = {}
16
21
 
@@ -3,9 +3,9 @@ import click
3
3
  import pyperclip
4
4
 
5
5
  from adam.commands import validate_args
6
+ from adam.commands.cli.cli_commands import CliCommands
6
7
  from adam.commands.command import Command, InvalidArgumentsException
7
8
  from adam.commands.command_helpers import ClusterOrPodCommandHelper
8
- from adam.commands.cli_commands import CliCommands
9
9
  from adam.repl_state import ReplState, RequiredState
10
10
  from adam.utils import tabulize, log, log2
11
11
 
@@ -62,10 +62,10 @@ class ClipboardCopy(Command):
62
62
  return state
63
63
 
64
64
  def completion(self, state: ReplState):
65
- return super().completion(state, lambda: {key: None for key in CliCommands.values(state).keys()})
65
+ return super().completion(state, lambda: {key: None for key in CliCommands.values(state).keys()}, auto_key='cli.cp-auto-complete')
66
66
 
67
- def help(self, _: ReplState):
68
- return f"{ClipboardCopy.COMMAND} <key>\t copy a value to clipboard for conveninence"
67
+ def help(self, state: ReplState):
68
+ return super().help(state, 'copy a value to clipboard for conveninence', args='<key')
69
69
 
70
70
  class CopyCommandHelper(click.Command):
71
71
  def lines(self):
@@ -1,7 +1,7 @@
1
+ from adam.commands.cli.cli_commands import CliCommands
1
2
  from adam.commands.command import Command
2
- from adam.commands.cli_commands import CliCommands
3
3
  from adam.repl_state import ReplState, RequiredState
4
- from adam.utils import tabulize, log
4
+ from adam.utils import tabulize
5
5
 
6
6
  class ShowKubectlCommands(Command):
7
7
  COMMAND = 'show cli-commands'
@@ -22,7 +22,7 @@ class ShowKubectlCommands(Command):
22
22
  return RequiredState.CLUSTER_OR_POD
23
23
 
24
24
  def run(self, cmd: str, state: ReplState):
25
- if not self.args(cmd):
25
+ if not (args := self.args(cmd)):
26
26
  return super().run(cmd, state)
27
27
 
28
28
  with self.validate(args, state) as (args, state):
@@ -52,5 +52,5 @@ class ShowKubectlCommands(Command):
52
52
  def completion(self, state: ReplState):
53
53
  return super().completion(state)
54
54
 
55
- def help(self, _: ReplState):
56
- return f"{ShowKubectlCommands.COMMAND}\t show kubectl commands"
55
+ def help(self, state: ReplState):
56
+ return super().help(state, 'show kubectl commands')
adam/commands/code.py CHANGED
@@ -53,5 +53,5 @@ class Code(Command):
53
53
  def completion(self, state: ReplState):
54
54
  return super().completion(state)
55
55
 
56
- def help(self, _: ReplState):
57
- return f'{Code.COMMAND} \t invoke interactive Python shell'
56
+ def help(self, state: ReplState):
57
+ return super().help(state, 'run interactive Python shell')
adam/commands/command.py CHANGED
@@ -5,8 +5,10 @@ import subprocess
5
5
  import sys
6
6
  from typing import Union
7
7
 
8
+ from adam.config import Config
8
9
  from adam.repl_state import ReplState, RequiredState
9
- from adam.utils import is_lambda, log2
10
+ from adam.sql.lark_completer import LarkCompleter
11
+ from adam.utils import log2
10
12
 
11
13
  repl_cmds: list['Command'] = []
12
14
 
@@ -20,6 +22,9 @@ class Command:
20
22
  def command(self) -> str:
21
23
  pass
22
24
 
25
+ def aliases(self):
26
+ return None
27
+
23
28
  # The chain of responsibility pattern
24
29
  # Do not do child of child!!!
25
30
  @abstractmethod
@@ -29,10 +34,10 @@ class Command:
29
34
 
30
35
  return None
31
36
 
32
- def completion(self, state: ReplState, leaf: dict[str, any] = None, pods: tuple[list[str], str] = None) -> dict[str, any]:
37
+ def completion(self, state: ReplState, leaf: dict[str, any] = None, pods: tuple[list[str], str] = None, auto: str = 'on', auto_key: str = None) -> dict[str, any]:
33
38
  # pods is a tuple of list of pod names and the current pod repl is on
34
39
  if not pods:
35
- return self._completion(state, leaf)
40
+ return self._completion(state, leaf, auto=auto, auto_key=auto_key)
36
41
 
37
42
  c = {}
38
43
 
@@ -40,23 +45,39 @@ class Command:
40
45
  pod = pods[1]
41
46
 
42
47
  if pod:
43
- c |= self._completion(state, leaf)
48
+ c |= self._completion(state, leaf, auto=auto, auto_key=auto_key)
44
49
 
45
- c |= {f'@{p}': self._completion(state, leaf, to_validate=False) for p in pod_names if p != pod}
50
+ c |= {f'@{p}': self._completion(state.with_pod(p), leaf, to_validate=False, auto=auto, auto_key=auto_key) for p in pod_names if p != pod}
46
51
 
47
52
  return c
48
53
 
49
- def _completion(self, state: ReplState, leaf: dict[str, any] = None, to_validate = True) -> dict[str, any]:
54
+ def _completion(self, state: ReplState, leaf: dict[str, any] = None, to_validate = True, auto: str = 'on', auto_key: str = None) -> dict[str, any]:
50
55
  if to_validate and not self.validate_state(state, show_err=False):
51
56
  return {}
52
57
 
53
- if is_lambda(leaf):
54
- leaf = leaf()
58
+ if callable(leaf):
59
+ if auto_key:
60
+ auto_key = f'auto-complete.{auto_key}'
61
+ auto = Config().get(auto_key, 'off')
62
+
63
+ if auto == 'on':
64
+ leaf = leaf()
65
+ elif auto in ['lazy', 'jit']:
66
+ leaf = LarkCompleter.from_lambda(auto_key, leaf, auto=auto)
67
+ else:
68
+ leaf = None
55
69
 
56
70
  d = leaf
57
71
  for t in reversed(self.command().split(' ')):
58
72
  d = {t: d}
59
73
 
74
+ if aliases := self.aliases():
75
+ for alias in aliases:
76
+ a = leaf
77
+ for t in reversed(alias.split(' ')):
78
+ a = {t: a}
79
+ d |= a
80
+
60
81
  return d
61
82
 
62
83
  def required(self) -> RequiredState:
@@ -68,16 +89,33 @@ class Command:
68
89
  def validate_state(self, state: ReplState, show_err = True):
69
90
  return state.validate(self.required(), show_err=show_err)
70
91
 
71
- def help(self, _: ReplState) -> str:
72
- return None
92
+ def help(self, _: ReplState, desc: str = None, command: str = None, args: str = None):
93
+ if not desc:
94
+ return None
95
+
96
+ if not command:
97
+ command = self.command()
98
+ if args:
99
+ args = f' {args}'
100
+ else:
101
+ args = ''
102
+ aliases = ' alias ' + ','.join(self.aliases()) if self.aliases() else ''
103
+ return f'{command}{args}{aliases}\t{desc}'
73
104
 
74
105
  def args(self, cmd: str):
75
106
  a = list(filter(None, cmd.split(' ')))
76
107
  spec = self.command_tokens()
77
- if spec != a[:len(spec)]:
78
- return None
108
+ if spec == a[:len(spec)]:
109
+ return a
79
110
 
80
- return a
111
+ if aliases := self.aliases():
112
+ for alias in aliases:
113
+ a = list(filter(None, cmd.split(' ')))
114
+ spec = alias.split(' ')
115
+ if spec == a[:len(spec)]:
116
+ return a
117
+
118
+ return None
81
119
 
82
120
  def apply_state(self, args: list[str], state: ReplState, resolve_pg = True, args_to_check = 6) -> tuple[ReplState, list[str]]:
83
121
  """
@@ -130,7 +168,7 @@ class Command:
130
168
  options = [options]
131
169
 
132
170
  if args and trailing:
133
- while args[-1] in trailing:
171
+ while args and args[-1] in trailing:
134
172
  found_trailing = True
135
173
  args = args[:-1]
136
174
 
@@ -148,6 +186,8 @@ class Command:
148
186
  return new_args, found_trailing, found_sequence, found_options
149
187
 
150
188
  def extract_option_sequence(args, sequence):
189
+ new_args = args
190
+
151
191
  len_sub = len(sequence)
152
192
  len_main = len(args)
153
193
  for i in range(len_main - len_sub + 1):
@@ -8,7 +8,7 @@ from adam.utils_k8s.cassandra_nodes import CassandraNodes
8
8
  from adam.utils_k8s.pods import Pods
9
9
  from adam.utils_k8s.statefulsets import StatefulSets
10
10
  from adam.repl_state import ReplState
11
- from adam.utils import SORT, duration, tabulize, log, log2
11
+ from adam.utils import SORT, duration, kaqing_log_file, tabulize, log2
12
12
 
13
13
  def show_pods(pods: List[client.V1Pod], ns: str, show_namespace = True, show_host_id = True):
14
14
  if len(pods) == 0:
@@ -59,14 +59,22 @@ def show_rollout(sts: str, ns: str):
59
59
  else:
60
60
  log2(f'Cluster has completed rollout {d} ago.')
61
61
 
62
- def show_table(state: ReplState, pods: list[str], cols: str, header: str, show_out=False):
62
+ def show_table(state: ReplState, pods: list[str], cols: str, header: str, show_out=False, backgrounded = False):
63
63
  columns = Columns.create_columns(cols)
64
64
 
65
65
  results = run_checks(cluster=state.sts, pod=state.pod, namespace=state.namespace, checks=collect_checks(columns), show_out=show_out)
66
66
 
67
- def line(pod_name: str):
68
- return
67
+ r = tabulize(pods, lambda p: ','.join([c.pod_value(results, p) for c in columns]), header=header, separator=',', sorted=SORT, to = 0 if backgrounded else 1)
68
+
69
+ if backgrounded:
70
+ r = write_to_kaqing_log_file(r)
71
+
72
+ IssuesUtils.show(results, state.in_repl)
73
+
74
+ return r
69
75
 
70
- tabulize(pods, lambda p: ','.join([c.pod_value(results, p) for c in columns]), header=header, separator=',', sorted=SORT)
76
+ def write_to_kaqing_log_file(r: str):
77
+ with kaqing_log_file() as f:
78
+ f.write(r)
71
79
 
72
- IssuesUtils.show(results, state.in_repl)
80
+ return f.name
File without changes
@@ -38,5 +38,5 @@ class GetParam(Command):
38
38
  def completion(self, _: ReplState):
39
39
  return {GetParam.COMMAND: {key: None for key in Config().keys()}}
40
40
 
41
- def help(self, _: ReplState):
42
- return f"{GetParam.COMMAND} <key>\t shows a Kaqing parameter"
41
+ def help(self, state: ReplState):
42
+ return super().help(state, "shows a Kaqing system parameter's value", args='<key>')
@@ -36,5 +36,5 @@ class SetParam(Command):
36
36
  def completion(self, _: ReplState):
37
37
  return {SetParam.COMMAND: {key: ({'true': None, 'false': None} if Config().get(key, None) in [True, False] else None) for key in Config().keys()}}
38
38
 
39
- def help(self, _: ReplState):
40
- return f"{SetParam.COMMAND} <key> <value>\t sets a Kaqing parameter to a different value"
39
+ def help(self, state: ReplState):
40
+ return super().help(state, 'sets a Kaqing system parameter to a different value', args='<key> <value>')
@@ -1,7 +1,7 @@
1
1
  from adam.commands.command import Command
2
2
  from adam.config import Config
3
3
  from adam.repl_state import ReplState
4
- from adam.utils import tabulize, log
4
+ from adam.utils import tabulize
5
5
 
6
6
  class ShowParams(Command):
7
7
  COMMAND = 'show params'
@@ -27,5 +27,5 @@ class ShowParams(Command):
27
27
  def completion(self, state: ReplState):
28
28
  return super().completion(state)
29
29
 
30
- def help(self, _: ReplState):
31
- return f"{ShowParams.COMMAND}\t show Kaqing parameters"
30
+ def help(self, state: ReplState):
31
+ return super().help(state, 'show Kaqing system parameters')
@@ -59,8 +59,8 @@ class AlterTables(Command):
59
59
  return state
60
60
 
61
61
  def completion(self, _: ReplState) -> dict[str, any]:
62
- # auto completion is taken care of by sql completer
62
+ # auto completion is taken care of by lark completer
63
63
  return {}
64
64
 
65
- def help(self, _: ReplState) -> str:
66
- return f'{AlterTables.COMMAND} <param = value> [--include-reaper] \t alter schema on all tables'
65
+ def help(self, state: ReplState) -> str:
66
+ return super().help(state, 'alter schema on all tables', args='with <param=value>,... [--include-reaper]')
@@ -0,0 +1,29 @@
1
+ from adam.commands.cql.utils_cql import cassandra_keyspaces, cassandra_table_names
2
+ from adam.commands.export.export_sessions import ExportSessions
3
+ from adam.commands.export.export_databases import ExportDatabases
4
+ from adam.config import Config
5
+ from adam.repl_state import ReplState
6
+ from adam.sql.lark_completer import LarkCompleter
7
+ from adam.utils import log_timing
8
+ from adam.utils_k8s.statefulsets import StatefulSets
9
+
10
+ def completions_c(state: ReplState) -> dict[str, any]:
11
+ ps = Config().get('cql.alter-tables.gc-grace-periods', '3600,86400,864000,7776000').split(',')
12
+
13
+ with log_timing('lark.completions'):
14
+ return LarkCompleter(
15
+ expandables = {
16
+ 'tables': lambda x: cassandra_table_names(state),
17
+ 'keyspaces': lambda x: cassandra_keyspaces(state.with_no_pod()),
18
+ 'table-props': {
19
+ 'GC_GRACE_SECONDS': ps
20
+ },
21
+ 'table-props-value': lambda x: {None: None, 'GC_GRACE_SECONDS': ps}[x],
22
+ 'export-database-types': ['athena', 'sqlite', 'csv'],
23
+ 'export-databases': lambda x: ExportDatabases.database_names(),
24
+ 'export-sessions': lambda x: ExportSessions.export_session_names(state.sts, state.pod, state.namespace),
25
+ 'export-sessions-incomplete': lambda x: ExportSessions.export_session_names(state.sts, state.pod, state.namespace, export_state='pending_import'),
26
+ 'hosts': lambda x: [f'@{p}' for p in StatefulSets.pod_names(state.sts, state.namespace)],
27
+ },
28
+ variant=ReplState.C
29
+ ).completions_for_nesting()