kaqing 2.0.184__py3-none-any.whl → 2.0.214__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 (152) hide show
  1. adam/app_session.py +1 -1
  2. adam/batch.py +15 -15
  3. adam/commands/app/app.py +2 -2
  4. adam/commands/app/show_app_actions.py +1 -1
  5. adam/commands/{show → app}/show_login.py +1 -1
  6. adam/commands/app/utils_app.py +9 -1
  7. adam/commands/audit/audit.py +6 -20
  8. adam/commands/audit/audit_repair_tables.py +1 -1
  9. adam/commands/audit/audit_run.py +1 -1
  10. adam/commands/audit/completions_l.py +15 -0
  11. adam/commands/audit/show_last10.py +0 -1
  12. adam/commands/bash/bash.py +1 -1
  13. adam/commands/bash/utils_bash.py +1 -1
  14. adam/commands/cassandra/download_cassandra_log.py +45 -0
  15. adam/commands/cassandra/restart_cluster.py +47 -0
  16. adam/commands/cassandra/restart_node.py +51 -0
  17. adam/commands/cassandra/restart_nodes.py +47 -0
  18. adam/commands/{rollout.py → cassandra/rollout.py} +1 -1
  19. adam/commands/{show → cassandra}/show_cassandra_repairs.py +5 -3
  20. adam/commands/{show → cassandra}/show_cassandra_status.py +22 -15
  21. adam/commands/cassandra/show_processes.py +50 -0
  22. adam/commands/{show → cassandra}/show_storage.py +10 -8
  23. adam/commands/cli/__init__.py +0 -0
  24. adam/commands/{cli_commands.py → cli/cli_commands.py} +6 -1
  25. adam/commands/{clipboard_copy.py → cli/clipboard_copy.py} +2 -2
  26. adam/commands/{show/show_commands.py → cli/show_cli_commands.py} +2 -2
  27. adam/commands/command.py +22 -9
  28. adam/commands/commands_utils.py +14 -6
  29. adam/commands/config/__init__.py +0 -0
  30. adam/commands/{show → config}/show_params.py +1 -1
  31. adam/commands/{alter_tables.py → cql/alter_tables.py} +1 -1
  32. adam/commands/cql/completions_c.py +29 -0
  33. adam/commands/cql/cqlsh.py +2 -6
  34. adam/commands/cql/utils_cql.py +26 -17
  35. adam/commands/debug/__init__.py +0 -0
  36. adam/commands/debug/debug.py +22 -0
  37. adam/commands/debug/debug_completes.py +35 -0
  38. adam/commands/debug/debug_timings.py +35 -0
  39. adam/commands/debug/show_offloaded_completes.py +45 -0
  40. adam/commands/devices/device.py +30 -4
  41. adam/commands/devices/device_app.py +1 -1
  42. adam/commands/devices/device_export.py +5 -2
  43. adam/commands/devices/device_postgres.py +13 -3
  44. adam/commands/devices/devices.py +1 -1
  45. adam/commands/diag/__init__.py +0 -0
  46. adam/commands/{check.py → diag/check.py} +1 -1
  47. adam/commands/diag/generate_report.py +52 -0
  48. adam/commands/export/completions_x.py +11 -0
  49. adam/commands/export/download_export_session.py +2 -1
  50. adam/commands/export/export.py +0 -16
  51. adam/commands/export/export_databases.py +16 -10
  52. adam/commands/export/export_select.py +8 -33
  53. adam/commands/export/export_sessions.py +12 -11
  54. adam/commands/export/export_use.py +3 -3
  55. adam/commands/export/export_x_select.py +48 -0
  56. adam/commands/export/exporter.py +140 -53
  57. adam/commands/export/import_files.py +2 -2
  58. adam/commands/export/import_session.py +0 -4
  59. adam/commands/export/importer.py +11 -11
  60. adam/commands/export/importer_athena.py +15 -35
  61. adam/commands/export/importer_sqlite.py +19 -8
  62. adam/commands/export/show_column_counts.py +10 -10
  63. adam/commands/export/show_export_databases.py +2 -1
  64. adam/commands/export/show_export_session.py +1 -1
  65. adam/commands/export/show_export_sessions.py +1 -1
  66. adam/commands/export/utils_export.py +38 -15
  67. adam/commands/fs/__init__.py +0 -0
  68. adam/commands/{cat.py → fs/cat.py} +2 -2
  69. adam/commands/fs/cat_local.py +42 -0
  70. adam/commands/{cd.py → fs/cd.py} +2 -2
  71. adam/commands/{download_file.py → fs/download_file.py} +5 -5
  72. adam/commands/{find_files.py → fs/find_files.py} +4 -4
  73. adam/commands/{find_processes.py → fs/find_processes.py} +3 -3
  74. adam/commands/{head.py → fs/head.py} +2 -2
  75. adam/commands/{ls.py → fs/ls.py} +2 -2
  76. adam/commands/fs/ls_local.py +40 -0
  77. adam/commands/fs/rm.py +18 -0
  78. adam/commands/fs/rm_downloads.py +39 -0
  79. adam/commands/fs/rm_logs.py +38 -0
  80. adam/commands/{show → fs}/show_adam.py +1 -1
  81. adam/commands/intermediate_command.py +3 -0
  82. adam/commands/medusa/medusa_restore.py +2 -16
  83. adam/commands/medusa/utils_medusa.py +15 -0
  84. adam/commands/nodetool/__init__.py +0 -0
  85. adam/commands/{nodetool.py → nodetool/nodetool.py} +3 -8
  86. adam/commands/postgres/completions_p.py +22 -0
  87. adam/commands/postgres/postgres.py +7 -14
  88. adam/commands/postgres/postgres_databases.py +3 -3
  89. adam/commands/postgres/postgres_ls.py +1 -1
  90. adam/commands/postgres/utils_postgres.py +12 -2
  91. adam/commands/preview_table.py +1 -1
  92. adam/commands/reaper/reaper_schedule_activate.py +6 -2
  93. adam/commands/reaper/reaper_schedule_start.py +1 -2
  94. adam/commands/reaper/reaper_schedule_stop.py +1 -2
  95. adam/commands/reaper/utils_reaper.py +10 -1
  96. adam/commands/repair/repair_scan.py +0 -2
  97. adam/commands/repair/repair_stop.py +0 -1
  98. adam/commands/{show/show.py → show.py} +12 -11
  99. adam/config.py +4 -5
  100. adam/embedded_params.py +1 -1
  101. adam/repl.py +22 -9
  102. adam/repl_commands.py +50 -42
  103. adam/repl_session.py +9 -1
  104. adam/repl_state.py +16 -1
  105. adam/sql/async_executor.py +62 -0
  106. adam/sql/lark_completer.py +286 -0
  107. adam/sql/lark_parser.py +604 -0
  108. adam/sql/qingl.lark +1076 -0
  109. adam/sso/cred_cache.py +2 -5
  110. adam/utils.py +216 -79
  111. adam/utils_k8s/app_clusters.py +11 -4
  112. adam/utils_k8s/app_pods.py +10 -5
  113. adam/utils_k8s/cassandra_clusters.py +8 -4
  114. adam/utils_k8s/cassandra_nodes.py +14 -5
  115. adam/utils_k8s/k8s.py +9 -0
  116. adam/utils_k8s/kube_context.py +1 -4
  117. adam/{pod_exec_result.py → utils_k8s/pod_exec_result.py} +8 -2
  118. adam/utils_k8s/pods.py +83 -24
  119. adam/utils_k8s/statefulsets.py +5 -2
  120. adam/utils_local.py +78 -2
  121. adam/utils_repl/appendable_completer.py +6 -0
  122. adam/utils_repl/repl_completer.py +51 -4
  123. adam/utils_sqlite.py +3 -8
  124. adam/version.py +1 -1
  125. {kaqing-2.0.184.dist-info → kaqing-2.0.214.dist-info}/METADATA +1 -1
  126. kaqing-2.0.214.dist-info/RECORD +272 -0
  127. kaqing-2.0.214.dist-info/top_level.txt +2 -0
  128. teddy/__init__.py +0 -0
  129. teddy/lark_parser.py +436 -0
  130. teddy/lark_parser2.py +618 -0
  131. adam/commands/cql/cql_completions.py +0 -32
  132. adam/commands/export/export_select_x.py +0 -54
  133. adam/commands/logs.py +0 -37
  134. adam/commands/postgres/psql_completions.py +0 -11
  135. adam/commands/report.py +0 -61
  136. adam/commands/restart.py +0 -60
  137. adam/commands/show/show_processes.py +0 -49
  138. kaqing-2.0.184.dist-info/RECORD +0 -244
  139. kaqing-2.0.184.dist-info/top_level.txt +0 -1
  140. /adam/commands/{login.py → app/login.py} +0 -0
  141. /adam/commands/{show → cassandra}/__init__.py +0 -0
  142. /adam/commands/{show → cassandra}/show_cassandra_version.py +0 -0
  143. /adam/commands/{watch.py → cassandra/watch.py} +0 -0
  144. /adam/commands/{param_get.py → config/param_get.py} +0 -0
  145. /adam/commands/{param_set.py → config/param_set.py} +0 -0
  146. /adam/commands/{issues.py → diag/issues.py} +0 -0
  147. /adam/commands/{pwd.py → fs/pwd.py} +0 -0
  148. /adam/commands/{shell.py → fs/shell.py} +0 -0
  149. /adam/commands/{show → fs}/show_host.py +0 -0
  150. /adam/commands/{nodetool_commands.py → nodetool/nodetool_commands.py} +0 -0
  151. {kaqing-2.0.184.dist-info → kaqing-2.0.214.dist-info}/WHEEL +0 -0
  152. {kaqing-2.0.184.dist-info → kaqing-2.0.214.dist-info}/entry_points.txt +0 -0
adam/app_session.py CHANGED
@@ -8,7 +8,7 @@ from adam.log import Log
8
8
  from adam.sso.idp import Idp
9
9
  from adam.sso.idp_login import IdpLogin
10
10
  from adam.config import Config
11
- from adam.utils import debug, debug_trace, json_to_csv, tabulize, log, log2, log_exc
11
+ from adam.utils import debug, debug_trace, json_to_csv, tabulize, log2, log_exc
12
12
  from adam.apps import Apps
13
13
 
14
14
  class AppLogin:
adam/batch.py CHANGED
@@ -2,28 +2,28 @@ import click
2
2
 
3
3
  from adam.commands.audit.audit import Audit, AuditCommandHelper
4
4
  from adam.commands.bash.bash import Bash
5
- from adam.commands.check import Check, CheckCommandHelper
6
- from adam.commands.clipboard_copy import ClipboardCopy, CopyCommandHelper
5
+ from adam.commands.cassandra.restart_nodes import RestartNodes
6
+ from adam.commands.cassandra.rollout import RollOut
7
+ from adam.commands.cassandra.watch import Watch
8
+ from adam.commands.cli.clipboard_copy import ClipboardCopy, CopyCommandHelper
7
9
  from adam.commands.command import Command
8
10
  from adam.commands.command_helpers import ClusterCommandHelper, ClusterOrPodCommandHelper, PodCommandHelper
9
11
  from adam.commands.cql.cqlsh import CqlCommandHelper, Cqlsh
10
12
  from adam.commands.deploy.deploy import Deploy, DeployCommandHelper
11
13
  from adam.commands.deploy.undeploy import Undeploy, UndeployCommandHelper
12
- from adam.commands.issues import Issues
13
- from adam.commands.login import Login
14
- from adam.commands.logs import Logs
15
- from adam.commands.ls import Ls
14
+ from adam.commands.app.login import Login
15
+ from adam.commands.cassandra.download_cassandra_log import DownloadCassandraLog
16
+ from adam.commands.diag.check import Check, CheckCommandHelper
17
+ from adam.commands.diag.generate_report import GenerateReport
18
+ from adam.commands.diag.issues import Issues
19
+ from adam.commands.fs.ls import Ls
16
20
  from adam.commands.medusa.medusa import Medusa
17
- from adam.commands.nodetool import NodeTool, NodeToolCommandHelper
21
+ from adam.commands.nodetool.nodetool import NodeTool, NodeToolCommandHelper
18
22
  from adam.commands.postgres.postgres import Postgres, PostgresCommandHelper
19
23
  from adam.commands.preview_table import PreviewTable
20
24
  from adam.commands.reaper.reaper import Reaper, ReaperCommandHelper
21
25
  from adam.commands.repair.repair import Repair, RepairCommandHelper
22
- from adam.commands.report import Report
23
- from adam.commands.restart import Restart
24
- from adam.commands.rollout import RollOut
25
- from adam.commands.show.show import Show, ShowCommandHelper
26
- from adam.commands.watch import Watch
26
+ from adam.commands.show import Show, ShowCommandHelper
27
27
  from adam.utils_k8s.kube_context import KubeContext
28
28
  from adam.repl import enter_repl
29
29
  from adam.repl_state import ReplState
@@ -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.')
adam/commands/app/app.py CHANGED
@@ -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,5 +1,5 @@
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
@@ -5,7 +5,7 @@ from adam.sso.idp import Idp
5
5
  from adam.sso.idp_login import IdpLogin
6
6
  from adam.commands.command import Command
7
7
  from adam.repl_state import ReplState
8
- from adam.utils import duration, tabulize, log, log2, log_exc
8
+ from adam.utils import duration, tabulize, log2, log_exc
9
9
 
10
10
  class ShowLogin(Command):
11
11
  COMMAND = 'show login'
@@ -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,6 +1,7 @@
1
1
  import click
2
2
 
3
3
  from adam.commands import validate_args
4
+ from adam.commands.audit.completions_l import completions_l
4
5
  from adam.commands.audit.audit_repair_tables import AuditRepairTables
5
6
  from adam.commands.audit.audit_run import AuditRun
6
7
  from adam.commands.audit.show_last10 import ShowLast10
@@ -10,7 +11,7 @@ from adam.commands.audit.utils_show_top10 import show_top10_completions_for_nest
10
11
  from adam.commands.command import Command
11
12
  from adam.commands.intermediate_command import IntermediateCommand
12
13
  from adam.repl_state import ReplState
13
- from adam.sql.sql_completer import SqlCompleter, SqlVariant
14
+ from adam.sql.lark_completer import LarkCompleter
14
15
  from adam.utils import log2, wait_log
15
16
  from adam.utils_athena import Athena
16
17
 
@@ -50,25 +51,10 @@ class Audit(IntermediateCommand):
50
51
  return state
51
52
 
52
53
  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 {}
54
+ if state.device != ReplState.L:
55
+ return {}
56
+
57
+ return completions_l()
72
58
 
73
59
  def cmd_list(self):
74
60
  return [AuditRepairTables(), AuditRun(), ShowLast10(), ShowSlow10(), ShowTop10()]
@@ -46,7 +46,7 @@ class AuditRepairTables(Command):
46
46
  with Audits.offload() as exec:
47
47
  exec.submit(lambda: self.auto_repair(hours))
48
48
 
49
- return super().completion(state)
49
+ # return super().completion(state)
50
50
 
51
51
  return {}
52
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()
@@ -30,7 +30,6 @@ class ShowLast10(Command):
30
30
  return state
31
31
 
32
32
  def completion(self, _: ReplState):
33
-
34
33
  return {}
35
34
 
36
35
  def help(self, _: ReplState):
@@ -30,7 +30,7 @@ class Bash(Command):
30
30
  return exec(args)
31
31
 
32
32
  def completion(self, state: ReplState):
33
- return Devices.device(state).bash_completion(Bash.COMMAND, state, default = {})
33
+ return super().completion(state, {c : {'&': None} for c in ['ls', 'cat', 'head']}, pods=Devices.of(state).pods(state, '-'))
34
34
 
35
35
  def help(self, _: ReplState):
36
36
  return f'{Bash.COMMAND} [pod-name] [bash-commands] [&]\t run bash on the Cassandra nodes'
@@ -13,4 +13,4 @@ class BashHandler:
13
13
  return False
14
14
 
15
15
  def exec(self, args: list[str]):
16
- return Devices.device(self.s1).bash(self.s0, self.s1, args)
16
+ return Devices.of(self.s1).bash(self.s0, self.s1, args)
@@ -0,0 +1,45 @@
1
+ from adam.commands.command import Command
2
+ from adam.commands.devices.devices import Devices
3
+ from adam.config import Config
4
+ from adam.utils_k8s.pod_exec_result import PodExecResult
5
+ from adam.utils import log2
6
+ from adam.utils_k8s.cassandra_nodes import CassandraNodes
7
+ from adam.repl_state import ReplState, RequiredState
8
+ from adam.utils_k8s.pods import Pods
9
+
10
+ class DownloadCassandraLog(Command):
11
+ COMMAND = 'download cassandra log'
12
+
13
+ # the singleton pattern
14
+ def __new__(cls, *args, **kwargs):
15
+ if not hasattr(cls, 'instance'): cls.instance = super(DownloadCassandraLog, cls).__new__(cls)
16
+
17
+ return cls.instance
18
+
19
+ def __init__(self, successor: Command=None):
20
+ super().__init__(successor)
21
+
22
+ def command(self):
23
+ return DownloadCassandraLog.COMMAND
24
+
25
+ def required(self):
26
+ return RequiredState.POD
27
+
28
+ def run(self, cmd: str, state: ReplState):
29
+ if not(args := self.args(cmd)):
30
+ return super().run(cmd, state)
31
+
32
+ with self.validate(args, state) as (args, state):
33
+ path = Config().get('logs.path', '/c3/cassandra/logs/system.log')
34
+ r: PodExecResult = CassandraNodes.exec(state.pod, state.namespace, f'cat {path}', backgrounded=True, history=False)
35
+
36
+ to_file = Pods.download_file(state.pod, 'cassandra', state.namespace, path)
37
+ log2(f'Downloaded to {to_file}.')
38
+
39
+ return r
40
+
41
+ def completion(self, state: ReplState):
42
+ return super().completion(state, pods=Devices.of(state).pods(state, '-'), auto='jit')
43
+
44
+ def help(self, _: ReplState):
45
+ return f'{DownloadCassandraLog.COMMAND}\t download cassandra system log'
@@ -0,0 +1,47 @@
1
+ from adam.commands import extract_options
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 RestartCluster(Command):
9
+ COMMAND = 'restart cluster'
10
+
11
+ # the singleton pattern
12
+ def __new__(cls, *args, **kwargs):
13
+ if not hasattr(cls, 'instance'): cls.instance = super(RestartCluster, 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 RestartCluster.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) as (args, state):
31
+ with extract_options(args, '--force') as (args, forced):
32
+ if not forced:
33
+ log2('Please add --force for restarting all nodes in a cluster.')
34
+
35
+ return 'force-needed'
36
+
37
+ log2(f'Restarting all pods from {state.sts}...')
38
+ for pod_name in StatefulSets.pod_names(state.sts, state.namespace):
39
+ Pods.delete(pod_name, state.namespace)
40
+
41
+ return state
42
+
43
+ def completion(self, state: ReplState):
44
+ return super().completion(state, {'--force': None})
45
+
46
+ def help(self, _: ReplState):
47
+ return f"{RestartCluster.COMMAND} --force\t restart all the nodes in the cluster"
@@ -0,0 +1,51 @@
1
+ from adam.commands import extract_options
2
+ from adam.commands.command import Command
3
+ from adam.commands.devices.devices import Devices
4
+ from adam.utils_k8s.pods import Pods
5
+ from adam.repl_state import ReplState, RequiredState
6
+ from adam.utils import log2
7
+
8
+ class RestartNode(Command):
9
+ COMMAND = 'restart node'
10
+
11
+ # the singleton pattern
12
+ def __new__(cls, *args, **kwargs):
13
+ if not hasattr(cls, 'instance'): cls.instance = super(RestartNode, 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 RestartNode.COMMAND
22
+
23
+ def required(self):
24
+ return RequiredState.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
+ if not state.pod:
32
+ log2("'pod' is required")
33
+
34
+ return 'pod-needed'
35
+
36
+ with extract_options(args, '--force') as (args, forced):
37
+ if not forced:
38
+ log2('Please add --force for restarting pod.')
39
+
40
+ return 'force-needed'
41
+
42
+ log2(f'Restarting {state.pod}...')
43
+ Pods.delete(state.pod, state.namespace)
44
+
45
+ return state
46
+
47
+ def completion(self, state: ReplState):
48
+ return super().completion(state, {'--force': None}, pods=Devices.of(state).pods(state, '-'))
49
+
50
+ def help(self, _: ReplState):
51
+ return f"{RestartNode.COMMAND} --force\t restart the node"
@@ -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, _: ReplState):
47
+ return f"{RestartNodes.COMMAND} <pod-name>... --force\t restart Cassandra nodes"
@@ -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
@@ -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
36
  def help(self, _: ReplState):
35
37
  return f'{ShowCassandraRepairs.COMMAND}\t show Cassandra repairs'
@@ -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
116
  def help(self, _: ReplState):
110
117
  return f'{ShowCassandraStatus.COMMAND} [-s]\t show merged nodetool status -s show commands on nodes'
@@ -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', '=', 'qing']) 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-qing.columns', 'pod,cpu,mem')
37
+ header = Config().get('processes-qing.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', 'qing']
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, _: ReplState):
50
+ return f'{ShowProcesses.COMMAND} [with recipe qing|metrics] [-s]\t show process overview -s show commands on nodes'
@@ -1,8 +1,9 @@
1
- from adam.commands import extract_options
1
+ from adam.commands import extract_options, extract_trailing_options
2
2
  from adam.commands.command import Command
3
3
  from adam.commands.cql.utils_cql import cassandra
4
4
  from adam.config import Config
5
5
  from adam.repl_state import ReplState, RequiredState
6
+ from adam.utils import ing
6
7
 
7
8
  class ShowStorage(Command):
8
9
  COMMAND = 'show storage'
@@ -27,16 +28,17 @@ class ShowStorage(Command):
27
28
  return super().run(cmd, state)
28
29
 
29
30
  with self.validate(args, state) as (args, state):
30
- with extract_options(args, ['-s', '--show']) as (args, show_out):
31
- cols = Config().get('storage.columns', 'pod,volume_root,volume_cassandra,snapshots,data,compactions')
32
- header = Config().get('storage.header', 'POD_NAME,VOLUME /,VOLUME CASS,SNAPSHOTS,DATA,COMPACTIONS')
33
- with cassandra(state) as pods:
34
- pods.display_table(cols, header, show_out=show_out)
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')
35
37
 
36
- return state
38
+ return state
37
39
 
38
40
  def completion(self, state: ReplState):
39
- return super().completion(state, {'-s': None})
41
+ return super().completion(state, {'-s': {'&': None}, '&': None})
40
42
 
41
43
  def help(self, _: ReplState):
42
44
  return f'{ShowStorage.COMMAND} [-s]\t show storage overview -s show commands on nodes'
File without changes