kaqing 2.0.98__py3-none-any.whl → 2.0.203__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.
- adam/__init__.py +0 -2
- adam/app_session.py +9 -12
- adam/apps.py +18 -4
- adam/batch.py +11 -25
- adam/checks/check_utils.py +16 -46
- adam/checks/cpu.py +7 -1
- adam/checks/cpu_metrics.py +52 -0
- adam/checks/disk.py +2 -3
- adam/columns/columns.py +3 -1
- adam/columns/cpu.py +3 -1
- adam/columns/cpu_metrics.py +22 -0
- adam/columns/memory.py +3 -4
- adam/commands/__init__.py +24 -0
- adam/commands/alter_tables.py +37 -63
- adam/commands/app/app.py +38 -0
- adam/commands/{app_ping.py → app/app_ping.py} +8 -14
- adam/commands/app/show_app_actions.py +49 -0
- adam/commands/{show → app}/show_app_id.py +8 -11
- adam/commands/{show → app}/show_app_queues.py +8 -14
- adam/commands/app/utils_app.py +106 -0
- adam/commands/audit/audit.py +31 -35
- adam/commands/audit/audit_repair_tables.py +26 -48
- adam/commands/audit/audit_run.py +50 -0
- adam/commands/audit/completions_l.py +15 -0
- adam/commands/audit/show_last10.py +36 -0
- adam/commands/audit/show_slow10.py +36 -0
- adam/commands/audit/show_top10.py +36 -0
- adam/commands/audit/utils_show_top10.py +71 -0
- adam/commands/bash/__init__.py +5 -0
- adam/commands/bash/bash.py +36 -0
- adam/commands/bash/bash_completer.py +93 -0
- adam/commands/bash/utils_bash.py +16 -0
- adam/commands/cassandra/__init__.py +0 -0
- adam/commands/cassandra/download_cassandra_log.py +45 -0
- adam/commands/cassandra/nodetool.py +64 -0
- adam/commands/cassandra/nodetool_commands.py +120 -0
- adam/commands/{restart.py → cassandra/restart_cluster.py} +12 -26
- adam/commands/cassandra/restart_node.py +51 -0
- adam/commands/cassandra/restart_nodes.py +47 -0
- adam/commands/cassandra/rollout.py +88 -0
- adam/commands/cat.py +36 -0
- adam/commands/cd.py +14 -92
- adam/commands/check.py +18 -21
- adam/commands/cli_commands.py +8 -4
- adam/commands/clipboard_copy.py +87 -0
- adam/commands/code.py +57 -0
- adam/commands/command.py +212 -39
- adam/commands/commands_utils.py +20 -28
- adam/commands/cql/alter_tables.py +66 -0
- adam/commands/cql/completions_c.py +29 -0
- adam/commands/cql/cqlsh.py +10 -29
- adam/commands/cql/utils_cql.py +305 -0
- adam/commands/debug/__init__.py +0 -0
- adam/commands/debug/debug.py +22 -0
- adam/commands/debug/debug_completes.py +35 -0
- adam/commands/debug/debug_timings.py +35 -0
- adam/commands/deploy/code_start.py +7 -10
- adam/commands/deploy/code_stop.py +4 -21
- adam/commands/deploy/code_utils.py +3 -3
- adam/commands/deploy/deploy.py +4 -21
- adam/commands/deploy/deploy_frontend.py +14 -17
- adam/commands/deploy/deploy_pg_agent.py +3 -6
- adam/commands/deploy/deploy_pod.py +65 -73
- adam/commands/deploy/deploy_utils.py +14 -24
- adam/commands/deploy/undeploy.py +4 -21
- adam/commands/deploy/undeploy_frontend.py +4 -7
- adam/commands/deploy/undeploy_pg_agent.py +6 -8
- adam/commands/deploy/undeploy_pod.py +11 -12
- adam/commands/devices/__init__.py +0 -0
- adam/commands/devices/device.py +149 -0
- adam/commands/devices/device_app.py +163 -0
- adam/commands/devices/device_auit_log.py +49 -0
- adam/commands/devices/device_cass.py +179 -0
- adam/commands/devices/device_export.py +87 -0
- adam/commands/devices/device_postgres.py +160 -0
- adam/commands/devices/devices.py +25 -0
- adam/commands/download_cassandra_log.py +45 -0
- adam/commands/download_file.py +47 -0
- adam/commands/exit.py +1 -4
- adam/commands/export/__init__.py +0 -0
- adam/commands/export/clean_up_all_export_sessions.py +37 -0
- adam/commands/export/clean_up_export_sessions.py +39 -0
- adam/commands/export/completions_x.py +11 -0
- adam/commands/export/download_export_session.py +40 -0
- adam/commands/export/drop_export_database.py +39 -0
- adam/commands/export/drop_export_databases.py +37 -0
- adam/commands/export/export.py +37 -0
- adam/commands/export/export_databases.py +247 -0
- adam/commands/export/export_select.py +34 -0
- adam/commands/export/export_sessions.py +211 -0
- adam/commands/export/export_use.py +49 -0
- adam/commands/export/export_x_select.py +48 -0
- adam/commands/export/exporter.py +361 -0
- adam/commands/export/import_files.py +44 -0
- adam/commands/export/import_session.py +44 -0
- adam/commands/export/importer.py +82 -0
- adam/commands/export/importer_athena.py +150 -0
- adam/commands/export/importer_sqlite.py +69 -0
- adam/commands/export/show_column_counts.py +45 -0
- adam/commands/export/show_export_databases.py +39 -0
- adam/commands/export/show_export_session.py +39 -0
- adam/commands/export/show_export_sessions.py +37 -0
- adam/commands/export/utils_export.py +366 -0
- adam/commands/find_files.py +51 -0
- adam/commands/find_processes.py +76 -0
- adam/commands/generate_report.py +52 -0
- adam/commands/head.py +36 -0
- adam/commands/help.py +12 -8
- adam/commands/intermediate_command.py +52 -0
- adam/commands/issues.py +14 -40
- adam/commands/kubectl.py +38 -0
- adam/commands/login.py +26 -25
- adam/commands/ls.py +11 -116
- adam/commands/medusa/medusa.py +4 -22
- adam/commands/medusa/medusa_backup.py +20 -27
- adam/commands/medusa/medusa_restore.py +35 -48
- adam/commands/medusa/medusa_show_backupjobs.py +17 -18
- adam/commands/medusa/medusa_show_restorejobs.py +13 -18
- adam/commands/medusa/utils_medusa.py +15 -0
- adam/commands/nodetool.py +8 -19
- adam/commands/os/__init__.py +0 -0
- adam/commands/os/cat.py +36 -0
- adam/commands/os/download_file.py +47 -0
- adam/commands/os/find_files.py +51 -0
- adam/commands/os/find_processes.py +76 -0
- adam/commands/os/head.py +36 -0
- adam/commands/os/shell.py +41 -0
- adam/commands/param_get.py +11 -14
- adam/commands/param_set.py +8 -12
- adam/commands/postgres/completions_p.py +22 -0
- adam/commands/postgres/postgres.py +47 -55
- adam/commands/postgres/postgres_databases.py +269 -0
- adam/commands/postgres/postgres_ls.py +4 -8
- adam/commands/postgres/postgres_preview.py +5 -9
- adam/commands/postgres/utils_postgres.py +79 -0
- adam/commands/preview_table.py +10 -61
- adam/commands/pwd.py +14 -46
- adam/commands/reaper/reaper.py +4 -24
- adam/commands/reaper/reaper_forward.py +49 -56
- adam/commands/reaper/reaper_forward_session.py +6 -0
- adam/commands/reaper/reaper_forward_stop.py +10 -16
- adam/commands/reaper/reaper_restart.py +7 -14
- adam/commands/reaper/reaper_run_abort.py +8 -33
- adam/commands/reaper/reaper_runs.py +43 -58
- adam/commands/reaper/reaper_runs_abort.py +29 -49
- adam/commands/reaper/reaper_schedule_activate.py +14 -33
- adam/commands/reaper/reaper_schedule_start.py +9 -33
- adam/commands/reaper/reaper_schedule_stop.py +9 -33
- adam/commands/reaper/reaper_schedules.py +4 -14
- adam/commands/reaper/reaper_status.py +8 -16
- adam/commands/reaper/utils_reaper.py +203 -0
- adam/commands/repair/repair.py +4 -22
- adam/commands/repair/repair_log.py +5 -11
- adam/commands/repair/repair_run.py +27 -34
- adam/commands/repair/repair_scan.py +32 -40
- adam/commands/repair/repair_stop.py +5 -12
- adam/commands/restart_cluster.py +47 -0
- adam/commands/restart_node.py +51 -0
- adam/commands/restart_nodes.py +47 -0
- adam/commands/rollout.py +19 -24
- adam/commands/shell.py +12 -4
- adam/commands/show/show.py +10 -23
- adam/commands/show/show_adam.py +3 -3
- adam/commands/show/show_cassandra_repairs.py +37 -0
- adam/commands/show/show_cassandra_status.py +47 -51
- adam/commands/show/show_cassandra_version.py +5 -18
- adam/commands/show/show_cli_commands.py +56 -0
- adam/commands/show/show_host.py +1 -1
- adam/commands/show/show_login.py +23 -27
- adam/commands/show/show_params.py +2 -5
- adam/commands/show/show_processes.py +18 -21
- adam/commands/show/show_storage.py +11 -20
- adam/commands/watch.py +26 -29
- adam/config.py +5 -15
- adam/embedded_params.py +1 -1
- adam/log.py +4 -4
- adam/repl.py +105 -133
- adam/repl_commands.py +68 -28
- adam/repl_session.py +9 -1
- adam/repl_state.py +300 -62
- adam/sql/async_executor.py +44 -0
- adam/sql/lark_completer.py +286 -0
- adam/sql/lark_parser.py +604 -0
- adam/sql/qingl.lark +1076 -0
- adam/sql/sql_completer.py +104 -64
- adam/sql/sql_state_machine.py +630 -0
- adam/sql/term_completer.py +3 -0
- adam/sso/authn_ad.py +6 -8
- adam/sso/authn_okta.py +4 -6
- adam/sso/cred_cache.py +3 -5
- adam/sso/idp.py +9 -12
- adam/utils.py +640 -10
- adam/utils_athena.py +140 -87
- adam/utils_audits.py +102 -0
- adam/utils_issues.py +32 -0
- adam/utils_k8s/app_clusters.py +28 -0
- adam/utils_k8s/app_pods.py +35 -0
- adam/utils_k8s/cassandra_clusters.py +34 -21
- adam/utils_k8s/cassandra_nodes.py +9 -6
- adam/utils_k8s/custom_resources.py +16 -17
- adam/utils_k8s/ingresses.py +2 -2
- adam/utils_k8s/jobs.py +7 -11
- adam/utils_k8s/k8s.py +96 -0
- adam/utils_k8s/kube_context.py +3 -6
- adam/{pod_exec_result.py → utils_k8s/pod_exec_result.py} +11 -5
- adam/utils_k8s/pods.py +146 -75
- adam/utils_k8s/secrets.py +4 -4
- adam/utils_k8s/service_accounts.py +5 -4
- adam/utils_k8s/services.py +2 -2
- adam/utils_k8s/statefulsets.py +6 -14
- adam/utils_local.py +42 -0
- adam/utils_net.py +4 -4
- adam/utils_repl/__init__.py +0 -0
- adam/utils_repl/appendable_completer.py +6 -0
- adam/utils_repl/automata_completer.py +48 -0
- adam/utils_repl/repl_completer.py +89 -0
- adam/utils_repl/state_machine.py +173 -0
- adam/utils_sqlite.py +137 -0
- adam/version.py +1 -1
- {kaqing-2.0.98.dist-info → kaqing-2.0.203.dist-info}/METADATA +1 -1
- kaqing-2.0.203.dist-info/RECORD +277 -0
- kaqing-2.0.203.dist-info/top_level.txt +2 -0
- teddy/__init__.py +0 -0
- teddy/lark_parser.py +436 -0
- teddy/lark_parser2.py +618 -0
- adam/commands/app.py +0 -67
- adam/commands/bash.py +0 -92
- adam/commands/cp.py +0 -95
- adam/commands/cql/cql_completions.py +0 -11
- adam/commands/cql/cql_table_completer.py +0 -8
- adam/commands/cql/cql_utils.py +0 -115
- adam/commands/describe/describe.py +0 -47
- adam/commands/describe/describe_keyspace.py +0 -60
- adam/commands/describe/describe_keyspaces.py +0 -49
- adam/commands/describe/describe_schema.py +0 -49
- adam/commands/describe/describe_table.py +0 -60
- adam/commands/describe/describe_tables.py +0 -49
- adam/commands/devices.py +0 -118
- adam/commands/logs.py +0 -39
- adam/commands/postgres/postgres_session.py +0 -240
- adam/commands/postgres/postgres_utils.py +0 -31
- adam/commands/postgres/psql_completions.py +0 -10
- adam/commands/postgres/psql_table_completer.py +0 -11
- adam/commands/reaper/reaper_session.py +0 -159
- adam/commands/report.py +0 -57
- adam/commands/show/show_app_actions.py +0 -53
- adam/commands/show/show_commands.py +0 -61
- adam/commands/show/show_repairs.py +0 -47
- adam/sql/state_machine.py +0 -460
- kaqing-2.0.98.dist-info/RECORD +0 -191
- kaqing-2.0.98.dist-info/top_level.txt +0 -1
- /adam/commands/{describe → app}/__init__.py +0 -0
- {kaqing-2.0.98.dist-info → kaqing-2.0.203.dist-info}/WHEEL +0 -0
- {kaqing-2.0.98.dist-info → kaqing-2.0.203.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from adam.commands.audit.utils_show_top10 import run_configured_query
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.repl_state import ReplState
|
|
4
|
+
|
|
5
|
+
class ShowTop10(Command):
|
|
6
|
+
COMMAND = 'show top'
|
|
7
|
+
|
|
8
|
+
# the singleton pattern
|
|
9
|
+
def __new__(cls, *args, **kwargs):
|
|
10
|
+
if not hasattr(cls, 'instance'): cls.instance = super(ShowTop10, cls).__new__(cls)
|
|
11
|
+
|
|
12
|
+
return cls.instance
|
|
13
|
+
|
|
14
|
+
def __init__(self, successor: Command=None):
|
|
15
|
+
super().__init__(successor)
|
|
16
|
+
|
|
17
|
+
def command(self):
|
|
18
|
+
return ShowTop10.COMMAND
|
|
19
|
+
|
|
20
|
+
def required(self):
|
|
21
|
+
return ReplState.L
|
|
22
|
+
|
|
23
|
+
def run(self, cmd: str, state: ReplState):
|
|
24
|
+
if not(args := self.args(cmd)):
|
|
25
|
+
return super().run(cmd, state)
|
|
26
|
+
|
|
27
|
+
with self.validate(args, state) as (args, state):
|
|
28
|
+
run_configured_query('audit.queries.top10', args)
|
|
29
|
+
|
|
30
|
+
return state
|
|
31
|
+
|
|
32
|
+
def completion(self, _: ReplState):
|
|
33
|
+
return {}
|
|
34
|
+
|
|
35
|
+
def help(self, _: ReplState):
|
|
36
|
+
return f'{ShowTop10.COMMAND} [limit]\t show top <limit> audit lines'
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from datetime import datetime, timedelta
|
|
2
|
+
|
|
3
|
+
from adam.config import Config
|
|
4
|
+
from adam.utils import log2, log_exc
|
|
5
|
+
from adam.utils_athena import Athena
|
|
6
|
+
from adam.utils_audits import Audits
|
|
7
|
+
from adam.utils_repl.automata_completer import AutomataCompleter
|
|
8
|
+
from adam.utils_repl.state_machine import StateMachine
|
|
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
|
+
|
|
21
|
+
def extract_limit_and_duration(args: list[str]) -> tuple[int, datetime]:
|
|
22
|
+
limit = 10
|
|
23
|
+
_from = datetime.now() - timedelta(days=30)
|
|
24
|
+
if args:
|
|
25
|
+
with log_exc():
|
|
26
|
+
limit = int(args[0])
|
|
27
|
+
|
|
28
|
+
if len(args) > 2 and args[1] == 'over':
|
|
29
|
+
if args[2] == 'day':
|
|
30
|
+
_from = datetime.now() - timedelta(days=1)
|
|
31
|
+
|
|
32
|
+
return (limit, Audits.date_from(_from))
|
|
33
|
+
|
|
34
|
+
def limit_and_duration_completion():
|
|
35
|
+
return {'10': {'over': {
|
|
36
|
+
'day': None,
|
|
37
|
+
'month': None
|
|
38
|
+
}}}
|
|
39
|
+
|
|
40
|
+
SHOW_TOP10_SPEC = [
|
|
41
|
+
' > show > show',
|
|
42
|
+
'show > last|slow|top > show_top ^ last,slow,top',
|
|
43
|
+
'show_top > word > show_top_n ^ 10',
|
|
44
|
+
'show_top_n > over > show_top_n_over ^ over',
|
|
45
|
+
'show_top_n_over > day|month > show_top_n_over$ ^ day,month',
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
SHOW_TOP10_KEYWORDS = [
|
|
49
|
+
'show',
|
|
50
|
+
'top',
|
|
51
|
+
'last',
|
|
52
|
+
'slow',
|
|
53
|
+
'over',
|
|
54
|
+
'day',
|
|
55
|
+
'month'
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
class ShowTop10StateMachine(StateMachine[str]):
|
|
59
|
+
def spec(self) -> str:
|
|
60
|
+
return SHOW_TOP10_SPEC
|
|
61
|
+
|
|
62
|
+
def keywords(self) -> list[str]:
|
|
63
|
+
return SHOW_TOP10_KEYWORDS
|
|
64
|
+
|
|
65
|
+
def show_top10_completions_for_nesting():
|
|
66
|
+
return {
|
|
67
|
+
'show': {
|
|
68
|
+
'last': AutomataCompleter(ShowTop10StateMachine(), first_term='show last'),
|
|
69
|
+
'slow': AutomataCompleter(ShowTop10StateMachine(), first_term='show slow'),
|
|
70
|
+
'top': AutomataCompleter(ShowTop10StateMachine(), first_term='show top'),
|
|
71
|
+
}}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from adam.commands.bash import bash
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.commands.devices.devices import Devices
|
|
4
|
+
from adam.repl_state import ReplState, RequiredState
|
|
5
|
+
|
|
6
|
+
class Bash(Command):
|
|
7
|
+
COMMAND = 'bash'
|
|
8
|
+
|
|
9
|
+
# the singleton pattern
|
|
10
|
+
def __new__(cls, *args, **kwargs):
|
|
11
|
+
if not hasattr(cls, 'instance'): cls.instance = super(Bash, cls).__new__(cls)
|
|
12
|
+
|
|
13
|
+
return cls.instance
|
|
14
|
+
|
|
15
|
+
def __init__(self, successor: Command=None):
|
|
16
|
+
super().__init__(successor)
|
|
17
|
+
|
|
18
|
+
def command(self):
|
|
19
|
+
return Bash.COMMAND
|
|
20
|
+
|
|
21
|
+
def required(self):
|
|
22
|
+
return [RequiredState.CLUSTER_OR_POD, RequiredState.APP_APP, ReplState.P]
|
|
23
|
+
|
|
24
|
+
def run(self, cmd: str, s0: ReplState):
|
|
25
|
+
if not(args := self.args(cmd)):
|
|
26
|
+
return super().run(cmd, s0)
|
|
27
|
+
|
|
28
|
+
with self.validate(args, s0) as (args, s1):
|
|
29
|
+
with bash(s0, s1) as exec:
|
|
30
|
+
return exec(args)
|
|
31
|
+
|
|
32
|
+
def completion(self, state: ReplState):
|
|
33
|
+
return super().completion(state, {c : {'&': None} for c in ['ls', 'cat', 'head']}, pods=Devices.of(state).pods(state, '-'))
|
|
34
|
+
|
|
35
|
+
def help(self, _: ReplState):
|
|
36
|
+
return f'{Bash.COMMAND} [pod-name] [bash-commands] [&]\t run bash on the Cassandra nodes'
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
from typing import Callable
|
|
2
|
+
from prompt_toolkit.completion import WordCompleter
|
|
3
|
+
|
|
4
|
+
from adam.utils_repl.automata_completer import AutomataCompleter
|
|
5
|
+
from adam.utils_repl.state_machine import State, StateMachine
|
|
6
|
+
|
|
7
|
+
BASH_SPEC = [
|
|
8
|
+
# <command> ::= <simple_command> | <pipeline> | <conditional_command>
|
|
9
|
+
# <simple_command> ::= <word> <argument>* <redirection>*
|
|
10
|
+
# <pipeline> ::= <command> '|' <command>
|
|
11
|
+
# <conditional_command> ::= <command> '&&' <command> | <command> '||' <command>
|
|
12
|
+
# <word> ::= <letter> <letter_or_digit>*
|
|
13
|
+
# <argument> ::= <word>
|
|
14
|
+
# <redirection> ::= '>' <filename> | '<' <filename>
|
|
15
|
+
# <filename> ::= <word>
|
|
16
|
+
# <letter> ::= 'a' | 'b' | ... | 'z' | 'A' | 'B' | ... | 'Z'
|
|
17
|
+
# <digit> ::= '0' | '1' | ... | '9'
|
|
18
|
+
# <letter_or_digit> ::= <letter> | <digit>
|
|
19
|
+
|
|
20
|
+
' > word > cmd ^ hosts',
|
|
21
|
+
'cmd > word > cmd ^ |,>,2>,<,&,&&,||',
|
|
22
|
+
'- > pipe > cmd_pipe',
|
|
23
|
+
'- > _rdr0_ > cmd_rdr0',
|
|
24
|
+
'- > _rdr1_ > cmd_rdr1',
|
|
25
|
+
'- > _rdr2_ > cmd_rdr2',
|
|
26
|
+
'- > & > cmd_bg ^ |,>,2>,<,&,&&,||',
|
|
27
|
+
'- > &&|_or_ > nocmd',
|
|
28
|
+
'cmd_a > word > cmd',
|
|
29
|
+
'cmd_pipe > word > cmd',
|
|
30
|
+
'cmd_rdr0 > word > cmd_rdr0_f',
|
|
31
|
+
'cmd_rdr1 > word > cmd_rdr1_f',
|
|
32
|
+
'cmd_rdr2 > word > cmd_rdr2_f',
|
|
33
|
+
'cmd_rdr1_f > pipe > cmd_pipe ^ |,2>,<,&,&&,||',
|
|
34
|
+
'- > _rdr2_ > cmd_rdr2',
|
|
35
|
+
'- > _rdr0_ > cmd_rdr0',
|
|
36
|
+
'cmd_rdr2_f > pipe > cmd_pipe ^ |,<,&,&&,||',
|
|
37
|
+
'- > _rdr0_ > cmd_rdr0',
|
|
38
|
+
'- > & > cmd_bg ^ |,>,2>,<,&,&&,||',
|
|
39
|
+
'- > &&|_or_ > nocmd',
|
|
40
|
+
'cmd_rdr0_f > pipe > cmd_pipe ^ |,&,&&,||',
|
|
41
|
+
'- > & > cmd_bg ^ |,>,2>,<,&,&&,||',
|
|
42
|
+
'- > &&|_or_ > cmd',
|
|
43
|
+
'cmd_bg > &&|_or_ > nocmd ^ &&,||',
|
|
44
|
+
'nocmd > word > cmd',
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
BASH_KEYWORDS = [
|
|
48
|
+
'&',
|
|
49
|
+
'&&',
|
|
50
|
+
'|',
|
|
51
|
+
'||',
|
|
52
|
+
'>',
|
|
53
|
+
'2>',
|
|
54
|
+
'>>',
|
|
55
|
+
'<',
|
|
56
|
+
'hosts'
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
class BashStateMachine(StateMachine[str]):
|
|
60
|
+
def spec(self) -> str:
|
|
61
|
+
return BASH_SPEC
|
|
62
|
+
|
|
63
|
+
def keywords(self) -> list[str]:
|
|
64
|
+
return BASH_KEYWORDS
|
|
65
|
+
|
|
66
|
+
class BashCompleter(AutomataCompleter[str]):
|
|
67
|
+
def __init__(self,
|
|
68
|
+
hosts: Callable[[], list[str]],
|
|
69
|
+
debug = False):
|
|
70
|
+
super().__init__(BashStateMachine(debug=debug), '', debug=debug)
|
|
71
|
+
|
|
72
|
+
self.hosts = hosts
|
|
73
|
+
self.debug = debug
|
|
74
|
+
|
|
75
|
+
def suggestions_completer(self, state: State, suggestions: str) -> list[str]:
|
|
76
|
+
if not suggestions:
|
|
77
|
+
return None
|
|
78
|
+
|
|
79
|
+
terms = []
|
|
80
|
+
for suggestion in suggestions.split(','):
|
|
81
|
+
terms.extend(self._terms(state, suggestion))
|
|
82
|
+
|
|
83
|
+
return WordCompleter(terms)
|
|
84
|
+
|
|
85
|
+
def _terms(self, _: State, word: str) -> list[str]:
|
|
86
|
+
terms = []
|
|
87
|
+
|
|
88
|
+
if word == 'hosts':
|
|
89
|
+
terms.extend(self.hosts())
|
|
90
|
+
else:
|
|
91
|
+
terms.append(word)
|
|
92
|
+
|
|
93
|
+
return terms
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from adam.commands.devices.devices import Devices
|
|
2
|
+
from adam.repl_state import ReplState
|
|
3
|
+
|
|
4
|
+
class BashHandler:
|
|
5
|
+
def __init__(self, s0: ReplState, s1: ReplState):
|
|
6
|
+
self.s0 = s0
|
|
7
|
+
self.s1 = s1
|
|
8
|
+
|
|
9
|
+
def __enter__(self):
|
|
10
|
+
return self.exec
|
|
11
|
+
|
|
12
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
13
|
+
return False
|
|
14
|
+
|
|
15
|
+
def exec(self, args: list[str]):
|
|
16
|
+
return Devices.of(self.s1).bash(self.s0, self.s1, args)
|
|
File without changes
|
|
@@ -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, no_history=True)
|
|
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,64 @@
|
|
|
1
|
+
import click
|
|
2
|
+
|
|
3
|
+
from adam.commands.command import Command
|
|
4
|
+
from adam.commands.command_helpers import ClusterOrPodCommandHelper
|
|
5
|
+
from adam.commands.cql.utils_cql import cassandra
|
|
6
|
+
from adam.commands.devices.devices import Devices
|
|
7
|
+
from adam.commands.cassandra.nodetool_commands import NODETOOL_COMMANDS
|
|
8
|
+
from adam.config import Config
|
|
9
|
+
from adam.repl_state import ReplState, RequiredState
|
|
10
|
+
from adam.utils import log
|
|
11
|
+
|
|
12
|
+
class NodeTool(Command):
|
|
13
|
+
COMMAND = 'nodetool'
|
|
14
|
+
|
|
15
|
+
# the singleton pattern
|
|
16
|
+
def __new__(cls, *args, **kwargs):
|
|
17
|
+
if not hasattr(cls, 'instance'): cls.instance = super(NodeTool, cls).__new__(cls)
|
|
18
|
+
|
|
19
|
+
return cls.instance
|
|
20
|
+
|
|
21
|
+
def __init__(self, successor: Command=None):
|
|
22
|
+
super().__init__(successor)
|
|
23
|
+
|
|
24
|
+
def command(self):
|
|
25
|
+
return NodeTool.COMMAND
|
|
26
|
+
|
|
27
|
+
def required(self):
|
|
28
|
+
return RequiredState.CLUSTER_OR_POD
|
|
29
|
+
|
|
30
|
+
def run(self, cmd: str, state: ReplState):
|
|
31
|
+
if not(args := self.args(cmd)):
|
|
32
|
+
return super().run(cmd, state)
|
|
33
|
+
|
|
34
|
+
with self.validate(args, state) as (args, state):
|
|
35
|
+
with cassandra(state) as pods:
|
|
36
|
+
pods.nodetool(' '.join(args), status=(args[0] == 'status'))
|
|
37
|
+
|
|
38
|
+
return state
|
|
39
|
+
|
|
40
|
+
def completion(self, state: ReplState):
|
|
41
|
+
return super().completion(state, {c: {'&': None} for c in NODETOOL_COMMANDS}, pods=Devices.of(state).pods(state, '-'))
|
|
42
|
+
|
|
43
|
+
def help(self, _: ReplState):
|
|
44
|
+
return f'{NodeTool.COMMAND} <sub-command> [&]\t run nodetool with arguments'
|
|
45
|
+
|
|
46
|
+
class NodeToolCommandHelper(click.Command):
|
|
47
|
+
def get_help(self, ctx: click.Context):
|
|
48
|
+
log(super().get_help(ctx))
|
|
49
|
+
log()
|
|
50
|
+
log('Sub-Commands:')
|
|
51
|
+
|
|
52
|
+
cmds = ''
|
|
53
|
+
for c in NODETOOL_COMMANDS:
|
|
54
|
+
if cmds:
|
|
55
|
+
cmds += ', '
|
|
56
|
+
cmds += c
|
|
57
|
+
if len(cmds) > Config().get('nodetool.commands_in_line', 40):
|
|
58
|
+
log(' ' + cmds)
|
|
59
|
+
cmds = ''
|
|
60
|
+
|
|
61
|
+
if len(cmds) > 0:
|
|
62
|
+
log(' ' + cmds)
|
|
63
|
+
log()
|
|
64
|
+
ClusterOrPodCommandHelper.cluter_or_pod_help()
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
NODETOOL_COMMANDS = [
|
|
2
|
+
'assassinate',
|
|
3
|
+
'bootstrap',
|
|
4
|
+
'cleanup',
|
|
5
|
+
'clearsnapshot',
|
|
6
|
+
'clientstats',
|
|
7
|
+
'compact',
|
|
8
|
+
'compactionhistory',
|
|
9
|
+
'compactionstats',
|
|
10
|
+
'decommission',
|
|
11
|
+
'describecluster',
|
|
12
|
+
'describering',
|
|
13
|
+
'disableauditlog',
|
|
14
|
+
'disableautocompaction',
|
|
15
|
+
'disablebackup',
|
|
16
|
+
'disablebinary',
|
|
17
|
+
'disablefullquerylog',
|
|
18
|
+
'disablegossip',
|
|
19
|
+
'disablehandoff',
|
|
20
|
+
'disablehintsfordc',
|
|
21
|
+
'disableoldprotocolversions',
|
|
22
|
+
'drain',
|
|
23
|
+
'enableauditlog',
|
|
24
|
+
'enableautocompaction',
|
|
25
|
+
'enablebackup',
|
|
26
|
+
'enablebinary',
|
|
27
|
+
'enablefullquerylog',
|
|
28
|
+
'enablegossip',
|
|
29
|
+
'enablehandoff',
|
|
30
|
+
'enablehintsfordc',
|
|
31
|
+
'enableoldprotocolversions',
|
|
32
|
+
'failuredetector',
|
|
33
|
+
'flush',
|
|
34
|
+
'garbagecollect',
|
|
35
|
+
'gcstats',
|
|
36
|
+
'getbatchlogreplaythrottle',
|
|
37
|
+
'getcompactionthreshold',
|
|
38
|
+
'getcompactionthroughput',
|
|
39
|
+
'getconcurrency',
|
|
40
|
+
'getconcurrentcompactors',
|
|
41
|
+
'getconcurrentviewbuilders',
|
|
42
|
+
'getendpoints',
|
|
43
|
+
'getfullquerylog',
|
|
44
|
+
'getinterdcstreamthroughput',
|
|
45
|
+
'getlogginglevels',
|
|
46
|
+
'getmaxhintwindow',
|
|
47
|
+
'getseeds',
|
|
48
|
+
'getsnapshotthrottle',
|
|
49
|
+
'getsstables',
|
|
50
|
+
'getstreamthroughput',
|
|
51
|
+
'gettimeout',
|
|
52
|
+
'gettraceprobability',
|
|
53
|
+
'gossipinfo',
|
|
54
|
+
'help',
|
|
55
|
+
'import',
|
|
56
|
+
'info',
|
|
57
|
+
'invalidatecountercache',
|
|
58
|
+
'invalidatekeycache',
|
|
59
|
+
'invalidaterowcache',
|
|
60
|
+
'join',
|
|
61
|
+
'listsnapshots',
|
|
62
|
+
'move',
|
|
63
|
+
'netstats',
|
|
64
|
+
'pausehandoff',
|
|
65
|
+
'profileload',
|
|
66
|
+
'proxyhistograms',
|
|
67
|
+
'rangekeysample',
|
|
68
|
+
'rebuild',
|
|
69
|
+
'rebuild_index',
|
|
70
|
+
'refresh',
|
|
71
|
+
'refreshsizeestimates',
|
|
72
|
+
'reloadlocalschema',
|
|
73
|
+
'reloadseeds',
|
|
74
|
+
'reloadssl',
|
|
75
|
+
'reloadtriggers',
|
|
76
|
+
'relocatesstables',
|
|
77
|
+
'removenode',
|
|
78
|
+
'repair',
|
|
79
|
+
'repair_admin',
|
|
80
|
+
'replaybatchlog',
|
|
81
|
+
'resetfullquerylog',
|
|
82
|
+
'resetlocalschema',
|
|
83
|
+
'resumehandoff',
|
|
84
|
+
'ring',
|
|
85
|
+
'scrub',
|
|
86
|
+
'setbatchlogreplaythrottle',
|
|
87
|
+
'setcachecapacity',
|
|
88
|
+
'setcachekeystosave',
|
|
89
|
+
'setcompactionthreshold',
|
|
90
|
+
'setcompactionthroughput',
|
|
91
|
+
'setconcurrency',
|
|
92
|
+
'setconcurrentcompactors',
|
|
93
|
+
'setconcurrentviewbuilders',
|
|
94
|
+
'sethintedhandoffthrottlekb',
|
|
95
|
+
'setinterdcstreamthroughput',
|
|
96
|
+
'setlogginglevel',
|
|
97
|
+
'setmaxhintwindow',
|
|
98
|
+
'setsnapshotthrottle',
|
|
99
|
+
'setstreamthroughput',
|
|
100
|
+
'settimeout',
|
|
101
|
+
'settraceprobability',
|
|
102
|
+
'sjk',
|
|
103
|
+
'snapshot',
|
|
104
|
+
'status',
|
|
105
|
+
'statusautocompaction',
|
|
106
|
+
'statusbackup',
|
|
107
|
+
'statusbinary',
|
|
108
|
+
'statusgossip',
|
|
109
|
+
'statushandoff',
|
|
110
|
+
'stop',
|
|
111
|
+
'stopdaemon',
|
|
112
|
+
'tablehistograms',
|
|
113
|
+
'tablestats',
|
|
114
|
+
'toppartitions',
|
|
115
|
+
'tpstats',
|
|
116
|
+
'truncatehints',
|
|
117
|
+
'upgradesstables',
|
|
118
|
+
'verify',
|
|
119
|
+
'version',
|
|
120
|
+
'viewbuildstatus']
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
from adam.commands import extract_options
|
|
1
2
|
from adam.commands.command import Command
|
|
2
3
|
from adam.utils_k8s.pods import Pods
|
|
3
4
|
from adam.utils_k8s.statefulsets import StatefulSets
|
|
4
5
|
from adam.repl_state import ReplState, RequiredState
|
|
5
6
|
from adam.utils import log2
|
|
6
7
|
|
|
7
|
-
class
|
|
8
|
-
COMMAND = 'restart'
|
|
8
|
+
class RestartCluster(Command):
|
|
9
|
+
COMMAND = 'restart cluster'
|
|
9
10
|
|
|
10
11
|
# the singleton pattern
|
|
11
12
|
def __new__(cls, *args, **kwargs):
|
|
12
|
-
if not hasattr(cls, 'instance'): cls.instance = super(
|
|
13
|
+
if not hasattr(cls, 'instance'): cls.instance = super(RestartCluster, cls).__new__(cls)
|
|
13
14
|
|
|
14
15
|
return cls.instance
|
|
15
16
|
|
|
@@ -17,45 +18,30 @@ class Restart(Command):
|
|
|
17
18
|
super().__init__(successor)
|
|
18
19
|
|
|
19
20
|
def command(self):
|
|
20
|
-
return
|
|
21
|
+
return RestartCluster.COMMAND
|
|
21
22
|
|
|
22
23
|
def required(self):
|
|
23
|
-
return RequiredState.
|
|
24
|
+
return RequiredState.CLUSTER
|
|
24
25
|
|
|
25
26
|
def run(self, cmd: str, state: ReplState):
|
|
26
27
|
if not(args := self.args(cmd)):
|
|
27
28
|
return super().run(cmd, state)
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return state
|
|
32
|
-
|
|
33
|
-
args, forced = Command.extract_options(args, '--force')
|
|
34
|
-
if not args:
|
|
35
|
-
if state.pod:
|
|
36
|
-
log2(f'Restarting {state.pod}...')
|
|
37
|
-
Pods.delete(state.pod, state.namespace)
|
|
38
|
-
else:
|
|
30
|
+
with self.validate(args, state) as (args, state):
|
|
31
|
+
with extract_options(args, '--force') as (args, forced):
|
|
39
32
|
if not forced:
|
|
40
33
|
log2('Please add --force for restarting all nodes in a cluster.')
|
|
34
|
+
|
|
41
35
|
return 'force-needed'
|
|
42
36
|
|
|
43
37
|
log2(f'Restarting all pods from {state.sts}...')
|
|
44
38
|
for pod_name in StatefulSets.pod_names(state.sts, state.namespace):
|
|
45
39
|
Pods.delete(pod_name, state.namespace)
|
|
46
|
-
else:
|
|
47
|
-
for arg in args:
|
|
48
|
-
Pods.delete(arg, state.namespace)
|
|
49
40
|
|
|
50
|
-
|
|
41
|
+
return state
|
|
51
42
|
|
|
52
43
|
def completion(self, state: ReplState):
|
|
53
|
-
|
|
54
|
-
return {Restart.COMMAND: None}
|
|
55
|
-
elif state.sts:
|
|
56
|
-
return {Restart.COMMAND: {p: None for p in StatefulSets.pod_names(state.sts, state.namespace)}}
|
|
57
|
-
|
|
58
|
-
return {}
|
|
44
|
+
return super().completion(state, {'--force': None})
|
|
59
45
|
|
|
60
46
|
def help(self, _: ReplState):
|
|
61
|
-
return f"{
|
|
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"
|