kaqing 2.0.52__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 +20 -6
- adam/batch.py +15 -19
- adam/checks/check_utils.py +19 -49
- adam/checks/compactionstats.py +1 -1
- adam/checks/cpu.py +9 -3
- adam/checks/cpu_metrics.py +52 -0
- adam/checks/disk.py +3 -4
- adam/checks/gossip.py +1 -1
- adam/checks/memory.py +3 -3
- adam/checks/status.py +1 -1
- 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 +37 -63
- adam/commands/app/app.py +38 -0
- adam/commands/{app_ping.py → app/app_ping.py} +8 -14
- adam/commands/app/show_app_actions.py +49 -0
- adam/commands/{show → app}/show_app_id.py +9 -12
- adam/commands/{show → app}/show_app_queues.py +8 -14
- adam/commands/app/utils_app.py +98 -0
- adam/commands/audit/audit.py +81 -0
- adam/commands/audit/audit_repair_tables.py +72 -0
- adam/commands/audit/audit_run.py +50 -0
- adam/commands/audit/show_last10.py +37 -0
- adam/commands/audit/show_slow10.py +36 -0
- adam/commands/audit/show_top10.py +36 -0
- adam/commands/audit/utils_show_top10.py +71 -0
- 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 +14 -89
- adam/commands/check.py +18 -21
- adam/commands/cli_commands.py +5 -6
- adam/commands/clipboard_copy.py +86 -0
- adam/commands/code.py +57 -0
- adam/commands/command.py +197 -35
- adam/commands/commands_utils.py +15 -31
- adam/commands/cql/cql_completions.py +29 -8
- adam/commands/cql/cqlsh.py +12 -27
- 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 +5 -5
- adam/commands/deploy/deploy.py +4 -21
- adam/commands/deploy/deploy_frontend.py +14 -17
- adam/commands/deploy/deploy_pg_agent.py +3 -6
- adam/commands/deploy/deploy_pod.py +71 -79
- adam/commands/deploy/deploy_utils.py +16 -26
- adam/commands/deploy/undeploy.py +4 -21
- adam/commands/deploy/undeploy_frontend.py +4 -7
- adam/commands/deploy/undeploy_pg_agent.py +6 -8
- adam/commands/deploy/undeploy_pod.py +15 -16
- 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 +14 -9
- adam/commands/intermediate_command.py +49 -0
- adam/commands/issues.py +14 -40
- adam/commands/kubectl.py +38 -0
- adam/commands/login.py +26 -25
- adam/commands/logs.py +5 -7
- adam/commands/ls.py +11 -110
- adam/commands/medusa/medusa.py +4 -22
- adam/commands/medusa/medusa_backup.py +22 -29
- adam/commands/medusa/medusa_restore.py +40 -39
- adam/commands/medusa/medusa_show_backupjobs.py +19 -20
- adam/commands/medusa/medusa_show_restorejobs.py +15 -20
- adam/commands/nodetool.py +11 -15
- 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 +10 -61
- adam/commands/pwd.py +14 -43
- adam/commands/reaper/reaper.py +4 -24
- 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 +8 -15
- 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 +6 -12
- adam/commands/repair/repair_run.py +29 -36
- adam/commands/repair/repair_scan.py +33 -39
- adam/commands/repair/repair_stop.py +6 -12
- adam/commands/report.py +25 -21
- adam/commands/restart.py +27 -28
- adam/commands/rollout.py +20 -25
- adam/commands/shell.py +12 -4
- adam/commands/show/show.py +11 -23
- adam/commands/show/show_adam.py +3 -3
- adam/commands/show/show_cassandra_repairs.py +35 -0
- adam/commands/show/show_cassandra_status.py +34 -52
- adam/commands/show/show_cassandra_version.py +5 -18
- adam/commands/show/show_commands.py +20 -25
- adam/commands/show/show_host.py +33 -0
- adam/commands/show/show_login.py +23 -27
- adam/commands/show/show_params.py +2 -5
- adam/commands/show/show_processes.py +16 -20
- adam/commands/show/show_storage.py +10 -20
- adam/commands/watch.py +27 -30
- adam/config.py +7 -15
- adam/embedded_params.py +1 -1
- adam/log.py +4 -4
- adam/pod_exec_result.py +13 -5
- adam/repl.py +126 -119
- adam/repl_commands.py +63 -29
- adam/repl_state.py +320 -71
- adam/sql/sql_completer.py +98 -383
- adam/sql/sql_state_machine.py +630 -0
- adam/sql/term_completer.py +14 -4
- adam/sso/authn_ad.py +6 -8
- adam/sso/authn_okta.py +4 -6
- adam/sso/cred_cache.py +4 -6
- adam/sso/idp.py +10 -13
- adam/utils.py +511 -10
- adam/utils_athena.py +145 -0
- adam/utils_audits.py +102 -0
- adam/utils_issues.py +32 -0
- adam/utils_k8s/__init__.py +0 -0
- adam/utils_k8s/app_clusters.py +28 -0
- adam/utils_k8s/app_pods.py +36 -0
- adam/utils_k8s/cassandra_clusters.py +44 -0
- adam/{k8s_utils → utils_k8s}/cassandra_nodes.py +11 -4
- adam/{k8s_utils → utils_k8s}/custom_resources.py +16 -17
- adam/{k8s_utils → utils_k8s}/deployment.py +2 -2
- adam/{k8s_utils → utils_k8s}/ingresses.py +2 -2
- adam/{k8s_utils → utils_k8s}/jobs.py +7 -11
- adam/utils_k8s/k8s.py +87 -0
- adam/{k8s_utils → utils_k8s}/kube_context.py +2 -2
- adam/{k8s_utils → utils_k8s}/pods.py +109 -74
- adam/{k8s_utils → utils_k8s}/secrets.py +7 -3
- adam/{k8s_utils → utils_k8s}/service_accounts.py +5 -4
- adam/{k8s_utils → utils_k8s}/services.py +2 -2
- adam/{k8s_utils → utils_k8s}/statefulsets.py +3 -14
- adam/utils_local.py +4 -0
- adam/utils_net.py +24 -0
- 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.52.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 -87
- adam/commands/cp.py +0 -95
- adam/commands/cql/cql_table_completer.py +0 -8
- adam/commands/cql/cql_utils.py +0 -109
- adam/commands/describe/describe.py +0 -46
- adam/commands/describe/describe_keyspace.py +0 -60
- adam/commands/describe/describe_keyspaces.py +0 -50
- adam/commands/describe/describe_table.py +0 -60
- adam/commands/describe/describe_tables.py +0 -50
- adam/commands/devices.py +0 -89
- adam/commands/postgres/postgres_session.py +0 -240
- adam/commands/postgres/postgres_utils.py +0 -31
- adam/commands/postgres/psql_table_completer.py +0 -11
- adam/commands/reaper/reaper_session.py +0 -159
- adam/commands/show/show_app_actions.py +0 -53
- adam/commands/show/show_repairs.py +0 -47
- adam/k8s_utils/cassandra_clusters.py +0 -35
- adam/sql/sql_utils.py +0 -5
- kaqing-2.0.52.dist-info/RECORD +0 -184
- /adam/commands/{describe → app}/__init__.py +0 -0
- /adam/{k8s_utils → commands/audit}/__init__.py +0 -0
- /adam/{k8s_utils → utils_k8s}/config_maps.py +0 -0
- /adam/{k8s_utils → utils_k8s}/volumes.py +0 -0
- {kaqing-2.0.52.dist-info → kaqing-2.0.184.dist-info}/WHEEL +0 -0
- {kaqing-2.0.52.dist-info → kaqing-2.0.184.dist-info}/entry_points.txt +0 -0
- {kaqing-2.0.52.dist-info → kaqing-2.0.184.dist-info}/top_level.txt +0 -0
adam/commands/alter_tables.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
from adam.commands import extract_options, validate_args
|
|
1
2
|
from adam.commands.command import Command
|
|
2
|
-
from adam.commands.cql.
|
|
3
|
+
from adam.commands.cql.utils_cql import cassandra, cassandra_tables as get_tables
|
|
3
4
|
from adam.config import Config
|
|
4
|
-
from adam.pod_exec_result import PodExecResult
|
|
5
5
|
from adam.repl_state import ReplState, RequiredState
|
|
6
|
-
from adam.utils import log2
|
|
6
|
+
from adam.utils import log2, log_exc
|
|
7
7
|
|
|
8
8
|
class AlterTables(Command):
|
|
9
9
|
COMMAND = 'alter tables with'
|
|
@@ -27,66 +27,40 @@ class AlterTables(Command):
|
|
|
27
27
|
if not(args := self.args(cmd)):
|
|
28
28
|
return super().run(cmd, state)
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
run_cql(state, cql, [], show_out=Config().is_debug(), on_any=True)
|
|
64
|
-
except Exception as e:
|
|
65
|
-
log2(e)
|
|
66
|
-
continue
|
|
67
|
-
else:
|
|
68
|
-
for t in v:
|
|
69
|
-
try:
|
|
70
|
-
# alter table <table_name> with GC_GRACE_SECONDS = <timeout>;
|
|
71
|
-
cql = f'alter table {k}.{t} with {arg_str}'
|
|
72
|
-
run_cql(state, cql, [], show_out=Config().is_debug(), on_any=True)
|
|
73
|
-
except Exception as e:
|
|
74
|
-
log2(e)
|
|
75
|
-
continue
|
|
76
|
-
|
|
77
|
-
log2(f'{len(v)} tables altered in {k}.')
|
|
78
|
-
|
|
79
|
-
# do not continue to cql route
|
|
80
|
-
return state
|
|
81
|
-
|
|
82
|
-
def completion(self, state: ReplState) -> dict[str, any]:
|
|
83
|
-
if state.sts:
|
|
84
|
-
ps = Config().get('cql.alter-tables.gc-grace-periods', '3600,86400,864000,7776000').split(',')
|
|
85
|
-
return super().completion(state, {
|
|
86
|
-
'GC_GRACE_SECONDS': {'=': {p.strip(' \r\n'): {'--include-reaper': None} for p in ps}},
|
|
87
|
-
})
|
|
88
|
-
|
|
30
|
+
with self.validate(args, state) as (args, state):
|
|
31
|
+
with extract_options(args, '--include-reaper') as (args, include_reaper):
|
|
32
|
+
with validate_args(args, state, name='gc grace in seconds') as arg_str:
|
|
33
|
+
excludes = [e.strip(' \r\n') for e in Config().get(
|
|
34
|
+
'cql.alter-tables.excludes',
|
|
35
|
+
'system_auth,system_traces,reaper_db,system_distributed,system_views,system,system_schema,system_virtual_schema').split(',')]
|
|
36
|
+
batching = Config().get('cql.alter-tables.batching', True)
|
|
37
|
+
tables = get_tables(state, on_any=True)
|
|
38
|
+
for k, v in tables.items():
|
|
39
|
+
if k not in excludes or k == 'reaper_db' and include_reaper:
|
|
40
|
+
if batching:
|
|
41
|
+
# alter table <table_name> with GC_GRACE_SECONDS = <timeout>;
|
|
42
|
+
cql = ';\n'.join([f'alter table {k}.{t} with {arg_str}' for t in v])
|
|
43
|
+
with log_exc(True):
|
|
44
|
+
with cassandra(state) as pods:
|
|
45
|
+
pods.cql(cql, show_out=Config().is_debug(), show_query=not Config().is_debug(), on_any=True)
|
|
46
|
+
continue
|
|
47
|
+
else:
|
|
48
|
+
for t in v:
|
|
49
|
+
with log_exc(True):
|
|
50
|
+
# alter table <table_name> with GC_GRACE_SECONDS = <timeout>;
|
|
51
|
+
cql = f'alter table {k}.{t} with {arg_str}'
|
|
52
|
+
with cassandra(state) as pods:
|
|
53
|
+
pods.cql(show_out=Config().is_debug(), show_query=not Config().is_debug(), on_any=True)
|
|
54
|
+
continue
|
|
55
|
+
|
|
56
|
+
log2(f'{len(v)} tables altered in {k}.')
|
|
57
|
+
|
|
58
|
+
# do not continue to cql route
|
|
59
|
+
return state
|
|
60
|
+
|
|
61
|
+
def completion(self, _: ReplState) -> dict[str, any]:
|
|
62
|
+
# auto completion is taken care of by sql completer
|
|
89
63
|
return {}
|
|
90
64
|
|
|
91
65
|
def help(self, _: ReplState) -> str:
|
|
92
|
-
return f'{AlterTables.COMMAND} <param = value> [--include-reaper] \t alter on all tables'
|
|
66
|
+
return f'{AlterTables.COMMAND} <param = value> [--include-reaper] \t alter schema on all tables'
|
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, state: ReplState):
|
|
35
|
+
return super().completion(state, {'--force': None})
|
|
36
|
+
|
|
37
|
+
def help(self, _: ReplState):
|
|
38
|
+
return f"<AppType>.<AppAction> <args> [--force]\t post app action; check with 'show app actions' command"
|
|
@@ -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 AppPing(Command):
|
|
6
6
|
COMMAND = 'app ping'
|
|
@@ -18,27 +18,21 @@ class AppPing(Command):
|
|
|
18
18
|
return AppPing.COMMAND
|
|
19
19
|
|
|
20
20
|
def required(self):
|
|
21
|
-
return RequiredState.
|
|
21
|
+
return RequiredState.APP_APP
|
|
22
22
|
|
|
23
23
|
def run(self, cmd: str, state: ReplState):
|
|
24
24
|
if not(args := self.args(cmd)):
|
|
25
25
|
return super().run(cmd, state)
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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)
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
AppSession.run(state.app_env, state.app_app, state.namespace, 'Echo', 'echoStatic', forced= forced)
|
|
34
|
-
|
|
35
|
-
return state
|
|
32
|
+
return state
|
|
36
33
|
|
|
37
34
|
def completion(self, state: ReplState):
|
|
38
|
-
|
|
39
|
-
return super().completion(state, {'--force': None})
|
|
40
|
-
|
|
41
|
-
return {}
|
|
35
|
+
return super().completion(state, {'--force': None})
|
|
42
36
|
|
|
43
37
|
def help(self, _: ReplState):
|
|
44
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 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"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from adam.commands.command import Command
|
|
2
|
-
from adam.
|
|
2
|
+
from adam.utils_k8s.custom_resources import CustomResources
|
|
3
3
|
from adam.repl_state import ReplState, RequiredState
|
|
4
4
|
from adam.utils import log
|
|
5
5
|
|
|
@@ -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'
|
|
@@ -18,27 +18,21 @@ class ShowAppQueues(Command):
|
|
|
18
18
|
return ShowAppQueues.COMMAND
|
|
19
19
|
|
|
20
20
|
def required(self):
|
|
21
|
-
return RequiredState.
|
|
21
|
+
return RequiredState.APP_APP
|
|
22
22
|
|
|
23
23
|
def run(self, cmd: str, state: ReplState):
|
|
24
24
|
if not(args := self.args(cmd)):
|
|
25
25
|
return super().run(cmd, state)
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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)
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
AppSession.run(state.app_env, state.app_app, state.namespace, 'InvalidationQueue', 'countAll', forced= forced)
|
|
34
|
-
|
|
35
|
-
return state
|
|
32
|
+
return state
|
|
36
33
|
|
|
37
34
|
def completion(self, state: ReplState):
|
|
38
|
-
|
|
39
|
-
return super().completion(state, {'--force': None})
|
|
40
|
-
|
|
41
|
-
return {}
|
|
35
|
+
return super().completion(state, {'--force': None})
|
|
42
36
|
|
|
43
37
|
def help(self, _: ReplState):
|
|
44
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
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import click
|
|
2
|
+
|
|
3
|
+
from adam.commands import validate_args
|
|
4
|
+
from adam.commands.audit.audit_repair_tables import AuditRepairTables
|
|
5
|
+
from adam.commands.audit.audit_run import AuditRun
|
|
6
|
+
from adam.commands.audit.show_last10 import ShowLast10
|
|
7
|
+
from adam.commands.audit.show_slow10 import ShowSlow10
|
|
8
|
+
from adam.commands.audit.show_top10 import ShowTop10
|
|
9
|
+
from adam.commands.audit.utils_show_top10 import show_top10_completions_for_nesting
|
|
10
|
+
from adam.commands.command import Command
|
|
11
|
+
from adam.commands.intermediate_command import IntermediateCommand
|
|
12
|
+
from adam.repl_state import ReplState
|
|
13
|
+
from adam.sql.sql_completer import SqlCompleter, SqlVariant
|
|
14
|
+
from adam.utils import log2, wait_log
|
|
15
|
+
from adam.utils_athena import Athena
|
|
16
|
+
|
|
17
|
+
class Audit(IntermediateCommand):
|
|
18
|
+
COMMAND = 'audit'
|
|
19
|
+
|
|
20
|
+
# the singleton pattern
|
|
21
|
+
def __new__(cls, *args, **kwargs):
|
|
22
|
+
if not hasattr(cls, 'instance'): cls.instance = super(Audit, cls).__new__(cls)
|
|
23
|
+
|
|
24
|
+
return cls.instance
|
|
25
|
+
|
|
26
|
+
def __init__(self, successor: Command=None):
|
|
27
|
+
super().__init__(successor)
|
|
28
|
+
self.schema_read = False
|
|
29
|
+
|
|
30
|
+
def command(self):
|
|
31
|
+
return Audit.COMMAND
|
|
32
|
+
|
|
33
|
+
def required(self):
|
|
34
|
+
return ReplState.L
|
|
35
|
+
|
|
36
|
+
def run(self, cmd: str, state: ReplState):
|
|
37
|
+
if not(args := self.args(cmd)):
|
|
38
|
+
return super().run(cmd, state)
|
|
39
|
+
|
|
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)
|
|
44
|
+
|
|
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)
|
|
49
|
+
|
|
50
|
+
return state
|
|
51
|
+
|
|
52
|
+
def completion(self, state: ReplState):
|
|
53
|
+
if state.device == ReplState.L:
|
|
54
|
+
if not self.schema_read:
|
|
55
|
+
wait_log(f'Inspecting audit database schema...')
|
|
56
|
+
self.schema_read = True
|
|
57
|
+
# warm up the caches first time when l: drive is accessed
|
|
58
|
+
Athena.table_names()
|
|
59
|
+
Athena.column_names()
|
|
60
|
+
Athena.column_names(partition_cols_only=True)
|
|
61
|
+
|
|
62
|
+
return super().completion(state) | show_top10_completions_for_nesting() | SqlCompleter(
|
|
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
|
|
69
|
+
).completions_for_nesting()
|
|
70
|
+
|
|
71
|
+
return {}
|
|
72
|
+
|
|
73
|
+
def cmd_list(self):
|
|
74
|
+
return [AuditRepairTables(), AuditRun(), ShowLast10(), ShowSlow10(), ShowTop10()]
|
|
75
|
+
|
|
76
|
+
def help(self, _: ReplState):
|
|
77
|
+
return f'[{Audit.COMMAND}] [<sql-statements>]\t run SQL queries on Authena audit database'
|
|
78
|
+
|
|
79
|
+
class AuditCommandHelper(click.Command):
|
|
80
|
+
def get_help(self, ctx: click.Context):
|
|
81
|
+
IntermediateCommand.intermediate_help(super().get_help(ctx), Audit.COMMAND, Audit().cmd_list(), show_cluster_help=False)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
from adam.commands import validate_args
|
|
4
|
+
from adam.commands.command import Command
|
|
5
|
+
from adam.config import Config
|
|
6
|
+
from adam.repl_state import ReplState
|
|
7
|
+
from adam.utils import log, log2
|
|
8
|
+
from adam.utils_athena import Athena
|
|
9
|
+
from adam.utils_audits import AuditMeta, Audits
|
|
10
|
+
|
|
11
|
+
class AuditRepairTables(Command):
|
|
12
|
+
COMMAND = 'audit repair'
|
|
13
|
+
|
|
14
|
+
# the singleton pattern
|
|
15
|
+
def __new__(cls, *args, **kwargs):
|
|
16
|
+
if not hasattr(cls, 'instance'): cls.instance = super(AuditRepairTables, cls).__new__(cls)
|
|
17
|
+
|
|
18
|
+
return cls.instance
|
|
19
|
+
|
|
20
|
+
def __init__(self, successor: Command=None):
|
|
21
|
+
super().__init__(successor)
|
|
22
|
+
self.auto_repaired = False
|
|
23
|
+
|
|
24
|
+
def command(self):
|
|
25
|
+
return AuditRepairTables.COMMAND
|
|
26
|
+
|
|
27
|
+
def required(self):
|
|
28
|
+
return ReplState.L
|
|
29
|
+
|
|
30
|
+
def run(self, cmd: str, state: ReplState):
|
|
31
|
+
if not(args := self.args(cmd)):
|
|
32
|
+
return super().run(cmd, state)
|
|
33
|
+
|
|
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)
|
|
38
|
+
|
|
39
|
+
return state
|
|
40
|
+
|
|
41
|
+
def completion(self, state: ReplState):
|
|
42
|
+
# trigger auto repair if on l: drive
|
|
43
|
+
if state.device == ReplState.L:
|
|
44
|
+
if not self.auto_repaired:
|
|
45
|
+
if hours := Config().get('audit.athena.auto-repair.elapsed_hours', 12):
|
|
46
|
+
with Audits.offload() as exec:
|
|
47
|
+
exec.submit(lambda: self.auto_repair(hours))
|
|
48
|
+
|
|
49
|
+
return super().completion(state)
|
|
50
|
+
|
|
51
|
+
return {}
|
|
52
|
+
|
|
53
|
+
def auto_repair(self, hours: int):
|
|
54
|
+
self.auto_repaired = True
|
|
55
|
+
|
|
56
|
+
meta: AuditMeta = Audits.get_meta()
|
|
57
|
+
if meta.partitions_last_checked + hours * 60 * 60 < time.time():
|
|
58
|
+
tables = Config().get('audit.athena.repair-partition-tables', 'audit').split(',')
|
|
59
|
+
self.repair(tables, meta, show_sql=True)
|
|
60
|
+
log2(f'Audit tables have been auto-repaired.')
|
|
61
|
+
|
|
62
|
+
def repair(self, tables: list[str], meta: AuditMeta, show_sql = False):
|
|
63
|
+
with Audits.offload() as exec:
|
|
64
|
+
for table in tables:
|
|
65
|
+
if show_sql:
|
|
66
|
+
log(f'MSCK REPAIR TABLE {table}')
|
|
67
|
+
|
|
68
|
+
exec.submit(Athena.query, f'MSCK REPAIR TABLE {table}', None,)
|
|
69
|
+
exec.submit(Audits.put_meta, Audits.PARTITIONS_ADDED, meta,)
|
|
70
|
+
|
|
71
|
+
def help(self, _: ReplState):
|
|
72
|
+
return f"{AuditRepairTables.COMMAND}\t run MSCK REPAIR command for new partition discovery"
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.config import Config
|
|
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 AuditMeta, Audits
|
|
7
|
+
|
|
8
|
+
class AuditRun(Command):
|
|
9
|
+
COMMAND = 'audit run'
|
|
10
|
+
|
|
11
|
+
# the singleton pattern
|
|
12
|
+
def __new__(cls, *args, **kwargs):
|
|
13
|
+
if not hasattr(cls, 'instance'): cls.instance = super(AuditRun, cls).__new__(cls)
|
|
14
|
+
|
|
15
|
+
return cls.instance
|
|
16
|
+
|
|
17
|
+
def __init__(self, successor: Command=None):
|
|
18
|
+
super().__init__(successor)
|
|
19
|
+
self.auto_repaired = False
|
|
20
|
+
|
|
21
|
+
def command(self):
|
|
22
|
+
return AuditRun.COMMAND
|
|
23
|
+
|
|
24
|
+
def required(self):
|
|
25
|
+
return ReplState.L
|
|
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
|
+
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.')
|
|
43
|
+
|
|
44
|
+
return state
|
|
45
|
+
|
|
46
|
+
def completion(self, state: ReplState):
|
|
47
|
+
return super().completion(state)
|
|
48
|
+
|
|
49
|
+
def help(self, _: ReplState):
|
|
50
|
+
return f"{AuditRun.COMMAND}\t run"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from adam.commands.audit.utils_show_top10 import run_configured_query
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.repl_state import ReplState
|
|
4
|
+
|
|
5
|
+
class ShowLast10(Command):
|
|
6
|
+
COMMAND = 'show last'
|
|
7
|
+
|
|
8
|
+
# the singleton pattern
|
|
9
|
+
def __new__(cls, *args, **kwargs):
|
|
10
|
+
if not hasattr(cls, 'instance'): cls.instance = super(ShowLast10, 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 ShowLast10.COMMAND
|
|
19
|
+
|
|
20
|
+
def required(self):
|
|
21
|
+
return ReplState.L
|
|
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
|
+
run_configured_query('audit.queries.last10', args)
|
|
29
|
+
|
|
30
|
+
return state
|
|
31
|
+
|
|
32
|
+
def completion(self, _: ReplState):
|
|
33
|
+
|
|
34
|
+
return {}
|
|
35
|
+
|
|
36
|
+
def help(self, _: ReplState):
|
|
37
|
+
return f'{ShowLast10.COMMAND} [limit]\t show last <limit> audit lines'
|