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.

Files changed (78) hide show
  1. adam/batch.py +7 -7
  2. adam/commands/app/utils_app.py +1 -1
  3. adam/commands/bash/bash.py +1 -1
  4. adam/commands/bash/utils_bash.py +1 -1
  5. adam/commands/cassandra/__init__.py +0 -0
  6. adam/commands/command.py +1 -1
  7. adam/commands/commands_utils.py +8 -13
  8. adam/commands/{alter_tables.py → cql/alter_tables.py} +1 -1
  9. adam/commands/cql/completions_c.py +1 -0
  10. adam/commands/cql/utils_cql.py +14 -13
  11. adam/commands/debug/__init__.py +0 -0
  12. adam/commands/debug/debug.py +22 -0
  13. adam/commands/debug/debug_completes.py +35 -0
  14. adam/commands/debug/debug_timings.py +35 -0
  15. adam/commands/devices/device.py +1 -1
  16. adam/commands/devices/devices.py +1 -1
  17. adam/commands/download_cassandra_log.py +45 -0
  18. adam/commands/export/export_databases.py +13 -8
  19. adam/commands/export/export_sessions.py +12 -11
  20. adam/commands/export/exporter.py +140 -53
  21. adam/commands/export/import_session.py +0 -4
  22. adam/commands/export/importer.py +11 -11
  23. adam/commands/export/importer_athena.py +15 -6
  24. adam/commands/export/importer_sqlite.py +19 -8
  25. adam/commands/export/utils_export.py +37 -15
  26. adam/commands/generate_report.py +52 -0
  27. adam/commands/medusa/medusa_restore.py +0 -16
  28. adam/commands/nodetool.py +1 -1
  29. adam/commands/os/__init__.py +0 -0
  30. adam/commands/postgres/postgres_databases.py +2 -3
  31. adam/commands/postgres/postgres_ls.py +1 -1
  32. adam/commands/postgres/utils_postgres.py +2 -1
  33. adam/commands/preview_table.py +1 -1
  34. adam/commands/restart_cluster.py +47 -0
  35. adam/commands/restart_node.py +51 -0
  36. adam/commands/restart_nodes.py +47 -0
  37. adam/commands/show/show_cassandra_status.py +3 -10
  38. adam/commands/show/show_cli_commands.py +1 -1
  39. adam/commands/show/show_processes.py +1 -1
  40. adam/commands/show/show_storage.py +2 -1
  41. adam/config.py +4 -6
  42. adam/embedded_params.py +1 -1
  43. adam/repl.py +5 -3
  44. adam/repl_commands.py +23 -17
  45. adam/repl_session.py +4 -3
  46. adam/repl_state.py +6 -0
  47. adam/sql/async_executor.py +44 -0
  48. adam/sql/lark_completer.py +6 -4
  49. adam/sql/qingl.lark +1076 -0
  50. adam/sso/cred_cache.py +2 -5
  51. adam/utils.py +206 -83
  52. adam/utils_k8s/app_clusters.py +11 -4
  53. adam/utils_k8s/app_pods.py +10 -5
  54. adam/utils_k8s/cassandra_clusters.py +8 -4
  55. adam/utils_k8s/cassandra_nodes.py +14 -5
  56. adam/utils_k8s/kube_context.py +1 -4
  57. adam/{pod_exec_result.py → utils_k8s/pod_exec_result.py} +8 -2
  58. adam/utils_k8s/pods.py +83 -24
  59. adam/utils_local.py +78 -2
  60. adam/utils_repl/repl_completer.py +10 -89
  61. adam/utils_sqlite.py +3 -8
  62. adam/version.py +1 -1
  63. {kaqing-2.0.188.dist-info → kaqing-2.0.211.dist-info}/METADATA +1 -1
  64. {kaqing-2.0.188.dist-info → kaqing-2.0.211.dist-info}/RECORD +67 -65
  65. adam/commands/cat.py +0 -36
  66. adam/commands/cd.py +0 -41
  67. adam/commands/download_file.py +0 -47
  68. adam/commands/find_files.py +0 -51
  69. adam/commands/find_processes.py +0 -76
  70. adam/commands/head.py +0 -36
  71. adam/commands/logs.py +0 -37
  72. adam/commands/ls.py +0 -41
  73. adam/commands/report.py +0 -61
  74. adam/commands/restart.py +0 -60
  75. adam/commands/shell.py +0 -41
  76. {kaqing-2.0.188.dist-info → kaqing-2.0.211.dist-info}/WHEEL +0 -0
  77. {kaqing-2.0.188.dist-info → kaqing-2.0.211.dist-info}/entry_points.txt +0 -0
  78. {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.logs import Logs
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.report import Report
23
- from adam.commands.restart import Restart
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(Logs(), kubeconfig, config, param, None, namespace, pod, extra_args)
131
+ run_command(DownloadCassandraLog(), kubeconfig, config, param, None, namespace, pod, extra_args)
132
132
 
133
133
 
134
134
  @cli.command(context_settings=dict(ignore_unknown_options=True, allow_extra_args=True), cls=ClusterCommandHelper, help='List statefulset or pods.')
@@ -221,7 +221,7 @@ def repair(kubeconfig: str, config: str, param: list[str], cluster: str, namespa
221
221
  @click.option('--show', '-s', is_flag=True, help='show output from Cassandra nodes')
222
222
  @click.argument('extra_args', nargs=-1, metavar='[cluster|pod]', type=click.UNPROCESSED)
223
223
  def report(kubeconfig: str, config: str, param: list[str], cluster: str, namespace: str, pod: str, show: bool, extra_args):
224
- run_command(Report(), kubeconfig, config, param, cluster, namespace, pod, ('-s',) + extra_args if show else extra_args)
224
+ run_command(GenerateReport(), kubeconfig, config, param, cluster, namespace, pod, ('-s',) + extra_args if show else extra_args)
225
225
 
226
226
 
227
227
  @cli.command(context_settings=dict(ignore_unknown_options=True, allow_extra_args=True), cls=ClusterOrPodCommandHelper, help='Restart Cassandra Cluster or Node')
@@ -234,7 +234,7 @@ def report(kubeconfig: str, config: str, param: list[str], cluster: str, namespa
234
234
  @click.option('--force', is_flag=True, help='need for restarting the whole cluster')
235
235
  @click.argument('extra_args', nargs=-1, metavar='<cluster|pod>', type=click.UNPROCESSED)
236
236
  def restart(kubeconfig: str, config: str, param: list[str], cluster: str, namespace: str, pod: str, force: bool, extra_args):
237
- run_command(Restart(), kubeconfig, config, param, cluster, namespace, pod, ('--force',) + extra_args if force else extra_args)
237
+ run_command(RestartNodes(), kubeconfig, config, param, cluster, namespace, pod, ('--force',) + extra_args if force else extra_args)
238
238
 
239
239
 
240
240
  @cli.command(context_settings=dict(ignore_unknown_options=True, allow_extra_args=True), cls=ClusterOrPodCommandHelper, help='Rolling restart Cassandra Cluster.')
@@ -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
@@ -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.device(state).pods(state, '-'))
33
+ return super().completion(state, {c : {'&': None} for c in ['ls', 'cat', 'head']}, pods=Devices.of(state).pods(state, '-'))
34
34
 
35
35
  def help(self, _: ReplState):
36
36
  return f'{Bash.COMMAND} [pod-name] [bash-commands] [&]\t run bash on the Cassandra nodes'
@@ -13,4 +13,4 @@ class BashHandler:
13
13
  return False
14
14
 
15
15
  def exec(self, args: list[str]):
16
- return Devices.device(self.s1).bash(self.s0, self.s1, args)
16
+ return Devices.of(self.s1).bash(self.s0, self.s1, args)
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
 
@@ -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, tabulize, log, log2
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
- log_prefix = Config().get('log-prefix', '/tmp/qing')
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
- with open(log_file, 'w') as f:
77
- f.write(r)
78
-
79
- ReplSession().append_history(f':sh cat {log_file}')
72
+ IssuesUtils.show(results, state.in_repl)
80
73
 
81
- r = log_file
74
+ return r
82
75
 
83
- IssuesUtils.show(results, state.in_repl)
76
+ def write_to_kaqing_log_file(r: str):
77
+ with kaqing_log_file() as f:
78
+ f.write(r)
84
79
 
85
- return r
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 sql completer
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),
@@ -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
- if state.pod:
274
- return show_table(state, [state.pod], cols, header, show_out=show_out, backgrounded = backgrounded)
275
- elif state.sts:
276
- pod_names = [pod.metadata.name for pod in StatefulSets.pods(state.sts, state.namespace)]
277
- return show_table(state, pod_names, cols, header, show_out=show_out, backgrounded = backgrounded)
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'
@@ -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
@@ -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 device(state: ReplState) -> Device:
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':sh cat {log_file}')
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
- log_prefix = Config().get('export.log-prefix', '/tmp/qing')
201
- log_file = f'{log_prefix}-{datetime.now().strftime("%d%H%M%S")}-export.log'
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(log_file, 'w') as f:
208
+ with open(export_log, flag) as f:
204
209
  f.write(out)
205
210
 
206
- return log_file
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, log_prefix
11
+ from adam.utils_k8s.pods import Pods
12
12
  from adam.utils_k8s.statefulsets import StatefulSets
13
- from adam.utils_local import local_tmp_dir
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'{log_prefix()}-{prefix}*_*.log*')
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'{log_prefix()}-(.*?)_.*\.log?(.*)', log_file)
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
- CassandraNodes.exec(pod, namespace, f'rm -rf {log_prefix()}-*.log*', show_out=Config().is_debug(), shell='bash')
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'{log_prefix()}-{session}_*.log*')
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'{log_prefix()}-{session}_(.*?)\.(.*?)\.log.*', log_file)
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
- CassandraNodes.exec(pod, namespace, f'rm -rf {log_file}', show_out=not multi_tables, shell='bash')
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(), local_tmp_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}.')