kaqing 2.0.186__py3-none-any.whl → 2.0.200__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.
- adam/app_session.py +1 -1
- adam/batch.py +6 -6
- 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 +2 -2
- adam/commands/cd.py +2 -2
- adam/commands/command.py +1 -1
- adam/commands/commands_utils.py +8 -13
- adam/commands/cql/alter_tables.py +66 -0
- adam/commands/cql/completions_c.py +1 -0
- adam/commands/cql/utils_cql.py +5 -5
- 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/devices/devices.py +1 -1
- adam/commands/download_cassandra_log.py +45 -0
- adam/commands/download_file.py +3 -3
- adam/commands/export/export_sessions.py +1 -1
- adam/commands/export/exporter.py +1 -1
- adam/commands/find_processes.py +2 -2
- adam/commands/generate_report.py +52 -0
- adam/commands/head.py +2 -2
- adam/commands/ls.py +2 -2
- adam/commands/medusa/medusa_restore.py +0 -16
- adam/commands/nodetool.py +1 -1
- 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/postgres/postgres_databases.py +2 -3
- adam/commands/preview_table.py +1 -1
- adam/commands/restart_cluster.py +47 -0
- adam/commands/restart_node.py +51 -0
- adam/commands/restart_nodes.py +47 -0
- adam/commands/show/show_cli_commands.py +1 -1
- adam/config.py +4 -6
- adam/embedded_params.py +1 -1
- adam/repl.py +5 -3
- adam/repl_commands.py +11 -6
- adam/repl_session.py +4 -3
- adam/repl_state.py +6 -0
- adam/sql/async_executor.py +44 -0
- adam/sql/lark_completer.py +15 -9
- adam/sql/qingl.lark +1076 -0
- adam/utils.py +95 -23
- adam/utils_k8s/app_clusters.py +1 -1
- adam/utils_k8s/app_pods.py +2 -3
- adam/utils_k8s/cassandra_clusters.py +7 -3
- adam/utils_k8s/cassandra_nodes.py +8 -5
- adam/utils_k8s/kube_context.py +1 -4
- adam/utils_k8s/pods.py +55 -1
- adam/utils_repl/repl_completer.py +4 -87
- adam/version.py +1 -1
- {kaqing-2.0.186.dist-info → kaqing-2.0.200.dist-info}/METADATA +1 -1
- {kaqing-2.0.186.dist-info → kaqing-2.0.200.dist-info}/RECORD +73 -46
- kaqing-2.0.200.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/logs.py +0 -37
- adam/commands/report.py +0 -61
- adam/commands/restart.py +0 -60
- kaqing-2.0.186.dist-info/top_level.txt +0 -1
- {kaqing-2.0.186.dist-info → kaqing-2.0.200.dist-info}/WHEEL +0 -0
- {kaqing-2.0.186.dist-info → kaqing-2.0.200.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,
|
|
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
|
@@ -11,7 +11,7 @@ from adam.commands.deploy.deploy import Deploy, DeployCommandHelper
|
|
|
11
11
|
from adam.commands.deploy.undeploy import Undeploy, UndeployCommandHelper
|
|
12
12
|
from adam.commands.issues import Issues
|
|
13
13
|
from adam.commands.login import Login
|
|
14
|
-
from adam.commands.
|
|
14
|
+
from adam.commands.download_cassandra_log import DownloadCassandraLog
|
|
15
15
|
from adam.commands.ls import Ls
|
|
16
16
|
from adam.commands.medusa.medusa import Medusa
|
|
17
17
|
from adam.commands.nodetool import NodeTool, NodeToolCommandHelper
|
|
@@ -19,8 +19,8 @@ from adam.commands.postgres.postgres import Postgres, PostgresCommandHelper
|
|
|
19
19
|
from adam.commands.preview_table import PreviewTable
|
|
20
20
|
from adam.commands.reaper.reaper import Reaper, ReaperCommandHelper
|
|
21
21
|
from adam.commands.repair.repair import Repair, RepairCommandHelper
|
|
22
|
-
from adam.commands.
|
|
23
|
-
from adam.commands.
|
|
22
|
+
from adam.commands.generate_report import GenerateReport
|
|
23
|
+
from adam.commands.restart_nodes import RestartNodes
|
|
24
24
|
from adam.commands.rollout import RollOut
|
|
25
25
|
from adam.commands.show.show import Show, ShowCommandHelper
|
|
26
26
|
from adam.commands.watch import Watch
|
|
@@ -128,7 +128,7 @@ def login(kubeconfig: str, config: str, param: list[str], namespace: str, pod: s
|
|
|
128
128
|
@click.option('--pod', '-p', required=False, metavar='pod', help='Kubernetes pod name')
|
|
129
129
|
@click.argument('extra_args', nargs=-1, metavar='<pod>', type=click.UNPROCESSED)
|
|
130
130
|
def logs(kubeconfig: str, config: str, param: list[str], namespace: str, pod: str, extra_args):
|
|
131
|
-
run_command(
|
|
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(
|
|
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(
|
|
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/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 super().completion(state, {c : {'&': None} for c in ['ls', 'cat', 'head']}, pods=Devices.
|
|
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.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
|
@@ -27,10 +27,10 @@ class Cat(Command):
|
|
|
27
27
|
|
|
28
28
|
with self.validate(args, state) as (args, state):
|
|
29
29
|
with validate_args(args, state, name='file'):
|
|
30
|
-
return Devices.
|
|
30
|
+
return Devices.of(state).bash(state, state, cmd.split(' '))
|
|
31
31
|
|
|
32
32
|
def completion(self, state: ReplState):
|
|
33
|
-
return super().completion(state, lambda: {f: None for f in Devices.
|
|
33
|
+
return super().completion(state, lambda: {f: None for f in Devices.of(state).files(state)}, pods=Devices.of(state).pods(state, '-'), auto='jit')
|
|
34
34
|
|
|
35
35
|
def help(self, _: ReplState):
|
|
36
36
|
return f'{Cat.COMMAND} file [&]\t run cat command on the pod'
|
adam/commands/cd.py
CHANGED
|
@@ -28,14 +28,14 @@ class Cd(Command):
|
|
|
28
28
|
|
|
29
29
|
with self.validate(args, state, apply=False) as (args, state):
|
|
30
30
|
with validate_args(args, state, name='directory') as arg_str:
|
|
31
|
-
device: Device = Devices.
|
|
31
|
+
device: Device = Devices.of(state)
|
|
32
32
|
for dir in arg_str.split('/'):
|
|
33
33
|
device.cd(dir, state)
|
|
34
34
|
|
|
35
35
|
return state
|
|
36
36
|
|
|
37
37
|
def completion(self, state: ReplState):
|
|
38
|
-
return Devices.
|
|
38
|
+
return Devices.of(state).cd_completion(Cd.COMMAND, state, default = {})
|
|
39
39
|
|
|
40
40
|
def help(self, _: ReplState):
|
|
41
41
|
return f'{Cd.COMMAND} <path> | .. \t move around on the operational device hierarchy'
|
adam/commands/command.py
CHANGED
|
@@ -44,7 +44,7 @@ class Command:
|
|
|
44
44
|
if pod:
|
|
45
45
|
c |= self._completion(state, leaf, auto=auto, auto_key=auto_key)
|
|
46
46
|
|
|
47
|
-
c |= {f'@{p}': self._completion(state, leaf, to_validate=False, auto=auto, auto_key=auto_key) for p in pod_names if p != pod}
|
|
47
|
+
c |= {f'@{p}': self._completion(state.with_pod(p), leaf, to_validate=False, auto=auto, auto_key=auto_key) for p in pod_names if p != pod}
|
|
48
48
|
|
|
49
49
|
return c
|
|
50
50
|
|
adam/commands/commands_utils.py
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
from datetime import datetime
|
|
2
1
|
from kubernetes import client
|
|
3
2
|
from typing import List
|
|
4
3
|
|
|
5
4
|
from adam.checks.check_utils import run_checks
|
|
6
5
|
from adam.columns.columns import Columns, collect_checks
|
|
7
|
-
from adam.config import Config
|
|
8
|
-
from adam.repl_session import ReplSession
|
|
9
6
|
from adam.utils_issues import IssuesUtils
|
|
10
7
|
from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
11
8
|
from adam.utils_k8s.pods import Pods
|
|
12
9
|
from adam.utils_k8s.statefulsets import StatefulSets
|
|
13
10
|
from adam.repl_state import ReplState
|
|
14
|
-
from adam.utils import SORT, duration,
|
|
11
|
+
from adam.utils import SORT, duration, kaqing_log_file, tabulize, log2
|
|
15
12
|
|
|
16
13
|
def show_pods(pods: List[client.V1Pod], ns: str, show_namespace = True, show_host_id = True):
|
|
17
14
|
if len(pods) == 0:
|
|
@@ -70,16 +67,14 @@ def show_table(state: ReplState, pods: list[str], cols: str, header: str, show_o
|
|
|
70
67
|
r = tabulize(pods, lambda p: ','.join([c.pod_value(results, p) for c in columns]), header=header, separator=',', sorted=SORT, to = 0 if backgrounded else 1)
|
|
71
68
|
|
|
72
69
|
if backgrounded:
|
|
73
|
-
|
|
74
|
-
log_file = f'{log_prefix}-{datetime.now().strftime("%d%H%M%S")}.log'
|
|
70
|
+
r = write_to_kaqing_log_file(r)
|
|
75
71
|
|
|
76
|
-
|
|
77
|
-
f.write(r)
|
|
78
|
-
|
|
79
|
-
ReplSession().append_history(f':sh cat {log_file}')
|
|
72
|
+
IssuesUtils.show(results, state.in_repl)
|
|
80
73
|
|
|
81
|
-
|
|
74
|
+
return r
|
|
82
75
|
|
|
83
|
-
|
|
76
|
+
def write_to_kaqing_log_file(r: str):
|
|
77
|
+
with kaqing_log_file() as f:
|
|
78
|
+
f.write(r)
|
|
84
79
|
|
|
85
|
-
|
|
80
|
+
return f.name
|