kaqing 2.0.188__py3-none-any.whl → 2.0.211__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/batch.py +7 -7
- adam/commands/app/utils_app.py +1 -1
- adam/commands/bash/bash.py +1 -1
- adam/commands/bash/utils_bash.py +1 -1
- adam/commands/cassandra/__init__.py +0 -0
- adam/commands/command.py +1 -1
- adam/commands/commands_utils.py +8 -13
- adam/commands/{alter_tables.py → cql/alter_tables.py} +1 -1
- adam/commands/cql/completions_c.py +1 -0
- adam/commands/cql/utils_cql.py +14 -13
- 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/device.py +1 -1
- adam/commands/devices/devices.py +1 -1
- adam/commands/download_cassandra_log.py +45 -0
- adam/commands/export/export_databases.py +13 -8
- adam/commands/export/export_sessions.py +12 -11
- adam/commands/export/exporter.py +140 -53
- adam/commands/export/import_session.py +0 -4
- adam/commands/export/importer.py +11 -11
- adam/commands/export/importer_athena.py +15 -6
- adam/commands/export/importer_sqlite.py +19 -8
- adam/commands/export/utils_export.py +37 -15
- adam/commands/generate_report.py +52 -0
- adam/commands/medusa/medusa_restore.py +0 -16
- adam/commands/nodetool.py +1 -1
- adam/commands/os/__init__.py +0 -0
- adam/commands/postgres/postgres_databases.py +2 -3
- adam/commands/postgres/postgres_ls.py +1 -1
- adam/commands/postgres/utils_postgres.py +2 -1
- 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_cassandra_status.py +3 -10
- adam/commands/show/show_cli_commands.py +1 -1
- adam/commands/show/show_processes.py +1 -1
- adam/commands/show/show_storage.py +2 -1
- adam/config.py +4 -6
- adam/embedded_params.py +1 -1
- adam/repl.py +5 -3
- adam/repl_commands.py +23 -17
- adam/repl_session.py +4 -3
- adam/repl_state.py +6 -0
- adam/sql/async_executor.py +44 -0
- adam/sql/lark_completer.py +6 -4
- adam/sql/qingl.lark +1076 -0
- adam/sso/cred_cache.py +2 -5
- adam/utils.py +206 -83
- adam/utils_k8s/app_clusters.py +11 -4
- adam/utils_k8s/app_pods.py +10 -5
- adam/utils_k8s/cassandra_clusters.py +8 -4
- adam/utils_k8s/cassandra_nodes.py +14 -5
- adam/utils_k8s/kube_context.py +1 -4
- adam/{pod_exec_result.py → utils_k8s/pod_exec_result.py} +8 -2
- adam/utils_k8s/pods.py +83 -24
- adam/utils_local.py +78 -2
- adam/utils_repl/repl_completer.py +10 -89
- adam/utils_sqlite.py +3 -8
- adam/version.py +1 -1
- {kaqing-2.0.188.dist-info → kaqing-2.0.211.dist-info}/METADATA +1 -1
- {kaqing-2.0.188.dist-info → kaqing-2.0.211.dist-info}/RECORD +67 -65
- adam/commands/cat.py +0 -36
- adam/commands/cd.py +0 -41
- adam/commands/download_file.py +0 -47
- adam/commands/find_files.py +0 -51
- adam/commands/find_processes.py +0 -76
- adam/commands/head.py +0 -36
- adam/commands/logs.py +0 -37
- adam/commands/ls.py +0 -41
- adam/commands/report.py +0 -61
- adam/commands/restart.py +0 -60
- adam/commands/shell.py +0 -41
- {kaqing-2.0.188.dist-info → kaqing-2.0.211.dist-info}/WHEEL +0 -0
- {kaqing-2.0.188.dist-info → kaqing-2.0.211.dist-info}/entry_points.txt +0 -0
- {kaqing-2.0.188.dist-info → kaqing-2.0.211.dist-info}/top_level.txt +0 -0
adam/batch.py
CHANGED
|
@@ -11,16 +11,16 @@ 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.
|
|
15
|
-
from adam.commands.ls import Ls
|
|
14
|
+
from adam.commands.download_cassandra_log import DownloadCassandraLog
|
|
15
|
+
from adam.commands.fs.ls import Ls
|
|
16
16
|
from adam.commands.medusa.medusa import Medusa
|
|
17
17
|
from adam.commands.nodetool import NodeTool, NodeToolCommandHelper
|
|
18
18
|
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/app/utils_app.py
CHANGED
|
@@ -3,7 +3,7 @@ from typing import Union
|
|
|
3
3
|
|
|
4
4
|
from adam.app_session import AppSession
|
|
5
5
|
from adam.apps import Apps
|
|
6
|
-
from adam.pod_exec_result import PodExecResult
|
|
6
|
+
from adam.utils_k8s.pod_exec_result import PodExecResult
|
|
7
7
|
from adam.repl_state import ReplState
|
|
8
8
|
from adam.utils import log2
|
|
9
9
|
from adam.utils_k8s.app_clusters import AppClusters
|
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
|
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
|
|
@@ -59,7 +59,7 @@ class AlterTables(Command):
|
|
|
59
59
|
return state
|
|
60
60
|
|
|
61
61
|
def completion(self, _: ReplState) -> dict[str, any]:
|
|
62
|
-
# auto completion is taken care of by
|
|
62
|
+
# auto completion is taken care of by lark completer
|
|
63
63
|
return {}
|
|
64
64
|
|
|
65
65
|
def help(self, _: ReplState) -> str:
|
|
@@ -18,6 +18,7 @@ def completions_c(state: ReplState) -> dict[str, any]:
|
|
|
18
18
|
'table-props': lambda x: {
|
|
19
19
|
'GC_GRACE_SECONDS': ps
|
|
20
20
|
},
|
|
21
|
+
'table-props-value': lambda x: {None: None, 'GC_GRACE_SECONDS': ps}[x],
|
|
21
22
|
'export-database-types': lambda x: ['athena', 'sqlite', 'csv'],
|
|
22
23
|
'export-databases': lambda x: ExportDatabases.database_names(),
|
|
23
24
|
'export-sessions': lambda x: ExportSessions.export_session_names(state.sts, state.pod, state.namespace),
|
adam/commands/cql/utils_cql.py
CHANGED
|
@@ -7,9 +7,9 @@ from adam.commands.commands_utils import show_table
|
|
|
7
7
|
from adam.utils_k8s.cassandra_clusters import CassandraClusters
|
|
8
8
|
from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
9
9
|
from adam.utils_k8s.secrets import Secrets
|
|
10
|
-
from adam.pod_exec_result import PodExecResult
|
|
10
|
+
from adam.utils_k8s.pod_exec_result import PodExecResult
|
|
11
11
|
from adam.repl_state import ReplState
|
|
12
|
-
from adam.utils import log2, log_timing, wait_log
|
|
12
|
+
from adam.utils import ing, log2, log_timing, wait_log
|
|
13
13
|
from adam.utils_k8s.statefulsets import StatefulSets
|
|
14
14
|
|
|
15
15
|
def cd_dirs(state: ReplState) -> list[str]:
|
|
@@ -55,7 +55,7 @@ def table_spec(state: ReplState, table: str, on_any=False) -> 'TableSpec':
|
|
|
55
55
|
|
|
56
56
|
return parse_cql_desc_table(r.stdout if state.pod else r[0].stdout)
|
|
57
57
|
|
|
58
|
-
def run_cql(state: ReplState, cql: str, opts: list = [], show_out = False, show_query = False, use_single_quotes = False, on_any = False, backgrounded=False, log_file=None) -> list[PodExecResult]:
|
|
58
|
+
def run_cql(state: ReplState, cql: str, opts: list = [], show_out = False, show_query = False, use_single_quotes = False, on_any = False, backgrounded=False, log_file=None, history=True) -> list[PodExecResult]:
|
|
59
59
|
if show_query:
|
|
60
60
|
log2(cql)
|
|
61
61
|
|
|
@@ -69,7 +69,7 @@ def run_cql(state: ReplState, cql: str, opts: list = [], show_out = False, show_
|
|
|
69
69
|
|
|
70
70
|
with log_timing(cql):
|
|
71
71
|
with cassandra(state) as pods:
|
|
72
|
-
return pods.exec(command, action='cql', show_out=show_out, on_any=on_any, backgrounded=backgrounded, log_file=log_file)
|
|
72
|
+
return pods.exec(command, action='cql', show_out=show_out, on_any=on_any, backgrounded=backgrounded, log_file=log_file, history=history)
|
|
73
73
|
|
|
74
74
|
def parse_cql_desc_tables(out: str):
|
|
75
75
|
# Keyspace data_endpoint_auth
|
|
@@ -227,16 +227,16 @@ class CassandraPodService:
|
|
|
227
227
|
def __init__(self, handler: 'CassandraExecHandler'):
|
|
228
228
|
self.handler = handler
|
|
229
229
|
|
|
230
|
-
def exec(self, command: str, action='bash', show_out = True, on_any = False, throw_err = False, shell = '/bin/sh', backgrounded = False, log_file = None) -> Union[PodExecResult, list[PodExecResult]]:
|
|
230
|
+
def exec(self, command: str, action='bash', show_out = True, on_any = False, throw_err = False, shell = '/bin/sh', backgrounded = False, log_file = None, history=True) -> Union[PodExecResult, list[PodExecResult]]:
|
|
231
231
|
state = self.handler.state
|
|
232
232
|
pod = self.handler.pod
|
|
233
233
|
|
|
234
234
|
if pod:
|
|
235
235
|
return CassandraNodes.exec(pod, state.namespace, command,
|
|
236
|
-
show_out=show_out, throw_err=throw_err, shell=shell, backgrounded=backgrounded, log_file=log_file)
|
|
236
|
+
show_out=show_out, throw_err=throw_err, shell=shell, backgrounded=backgrounded, log_file=log_file, history=history)
|
|
237
237
|
elif state.sts:
|
|
238
238
|
return CassandraClusters.exec(state.sts, state.namespace, command, action=action,
|
|
239
|
-
show_out=show_out, on_any=on_any, shell=shell, backgrounded=backgrounded, log_file=log_file)
|
|
239
|
+
show_out=show_out, on_any=on_any, shell=shell, backgrounded=backgrounded, log_file=log_file, history=history)
|
|
240
240
|
|
|
241
241
|
return []
|
|
242
242
|
|
|
@@ -267,14 +267,15 @@ class CassandraPodService:
|
|
|
267
267
|
|
|
268
268
|
return run_cql(state, query, opts=opts, show_out=show_out, show_query=show_query, use_single_quotes=use_single_quotes, on_any=on_any, backgrounded=backgrounded, log_file=log_file)
|
|
269
269
|
|
|
270
|
-
def display_table(self, cols: str, header: str, show_out = True, backgrounded = False):
|
|
270
|
+
def display_table(self, cols: str, header: str, show_out = True, backgrounded = False, msg: str = None):
|
|
271
271
|
state = self.handler.state
|
|
272
272
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
273
|
+
with ing(msg=msg, condition=backgrounded and msg):
|
|
274
|
+
if state.pod:
|
|
275
|
+
return show_table(state, [state.pod], cols, header, show_out=show_out, backgrounded = backgrounded)
|
|
276
|
+
elif state.sts:
|
|
277
|
+
pod_names = [pod.metadata.name for pod in StatefulSets.pods(state.sts, state.namespace)]
|
|
278
|
+
return show_table(state, pod_names, cols, header, show_out=show_out, backgrounded = backgrounded)
|
|
278
279
|
|
|
279
280
|
def nodetool(self, args: str, status = False, show_out = True, backgrounded = False) -> Union[PodExecResult, list[PodExecResult]]:
|
|
280
281
|
state = self.handler.state
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.debug.debug_completes import DebugCompletes
|
|
3
|
+
from adam.commands.debug.debug_timings import DebugTimings
|
|
4
|
+
from adam.commands.intermediate_command import IntermediateCommand
|
|
5
|
+
|
|
6
|
+
class Debug(IntermediateCommand):
|
|
7
|
+
COMMAND = 'debug'
|
|
8
|
+
|
|
9
|
+
# the singleton pattern
|
|
10
|
+
def __new__(cls, *args, **kwargs):
|
|
11
|
+
if not hasattr(cls, 'instance'): cls.instance = super(Debug, 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 Debug.COMMAND
|
|
20
|
+
|
|
21
|
+
def cmd_list(self):
|
|
22
|
+
return [DebugTimings(), DebugCompletes()]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from adam.commands import validate_args
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.config import Config
|
|
4
|
+
from adam.repl_state import ReplState
|
|
5
|
+
|
|
6
|
+
class DebugCompletes(Command):
|
|
7
|
+
COMMAND = 'debug completes'
|
|
8
|
+
|
|
9
|
+
# the singleton pattern
|
|
10
|
+
def __new__(cls, *args, **kwargs):
|
|
11
|
+
if not hasattr(cls, 'instance'): cls.instance = super(DebugCompletes, 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 DebugCompletes.COMMAND
|
|
20
|
+
|
|
21
|
+
def run(self, cmd: str, state: ReplState):
|
|
22
|
+
if not(args := self.args(cmd)):
|
|
23
|
+
return super().run(cmd, state)
|
|
24
|
+
|
|
25
|
+
with self.validate(args, state) as (args, state):
|
|
26
|
+
with validate_args(args, state, name='on, off or file') as args:
|
|
27
|
+
Config().set('debugs.complete', args)
|
|
28
|
+
|
|
29
|
+
return state
|
|
30
|
+
|
|
31
|
+
def completion(self, state: ReplState):
|
|
32
|
+
return super().completion(state, {f: None for f in ['on', 'off', 'file']})
|
|
33
|
+
|
|
34
|
+
def help(self, _: ReplState):
|
|
35
|
+
return f'{DebugCompletes.COMMAND} on|off|file\t turn auto complete debug on or off'
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from adam.commands import validate_args
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.config import Config
|
|
4
|
+
from adam.repl_state import ReplState
|
|
5
|
+
|
|
6
|
+
class DebugTimings(Command):
|
|
7
|
+
COMMAND = 'debug timings'
|
|
8
|
+
|
|
9
|
+
# the singleton pattern
|
|
10
|
+
def __new__(cls, *args, **kwargs):
|
|
11
|
+
if not hasattr(cls, 'instance'): cls.instance = super(DebugTimings, 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 DebugTimings.COMMAND
|
|
20
|
+
|
|
21
|
+
def run(self, cmd: str, state: ReplState):
|
|
22
|
+
if not(args := self.args(cmd)):
|
|
23
|
+
return super().run(cmd, state)
|
|
24
|
+
|
|
25
|
+
with self.validate(args, state) as (args, state):
|
|
26
|
+
with validate_args(args, state, name='on, off or file') as args:
|
|
27
|
+
Config().set('debugs.timings', args)
|
|
28
|
+
|
|
29
|
+
return state
|
|
30
|
+
|
|
31
|
+
def completion(self, state: ReplState):
|
|
32
|
+
return super().completion(state, {f: None for f in ['on', 'off', 'file']})
|
|
33
|
+
|
|
34
|
+
def help(self, _: ReplState):
|
|
35
|
+
return f'{DebugTimings.COMMAND} on|off|file\t turn timing debug on or off'
|
adam/commands/devices/device.py
CHANGED
|
@@ -2,7 +2,7 @@ from abc import abstractmethod
|
|
|
2
2
|
|
|
3
3
|
from adam.commands.command import Command
|
|
4
4
|
from adam.config import Config
|
|
5
|
-
from adam.pod_exec_result import PodExecResult
|
|
5
|
+
from adam.utils_k8s.pod_exec_result import PodExecResult
|
|
6
6
|
from adam.repl_state import BashSession, ReplState
|
|
7
7
|
from adam.utils import log2
|
|
8
8
|
from adam.utils_k8s.pods import Pods
|
adam/commands/devices/devices.py
CHANGED
|
@@ -7,7 +7,7 @@ from adam.commands.devices.device_postgres import DevicePostgres
|
|
|
7
7
|
from adam.repl_state import ReplState
|
|
8
8
|
|
|
9
9
|
class Devices:
|
|
10
|
-
def
|
|
10
|
+
def of(state: ReplState) -> Device:
|
|
11
11
|
if state.device == ReplState.A:
|
|
12
12
|
return DeviceApp()
|
|
13
13
|
elif state.device == ReplState.C:
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.devices.devices import Devices
|
|
3
|
+
from adam.config import Config
|
|
4
|
+
from adam.utils_k8s.pod_exec_result import PodExecResult
|
|
5
|
+
from adam.utils import log2
|
|
6
|
+
from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
7
|
+
from adam.repl_state import ReplState, RequiredState
|
|
8
|
+
from adam.utils_k8s.pods import Pods
|
|
9
|
+
|
|
10
|
+
class DownloadCassandraLog(Command):
|
|
11
|
+
COMMAND = 'download cassandra log'
|
|
12
|
+
|
|
13
|
+
# the singleton pattern
|
|
14
|
+
def __new__(cls, *args, **kwargs):
|
|
15
|
+
if not hasattr(cls, 'instance'): cls.instance = super(DownloadCassandraLog, cls).__new__(cls)
|
|
16
|
+
|
|
17
|
+
return cls.instance
|
|
18
|
+
|
|
19
|
+
def __init__(self, successor: Command=None):
|
|
20
|
+
super().__init__(successor)
|
|
21
|
+
|
|
22
|
+
def command(self):
|
|
23
|
+
return DownloadCassandraLog.COMMAND
|
|
24
|
+
|
|
25
|
+
def required(self):
|
|
26
|
+
return RequiredState.POD
|
|
27
|
+
|
|
28
|
+
def run(self, cmd: str, state: ReplState):
|
|
29
|
+
if not(args := self.args(cmd)):
|
|
30
|
+
return super().run(cmd, state)
|
|
31
|
+
|
|
32
|
+
with self.validate(args, state) as (args, state):
|
|
33
|
+
path = Config().get('logs.path', '/c3/cassandra/logs/system.log')
|
|
34
|
+
r: PodExecResult = CassandraNodes.exec(state.pod, state.namespace, f'cat {path}', backgrounded=True, history=False)
|
|
35
|
+
|
|
36
|
+
to_file = Pods.download_file(state.pod, 'cassandra', state.namespace, path)
|
|
37
|
+
log2(f'Downloaded to {to_file}.')
|
|
38
|
+
|
|
39
|
+
return r
|
|
40
|
+
|
|
41
|
+
def completion(self, state: ReplState):
|
|
42
|
+
return super().completion(state, pods=Devices.of(state).pods(state, '-'), auto='jit')
|
|
43
|
+
|
|
44
|
+
def help(self, _: ReplState):
|
|
45
|
+
return f'{DownloadCassandraLog.COMMAND}\t download cassandra system log'
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
from collections.abc import Callable
|
|
2
2
|
from datetime import datetime
|
|
3
|
+
from functools import partial
|
|
3
4
|
import os
|
|
4
5
|
import boto3
|
|
5
6
|
|
|
6
7
|
from adam.commands.export.export_sessions import ExportSessions
|
|
7
8
|
from adam.commands.export.importer import Importer
|
|
9
|
+
from adam.commands.export.utils_export import export_log_dir
|
|
8
10
|
from adam.config import Config
|
|
9
11
|
from adam.repl_session import ReplSession
|
|
10
12
|
from adam.repl_state import ReplState
|
|
@@ -31,7 +33,7 @@ class ExportDatabases:
|
|
|
31
33
|
|
|
32
34
|
if Config().get('repl.history.push-cat-log-file', True):
|
|
33
35
|
if log_file and ReplSession().prompt_session:
|
|
34
|
-
ReplSession().prompt_session.history.append_string(f':
|
|
36
|
+
ReplSession().prompt_session.history.append_string(f':cat {log_file}')
|
|
35
37
|
|
|
36
38
|
return cnt
|
|
37
39
|
|
|
@@ -192,20 +194,23 @@ class ExportDatabaseService:
|
|
|
192
194
|
def __init__(self, handler: 'ExportDatabaseHandler'):
|
|
193
195
|
self.handler = handler
|
|
194
196
|
|
|
195
|
-
def sql(self, query: str, database: str = None, backgrounded = False):
|
|
197
|
+
def sql(self, query: str, database: str = None, backgrounded = False, export_log: str = None):
|
|
196
198
|
if not database:
|
|
197
199
|
database = self.handler.state.export_session
|
|
198
200
|
|
|
199
|
-
def output(out: str):
|
|
200
|
-
|
|
201
|
-
|
|
201
|
+
def output(export_log: str, out: str):
|
|
202
|
+
# serving for 1. export log or 2. job log for the sampling select 10 rows afterward
|
|
203
|
+
flag = 'at'
|
|
204
|
+
if not export_log:
|
|
205
|
+
export_log = f'{export_log_dir()}/{datetime.now().strftime("%d%H%M%S")}-export.log'
|
|
206
|
+
flag = 'w'
|
|
202
207
|
|
|
203
|
-
with open(
|
|
208
|
+
with open(export_log, flag) as f:
|
|
204
209
|
f.write(out)
|
|
205
210
|
|
|
206
|
-
return
|
|
211
|
+
return export_log
|
|
207
212
|
|
|
208
|
-
ExportDatabases.run_query(query, database, output = output if backgrounded else None, show_query = not backgrounded)
|
|
213
|
+
ExportDatabases.run_query(query, database, output = partial(output, export_log) if backgrounded else None, show_query = not backgrounded)
|
|
209
214
|
|
|
210
215
|
def drop(self, database: str):
|
|
211
216
|
state = self.handler.state
|
|
@@ -3,14 +3,14 @@ import os
|
|
|
3
3
|
import re
|
|
4
4
|
|
|
5
5
|
from adam.commands.export.importer import Importer
|
|
6
|
-
from adam.commands.export.utils_export import ExportTableStatus, csv_dir, find_files
|
|
6
|
+
from adam.commands.export.utils_export import ExportTableStatus, csv_dir, export_log_dir, find_files, os_system_exec
|
|
7
7
|
from adam.config import Config
|
|
8
8
|
from adam.repl_state import ReplState
|
|
9
9
|
from adam.utils import log2, tabulize, log, parallelize
|
|
10
10
|
from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
11
|
-
from adam.utils_k8s.pods import Pods
|
|
11
|
+
from adam.utils_k8s.pods import Pods
|
|
12
12
|
from adam.utils_k8s.statefulsets import StatefulSets
|
|
13
|
-
from adam.utils_local import
|
|
13
|
+
from adam.utils_local import local_downloads_dir
|
|
14
14
|
|
|
15
15
|
class ExportSessions:
|
|
16
16
|
def clear_export_session_cache():
|
|
@@ -36,13 +36,13 @@ class ExportSessions:
|
|
|
36
36
|
|
|
37
37
|
prefix = Importer.prefix_from_importer(importer)
|
|
38
38
|
|
|
39
|
-
log_files: list[str] = find_files(pod, namespace, f'{
|
|
39
|
+
log_files: list[str] = find_files(pod, namespace, f'{export_log_dir()}/{prefix}*_*.log*')
|
|
40
40
|
|
|
41
41
|
if not log_files:
|
|
42
42
|
return {}
|
|
43
43
|
|
|
44
44
|
for log_file in log_files[:limit]:
|
|
45
|
-
m = re.match(f'{
|
|
45
|
+
m = re.match(f'{export_log_dir()}/([ces].*?)_.*\.log?(.*)', log_file)
|
|
46
46
|
if m:
|
|
47
47
|
s = m.group(1)
|
|
48
48
|
state = m.group(2) # '', '.pending_import', '.done'
|
|
@@ -66,7 +66,8 @@ class ExportSessions:
|
|
|
66
66
|
pod = StatefulSets.pod_names(sts, namespace)[0]
|
|
67
67
|
|
|
68
68
|
CassandraNodes.exec(pod, namespace, f'rm -rf {csv_dir()}/*', show_out=Config().is_debug(), shell='bash')
|
|
69
|
-
|
|
69
|
+
cmd = f'rm -rf {export_log_dir()}/*.log*'
|
|
70
|
+
os_system_exec(cmd, show_out=Config().is_debug())
|
|
70
71
|
|
|
71
72
|
return True
|
|
72
73
|
|
|
@@ -102,17 +103,18 @@ class ExportSessions:
|
|
|
102
103
|
csv_cnt = 0
|
|
103
104
|
log_cnt = 0
|
|
104
105
|
|
|
105
|
-
log_files: list[str] = find_files(pod, namespace, f'{
|
|
106
|
+
log_files: list[str] = find_files(pod, namespace, f'{export_log_dir()}/{session}_*.log*')
|
|
106
107
|
|
|
107
108
|
for log_file in log_files:
|
|
108
|
-
m = re.match(f'{
|
|
109
|
+
m = re.match(f'{export_log_dir()}/{session}_(.*?)\.(.*?)\.log.*', log_file)
|
|
109
110
|
if m:
|
|
110
111
|
table = m.group(2)
|
|
111
112
|
|
|
112
113
|
CassandraNodes.exec(pod, namespace, f'rm -rf {csv_dir()}/{session}_{table}', show_out=not multi_tables, shell='bash')
|
|
113
114
|
csv_cnt += 1
|
|
114
115
|
|
|
115
|
-
|
|
116
|
+
cmd = f'rm -rf {log_file}'
|
|
117
|
+
os_system_exec(cmd, show_out=not multi_tables)
|
|
116
118
|
log_cnt += 1
|
|
117
119
|
|
|
118
120
|
return csv_cnt, log_cnt
|
|
@@ -142,8 +144,7 @@ class ExportSessions:
|
|
|
142
144
|
def download_csv(table):
|
|
143
145
|
from_path: str = table.csv_file
|
|
144
146
|
|
|
145
|
-
to_path = from_path.replace(csv_dir(),
|
|
146
|
-
os.makedirs(os.path.dirname(to_path), exist_ok=True)
|
|
147
|
+
to_path = from_path.replace(csv_dir(), local_downloads_dir())
|
|
147
148
|
Pods.download_file(pod, 'cassandra', namespace, from_path, to_path)
|
|
148
149
|
|
|
149
150
|
log2(f'[{session}] Downloaded to {to_path}.')
|