kaqing 2.0.174__py3-none-any.whl → 2.0.188__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 +2 -2
- adam/apps.py +18 -4
- adam/batch.py +1 -1
- adam/checks/check_utils.py +3 -1
- adam/commands/__init__.py +4 -2
- adam/commands/app/__init__.py +0 -0
- adam/commands/app/app.py +38 -0
- adam/commands/app/app_ping.py +38 -0
- adam/commands/app/show_app_actions.py +49 -0
- adam/commands/app/show_app_id.py +44 -0
- adam/commands/app/show_app_queues.py +38 -0
- adam/commands/app/utils_app.py +106 -0
- adam/commands/audit/audit.py +9 -27
- adam/commands/audit/audit_repair_tables.py +5 -7
- adam/commands/audit/audit_run.py +1 -1
- adam/commands/audit/completions_l.py +15 -0
- adam/commands/audit/show_last10.py +2 -14
- adam/commands/audit/show_slow10.py +2 -13
- adam/commands/audit/show_top10.py +2 -11
- adam/commands/audit/utils_show_top10.py +14 -1
- adam/commands/bash/bash.py +1 -1
- adam/commands/cat.py +3 -7
- adam/commands/check.py +2 -2
- adam/commands/cli_commands.py +6 -1
- adam/commands/{cp.py → clipboard_copy.py} +18 -12
- adam/commands/code.py +2 -2
- adam/commands/command.py +61 -11
- adam/commands/commands_utils.py +19 -12
- adam/commands/cql/completions_c.py +28 -0
- adam/commands/cql/cqlsh.py +3 -7
- adam/commands/cql/utils_cql.py +22 -58
- adam/commands/deploy/deploy_pg_agent.py +2 -2
- adam/commands/deploy/undeploy_pg_agent.py +2 -2
- adam/commands/devices/device.py +39 -8
- adam/commands/devices/device_app.py +18 -28
- adam/commands/devices/device_auit_log.py +3 -3
- adam/commands/devices/device_cass.py +16 -22
- adam/commands/devices/device_export.py +6 -3
- adam/commands/devices/device_postgres.py +79 -63
- adam/commands/download_file.py +47 -0
- adam/commands/export/clean_up_all_export_sessions.py +3 -3
- adam/commands/export/clean_up_export_sessions.py +5 -10
- adam/commands/export/completions_x.py +11 -0
- adam/commands/export/download_export_session.py +40 -0
- adam/commands/export/export.py +0 -16
- adam/commands/export/export_databases.py +26 -9
- adam/commands/export/export_select.py +9 -58
- adam/commands/export/export_sessions.py +90 -5
- adam/commands/export/export_use.py +13 -10
- adam/commands/export/export_x_select.py +48 -0
- adam/commands/export/exporter.py +60 -22
- adam/commands/export/import_files.py +44 -0
- adam/commands/export/import_session.py +8 -4
- adam/commands/export/importer.py +7 -0
- adam/commands/export/importer_athena.py +101 -34
- adam/commands/export/importer_sqlite.py +30 -5
- adam/commands/export/show_column_counts.py +11 -11
- adam/commands/export/show_export_databases.py +5 -3
- adam/commands/export/show_export_session.py +5 -6
- adam/commands/export/show_export_sessions.py +4 -11
- adam/commands/export/utils_export.py +42 -14
- adam/commands/find_files.py +51 -0
- adam/commands/find_processes.py +76 -0
- adam/commands/head.py +36 -0
- adam/commands/help.py +2 -2
- adam/commands/intermediate_command.py +6 -3
- adam/commands/ls.py +1 -1
- adam/commands/medusa/medusa_backup.py +12 -14
- adam/commands/medusa/medusa_restore.py +20 -15
- adam/commands/medusa/medusa_show_backupjobs.py +6 -4
- adam/commands/medusa/medusa_show_restorejobs.py +5 -3
- adam/commands/medusa/utils_medusa.py +15 -0
- adam/commands/nodetool.py +3 -8
- adam/commands/param_get.py +2 -3
- adam/commands/param_set.py +1 -1
- adam/commands/postgres/completions_p.py +22 -0
- adam/commands/postgres/postgres.py +14 -21
- adam/commands/postgres/postgres_databases.py +270 -0
- adam/commands/postgres/utils_postgres.py +29 -20
- adam/commands/preview_table.py +3 -1
- adam/commands/pwd.py +3 -3
- adam/commands/reaper/reaper_forward.py +2 -2
- adam/commands/reaper/reaper_runs.py +3 -3
- adam/commands/reaper/reaper_schedule_activate.py +6 -2
- adam/commands/reaper/reaper_schedule_start.py +1 -2
- adam/commands/reaper/reaper_schedule_stop.py +1 -2
- adam/commands/reaper/utils_reaper.py +13 -6
- adam/commands/repair/repair_scan.py +0 -2
- adam/commands/repair/repair_stop.py +0 -1
- adam/commands/shell.py +7 -5
- adam/commands/show/show.py +1 -1
- adam/commands/show/show_adam.py +3 -3
- adam/commands/show/show_cassandra_repairs.py +5 -3
- adam/commands/show/show_cassandra_status.py +27 -20
- adam/commands/show/{show_commands.py → show_cli_commands.py} +2 -2
- adam/commands/show/show_login.py +2 -2
- adam/commands/show/show_params.py +2 -5
- adam/commands/show/show_processes.py +15 -14
- adam/commands/show/show_storage.py +9 -8
- adam/config.py +1 -0
- adam/embedded_params.py +1 -1
- adam/repl.py +16 -9
- adam/repl_commands.py +16 -9
- adam/repl_session.py +8 -1
- adam/repl_state.py +33 -10
- adam/sql/lark_completer.py +284 -0
- adam/sql/lark_parser.py +604 -0
- adam/sql/sql_state_machine.py +8 -2
- adam/utils.py +116 -29
- adam/utils_athena.py +7 -8
- adam/utils_issues.py +2 -2
- adam/utils_k8s/app_clusters.py +2 -2
- adam/utils_k8s/app_pods.py +5 -2
- adam/utils_k8s/cassandra_clusters.py +11 -3
- adam/utils_k8s/cassandra_nodes.py +2 -2
- adam/utils_k8s/k8s.py +9 -0
- adam/utils_k8s/kube_context.py +2 -2
- adam/utils_k8s/pods.py +23 -5
- adam/utils_k8s/statefulsets.py +5 -2
- adam/utils_local.py +4 -0
- adam/utils_repl/appendable_completer.py +6 -0
- adam/utils_repl/repl_completer.py +128 -2
- adam/utils_sqlite.py +2 -2
- adam/version.py +1 -1
- {kaqing-2.0.174.dist-info → kaqing-2.0.188.dist-info}/METADATA +1 -1
- kaqing-2.0.188.dist-info/RECORD +253 -0
- kaqing-2.0.188.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/postgres/postgres_context.py +0 -272
- adam/commands/postgres/psql_completions.py +0 -10
- kaqing-2.0.174.dist-info/RECORD +0 -230
- kaqing-2.0.174.dist-info/top_level.txt +0 -1
- {kaqing-2.0.174.dist-info → kaqing-2.0.188.dist-info}/WHEEL +0 -0
- {kaqing-2.0.174.dist-info → kaqing-2.0.188.dist-info}/entry_points.txt +0 -0
adam/app_session.py
CHANGED
|
@@ -8,7 +8,7 @@ from adam.log import Log
|
|
|
8
8
|
from adam.sso.idp import Idp
|
|
9
9
|
from adam.sso.idp_login import IdpLogin
|
|
10
10
|
from adam.config import Config
|
|
11
|
-
from adam.utils import debug, debug_trace, json_to_csv,
|
|
11
|
+
from adam.utils import debug, debug_trace, json_to_csv, tabulize, log2, log_exc
|
|
12
12
|
from adam.apps import Apps
|
|
13
13
|
|
|
14
14
|
class AppLogin:
|
|
@@ -63,7 +63,7 @@ class AppSession:
|
|
|
63
63
|
js = r.json()
|
|
64
64
|
with log_exc(js):
|
|
65
65
|
header, lines = json_to_csv(js, delimiter='\t')
|
|
66
|
-
|
|
66
|
+
tabulize(lines, header=header, separator='\t')
|
|
67
67
|
except:
|
|
68
68
|
if urlparse(r.url).hostname != urlparse(uri).hostname and not retried:
|
|
69
69
|
app_login = app_session.login(idp_uri=app_login.idp_uri, forced=forced, use_token_from_env=False, use_cached_creds=False)
|
adam/apps.py
CHANGED
|
@@ -12,7 +12,8 @@ from adam.utils_k8s.services import Services
|
|
|
12
12
|
from adam.utils import copy_config_file
|
|
13
13
|
|
|
14
14
|
class AppAction:
|
|
15
|
-
def __init__(self, name: str, payload: str = None, args: dict[str, str] = None, help: str = None):
|
|
15
|
+
def __init__(self, typ: str, name: str, payload: str = None, args: dict[str, str] = None, help: str = None):
|
|
16
|
+
self.typ = typ
|
|
16
17
|
self.name = name
|
|
17
18
|
self.payload = payload
|
|
18
19
|
self.args = args
|
|
@@ -33,6 +34,19 @@ class AppAction:
|
|
|
33
34
|
|
|
34
35
|
return args
|
|
35
36
|
|
|
37
|
+
def __str__(self):
|
|
38
|
+
line = None
|
|
39
|
+
|
|
40
|
+
args = ','.join(self.arguments())
|
|
41
|
+
if args:
|
|
42
|
+
line = f'{self.typ}.{self.name},{args}'
|
|
43
|
+
else:
|
|
44
|
+
line = f'{self.typ}.{self.name},'
|
|
45
|
+
if self.help:
|
|
46
|
+
line = f'{line},{self.help}'
|
|
47
|
+
|
|
48
|
+
return line
|
|
49
|
+
|
|
36
50
|
class AppType:
|
|
37
51
|
all_types: list['AppType'] = []
|
|
38
52
|
|
|
@@ -62,12 +76,12 @@ class AppType:
|
|
|
62
76
|
aa: AppAction = None
|
|
63
77
|
|
|
64
78
|
if isinstance(v, str):
|
|
65
|
-
aa = AppAction(k, help=v)
|
|
79
|
+
aa = AppAction(typ, k, help=v)
|
|
66
80
|
elif isinstance(v, dict):
|
|
67
81
|
args = {k: v1 for k, v1 in v.items()}
|
|
68
|
-
aa = AppAction(k, payload=v['payload'], args=args, help=v['help'])
|
|
82
|
+
aa = AppAction(typ, k, payload=v['payload'], args=args, help=v['help'])
|
|
69
83
|
else:
|
|
70
|
-
aa = AppAction(k)
|
|
84
|
+
aa = AppAction(typ, k)
|
|
71
85
|
|
|
72
86
|
app_actions.append(aa)
|
|
73
87
|
|
adam/batch.py
CHANGED
|
@@ -3,7 +3,7 @@ import click
|
|
|
3
3
|
from adam.commands.audit.audit import Audit, AuditCommandHelper
|
|
4
4
|
from adam.commands.bash.bash import Bash
|
|
5
5
|
from adam.commands.check import Check, CheckCommandHelper
|
|
6
|
-
from adam.commands.
|
|
6
|
+
from adam.commands.clipboard_copy import ClipboardCopy, CopyCommandHelper
|
|
7
7
|
from adam.commands.command import Command
|
|
8
8
|
from adam.commands.command_helpers import ClusterCommandHelper, ClusterOrPodCommandHelper, PodCommandHelper
|
|
9
9
|
from adam.commands.cql.cqlsh import CqlCommandHelper, Cqlsh
|
adam/checks/check_utils.py
CHANGED
|
@@ -47,7 +47,9 @@ def run_checks(cluster: str = None, namespace: str = None, pod: str = None, chec
|
|
|
47
47
|
if not pod or pod == pod_name:
|
|
48
48
|
sts_ns_pods.append((sts, ns, pod_name))
|
|
49
49
|
|
|
50
|
-
with parallelize(sts_ns_pods,
|
|
50
|
+
with parallelize(sts_ns_pods,
|
|
51
|
+
Config().action_workers('issues', 30),
|
|
52
|
+
msg='d`Running|Ran checks on {size} pods') as exec:
|
|
51
53
|
return exec.map(lambda sts_ns_pod: run_checks_on_pod(checks, sts_ns_pod[0], sts_ns_pod[1], sts_ns_pod[2], show_out))
|
|
52
54
|
|
|
53
55
|
def run_checks_on_pod(checks: list[Check], cluster: str = None, namespace: str = None, pod: str = None, show_out=True):
|
adam/commands/__init__.py
CHANGED
|
@@ -18,5 +18,7 @@ def extract_all_options(args: list[str], trailing = None, sequence = None, optio
|
|
|
18
18
|
def extract_sequence(args: list[str], sequence: list[str]):
|
|
19
19
|
return ExtractSequenceOptionsHandler(args, sequence = sequence)
|
|
20
20
|
|
|
21
|
-
def validate_args(args: list[str], state: ReplState,
|
|
22
|
-
|
|
21
|
+
def validate_args(args: list[str], state: ReplState, at_least: int = 1, exactly: int = -1,
|
|
22
|
+
name: str = None, msg: Callable[[], None] = None, default: str = None,
|
|
23
|
+
separator=None):
|
|
24
|
+
return ValidateArgCountHandler(args, state, at_least=at_least, exactly=exactly, name=name, msg=msg, default=default, separator=separator)
|
|
File without changes
|
adam/commands/app/app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from adam.commands import app, extract_options
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.repl_state import ReplState, RequiredState
|
|
4
|
+
|
|
5
|
+
class App(Command):
|
|
6
|
+
COMMAND = 'app'
|
|
7
|
+
|
|
8
|
+
# the singleton pattern
|
|
9
|
+
def __new__(cls, *args, **kwargs):
|
|
10
|
+
if not hasattr(cls, 'instance'): cls.instance = super(App, cls).__new__(cls)
|
|
11
|
+
|
|
12
|
+
return cls.instance
|
|
13
|
+
|
|
14
|
+
def __init__(self, successor: Command=None):
|
|
15
|
+
super().__init__(successor)
|
|
16
|
+
|
|
17
|
+
def command(self):
|
|
18
|
+
return App.COMMAND
|
|
19
|
+
|
|
20
|
+
def required(self):
|
|
21
|
+
return RequiredState.APP_APP
|
|
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
|
+
with extract_options(args, '--force') as (args, forced):
|
|
29
|
+
with app(state) as http:
|
|
30
|
+
http.post(args, forced=forced)
|
|
31
|
+
|
|
32
|
+
return state
|
|
33
|
+
|
|
34
|
+
def completion(self, _: ReplState):
|
|
35
|
+
return {}
|
|
36
|
+
|
|
37
|
+
def help(self, _: ReplState):
|
|
38
|
+
return f"<AppType>.<AppAction> <args> [--force]\t post app action; check with 'show app actions' command"
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from adam.commands import app, extract_options
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.repl_state import ReplState, RequiredState
|
|
4
|
+
|
|
5
|
+
class AppPing(Command):
|
|
6
|
+
COMMAND = 'app ping'
|
|
7
|
+
|
|
8
|
+
# the singleton pattern
|
|
9
|
+
def __new__(cls, *args, **kwargs):
|
|
10
|
+
if not hasattr(cls, 'instance'): cls.instance = super(AppPing, cls).__new__(cls)
|
|
11
|
+
|
|
12
|
+
return cls.instance
|
|
13
|
+
|
|
14
|
+
def __init__(self, successor: Command=None):
|
|
15
|
+
super().__init__(successor)
|
|
16
|
+
|
|
17
|
+
def command(self):
|
|
18
|
+
return AppPing.COMMAND
|
|
19
|
+
|
|
20
|
+
def required(self):
|
|
21
|
+
return RequiredState.APP_APP
|
|
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
|
+
with extract_options(args, '--force') as (args, forced):
|
|
29
|
+
with app(state) as http:
|
|
30
|
+
http.post(['Echo.echoStatic'], forced=forced)
|
|
31
|
+
|
|
32
|
+
return state
|
|
33
|
+
|
|
34
|
+
def completion(self, state: ReplState):
|
|
35
|
+
return super().completion(state, {'--force': None})
|
|
36
|
+
|
|
37
|
+
def help(self, _: ReplState):
|
|
38
|
+
return f"{AppPing.COMMAND} [--force]\t ping app server with Echo.echoStatic()"
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from adam.app_session import AppSession
|
|
2
|
+
from adam.apps import 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"
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.utils_k8s.custom_resources import CustomResources
|
|
3
|
+
from adam.repl_state import ReplState, RequiredState
|
|
4
|
+
from adam.utils import log
|
|
5
|
+
|
|
6
|
+
class ShowAppId(Command):
|
|
7
|
+
COMMAND = 'show app id'
|
|
8
|
+
|
|
9
|
+
# the singleton pattern
|
|
10
|
+
def __new__(cls, *args, **kwargs):
|
|
11
|
+
if not hasattr(cls, 'instance'): cls.instance = super(ShowAppId, 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 ShowAppId.COMMAND
|
|
20
|
+
|
|
21
|
+
def required(self):
|
|
22
|
+
return RequiredState.CLUSTER_OR_POD
|
|
23
|
+
|
|
24
|
+
def run(self, cmd: str, state: ReplState):
|
|
25
|
+
if not(args := self.args(cmd)):
|
|
26
|
+
return super().run(cmd, state)
|
|
27
|
+
|
|
28
|
+
with self.validate(args, state) as (args, state):
|
|
29
|
+
c3_app_id = 'Unknown'
|
|
30
|
+
|
|
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])
|
|
35
|
+
|
|
36
|
+
log(c3_app_id)
|
|
37
|
+
|
|
38
|
+
return c3_app_id
|
|
39
|
+
|
|
40
|
+
def completion(self, state: ReplState):
|
|
41
|
+
return super().completion(state)
|
|
42
|
+
|
|
43
|
+
def help(self, _: ReplState):
|
|
44
|
+
return f'{ShowAppId.COMMAND}\t show app id for the Cassandra cluster'
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from adam.commands import app, extract_options
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.repl_state import ReplState, RequiredState
|
|
4
|
+
|
|
5
|
+
class ShowAppQueues(Command):
|
|
6
|
+
COMMAND = 'show app queues'
|
|
7
|
+
|
|
8
|
+
# the singleton pattern
|
|
9
|
+
def __new__(cls, *args, **kwargs):
|
|
10
|
+
if not hasattr(cls, 'instance'): cls.instance = super(ShowAppQueues, cls).__new__(cls)
|
|
11
|
+
|
|
12
|
+
return cls.instance
|
|
13
|
+
|
|
14
|
+
def __init__(self, successor: Command=None):
|
|
15
|
+
super().__init__(successor)
|
|
16
|
+
|
|
17
|
+
def command(self):
|
|
18
|
+
return ShowAppQueues.COMMAND
|
|
19
|
+
|
|
20
|
+
def required(self):
|
|
21
|
+
return RequiredState.APP_APP
|
|
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 (_, state):
|
|
28
|
+
with extract_options(args, '--force') as (args, forced):
|
|
29
|
+
with app(state) as http:
|
|
30
|
+
http.post(['InvalidationQueue.countAll'], forced=forced)
|
|
31
|
+
|
|
32
|
+
return state
|
|
33
|
+
|
|
34
|
+
def completion(self, state: ReplState):
|
|
35
|
+
return super().completion(state, {'--force': None})
|
|
36
|
+
|
|
37
|
+
def help(self, _: ReplState):
|
|
38
|
+
return f"{ShowAppQueues.COMMAND} [--force]\t show invalidation queue counts"
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
def app_cd_dirs(state: ReplState):
|
|
13
|
+
if state.app_app:
|
|
14
|
+
return ['..'] + AppPods.pod_names(state.namespace, state.app_env, state.app_app)
|
|
15
|
+
elif state.app_env:
|
|
16
|
+
return ['..'] + [app[0].split('-')[1] for app in Apps.apps(state.app_env)]
|
|
17
|
+
else:
|
|
18
|
+
return [env[0] for env in Apps.envs()]
|
|
19
|
+
|
|
20
|
+
class AppRestHandler:
|
|
21
|
+
def __init__(self, state: ReplState, forced = False):
|
|
22
|
+
self.state = state
|
|
23
|
+
self.forced = forced
|
|
24
|
+
|
|
25
|
+
def __enter__(self):
|
|
26
|
+
return self.post
|
|
27
|
+
|
|
28
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
29
|
+
return False
|
|
30
|
+
|
|
31
|
+
def post(self, args: list[str]) -> Union[ReplState, str]:
|
|
32
|
+
if not args:
|
|
33
|
+
return 'arg missing'
|
|
34
|
+
|
|
35
|
+
t_f = args[0].split('.')
|
|
36
|
+
if len(t_f) < 2:
|
|
37
|
+
return 'arg missing'
|
|
38
|
+
|
|
39
|
+
state = self.state
|
|
40
|
+
|
|
41
|
+
payload, valid = Apps().payload(t_f[0], t_f[1], args[1:] if len(args) > 1 else [])
|
|
42
|
+
if not valid:
|
|
43
|
+
log2('Missing one or more action arguments.')
|
|
44
|
+
return state
|
|
45
|
+
|
|
46
|
+
if payload:
|
|
47
|
+
try:
|
|
48
|
+
payload = json.loads(payload)
|
|
49
|
+
except json.decoder.JSONDecodeError as e:
|
|
50
|
+
log2(f'Invalid json argument: {e}')
|
|
51
|
+
return state
|
|
52
|
+
|
|
53
|
+
AppSession.run(state.app_env, state.app_app, state.namespace, t_f[0], t_f[1], payload=payload, forced=self.forced)
|
|
54
|
+
|
|
55
|
+
return state
|
|
56
|
+
|
|
57
|
+
class AppPodService:
|
|
58
|
+
def __init__(self, handler: 'AppHandler'):
|
|
59
|
+
self.handler = handler
|
|
60
|
+
|
|
61
|
+
def exec(self, command: str, show_out = True) -> Union[PodExecResult, list[PodExecResult]]:
|
|
62
|
+
state = self.handler.state
|
|
63
|
+
|
|
64
|
+
if state.app_pod:
|
|
65
|
+
return AppPods.exec(state.app_pod, state.namespace, command, show_out=show_out, shell='bash')
|
|
66
|
+
elif state.app_app:
|
|
67
|
+
pods = AppPods.pod_names(state.namespace, state.app_env, state.app_app)
|
|
68
|
+
return AppClusters.exec(pods, state.namespace, command, action='bash', show_out=show_out, shell='bash')
|
|
69
|
+
|
|
70
|
+
return []
|
|
71
|
+
|
|
72
|
+
def post(self, args: list[str], forced=False) -> Union[ReplState, str]:
|
|
73
|
+
state = self.handler.state
|
|
74
|
+
|
|
75
|
+
if not args:
|
|
76
|
+
return 'arg missing'
|
|
77
|
+
|
|
78
|
+
t_f = args[0].split('.')
|
|
79
|
+
if len(t_f) < 2:
|
|
80
|
+
return 'arg missing'
|
|
81
|
+
|
|
82
|
+
payload, valid = Apps().payload(t_f[0], t_f[1], args[1:] if len(args) > 1 else [])
|
|
83
|
+
if not valid:
|
|
84
|
+
log2('Missing one or more action arguments.')
|
|
85
|
+
return state
|
|
86
|
+
|
|
87
|
+
if payload:
|
|
88
|
+
try:
|
|
89
|
+
payload = json.loads(payload)
|
|
90
|
+
except json.decoder.JSONDecodeError as e:
|
|
91
|
+
log2(f'Invalid json argument: {e}')
|
|
92
|
+
return state
|
|
93
|
+
|
|
94
|
+
AppSession.run(state.app_env, state.app_app, state.namespace, t_f[0], t_f[1], payload=payload, forced=forced)
|
|
95
|
+
|
|
96
|
+
return state
|
|
97
|
+
|
|
98
|
+
class AppHandler:
|
|
99
|
+
def __init__(self, state: ReplState):
|
|
100
|
+
self.state = state
|
|
101
|
+
|
|
102
|
+
def __enter__(self):
|
|
103
|
+
return AppPodService(self)
|
|
104
|
+
|
|
105
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
106
|
+
return False
|
adam/commands/audit/audit.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import click
|
|
2
2
|
|
|
3
|
+
from adam.commands import validate_args
|
|
4
|
+
from adam.commands.audit.completions_l import completions_l
|
|
3
5
|
from adam.commands.audit.audit_repair_tables import AuditRepairTables
|
|
4
6
|
from adam.commands.audit.audit_run import AuditRun
|
|
5
7
|
from adam.commands.audit.show_last10 import ShowLast10
|
|
@@ -8,9 +10,8 @@ from adam.commands.audit.show_top10 import ShowTop10
|
|
|
8
10
|
from adam.commands.audit.utils_show_top10 import show_top10_completions_for_nesting
|
|
9
11
|
from adam.commands.command import Command
|
|
10
12
|
from adam.commands.intermediate_command import IntermediateCommand
|
|
11
|
-
from adam.config import Config
|
|
12
13
|
from adam.repl_state import ReplState
|
|
13
|
-
from adam.sql.
|
|
14
|
+
from adam.sql.lark_completer import LarkCompleter
|
|
14
15
|
from adam.utils import log2, wait_log
|
|
15
16
|
from adam.utils_athena import Athena
|
|
16
17
|
|
|
@@ -43,36 +44,17 @@ class Audit(IntermediateCommand):
|
|
|
43
44
|
r = self.intermediate_run(cmd, state, args, self.cmd_list(), display_help=False)
|
|
44
45
|
|
|
45
46
|
if not r or isinstance(r, str) and r == 'command-missing':
|
|
46
|
-
|
|
47
|
-
if args:
|
|
48
|
-
sql = ' '.join(args)
|
|
49
|
-
else:
|
|
47
|
+
with validate_args(args, state, default='select * from audit order by ts desc limit 10') as sql:
|
|
50
48
|
log2(sql)
|
|
51
|
-
|
|
52
|
-
Athena.run_query(sql)
|
|
49
|
+
Athena.run_query(sql)
|
|
53
50
|
|
|
54
51
|
return state
|
|
55
52
|
|
|
56
53
|
def completion(self, state: ReplState):
|
|
57
|
-
if state.device
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
# warm up the caches first time when l: drive is accessed
|
|
62
|
-
Athena.table_names()
|
|
63
|
-
Athena.column_names()
|
|
64
|
-
Athena.column_names(partition_cols_only=True)
|
|
65
|
-
|
|
66
|
-
return super().completion(state) | show_top10_completions_for_nesting() | SqlCompleter(
|
|
67
|
-
lambda: Athena.table_names(),
|
|
68
|
-
expandables={
|
|
69
|
-
'columns': lambda table: Athena.column_names(),
|
|
70
|
-
'partition_columns': lambda table: Athena.column_names(partition_cols_only=True)
|
|
71
|
-
},
|
|
72
|
-
variant=SqlVariant.ATHENA
|
|
73
|
-
).completions_for_nesting()
|
|
74
|
-
|
|
75
|
-
return {}
|
|
54
|
+
if state.device != ReplState.L:
|
|
55
|
+
return {}
|
|
56
|
+
|
|
57
|
+
return completions_l()
|
|
76
58
|
|
|
77
59
|
def cmd_list(self):
|
|
78
60
|
return [AuditRepairTables(), AuditRun(), ShowLast10(), ShowSlow10(), ShowTop10()]
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import time
|
|
2
2
|
|
|
3
|
+
from adam.commands import validate_args
|
|
3
4
|
from adam.commands.command import Command
|
|
4
5
|
from adam.config import Config
|
|
5
6
|
from adam.repl_state import ReplState
|
|
@@ -31,12 +32,9 @@ class AuditRepairTables(Command):
|
|
|
31
32
|
return super().run(cmd, state)
|
|
32
33
|
|
|
33
34
|
with self.validate(args, state) as (args, state):
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
tables
|
|
37
|
-
|
|
38
|
-
meta = Audits.get_meta()
|
|
39
|
-
self.repair(tables, meta)
|
|
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
39
|
return state
|
|
42
40
|
|
|
@@ -48,7 +46,7 @@ class AuditRepairTables(Command):
|
|
|
48
46
|
with Audits.offload() as exec:
|
|
49
47
|
exec.submit(lambda: self.auto_repair(hours))
|
|
50
48
|
|
|
51
|
-
return super().completion(state)
|
|
49
|
+
# return super().completion(state)
|
|
52
50
|
|
|
53
51
|
return {}
|
|
54
52
|
|
adam/commands/audit/audit_run.py
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from adam.repl_state import ReplState
|
|
2
|
+
from adam.sql.lark_completer import LarkCompleter
|
|
3
|
+
from adam.utils_athena import Athena
|
|
4
|
+
|
|
5
|
+
def completions_l():
|
|
6
|
+
return LarkCompleter(
|
|
7
|
+
expandables={
|
|
8
|
+
'tables': lambda x: Athena.table_names(),
|
|
9
|
+
'columns': lambda table: Athena.column_names(),
|
|
10
|
+
'partition-columns': lambda table: Athena.column_names(partition_cols_only=True),
|
|
11
|
+
'topn-counts': lambda x: ['10'],
|
|
12
|
+
'topn-types': lambda x: ['last', 'slow', 'top'],
|
|
13
|
+
'topn-windows': lambda x: ['day', 'month'],
|
|
14
|
+
}, variant=ReplState.L
|
|
15
|
+
).completions_for_nesting()
|
|
@@ -1,9 +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_athena import Athena
|
|
6
|
-
from adam.utils_audits import Audits
|
|
7
4
|
|
|
8
5
|
class ShowLast10(Command):
|
|
9
6
|
COMMAND = 'show last'
|
|
@@ -28,20 +25,11 @@ class ShowLast10(Command):
|
|
|
28
25
|
return super().run(cmd, state)
|
|
29
26
|
|
|
30
27
|
with self.validate(args, state) as (args, state):
|
|
31
|
-
|
|
32
|
-
|
|
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)
|
|
28
|
+
run_configured_query('audit.queries.last10', args)
|
|
40
29
|
|
|
41
30
|
return state
|
|
42
31
|
|
|
43
32
|
def completion(self, _: ReplState):
|
|
44
|
-
|
|
45
33
|
return {}
|
|
46
34
|
|
|
47
35
|
def help(self, _: ReplState):
|
|
@@ -1,9 +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_athena import Athena
|
|
6
|
-
from adam.utils_audits import Audits
|
|
7
4
|
|
|
8
5
|
class ShowSlow10(Command):
|
|
9
6
|
COMMAND = 'show slow'
|
|
@@ -28,15 +25,7 @@ class ShowSlow10(Command):
|
|
|
28
25
|
return super().run(cmd, state)
|
|
29
26
|
|
|
30
27
|
with self.validate(args, state) as (args, state):
|
|
31
|
-
|
|
32
|
-
|
|
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)
|
|
28
|
+
run_configured_query('audit.queries.slow10', args)
|
|
40
29
|
|
|
41
30
|
return state
|
|
42
31
|
|
|
@@ -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_athena import Athena
|
|
6
4
|
|
|
7
5
|
class ShowTop10(Command):
|
|
8
6
|
COMMAND = 'show top'
|
|
@@ -27,14 +25,7 @@ class ShowTop10(Command):
|
|
|
27
25
|
return super().run(cmd, state)
|
|
28
26
|
|
|
29
27
|
with self.validate(args, state) as (args, state):
|
|
30
|
-
|
|
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)
|
|
28
|
+
run_configured_query('audit.queries.top10', args)
|
|
38
29
|
|
|
39
30
|
return state
|
|
40
31
|
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
from datetime import datetime, timedelta
|
|
2
2
|
|
|
3
|
-
from adam.
|
|
3
|
+
from adam.config import Config
|
|
4
|
+
from adam.utils import log2, log_exc
|
|
5
|
+
from adam.utils_athena import Athena
|
|
4
6
|
from adam.utils_audits import Audits
|
|
5
7
|
from adam.utils_repl.automata_completer import AutomataCompleter
|
|
6
8
|
from adam.utils_repl.state_machine import StateMachine
|
|
7
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
|
+
|
|
8
21
|
def extract_limit_and_duration(args: list[str]) -> tuple[int, datetime]:
|
|
9
22
|
limit = 10
|
|
10
23
|
_from = datetime.now() - timedelta(days=30)
|
adam/commands/bash/bash.py
CHANGED
|
@@ -30,7 +30,7 @@ class Bash(Command):
|
|
|
30
30
|
return exec(args)
|
|
31
31
|
|
|
32
32
|
def completion(self, state: ReplState):
|
|
33
|
-
return
|
|
33
|
+
return super().completion(state, {c : {'&': None} for c in ['ls', 'cat', 'head']}, pods=Devices.device(state).pods(state, '-'))
|
|
34
34
|
|
|
35
35
|
def help(self, _: ReplState):
|
|
36
36
|
return f'{Bash.COMMAND} [pod-name] [bash-commands] [&]\t run bash on the Cassandra nodes'
|