kaqing 2.0.145__py3-none-any.whl → 2.0.172__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/__init__.py +0 -2
- adam/app_session.py +8 -11
- adam/batch.py +3 -3
- adam/checks/check_utils.py +14 -46
- adam/checks/cpu.py +7 -1
- adam/checks/cpu_metrics.py +52 -0
- adam/checks/disk.py +2 -3
- adam/columns/columns.py +3 -1
- adam/columns/cpu.py +3 -1
- adam/columns/cpu_metrics.py +22 -0
- adam/columns/memory.py +3 -4
- adam/commands/__init__.py +18 -0
- adam/commands/alter_tables.py +43 -47
- adam/commands/audit/audit.py +22 -23
- adam/commands/audit/audit_repair_tables.py +14 -17
- adam/commands/audit/audit_run.py +15 -23
- adam/commands/audit/show_last10.py +10 -13
- adam/commands/audit/show_slow10.py +10 -13
- adam/commands/audit/show_top10.py +10 -13
- adam/commands/audit/utils_show_top10.py +2 -3
- adam/commands/bash/__init__.py +5 -0
- adam/commands/bash/bash.py +7 -104
- adam/commands/bash/utils_bash.py +16 -0
- adam/commands/cat.py +13 -19
- adam/commands/cd.py +8 -10
- adam/commands/check.py +20 -21
- adam/commands/cli_commands.py +2 -3
- adam/commands/code.py +20 -23
- adam/commands/command.py +120 -39
- adam/commands/commands_utils.py +8 -17
- adam/commands/cp.py +33 -39
- adam/commands/cql/cql_completions.py +9 -4
- adam/commands/cql/cqlsh.py +10 -30
- adam/commands/cql/{cql_utils.py → utils_cql.py} +149 -15
- adam/commands/deploy/code_start.py +7 -10
- adam/commands/deploy/code_stop.py +4 -21
- adam/commands/deploy/code_utils.py +3 -3
- adam/commands/deploy/deploy.py +4 -27
- adam/commands/deploy/deploy_frontend.py +14 -17
- adam/commands/deploy/deploy_pg_agent.py +2 -5
- adam/commands/deploy/deploy_pod.py +64 -68
- adam/commands/deploy/undeploy.py +4 -27
- adam/commands/deploy/undeploy_frontend.py +4 -7
- adam/commands/deploy/undeploy_pg_agent.py +4 -7
- adam/commands/deploy/undeploy_pod.py +9 -12
- adam/commands/devices/device.py +93 -2
- adam/commands/devices/device_app.py +37 -10
- adam/commands/devices/device_auit_log.py +8 -2
- adam/commands/devices/device_cass.py +47 -7
- adam/commands/devices/device_export.py +2 -2
- adam/commands/devices/device_postgres.py +41 -6
- adam/commands/exit.py +1 -4
- adam/commands/export/clean_up_all_export_sessions.py +37 -0
- adam/commands/export/clean_up_export_sessions.py +18 -7
- adam/commands/export/drop_export_database.py +15 -18
- adam/commands/export/drop_export_databases.py +6 -9
- adam/commands/export/export.py +8 -38
- adam/commands/export/export_databases.py +16 -12
- adam/commands/export/export_handlers.py +71 -0
- adam/commands/export/export_select.py +33 -24
- adam/commands/export/export_use.py +12 -15
- adam/commands/export/exporter.py +37 -48
- adam/commands/export/import_session.py +4 -32
- adam/commands/export/importer_athena.py +4 -7
- adam/commands/export/importer_sqlite.py +19 -27
- adam/commands/export/show_column_counts.py +13 -22
- adam/commands/export/show_export_databases.py +3 -6
- adam/commands/export/show_export_session.py +10 -13
- adam/commands/export/show_export_sessions.py +8 -11
- adam/commands/export/utils_export.py +24 -1
- adam/commands/intermediate_command.py +49 -0
- adam/commands/issues.py +11 -43
- adam/commands/kubectl.py +3 -6
- adam/commands/login.py +22 -24
- adam/commands/logs.py +3 -6
- adam/commands/ls.py +8 -9
- adam/commands/medusa/medusa.py +4 -22
- adam/commands/medusa/medusa_backup.py +20 -24
- adam/commands/medusa/medusa_restore.py +29 -33
- adam/commands/medusa/medusa_show_backupjobs.py +14 -18
- adam/commands/medusa/medusa_show_restorejobs.py +11 -18
- adam/commands/nodetool.py +6 -15
- adam/commands/param_get.py +11 -12
- adam/commands/param_set.py +9 -10
- adam/commands/postgres/postgres.py +29 -37
- adam/commands/postgres/postgres_context.py +47 -23
- adam/commands/postgres/postgres_ls.py +4 -8
- adam/commands/postgres/postgres_preview.py +5 -9
- adam/commands/postgres/psql_completions.py +1 -1
- adam/commands/postgres/utils_postgres.py +66 -0
- adam/commands/preview_table.py +5 -44
- adam/commands/pwd.py +13 -16
- adam/commands/reaper/reaper.py +4 -27
- adam/commands/reaper/reaper_forward.py +48 -55
- adam/commands/reaper/reaper_forward_session.py +6 -0
- adam/commands/reaper/reaper_forward_stop.py +10 -16
- adam/commands/reaper/reaper_restart.py +7 -14
- adam/commands/reaper/reaper_run_abort.py +11 -30
- adam/commands/reaper/reaper_runs.py +42 -57
- adam/commands/reaper/reaper_runs_abort.py +29 -49
- adam/commands/reaper/reaper_schedule_activate.py +11 -30
- adam/commands/reaper/reaper_schedule_start.py +10 -29
- adam/commands/reaper/reaper_schedule_stop.py +10 -29
- adam/commands/reaper/reaper_schedules.py +4 -14
- adam/commands/reaper/reaper_status.py +8 -16
- adam/commands/reaper/utils_reaper.py +196 -0
- adam/commands/repair/repair.py +4 -22
- adam/commands/repair/repair_log.py +5 -11
- adam/commands/repair/repair_run.py +27 -34
- adam/commands/repair/repair_scan.py +32 -38
- adam/commands/repair/repair_stop.py +5 -11
- adam/commands/report.py +27 -29
- adam/commands/restart.py +25 -26
- adam/commands/rollout.py +19 -24
- adam/commands/shell.py +10 -4
- adam/commands/show/show.py +10 -26
- adam/commands/show/show_cassandra_repairs.py +35 -0
- adam/commands/show/show_cassandra_status.py +32 -43
- adam/commands/show/show_cassandra_version.py +5 -18
- adam/commands/show/show_commands.py +19 -24
- adam/commands/show/show_host.py +1 -1
- adam/commands/show/show_login.py +20 -27
- adam/commands/show/show_processes.py +15 -19
- adam/commands/show/show_storage.py +10 -20
- adam/commands/watch.py +26 -29
- adam/config.py +4 -16
- adam/embedded_params.py +1 -1
- adam/log.py +4 -4
- adam/pod_exec_result.py +3 -3
- adam/repl.py +29 -32
- adam/repl_commands.py +11 -11
- adam/repl_state.py +52 -26
- adam/sql/sql_completer.py +4 -6
- adam/sql/sql_state_machine.py +21 -14
- adam/sso/authn_ad.py +6 -8
- adam/sso/authn_okta.py +4 -6
- adam/sso/cred_cache.py +3 -5
- adam/sso/idp.py +9 -12
- adam/utils.py +393 -33
- adam/utils_athena.py +14 -13
- adam/utils_audits.py +12 -12
- adam/utils_issues.py +32 -0
- adam/utils_k8s/app_clusters.py +13 -18
- adam/utils_k8s/app_pods.py +2 -0
- adam/utils_k8s/cassandra_clusters.py +21 -18
- adam/utils_k8s/custom_resources.py +16 -17
- adam/utils_k8s/ingresses.py +2 -2
- adam/utils_k8s/jobs.py +7 -11
- adam/utils_k8s/k8s.py +87 -0
- adam/utils_k8s/pods.py +14 -76
- adam/utils_k8s/secrets.py +4 -4
- adam/utils_k8s/service_accounts.py +5 -4
- adam/utils_k8s/services.py +2 -2
- adam/utils_k8s/statefulsets.py +1 -12
- adam/utils_repl/state_machine.py +3 -3
- adam/utils_sqlite.py +78 -42
- adam/version.py +1 -1
- {kaqing-2.0.145.dist-info → kaqing-2.0.172.dist-info}/METADATA +1 -1
- kaqing-2.0.172.dist-info/RECORD +230 -0
- adam/commands/app.py +0 -67
- adam/commands/app_ping.py +0 -44
- adam/commands/export/clean_up_export_session.py +0 -53
- adam/commands/postgres/postgres_utils.py +0 -31
- adam/commands/reaper/reaper_session.py +0 -159
- adam/commands/show/show_app_actions.py +0 -56
- adam/commands/show/show_app_id.py +0 -47
- adam/commands/show/show_app_queues.py +0 -45
- adam/commands/show/show_repairs.py +0 -47
- kaqing-2.0.145.dist-info/RECORD +0 -227
- {kaqing-2.0.145.dist-info → kaqing-2.0.172.dist-info}/WHEEL +0 -0
- {kaqing-2.0.145.dist-info → kaqing-2.0.172.dist-info}/entry_points.txt +0 -0
- {kaqing-2.0.145.dist-info → kaqing-2.0.172.dist-info}/top_level.txt +0 -0
adam/commands/audit/audit_run.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import concurrent
|
|
2
|
-
|
|
3
1
|
from adam.commands.command import Command
|
|
4
2
|
from adam.config import Config
|
|
5
3
|
from adam.repl_state import ReplState
|
|
@@ -30,29 +28,23 @@ class AuditRun(Command):
|
|
|
30
28
|
if not(args := self.args(cmd)):
|
|
31
29
|
return super().run(cmd, state)
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
executor.submit(Athena.run_query, f'MSCK REPAIR TABLE {table}', None,)
|
|
46
|
-
else:
|
|
47
|
-
log2(f'No new clusters were found.')
|
|
31
|
+
with self.validate(args, state) as (args, state):
|
|
32
|
+
meta: AuditMeta = Audits.get_meta()
|
|
33
|
+
clusters = Audits.find_new_clusters(meta.cluster_last_checked)
|
|
34
|
+
Audits.put_meta(Audits.ADD_CLUSTERS, meta, clusters=clusters)
|
|
35
|
+
if clusters:
|
|
36
|
+
log2(f'Added {len(clusters)} new clusters.')
|
|
37
|
+
tables = Config().get('audit.athena.repair-cluster-tables', 'cluster').split(',')
|
|
38
|
+
with Audits.offload() as exec:
|
|
39
|
+
for table in tables:
|
|
40
|
+
exec.submit(Athena.query, f'MSCK REPAIR TABLE {table}', None,)
|
|
41
|
+
else:
|
|
42
|
+
log2(f'No new clusters were found.')
|
|
48
43
|
|
|
49
|
-
|
|
44
|
+
return state
|
|
50
45
|
|
|
51
46
|
def completion(self, state: ReplState):
|
|
52
|
-
|
|
53
|
-
return super().completion(state)
|
|
54
|
-
|
|
55
|
-
return {}
|
|
47
|
+
return super().completion(state)
|
|
56
48
|
|
|
57
49
|
def help(self, _: ReplState):
|
|
58
|
-
return f"{AuditRun.COMMAND}
|
|
50
|
+
return f"{AuditRun.COMMAND}\t run"
|
|
@@ -27,21 +27,18 @@ class ShowLast10(Command):
|
|
|
27
27
|
if not(args := self.args(cmd)):
|
|
28
28
|
return super().run(cmd, state)
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return state
|
|
33
|
-
|
|
34
|
-
limit, date_condition = extract_limit_and_duration(args)
|
|
30
|
+
with self.validate(args, state) as (args, state):
|
|
31
|
+
limit, date_condition = extract_limit_and_duration(args)
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
query = '\n '.join([
|
|
34
|
+
"SELECT * FROM audit",
|
|
35
|
+
f"WHERE drive <> 'z' and ({date_condition})",
|
|
36
|
+
f"ORDER BY ts DESC LIMIT {limit};"])
|
|
37
|
+
log2(query)
|
|
38
|
+
log2()
|
|
39
|
+
Athena.run_query(query)
|
|
43
40
|
|
|
44
|
-
|
|
41
|
+
return state
|
|
45
42
|
|
|
46
43
|
def completion(self, _: ReplState):
|
|
47
44
|
|
|
@@ -27,21 +27,18 @@ class ShowSlow10(Command):
|
|
|
27
27
|
if not(args := self.args(cmd)):
|
|
28
28
|
return super().run(cmd, state)
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return state
|
|
33
|
-
|
|
34
|
-
limit, date_condition = extract_limit_and_duration(args)
|
|
30
|
+
with self.validate(args, state) as (args, state):
|
|
31
|
+
limit, date_condition = extract_limit_and_duration(args)
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
query = '\n '.join([
|
|
34
|
+
"SELECT * FROM audit",
|
|
35
|
+
f"WHERE drive <> 'z' and ({date_condition})",
|
|
36
|
+
f"ORDER BY CAST(duration AS REAL) DESC LIMIT {limit};"])
|
|
37
|
+
log2(query)
|
|
38
|
+
log2()
|
|
39
|
+
Athena.run_query(query)
|
|
43
40
|
|
|
44
|
-
|
|
41
|
+
return state
|
|
45
42
|
|
|
46
43
|
def completion(self, _: ReplState):
|
|
47
44
|
return {}
|
|
@@ -26,20 +26,17 @@ class ShowTop10(Command):
|
|
|
26
26
|
if not(args := self.args(cmd)):
|
|
27
27
|
return super().run(cmd, state)
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
log2(query)
|
|
39
|
-
log2()
|
|
40
|
-
Athena.run_query(query)
|
|
29
|
+
with self.validate(args, state) as (args, state):
|
|
30
|
+
limit, date_condition = extract_limit_and_duration(args)
|
|
31
|
+
query = '\n '.join([
|
|
32
|
+
"SELECT min(c) AS cluster, line, COUNT(*) AS cnt, avg(CAST(duration AS REAL)) AS duration",
|
|
33
|
+
f"FROM audit WHERE drive <> 'z' and ({date_condition})",
|
|
34
|
+
f"GROUP BY line ORDER BY cnt DESC LIMIT {limit};"])
|
|
35
|
+
log2(query)
|
|
36
|
+
log2()
|
|
37
|
+
Athena.run_query(query)
|
|
41
38
|
|
|
42
|
-
|
|
39
|
+
return state
|
|
43
40
|
|
|
44
41
|
def completion(self, _: ReplState):
|
|
45
42
|
return {}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from datetime import datetime, timedelta
|
|
2
2
|
|
|
3
|
+
from adam.utils import log_exc
|
|
3
4
|
from adam.utils_audits import Audits
|
|
4
5
|
from adam.utils_repl.automata_completer import AutomataCompleter
|
|
5
6
|
from adam.utils_repl.state_machine import StateMachine
|
|
@@ -8,10 +9,8 @@ def extract_limit_and_duration(args: list[str]) -> tuple[int, datetime]:
|
|
|
8
9
|
limit = 10
|
|
9
10
|
_from = datetime.now() - timedelta(days=30)
|
|
10
11
|
if args:
|
|
11
|
-
|
|
12
|
+
with log_exc():
|
|
12
13
|
limit = int(args[0])
|
|
13
|
-
except:
|
|
14
|
-
pass
|
|
15
14
|
|
|
16
15
|
if len(args) > 2 and args[1] == 'over':
|
|
17
16
|
if args[2] == 'day':
|
adam/commands/bash/__init__.py
CHANGED
adam/commands/bash/bash.py
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
from
|
|
2
|
-
|
|
3
|
-
from adam.commands.bash.bash_completer import BashCompleter
|
|
1
|
+
from adam.commands.bash import bash
|
|
4
2
|
from adam.commands.command import Command
|
|
5
|
-
from adam.
|
|
6
|
-
from adam.
|
|
7
|
-
from adam.utils_k8s.cassandra_clusters import CassandraClusters
|
|
8
|
-
from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
9
|
-
from adam.pod_exec_result import PodExecResult
|
|
10
|
-
from adam.repl_state import BashSession, ReplState, RequiredState
|
|
11
|
-
from adam.utils_k8s.pods import Pods
|
|
12
|
-
from adam.utils_k8s.statefulsets import StatefulSets
|
|
13
|
-
from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
3
|
+
from adam.commands.devices.devices import Devices
|
|
4
|
+
from adam.repl_state import ReplState, RequiredState
|
|
14
5
|
|
|
15
6
|
class Bash(Command):
|
|
16
7
|
COMMAND = 'bash'
|
|
@@ -34,100 +25,12 @@ class Bash(Command):
|
|
|
34
25
|
if not(args := self.args(cmd)):
|
|
35
26
|
return super().run(cmd, s0)
|
|
36
27
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def _run(state_changed: bool, cli: Callable[[str], None]):
|
|
42
|
-
if state.in_repl:
|
|
43
|
-
if state_changed:
|
|
44
|
-
r = self.exec_with_dir(state, args)
|
|
45
|
-
else:
|
|
46
|
-
r = self.exec_with_dir(s0, args)
|
|
47
|
-
|
|
48
|
-
if not r:
|
|
49
|
-
state.exit_bash()
|
|
50
|
-
|
|
51
|
-
return 'inconsistent pwd'
|
|
52
|
-
|
|
53
|
-
return r
|
|
54
|
-
else:
|
|
55
|
-
cli(' '.join(args))
|
|
56
|
-
|
|
57
|
-
return state
|
|
58
|
-
|
|
59
|
-
if state.device == ReplState.A:
|
|
60
|
-
def cli(command: str):
|
|
61
|
-
if state.app_pod:
|
|
62
|
-
AppPods.exec(state.app_pod, state.namespace, command, show_out=True)
|
|
63
|
-
elif state.app_app:
|
|
64
|
-
AppClusters.exec(AppPods.pod_names(state.namespace, state.app_env, state.app_app), state.namespace, command, action='bash', show_out=True)
|
|
65
|
-
|
|
66
|
-
return _run(s0.app_env != state.app_env or s0.app_app != state.app_app or s0.app_pod != state.app_pod, cli)
|
|
67
|
-
elif state.device == ReplState.P:
|
|
68
|
-
def cli(command: str):
|
|
69
|
-
Pods.exec(state.app_pod, 'ops', state.namespace, command, show_out=True)
|
|
70
|
-
|
|
71
|
-
return _run(s0.pg_path != state.pg_path, cli)
|
|
72
|
-
|
|
73
|
-
def cli(command: str):
|
|
74
|
-
if state.pod:
|
|
75
|
-
CassandraNodes.exec(state.pod, state.namespace, command, show_out=True)
|
|
76
|
-
elif state.sts:
|
|
77
|
-
CassandraClusters.exec(state.sts, state.namespace, command, action='bash', show_out=True)
|
|
78
|
-
|
|
79
|
-
return _run(s0.sts != state.sts or s0.pod != state.pod, cli)
|
|
80
|
-
|
|
81
|
-
def exec_with_dir(self, state: ReplState, args: list[str]) -> list[PodExecResult]:
|
|
82
|
-
session_just_created = False
|
|
83
|
-
if not args:
|
|
84
|
-
session_just_created = True
|
|
85
|
-
session = BashSession(state.device)
|
|
86
|
-
state.enter_bash(session)
|
|
87
|
-
|
|
88
|
-
if state.bash_session:
|
|
89
|
-
if args != ['pwd']:
|
|
90
|
-
if args:
|
|
91
|
-
args.append('&&')
|
|
92
|
-
args.extend(['pwd', '>', f'/tmp/.qing-{state.bash_session.session_id}'])
|
|
93
|
-
|
|
94
|
-
if not session_just_created:
|
|
95
|
-
if pwd := state.bash_session.pwd(state):
|
|
96
|
-
args = ['cd', pwd, '&&'] + args
|
|
97
|
-
|
|
98
|
-
command = ' '.join(args)
|
|
99
|
-
|
|
100
|
-
rs = []
|
|
101
|
-
|
|
102
|
-
if state.device == ReplState.A:
|
|
103
|
-
if state.app_pod:
|
|
104
|
-
rs = [AppPods.exec(state.app_pod, state.namespace, command,
|
|
105
|
-
show_out=not session_just_created, shell='bash')]
|
|
106
|
-
elif state.app_app:
|
|
107
|
-
rs = AppClusters.exec(AppPods.pod_names(state.namespace, state.app_env, state.app_app), state.namespace, command, action='bash',
|
|
108
|
-
show_out=not session_just_created, shell='bash')
|
|
109
|
-
elif state.device == ReplState.P:
|
|
110
|
-
rs = [Pods.exec(state.app_pod, 'ops', state.namespace, command,
|
|
111
|
-
show_out=not session_just_created, shell='bash')]
|
|
112
|
-
else:
|
|
113
|
-
if state.pod:
|
|
114
|
-
rs = [CassandraNodes.exec(state.pod, state.namespace, command,
|
|
115
|
-
show_out=not session_just_created, shell='bash')]
|
|
116
|
-
elif state.sts:
|
|
117
|
-
rs = CassandraClusters.exec(state.sts, state.namespace, command, action='bash',
|
|
118
|
-
show_out=not session_just_created, shell='bash')
|
|
119
|
-
|
|
120
|
-
return rs
|
|
28
|
+
with self.validate(args, s0) as (args, s1):
|
|
29
|
+
with bash(s0, s1) as exec:
|
|
30
|
+
return exec(args)
|
|
121
31
|
|
|
122
32
|
def completion(self, state: ReplState):
|
|
123
|
-
|
|
124
|
-
return { Bash.COMMAND: BashCompleter(lambda: []) } | \
|
|
125
|
-
{f'@{p}': {Bash.COMMAND: BashCompleter(lambda: [])} for p in AppPods.pod_names(state.namespace, state.app_env, state.app_app)}
|
|
126
|
-
elif state.sts:
|
|
127
|
-
return { Bash.COMMAND: BashCompleter(lambda: []) } | \
|
|
128
|
-
{f'@{p}': {Bash.COMMAND: BashCompleter(lambda: [])} for p in StatefulSets.pod_names(state.sts, state.namespace)}
|
|
129
|
-
|
|
130
|
-
return {}
|
|
33
|
+
return Devices.device(state).bash_completion(Bash.COMMAND, state, default = {})
|
|
131
34
|
|
|
132
35
|
def help(self, _: ReplState):
|
|
133
36
|
return f'{Bash.COMMAND} [pod-name] [bash-commands] [&]\t run bash on the Cassandra nodes'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from adam.commands.devices.devices import Devices
|
|
2
|
+
from adam.repl_state import ReplState
|
|
3
|
+
|
|
4
|
+
class BashHandler:
|
|
5
|
+
def __init__(self, s0: ReplState, s1: ReplState):
|
|
6
|
+
self.s0 = s0
|
|
7
|
+
self.s1 = s1
|
|
8
|
+
|
|
9
|
+
def __enter__(self):
|
|
10
|
+
return self.exec
|
|
11
|
+
|
|
12
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
13
|
+
return False
|
|
14
|
+
|
|
15
|
+
def exec(self, args: list[str]):
|
|
16
|
+
return Devices.device(self.s1).bash(self.s0, self.s1, args)
|
adam/commands/cat.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
from adam.commands.bash.bash import Bash
|
|
2
1
|
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.devices.devices import Devices
|
|
3
3
|
from adam.repl_state import ReplState, RequiredState
|
|
4
4
|
from adam.utils import log2
|
|
5
5
|
from adam.utils_k8s.app_pods import AppPods
|
|
@@ -27,28 +27,22 @@ class Cat(Command):
|
|
|
27
27
|
if not(args := self.args(cmd)):
|
|
28
28
|
return super().run(cmd, state)
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
with self.validate(args, state) as (args, state):
|
|
31
|
+
if len(args) < 1:
|
|
32
|
+
if state.in_repl:
|
|
33
|
+
log2('File is required.')
|
|
34
|
+
log2()
|
|
35
|
+
else:
|
|
36
|
+
log2('* File is missing.')
|
|
37
|
+
Command.display_help()
|
|
31
38
|
|
|
32
|
-
|
|
33
|
-
if state.in_repl:
|
|
34
|
-
log2('File is required.')
|
|
35
|
-
log2()
|
|
36
|
-
else:
|
|
37
|
-
log2('* File is missing.')
|
|
38
|
-
Command.display_help()
|
|
39
|
+
return 'command-missing'
|
|
39
40
|
|
|
40
|
-
return
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return Bash().run('bash ' + cmd, state)
|
|
41
|
+
return Devices.device(state).cat(cmd, state)
|
|
44
42
|
|
|
45
43
|
def completion(self, state: ReplState):
|
|
46
|
-
if
|
|
47
|
-
return
|
|
48
|
-
{f'@{p}': {Cat.COMMAND: None} for p in AppPods.pod_names(state.namespace, state.app_env, state.app_app)}
|
|
49
|
-
elif state.device == ReplState.C and state.sts:
|
|
50
|
-
return super().completion(state) | \
|
|
51
|
-
{f'@{p}': {Cat.COMMAND: None} for p in StatefulSets.pod_names(state.sts, state.namespace)}
|
|
44
|
+
if super().completion(state):
|
|
45
|
+
return Devices.device(state).cat_completion(Cat.COMMAND, state, default={})
|
|
52
46
|
|
|
53
47
|
return {}
|
|
54
48
|
|
adam/commands/cd.py
CHANGED
|
@@ -25,18 +25,16 @@ class Cd(Command):
|
|
|
25
25
|
if not(args := self.args(cmd)):
|
|
26
26
|
return super().run(cmd, state)
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if len(args) < 2:
|
|
32
|
-
return state
|
|
28
|
+
with self.validate(args, state, apply=False) as (args, state):
|
|
29
|
+
if len(args) < 2:
|
|
30
|
+
return state
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
device: Device = Devices.device(state)
|
|
33
|
+
arg = args[1]
|
|
34
|
+
for dir in arg.split('/'):
|
|
35
|
+
device.cd(dir, state)
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
return state
|
|
40
38
|
|
|
41
39
|
def completion(self, state: ReplState):
|
|
42
40
|
return Devices.device(state).cd_completion(Cd.COMMAND, state, default = {})
|
adam/commands/check.py
CHANGED
|
@@ -2,11 +2,13 @@ import click
|
|
|
2
2
|
|
|
3
3
|
from adam.checks.check_result import CheckResult
|
|
4
4
|
from adam.checks.check_utils import all_checks, checks_from_csv, run_checks
|
|
5
|
+
from adam.commands import extract_options
|
|
5
6
|
from adam.commands.command import Command
|
|
6
7
|
from adam.commands.command_helpers import ClusterOrPodCommandHelper
|
|
7
8
|
from adam.commands.issues import Issues
|
|
8
9
|
from adam.repl_state import ReplState
|
|
9
10
|
from adam.utils import lines_to_tabular, log
|
|
11
|
+
from adam.utils_issues import IssuesUtils
|
|
10
12
|
|
|
11
13
|
class Check(Issues):
|
|
12
14
|
COMMAND = 'check'
|
|
@@ -30,36 +32,33 @@ class Check(Issues):
|
|
|
30
32
|
if not(args := self.args(cmd)):
|
|
31
33
|
return super().run(cmd, state)
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
with self.validate(args, state) as (args, state):
|
|
36
|
+
with extract_options(args, ['-s', '--show']) as (args, show_out):
|
|
37
|
+
if not args:
|
|
38
|
+
if state.in_repl:
|
|
39
|
+
log(lines_to_tabular([check.help() for check in all_checks()], separator=':'))
|
|
40
|
+
else:
|
|
41
|
+
log('* Check name is missing.')
|
|
42
|
+
Command.display_help()
|
|
36
43
|
|
|
37
|
-
|
|
44
|
+
return 'arg missing'
|
|
38
45
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
else:
|
|
43
|
-
log('* Check name is missing.')
|
|
44
|
-
Command.display_help()
|
|
45
|
-
return 'arg missing'
|
|
46
|
+
checks = checks_from_csv(args[0])
|
|
47
|
+
if not checks:
|
|
48
|
+
return 'invalid check name'
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
if not checks:
|
|
49
|
-
return 'invalid check name'
|
|
50
|
+
results = run_checks(state.sts, state.namespace, state.pod, checks=checks, show_out=show_out)
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
issues = CheckResult.collect_issues(results)
|
|
53
|
+
IssuesUtils.show_issues(issues, in_repl=state.in_repl)
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
Issues.show_issues(issues, in_repl=state.in_repl)
|
|
55
|
-
|
|
56
|
-
return issues if issues else 'no issues found'
|
|
55
|
+
return issues if issues else 'no issues found'
|
|
57
56
|
|
|
58
57
|
def completion(self, _: ReplState):
|
|
59
|
-
return {Check.COMMAND: {check.name(): None for check in all_checks()}}
|
|
58
|
+
return {Check.COMMAND: {check.name(): {'-s': None} for check in all_checks()}}
|
|
60
59
|
|
|
61
60
|
def help(self, _: ReplState):
|
|
62
|
-
return f'{Check.COMMAND} <check-name
|
|
61
|
+
return f'{Check.COMMAND} <check-name> [-s]\t run a single check'
|
|
63
62
|
|
|
64
63
|
class CheckCommandHelper(click.Command):
|
|
65
64
|
def get_help(self, ctx: click.Context):
|
adam/commands/cli_commands.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import functools
|
|
2
2
|
import re
|
|
3
3
|
|
|
4
|
-
from adam.commands.reaper.
|
|
4
|
+
from adam.commands.reaper.utils_reaper import Reapers
|
|
5
5
|
from adam.config import Config
|
|
6
6
|
from adam.utils_k8s.kube_context import KubeContext
|
|
7
7
|
from adam.utils_k8s.secrets import Secrets
|
|
@@ -66,8 +66,7 @@ class CliCommands:
|
|
|
66
66
|
return key.replace(f'{state.namespace}-', '').replace('-k8spg-cs-001', '')
|
|
67
67
|
d |= {f'pg-{reduce_key(k)}': f'PGPASSWORD={v["postgres-admin-password"]} psql -h {v["postgres-db-endpoint"]} -p {v["postgres-db-port"]} -U {v["postgres-admin-username"]} postgres' for k, v in data.items()}
|
|
68
68
|
|
|
69
|
-
if
|
|
70
|
-
reaper = r.reaper_spec(state)
|
|
69
|
+
if reaper := Reapers.reaper_spec(state):
|
|
71
70
|
d |= {
|
|
72
71
|
'reaper-exec': reaper["exec"],
|
|
73
72
|
'reaper-forward': reaper["forward"],
|
adam/commands/code.py
CHANGED
|
@@ -2,7 +2,7 @@ import code
|
|
|
2
2
|
from functools import partial
|
|
3
3
|
|
|
4
4
|
from adam.commands.command import Command
|
|
5
|
-
from adam.commands.cql.
|
|
5
|
+
from adam.commands.cql.utils_cql import cassandra_table_names, run_cql
|
|
6
6
|
from adam.repl_state import ReplState, RequiredState
|
|
7
7
|
from adam.utils import lines_to_tabular
|
|
8
8
|
from adam.utils_k8s.statefulsets import StatefulSets
|
|
@@ -29,29 +29,26 @@ class Code(Command):
|
|
|
29
29
|
if not(args := self.args(cmd)):
|
|
30
30
|
return super().run(cmd, state)
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
with self.validate(args, state) as (args, state):
|
|
33
|
+
sts = state.sts
|
|
34
|
+
pod = state.pod
|
|
35
|
+
pods = StatefulSets.pod_names(state.sts, state.namespace)
|
|
36
|
+
tables = cassandra_table_names(state)
|
|
37
|
+
cql = partial(run_cql, state, show_out=True)
|
|
38
|
+
|
|
39
|
+
my_local = globals() | locals()
|
|
40
|
+
# my_local = globals() | {'StatefulSets': StatefulSets} | locals()
|
|
41
|
+
lines = [
|
|
42
|
+
'sts: StatefulSet name',
|
|
43
|
+
'pod: Pod name',
|
|
44
|
+
'pods: Pod names in the current StatefulSet',
|
|
45
|
+
'tables: Cassandra tables names in the current StatefulSet',
|
|
46
|
+
"cql('select...'): run cql statement"
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
code.interact(local=my_local, banner=lines_to_tabular(lines, header='Variables', separator=':'))
|
|
35
50
|
|
|
36
|
-
|
|
37
|
-
pod = state.pod
|
|
38
|
-
pods = StatefulSets.pod_names(state.sts, state.namespace)
|
|
39
|
-
tables = cassandra_table_names(state)
|
|
40
|
-
cql = partial(run_cql, state, show_out=True)
|
|
41
|
-
|
|
42
|
-
my_local = globals() | locals()
|
|
43
|
-
# my_local = globals() | {'StatefulSets': StatefulSets} | locals()
|
|
44
|
-
lines = [
|
|
45
|
-
'sts: StatefulSet name',
|
|
46
|
-
'pod: Pod name',
|
|
47
|
-
'pods: Pod names in the current StatefulSet',
|
|
48
|
-
'tables: Cassandra tables names in the current StatefulSet',
|
|
49
|
-
"cql('select...'): run cql statement"
|
|
50
|
-
]
|
|
51
|
-
|
|
52
|
-
code.interact(local=my_local, banner=lines_to_tabular(lines, header='Variables', separator=':'))
|
|
53
|
-
|
|
54
|
-
return state
|
|
51
|
+
return state
|
|
55
52
|
|
|
56
53
|
def completion(self, state: ReplState):
|
|
57
54
|
return super().completion(state)
|