kaqing 2.0.184__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.
- adam/app_session.py +1 -1
- adam/batch.py +15 -15
- adam/checks/compactionstats.py +2 -1
- adam/checks/cpu.py +2 -1
- adam/checks/disk.py +6 -5
- adam/checks/gossip.py +2 -1
- adam/checks/memory.py +2 -1
- adam/checks/status.py +2 -1
- adam/commands/app/app.py +4 -4
- adam/commands/app/app_ping.py +2 -2
- adam/commands/{login.py → app/login.py} +2 -2
- adam/commands/app/show_app_actions.py +3 -3
- adam/commands/app/show_app_id.py +2 -2
- adam/commands/app/show_app_queues.py +2 -2
- adam/commands/{show → app}/show_login.py +3 -3
- adam/commands/app/utils_app.py +9 -1
- adam/commands/audit/audit.py +8 -24
- adam/commands/audit/audit_repair_tables.py +3 -3
- adam/commands/audit/audit_run.py +3 -3
- adam/commands/audit/completions_l.py +15 -0
- adam/commands/audit/show_last10.py +2 -3
- adam/commands/audit/show_slow10.py +2 -2
- adam/commands/audit/show_top10.py +2 -2
- adam/commands/bash/bash.py +3 -3
- adam/commands/bash/utils_bash.py +1 -1
- adam/commands/cassandra/download_cassandra_log.py +45 -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/{rollout.py → cassandra/rollout.py} +3 -3
- adam/commands/{show → cassandra}/show_cassandra_repairs.py +7 -5
- adam/commands/{show → cassandra}/show_cassandra_status.py +24 -17
- adam/commands/{show → cassandra}/show_cassandra_version.py +2 -2
- adam/commands/cassandra/show_processes.py +50 -0
- adam/commands/cassandra/show_storage.py +44 -0
- adam/commands/{watch.py → cassandra/watch.py} +2 -2
- adam/commands/cli/__init__.py +0 -0
- adam/commands/{cli_commands.py → cli/cli_commands.py} +6 -1
- adam/commands/{clipboard_copy.py → cli/clipboard_copy.py} +4 -4
- adam/commands/{show/show_commands.py → cli/show_cli_commands.py} +5 -5
- adam/commands/code.py +2 -2
- adam/commands/command.py +54 -14
- adam/commands/commands_utils.py +14 -6
- adam/commands/config/__init__.py +0 -0
- adam/commands/{param_get.py → config/param_get.py} +2 -2
- adam/commands/{param_set.py → config/param_set.py} +2 -2
- adam/commands/{show → config}/show_params.py +3 -3
- adam/commands/{alter_tables.py → cql/alter_tables.py} +3 -3
- adam/commands/cql/completions_c.py +29 -0
- adam/commands/cql/cqlsh.py +4 -8
- adam/commands/cql/utils_cql.py +36 -17
- 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/debug/show_offloaded_completes.py +45 -0
- adam/commands/deploy/code_start.py +2 -2
- adam/commands/deploy/code_stop.py +2 -2
- adam/commands/deploy/deploy_frontend.py +2 -2
- adam/commands/deploy/deploy_pg_agent.py +2 -2
- adam/commands/deploy/deploy_pod.py +2 -2
- adam/commands/deploy/undeploy_frontend.py +2 -2
- adam/commands/deploy/undeploy_pg_agent.py +2 -2
- adam/commands/deploy/undeploy_pod.py +2 -2
- adam/commands/devices/device.py +37 -11
- adam/commands/devices/device_app.py +7 -7
- adam/commands/devices/device_auit_log.py +2 -2
- adam/commands/devices/device_cass.py +6 -6
- adam/commands/devices/device_export.py +7 -4
- adam/commands/devices/device_postgres.py +19 -9
- adam/commands/devices/devices.py +1 -1
- adam/commands/diag/__init__.py +0 -0
- adam/commands/{check.py → diag/check.py} +3 -3
- adam/commands/diag/generate_report.py +52 -0
- adam/commands/{issues.py → diag/issues.py} +3 -2
- adam/commands/exit.py +2 -2
- adam/commands/export/clean_up_all_export_sessions.py +2 -2
- adam/commands/export/clean_up_export_sessions.py +2 -2
- adam/commands/export/completions_x.py +11 -0
- adam/commands/export/download_export_session.py +5 -5
- adam/commands/export/drop_export_database.py +2 -2
- adam/commands/export/drop_export_databases.py +2 -2
- adam/commands/export/export.py +3 -19
- adam/commands/export/export_databases.py +20 -11
- adam/commands/export/export_select.py +9 -34
- adam/commands/export/export_sessions.py +13 -11
- adam/commands/export/export_use.py +6 -6
- adam/commands/export/export_x_select.py +48 -0
- adam/commands/export/exporter.py +140 -53
- adam/commands/export/import_files.py +3 -7
- adam/commands/export/import_session.py +2 -6
- adam/commands/export/importer.py +12 -13
- adam/commands/export/importer_athena.py +15 -35
- adam/commands/export/importer_sqlite.py +19 -8
- adam/commands/export/show_column_counts.py +11 -12
- adam/commands/export/show_export_databases.py +4 -4
- adam/commands/export/show_export_session.py +5 -5
- adam/commands/export/show_export_sessions.py +4 -4
- adam/commands/export/utils_export.py +40 -25
- adam/commands/fs/__init__.py +0 -0
- adam/commands/{cat.py → fs/cat.py} +4 -4
- adam/commands/fs/cat_local.py +42 -0
- adam/commands/{cd.py → fs/cd.py} +4 -4
- adam/commands/{download_file.py → fs/download_file.py} +7 -7
- adam/commands/{find_files.py → fs/find_files.py} +7 -7
- adam/commands/{find_processes.py → fs/find_processes.py} +14 -22
- adam/commands/{head.py → fs/head.py} +5 -5
- adam/commands/fs/head_local.py +46 -0
- adam/commands/{ls.py → fs/ls.py} +4 -4
- adam/commands/fs/ls_local.py +40 -0
- adam/commands/{pwd.py → fs/pwd.py} +2 -2
- adam/commands/fs/rm.py +18 -0
- adam/commands/fs/rm_downloads.py +39 -0
- adam/commands/fs/rm_logs.py +44 -0
- adam/commands/fs/rm_logs_local.py +38 -0
- adam/commands/{shell.py → fs/shell.py} +2 -2
- adam/commands/{show → fs}/show_adam.py +3 -3
- adam/commands/{show → fs}/show_host.py +2 -2
- adam/commands/fs/show_last_results.py +39 -0
- adam/commands/fs/tail.py +36 -0
- adam/commands/fs/tail_local.py +46 -0
- adam/commands/fs/utils_fs.py +192 -0
- adam/commands/help.py +2 -2
- adam/commands/intermediate_command.py +3 -0
- adam/commands/kubectl.py +2 -2
- adam/commands/medusa/medusa_backup.py +2 -2
- adam/commands/medusa/medusa_restore.py +4 -18
- adam/commands/medusa/medusa_show_backupjobs.py +2 -2
- adam/commands/medusa/medusa_show_restorejobs.py +2 -2
- adam/commands/medusa/utils_medusa.py +15 -0
- adam/commands/nodetool/__init__.py +0 -0
- adam/commands/nodetool/nodetool.py +87 -0
- adam/commands/nodetool/utils_nodetool.py +44 -0
- adam/commands/postgres/completions_p.py +22 -0
- adam/commands/postgres/postgres.py +10 -20
- adam/commands/postgres/postgres_databases.py +3 -3
- adam/commands/postgres/postgres_ls.py +3 -3
- adam/commands/postgres/postgres_preview.py +2 -2
- adam/commands/postgres/utils_postgres.py +12 -2
- adam/commands/preview_table.py +3 -4
- adam/commands/reaper/reaper_forward.py +2 -2
- adam/commands/reaper/reaper_forward_stop.py +2 -2
- adam/commands/reaper/reaper_restart.py +2 -2
- adam/commands/reaper/reaper_run_abort.py +2 -2
- adam/commands/reaper/reaper_runs.py +14 -12
- adam/commands/reaper/reaper_runs_abort.py +2 -2
- adam/commands/reaper/reaper_schedule_activate.py +8 -4
- adam/commands/reaper/reaper_schedule_start.py +3 -4
- adam/commands/reaper/reaper_schedule_stop.py +3 -4
- adam/commands/reaper/reaper_schedules.py +2 -2
- adam/commands/reaper/reaper_status.py +2 -2
- adam/commands/reaper/utils_reaper.py +41 -6
- adam/commands/repair/repair_log.py +2 -2
- adam/commands/repair/repair_run.py +2 -2
- adam/commands/repair/repair_scan.py +2 -4
- adam/commands/repair/repair_stop.py +2 -3
- adam/commands/{show/show.py → show.py} +12 -11
- adam/config.py +4 -5
- adam/embedded_params.py +1 -1
- adam/repl.py +24 -10
- adam/repl_commands.py +68 -45
- adam/repl_session.py +16 -1
- adam/repl_state.py +16 -1
- adam/sql/async_executor.py +62 -0
- adam/sql/lark_completer.py +286 -0
- adam/sql/lark_parser.py +604 -0
- adam/sql/qingl.lark +1075 -0
- adam/sso/cred_cache.py +2 -5
- adam/utils.py +259 -82
- adam/utils_async_job.py +73 -0
- adam/utils_k8s/app_clusters.py +11 -4
- adam/utils_k8s/app_pods.py +10 -5
- adam/utils_k8s/cassandra_clusters.py +19 -7
- adam/utils_k8s/cassandra_nodes.py +16 -6
- adam/utils_k8s/k8s.py +9 -0
- 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 +189 -29
- adam/utils_k8s/statefulsets.py +5 -2
- adam/utils_local.py +78 -2
- adam/utils_repl/appendable_completer.py +6 -0
- adam/utils_repl/repl_completer.py +51 -4
- adam/utils_sqlite.py +3 -8
- adam/version.py +1 -1
- {kaqing-2.0.184.dist-info → kaqing-2.0.227.dist-info}/METADATA +1 -1
- kaqing-2.0.227.dist-info/RECORD +280 -0
- kaqing-2.0.227.dist-info/top_level.txt +2 -0
- teddy/__init__.py +0 -0
- teddy/lark_parser.py +436 -0
- teddy/lark_parser2.py +618 -0
- adam/commands/cql/cql_completions.py +0 -32
- adam/commands/export/export_select_x.py +0 -54
- adam/commands/logs.py +0 -37
- adam/commands/nodetool.py +0 -69
- adam/commands/postgres/psql_completions.py +0 -11
- adam/commands/report.py +0 -61
- adam/commands/restart.py +0 -60
- adam/commands/show/show_processes.py +0 -49
- adam/commands/show/show_storage.py +0 -42
- kaqing-2.0.184.dist-info/RECORD +0 -244
- kaqing-2.0.184.dist-info/top_level.txt +0 -1
- /adam/commands/{show → cassandra}/__init__.py +0 -0
- /adam/commands/{nodetool_commands.py → nodetool/nodetool_commands.py} +0 -0
- {kaqing-2.0.184.dist-info → kaqing-2.0.227.dist-info}/WHEEL +0 -0
- {kaqing-2.0.184.dist-info → kaqing-2.0.227.dist-info}/entry_points.txt +0 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import io
|
|
2
|
+
import os
|
|
2
3
|
import re
|
|
3
4
|
|
|
4
5
|
from adam.config import Config
|
|
5
|
-
from adam.
|
|
6
|
+
from adam.utils import ExecResult, creating_dir, log2, log_to_pods
|
|
6
7
|
from adam.repl_state import ReplState
|
|
7
|
-
from adam.utils_k8s.
|
|
8
|
-
from adam.utils_k8s.pods import log_prefix
|
|
8
|
+
from adam.utils_k8s.pods import Pods
|
|
9
9
|
from adam.utils_k8s.statefulsets import StatefulSets
|
|
10
|
+
from adam.utils_local import local_exec
|
|
10
11
|
|
|
11
12
|
class ImportSpec:
|
|
12
13
|
def __init__(self, table_name: str, session: str = None, files: list[str] = None, importer: str = None):
|
|
@@ -196,7 +197,7 @@ class ExportTableStatus:
|
|
|
196
197
|
statuses: list[ExportTableStatus] = []
|
|
197
198
|
|
|
198
199
|
status_in_whole = 'done'
|
|
199
|
-
log_files: list[str] = find_files(pod, namespace, f'{
|
|
200
|
+
log_files: list[str] = Pods.find_files(pod, 'cassandra', namespace, f'{table_log_dir(pod, namespace)}/{export_session}_*.log*', remote=log_to_pods())
|
|
200
201
|
|
|
201
202
|
for log_file in log_files:
|
|
202
203
|
status: ExportTableStatus = ExportTableStatus.from_log_file(pod, namespace, export_session, log_file)
|
|
@@ -211,7 +212,7 @@ class ExportTableStatus:
|
|
|
211
212
|
def get_csv_files_n_table(target_table: str):
|
|
212
213
|
db = f'{copy_session}_{target_table}'
|
|
213
214
|
csv_file = f'{csv_dir()}/{db}/*.csv'
|
|
214
|
-
csv_files: list[str] = find_files(pod, namespace, csv_file)
|
|
215
|
+
csv_files: list[str] = Pods.find_files(pod, 'cassandra', namespace, csv_file, remote=log_to_pods())
|
|
215
216
|
if csv_files:
|
|
216
217
|
table = target_table
|
|
217
218
|
m = re.match(f'{csv_dir()}/{db}/(.*).csv', csv_files[0])
|
|
@@ -221,7 +222,7 @@ class ExportTableStatus:
|
|
|
221
222
|
|
|
222
223
|
return csv_files, target_table
|
|
223
224
|
|
|
224
|
-
m = re.match(f'{
|
|
225
|
+
m = re.match(f'{table_log_dir(pod, namespace)}/{copy_session}_(.*?)\.(.*?)\.log(.*)', log_file)
|
|
225
226
|
if m:
|
|
226
227
|
keyspace = m.group(1)
|
|
227
228
|
target_table = m.group(2)
|
|
@@ -234,7 +235,11 @@ class ExportTableStatus:
|
|
|
234
235
|
|
|
235
236
|
# 4 rows exported to 1 files in 0 day, 0 hour, 0 minute, and 1.335 seconds.
|
|
236
237
|
pattern = 'rows exported to'
|
|
237
|
-
|
|
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())
|
|
242
|
+
|
|
238
243
|
if r.exit_code() == 0:
|
|
239
244
|
csv_files, table = get_csv_files_n_table(target_table)
|
|
240
245
|
if csv_files:
|
|
@@ -246,23 +251,6 @@ class ExportTableStatus:
|
|
|
246
251
|
|
|
247
252
|
return ExportTableStatus(None, None, 'unknown')
|
|
248
253
|
|
|
249
|
-
def csv_dir():
|
|
250
|
-
return Config().get('export.csv_dir', '/c3/cassandra/tmp')
|
|
251
|
-
|
|
252
|
-
def find_files(pod: str, namespace: str, pattern: str, mmin: int = 0):
|
|
253
|
-
if mmin:
|
|
254
|
-
r = CassandraNodes.exec(pod, namespace, f'find {pattern} -mmin -{mmin}', show_out=Config().is_debug(), shell='bash')
|
|
255
|
-
else:
|
|
256
|
-
r = CassandraNodes.exec(pod, namespace, f'find {pattern}', show_out=Config().is_debug(), shell='bash')
|
|
257
|
-
|
|
258
|
-
log_files = []
|
|
259
|
-
for line in r.stdout.split('\n'):
|
|
260
|
-
line = line.strip(' \r')
|
|
261
|
-
if line:
|
|
262
|
-
log_files.append(line)
|
|
263
|
-
|
|
264
|
-
return log_files
|
|
265
|
-
|
|
266
254
|
class GeneratorStream(io.RawIOBase):
|
|
267
255
|
def __init__(self, generator):
|
|
268
256
|
self._generator = generator
|
|
@@ -325,6 +313,7 @@ class PodPushHandler:
|
|
|
325
313
|
state = self.state
|
|
326
314
|
|
|
327
315
|
if not state.pod:
|
|
316
|
+
self.pushed = True
|
|
328
317
|
state.push()
|
|
329
318
|
|
|
330
319
|
if not self.pod:
|
|
@@ -340,4 +329,30 @@ class PodPushHandler:
|
|
|
340
329
|
return False
|
|
341
330
|
|
|
342
331
|
def state_with_pod(state: ReplState, pod: str = None):
|
|
343
|
-
return PodPushHandler(state, pod=pod)
|
|
332
|
+
return PodPushHandler(state, pod=pod)
|
|
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
|
+
|
|
340
|
+
def os_system_exec(cmd: str, show_out = False):
|
|
341
|
+
if show_out: log2(cmd)
|
|
342
|
+
|
|
343
|
+
os.system(cmd)
|
|
344
|
+
|
|
345
|
+
def csv_dir():
|
|
346
|
+
return Config().get('export.csv_dir', '/c3/cassandra/tmp')
|
|
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
|
+
|
|
354
|
+
def export_log_dir():
|
|
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'))
|
|
File without changes
|
|
@@ -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, pods=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
|
-
def help(self,
|
|
36
|
-
return
|
|
35
|
+
def help(self, state: ReplState):
|
|
36
|
+
return super().help(state, 'run cat command on the pod', args='<file>')
|
|
@@ -0,0 +1,42 @@
|
|
|
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 CatLocal(Command):
|
|
10
|
+
COMMAND = ':cat'
|
|
11
|
+
|
|
12
|
+
# the singleton pattern
|
|
13
|
+
def __new__(cls, *args, **kwargs):
|
|
14
|
+
if not hasattr(cls, 'instance'): cls.instance = super(CatLocal, 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 CatLocal.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
|
+
os.system(f'cat {args}')
|
|
34
|
+
log2()
|
|
35
|
+
|
|
36
|
+
return state
|
|
37
|
+
|
|
38
|
+
def completion(self, state: ReplState):
|
|
39
|
+
return super().completion(state, lambda: {n: None for n in find_local_files(file_type='f', max_depth=1)}, auto='jit')
|
|
40
|
+
|
|
41
|
+
def help(self, state: ReplState):
|
|
42
|
+
return super().help(state, 'run cat command on local file system', args='<file>')
|
adam/commands/{cd.py → fs/cd.py}
RENAMED
|
@@ -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
|
-
def help(self,
|
|
41
|
-
return
|
|
40
|
+
def help(self, state: ReplState):
|
|
41
|
+
return super().help(state, 'move around on the operational device hierarchy', args='<path> | ..')
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
from adam.commands import validate_args
|
|
2
2
|
from adam.commands.command import Command
|
|
3
3
|
from adam.commands.devices.devices import Devices
|
|
4
|
+
from adam.config import Config
|
|
5
|
+
from adam.utils_k8s.pod_exec_result import PodExecResult
|
|
4
6
|
from adam.repl_state import ReplState, RequiredState
|
|
5
7
|
from adam.utils import log2
|
|
6
8
|
from adam.utils_k8s.pods import Pods
|
|
@@ -29,8 +31,8 @@ class DownloadFile(Command):
|
|
|
29
31
|
|
|
30
32
|
with self.validate(args, state) as (args, state):
|
|
31
33
|
with validate_args(args, state, name='file'):
|
|
32
|
-
to_file = Pods.download_file(state.pod,
|
|
33
|
-
Devices.
|
|
34
|
+
to_file = Pods.download_file(Devices.of(state).pod(state),
|
|
35
|
+
Devices.of(state).default_container(state),
|
|
34
36
|
state.namespace,
|
|
35
37
|
args[0],
|
|
36
38
|
args[1] if len(args) > 1 else None)
|
|
@@ -39,9 +41,7 @@ class DownloadFile(Command):
|
|
|
39
41
|
return state
|
|
40
42
|
|
|
41
43
|
def completion(self, state: ReplState):
|
|
42
|
-
return super().completion(state, pods=Devices.
|
|
44
|
+
return super().completion(state, lambda: {f: None for f in Devices.of(state).files(state)}, pods=Devices.of(state).pods(state, '-'), auto='jit')
|
|
43
45
|
|
|
44
|
-
|
|
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]')
|
|
@@ -3,10 +3,10 @@ import os
|
|
|
3
3
|
from adam.commands.command import Command
|
|
4
4
|
from adam.repl_state import ReplState
|
|
5
5
|
from adam.utils import log2
|
|
6
|
-
from adam.utils_local import
|
|
6
|
+
from adam.utils_local import local_qing_dir
|
|
7
7
|
|
|
8
8
|
class FindLocalFiles(Command):
|
|
9
|
-
COMMAND = 'find
|
|
9
|
+
COMMAND = ':find file'
|
|
10
10
|
|
|
11
11
|
# the singleton pattern
|
|
12
12
|
def __new__(cls, *args, **kwargs):
|
|
@@ -28,14 +28,14 @@ class FindLocalFiles(Command):
|
|
|
28
28
|
cmd = 'find'
|
|
29
29
|
|
|
30
30
|
if not args:
|
|
31
|
-
cmd = f'find {
|
|
31
|
+
cmd = f'find {local_qing_dir()}'
|
|
32
32
|
elif len(args) == 1:
|
|
33
|
-
cmd = f"find {
|
|
33
|
+
cmd = f"find {local_qing_dir()} -name '{args[0]}'"
|
|
34
34
|
else:
|
|
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,
|
|
51
|
-
return
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
|
49
|
-
pids.append(f'{
|
|
40
|
+
for p in processes:
|
|
41
|
+
pids.append(f'{p.pid}@{p.pod}')
|
|
50
42
|
|
|
51
|
-
tabulize(
|
|
43
|
+
ProcessInfo.tabulize(processes)
|
|
52
44
|
log2()
|
|
53
45
|
log2(f'PIDS with {",".join(args)}: {",".join(pids)}')
|
|
54
46
|
|
|
@@ -62,15 +54,15 @@ class FindProcesses(Command):
|
|
|
62
54
|
|
|
63
55
|
pod = pid_n_pod[1]
|
|
64
56
|
|
|
65
|
-
log2(f'@{pod} kill -9 {pid}')
|
|
57
|
+
log2(f'@{pod} bash kill -9 {pid}')
|
|
66
58
|
|
|
67
59
|
with state_with_pod(state, pod) as state1:
|
|
68
|
-
Devices.
|
|
60
|
+
Devices.of(state).bash(state, state1, ['kill', '-9', pid])
|
|
69
61
|
|
|
70
|
-
return
|
|
62
|
+
return state
|
|
71
63
|
|
|
72
64
|
def completion(self, state: ReplState):
|
|
73
65
|
return super().completion(state)
|
|
74
66
|
|
|
75
|
-
def help(self,
|
|
76
|
-
return
|
|
67
|
+
def help(self, state: ReplState):
|
|
68
|
+
return super().help(state, 'find processes with words --kill kill matching processes', args='word... [-kill]')
|
|
@@ -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.
|
|
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
|
-
return super().completion(state, pods=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
|
-
def help(self,
|
|
36
|
-
return
|
|
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/{ls.py → fs/ls.py}
RENAMED
|
@@ -30,12 +30,12 @@ class Ls(Command):
|
|
|
30
30
|
state = copy.copy(state)
|
|
31
31
|
state.device = arg.replace(':', '')
|
|
32
32
|
|
|
33
|
-
Devices.
|
|
33
|
+
Devices.of(state).ls(cmd, state)
|
|
34
34
|
|
|
35
35
|
return state
|
|
36
36
|
|
|
37
37
|
def completion(self, state: ReplState):
|
|
38
|
-
return
|
|
38
|
+
return super().completion(state, {'&': None}, pods=Devices.of(state).pods(state, '-'))
|
|
39
39
|
|
|
40
|
-
def help(self,
|
|
41
|
-
return
|
|
40
|
+
def help(self, state: ReplState):
|
|
41
|
+
return super().help(state, 'list apps, envs, clusters, nodes, pg hosts/databases or export databases', args='[device:]')
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from adam.commands.command import Command
|
|
4
|
+
from adam.repl_state import ReplState
|
|
5
|
+
from adam.utils import log2
|
|
6
|
+
from adam.utils_local import local_qing_dir
|
|
7
|
+
|
|
8
|
+
class LsLocal(Command):
|
|
9
|
+
COMMAND = ':ls'
|
|
10
|
+
|
|
11
|
+
# the singleton pattern
|
|
12
|
+
def __new__(cls, *args, **kwargs):
|
|
13
|
+
if not hasattr(cls, 'instance'): cls.instance = super(LsLocal, 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 LsLocal.COMMAND
|
|
22
|
+
|
|
23
|
+
def run(self, cmd: str, state: ReplState):
|
|
24
|
+
if not(args := self.args(cmd)):
|
|
25
|
+
return super().run(cmd, state)
|
|
26
|
+
|
|
27
|
+
with self.validate(args, state) as (args, state):
|
|
28
|
+
if args:
|
|
29
|
+
os.system(f'ls {args}')
|
|
30
|
+
else:
|
|
31
|
+
os.system(f'ls {local_qing_dir()}')
|
|
32
|
+
log2()
|
|
33
|
+
|
|
34
|
+
return state
|
|
35
|
+
|
|
36
|
+
def completion(self, state: ReplState):
|
|
37
|
+
return super().completion(state)
|
|
38
|
+
|
|
39
|
+
def help(self, state: ReplState):
|
|
40
|
+
return super().help(state, 'list files on local system', args='[dir]')
|
|
@@ -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,
|
|
45
|
-
return
|
|
44
|
+
def help(self, state: ReplState):
|
|
45
|
+
return super().help(state, 'print current working directories')
|
adam/commands/fs/rm.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from adam.commands.fs.rm_downloads import RmDownloads
|
|
2
|
+
from adam.commands.fs.rm_logs_local import RmLogsLocal
|
|
3
|
+
from adam.commands.intermediate_command import IntermediateCommand
|
|
4
|
+
|
|
5
|
+
class RmLocal(IntermediateCommand):
|
|
6
|
+
COMMAND = ':rm'
|
|
7
|
+
|
|
8
|
+
# the singleton pattern
|
|
9
|
+
def __new__(cls, *args, **kwargs):
|
|
10
|
+
if not hasattr(cls, 'instance'): cls.instance = super(RmLocal, cls).__new__(cls)
|
|
11
|
+
|
|
12
|
+
return cls.instance
|
|
13
|
+
|
|
14
|
+
def command(self):
|
|
15
|
+
return RmLocal.COMMAND
|
|
16
|
+
|
|
17
|
+
def cmd_list(self):
|
|
18
|
+
return [RmDownloads(), RmLogsLocal()]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from adam.commands.command import Command
|
|
4
|
+
from adam.repl_state import ReplState
|
|
5
|
+
from adam.utils import log2
|
|
6
|
+
from adam.utils_local import local_downloads_dir
|
|
7
|
+
|
|
8
|
+
class RmDownloads(Command):
|
|
9
|
+
COMMAND = ':rm downloads'
|
|
10
|
+
|
|
11
|
+
# the singleton pattern
|
|
12
|
+
def __new__(cls, *args, **kwargs):
|
|
13
|
+
if not hasattr(cls, 'instance'): cls.instance = super(RmDownloads, 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 RmDownloads.COMMAND
|
|
22
|
+
|
|
23
|
+
def run(self, cmd: str, state: ReplState):
|
|
24
|
+
if not(args := self.args(cmd)):
|
|
25
|
+
return super().run(cmd, state)
|
|
26
|
+
|
|
27
|
+
with self.validate(args, state) as (args, state):
|
|
28
|
+
cmd = f'rm -rf {local_downloads_dir()}/*'
|
|
29
|
+
log2(cmd)
|
|
30
|
+
os.system(cmd)
|
|
31
|
+
log2()
|
|
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, f'remove all downloads files under {local_downloads_dir()}')
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from adam.commands.command import Command
|
|
4
|
+
from adam.commands.devices.devices import Devices
|
|
5
|
+
from adam.config import Config
|
|
6
|
+
from adam.repl_state import ReplState
|
|
7
|
+
from adam.utils import log2, log_dir
|
|
8
|
+
from adam.utils_k8s.pods import Pods
|
|
9
|
+
|
|
10
|
+
class RmLogs(Command):
|
|
11
|
+
COMMAND = 'rm logs'
|
|
12
|
+
|
|
13
|
+
# the singleton pattern
|
|
14
|
+
def __new__(cls, *args, **kwargs):
|
|
15
|
+
if not hasattr(cls, 'instance'): cls.instance = super(RmLogs, 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 RmLogs.COMMAND
|
|
24
|
+
|
|
25
|
+
def run(self, cmd: str, state: ReplState):
|
|
26
|
+
if not(args := self.args(cmd)):
|
|
27
|
+
return super().run(cmd, state)
|
|
28
|
+
|
|
29
|
+
with self.validate(args, state) as (args, state):
|
|
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'))
|
|
37
|
+
|
|
38
|
+
return state
|
|
39
|
+
|
|
40
|
+
def completion(self, state: ReplState):
|
|
41
|
+
return super().completion(state)
|
|
42
|
+
|
|
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()}')
|
|
@@ -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,
|
|
41
|
-
return
|
|
40
|
+
def help(self, state: ReplState):
|
|
41
|
+
return super().help(state, 'drop down to shell')
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import sys
|
|
2
2
|
import os
|
|
3
3
|
|
|
4
|
-
from adam.utils import tabulize
|
|
4
|
+
from adam.utils import tabulize
|
|
5
5
|
|
|
6
6
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
7
7
|
|
|
@@ -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,
|
|
48
|
-
return
|
|
47
|
+
def help(self, state: ReplState):
|
|
48
|
+
return super().help(state, 'show kaqing version')
|