kaqing 2.0.171__py3-none-any.whl → 2.0.203__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.
- adam/app_session.py +5 -10
- adam/apps.py +18 -4
- adam/batch.py +7 -7
- adam/checks/check_utils.py +3 -1
- adam/checks/disk.py +2 -3
- adam/columns/memory.py +3 -4
- adam/commands/__init__.py +15 -6
- adam/commands/alter_tables.py +26 -41
- adam/commands/app/__init__.py +0 -0
- adam/commands/{app_cmd.py → app/app.py} +2 -2
- adam/commands/{show → app}/show_app_actions.py +7 -15
- adam/commands/{show → app}/show_app_queues.py +1 -4
- adam/{utils_app.py → commands/app/utils_app.py} +9 -1
- adam/commands/audit/audit.py +9 -26
- 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 +15 -3
- adam/commands/bash/bash.py +1 -1
- adam/commands/bash/utils_bash.py +1 -1
- adam/commands/cassandra/__init__.py +0 -0
- adam/commands/cassandra/download_cassandra_log.py +45 -0
- adam/commands/cassandra/nodetool.py +64 -0
- adam/commands/cassandra/nodetool_commands.py +120 -0
- adam/commands/cassandra/restart_cluster.py +47 -0
- adam/commands/cassandra/restart_node.py +51 -0
- adam/commands/cassandra/restart_nodes.py +47 -0
- adam/commands/cassandra/rollout.py +88 -0
- adam/commands/cat.py +5 -19
- adam/commands/cd.py +7 -9
- adam/commands/check.py +10 -18
- adam/commands/cli_commands.py +6 -1
- adam/commands/{cp.py → clipboard_copy.py} +34 -36
- adam/commands/code.py +2 -2
- adam/commands/command.py +139 -22
- adam/commands/commands_utils.py +14 -12
- adam/commands/cql/alter_tables.py +66 -0
- adam/commands/cql/completions_c.py +29 -0
- adam/commands/cql/cqlsh.py +3 -7
- adam/commands/cql/utils_cql.py +23 -61
- 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/deploy/deploy_pg_agent.py +2 -2
- adam/commands/deploy/deploy_pod.py +2 -4
- adam/commands/deploy/undeploy_pg_agent.py +2 -2
- adam/commands/devices/device.py +40 -9
- adam/commands/devices/device_app.py +19 -29
- adam/commands/devices/device_auit_log.py +3 -3
- adam/commands/devices/device_cass.py +17 -23
- adam/commands/devices/device_export.py +12 -11
- adam/commands/devices/device_postgres.py +79 -63
- adam/commands/devices/devices.py +1 -1
- adam/commands/download_cassandra_log.py +45 -0
- 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 +7 -19
- adam/commands/export/completions_x.py +11 -0
- adam/commands/export/download_export_session.py +40 -0
- adam/commands/export/drop_export_database.py +6 -22
- adam/commands/export/drop_export_databases.py +3 -9
- adam/commands/export/export.py +1 -17
- adam/commands/export/export_databases.py +109 -32
- adam/commands/export/export_select.py +8 -55
- adam/commands/export/export_sessions.py +211 -0
- adam/commands/export/export_use.py +13 -16
- adam/commands/export/export_x_select.py +48 -0
- adam/commands/export/exporter.py +176 -167
- adam/commands/export/import_files.py +44 -0
- adam/commands/export/import_session.py +10 -6
- adam/commands/export/importer.py +24 -9
- adam/commands/export/importer_athena.py +114 -44
- adam/commands/export/importer_sqlite.py +45 -23
- adam/commands/export/show_column_counts.py +11 -20
- adam/commands/export/show_export_databases.py +5 -2
- adam/commands/export/show_export_session.py +6 -15
- adam/commands/export/show_export_sessions.py +4 -11
- adam/commands/export/utils_export.py +79 -27
- adam/commands/find_files.py +51 -0
- adam/commands/find_processes.py +76 -0
- adam/commands/generate_report.py +52 -0
- adam/commands/head.py +36 -0
- adam/commands/help.py +2 -2
- adam/commands/intermediate_command.py +6 -3
- adam/commands/login.py +3 -6
- adam/commands/ls.py +2 -2
- adam/commands/medusa/medusa_backup.py +13 -16
- adam/commands/medusa/medusa_restore.py +26 -37
- adam/commands/medusa/medusa_show_backupjobs.py +7 -7
- adam/commands/medusa/medusa_show_restorejobs.py +6 -6
- adam/commands/medusa/utils_medusa.py +15 -0
- adam/commands/nodetool.py +3 -8
- adam/commands/os/__init__.py +0 -0
- adam/commands/os/cat.py +36 -0
- adam/commands/os/download_file.py +47 -0
- adam/commands/os/find_files.py +51 -0
- adam/commands/os/find_processes.py +76 -0
- adam/commands/os/head.py +36 -0
- adam/commands/os/shell.py +41 -0
- adam/commands/param_get.py +10 -12
- adam/commands/param_set.py +7 -10
- adam/commands/postgres/completions_p.py +22 -0
- adam/commands/postgres/postgres.py +25 -40
- adam/commands/postgres/postgres_databases.py +269 -0
- adam/commands/postgres/utils_postgres.py +33 -20
- adam/commands/preview_table.py +4 -2
- adam/commands/pwd.py +4 -6
- adam/commands/reaper/reaper_forward.py +2 -2
- adam/commands/reaper/reaper_run_abort.py +4 -10
- adam/commands/reaper/reaper_runs.py +3 -3
- adam/commands/reaper/reaper_schedule_activate.py +12 -12
- adam/commands/reaper/reaper_schedule_start.py +7 -12
- adam/commands/reaper/reaper_schedule_stop.py +7 -12
- adam/commands/reaper/utils_reaper.py +13 -6
- adam/commands/repair/repair_log.py +1 -4
- adam/commands/repair/repair_run.py +3 -8
- adam/commands/repair/repair_scan.py +1 -6
- adam/commands/repair/repair_stop.py +1 -5
- adam/commands/restart_cluster.py +47 -0
- adam/commands/restart_node.py +51 -0
- adam/commands/restart_nodes.py +47 -0
- adam/commands/shell.py +9 -2
- adam/commands/show/show.py +4 -4
- adam/commands/show/show_adam.py +3 -3
- adam/commands/show/show_cassandra_repairs.py +5 -6
- adam/commands/show/show_cassandra_status.py +29 -29
- adam/commands/show/show_cassandra_version.py +1 -4
- adam/commands/show/{show_commands.py → show_cli_commands.py} +3 -6
- adam/commands/show/show_login.py +3 -9
- adam/commands/show/show_params.py +2 -5
- adam/commands/show/show_processes.py +15 -16
- adam/commands/show/show_storage.py +9 -8
- adam/config.py +4 -5
- adam/embedded_params.py +1 -1
- adam/log.py +4 -4
- adam/repl.py +26 -18
- adam/repl_commands.py +32 -20
- adam/repl_session.py +9 -1
- adam/repl_state.py +39 -10
- adam/sql/async_executor.py +44 -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 +4 -6
- adam/sql/sql_state_machine.py +25 -13
- adam/sso/authn_ad.py +2 -5
- adam/sso/authn_okta.py +2 -4
- adam/sso/cred_cache.py +2 -5
- adam/sso/idp.py +8 -11
- adam/utils.py +299 -105
- adam/utils_athena.py +18 -18
- adam/utils_audits.py +3 -7
- adam/utils_issues.py +2 -2
- adam/utils_k8s/app_clusters.py +4 -4
- adam/utils_k8s/app_pods.py +8 -6
- adam/utils_k8s/cassandra_clusters.py +16 -5
- adam/utils_k8s/cassandra_nodes.py +9 -6
- adam/utils_k8s/custom_resources.py +11 -17
- adam/utils_k8s/jobs.py +7 -11
- adam/utils_k8s/k8s.py +14 -5
- adam/utils_k8s/kube_context.py +3 -6
- adam/{pod_exec_result.py → utils_k8s/pod_exec_result.py} +4 -4
- adam/utils_k8s/pods.py +85 -23
- adam/utils_k8s/statefulsets.py +5 -2
- adam/utils_local.py +42 -0
- adam/utils_repl/appendable_completer.py +6 -0
- adam/utils_repl/repl_completer.py +45 -2
- adam/utils_repl/state_machine.py +3 -3
- adam/utils_sqlite.py +58 -30
- adam/version.py +1 -1
- {kaqing-2.0.171.dist-info → kaqing-2.0.203.dist-info}/METADATA +1 -1
- kaqing-2.0.203.dist-info/RECORD +277 -0
- kaqing-2.0.203.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 -33
- adam/commands/export/export_handlers.py +0 -71
- adam/commands/export/export_select_x.py +0 -54
- adam/commands/logs.py +0 -37
- adam/commands/postgres/postgres_context.py +0 -274
- adam/commands/postgres/psql_completions.py +0 -10
- adam/commands/report.py +0 -61
- adam/commands/restart.py +0 -60
- kaqing-2.0.171.dist-info/RECORD +0 -236
- kaqing-2.0.171.dist-info/top_level.txt +0 -1
- /adam/commands/{app_ping.py → app/app_ping.py} +0 -0
- /adam/commands/{show → app}/show_app_id.py +0 -0
- {kaqing-2.0.171.dist-info → kaqing-2.0.203.dist-info}/WHEEL +0 -0
- {kaqing-2.0.171.dist-info → kaqing-2.0.203.dist-info}/entry_points.txt +0 -0
adam/app_session.py
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import threading
|
|
3
3
|
import time
|
|
4
|
-
import traceback
|
|
5
4
|
import requests
|
|
6
5
|
from urllib.parse import urlparse
|
|
7
6
|
|
|
8
7
|
from adam.log import Log
|
|
9
|
-
from adam.repl_state import ReplState
|
|
10
8
|
from adam.sso.idp import Idp
|
|
11
9
|
from adam.sso.idp_login import IdpLogin
|
|
12
10
|
from adam.config import Config
|
|
13
|
-
from adam.utils import debug, json_to_csv,
|
|
11
|
+
from adam.utils import debug, debug_trace, json_to_csv, tabulize, log2, log_exc
|
|
14
12
|
from adam.apps import Apps
|
|
15
13
|
|
|
16
14
|
class AppLogin:
|
|
@@ -63,12 +61,9 @@ class AppSession:
|
|
|
63
61
|
if r.status_code >= 200 and r.status_code < 300 or r.status_code == 400:
|
|
64
62
|
try:
|
|
65
63
|
js = r.json()
|
|
66
|
-
|
|
64
|
+
with log_exc(js):
|
|
67
65
|
header, lines = json_to_csv(js, delimiter='\t')
|
|
68
|
-
|
|
69
|
-
except Exception as e:
|
|
70
|
-
# traceback.print_exc(e)
|
|
71
|
-
log(js)
|
|
66
|
+
tabulize(lines, header=header, separator='\t')
|
|
72
67
|
except:
|
|
73
68
|
if urlparse(r.url).hostname != urlparse(uri).hostname and not retried:
|
|
74
69
|
app_login = app_session.login(idp_uri=app_login.idp_uri, forced=forced, use_token_from_env=False, use_cached_creds=False)
|
|
@@ -147,7 +142,7 @@ class AppSession:
|
|
|
147
142
|
debug(f'{r.text}')
|
|
148
143
|
|
|
149
144
|
self.app_login = AppLogin(session, app_access_token, idp_uri)
|
|
150
|
-
except Exception:
|
|
145
|
+
except Exception as e:
|
|
151
146
|
try:
|
|
152
147
|
need = urlparse(r.url).hostname
|
|
153
148
|
if idp_login.idp_uri:
|
|
@@ -160,7 +155,7 @@ class AppSession:
|
|
|
160
155
|
log2(f"Invalid username/password.")
|
|
161
156
|
break
|
|
162
157
|
finally:
|
|
163
|
-
|
|
158
|
+
debug_trace()
|
|
164
159
|
|
|
165
160
|
if 'res_text' in locals():
|
|
166
161
|
Log.log_to_file(res_text)
|
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
|
|
@@ -11,7 +11,7 @@ from adam.commands.deploy.deploy import Deploy, DeployCommandHelper
|
|
|
11
11
|
from adam.commands.deploy.undeploy import Undeploy, UndeployCommandHelper
|
|
12
12
|
from adam.commands.issues import Issues
|
|
13
13
|
from adam.commands.login import Login
|
|
14
|
-
from adam.commands.
|
|
14
|
+
from adam.commands.download_cassandra_log import DownloadCassandraLog
|
|
15
15
|
from adam.commands.ls import Ls
|
|
16
16
|
from adam.commands.medusa.medusa import Medusa
|
|
17
17
|
from adam.commands.nodetool import NodeTool, NodeToolCommandHelper
|
|
@@ -19,8 +19,8 @@ from adam.commands.postgres.postgres import Postgres, PostgresCommandHelper
|
|
|
19
19
|
from adam.commands.preview_table import PreviewTable
|
|
20
20
|
from adam.commands.reaper.reaper import Reaper, ReaperCommandHelper
|
|
21
21
|
from adam.commands.repair.repair import Repair, RepairCommandHelper
|
|
22
|
-
from adam.commands.
|
|
23
|
-
from adam.commands.
|
|
22
|
+
from adam.commands.generate_report import GenerateReport
|
|
23
|
+
from adam.commands.restart_nodes import RestartNodes
|
|
24
24
|
from adam.commands.rollout import RollOut
|
|
25
25
|
from adam.commands.show.show import Show, ShowCommandHelper
|
|
26
26
|
from adam.commands.watch import Watch
|
|
@@ -128,7 +128,7 @@ def login(kubeconfig: str, config: str, param: list[str], namespace: str, pod: s
|
|
|
128
128
|
@click.option('--pod', '-p', required=False, metavar='pod', help='Kubernetes pod name')
|
|
129
129
|
@click.argument('extra_args', nargs=-1, metavar='<pod>', type=click.UNPROCESSED)
|
|
130
130
|
def logs(kubeconfig: str, config: str, param: list[str], namespace: str, pod: str, extra_args):
|
|
131
|
-
run_command(
|
|
131
|
+
run_command(DownloadCassandraLog(), kubeconfig, config, param, None, namespace, pod, extra_args)
|
|
132
132
|
|
|
133
133
|
|
|
134
134
|
@cli.command(context_settings=dict(ignore_unknown_options=True, allow_extra_args=True), cls=ClusterCommandHelper, help='List statefulset or pods.')
|
|
@@ -221,7 +221,7 @@ def repair(kubeconfig: str, config: str, param: list[str], cluster: str, namespa
|
|
|
221
221
|
@click.option('--show', '-s', is_flag=True, help='show output from Cassandra nodes')
|
|
222
222
|
@click.argument('extra_args', nargs=-1, metavar='[cluster|pod]', type=click.UNPROCESSED)
|
|
223
223
|
def report(kubeconfig: str, config: str, param: list[str], cluster: str, namespace: str, pod: str, show: bool, extra_args):
|
|
224
|
-
run_command(
|
|
224
|
+
run_command(GenerateReport(), kubeconfig, config, param, cluster, namespace, pod, ('-s',) + extra_args if show else extra_args)
|
|
225
225
|
|
|
226
226
|
|
|
227
227
|
@cli.command(context_settings=dict(ignore_unknown_options=True, allow_extra_args=True), cls=ClusterOrPodCommandHelper, help='Restart Cassandra Cluster or Node')
|
|
@@ -234,7 +234,7 @@ def report(kubeconfig: str, config: str, param: list[str], cluster: str, namespa
|
|
|
234
234
|
@click.option('--force', is_flag=True, help='need for restarting the whole cluster')
|
|
235
235
|
@click.argument('extra_args', nargs=-1, metavar='<cluster|pod>', type=click.UNPROCESSED)
|
|
236
236
|
def restart(kubeconfig: str, config: str, param: list[str], cluster: str, namespace: str, pod: str, force: bool, extra_args):
|
|
237
|
-
run_command(
|
|
237
|
+
run_command(RestartNodes(), kubeconfig, config, param, cluster, namespace, pod, ('--force',) + extra_args if force else extra_args)
|
|
238
238
|
|
|
239
239
|
|
|
240
240
|
@cli.command(context_settings=dict(ignore_unknown_options=True, allow_extra_args=True), cls=ClusterOrPodCommandHelper, help='Rolling restart Cassandra Cluster.')
|
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/checks/disk.py
CHANGED
|
@@ -6,6 +6,7 @@ from adam.checks.check_context import CheckContext
|
|
|
6
6
|
from adam.checks.check_result import CheckResult
|
|
7
7
|
from adam.checks.issue import Issue
|
|
8
8
|
from adam.config import Config
|
|
9
|
+
from adam.utils import log_exc
|
|
9
10
|
from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
10
11
|
|
|
11
12
|
class Disk(Check):
|
|
@@ -87,10 +88,8 @@ class Disk(Check):
|
|
|
87
88
|
|
|
88
89
|
ss_size = 0.0
|
|
89
90
|
if ss_out:
|
|
90
|
-
|
|
91
|
+
with log_exc():
|
|
91
92
|
ss_size = round(float(ss_out.strip(' \r\n')) / 1024 / 1024, 2)
|
|
92
|
-
except:
|
|
93
|
-
pass
|
|
94
93
|
|
|
95
94
|
def parse_du_out(l: str, default: str = None):
|
|
96
95
|
groups = re.match(r'^(\S+)\s+(\S+)$', l.strip('\r'))
|
adam/columns/memory.py
CHANGED
|
@@ -3,6 +3,7 @@ from kubernetes.utils import parse_quantity
|
|
|
3
3
|
from adam.checks.check_result import CheckResult
|
|
4
4
|
from adam.checks.memory import Memory as MemoryCheck
|
|
5
5
|
from adam.columns.column import Column
|
|
6
|
+
from adam.utils import log_exc
|
|
6
7
|
|
|
7
8
|
class Memory(Column):
|
|
8
9
|
def name(self):
|
|
@@ -18,7 +19,5 @@ class Memory(Column):
|
|
|
18
19
|
return f"{Memory.to_g(mem['used'])}/{Memory.to_g(mem['limit'])}"
|
|
19
20
|
|
|
20
21
|
def to_g(v: str):
|
|
21
|
-
|
|
22
|
-
return f'{round(parse_quantity(v) / 1024 / 1024 / 1024, 2)}G'
|
|
23
|
-
except:
|
|
24
|
-
return v
|
|
22
|
+
with log_exc():
|
|
23
|
+
return f'{round(parse_quantity(v) / 1024 / 1024 / 1024, 2)}G'
|
adam/commands/__init__.py
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
|
-
from
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
from adam.commands.command import ExtractAllOptionsHandler, ExtractOptionsHandler, ExtractSequenceOptionsHandler, ExtractTrailingOptionsHandler, ValidateArgCountHandler
|
|
2
3
|
from adam.repl_state import ReplState
|
|
3
|
-
from adam.utils_app import AppHandler
|
|
4
|
+
from adam.commands.app.utils_app import AppHandler
|
|
4
5
|
|
|
5
6
|
def app(state: ReplState) -> AppHandler:
|
|
6
7
|
return AppHandler(state)
|
|
7
8
|
|
|
8
|
-
def extract_options(args: list[str], options
|
|
9
|
+
def extract_options(args: list[str], options: list[str]):
|
|
9
10
|
return ExtractOptionsHandler(args, options = options)
|
|
10
11
|
|
|
11
|
-
def extract_trailing_options(args: list[str], trailing
|
|
12
|
+
def extract_trailing_options(args: list[str], trailing: list[str]):
|
|
12
13
|
return ExtractTrailingOptionsHandler(args, trailing = trailing)
|
|
13
14
|
|
|
14
|
-
def extract_all_options(args: list[str], trailing = None, options = None):
|
|
15
|
-
return ExtractAllOptionsHandler(args, trailing = trailing, options = options)
|
|
15
|
+
def extract_all_options(args: list[str], trailing = None, sequence = None, options = None):
|
|
16
|
+
return ExtractAllOptionsHandler(args, trailing = trailing, sequence = sequence, options = options)
|
|
17
|
+
|
|
18
|
+
def extract_sequence(args: list[str], sequence: list[str]):
|
|
19
|
+
return ExtractSequenceOptionsHandler(args, sequence = sequence)
|
|
20
|
+
|
|
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)
|
adam/commands/alter_tables.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
from adam.commands import extract_options
|
|
1
|
+
from adam.commands import extract_options, validate_args
|
|
2
2
|
from adam.commands.command import Command
|
|
3
3
|
from adam.commands.cql.utils_cql import cassandra, cassandra_tables as get_tables
|
|
4
4
|
from adam.config import Config
|
|
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'
|
|
@@ -29,49 +29,34 @@ class AlterTables(Command):
|
|
|
29
29
|
|
|
30
30
|
with self.validate(args, state) as (args, state):
|
|
31
31
|
with extract_options(args, '--include-reaper') as (args, include_reaper):
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
excludes = [e.strip(' \r\n') for e in Config().get(
|
|
45
|
-
'cql.alter-tables.excludes',
|
|
46
|
-
'system_auth,system_traces,reaper_db,system_distributed,system_views,system,system_schema,system_virtual_schema').split(',')]
|
|
47
|
-
batching = Config().get('cql.alter-tables.batching', True)
|
|
48
|
-
tables = get_tables(state, on_any=True)
|
|
49
|
-
for k, v in tables.items():
|
|
50
|
-
if k not in excludes or k == 'reaper_db' and include_reaper:
|
|
51
|
-
if batching:
|
|
52
|
-
# alter table <table_name> with GC_GRACE_SECONDS = <timeout>;
|
|
53
|
-
cql = ';\n'.join([f'alter table {k}.{t} with {arg_str}' for t in v])
|
|
54
|
-
try:
|
|
55
|
-
with cassandra(state) as pods:
|
|
56
|
-
pods.cql(cql, show_out=Config().is_debug(), show_query=not Config().is_debug(), on_any=True)
|
|
57
|
-
except Exception as e:
|
|
58
|
-
log2(e)
|
|
59
|
-
continue
|
|
60
|
-
else:
|
|
61
|
-
for t in v:
|
|
62
|
-
try:
|
|
63
|
-
# alter table <table_name> with GC_GRACE_SECONDS = <timeout>;
|
|
64
|
-
cql = f'alter table {k}.{t} with {arg_str}'
|
|
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):
|
|
65
44
|
with cassandra(state) as pods:
|
|
66
|
-
pods.cql(show_out=Config().is_debug(), show_query=not Config().is_debug(), on_any=True)
|
|
67
|
-
except Exception as e:
|
|
68
|
-
log2(e)
|
|
45
|
+
pods.cql(cql, show_out=Config().is_debug(), show_query=not Config().is_debug(), on_any=True)
|
|
69
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
|
|
70
55
|
|
|
71
|
-
|
|
56
|
+
log2(f'{len(v)} tables altered in {k}.')
|
|
72
57
|
|
|
73
|
-
|
|
74
|
-
|
|
58
|
+
# do not continue to cql route
|
|
59
|
+
return state
|
|
75
60
|
|
|
76
61
|
def completion(self, _: ReplState) -> dict[str, any]:
|
|
77
62
|
# auto completion is taken care of by sql completer
|
|
File without changes
|
|
@@ -31,8 +31,8 @@ class App(Command):
|
|
|
31
31
|
|
|
32
32
|
return state
|
|
33
33
|
|
|
34
|
-
def completion(self,
|
|
35
|
-
return
|
|
34
|
+
def completion(self, _: ReplState):
|
|
35
|
+
return {}
|
|
36
36
|
|
|
37
37
|
def help(self, _: ReplState):
|
|
38
38
|
return f"<AppType>.<AppAction> <args> [--force]\t post app action; check with 'show app actions' command"
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
from adam.app_session import AppSession
|
|
2
|
-
from adam.apps import
|
|
2
|
+
from adam.apps import Apps
|
|
3
3
|
from adam.commands.command import Command
|
|
4
4
|
from adam.config import Config
|
|
5
5
|
from adam.repl_state import ReplState
|
|
6
|
-
from adam.utils import
|
|
6
|
+
from adam.utils import tabulize, log
|
|
7
7
|
|
|
8
8
|
class ShowAppActions(Command):
|
|
9
9
|
COMMAND = 'show app actions'
|
|
@@ -28,25 +28,17 @@ class ShowAppActions(Command):
|
|
|
28
28
|
return super().run(cmd, state)
|
|
29
29
|
|
|
30
30
|
with self.validate(args, state) as (args, state):
|
|
31
|
-
|
|
31
|
+
actions = []
|
|
32
32
|
for typ in Apps().app_types():
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if args:
|
|
37
|
-
line = f'{typ.name}.{a.name},{args}'
|
|
38
|
-
else:
|
|
39
|
-
line = f'{typ.name}.{a.name},'
|
|
40
|
-
if a.help:
|
|
41
|
-
line = f'{line},{a.help}'
|
|
42
|
-
lines.append(line)
|
|
43
|
-
log(lines_to_tabular(lines, 'ACTION,ARGS,DESCRIPTION', separator=','))
|
|
33
|
+
actions.extend(typ.actions)
|
|
34
|
+
|
|
35
|
+
lines = tabulize(actions, lambda a: str(a), header='ACTION,ARGS,DESCRIPTION', separator=',')
|
|
44
36
|
log()
|
|
45
37
|
|
|
46
38
|
app_session: AppSession = AppSession.create(state.app_env or 'c3', state.app_app or 'c3')
|
|
47
39
|
endpoint = Config().get('app.console-endpoint', 'https://{host}/{env}/{app}/static/console/index.html')
|
|
48
40
|
endpoint = endpoint.replace('{host}', app_session.host).replace('{env}', app_session.env).replace('{app}', state.app_app or 'c3')
|
|
49
|
-
|
|
41
|
+
tabulize([f'CONSOLE:,{endpoint}'], separator=',')
|
|
50
42
|
|
|
51
43
|
return lines
|
|
52
44
|
|
|
@@ -32,10 +32,7 @@ class ShowAppQueues(Command):
|
|
|
32
32
|
return state
|
|
33
33
|
|
|
34
34
|
def completion(self, state: ReplState):
|
|
35
|
-
|
|
36
|
-
return super().completion(state, {'--force': None})
|
|
37
|
-
|
|
38
|
-
return {}
|
|
35
|
+
return super().completion(state, {'--force': None})
|
|
39
36
|
|
|
40
37
|
def help(self, _: ReplState):
|
|
41
38
|
return f"{ShowAppQueues.COMMAND} [--force]\t show invalidation queue counts"
|
|
@@ -3,12 +3,20 @@ from typing import Union
|
|
|
3
3
|
|
|
4
4
|
from adam.app_session import AppSession
|
|
5
5
|
from adam.apps import Apps
|
|
6
|
-
from adam.pod_exec_result import PodExecResult
|
|
6
|
+
from adam.utils_k8s.pod_exec_result import PodExecResult
|
|
7
7
|
from adam.repl_state import ReplState
|
|
8
8
|
from adam.utils import log2
|
|
9
9
|
from adam.utils_k8s.app_clusters import AppClusters
|
|
10
10
|
from adam.utils_k8s.app_pods import AppPods
|
|
11
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
|
+
|
|
12
20
|
class AppRestHandler:
|
|
13
21
|
def __init__(self, state: ReplState, forced = False):
|
|
14
22
|
self.state = state
|
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
|
|
@@ -9,7 +11,7 @@ from adam.commands.audit.utils_show_top10 import show_top10_completions_for_nest
|
|
|
9
11
|
from adam.commands.command import Command
|
|
10
12
|
from adam.commands.intermediate_command import IntermediateCommand
|
|
11
13
|
from adam.repl_state import ReplState
|
|
12
|
-
from adam.sql.
|
|
14
|
+
from adam.sql.lark_completer import LarkCompleter
|
|
13
15
|
from adam.utils import log2, wait_log
|
|
14
16
|
from adam.utils_athena import Athena
|
|
15
17
|
|
|
@@ -42,36 +44,17 @@ class Audit(IntermediateCommand):
|
|
|
42
44
|
r = self.intermediate_run(cmd, state, args, self.cmd_list(), display_help=False)
|
|
43
45
|
|
|
44
46
|
if not r or isinstance(r, str) and r == 'command-missing':
|
|
45
|
-
|
|
46
|
-
if args:
|
|
47
|
-
sql = ' '.join(args)
|
|
48
|
-
else:
|
|
47
|
+
with validate_args(args, state, default='select * from audit order by ts desc limit 10') as sql:
|
|
49
48
|
log2(sql)
|
|
50
|
-
|
|
51
|
-
Athena.run_query(sql)
|
|
49
|
+
Athena.run_query(sql)
|
|
52
50
|
|
|
53
51
|
return state
|
|
54
52
|
|
|
55
53
|
def completion(self, state: ReplState):
|
|
56
|
-
if state.device
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
# warm up the caches first time when l: drive is accessed
|
|
61
|
-
Athena.table_names()
|
|
62
|
-
Athena.column_names()
|
|
63
|
-
Athena.column_names(partition_cols_only=True)
|
|
64
|
-
|
|
65
|
-
return super().completion(state) | show_top10_completions_for_nesting() | SqlCompleter(
|
|
66
|
-
lambda: Athena.table_names(),
|
|
67
|
-
expandables={
|
|
68
|
-
'columns': lambda table: Athena.column_names(),
|
|
69
|
-
'partition_columns': lambda table: Athena.column_names(partition_cols_only=True)
|
|
70
|
-
},
|
|
71
|
-
variant=SqlVariant.ATHENA
|
|
72
|
-
).completions_for_nesting()
|
|
73
|
-
|
|
74
|
-
return {}
|
|
54
|
+
if state.device != ReplState.L:
|
|
55
|
+
return {}
|
|
56
|
+
|
|
57
|
+
return completions_l()
|
|
75
58
|
|
|
76
59
|
def cmd_list(self):
|
|
77
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,17 +1,29 @@
|
|
|
1
1
|
from datetime import datetime, timedelta
|
|
2
2
|
|
|
3
|
+
from adam.config import Config
|
|
4
|
+
from adam.utils import log2, log_exc
|
|
5
|
+
from adam.utils_athena import Athena
|
|
3
6
|
from adam.utils_audits import Audits
|
|
4
7
|
from adam.utils_repl.automata_completer import AutomataCompleter
|
|
5
8
|
from adam.utils_repl.state_machine import StateMachine
|
|
6
9
|
|
|
10
|
+
def run_configured_query(config_key: str, args: list[str]):
|
|
11
|
+
limit, date_condition = extract_limit_and_duration(args)
|
|
12
|
+
if query := Config().get(config_key, None):
|
|
13
|
+
query = '\n '.join(query.split('\n'))
|
|
14
|
+
query = query.replace('{date_condition}', date_condition)
|
|
15
|
+
query = query.replace('{limit}', str(limit))
|
|
16
|
+
|
|
17
|
+
log2(query)
|
|
18
|
+
log2()
|
|
19
|
+
Athena.run_query(query)
|
|
20
|
+
|
|
7
21
|
def extract_limit_and_duration(args: list[str]) -> tuple[int, datetime]:
|
|
8
22
|
limit = 10
|
|
9
23
|
_from = datetime.now() - timedelta(days=30)
|
|
10
24
|
if args:
|
|
11
|
-
|
|
25
|
+
with log_exc():
|
|
12
26
|
limit = int(args[0])
|
|
13
|
-
except:
|
|
14
|
-
pass
|
|
15
27
|
|
|
16
28
|
if len(args) > 2 and args[1] == 'over':
|
|
17
29
|
if args[2] == 'day':
|