kaqing 2.0.214__py3-none-any.whl → 2.0.227__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 (149) hide show
  1. adam/checks/compactionstats.py +2 -1
  2. adam/checks/cpu.py +2 -1
  3. adam/checks/disk.py +6 -5
  4. adam/checks/gossip.py +2 -1
  5. adam/checks/memory.py +2 -1
  6. adam/checks/status.py +2 -1
  7. adam/commands/app/app.py +2 -2
  8. adam/commands/app/app_ping.py +2 -2
  9. adam/commands/app/login.py +2 -2
  10. adam/commands/app/show_app_actions.py +2 -2
  11. adam/commands/app/show_app_id.py +2 -2
  12. adam/commands/app/show_app_queues.py +2 -2
  13. adam/commands/app/show_login.py +2 -2
  14. adam/commands/audit/audit.py +3 -5
  15. adam/commands/audit/audit_repair_tables.py +2 -2
  16. adam/commands/audit/audit_run.py +2 -2
  17. adam/commands/audit/show_last10.py +2 -2
  18. adam/commands/audit/show_slow10.py +2 -2
  19. adam/commands/audit/show_top10.py +2 -2
  20. adam/commands/bash/bash.py +2 -2
  21. adam/commands/cassandra/download_cassandra_log.py +2 -2
  22. adam/commands/cassandra/restart_cluster.py +2 -2
  23. adam/commands/cassandra/restart_node.py +2 -2
  24. adam/commands/cassandra/restart_nodes.py +2 -2
  25. adam/commands/cassandra/rollout.py +2 -2
  26. adam/commands/cassandra/show_cassandra_repairs.py +2 -2
  27. adam/commands/cassandra/show_cassandra_status.py +2 -2
  28. adam/commands/cassandra/show_cassandra_version.py +2 -2
  29. adam/commands/cassandra/show_processes.py +6 -6
  30. adam/commands/cassandra/show_storage.py +2 -2
  31. adam/commands/cassandra/watch.py +2 -2
  32. adam/commands/cli/clipboard_copy.py +2 -2
  33. adam/commands/cli/show_cli_commands.py +3 -3
  34. adam/commands/code.py +2 -2
  35. adam/commands/command.py +32 -5
  36. adam/commands/config/param_get.py +2 -2
  37. adam/commands/config/param_set.py +2 -2
  38. adam/commands/config/show_params.py +2 -2
  39. adam/commands/cql/alter_tables.py +2 -2
  40. adam/commands/cql/cqlsh.py +2 -2
  41. adam/commands/cql/utils_cql.py +13 -3
  42. adam/commands/debug/debug_completes.py +2 -2
  43. adam/commands/debug/debug_timings.py +2 -2
  44. adam/commands/debug/show_offloaded_completes.py +2 -2
  45. adam/commands/deploy/code_start.py +2 -2
  46. adam/commands/deploy/code_stop.py +2 -2
  47. adam/commands/deploy/deploy_frontend.py +2 -2
  48. adam/commands/deploy/deploy_pg_agent.py +2 -2
  49. adam/commands/deploy/deploy_pod.py +2 -2
  50. adam/commands/deploy/undeploy_frontend.py +2 -2
  51. adam/commands/deploy/undeploy_pg_agent.py +2 -2
  52. adam/commands/deploy/undeploy_pod.py +2 -2
  53. adam/commands/devices/device.py +7 -7
  54. adam/commands/devices/device_app.py +6 -6
  55. adam/commands/devices/device_auit_log.py +2 -2
  56. adam/commands/devices/device_cass.py +6 -6
  57. adam/commands/devices/device_export.py +2 -2
  58. adam/commands/devices/device_postgres.py +6 -6
  59. adam/commands/diag/check.py +2 -2
  60. adam/commands/diag/generate_report.py +2 -2
  61. adam/commands/diag/issues.py +3 -2
  62. adam/commands/exit.py +2 -2
  63. adam/commands/export/clean_up_all_export_sessions.py +2 -2
  64. adam/commands/export/clean_up_export_sessions.py +2 -2
  65. adam/commands/export/download_export_session.py +4 -5
  66. adam/commands/export/drop_export_database.py +2 -2
  67. adam/commands/export/drop_export_databases.py +2 -2
  68. adam/commands/export/export.py +3 -3
  69. adam/commands/export/export_databases.py +3 -0
  70. adam/commands/export/export_select.py +2 -2
  71. adam/commands/export/export_sessions.py +10 -9
  72. adam/commands/export/export_use.py +3 -3
  73. adam/commands/export/export_x_select.py +2 -2
  74. adam/commands/export/exporter.py +11 -11
  75. adam/commands/export/import_files.py +3 -7
  76. adam/commands/export/import_session.py +2 -2
  77. adam/commands/export/importer.py +6 -7
  78. adam/commands/export/show_column_counts.py +2 -3
  79. adam/commands/export/show_export_databases.py +3 -4
  80. adam/commands/export/show_export_session.py +4 -4
  81. adam/commands/export/show_export_sessions.py +3 -3
  82. adam/commands/export/utils_export.py +25 -33
  83. adam/commands/fs/cat.py +2 -2
  84. adam/commands/fs/cat_local.py +2 -2
  85. adam/commands/fs/cd.py +2 -2
  86. adam/commands/fs/download_file.py +2 -2
  87. adam/commands/fs/find_files.py +3 -3
  88. adam/commands/fs/find_processes.py +12 -20
  89. adam/commands/fs/head.py +4 -4
  90. adam/commands/fs/head_local.py +46 -0
  91. adam/commands/fs/ls.py +2 -2
  92. adam/commands/fs/ls_local.py +2 -2
  93. adam/commands/fs/pwd.py +2 -2
  94. adam/commands/fs/rm.py +2 -2
  95. adam/commands/fs/rm_downloads.py +2 -2
  96. adam/commands/fs/rm_logs.py +13 -7
  97. adam/commands/fs/rm_logs_local.py +38 -0
  98. adam/commands/fs/shell.py +2 -2
  99. adam/commands/fs/show_adam.py +2 -2
  100. adam/commands/fs/show_host.py +2 -2
  101. adam/commands/fs/show_last_results.py +39 -0
  102. adam/commands/fs/tail.py +36 -0
  103. adam/commands/fs/tail_local.py +46 -0
  104. adam/commands/fs/utils_fs.py +192 -0
  105. adam/commands/help.py +2 -2
  106. adam/commands/kubectl.py +2 -2
  107. adam/commands/medusa/medusa_backup.py +2 -2
  108. adam/commands/medusa/medusa_restore.py +2 -2
  109. adam/commands/medusa/medusa_show_backupjobs.py +2 -2
  110. adam/commands/medusa/medusa_show_restorejobs.py +2 -2
  111. adam/commands/nodetool/nodetool.py +30 -7
  112. adam/commands/nodetool/utils_nodetool.py +44 -0
  113. adam/commands/postgres/postgres.py +3 -6
  114. adam/commands/postgres/postgres_ls.py +2 -2
  115. adam/commands/postgres/postgres_preview.py +2 -2
  116. adam/commands/preview_table.py +2 -3
  117. adam/commands/reaper/reaper_forward.py +2 -2
  118. adam/commands/reaper/reaper_forward_stop.py +2 -2
  119. adam/commands/reaper/reaper_restart.py +2 -2
  120. adam/commands/reaper/reaper_run_abort.py +2 -2
  121. adam/commands/reaper/reaper_runs.py +14 -12
  122. adam/commands/reaper/reaper_runs_abort.py +2 -2
  123. adam/commands/reaper/reaper_schedule_activate.py +2 -2
  124. adam/commands/reaper/reaper_schedule_start.py +2 -2
  125. adam/commands/reaper/reaper_schedule_stop.py +2 -2
  126. adam/commands/reaper/reaper_schedules.py +2 -2
  127. adam/commands/reaper/reaper_status.py +2 -2
  128. adam/commands/reaper/utils_reaper.py +31 -5
  129. adam/commands/repair/repair_log.py +2 -2
  130. adam/commands/repair/repair_run.py +2 -2
  131. adam/commands/repair/repair_scan.py +2 -2
  132. adam/commands/repair/repair_stop.py +2 -2
  133. adam/embedded_params.py +1 -1
  134. adam/repl.py +2 -1
  135. adam/repl_commands.py +25 -10
  136. adam/repl_session.py +10 -3
  137. adam/sql/qingl.lark +58 -59
  138. adam/utils.py +48 -8
  139. adam/utils_async_job.py +73 -0
  140. adam/utils_k8s/cassandra_clusters.py +15 -7
  141. adam/utils_k8s/cassandra_nodes.py +5 -4
  142. adam/utils_k8s/pods.py +152 -51
  143. adam/version.py +1 -1
  144. {kaqing-2.0.214.dist-info → kaqing-2.0.227.dist-info}/METADATA +1 -1
  145. kaqing-2.0.227.dist-info/RECORD +280 -0
  146. kaqing-2.0.214.dist-info/RECORD +0 -272
  147. {kaqing-2.0.214.dist-info → kaqing-2.0.227.dist-info}/WHEEL +0 -0
  148. {kaqing-2.0.214.dist-info → kaqing-2.0.227.dist-info}/entry_points.txt +0 -0
  149. {kaqing-2.0.214.dist-info → kaqing-2.0.227.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  from adam.commands import validate_args
2
2
  from adam.commands.command import Command
3
- from adam.commands.export.export_sessions import ExportSessions, export_session
3
+ from adam.commands.export.export_sessions import export_session
4
4
  from adam.repl_state import ReplState, RequiredState
5
5
 
6
6
  class ShowExportSession(Command):
@@ -32,8 +32,8 @@ class ShowExportSession(Command):
32
32
 
33
33
  return state
34
34
 
35
- def completion(self, state: ReplState):
35
+ def completion(self, _: ReplState):
36
36
  return {}
37
37
 
38
- def help(self, _: ReplState):
39
- return f'{ShowExportSession.COMMAND} <export-session-name>\t show export session'
38
+ def help(self, state: ReplState):
39
+ return super().help(state, 'show export session', args='<export-session-name>')
@@ -30,8 +30,8 @@ class ShowExportSessions(Command):
30
30
 
31
31
  return state
32
32
 
33
- def completion(self, state: ReplState):
33
+ def completion(self, _: ReplState):
34
34
  return {}
35
35
 
36
- def help(self, _: ReplState):
37
- return f'{ShowExportSessions.COMMAND}\t list export sessions'
36
+ def help(self, state: ReplState):
37
+ return super().help(state, 'list export sessions')
@@ -3,9 +3,9 @@ import os
3
3
  import re
4
4
 
5
5
  from adam.config import Config
6
- from adam.utils import ExecResult, creating_dir, log2
6
+ from adam.utils import ExecResult, creating_dir, log2, log_to_pods
7
7
  from adam.repl_state import ReplState
8
- from adam.utils_k8s.cassandra_nodes import CassandraNodes
8
+ from adam.utils_k8s.pods import Pods
9
9
  from adam.utils_k8s.statefulsets import StatefulSets
10
10
  from adam.utils_local import local_exec
11
11
 
@@ -197,7 +197,7 @@ class ExportTableStatus:
197
197
  statuses: list[ExportTableStatus] = []
198
198
 
199
199
  status_in_whole = 'done'
200
- log_files: list[str] = find_files(pod, namespace, f'{export_log_dir()}/{export_session}_*.log*')
200
+ log_files: list[str] = Pods.find_files(pod, 'cassandra', namespace, f'{table_log_dir(pod, namespace)}/{export_session}_*.log*', remote=log_to_pods())
201
201
 
202
202
  for log_file in log_files:
203
203
  status: ExportTableStatus = ExportTableStatus.from_log_file(pod, namespace, export_session, log_file)
@@ -212,7 +212,7 @@ class ExportTableStatus:
212
212
  def get_csv_files_n_table(target_table: str):
213
213
  db = f'{copy_session}_{target_table}'
214
214
  csv_file = f'{csv_dir()}/{db}/*.csv'
215
- csv_files: list[str] = find_files(pod, namespace, csv_file, remote=True)
215
+ csv_files: list[str] = Pods.find_files(pod, 'cassandra', namespace, csv_file, remote=log_to_pods())
216
216
  if csv_files:
217
217
  table = target_table
218
218
  m = re.match(f'{csv_dir()}/{db}/(.*).csv', csv_files[0])
@@ -222,7 +222,7 @@ class ExportTableStatus:
222
222
 
223
223
  return csv_files, target_table
224
224
 
225
- m = re.match(f'{export_log_dir()}/{copy_session}_(.*?)\.(.*?)\.log(.*)', log_file)
225
+ m = re.match(f'{table_log_dir(pod, namespace)}/{copy_session}_(.*?)\.(.*?)\.log(.*)', log_file)
226
226
  if m:
227
227
  keyspace = m.group(1)
228
228
  target_table = m.group(2)
@@ -235,7 +235,10 @@ class ExportTableStatus:
235
235
 
236
236
  # 4 rows exported to 1 files in 0 day, 0 hour, 0 minute, and 1.335 seconds.
237
237
  pattern = 'rows exported to'
238
- r: ExecResult = local_exec(['grep', pattern, log_file], show_out=Config().is_debug())
238
+ if log_to_pods():
239
+ r: ExecResult = Pods.exec(pod, 'cassandra', namespace, f"grep '{pattern}' {log_file}", show_out=Config().is_debug())
240
+ else:
241
+ r: ExecResult = local_exec(["grep", pattern, log_file], show_out=Config().is_debug())
239
242
 
240
243
  if r.exit_code() == 0:
241
244
  csv_files, table = get_csv_files_n_table(target_table)
@@ -248,32 +251,6 @@ class ExportTableStatus:
248
251
 
249
252
  return ExportTableStatus(None, None, 'unknown')
250
253
 
251
- def find_files(pod: str, namespace: str, pattern: str, mmin: int = 0, remote = False):
252
- stdout = ''
253
- if not remote:
254
- # find . -maxdepth 1 -type f -name '*'
255
- dir = os.path.dirname(pattern)
256
- base = os.path.basename(pattern)
257
- cmd = ['find', dir, '-name', base]
258
- if mmin:
259
- cmd += ['-mmin', f'-{mmin}']
260
-
261
- stdout = local_exec(cmd, show_out=Config().is_debug()).stdout
262
- else:
263
- cmd = f'find {pattern}'
264
- if mmin:
265
- cmd = f'{cmd} -mmin -{mmin}'
266
-
267
- stdout = CassandraNodes.exec(pod, namespace, cmd, show_out=Config().is_debug(), shell='bash').stdout
268
-
269
- log_files = []
270
- for line in stdout.split('\n'):
271
- line = line.strip(' \r')
272
- if line:
273
- log_files.append(line)
274
-
275
- return log_files
276
-
277
254
  class GeneratorStream(io.RawIOBase):
278
255
  def __init__(self, generator):
279
256
  self._generator = generator
@@ -354,6 +331,12 @@ class PodPushHandler:
354
331
  def state_with_pod(state: ReplState, pod: str = None):
355
332
  return PodPushHandler(state, pod=pod)
356
333
 
334
+ def fs_exec(pod: str, namespace: str, cmd: str, show_out = False):
335
+ if log_to_pods():
336
+ Pods.exec(pod, 'cassandra', namespace, cmd, show_out = show_out)
337
+ else:
338
+ os_system_exec(cmd, show_out=show_out)
339
+
357
340
  def os_system_exec(cmd: str, show_out = False):
358
341
  if show_out: log2(cmd)
359
342
 
@@ -362,5 +345,14 @@ def os_system_exec(cmd: str, show_out = False):
362
345
  def csv_dir():
363
346
  return Config().get('export.csv_dir', '/c3/cassandra/tmp')
364
347
 
348
+ def table_log_dir(pod: str, namespace: str):
349
+ if log_to_pods():
350
+ return remote_export_log_dir(pod, namespace)
351
+ else:
352
+ return export_log_dir()
353
+
365
354
  def export_log_dir():
366
- return creating_dir(Config().get('export.log-dir', '/tmp/qing-db/q/export/logs'))
355
+ return creating_dir(Config().get('export.log-dir', '/tmp/qing-db/q/export/logs'))
356
+
357
+ def remote_export_log_dir(pod: str, namespace: str):
358
+ return Pods.creating_dir(pod, 'cassandra', namespace, Config().get('export.remote.log-dir', '/tmp/q/export/logs'))
adam/commands/fs/cat.py CHANGED
@@ -32,5 +32,5 @@ class Cat(Command):
32
32
  def completion(self, state: ReplState):
33
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
- def help(self, _: ReplState):
36
- return f'{Cat.COMMAND} file [&]\t run cat command on the pod'
35
+ def help(self, state: ReplState):
36
+ return super().help(state, 'run cat command on the pod', args='<file>')
@@ -38,5 +38,5 @@ class CatLocal(Command):
38
38
  def completion(self, state: ReplState):
39
39
  return super().completion(state, lambda: {n: None for n in find_local_files(file_type='f', max_depth=1)}, auto='jit')
40
40
 
41
- def help(self, _: ReplState):
42
- return f'{CatLocal.COMMAND} file\t run cat command on local system'
41
+ def help(self, state: ReplState):
42
+ return super().help(state, 'run cat command on local file system', args='<file>')
adam/commands/fs/cd.py CHANGED
@@ -37,5 +37,5 @@ class Cd(Command):
37
37
  def completion(self, state: ReplState):
38
38
  return Devices.of(state).cd_completion(Cd.COMMAND, state, default = {})
39
39
 
40
- def help(self, _: ReplState):
41
- return f'{Cd.COMMAND} <path> | .. \t move around on the operational device hierarchy'
40
+ def help(self, state: ReplState):
41
+ return super().help(state, 'move around on the operational device hierarchy', args='<path> | ..')
@@ -43,5 +43,5 @@ class DownloadFile(Command):
43
43
  def completion(self, state: ReplState):
44
44
  return super().completion(state, lambda: {f: None for f in Devices.of(state).files(state)}, pods=Devices.of(state).pods(state, '-'), auto='jit')
45
45
 
46
- def help(self, _: ReplState):
47
- return f'{DownloadFile.COMMAND} from-file [to-file]\t download file from pod'
46
+ def help(self, state: ReplState):
47
+ return super().help(state, 'download file from pod', args='<from-file> [to-file]')
@@ -35,7 +35,7 @@ class FindLocalFiles(Command):
35
35
  new_args = [f"'{arg}'" if '*' in arg else arg for arg in args]
36
36
  cmd = 'find ' + ' '.join(new_args)
37
37
 
38
- log2(cmd)
38
+ log2(cmd, text_color='gray')
39
39
  os.system(cmd)
40
40
 
41
41
  return state
@@ -47,5 +47,5 @@ class FindLocalFiles(Command):
47
47
  '*': None
48
48
  })
49
49
 
50
- def help(self, _: ReplState):
51
- return f'{FindLocalFiles.COMMAND} [linux-find-arguments]\t find files from local machine'
50
+ def help(self, state: ReplState):
51
+ return super().help(state, 'find files from local machine', args='[linux-find-arguments]')
@@ -2,8 +2,10 @@ from adam.commands import extract_options, validate_args
2
2
  from adam.commands.command import Command
3
3
  from adam.commands.devices.devices import Devices
4
4
  from adam.commands.export.utils_export import state_with_pod
5
+ from adam.commands.fs.utils_fs import ProcessInfo, find_pids_for_cluster
5
6
  from adam.repl_state import ReplState, RequiredState
6
7
  from adam.utils import log2, tabulize
8
+ from adam.utils_k8s.pod_exec_result import PodExecResult
7
9
 
8
10
  class FindProcesses(Command):
9
11
  COMMAND = 'find processes'
@@ -29,26 +31,16 @@ class FindProcesses(Command):
29
31
 
30
32
  with self.validate(args, state) as (args, state):
31
33
  with extract_options(args, '-kill') as (args, kill):
32
- with validate_args(args, state, name='words to look for'):
33
- arg = ' | '.join([f'grep {a}' for a in args])
34
- awk = "awk '{ print $1, $2, $8, $NF }'"
35
- rs = Devices.of(state).bash(state, state, f"ps -ef | grep -v grep | {arg} | {awk}".split(' '))
36
-
37
- lines: list[list[str]] = []
38
- for r in rs:
39
- for l in r.stdout.split('\n'):
40
- l = l.strip(' \t\r\n')
41
- if not l:
42
- continue
43
-
44
- tokens = [r.pod] + l.split(' ')
45
- lines.append(tokens)
34
+ with validate_args(args, state, name='words to look for', separator=' ') as keywords:
35
+ action = 'find-files'
36
+ msg = 'd`Running|Ran ' + action + ' command onto {size} pods'
37
+ processes = find_pids_for_cluster(state, keywords)
46
38
 
47
39
  pids = []
48
- for l in lines:
49
- pids.append(f'{l[2]}@{l[0]}')
40
+ for p in processes:
41
+ pids.append(f'{p.pid}@{p.pod}')
50
42
 
51
- tabulize(lines, lambda l: '\t'.join(l), header = 'POD\tUSER\tPID\tCMD\tLAST_ARG', separator='\t')
43
+ ProcessInfo.tabulize(processes)
52
44
  log2()
53
45
  log2(f'PIDS with {",".join(args)}: {",".join(pids)}')
54
46
 
@@ -67,10 +59,10 @@ class FindProcesses(Command):
67
59
  with state_with_pod(state, pod) as state1:
68
60
  Devices.of(state).bash(state, state1, ['kill', '-9', pid])
69
61
 
70
- return rs
62
+ return state
71
63
 
72
64
  def completion(self, state: ReplState):
73
65
  return super().completion(state)
74
66
 
75
- def help(self, _: ReplState):
76
- return f'{FindProcesses.COMMAND} word... [-kill]\t find processes with words'
67
+ def help(self, state: ReplState):
68
+ return super().help(state, 'find processes with words --kill kill matching processes', args='word... [-kill]')
adam/commands/fs/head.py CHANGED
@@ -26,11 +26,11 @@ class Head(Command):
26
26
  return super().run(cmd, state)
27
27
 
28
28
  with self.validate(args, state) as (args, state):
29
- with validate_args(args, state, name='file'):
30
- return Devices.of(state).bash(state, state, cmd.split(' '))
29
+ with validate_args(args, state, name='file') as args:
30
+ return Devices.of(state).bash(state, state, ['head', '-n', '10', args])
31
31
 
32
32
  def completion(self, state: ReplState):
33
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
- def help(self, _: ReplState):
36
- return f'{Head.COMMAND} file [&]\t run head command on the pod'
35
+ def help(self, state: ReplState):
36
+ return super().help(state, 'run head command on the pod', args='<file>')
@@ -0,0 +1,46 @@
1
+ import os
2
+
3
+ from adam.commands import validate_args
4
+ from adam.commands.command import Command
5
+ from adam.repl_state import ReplState, RequiredState
6
+ from adam.utils import log2
7
+ from adam.utils_local import find_local_files
8
+
9
+ class HeadLocal(Command):
10
+ COMMAND = ':head'
11
+
12
+ # the singleton pattern
13
+ def __new__(cls, *args, **kwargs):
14
+ if not hasattr(cls, 'instance'): cls.instance = super(HeadLocal, cls).__new__(cls)
15
+
16
+ return cls.instance
17
+
18
+ def __init__(self, successor: Command=None):
19
+ super().__init__(successor)
20
+
21
+ def command(self):
22
+ return HeadLocal.COMMAND
23
+
24
+ def required(self):
25
+ return [RequiredState.CLUSTER_OR_POD, RequiredState.APP_APP, ReplState.P]
26
+
27
+ def run(self, cmd: str, state: ReplState):
28
+ if not(args := self.args(cmd)):
29
+ return super().run(cmd, state)
30
+
31
+ with self.validate(args, state) as (args, state):
32
+ with validate_args(args, state, name='file') as args:
33
+ cmd = f'head -n 10 {args}'
34
+ log2(cmd)
35
+ log2()
36
+
37
+ os.system(cmd)
38
+ log2()
39
+
40
+ return state
41
+
42
+ def completion(self, state: ReplState):
43
+ return super().completion(state, lambda: {n: None for n in find_local_files(file_type='f', max_depth=1)}, auto='jit')
44
+
45
+ def help(self, state: ReplState):
46
+ return super().help(state, 'run head command on local system', args='<file>')
adam/commands/fs/ls.py CHANGED
@@ -37,5 +37,5 @@ class Ls(Command):
37
37
  def completion(self, state: ReplState):
38
38
  return super().completion(state, {'&': None}, pods=Devices.of(state).pods(state, '-'))
39
39
 
40
- def help(self, _: ReplState):
41
- return f'{Ls.COMMAND} [device:]\t list apps, envs, clusters, nodes, pg hosts/databases or export databases'
40
+ def help(self, state: ReplState):
41
+ return super().help(state, 'list apps, envs, clusters, nodes, pg hosts/databases or export databases', args='[device:]')
@@ -36,5 +36,5 @@ class LsLocal(Command):
36
36
  def completion(self, state: ReplState):
37
37
  return super().completion(state)
38
38
 
39
- def help(self, _: ReplState):
40
- return f'{LsLocal.COMMAND} [dir]\t list files on local system'
39
+ def help(self, state: ReplState):
40
+ return super().help(state, 'list files on local system', args='[dir]')
adam/commands/fs/pwd.py CHANGED
@@ -41,5 +41,5 @@ class Pwd(Command):
41
41
  def completion(self, state: ReplState):
42
42
  return super().completion(state)
43
43
 
44
- def help(self, _: ReplState):
45
- return f'{Pwd.COMMAND}\t print current working directories'
44
+ def help(self, state: ReplState):
45
+ return super().help(state, 'print current working directories')
adam/commands/fs/rm.py CHANGED
@@ -1,5 +1,5 @@
1
1
  from adam.commands.fs.rm_downloads import RmDownloads
2
- from adam.commands.fs.rm_logs import RmLogs
2
+ from adam.commands.fs.rm_logs_local import RmLogsLocal
3
3
  from adam.commands.intermediate_command import IntermediateCommand
4
4
 
5
5
  class RmLocal(IntermediateCommand):
@@ -15,4 +15,4 @@ class RmLocal(IntermediateCommand):
15
15
  return RmLocal.COMMAND
16
16
 
17
17
  def cmd_list(self):
18
- return [RmDownloads(), RmLogs()]
18
+ return [RmDownloads(), RmLogsLocal()]
@@ -35,5 +35,5 @@ class RmDownloads(Command):
35
35
  def completion(self, state: ReplState):
36
36
  return super().completion(state)
37
37
 
38
- def help(self, _: ReplState):
39
- return f'{RmDownloads.COMMAND}\t remove all downloads files under {local_downloads_dir()}'
38
+ def help(self, state: ReplState):
39
+ return super().help(state, f'remove all downloads files under {local_downloads_dir()}')
@@ -1,11 +1,14 @@
1
1
  import os
2
2
 
3
3
  from adam.commands.command import Command
4
+ from adam.commands.devices.devices import Devices
5
+ from adam.config import Config
4
6
  from adam.repl_state import ReplState
5
7
  from adam.utils import log2, log_dir
8
+ from adam.utils_k8s.pods import Pods
6
9
 
7
10
  class RmLogs(Command):
8
- COMMAND = ':rm logs'
11
+ COMMAND = 'rm logs'
9
12
 
10
13
  # the singleton pattern
11
14
  def __new__(cls, *args, **kwargs):
@@ -24,15 +27,18 @@ class RmLogs(Command):
24
27
  return super().run(cmd, state)
25
28
 
26
29
  with self.validate(args, state) as (args, state):
27
- cmd = f'rm -rf {log_dir()}/*'
28
- log2(cmd)
29
- os.system(cmd)
30
- log2()
30
+ cmd = f'rm -rf {self.log_dir()}/*'
31
+ action = 'rm-logs'
32
+ msg = 'd`Running|Ran ' + action + ' onto {size} pods'
33
+ pods = Devices.of(state).pod_names(state)
34
+ container = Devices.of(state).default_container(state)
35
+ with Pods.parallelize(pods, len(pods), msg=msg, action=action) as exec:
36
+ exec.map(lambda pod: Pods.exec(pod, container, state.namespace, cmd, show_out=True, text_color='gray'))
31
37
 
32
38
  return state
33
39
 
34
40
  def completion(self, state: ReplState):
35
41
  return super().completion(state)
36
42
 
37
- def help(self, _: ReplState):
38
- return f'{RmLogs.COMMAND}\t remove all qing log files under {log_dir()}'
43
+ def help(self, state: ReplState):
44
+ return super().help(state, f'remove all qing log files under {self.log_dir()}')
@@ -0,0 +1,38 @@
1
+ import os
2
+
3
+ from adam.commands.command import Command
4
+ from adam.repl_state import ReplState
5
+ from adam.utils import log2, log_dir
6
+
7
+ class RmLogsLocal(Command):
8
+ COMMAND = ':rm logs'
9
+
10
+ # the singleton pattern
11
+ def __new__(cls, *args, **kwargs):
12
+ if not hasattr(cls, 'instance'): cls.instance = super(RmLogsLocal, cls).__new__(cls)
13
+
14
+ return cls.instance
15
+
16
+ def __init__(self, successor: Command=None):
17
+ super().__init__(successor)
18
+
19
+ def command(self):
20
+ return RmLogsLocal.COMMAND
21
+
22
+ def run(self, cmd: str, state: ReplState):
23
+ if not(args := self.args(cmd)):
24
+ return super().run(cmd, state)
25
+
26
+ with self.validate(args, state) as (args, state):
27
+ cmd = f'rm -rf {log_dir()}/*'
28
+ log2(cmd, text_color='gray')
29
+ os.system(cmd)
30
+ log2()
31
+
32
+ return state
33
+
34
+ def completion(self, state: ReplState):
35
+ return super().completion(state)
36
+
37
+ def help(self, state: ReplState):
38
+ return super().help(state, f'remove all qing log files under {log_dir()}')
adam/commands/fs/shell.py CHANGED
@@ -37,5 +37,5 @@ class Shell(Command):
37
37
  def completion(self, state: ReplState):
38
38
  return super().completion(state)
39
39
 
40
- def help(self, _: ReplState):
41
- return f'{Shell.COMMAND}\t drop down to shell'
40
+ def help(self, state: ReplState):
41
+ return super().help(state, 'drop down to shell')
@@ -44,5 +44,5 @@ class ShowAdam(Command):
44
44
  def completion(self, state: ReplState):
45
45
  return super().completion(state)
46
46
 
47
- def help(self, _: ReplState):
48
- return f'{ShowAdam.COMMAND}\t show kaqing version'
47
+ def help(self, state: ReplState):
48
+ return super().help(state, 'show kaqing version')
@@ -29,5 +29,5 @@ class ShowHost(Command):
29
29
  def completion(self, state: ReplState):
30
30
  return super().completion(state)
31
31
 
32
- def help(self, _: ReplState):
33
- return f'{ShowHost.COMMAND}\t show host'
32
+ def help(self, state: ReplState):
33
+ return super().help(state, 'show host')
@@ -0,0 +1,39 @@
1
+ from adam.commands.fs.utils_fs import show_last_pod_results, show_last_results
2
+ from adam.commands.command import Command
3
+ from adam.repl_state import ReplState
4
+ from adam.utils import log_to_pods
5
+
6
+ class ShowLastResults(Command):
7
+ COMMAND = 'show last results'
8
+
9
+ # the singleton pattern
10
+ def __new__(cls, *args, **kwargs):
11
+ if not hasattr(cls, 'instance'): cls.instance = super(ShowLastResults, 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 ShowLastResults.COMMAND
20
+
21
+ def aliases(self):
22
+ return [':?']
23
+
24
+ def run(self, cmd: str, state: ReplState):
25
+ if not self.args(cmd):
26
+ return super().run(cmd, state)
27
+
28
+ if log_to_pods():
29
+ show_last_pod_results(state)
30
+ else:
31
+ show_last_results(state)
32
+
33
+ return state
34
+
35
+ def completion(self, state: ReplState):
36
+ return super().completion(state)
37
+
38
+ def help(self, state: ReplState):
39
+ return super().help(state, 'show results of last command')
@@ -0,0 +1,36 @@
1
+ from adam.commands import validate_args
2
+ from adam.commands.command import Command
3
+ from adam.commands.devices.devices import Devices
4
+ from adam.repl_state import ReplState, RequiredState
5
+
6
+ class Tail(Command):
7
+ COMMAND = 'tail'
8
+
9
+ # the singleton pattern
10
+ def __new__(cls, *args, **kwargs):
11
+ if not hasattr(cls, 'instance'): cls.instance = super(Tail, 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 Tail.COMMAND
20
+
21
+ def required(self):
22
+ return [RequiredState.CLUSTER_OR_POD, RequiredState.APP_APP, ReplState.P]
23
+
24
+ def run(self, cmd: str, state: ReplState):
25
+ if not(args := self.args(cmd)):
26
+ return super().run(cmd, state)
27
+
28
+ with self.validate(args, state) as (args, state):
29
+ with validate_args(args, state, name='file') as args:
30
+ return Devices.of(state).bash(state, state, ['tail', '-n', '10', args])
31
+
32
+ def completion(self, state: ReplState):
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
+
35
+ def help(self, state: ReplState):
36
+ return super().help(state, 'run tail command on the pod', args='<file>')
@@ -0,0 +1,46 @@
1
+ import os
2
+
3
+ from adam.commands import validate_args
4
+ from adam.commands.command import Command
5
+ from adam.repl_state import ReplState, RequiredState
6
+ from adam.utils import log2
7
+ from adam.utils_local import find_local_files
8
+
9
+ class TailLocal(Command):
10
+ COMMAND = ':tail'
11
+
12
+ # the singleton pattern
13
+ def __new__(cls, *args, **kwargs):
14
+ if not hasattr(cls, 'instance'): cls.instance = super(TailLocal, cls).__new__(cls)
15
+
16
+ return cls.instance
17
+
18
+ def __init__(self, successor: Command=None):
19
+ super().__init__(successor)
20
+
21
+ def command(self):
22
+ return TailLocal.COMMAND
23
+
24
+ def required(self):
25
+ return [RequiredState.CLUSTER_OR_POD, RequiredState.APP_APP, ReplState.P]
26
+
27
+ def run(self, cmd: str, state: ReplState):
28
+ if not(args := self.args(cmd)):
29
+ return super().run(cmd, state)
30
+
31
+ with self.validate(args, state) as (args, state):
32
+ with validate_args(args, state, name='file') as args:
33
+ cmd = f'tail -n 10 {args}'
34
+ log2(cmd)
35
+ log2()
36
+
37
+ os.system(cmd)
38
+ log2()
39
+
40
+ return state
41
+
42
+ def completion(self, state: ReplState):
43
+ return super().completion(state, lambda: {n: None for n in find_local_files(file_type='f', max_depth=1)}, auto='jit')
44
+
45
+ def help(self, state: ReplState):
46
+ return super().help(state, 'run tail command on local file system', args='<file>')