kaqing 2.0.171__py3-none-any.whl → 2.0.204__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- adam/app_session.py +5 -10
- adam/apps.py +18 -4
- adam/batch.py +7 -7
- adam/checks/check_utils.py +3 -1
- adam/checks/disk.py +2 -3
- adam/columns/memory.py +3 -4
- adam/commands/__init__.py +15 -6
- adam/commands/alter_tables.py +26 -41
- adam/commands/app/__init__.py +0 -0
- adam/commands/{app_cmd.py → app/app.py} +2 -2
- adam/commands/{show → app}/show_app_actions.py +7 -15
- adam/commands/{show → app}/show_app_queues.py +1 -4
- adam/{utils_app.py → commands/app/utils_app.py} +9 -1
- adam/commands/audit/audit.py +9 -26
- adam/commands/audit/audit_repair_tables.py +5 -7
- adam/commands/audit/audit_run.py +1 -1
- adam/commands/audit/completions_l.py +15 -0
- adam/commands/audit/show_last10.py +2 -14
- adam/commands/audit/show_slow10.py +2 -13
- adam/commands/audit/show_top10.py +2 -11
- adam/commands/audit/utils_show_top10.py +15 -3
- adam/commands/bash/bash.py +1 -1
- adam/commands/bash/utils_bash.py +1 -1
- 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/cassandra/restart_cluster.py +47 -0
- 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 +5 -19
- adam/commands/cd.py +7 -9
- adam/commands/check.py +10 -18
- adam/commands/cli_commands.py +6 -1
- adam/commands/{cp.py → clipboard_copy.py} +34 -36
- adam/commands/code.py +2 -2
- adam/commands/command.py +139 -22
- adam/commands/commands_utils.py +14 -12
- adam/commands/cql/alter_tables.py +66 -0
- adam/commands/cql/completions_c.py +29 -0
- adam/commands/cql/cqlsh.py +3 -7
- adam/commands/cql/utils_cql.py +23 -61
- 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/deploy_pg_agent.py +2 -2
- adam/commands/deploy/deploy_pod.py +2 -4
- adam/commands/deploy/undeploy_pg_agent.py +2 -2
- adam/commands/devices/device.py +40 -9
- adam/commands/devices/device_app.py +19 -29
- adam/commands/devices/device_auit_log.py +3 -3
- adam/commands/devices/device_cass.py +17 -23
- adam/commands/devices/device_export.py +12 -11
- adam/commands/devices/device_postgres.py +79 -63
- adam/commands/devices/devices.py +1 -1
- adam/commands/download_cassandra_log.py +45 -0
- adam/commands/download_file.py +47 -0
- adam/commands/export/clean_up_all_export_sessions.py +3 -3
- adam/commands/export/clean_up_export_sessions.py +7 -19
- adam/commands/export/completions_x.py +11 -0
- adam/commands/export/download_export_session.py +40 -0
- adam/commands/export/drop_export_database.py +6 -22
- adam/commands/export/drop_export_databases.py +3 -9
- adam/commands/export/export.py +1 -17
- adam/commands/export/export_databases.py +109 -32
- adam/commands/export/export_select.py +8 -55
- adam/commands/export/export_sessions.py +211 -0
- adam/commands/export/export_use.py +13 -16
- adam/commands/export/export_x_select.py +48 -0
- adam/commands/export/exporter.py +176 -167
- adam/commands/export/import_files.py +44 -0
- adam/commands/export/import_session.py +10 -6
- adam/commands/export/importer.py +24 -9
- adam/commands/export/importer_athena.py +114 -44
- adam/commands/export/importer_sqlite.py +45 -23
- adam/commands/export/show_column_counts.py +11 -20
- adam/commands/export/show_export_databases.py +5 -2
- adam/commands/export/show_export_session.py +6 -15
- adam/commands/export/show_export_sessions.py +4 -11
- adam/commands/export/utils_export.py +79 -27
- 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 +2 -2
- adam/commands/intermediate_command.py +6 -3
- adam/commands/login.py +3 -6
- adam/commands/ls.py +2 -2
- adam/commands/medusa/medusa_backup.py +13 -16
- adam/commands/medusa/medusa_restore.py +26 -37
- adam/commands/medusa/medusa_show_backupjobs.py +7 -7
- adam/commands/medusa/medusa_show_restorejobs.py +6 -6
- adam/commands/medusa/utils_medusa.py +15 -0
- adam/commands/nodetool.py +3 -8
- 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 +10 -12
- adam/commands/param_set.py +7 -10
- adam/commands/postgres/completions_p.py +22 -0
- adam/commands/postgres/postgres.py +25 -40
- adam/commands/postgres/postgres_databases.py +269 -0
- adam/commands/postgres/utils_postgres.py +33 -20
- adam/commands/preview_table.py +4 -2
- adam/commands/pwd.py +4 -6
- adam/commands/reaper/reaper_forward.py +2 -2
- adam/commands/reaper/reaper_run_abort.py +4 -10
- adam/commands/reaper/reaper_runs.py +3 -3
- adam/commands/reaper/reaper_schedule_activate.py +12 -12
- adam/commands/reaper/reaper_schedule_start.py +7 -12
- adam/commands/reaper/reaper_schedule_stop.py +7 -12
- adam/commands/reaper/utils_reaper.py +13 -6
- adam/commands/repair/repair_log.py +1 -4
- adam/commands/repair/repair_run.py +3 -8
- adam/commands/repair/repair_scan.py +1 -6
- adam/commands/repair/repair_stop.py +1 -5
- adam/commands/restart_cluster.py +47 -0
- adam/commands/restart_node.py +51 -0
- adam/commands/restart_nodes.py +47 -0
- adam/commands/shell.py +9 -2
- adam/commands/show/show.py +4 -4
- adam/commands/show/show_adam.py +3 -3
- adam/commands/show/show_cassandra_repairs.py +5 -6
- adam/commands/show/show_cassandra_status.py +29 -29
- adam/commands/show/show_cassandra_version.py +1 -4
- adam/commands/show/{show_commands.py → show_cli_commands.py} +3 -6
- adam/commands/show/show_login.py +3 -9
- adam/commands/show/show_params.py +2 -5
- adam/commands/show/show_processes.py +15 -16
- adam/commands/show/show_storage.py +9 -8
- adam/config.py +4 -5
- adam/embedded_params.py +1 -1
- adam/log.py +4 -4
- adam/repl.py +26 -18
- adam/repl_commands.py +32 -20
- adam/repl_session.py +9 -1
- adam/repl_state.py +39 -10
- 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 +4 -6
- adam/sql/sql_state_machine.py +25 -13
- adam/sso/authn_ad.py +2 -5
- adam/sso/authn_okta.py +2 -4
- adam/sso/cred_cache.py +2 -5
- adam/sso/idp.py +8 -11
- adam/utils.py +299 -105
- adam/utils_athena.py +18 -18
- adam/utils_audits.py +3 -7
- adam/utils_issues.py +2 -2
- adam/utils_k8s/app_clusters.py +4 -4
- adam/utils_k8s/app_pods.py +8 -6
- adam/utils_k8s/cassandra_clusters.py +16 -5
- adam/utils_k8s/cassandra_nodes.py +7 -6
- adam/utils_k8s/custom_resources.py +11 -17
- adam/utils_k8s/jobs.py +7 -11
- adam/utils_k8s/k8s.py +14 -5
- adam/utils_k8s/kube_context.py +3 -6
- adam/{pod_exec_result.py → utils_k8s/pod_exec_result.py} +4 -4
- adam/utils_k8s/pods.py +98 -36
- adam/utils_k8s/statefulsets.py +5 -2
- adam/utils_local.py +42 -0
- adam/utils_repl/appendable_completer.py +6 -0
- adam/utils_repl/repl_completer.py +45 -2
- adam/utils_repl/state_machine.py +3 -3
- adam/utils_sqlite.py +58 -30
- adam/version.py +1 -1
- {kaqing-2.0.171.dist-info → kaqing-2.0.204.dist-info}/METADATA +1 -1
- kaqing-2.0.204.dist-info/RECORD +277 -0
- kaqing-2.0.204.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/cql/cql_completions.py +0 -33
- adam/commands/export/export_handlers.py +0 -71
- adam/commands/export/export_select_x.py +0 -54
- adam/commands/logs.py +0 -37
- adam/commands/postgres/postgres_context.py +0 -274
- adam/commands/postgres/psql_completions.py +0 -10
- adam/commands/report.py +0 -61
- adam/commands/restart.py +0 -60
- kaqing-2.0.171.dist-info/RECORD +0 -236
- kaqing-2.0.171.dist-info/top_level.txt +0 -1
- /adam/commands/{app_ping.py → app/app_ping.py} +0 -0
- /adam/commands/{show → app}/show_app_id.py +0 -0
- {kaqing-2.0.171.dist-info → kaqing-2.0.204.dist-info}/WHEEL +0 -0
- {kaqing-2.0.171.dist-info → kaqing-2.0.204.dist-info}/entry_points.txt +0 -0
adam/commands/bash/bash.py
CHANGED
|
@@ -30,7 +30,7 @@ class Bash(Command):
|
|
|
30
30
|
return exec(args)
|
|
31
31
|
|
|
32
32
|
def completion(self, state: ReplState):
|
|
33
|
-
return
|
|
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'
|
adam/commands/bash/utils_bash.py
CHANGED
|
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']
|
|
@@ -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"
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
from kubernetes import client
|
|
3
|
+
from kubernetes.client.rest import ApiException
|
|
4
|
+
|
|
5
|
+
from adam.commands import extract_options
|
|
6
|
+
from adam.commands.command import Command
|
|
7
|
+
from adam.commands.watch import Watch
|
|
8
|
+
from adam.utils_k8s.statefulsets import StatefulSets
|
|
9
|
+
from adam.config import Config
|
|
10
|
+
from adam.repl_state import ReplState, RequiredState
|
|
11
|
+
from adam.utils import duration, log2
|
|
12
|
+
|
|
13
|
+
class RollOut(Command):
|
|
14
|
+
COMMAND = 'rollout'
|
|
15
|
+
|
|
16
|
+
# the singleton pattern
|
|
17
|
+
def __new__(cls, *args, **kwargs):
|
|
18
|
+
if not hasattr(cls, 'instance'): cls.instance = super(RollOut, cls).__new__(cls)
|
|
19
|
+
|
|
20
|
+
return cls.instance
|
|
21
|
+
|
|
22
|
+
def __init__(self, successor: Command=None):
|
|
23
|
+
super().__init__(successor)
|
|
24
|
+
|
|
25
|
+
def command(self):
|
|
26
|
+
return RollOut.COMMAND
|
|
27
|
+
|
|
28
|
+
def required(self):
|
|
29
|
+
return RequiredState.CLUSTER
|
|
30
|
+
|
|
31
|
+
def run(self, cmd: str, state: ReplState):
|
|
32
|
+
if not(args := self.args(cmd)):
|
|
33
|
+
return super().run(cmd, state)
|
|
34
|
+
|
|
35
|
+
with self.validate(args, state) as (args, state):
|
|
36
|
+
with extract_options(args, '--force') as (args, forced):
|
|
37
|
+
restarted, rollingout = StatefulSets.restarted_at(state.sts, state.namespace)
|
|
38
|
+
if rollingout and not forced:
|
|
39
|
+
log2(f"* Cluster is being rolled out for {duration(restarted)}. Please wait until it's done or use --force.")
|
|
40
|
+
|
|
41
|
+
return state
|
|
42
|
+
|
|
43
|
+
self.rolling_restart(state.sts, state.namespace)
|
|
44
|
+
|
|
45
|
+
auto_watch = False
|
|
46
|
+
if (auto_watch_cmds := Config().get('watch.auto', 'rollout')):
|
|
47
|
+
cmds = [c.strip(' ') for c in auto_watch_cmds.split(',')]
|
|
48
|
+
if self.command() in cmds:
|
|
49
|
+
auto_watch = True
|
|
50
|
+
log2('Rolling out cluster with auto watch...')
|
|
51
|
+
Watch().run('watch', state)
|
|
52
|
+
|
|
53
|
+
if not auto_watch:
|
|
54
|
+
log2('Rolling out cluster...')
|
|
55
|
+
|
|
56
|
+
return state
|
|
57
|
+
|
|
58
|
+
def rolling_restart(self, statefulset, namespace):
|
|
59
|
+
# kubectl rollout restart statefulset <statefulset-name>
|
|
60
|
+
v1_apps = client.AppsV1Api()
|
|
61
|
+
|
|
62
|
+
now = datetime.datetime.now(datetime.timezone.utc)
|
|
63
|
+
now = str(now.isoformat("T") + "Z")
|
|
64
|
+
body = {
|
|
65
|
+
'spec': {
|
|
66
|
+
'template':{
|
|
67
|
+
'metadata': {
|
|
68
|
+
'annotations': {
|
|
69
|
+
'kubectl.kubernetes.io/restartedAt': now
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
try:
|
|
77
|
+
v1_apps.patch_namespaced_stateful_set(statefulset, namespace, body, pretty='true')
|
|
78
|
+
except ApiException as e:
|
|
79
|
+
log2("Exception when calling AppsV1Api->read_namespaced_statefulset_status: %s\n" % e)
|
|
80
|
+
|
|
81
|
+
def completion(self, state: ReplState):
|
|
82
|
+
if super().completion(state):
|
|
83
|
+
return {RollOut.COMMAND: None}
|
|
84
|
+
|
|
85
|
+
return {}
|
|
86
|
+
|
|
87
|
+
def help(self, _: ReplState):
|
|
88
|
+
return f'{RollOut.COMMAND} [--force]\t rollout all nodes'
|
adam/commands/cat.py
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
from adam.commands import validate_args
|
|
1
2
|
from adam.commands.command import Command
|
|
2
3
|
from adam.commands.devices.devices import Devices
|
|
3
4
|
from adam.repl_state import ReplState, RequiredState
|
|
4
|
-
from adam.utils import log2
|
|
5
|
-
from adam.utils_k8s.app_pods import AppPods
|
|
6
|
-
from adam.utils_k8s.statefulsets import StatefulSets
|
|
7
5
|
|
|
8
6
|
class Cat(Command):
|
|
9
7
|
COMMAND = 'cat'
|
|
@@ -28,23 +26,11 @@ class Cat(Command):
|
|
|
28
26
|
return super().run(cmd, state)
|
|
29
27
|
|
|
30
28
|
with self.validate(args, state) as (args, state):
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
log2('File is required.')
|
|
34
|
-
log2()
|
|
35
|
-
else:
|
|
36
|
-
log2('* File is missing.')
|
|
37
|
-
Command.display_help()
|
|
38
|
-
|
|
39
|
-
return 'command-missing'
|
|
40
|
-
|
|
41
|
-
return Devices.device(state).cat(cmd, state)
|
|
29
|
+
with validate_args(args, state, name='file'):
|
|
30
|
+
return Devices.of(state).bash(state, state, cmd.split(' '))
|
|
42
31
|
|
|
43
32
|
def completion(self, state: ReplState):
|
|
44
|
-
|
|
45
|
-
return Devices.device(state).cat_completion(Cat.COMMAND, state, default={})
|
|
46
|
-
|
|
47
|
-
return {}
|
|
33
|
+
return super().completion(state, lambda: {f: None for f in Devices.of(state).files(state)}, pods=Devices.of(state).pods(state, '-'), auto='jit')
|
|
48
34
|
|
|
49
35
|
def help(self, _: ReplState):
|
|
50
|
-
return f'{Cat.COMMAND} file [&]\t run cat command on the
|
|
36
|
+
return f'{Cat.COMMAND} file [&]\t run cat command on the pod'
|
adam/commands/cd.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from adam.commands import validate_args
|
|
1
2
|
from adam.commands.command import Command
|
|
2
3
|
from adam.commands.devices.device import Device
|
|
3
4
|
from adam.commands.devices.devices import Devices
|
|
@@ -26,18 +27,15 @@ class Cd(Command):
|
|
|
26
27
|
return super().run(cmd, state)
|
|
27
28
|
|
|
28
29
|
with self.validate(args, state, apply=False) as (args, state):
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
arg = args[1]
|
|
34
|
-
for dir in arg.split('/'):
|
|
35
|
-
device.cd(dir, state)
|
|
30
|
+
with validate_args(args, state, name='directory') as arg_str:
|
|
31
|
+
device: Device = Devices.of(state)
|
|
32
|
+
for dir in arg_str.split('/'):
|
|
33
|
+
device.cd(dir, state)
|
|
36
34
|
|
|
37
|
-
|
|
35
|
+
return state
|
|
38
36
|
|
|
39
37
|
def completion(self, state: ReplState):
|
|
40
|
-
return Devices.
|
|
38
|
+
return Devices.of(state).cd_completion(Cd.COMMAND, state, default = {})
|
|
41
39
|
|
|
42
40
|
def help(self, _: ReplState):
|
|
43
41
|
return f'{Cd.COMMAND} <path> | .. \t move around on the operational device hierarchy'
|
adam/commands/check.py
CHANGED
|
@@ -2,12 +2,12 @@ import click
|
|
|
2
2
|
|
|
3
3
|
from adam.checks.check_result import CheckResult
|
|
4
4
|
from adam.checks.check_utils import all_checks, checks_from_csv, run_checks
|
|
5
|
-
from adam.commands import extract_options
|
|
5
|
+
from adam.commands import extract_options, validate_args
|
|
6
6
|
from adam.commands.command import Command
|
|
7
7
|
from adam.commands.command_helpers import ClusterOrPodCommandHelper
|
|
8
8
|
from adam.commands.issues import Issues
|
|
9
9
|
from adam.repl_state import ReplState
|
|
10
|
-
from adam.utils import
|
|
10
|
+
from adam.utils import tabulize, log
|
|
11
11
|
from adam.utils_issues import IssuesUtils
|
|
12
12
|
|
|
13
13
|
class Check(Issues):
|
|
@@ -34,25 +34,17 @@ class Check(Issues):
|
|
|
34
34
|
|
|
35
35
|
with self.validate(args, state) as (args, state):
|
|
36
36
|
with extract_options(args, ['-s', '--show']) as (args, show_out):
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
log('* Check name is missing.')
|
|
42
|
-
Command.display_help()
|
|
37
|
+
with validate_args(args, state, name='check name', msg=lambda: tabulize([check.help() for check in all_checks()], separator=':')) as arg:
|
|
38
|
+
checks = checks_from_csv(args[0])
|
|
39
|
+
if not checks:
|
|
40
|
+
return 'invalid check name'
|
|
43
41
|
|
|
44
|
-
|
|
42
|
+
results = run_checks(state.sts, state.namespace, state.pod, checks=checks, show_out=show_out)
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return 'invalid check name'
|
|
44
|
+
issues = CheckResult.collect_issues(results)
|
|
45
|
+
IssuesUtils.show_issues(issues, in_repl=state.in_repl)
|
|
49
46
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
issues = CheckResult.collect_issues(results)
|
|
53
|
-
IssuesUtils.show_issues(issues, in_repl=state.in_repl)
|
|
54
|
-
|
|
55
|
-
return issues if issues else 'no issues found'
|
|
47
|
+
return issues if issues else 'no issues found'
|
|
56
48
|
|
|
57
49
|
def completion(self, _: ReplState):
|
|
58
50
|
return {Check.COMMAND: {check.name(): {'-s': None} for check in all_checks()}}
|
adam/commands/cli_commands.py
CHANGED
|
@@ -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
|
|