kaqing 2.0.110__py3-none-any.whl → 2.0.214__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 +19 -19
- 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/app/app.py +38 -0
- adam/commands/{app_ping.py → app/app_ping.py} +7 -13
- adam/commands/{login.py → app/login.py} +22 -24
- 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/show_login.py +56 -0
- adam/commands/app/utils_app.py +106 -0
- adam/commands/audit/audit.py +22 -40
- adam/commands/audit/audit_repair_tables.py +15 -19
- adam/commands/audit/audit_run.py +15 -22
- adam/commands/audit/completions_l.py +15 -0
- adam/commands/audit/show_last10.py +4 -18
- 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/cassandra/__init__.py +0 -0
- adam/commands/cassandra/download_cassandra_log.py +45 -0
- adam/commands/{restart.py → cassandra/restart_cluster.py} +12 -26
- adam/commands/cassandra/restart_node.py +51 -0
- adam/commands/cassandra/restart_nodes.py +47 -0
- adam/commands/{rollout.py → cassandra/rollout.py} +20 -25
- adam/commands/cassandra/show_cassandra_repairs.py +37 -0
- adam/commands/cassandra/show_cassandra_status.py +117 -0
- adam/commands/{show → cassandra}/show_cassandra_version.py +5 -18
- adam/commands/cassandra/show_processes.py +50 -0
- adam/commands/cassandra/show_storage.py +44 -0
- adam/commands/{watch.py → cassandra/watch.py} +26 -29
- adam/commands/cli/__init__.py +0 -0
- adam/commands/{cli_commands.py → cli/cli_commands.py} +8 -4
- adam/commands/cli/clipboard_copy.py +86 -0
- adam/commands/cli/show_cli_commands.py +56 -0
- adam/commands/code.py +57 -0
- adam/commands/command.py +211 -40
- adam/commands/commands_utils.py +20 -27
- adam/commands/config/__init__.py +0 -0
- adam/commands/{param_get.py → config/param_get.py} +11 -14
- adam/commands/{param_set.py → config/param_set.py} +8 -12
- adam/commands/{show → config}/show_params.py +2 -5
- adam/commands/cql/alter_tables.py +66 -0
- adam/commands/cql/completions_c.py +29 -0
- adam/commands/cql/cqlsh.py +10 -32
- adam/commands/cql/utils_cql.py +306 -0
- adam/commands/debug/__init__.py +0 -0
- adam/commands/debug/debug.py +22 -0
- adam/commands/debug/debug_completes.py +35 -0
- adam/commands/debug/debug_timings.py +35 -0
- adam/commands/debug/show_offloaded_completes.py +45 -0
- adam/commands/deploy/code_start.py +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 +149 -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 +87 -0
- adam/commands/devices/device_postgres.py +160 -0
- adam/commands/devices/devices.py +25 -0
- adam/commands/diag/__init__.py +0 -0
- adam/commands/{check.py → diag/check.py} +16 -25
- adam/commands/diag/generate_report.py +52 -0
- adam/commands/diag/issues.py +43 -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/completions_x.py +11 -0
- adam/commands/export/download_export_session.py +40 -0
- adam/commands/export/drop_export_database.py +39 -0
- adam/commands/export/drop_export_databases.py +37 -0
- adam/commands/export/export.py +37 -0
- adam/commands/export/export_databases.py +251 -0
- adam/commands/export/export_select.py +34 -0
- adam/commands/export/export_sessions.py +210 -0
- adam/commands/export/export_use.py +49 -0
- adam/commands/export/export_x_select.py +48 -0
- adam/commands/export/exporter.py +419 -0
- adam/commands/export/import_files.py +44 -0
- adam/commands/export/import_session.py +40 -0
- adam/commands/export/importer.py +81 -0
- adam/commands/export/importer_athena.py +157 -0
- adam/commands/export/importer_sqlite.py +78 -0
- adam/commands/export/show_column_counts.py +45 -0
- adam/commands/export/show_export_databases.py +39 -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 +366 -0
- adam/commands/fs/__init__.py +0 -0
- adam/commands/fs/cat.py +36 -0
- adam/commands/fs/cat_local.py +42 -0
- adam/commands/fs/cd.py +41 -0
- adam/commands/fs/download_file.py +47 -0
- adam/commands/fs/find_files.py +51 -0
- adam/commands/fs/find_processes.py +76 -0
- adam/commands/fs/head.py +36 -0
- adam/commands/fs/ls.py +41 -0
- adam/commands/fs/ls_local.py +40 -0
- adam/commands/fs/pwd.py +45 -0
- adam/commands/fs/rm.py +18 -0
- adam/commands/fs/rm_downloads.py +39 -0
- adam/commands/fs/rm_logs.py +38 -0
- adam/commands/{shell.py → fs/shell.py} +12 -4
- adam/commands/{show → fs}/show_adam.py +3 -3
- adam/commands/{show → fs}/show_host.py +1 -1
- adam/commands/help.py +5 -3
- adam/commands/intermediate_command.py +52 -0
- adam/commands/kubectl.py +38 -0
- adam/commands/medusa/medusa.py +4 -22
- adam/commands/medusa/medusa_backup.py +20 -27
- adam/commands/medusa/medusa_restore.py +35 -48
- adam/commands/medusa/medusa_show_backupjobs.py +16 -18
- adam/commands/medusa/medusa_show_restorejobs.py +13 -18
- adam/commands/medusa/utils_medusa.py +15 -0
- adam/commands/nodetool/__init__.py +0 -0
- adam/commands/{nodetool.py → nodetool/nodetool.py} +9 -20
- adam/commands/postgres/completions_p.py +22 -0
- adam/commands/postgres/postgres.py +47 -55
- adam/commands/postgres/postgres_databases.py +269 -0
- adam/commands/postgres/postgres_ls.py +5 -9
- adam/commands/postgres/postgres_preview.py +5 -9
- adam/commands/postgres/utils_postgres.py +80 -0
- adam/commands/preview_table.py +8 -44
- 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 +14 -33
- adam/commands/reaper/reaper_schedule_start.py +9 -33
- adam/commands/reaper/reaper_schedule_stop.py +9 -33
- adam/commands/reaper/reaper_schedules.py +4 -14
- adam/commands/reaper/reaper_status.py +8 -16
- adam/commands/reaper/utils_reaper.py +203 -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 -40
- adam/commands/repair/repair_stop.py +5 -12
- adam/commands/show.py +40 -0
- adam/config.py +5 -15
- adam/embedded_params.py +1 -1
- adam/log.py +4 -4
- adam/repl.py +83 -116
- adam/repl_commands.py +86 -45
- adam/repl_session.py +9 -1
- adam/repl_state.py +176 -40
- adam/sql/async_executor.py +62 -0
- adam/sql/lark_completer.py +286 -0
- adam/sql/lark_parser.py +604 -0
- adam/sql/qingl.lark +1076 -0
- 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 +4 -9
- adam/sso/idp.py +9 -12
- adam/utils.py +670 -31
- adam/utils_athena.py +145 -0
- adam/utils_audits.py +12 -103
- adam/utils_issues.py +32 -0
- adam/utils_k8s/app_clusters.py +35 -0
- adam/utils_k8s/app_pods.py +41 -0
- adam/utils_k8s/cassandra_clusters.py +35 -20
- adam/utils_k8s/cassandra_nodes.py +15 -6
- 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 +96 -0
- adam/utils_k8s/kube_context.py +3 -6
- adam/{pod_exec_result.py → utils_k8s/pod_exec_result.py} +13 -4
- adam/utils_k8s/pods.py +159 -89
- 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 +6 -14
- adam/utils_local.py +80 -0
- adam/utils_net.py +4 -4
- adam/utils_repl/__init__.py +0 -0
- adam/utils_repl/appendable_completer.py +6 -0
- adam/utils_repl/automata_completer.py +48 -0
- adam/utils_repl/repl_completer.py +93 -0
- adam/utils_repl/state_machine.py +173 -0
- adam/utils_sqlite.py +132 -0
- adam/version.py +1 -1
- {kaqing-2.0.110.dist-info → kaqing-2.0.214.dist-info}/METADATA +1 -1
- kaqing-2.0.214.dist-info/RECORD +272 -0
- kaqing-2.0.214.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/alter_tables.py +0 -81
- adam/commands/app.py +0 -67
- adam/commands/bash.py +0 -150
- adam/commands/cd.py +0 -125
- adam/commands/cp.py +0 -95
- adam/commands/cql/cql_completions.py +0 -15
- adam/commands/cql/cql_utils.py +0 -112
- adam/commands/devices.py +0 -118
- adam/commands/issues.py +0 -75
- adam/commands/logs.py +0 -40
- adam/commands/ls.py +0 -146
- adam/commands/postgres/postgres_context.py +0 -239
- adam/commands/postgres/postgres_utils.py +0 -31
- adam/commands/postgres/psql_completions.py +0 -10
- adam/commands/pwd.py +0 -77
- adam/commands/reaper/reaper_session.py +0 -159
- adam/commands/report.py +0 -63
- adam/commands/show/show.py +0 -54
- adam/commands/show/show_app_actions.py +0 -56
- adam/commands/show/show_cassandra_status.py +0 -128
- adam/commands/show/show_commands.py +0 -61
- adam/commands/show/show_login.py +0 -63
- adam/commands/show/show_processes.py +0 -53
- adam/commands/show/show_repairs.py +0 -47
- adam/commands/show/show_storage.py +0 -52
- kaqing-2.0.110.dist-info/RECORD +0 -187
- kaqing-2.0.110.dist-info/top_level.txt +0 -1
- /adam/commands/{show → app}/__init__.py +0 -0
- /adam/commands/{nodetool_commands.py → nodetool/nodetool_commands.py} +0 -0
- {kaqing-2.0.110.dist-info → kaqing-2.0.214.dist-info}/WHEEL +0 -0
- {kaqing-2.0.110.dist-info → kaqing-2.0.214.dist-info}/entry_points.txt +0 -0
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import signal
|
|
3
|
-
import traceback
|
|
4
3
|
|
|
5
4
|
from adam.app_session import AppSession
|
|
6
5
|
from adam.apps import Apps
|
|
6
|
+
from adam.commands import extract_options
|
|
7
7
|
from adam.config import Config
|
|
8
8
|
from adam.sso.idp import Idp
|
|
9
9
|
from adam.sso.idp_login import IdpLogin
|
|
10
10
|
from adam.commands.command import Command
|
|
11
|
-
from adam.repl_state import ReplState
|
|
12
|
-
from adam.utils import log, log2
|
|
11
|
+
from adam.repl_state import ReplState
|
|
12
|
+
from adam.utils import log, log2, log_exc
|
|
13
13
|
|
|
14
14
|
class Login(Command):
|
|
15
15
|
COMMAND = 'login'
|
|
@@ -30,37 +30,35 @@ class Login(Command):
|
|
|
30
30
|
return ReplState.NON_L
|
|
31
31
|
|
|
32
32
|
def run(self, cmd: str, state: ReplState):
|
|
33
|
+
if not(args := self.args(cmd)):
|
|
34
|
+
return super().run(cmd, state)
|
|
35
|
+
|
|
33
36
|
def custom_handler(signum, frame):
|
|
34
37
|
AppSession.ctrl_c_entered = True
|
|
35
38
|
|
|
36
39
|
signal.signal(signal.SIGINT, custom_handler)
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
args, debug = Command.extract_options(args, ['d'])
|
|
43
|
-
if debug:
|
|
44
|
-
Config().set('debug', True)
|
|
41
|
+
with self.validate(args, state) as (args, state):
|
|
42
|
+
with extract_options(args, 'd') as (args, debug):
|
|
43
|
+
if debug:
|
|
44
|
+
Config().set('debug', True)
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
username: str = os.getenv('USERNAME')
|
|
47
|
+
if len(args) > 0:
|
|
48
|
+
username = args[0]
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
login: IdpLogin = None
|
|
51
|
+
with log_exc(True):
|
|
52
|
+
if not(host := Apps.app_host('c3', 'c3', state.namespace)):
|
|
53
|
+
log2('Cannot locate ingress for app.')
|
|
54
|
+
return state
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
except:
|
|
59
|
-
log2(traceback.format_exc())
|
|
56
|
+
if not (login := Idp.login(host, username=username, use_token_from_env=False)):
|
|
57
|
+
log2('Invalid username/password. Please try again.')
|
|
60
58
|
|
|
61
|
-
|
|
59
|
+
log(f'IDP_TOKEN={login.ser() if login else ""}')
|
|
62
60
|
|
|
63
|
-
|
|
61
|
+
return state
|
|
64
62
|
|
|
65
63
|
def completion(self, state: ReplState):
|
|
66
64
|
return super().completion(state)
|
|
@@ -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"
|
|
@@ -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,56 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
from adam.apps import Apps
|
|
4
|
+
from adam.sso.idp import Idp
|
|
5
|
+
from adam.sso.idp_login import IdpLogin
|
|
6
|
+
from adam.commands.command import Command
|
|
7
|
+
from adam.repl_state import ReplState
|
|
8
|
+
from adam.utils import duration, tabulize, log2, log_exc
|
|
9
|
+
|
|
10
|
+
class ShowLogin(Command):
|
|
11
|
+
COMMAND = 'show login'
|
|
12
|
+
|
|
13
|
+
# the singleton pattern
|
|
14
|
+
def __new__(cls, *args, **kwargs):
|
|
15
|
+
if not hasattr(cls, 'instance'): cls.instance = super(ShowLogin, cls).__new__(cls)
|
|
16
|
+
|
|
17
|
+
return cls.instance
|
|
18
|
+
|
|
19
|
+
def __init__(self, successor: Command=None):
|
|
20
|
+
super().__init__(successor)
|
|
21
|
+
|
|
22
|
+
def command(self):
|
|
23
|
+
return ShowLogin.COMMAND
|
|
24
|
+
|
|
25
|
+
def required(self):
|
|
26
|
+
return ReplState.NON_L
|
|
27
|
+
|
|
28
|
+
def run(self, cmd: str, state: ReplState):
|
|
29
|
+
if not(args := self.args(cmd)):
|
|
30
|
+
return super().run(cmd, state)
|
|
31
|
+
|
|
32
|
+
with self.validate(args, state) as (args, state):
|
|
33
|
+
login: IdpLogin = None
|
|
34
|
+
with log_exc(True):
|
|
35
|
+
if not(host := Apps.app_host('c3', 'c3', state.namespace)):
|
|
36
|
+
log2('Cannot locate ingress for app.')
|
|
37
|
+
return state
|
|
38
|
+
|
|
39
|
+
login = Idp.login(host, use_token_from_env=True)
|
|
40
|
+
if login and login.id_token_obj:
|
|
41
|
+
it = login.id_token_obj
|
|
42
|
+
lines = [
|
|
43
|
+
f'email\t{it.email}',
|
|
44
|
+
f'user\t{it.username}',
|
|
45
|
+
f'IDP expires in\t{duration(time.time(), it.exp)}',
|
|
46
|
+
f'IDP Groups\t{",".join(it.groups)}'
|
|
47
|
+
]
|
|
48
|
+
tabulize(lines, separator='\t')
|
|
49
|
+
|
|
50
|
+
return state
|
|
51
|
+
|
|
52
|
+
def completion(self, state: ReplState):
|
|
53
|
+
return super().completion(state)
|
|
54
|
+
|
|
55
|
+
def help(self, _: ReplState):
|
|
56
|
+
return f'{ShowLogin.COMMAND}\t show login details'
|
|
@@ -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.utils_k8s.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
|
|
@@ -7,13 +9,13 @@ from adam.commands.audit.show_slow10 import ShowSlow10
|
|
|
7
9
|
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
|
-
from adam.
|
|
12
|
+
from adam.commands.intermediate_command import IntermediateCommand
|
|
11
13
|
from adam.repl_state import ReplState
|
|
12
|
-
from adam.sql.
|
|
13
|
-
from adam.utils import log2
|
|
14
|
-
from adam.
|
|
14
|
+
from adam.sql.lark_completer import LarkCompleter
|
|
15
|
+
from adam.utils import log2, wait_log
|
|
16
|
+
from adam.utils_athena import Athena
|
|
15
17
|
|
|
16
|
-
class Audit(
|
|
18
|
+
class Audit(IntermediateCommand):
|
|
17
19
|
COMMAND = 'audit'
|
|
18
20
|
|
|
19
21
|
# the singleton pattern
|
|
@@ -36,45 +38,25 @@ class Audit(Command):
|
|
|
36
38
|
if not(args := self.args(cmd)):
|
|
37
39
|
return super().run(cmd, state)
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
with self.validate(args, state) as (args, state):
|
|
42
|
+
r = None
|
|
43
|
+
if len(args) > 0:
|
|
44
|
+
r = self.intermediate_run(cmd, state, args, self.cmd_list(), display_help=False)
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
if not r or isinstance(r, str) and r == 'command-missing':
|
|
47
|
+
with validate_args(args, state, default='select * from audit order by ts desc limit 10') as sql:
|
|
48
|
+
log2(sql)
|
|
49
|
+
Athena.run_query(sql)
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
sql = 'select * from audit order by ts desc limit 10'
|
|
49
|
-
if args:
|
|
50
|
-
sql = ' '.join(args)
|
|
51
|
-
else:
|
|
52
|
-
log2(sql)
|
|
51
|
+
return state
|
|
53
52
|
|
|
54
|
-
|
|
53
|
+
def completion(self, state: ReplState):
|
|
54
|
+
if state.device != ReplState.L:
|
|
55
|
+
return {}
|
|
55
56
|
|
|
56
|
-
return
|
|
57
|
+
return completions_l()
|
|
57
58
|
|
|
58
|
-
def
|
|
59
|
-
if state.device == ReplState.L:
|
|
60
|
-
if not self.schema_read:
|
|
61
|
-
Config().wait_log(f'Inspecting audit database schema...')
|
|
62
|
-
self.schema_read = True
|
|
63
|
-
# warm up the caches first time when l: drive is accessed
|
|
64
|
-
Audits.audit_table_names()
|
|
65
|
-
Audits.audit_column_names()
|
|
66
|
-
Audits.audit_column_names(partition_cols_only=True)
|
|
67
|
-
|
|
68
|
-
return super().completion(state) | show_top10_completions_for_nesting() | SqlCompleter(
|
|
69
|
-
lambda: Audits.audit_table_names(),
|
|
70
|
-
columns=lambda table: Audits.audit_column_names(),
|
|
71
|
-
partition_columns=lambda table: Audits.audit_column_names(partition_cols_only=True),
|
|
72
|
-
variant='athena'
|
|
73
|
-
).completions_for_nesting()
|
|
74
|
-
|
|
75
|
-
return {}
|
|
76
|
-
|
|
77
|
-
def cmd_list():
|
|
59
|
+
def cmd_list(self):
|
|
78
60
|
return [AuditRepairTables(), AuditRun(), ShowLast10(), ShowSlow10(), ShowTop10()]
|
|
79
61
|
|
|
80
62
|
def help(self, _: ReplState):
|
|
@@ -82,4 +64,4 @@ class Audit(Command):
|
|
|
82
64
|
|
|
83
65
|
class AuditCommandHelper(click.Command):
|
|
84
66
|
def get_help(self, ctx: click.Context):
|
|
85
|
-
|
|
67
|
+
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,27 +31,22 @@ 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
|
-
return super().completion(state)
|
|
49
|
+
# return super().completion(state)
|
|
54
50
|
|
|
55
51
|
return {}
|
|
56
52
|
|
|
@@ -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
|
-
if state.device == ReplState.L:
|
|
52
|
-
return super().completion(state)
|
|
53
|
-
|
|
54
47
|
return {}
|
|
55
48
|
|
|
56
49
|
def help(self, _: ReplState):
|
|
57
|
-
return f"{AuditRun.COMMAND}
|
|
50
|
+
return f"{AuditRun.COMMAND}\t run"
|
|
@@ -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,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,24 +24,12 @@ 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)
|
|
34
|
-
|
|
35
|
-
query = '\n '.join([
|
|
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)
|
|
27
|
+
with self.validate(args, state) as (args, state):
|
|
28
|
+
run_configured_query('audit.queries.last10', args)
|
|
42
29
|
|
|
43
|
-
|
|
30
|
+
return state
|
|
44
31
|
|
|
45
32
|
def completion(self, _: ReplState):
|
|
46
|
-
|
|
47
33
|
return {}
|
|
48
34
|
|
|
49
35
|
def help(self, _: ReplState):
|
|
@@ -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 {}
|