kaqing 2.0.110__py3-none-any.whl → 2.0.184__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 +9 -12
- adam/apps.py +18 -4
- adam/batch.py +5 -5
- adam/checks/check_utils.py +16 -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 +24 -0
- adam/commands/alter_tables.py +33 -48
- adam/commands/app/__init__.py +0 -0
- adam/commands/app/app.py +38 -0
- adam/commands/{app_ping.py → app/app_ping.py} +7 -13
- adam/commands/app/show_app_actions.py +49 -0
- adam/commands/{show → app}/show_app_id.py +8 -11
- adam/commands/{show → app}/show_app_queues.py +7 -14
- adam/commands/app/utils_app.py +98 -0
- adam/commands/audit/audit.py +27 -31
- adam/commands/audit/audit_repair_tables.py +14 -18
- adam/commands/audit/audit_run.py +16 -23
- adam/commands/audit/show_last10.py +4 -17
- adam/commands/audit/show_slow10.py +4 -17
- adam/commands/audit/show_top10.py +4 -16
- adam/commands/audit/utils_show_top10.py +15 -3
- adam/commands/bash/__init__.py +5 -0
- adam/commands/bash/bash.py +36 -0
- adam/commands/bash/bash_completer.py +93 -0
- adam/commands/bash/utils_bash.py +16 -0
- adam/commands/cat.py +36 -0
- adam/commands/cd.py +11 -95
- adam/commands/check.py +15 -24
- adam/commands/cli_commands.py +2 -3
- adam/commands/clipboard_copy.py +86 -0
- adam/commands/code.py +57 -0
- adam/commands/command.py +198 -40
- adam/commands/commands_utils.py +12 -27
- adam/commands/cql/cql_completions.py +27 -10
- adam/commands/cql/cqlsh.py +12 -30
- adam/commands/cql/utils_cql.py +297 -0
- 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 +3 -6
- adam/commands/deploy/deploy_pod.py +65 -73
- adam/commands/deploy/deploy_utils.py +14 -24
- adam/commands/deploy/undeploy.py +4 -27
- adam/commands/deploy/undeploy_frontend.py +4 -7
- adam/commands/deploy/undeploy_pg_agent.py +6 -8
- adam/commands/deploy/undeploy_pod.py +11 -12
- adam/commands/devices/__init__.py +0 -0
- adam/commands/devices/device.py +123 -0
- adam/commands/devices/device_app.py +163 -0
- adam/commands/devices/device_auit_log.py +49 -0
- adam/commands/devices/device_cass.py +179 -0
- adam/commands/devices/device_export.py +84 -0
- adam/commands/devices/device_postgres.py +150 -0
- adam/commands/devices/devices.py +25 -0
- adam/commands/download_file.py +47 -0
- adam/commands/exit.py +1 -4
- adam/commands/export/__init__.py +0 -0
- adam/commands/export/clean_up_all_export_sessions.py +37 -0
- adam/commands/export/clean_up_export_sessions.py +39 -0
- adam/commands/export/download_export_session.py +39 -0
- adam/commands/export/drop_export_database.py +39 -0
- adam/commands/export/drop_export_databases.py +37 -0
- adam/commands/export/export.py +53 -0
- adam/commands/export/export_databases.py +245 -0
- adam/commands/export/export_select.py +59 -0
- adam/commands/export/export_select_x.py +54 -0
- adam/commands/export/export_sessions.py +209 -0
- adam/commands/export/export_use.py +49 -0
- adam/commands/export/exporter.py +332 -0
- adam/commands/export/import_files.py +44 -0
- adam/commands/export/import_session.py +44 -0
- adam/commands/export/importer.py +81 -0
- adam/commands/export/importer_athena.py +177 -0
- adam/commands/export/importer_sqlite.py +67 -0
- adam/commands/export/show_column_counts.py +45 -0
- adam/commands/export/show_export_databases.py +38 -0
- adam/commands/export/show_export_session.py +39 -0
- adam/commands/export/show_export_sessions.py +37 -0
- adam/commands/export/utils_export.py +343 -0
- adam/commands/find_files.py +51 -0
- adam/commands/find_processes.py +76 -0
- adam/commands/head.py +36 -0
- adam/commands/help.py +5 -3
- adam/commands/intermediate_command.py +49 -0
- adam/commands/issues.py +11 -43
- adam/commands/kubectl.py +38 -0
- adam/commands/login.py +22 -24
- adam/commands/logs.py +3 -6
- adam/commands/ls.py +11 -116
- adam/commands/medusa/medusa.py +4 -22
- adam/commands/medusa/medusa_backup.py +20 -27
- adam/commands/medusa/medusa_restore.py +38 -37
- adam/commands/medusa/medusa_show_backupjobs.py +16 -18
- adam/commands/medusa/medusa_show_restorejobs.py +13 -18
- adam/commands/nodetool.py +11 -17
- adam/commands/param_get.py +11 -14
- adam/commands/param_set.py +8 -12
- adam/commands/postgres/postgres.py +45 -46
- adam/commands/postgres/postgres_databases.py +269 -0
- adam/commands/postgres/postgres_ls.py +4 -8
- adam/commands/postgres/postgres_preview.py +5 -9
- adam/commands/postgres/psql_completions.py +4 -3
- adam/commands/postgres/utils_postgres.py +70 -0
- adam/commands/preview_table.py +8 -44
- adam/commands/pwd.py +14 -46
- adam/commands/reaper/reaper.py +4 -27
- adam/commands/reaper/reaper_forward.py +49 -56
- 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 +8 -33
- adam/commands/reaper/reaper_runs.py +43 -58
- adam/commands/reaper/reaper_runs_abort.py +29 -49
- adam/commands/reaper/reaper_schedule_activate.py +9 -32
- adam/commands/reaper/reaper_schedule_start.py +9 -32
- adam/commands/reaper/reaper_schedule_stop.py +9 -32
- adam/commands/reaper/reaper_schedules.py +4 -14
- adam/commands/reaper/reaper_status.py +8 -16
- adam/commands/reaper/utils_reaper.py +194 -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 +12 -4
- adam/commands/show/show.py +10 -25
- adam/commands/show/show_adam.py +3 -3
- adam/commands/show/show_cassandra_repairs.py +35 -0
- adam/commands/show/show_cassandra_status.py +33 -51
- adam/commands/show/show_cassandra_version.py +5 -18
- adam/commands/show/show_commands.py +20 -25
- adam/commands/show/show_host.py +1 -1
- adam/commands/show/show_login.py +20 -27
- adam/commands/show/show_params.py +2 -5
- 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 +5 -14
- adam/embedded_params.py +1 -1
- adam/log.py +4 -4
- adam/pod_exec_result.py +6 -3
- adam/repl.py +69 -115
- adam/repl_commands.py +52 -19
- adam/repl_state.py +161 -40
- adam/sql/sql_completer.py +52 -27
- adam/sql/sql_state_machine.py +131 -19
- 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 +511 -9
- adam/utils_athena.py +145 -0
- adam/utils_audits.py +12 -103
- adam/utils_issues.py +32 -0
- adam/utils_k8s/app_clusters.py +28 -0
- adam/utils_k8s/app_pods.py +36 -0
- adam/utils_k8s/cassandra_clusters.py +30 -19
- adam/utils_k8s/cassandra_nodes.py +3 -3
- 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/kube_context.py +2 -2
- adam/utils_k8s/pods.py +89 -78
- 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_local.py +4 -0
- adam/utils_net.py +4 -4
- adam/utils_repl/__init__.py +0 -0
- adam/utils_repl/automata_completer.py +48 -0
- adam/utils_repl/repl_completer.py +46 -0
- adam/utils_repl/state_machine.py +173 -0
- adam/utils_sqlite.py +137 -0
- adam/version.py +1 -1
- {kaqing-2.0.110.dist-info → kaqing-2.0.184.dist-info}/METADATA +1 -1
- kaqing-2.0.184.dist-info/RECORD +244 -0
- adam/commands/app.py +0 -67
- adam/commands/bash.py +0 -150
- adam/commands/cp.py +0 -95
- adam/commands/cql/cql_utils.py +0 -112
- adam/commands/devices.py +0 -118
- adam/commands/postgres/postgres_context.py +0 -239
- 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_repairs.py +0 -47
- kaqing-2.0.110.dist-info/RECORD +0 -187
- {kaqing-2.0.110.dist-info → kaqing-2.0.184.dist-info}/WHEEL +0 -0
- {kaqing-2.0.110.dist-info → kaqing-2.0.184.dist-info}/entry_points.txt +0 -0
- {kaqing-2.0.110.dist-info → kaqing-2.0.184.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from adam.app_session import AppSession
|
|
2
|
+
from adam.apps import AppAction, Apps
|
|
3
|
+
from adam.commands.command import Command
|
|
4
|
+
from adam.config import Config
|
|
5
|
+
from adam.repl_state import ReplState
|
|
6
|
+
from adam.utils import tabulize, log
|
|
7
|
+
|
|
8
|
+
class ShowAppActions(Command):
|
|
9
|
+
COMMAND = 'show app actions'
|
|
10
|
+
|
|
11
|
+
# the singleton pattern
|
|
12
|
+
def __new__(cls, *args, **kwargs):
|
|
13
|
+
if not hasattr(cls, 'instance'): cls.instance = super(ShowAppActions, 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 ShowAppActions.COMMAND
|
|
22
|
+
|
|
23
|
+
def required(self):
|
|
24
|
+
return ReplState.A
|
|
25
|
+
|
|
26
|
+
def run(self, cmd: str, state: ReplState):
|
|
27
|
+
if not (args := self.args(cmd)):
|
|
28
|
+
return super().run(cmd, state)
|
|
29
|
+
|
|
30
|
+
with self.validate(args, state) as (args, state):
|
|
31
|
+
actions = []
|
|
32
|
+
for typ in Apps().app_types():
|
|
33
|
+
actions.extend(typ.actions)
|
|
34
|
+
|
|
35
|
+
lines = tabulize(actions, lambda a: str(a), header='ACTION,ARGS,DESCRIPTION', separator=',')
|
|
36
|
+
log()
|
|
37
|
+
|
|
38
|
+
app_session: AppSession = AppSession.create(state.app_env or 'c3', state.app_app or 'c3')
|
|
39
|
+
endpoint = Config().get('app.console-endpoint', 'https://{host}/{env}/{app}/static/console/index.html')
|
|
40
|
+
endpoint = endpoint.replace('{host}', app_session.host).replace('{env}', app_session.env).replace('{app}', state.app_app or 'c3')
|
|
41
|
+
tabulize([f'CONSOLE:,{endpoint}'], separator=',')
|
|
42
|
+
|
|
43
|
+
return lines
|
|
44
|
+
|
|
45
|
+
def completion(self, state: ReplState):
|
|
46
|
+
return super().completion(state)
|
|
47
|
+
|
|
48
|
+
def help(self, _: ReplState):
|
|
49
|
+
return f"{ShowAppActions.COMMAND}\t show app actions"
|
|
@@ -25,20 +25,17 @@ class ShowAppId(Command):
|
|
|
25
25
|
if not(args := self.args(cmd)):
|
|
26
26
|
return super().run(cmd, state)
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return state
|
|
28
|
+
with self.validate(args, state) as (args, state):
|
|
29
|
+
c3_app_id = 'Unknown'
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
apps = CustomResources.get_app_ids()
|
|
32
|
+
cr_name = CustomResources.get_cr_name(state.sts if state.sts else state.pod, namespace=state.namespace)
|
|
33
|
+
if cr_name in apps:
|
|
34
|
+
c3_app_id = (apps[cr_name])
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
cr_name = CustomResources.get_cr_name(state.sts if state.sts else state.pod, namespace=state.namespace)
|
|
36
|
-
if cr_name in apps:
|
|
37
|
-
c3_app_id = (apps[cr_name])
|
|
36
|
+
log(c3_app_id)
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return c3_app_id
|
|
38
|
+
return c3_app_id
|
|
42
39
|
|
|
43
40
|
def completion(self, state: ReplState):
|
|
44
41
|
return super().completion(state)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
from adam.commands import app, extract_options
|
|
1
2
|
from adam.commands.command import Command
|
|
2
3
|
from adam.repl_state import ReplState, RequiredState
|
|
3
|
-
from adam.app_session import AppSession
|
|
4
4
|
|
|
5
5
|
class ShowAppQueues(Command):
|
|
6
6
|
COMMAND = 'show app queues'
|
|
@@ -24,22 +24,15 @@ class ShowAppQueues(Command):
|
|
|
24
24
|
if not(args := self.args(cmd)):
|
|
25
25
|
return super().run(cmd, state)
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
with self.validate(args, state) as (_, state):
|
|
28
|
+
with extract_options(args, '--force') as (args, forced):
|
|
29
|
+
with app(state) as http:
|
|
30
|
+
http.post(['InvalidationQueue.countAll'], forced=forced)
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
AppSession.run(state.app_env, state.app_app, state.namespace, 'InvalidationQueue', 'countAll', forced= forced)
|
|
35
|
-
|
|
36
|
-
return state
|
|
32
|
+
return state
|
|
37
33
|
|
|
38
34
|
def completion(self, state: ReplState):
|
|
39
|
-
|
|
40
|
-
return super().completion(state, {'--force': None})
|
|
41
|
-
|
|
42
|
-
return {}
|
|
35
|
+
return super().completion(state, {'--force': None})
|
|
43
36
|
|
|
44
37
|
def help(self, _: ReplState):
|
|
45
38
|
return f"{ShowAppQueues.COMMAND} [--force]\t show invalidation queue counts"
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import Union
|
|
3
|
+
|
|
4
|
+
from adam.app_session import AppSession
|
|
5
|
+
from adam.apps import Apps
|
|
6
|
+
from adam.pod_exec_result import PodExecResult
|
|
7
|
+
from adam.repl_state import ReplState
|
|
8
|
+
from adam.utils import log2
|
|
9
|
+
from adam.utils_k8s.app_clusters import AppClusters
|
|
10
|
+
from adam.utils_k8s.app_pods import AppPods
|
|
11
|
+
|
|
12
|
+
class AppRestHandler:
|
|
13
|
+
def __init__(self, state: ReplState, forced = False):
|
|
14
|
+
self.state = state
|
|
15
|
+
self.forced = forced
|
|
16
|
+
|
|
17
|
+
def __enter__(self):
|
|
18
|
+
return self.post
|
|
19
|
+
|
|
20
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
21
|
+
return False
|
|
22
|
+
|
|
23
|
+
def post(self, args: list[str]) -> Union[ReplState, str]:
|
|
24
|
+
if not args:
|
|
25
|
+
return 'arg missing'
|
|
26
|
+
|
|
27
|
+
t_f = args[0].split('.')
|
|
28
|
+
if len(t_f) < 2:
|
|
29
|
+
return 'arg missing'
|
|
30
|
+
|
|
31
|
+
state = self.state
|
|
32
|
+
|
|
33
|
+
payload, valid = Apps().payload(t_f[0], t_f[1], args[1:] if len(args) > 1 else [])
|
|
34
|
+
if not valid:
|
|
35
|
+
log2('Missing one or more action arguments.')
|
|
36
|
+
return state
|
|
37
|
+
|
|
38
|
+
if payload:
|
|
39
|
+
try:
|
|
40
|
+
payload = json.loads(payload)
|
|
41
|
+
except json.decoder.JSONDecodeError as e:
|
|
42
|
+
log2(f'Invalid json argument: {e}')
|
|
43
|
+
return state
|
|
44
|
+
|
|
45
|
+
AppSession.run(state.app_env, state.app_app, state.namespace, t_f[0], t_f[1], payload=payload, forced=self.forced)
|
|
46
|
+
|
|
47
|
+
return state
|
|
48
|
+
|
|
49
|
+
class AppPodService:
|
|
50
|
+
def __init__(self, handler: 'AppHandler'):
|
|
51
|
+
self.handler = handler
|
|
52
|
+
|
|
53
|
+
def exec(self, command: str, show_out = True) -> Union[PodExecResult, list[PodExecResult]]:
|
|
54
|
+
state = self.handler.state
|
|
55
|
+
|
|
56
|
+
if state.app_pod:
|
|
57
|
+
return AppPods.exec(state.app_pod, state.namespace, command, show_out=show_out, shell='bash')
|
|
58
|
+
elif state.app_app:
|
|
59
|
+
pods = AppPods.pod_names(state.namespace, state.app_env, state.app_app)
|
|
60
|
+
return AppClusters.exec(pods, state.namespace, command, action='bash', show_out=show_out, shell='bash')
|
|
61
|
+
|
|
62
|
+
return []
|
|
63
|
+
|
|
64
|
+
def post(self, args: list[str], forced=False) -> Union[ReplState, str]:
|
|
65
|
+
state = self.handler.state
|
|
66
|
+
|
|
67
|
+
if not args:
|
|
68
|
+
return 'arg missing'
|
|
69
|
+
|
|
70
|
+
t_f = args[0].split('.')
|
|
71
|
+
if len(t_f) < 2:
|
|
72
|
+
return 'arg missing'
|
|
73
|
+
|
|
74
|
+
payload, valid = Apps().payload(t_f[0], t_f[1], args[1:] if len(args) > 1 else [])
|
|
75
|
+
if not valid:
|
|
76
|
+
log2('Missing one or more action arguments.')
|
|
77
|
+
return state
|
|
78
|
+
|
|
79
|
+
if payload:
|
|
80
|
+
try:
|
|
81
|
+
payload = json.loads(payload)
|
|
82
|
+
except json.decoder.JSONDecodeError as e:
|
|
83
|
+
log2(f'Invalid json argument: {e}')
|
|
84
|
+
return state
|
|
85
|
+
|
|
86
|
+
AppSession.run(state.app_env, state.app_app, state.namespace, t_f[0], t_f[1], payload=payload, forced=forced)
|
|
87
|
+
|
|
88
|
+
return state
|
|
89
|
+
|
|
90
|
+
class AppHandler:
|
|
91
|
+
def __init__(self, state: ReplState):
|
|
92
|
+
self.state = state
|
|
93
|
+
|
|
94
|
+
def __enter__(self):
|
|
95
|
+
return AppPodService(self)
|
|
96
|
+
|
|
97
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
98
|
+
return False
|
adam/commands/audit/audit.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import click
|
|
2
2
|
|
|
3
|
+
from adam.commands import validate_args
|
|
3
4
|
from adam.commands.audit.audit_repair_tables import AuditRepairTables
|
|
4
5
|
from adam.commands.audit.audit_run import AuditRun
|
|
5
6
|
from adam.commands.audit.show_last10 import ShowLast10
|
|
@@ -7,13 +8,13 @@ from adam.commands.audit.show_slow10 import ShowSlow10
|
|
|
7
8
|
from adam.commands.audit.show_top10 import ShowTop10
|
|
8
9
|
from adam.commands.audit.utils_show_top10 import show_top10_completions_for_nesting
|
|
9
10
|
from adam.commands.command import Command
|
|
10
|
-
from adam.
|
|
11
|
+
from adam.commands.intermediate_command import IntermediateCommand
|
|
11
12
|
from adam.repl_state import ReplState
|
|
12
|
-
from adam.sql.sql_completer import SqlCompleter
|
|
13
|
-
from adam.utils import log2
|
|
14
|
-
from adam.
|
|
13
|
+
from adam.sql.sql_completer import SqlCompleter, SqlVariant
|
|
14
|
+
from adam.utils import log2, wait_log
|
|
15
|
+
from adam.utils_athena import Athena
|
|
15
16
|
|
|
16
|
-
class Audit(
|
|
17
|
+
class Audit(IntermediateCommand):
|
|
17
18
|
COMMAND = 'audit'
|
|
18
19
|
|
|
19
20
|
# the singleton pattern
|
|
@@ -36,45 +37,40 @@ class Audit(Command):
|
|
|
36
37
|
if not(args := self.args(cmd)):
|
|
37
38
|
return super().run(cmd, state)
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
r = None
|
|
44
|
-
if len(args) > 0:
|
|
45
|
-
r = super().intermediate_run(cmd, state, args, Audit.cmd_list(), display_help=False)
|
|
40
|
+
with self.validate(args, state) as (args, state):
|
|
41
|
+
r = None
|
|
42
|
+
if len(args) > 0:
|
|
43
|
+
r = self.intermediate_run(cmd, state, args, self.cmd_list(), display_help=False)
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
else:
|
|
52
|
-
log2(sql)
|
|
45
|
+
if not r or isinstance(r, str) and r == 'command-missing':
|
|
46
|
+
with validate_args(args, state, default='select * from audit order by ts desc limit 10') as sql:
|
|
47
|
+
log2(sql)
|
|
48
|
+
Athena.run_query(sql)
|
|
53
49
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return state
|
|
50
|
+
return state
|
|
57
51
|
|
|
58
52
|
def completion(self, state: ReplState):
|
|
59
53
|
if state.device == ReplState.L:
|
|
60
54
|
if not self.schema_read:
|
|
61
|
-
|
|
55
|
+
wait_log(f'Inspecting audit database schema...')
|
|
62
56
|
self.schema_read = True
|
|
63
57
|
# warm up the caches first time when l: drive is accessed
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
58
|
+
Athena.table_names()
|
|
59
|
+
Athena.column_names()
|
|
60
|
+
Athena.column_names(partition_cols_only=True)
|
|
67
61
|
|
|
68
62
|
return super().completion(state) | show_top10_completions_for_nesting() | SqlCompleter(
|
|
69
|
-
lambda:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
lambda: Athena.table_names(),
|
|
64
|
+
expandables={
|
|
65
|
+
'columns': lambda table: Athena.column_names(),
|
|
66
|
+
'partition_columns': lambda table: Athena.column_names(partition_cols_only=True)
|
|
67
|
+
},
|
|
68
|
+
variant=SqlVariant.ATHENA
|
|
73
69
|
).completions_for_nesting()
|
|
74
70
|
|
|
75
71
|
return {}
|
|
76
72
|
|
|
77
|
-
def cmd_list():
|
|
73
|
+
def cmd_list(self):
|
|
78
74
|
return [AuditRepairTables(), AuditRun(), ShowLast10(), ShowSlow10(), ShowTop10()]
|
|
79
75
|
|
|
80
76
|
def help(self, _: ReplState):
|
|
@@ -82,4 +78,4 @@ class Audit(Command):
|
|
|
82
78
|
|
|
83
79
|
class AuditCommandHelper(click.Command):
|
|
84
80
|
def get_help(self, ctx: click.Context):
|
|
85
|
-
|
|
81
|
+
IntermediateCommand.intermediate_help(super().get_help(ctx), Audit.COMMAND, Audit().cmd_list(), show_cluster_help=False)
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import concurrent
|
|
2
1
|
import time
|
|
3
2
|
|
|
3
|
+
from adam.commands import validate_args
|
|
4
4
|
from adam.commands.command import Command
|
|
5
5
|
from adam.config import Config
|
|
6
6
|
from adam.repl_state import ReplState
|
|
7
7
|
from adam.utils import log, log2
|
|
8
|
+
from adam.utils_athena import Athena
|
|
8
9
|
from adam.utils_audits import AuditMeta, Audits
|
|
9
10
|
|
|
10
11
|
class AuditRepairTables(Command):
|
|
@@ -30,25 +31,20 @@ class AuditRepairTables(Command):
|
|
|
30
31
|
if not(args := self.args(cmd)):
|
|
31
32
|
return super().run(cmd, state)
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
tables = Config().get('audit.athena.repair-partition-tables', 'audit').split(',')
|
|
38
|
-
if args:
|
|
39
|
-
tables = args
|
|
34
|
+
with self.validate(args, state) as (args, state):
|
|
35
|
+
with validate_args(args, state, default=Config().get('audit.athena.repair-partition-tables', 'audit').split(',')) as tables:
|
|
36
|
+
meta = Audits.get_meta()
|
|
37
|
+
self.repair(tables, meta)
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
self.repair(tables, meta)
|
|
43
|
-
|
|
44
|
-
return state
|
|
39
|
+
return state
|
|
45
40
|
|
|
46
41
|
def completion(self, state: ReplState):
|
|
42
|
+
# trigger auto repair if on l: drive
|
|
47
43
|
if state.device == ReplState.L:
|
|
48
44
|
if not self.auto_repaired:
|
|
49
45
|
if hours := Config().get('audit.athena.auto-repair.elapsed_hours', 12):
|
|
50
|
-
with
|
|
51
|
-
|
|
46
|
+
with Audits.offload() as exec:
|
|
47
|
+
exec.submit(lambda: self.auto_repair(hours))
|
|
52
48
|
|
|
53
49
|
return super().completion(state)
|
|
54
50
|
|
|
@@ -64,13 +60,13 @@ class AuditRepairTables(Command):
|
|
|
64
60
|
log2(f'Audit tables have been auto-repaired.')
|
|
65
61
|
|
|
66
62
|
def repair(self, tables: list[str], meta: AuditMeta, show_sql = False):
|
|
67
|
-
with
|
|
63
|
+
with Audits.offload() as exec:
|
|
68
64
|
for table in tables:
|
|
69
65
|
if show_sql:
|
|
70
66
|
log(f'MSCK REPAIR TABLE {table}')
|
|
71
67
|
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
exec.submit(Athena.query, f'MSCK REPAIR TABLE {table}', None,)
|
|
69
|
+
exec.submit(Audits.put_meta, Audits.PARTITIONS_ADDED, meta,)
|
|
74
70
|
|
|
75
71
|
def help(self, _: ReplState):
|
|
76
|
-
return f"{AuditRepairTables.COMMAND}
|
|
72
|
+
return f"{AuditRepairTables.COMMAND}\t run MSCK REPAIR command for new partition discovery"
|
adam/commands/audit/audit_run.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
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
|
|
6
4
|
from adam.utils import log2
|
|
5
|
+
from adam.utils_athena import Athena
|
|
7
6
|
from adam.utils_audits import AuditMeta, Audits
|
|
8
7
|
|
|
9
8
|
class AuditRun(Command):
|
|
@@ -29,29 +28,23 @@ class AuditRun(Command):
|
|
|
29
28
|
if not(args := self.args(cmd)):
|
|
30
29
|
return super().run(cmd, state)
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
executor.submit(Audits.run_audit_query, f'MSCK REPAIR TABLE {table}', None,)
|
|
45
|
-
else:
|
|
46
|
-
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.')
|
|
47
43
|
|
|
48
|
-
|
|
44
|
+
return state
|
|
49
45
|
|
|
50
46
|
def completion(self, state: ReplState):
|
|
51
|
-
|
|
52
|
-
return super().completion(state)
|
|
53
|
-
|
|
54
|
-
return {}
|
|
47
|
+
return super().completion(state)
|
|
55
48
|
|
|
56
49
|
def help(self, _: ReplState):
|
|
57
|
-
return f"{AuditRun.COMMAND}
|
|
50
|
+
return f"{AuditRun.COMMAND}\t run"
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
from adam.commands.audit.utils_show_top10 import
|
|
1
|
+
from adam.commands.audit.utils_show_top10 import run_configured_query
|
|
2
2
|
from adam.commands.command import Command
|
|
3
3
|
from adam.repl_state import ReplState
|
|
4
|
-
from adam.utils import log2
|
|
5
|
-
from adam.utils_audits import Audits
|
|
6
4
|
|
|
7
5
|
class ShowLast10(Command):
|
|
8
6
|
COMMAND = 'show last'
|
|
@@ -26,21 +24,10 @@ class ShowLast10(Command):
|
|
|
26
24
|
if not(args := self.args(cmd)):
|
|
27
25
|
return super().run(cmd, state)
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return state
|
|
32
|
-
|
|
33
|
-
limit, date_condition = extract_limit_and_duration(args)
|
|
27
|
+
with self.validate(args, state) as (args, state):
|
|
28
|
+
run_configured_query('audit.queries.last10', args)
|
|
34
29
|
|
|
35
|
-
|
|
36
|
-
"SELECT * FROM audit",
|
|
37
|
-
f"WHERE drive <> 'z' and ({date_condition})",
|
|
38
|
-
f"ORDER BY ts DESC LIMIT {limit};"])
|
|
39
|
-
log2(query)
|
|
40
|
-
log2()
|
|
41
|
-
Audits.run_audit_query(query)
|
|
42
|
-
|
|
43
|
-
return state
|
|
30
|
+
return state
|
|
44
31
|
|
|
45
32
|
def completion(self, _: ReplState):
|
|
46
33
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
from adam.commands.audit.utils_show_top10 import
|
|
1
|
+
from adam.commands.audit.utils_show_top10 import run_configured_query
|
|
2
2
|
from adam.commands.command import Command
|
|
3
3
|
from adam.repl_state import ReplState
|
|
4
|
-
from adam.utils import log2
|
|
5
|
-
from adam.utils_audits import Audits
|
|
6
4
|
|
|
7
5
|
class ShowSlow10(Command):
|
|
8
6
|
COMMAND = 'show slow'
|
|
@@ -26,21 +24,10 @@ class ShowSlow10(Command):
|
|
|
26
24
|
if not(args := self.args(cmd)):
|
|
27
25
|
return super().run(cmd, state)
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return state
|
|
32
|
-
|
|
33
|
-
limit, date_condition = extract_limit_and_duration(args)
|
|
27
|
+
with self.validate(args, state) as (args, state):
|
|
28
|
+
run_configured_query('audit.queries.slow10', args)
|
|
34
29
|
|
|
35
|
-
|
|
36
|
-
"SELECT * FROM audit",
|
|
37
|
-
f"WHERE drive <> 'z' and ({date_condition})",
|
|
38
|
-
f"ORDER BY CAST(duration AS REAL) DESC LIMIT {limit};"])
|
|
39
|
-
log2(query)
|
|
40
|
-
log2()
|
|
41
|
-
Audits.run_audit_query(query)
|
|
42
|
-
|
|
43
|
-
return state
|
|
30
|
+
return state
|
|
44
31
|
|
|
45
32
|
def completion(self, _: ReplState):
|
|
46
33
|
return {}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
from adam.commands.audit.utils_show_top10 import
|
|
1
|
+
from adam.commands.audit.utils_show_top10 import run_configured_query
|
|
2
2
|
from adam.commands.command import Command
|
|
3
3
|
from adam.repl_state import ReplState
|
|
4
|
-
from adam.utils import log2
|
|
5
|
-
from adam.utils_audits import Audits
|
|
6
4
|
|
|
7
5
|
class ShowTop10(Command):
|
|
8
6
|
COMMAND = 'show top'
|
|
@@ -26,20 +24,10 @@ class ShowTop10(Command):
|
|
|
26
24
|
if not(args := self.args(cmd)):
|
|
27
25
|
return super().run(cmd, state)
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return state
|
|
32
|
-
|
|
33
|
-
limit, date_condition = extract_limit_and_duration(args)
|
|
34
|
-
query = '\n '.join([
|
|
35
|
-
"SELECT min(c) AS cluster, line, COUNT(*) AS cnt, avg(CAST(duration AS REAL)) AS duration",
|
|
36
|
-
f"FROM audit WHERE drive <> 'z' and ({date_condition})",
|
|
37
|
-
f"GROUP BY line ORDER BY cnt DESC LIMIT {limit};"])
|
|
38
|
-
log2(query)
|
|
39
|
-
log2()
|
|
40
|
-
Audits.run_audit_query(query)
|
|
27
|
+
with self.validate(args, state) as (args, state):
|
|
28
|
+
run_configured_query('audit.queries.top10', args)
|
|
41
29
|
|
|
42
|
-
|
|
30
|
+
return state
|
|
43
31
|
|
|
44
32
|
def completion(self, _: ReplState):
|
|
45
33
|
return {}
|
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
from datetime import datetime, timedelta
|
|
2
2
|
|
|
3
|
+
from adam.config import Config
|
|
4
|
+
from adam.utils import log2, log_exc
|
|
5
|
+
from adam.utils_athena import Athena
|
|
3
6
|
from adam.utils_audits import Audits
|
|
4
7
|
from adam.utils_repl.automata_completer import AutomataCompleter
|
|
5
8
|
from adam.utils_repl.state_machine import StateMachine
|
|
6
9
|
|
|
10
|
+
def run_configured_query(config_key: str, args: list[str]):
|
|
11
|
+
limit, date_condition = extract_limit_and_duration(args)
|
|
12
|
+
if query := Config().get(config_key, None):
|
|
13
|
+
query = '\n '.join(query.split('\n'))
|
|
14
|
+
query = query.replace('{date_condition}', date_condition)
|
|
15
|
+
query = query.replace('{limit}', str(limit))
|
|
16
|
+
|
|
17
|
+
log2(query)
|
|
18
|
+
log2()
|
|
19
|
+
Athena.run_query(query)
|
|
20
|
+
|
|
7
21
|
def extract_limit_and_duration(args: list[str]) -> tuple[int, datetime]:
|
|
8
22
|
limit = 10
|
|
9
23
|
_from = datetime.now() - timedelta(days=30)
|
|
10
24
|
if args:
|
|
11
|
-
|
|
25
|
+
with log_exc():
|
|
12
26
|
limit = int(args[0])
|
|
13
|
-
except:
|
|
14
|
-
pass
|
|
15
27
|
|
|
16
28
|
if len(args) > 2 and args[1] == 'over':
|
|
17
29
|
if args[2] == 'day':
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from adam.commands.bash import bash
|
|
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 Bash(Command):
|
|
7
|
+
COMMAND = 'bash'
|
|
8
|
+
|
|
9
|
+
# the singleton pattern
|
|
10
|
+
def __new__(cls, *args, **kwargs):
|
|
11
|
+
if not hasattr(cls, 'instance'): cls.instance = super(Bash, 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 Bash.COMMAND
|
|
20
|
+
|
|
21
|
+
def required(self):
|
|
22
|
+
return [RequiredState.CLUSTER_OR_POD, RequiredState.APP_APP, ReplState.P]
|
|
23
|
+
|
|
24
|
+
def run(self, cmd: str, s0: ReplState):
|
|
25
|
+
if not(args := self.args(cmd)):
|
|
26
|
+
return super().run(cmd, s0)
|
|
27
|
+
|
|
28
|
+
with self.validate(args, s0) as (args, s1):
|
|
29
|
+
with bash(s0, s1) as exec:
|
|
30
|
+
return exec(args)
|
|
31
|
+
|
|
32
|
+
def completion(self, state: ReplState):
|
|
33
|
+
return Devices.device(state).bash_completion(Bash.COMMAND, state, default = {})
|
|
34
|
+
|
|
35
|
+
def help(self, _: ReplState):
|
|
36
|
+
return f'{Bash.COMMAND} [pod-name] [bash-commands] [&]\t run bash on the Cassandra nodes'
|