kaqing 1.98.15__py3-none-any.whl → 2.0.145__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of kaqing might be problematic. Click here for more details.
- adam/app_session.py +1 -1
- adam/apps.py +2 -2
- adam/batch.py +30 -31
- adam/checks/check_utils.py +4 -4
- adam/checks/compactionstats.py +1 -1
- adam/checks/cpu.py +2 -2
- adam/checks/disk.py +1 -1
- adam/checks/gossip.py +1 -1
- adam/checks/memory.py +3 -3
- adam/checks/status.py +1 -1
- adam/commands/alter_tables.py +81 -0
- adam/commands/app.py +3 -3
- adam/commands/app_ping.py +2 -2
- adam/commands/audit/audit.py +86 -0
- adam/commands/audit/audit_repair_tables.py +77 -0
- adam/commands/audit/audit_run.py +58 -0
- adam/commands/audit/show_last10.py +51 -0
- adam/commands/audit/show_slow10.py +50 -0
- adam/commands/audit/show_top10.py +48 -0
- adam/commands/audit/utils_show_top10.py +59 -0
- adam/commands/bash/bash.py +133 -0
- adam/commands/bash/bash_completer.py +93 -0
- adam/commands/cat.py +56 -0
- adam/commands/cd.py +12 -82
- adam/commands/check.py +6 -0
- adam/commands/cli_commands.py +3 -3
- adam/commands/code.py +60 -0
- adam/commands/command.py +48 -12
- adam/commands/commands_utils.py +4 -5
- adam/commands/cql/cql_completions.py +28 -0
- adam/commands/cql/cql_utils.py +209 -0
- adam/commands/{cqlsh.py → cql/cqlsh.py} +15 -10
- adam/commands/deploy/__init__.py +0 -0
- adam/commands/{frontend → deploy}/code_start.py +1 -1
- adam/commands/{frontend → deploy}/code_stop.py +1 -1
- adam/commands/{frontend → deploy}/code_utils.py +2 -2
- adam/commands/deploy/deploy.py +48 -0
- adam/commands/deploy/deploy_frontend.py +52 -0
- adam/commands/deploy/deploy_pg_agent.py +38 -0
- adam/commands/deploy/deploy_pod.py +110 -0
- adam/commands/deploy/deploy_utils.py +29 -0
- adam/commands/deploy/undeploy.py +48 -0
- adam/commands/deploy/undeploy_frontend.py +41 -0
- adam/commands/deploy/undeploy_pg_agent.py +42 -0
- adam/commands/deploy/undeploy_pod.py +51 -0
- adam/commands/devices/__init__.py +0 -0
- adam/commands/devices/device.py +27 -0
- adam/commands/devices/device_app.py +146 -0
- adam/commands/devices/device_auit_log.py +43 -0
- adam/commands/devices/device_cass.py +145 -0
- adam/commands/devices/device_export.py +86 -0
- adam/commands/devices/device_postgres.py +109 -0
- adam/commands/devices/devices.py +25 -0
- adam/commands/export/__init__.py +0 -0
- adam/commands/export/clean_up_export_session.py +53 -0
- adam/commands/{frontend/teardown_frontend.py → export/clean_up_export_sessions.py} +9 -11
- adam/commands/export/drop_export_database.py +58 -0
- adam/commands/export/drop_export_databases.py +46 -0
- adam/commands/export/export.py +83 -0
- adam/commands/export/export_databases.py +170 -0
- adam/commands/export/export_select.py +85 -0
- adam/commands/export/export_select_x.py +54 -0
- adam/commands/export/export_use.py +55 -0
- adam/commands/export/exporter.py +364 -0
- adam/commands/export/import_session.py +68 -0
- adam/commands/export/importer.py +67 -0
- adam/commands/export/importer_athena.py +80 -0
- adam/commands/export/importer_sqlite.py +47 -0
- adam/commands/export/show_column_counts.py +63 -0
- adam/commands/export/show_export_databases.py +39 -0
- adam/commands/export/show_export_session.py +51 -0
- adam/commands/export/show_export_sessions.py +47 -0
- adam/commands/export/utils_export.py +291 -0
- adam/commands/help.py +12 -7
- adam/commands/issues.py +6 -0
- adam/commands/kubectl.py +41 -0
- adam/commands/login.py +9 -5
- adam/commands/logs.py +2 -1
- adam/commands/ls.py +4 -107
- adam/commands/medusa/medusa.py +2 -26
- adam/commands/medusa/medusa_backup.py +2 -2
- adam/commands/medusa/medusa_restore.py +3 -4
- adam/commands/medusa/medusa_show_backupjobs.py +4 -3
- adam/commands/medusa/medusa_show_restorejobs.py +3 -3
- adam/commands/nodetool.py +9 -4
- adam/commands/param_set.py +1 -1
- adam/commands/postgres/postgres.py +42 -43
- adam/commands/postgres/postgres_context.py +248 -0
- adam/commands/postgres/postgres_preview.py +0 -1
- adam/commands/postgres/postgres_utils.py +31 -0
- adam/commands/postgres/psql_completions.py +10 -0
- adam/commands/preview_table.py +18 -40
- adam/commands/pwd.py +2 -28
- adam/commands/reaper/reaper.py +4 -24
- adam/commands/reaper/reaper_restart.py +1 -1
- adam/commands/reaper/reaper_session.py +2 -2
- adam/commands/repair/repair.py +3 -27
- adam/commands/repair/repair_log.py +1 -1
- adam/commands/repair/repair_run.py +2 -2
- adam/commands/repair/repair_scan.py +2 -7
- adam/commands/repair/repair_stop.py +1 -1
- adam/commands/report.py +6 -0
- adam/commands/restart.py +2 -2
- adam/commands/rollout.py +1 -1
- adam/commands/shell.py +33 -0
- adam/commands/show/show.py +11 -26
- adam/commands/show/show_app_actions.py +3 -0
- adam/commands/show/show_app_id.py +1 -1
- adam/commands/show/show_app_queues.py +3 -2
- adam/commands/show/show_cassandra_status.py +3 -3
- adam/commands/show/show_cassandra_version.py +3 -3
- adam/commands/show/show_commands.py +4 -1
- adam/commands/show/show_host.py +33 -0
- adam/commands/show/show_login.py +3 -0
- adam/commands/show/show_processes.py +1 -1
- adam/commands/show/show_repairs.py +2 -2
- adam/commands/show/show_storage.py +1 -1
- adam/commands/watch.py +1 -1
- adam/config.py +16 -3
- adam/embedded_params.py +1 -1
- adam/pod_exec_result.py +10 -2
- adam/repl.py +132 -117
- adam/repl_commands.py +62 -18
- adam/repl_state.py +276 -55
- adam/sql/__init__.py +0 -0
- adam/sql/sql_completer.py +120 -0
- adam/sql/sql_state_machine.py +617 -0
- adam/sql/term_completer.py +76 -0
- adam/sso/authenticator.py +1 -1
- adam/sso/authn_ad.py +36 -56
- adam/sso/authn_okta.py +6 -32
- adam/sso/cred_cache.py +1 -1
- adam/sso/idp.py +74 -9
- adam/sso/idp_login.py +2 -2
- adam/sso/idp_session.py +10 -7
- adam/utils.py +85 -4
- adam/utils_athena.py +145 -0
- adam/utils_audits.py +102 -0
- adam/utils_k8s/__init__.py +0 -0
- adam/utils_k8s/app_clusters.py +33 -0
- adam/utils_k8s/app_pods.py +31 -0
- adam/{k8s_utils → utils_k8s}/cassandra_clusters.py +6 -21
- adam/{k8s_utils → utils_k8s}/cassandra_nodes.py +12 -5
- adam/utils_k8s/config_maps.py +34 -0
- adam/utils_k8s/deployment.py +56 -0
- adam/{k8s_utils → utils_k8s}/jobs.py +1 -1
- adam/{k8s_utils → utils_k8s}/kube_context.py +1 -1
- adam/utils_k8s/pods.py +342 -0
- adam/{k8s_utils → utils_k8s}/secrets.py +4 -0
- adam/utils_k8s/service_accounts.py +169 -0
- adam/{k8s_utils → utils_k8s}/statefulsets.py +5 -4
- adam/{k8s_utils → utils_k8s}/volumes.py +9 -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 +101 -0
- adam/version.py +1 -1
- {kaqing-1.98.15.dist-info → kaqing-2.0.145.dist-info}/METADATA +1 -1
- kaqing-2.0.145.dist-info/RECORD +227 -0
- adam/commands/bash.py +0 -87
- adam/commands/cql_utils.py +0 -53
- adam/commands/devices.py +0 -89
- adam/commands/frontend/setup.py +0 -60
- adam/commands/frontend/setup_frontend.py +0 -58
- adam/commands/frontend/teardown.py +0 -61
- adam/commands/postgres/postgres_session.py +0 -225
- adam/commands/user_entry.py +0 -77
- adam/k8s_utils/pods.py +0 -211
- kaqing-1.98.15.dist-info/RECORD +0 -160
- /adam/commands/{frontend → audit}/__init__.py +0 -0
- /adam/{k8s_utils → commands/bash}/__init__.py +0 -0
- /adam/{medusa_show_restorejobs.py → commands/cql/__init__.py} +0 -0
- /adam/{k8s_utils → utils_k8s}/custom_resources.py +0 -0
- /adam/{k8s_utils → utils_k8s}/ingresses.py +0 -0
- /adam/{k8s_utils → utils_k8s}/services.py +0 -0
- {kaqing-1.98.15.dist-info → kaqing-2.0.145.dist-info}/WHEEL +0 -0
- {kaqing-1.98.15.dist-info → kaqing-2.0.145.dist-info}/entry_points.txt +0 -0
- {kaqing-1.98.15.dist-info → kaqing-2.0.145.dist-info}/top_level.txt +0 -0
adam/commands/command.py
CHANGED
|
@@ -3,8 +3,9 @@ import copy
|
|
|
3
3
|
import subprocess
|
|
4
4
|
import sys
|
|
5
5
|
|
|
6
|
-
from adam.
|
|
6
|
+
from adam.commands.command_helpers import ClusterCommandHelper
|
|
7
7
|
from adam.repl_state import ReplState, RequiredState
|
|
8
|
+
from adam.utils import is_lambda, lines_to_tabular, log, log2
|
|
8
9
|
|
|
9
10
|
repl_cmds: list['Command'] = []
|
|
10
11
|
|
|
@@ -22,14 +23,18 @@ class Command:
|
|
|
22
23
|
# Do not do child of child!!!
|
|
23
24
|
@abstractmethod
|
|
24
25
|
def run(self, cmd: str, state: ReplState):
|
|
25
|
-
Config().debug(cmd)
|
|
26
26
|
if self._successor:
|
|
27
27
|
return self._successor.run(cmd, state)
|
|
28
28
|
|
|
29
29
|
return None
|
|
30
30
|
|
|
31
|
-
def completion(self,
|
|
32
|
-
|
|
31
|
+
def completion(self, state: ReplState, leaf: dict[str, any] = None) -> dict[str, any]:
|
|
32
|
+
if not self.validate_state(state, show_err=False):
|
|
33
|
+
return {}
|
|
34
|
+
|
|
35
|
+
if is_lambda(leaf):
|
|
36
|
+
leaf = leaf()
|
|
37
|
+
|
|
33
38
|
d = leaf
|
|
34
39
|
for t in reversed(self.command().split(' ')):
|
|
35
40
|
d = {t: d}
|
|
@@ -39,12 +44,11 @@ class Command:
|
|
|
39
44
|
def required(self) -> RequiredState:
|
|
40
45
|
return None
|
|
41
46
|
|
|
42
|
-
def validate_state(self, state: ReplState,
|
|
43
|
-
return state.validate(self.required(),
|
|
47
|
+
def validate_state(self, state: ReplState, show_err=True):
|
|
48
|
+
return state.validate(self.required(), show_err=show_err)
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
pass
|
|
50
|
+
def help(self, _: ReplState) -> str:
|
|
51
|
+
return None
|
|
48
52
|
|
|
49
53
|
def args(self, cmd: str):
|
|
50
54
|
a = list(filter(None, cmd.split(' ')))
|
|
@@ -54,8 +58,11 @@ class Command:
|
|
|
54
58
|
|
|
55
59
|
return a
|
|
56
60
|
|
|
57
|
-
def apply_state(self, args: list[str], state: ReplState, resolve_pg = True) -> tuple[ReplState, list[str]]:
|
|
58
|
-
|
|
61
|
+
def apply_state(self, args: list[str], state: ReplState, resolve_pg = True, args_to_check = 6) -> tuple[ReplState, list[str]]:
|
|
62
|
+
"""
|
|
63
|
+
Applies any contextual arguments such as namespace or statefulset to the ReplState and returns any non-contextual arguments.
|
|
64
|
+
"""
|
|
65
|
+
return state.apply_args(args, cmd=self.command_tokens(), resolve_pg=resolve_pg, args_to_check=args_to_check)
|
|
59
66
|
|
|
60
67
|
def command_tokens(self):
|
|
61
68
|
return self.command().split(' ')
|
|
@@ -103,4 +110,33 @@ class Command:
|
|
|
103
110
|
while s := cmd._successor:
|
|
104
111
|
print(f'-> {s.command()}', end = '')
|
|
105
112
|
cmd = s
|
|
106
|
-
print()
|
|
113
|
+
print()
|
|
114
|
+
|
|
115
|
+
def intermediate_run(self, cmd: str, state: ReplState, args: list[str], cmds: list['Command'], separator='\t', display_help=True):
|
|
116
|
+
state, _ = self.apply_state(args, state)
|
|
117
|
+
|
|
118
|
+
if state.in_repl:
|
|
119
|
+
if display_help:
|
|
120
|
+
log(lines_to_tabular([c.help(state) for c in cmds], separator=separator))
|
|
121
|
+
|
|
122
|
+
return 'command-missing'
|
|
123
|
+
else:
|
|
124
|
+
# head with the Chain of Responsibility pattern
|
|
125
|
+
cmds = Command.chain(cmds)
|
|
126
|
+
if not cmds.run(cmd, state):
|
|
127
|
+
if display_help:
|
|
128
|
+
log2('* Command is missing.')
|
|
129
|
+
Command.display_help()
|
|
130
|
+
return 'command-missing'
|
|
131
|
+
|
|
132
|
+
return state
|
|
133
|
+
|
|
134
|
+
def intermediate_help(super_help: str, cmd: str, cmd_list: list['Command'], separator='\t', show_cluster_help=False):
|
|
135
|
+
log(super_help)
|
|
136
|
+
log()
|
|
137
|
+
log('Sub-Commands:')
|
|
138
|
+
|
|
139
|
+
log(lines_to_tabular([c.help(ReplState()).replace(f'{cmd} ', ' ', 1) for c in cmd_list], separator=separator))
|
|
140
|
+
if show_cluster_help:
|
|
141
|
+
log()
|
|
142
|
+
ClusterCommandHelper.cluster_help()
|
adam/commands/commands_utils.py
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
from concurrent.futures import ThreadPoolExecutor
|
|
2
|
-
import time
|
|
3
2
|
from kubernetes import client
|
|
4
3
|
from typing import List
|
|
5
4
|
|
|
6
5
|
from adam.checks.check_utils import run_checks
|
|
7
6
|
from adam.columns.columns import Columns, collect_checks
|
|
8
7
|
from adam.commands.issues import Issues
|
|
9
|
-
from adam.
|
|
10
|
-
from adam.
|
|
11
|
-
from adam.
|
|
8
|
+
from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
9
|
+
from adam.utils_k8s.pods import Pods
|
|
10
|
+
from adam.utils_k8s.statefulsets import StatefulSets
|
|
12
11
|
from adam.repl_state import ReplState
|
|
13
|
-
from adam.utils import
|
|
12
|
+
from adam.utils import duration, lines_to_tabular, log, log2
|
|
14
13
|
|
|
15
14
|
def show_pods(pods: List[client.V1Pod], ns: str, show_namespace = True, show_host_id = True):
|
|
16
15
|
if len(pods) == 0:
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from adam.commands.cql.cql_utils import cassandra_keyspaces, cassandra_table_names
|
|
2
|
+
from adam.commands.export.exporter import Exporter
|
|
3
|
+
from adam.commands.export.export_databases import ExportDatabases
|
|
4
|
+
from adam.config import Config
|
|
5
|
+
from adam.repl_state import ReplState
|
|
6
|
+
from adam.sql.sql_completer import SqlCompleter, SqlVariant
|
|
7
|
+
|
|
8
|
+
def cql_completions(state: ReplState) -> dict[str, any]:
|
|
9
|
+
ps = Config().get('cql.alter-tables.gc-grace-periods', '3600,86400,864000,7776000').split(',')
|
|
10
|
+
# warm up caches
|
|
11
|
+
cassandra_keyspaces(state)
|
|
12
|
+
cassandra_table_names(state)
|
|
13
|
+
ExportDatabases.database_names()
|
|
14
|
+
|
|
15
|
+
expandables = {
|
|
16
|
+
'keyspaces': lambda: cassandra_keyspaces(state),
|
|
17
|
+
'table-props': lambda: {
|
|
18
|
+
'GC_GRACE_SECONDS': ps
|
|
19
|
+
},
|
|
20
|
+
'export-dbs': lambda: ExportDatabases.database_names(),
|
|
21
|
+
'export-sessions': lambda: Exporter.export_session_names(state.sts, state.pod, state.namespace),
|
|
22
|
+
'export-sessions-incomplete': lambda: Exporter.export_session_names(state.sts, state.pod, state.namespace, export_state='pending_import'),
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return SqlCompleter(
|
|
26
|
+
lambda: cassandra_table_names(state),
|
|
27
|
+
expandables=expandables,
|
|
28
|
+
variant=SqlVariant.CQL).completions_for_nesting()
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
from adam.config import Config
|
|
5
|
+
from adam.utils_k8s.cassandra_clusters import CassandraClusters
|
|
6
|
+
from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
7
|
+
from adam.utils_k8s.secrets import Secrets
|
|
8
|
+
from adam.pod_exec_result import PodExecResult
|
|
9
|
+
from adam.repl_state import ReplState
|
|
10
|
+
from adam.utils import log2
|
|
11
|
+
|
|
12
|
+
@functools.lru_cache()
|
|
13
|
+
def cassandra_keyspaces(state: ReplState, on_any=True):
|
|
14
|
+
if state.pod:
|
|
15
|
+
Config().wait_log(f'Inspecting Cassandra Keyspaces on {state.pod}...')
|
|
16
|
+
else:
|
|
17
|
+
Config().wait_log(f'Inspecting Cassandra Keyspaces...')
|
|
18
|
+
|
|
19
|
+
r: list[PodExecResult] = run_cql(state, 'describe keyspaces', show_out=False, on_any=on_any)
|
|
20
|
+
if not r:
|
|
21
|
+
log2('No pod is available')
|
|
22
|
+
return []
|
|
23
|
+
|
|
24
|
+
return parse_cql_desc_keyspaces(r.stdout if state.pod else r[0].stdout)
|
|
25
|
+
|
|
26
|
+
def cassandra_table_names(state: ReplState, keyspace = None):
|
|
27
|
+
return [f'{k}.{t}' for k, ts in cassandra_tables(state, on_any=True).items() for t in ts if not keyspace or keyspace == '*' or k == keyspace]
|
|
28
|
+
|
|
29
|
+
@functools.lru_cache()
|
|
30
|
+
def cassandra_tables(state: ReplState, on_any=False) -> dict[str, list[str]]:
|
|
31
|
+
r: list[PodExecResult] = run_cql(state, 'describe tables', show_out=False, on_any=on_any)
|
|
32
|
+
if not r:
|
|
33
|
+
log2('No pod is available')
|
|
34
|
+
return {}
|
|
35
|
+
|
|
36
|
+
return parse_cql_desc_tables(r.stdout if state.pod else r[0].stdout)
|
|
37
|
+
|
|
38
|
+
@functools.lru_cache()
|
|
39
|
+
def table_spec(state: ReplState, table: str, on_any=False) -> 'TableSpec':
|
|
40
|
+
r: list[PodExecResult] = run_cql(state, f'describe table {table}', show_out=False, on_any=on_any)
|
|
41
|
+
if not r:
|
|
42
|
+
log2('No pod is available')
|
|
43
|
+
return None
|
|
44
|
+
|
|
45
|
+
return parse_cql_desc_table(r.stdout if state.pod else r[0].stdout)
|
|
46
|
+
|
|
47
|
+
def run_cql(state: ReplState, cql: str, opts: list = [], show_out = False, use_single_quotes = False, on_any = False, background=False, log_file=None) -> list[PodExecResult]:
|
|
48
|
+
user, pw = Secrets.get_user_pass(state.sts if state.sts else state.pod, state.namespace, secret_path='cql.secret')
|
|
49
|
+
if use_single_quotes:
|
|
50
|
+
command = f"cqlsh -u {user} -p {pw} {' '.join(opts)} -e '{cql}'"
|
|
51
|
+
else:
|
|
52
|
+
command = f'cqlsh -u {user} -p {pw} {" ".join(opts)} -e "{cql}"'
|
|
53
|
+
|
|
54
|
+
if state.pod:
|
|
55
|
+
return CassandraNodes.exec(state.pod, state.namespace, command, show_out=show_out, background=background, log_file=log_file)
|
|
56
|
+
else:
|
|
57
|
+
return CassandraClusters.exec(state.sts, state.namespace, command, show_out=show_out, action='cql', on_any=on_any, background=background, log_file=log_file)
|
|
58
|
+
|
|
59
|
+
def parse_cql_desc_tables(out: str):
|
|
60
|
+
# Keyspace data_endpoint_auth
|
|
61
|
+
# ---------------------------
|
|
62
|
+
# "token"
|
|
63
|
+
|
|
64
|
+
# Keyspace reaper_db
|
|
65
|
+
# ------------------
|
|
66
|
+
# repair_run schema_migration
|
|
67
|
+
# repair_run_by_cluster schema_migration_leader
|
|
68
|
+
|
|
69
|
+
# Keyspace system
|
|
70
|
+
tables_by_keyspace: dict[str, list[str]] = {}
|
|
71
|
+
keyspace = None
|
|
72
|
+
state = 's0'
|
|
73
|
+
for line in out.split('\n'):
|
|
74
|
+
if state == 's0':
|
|
75
|
+
groups = re.match(r'^Keyspace (.*)$', line)
|
|
76
|
+
if groups:
|
|
77
|
+
keyspace = groups[1].strip(' \r')
|
|
78
|
+
state = 's1'
|
|
79
|
+
elif state == 's1':
|
|
80
|
+
if line.startswith('---'):
|
|
81
|
+
state = 's2'
|
|
82
|
+
elif state == 's2':
|
|
83
|
+
if not line.strip(' \r'):
|
|
84
|
+
state = 's0'
|
|
85
|
+
else:
|
|
86
|
+
for table in line.split(' '):
|
|
87
|
+
if t := table.strip(' \r'):
|
|
88
|
+
if not keyspace in tables_by_keyspace:
|
|
89
|
+
tables_by_keyspace[keyspace] = []
|
|
90
|
+
tables_by_keyspace[keyspace].append(t)
|
|
91
|
+
|
|
92
|
+
return tables_by_keyspace
|
|
93
|
+
|
|
94
|
+
def parse_cql_desc_keyspaces(out: str) -> list[str]:
|
|
95
|
+
#
|
|
96
|
+
# Warning: Cannot create directory at `/home/cassandra/.cassandra`. Command history will not be saved. Please check what was the environment property CQL_HISTORY set to.
|
|
97
|
+
#
|
|
98
|
+
#
|
|
99
|
+
# Warning: Using a password on the command line interface can be insecure.
|
|
100
|
+
# Recommendation: use the credentials file to securely provide the password.
|
|
101
|
+
#
|
|
102
|
+
#
|
|
103
|
+
# azops88_db system_auth system_traces
|
|
104
|
+
# reaper_db system_distributed system_views
|
|
105
|
+
# system system_schema system_virtual_schema
|
|
106
|
+
#
|
|
107
|
+
kses = []
|
|
108
|
+
for line in out.split('\n'):
|
|
109
|
+
line = line.strip(' \r')
|
|
110
|
+
if not line:
|
|
111
|
+
continue
|
|
112
|
+
if line.startswith('Warning:'):
|
|
113
|
+
continue
|
|
114
|
+
if line.startswith('Recommendation:'):
|
|
115
|
+
continue
|
|
116
|
+
|
|
117
|
+
for ks in line.split(' '):
|
|
118
|
+
if s := ks.strip(' \r\t'):
|
|
119
|
+
kses.append(s)
|
|
120
|
+
|
|
121
|
+
return kses
|
|
122
|
+
|
|
123
|
+
class ColumnSpec:
|
|
124
|
+
def __init__(self, name: str, type: str, key_index = -1):
|
|
125
|
+
self.name = name
|
|
126
|
+
self.type = type
|
|
127
|
+
self.key_index = key_index
|
|
128
|
+
|
|
129
|
+
def __eq__(self, other):
|
|
130
|
+
if not isinstance(other, ColumnSpec):
|
|
131
|
+
return NotImplemented
|
|
132
|
+
|
|
133
|
+
return self.name == other.name and self.type == other.type and self.key_index == other.key_index
|
|
134
|
+
|
|
135
|
+
class TableSpec:
|
|
136
|
+
def __init__(self, columns: list[ColumnSpec]):
|
|
137
|
+
self.columns = columns
|
|
138
|
+
|
|
139
|
+
def row_key(self):
|
|
140
|
+
for c in self.columns:
|
|
141
|
+
if c.key_index == 0:
|
|
142
|
+
return c.name
|
|
143
|
+
|
|
144
|
+
def keys(self):
|
|
145
|
+
return [c.name for c in self.columns if c.key_index > -1]
|
|
146
|
+
|
|
147
|
+
def parse_cql_desc_table(out: str) -> TableSpec:
|
|
148
|
+
# CREATE TABLE azops88_db.analyticscontainer_dfeevalhistory (
|
|
149
|
+
# id text,
|
|
150
|
+
# columnname text,
|
|
151
|
+
# version bigint static,
|
|
152
|
+
# contentb blob,
|
|
153
|
+
# contentbool boolean,
|
|
154
|
+
# contentn double,
|
|
155
|
+
# contents text,
|
|
156
|
+
# PRIMARY KEY (id, columnname)
|
|
157
|
+
# ) WITH CLUSTERING ORDER BY (columnname ASC)
|
|
158
|
+
# AND additional_write_policy = '99p'
|
|
159
|
+
# AND bloom_filter_fp_chance = 0.1
|
|
160
|
+
# AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
|
|
161
|
+
# AND cdc = false
|
|
162
|
+
# AND comment = ''
|
|
163
|
+
# AND compaction = {'class': 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
|
|
164
|
+
# AND compression = {'chunk_length_in_kb': '16', 'class': 'org.apache.cassandra.io.compress.SnappyCompressor'}
|
|
165
|
+
# AND memtable = 'default'
|
|
166
|
+
# AND crc_check_chance = 1.0
|
|
167
|
+
# AND default_time_to_live = 0
|
|
168
|
+
# AND extensions = {}
|
|
169
|
+
# AND gc_grace_seconds = 3600
|
|
170
|
+
# AND max_index_interval = 2048
|
|
171
|
+
# AND memtable_flush_period_in_ms = 0
|
|
172
|
+
# AND min_index_interval = 128
|
|
173
|
+
# AND read_repair = 'BLOCKING'
|
|
174
|
+
# AND speculative_retry = '99p';
|
|
175
|
+
pkeys = {}
|
|
176
|
+
columns: list[ColumnSpec] = []
|
|
177
|
+
|
|
178
|
+
state = 's0'
|
|
179
|
+
for line in out.split('\n'):
|
|
180
|
+
if state == 's0':
|
|
181
|
+
if line.startswith('CREATE TABLE'):
|
|
182
|
+
state = 's1'
|
|
183
|
+
elif state == 's1':
|
|
184
|
+
if line.startswith(')'):
|
|
185
|
+
state = 's2'
|
|
186
|
+
continue
|
|
187
|
+
|
|
188
|
+
groups = re.match(r'^\s*PRIMARY KEY\s*\((.*)\).*$', line)
|
|
189
|
+
if groups:
|
|
190
|
+
pkeys = {n.strip(' '): i for i, n in enumerate(groups[1].strip(' \r').split(','))}
|
|
191
|
+
continue
|
|
192
|
+
|
|
193
|
+
# single key column - name text PRIMARY KEY,
|
|
194
|
+
groups = re.match(r'^\s*(\S*?)\s*(\S*?)\s*PRIMARY KEY,.*$', line)
|
|
195
|
+
if groups:
|
|
196
|
+
columns.append(ColumnSpec(groups[1], groups[2]))
|
|
197
|
+
pkeys[groups[1]] = 0
|
|
198
|
+
else:
|
|
199
|
+
groups = re.match(r'^\s*(\S*?)\s*(\S*?),.*$', line)
|
|
200
|
+
if groups:
|
|
201
|
+
columns.append(ColumnSpec(groups[1], groups[2]))
|
|
202
|
+
elif state == 's2':
|
|
203
|
+
pass
|
|
204
|
+
|
|
205
|
+
for column in columns:
|
|
206
|
+
if column.name in pkeys.keys():
|
|
207
|
+
column.key_index = pkeys[column.name]
|
|
208
|
+
|
|
209
|
+
return TableSpec(columns)
|
|
@@ -2,7 +2,9 @@ import click
|
|
|
2
2
|
|
|
3
3
|
from adam.commands.command import Command
|
|
4
4
|
from adam.commands.command_helpers import ClusterOrPodCommandHelper
|
|
5
|
-
from adam.commands.
|
|
5
|
+
from adam.commands.cql.cql_completions import cql_completions
|
|
6
|
+
from adam.utils_k8s.statefulsets import StatefulSets
|
|
7
|
+
from .cql_utils import run_cql
|
|
6
8
|
from adam.repl_state import ReplState, RequiredState
|
|
7
9
|
from adam.utils import log, log2
|
|
8
10
|
|
|
@@ -32,11 +34,14 @@ class Cqlsh(Command):
|
|
|
32
34
|
if not self.validate_state(state):
|
|
33
35
|
return state
|
|
34
36
|
|
|
37
|
+
background = False
|
|
35
38
|
opts = []
|
|
36
39
|
cqls = []
|
|
37
|
-
for arg in args:
|
|
40
|
+
for index, arg in enumerate(args):
|
|
38
41
|
if arg.startswith('--'):
|
|
39
42
|
opts.append(arg)
|
|
43
|
+
elif index == len(args) -1 and arg == '&':
|
|
44
|
+
background = True
|
|
40
45
|
elif arg != '-e':
|
|
41
46
|
cqls.append(arg)
|
|
42
47
|
if not cqls:
|
|
@@ -50,21 +55,21 @@ class Cqlsh(Command):
|
|
|
50
55
|
return 'no-cql'
|
|
51
56
|
|
|
52
57
|
cql = ' '.join(cqls)
|
|
53
|
-
return run_cql(state, cql, opts, show_out=True)
|
|
58
|
+
return run_cql(state, cql, opts, show_out=True, background=background)
|
|
54
59
|
|
|
55
60
|
def completion(self, state: ReplState) -> dict[str, any]:
|
|
61
|
+
if state.device != state.C:
|
|
62
|
+
# conflicts with psql completions
|
|
63
|
+
return {}
|
|
64
|
+
|
|
56
65
|
if state.sts or state.pod:
|
|
57
|
-
return
|
|
58
|
-
|
|
59
|
-
'insert': {'into': None},
|
|
60
|
-
'select': None,
|
|
61
|
-
'update': None,
|
|
62
|
-
}
|
|
66
|
+
return cql_completions(state) | \
|
|
67
|
+
{f'@{p}': cql_completions(state) for p in StatefulSets.pod_names(state.sts, state.namespace)}
|
|
63
68
|
|
|
64
69
|
return {}
|
|
65
70
|
|
|
66
71
|
def help(self, _: ReplState) -> str:
|
|
67
|
-
return f'
|
|
72
|
+
return f'<cql-statements> [&]\t run cqlsh with queries'
|
|
68
73
|
|
|
69
74
|
class CqlCommandHelper(click.Command):
|
|
70
75
|
def get_help(self, ctx: click.Context):
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from adam.commands.command import Command
|
|
2
|
-
from adam.commands.
|
|
2
|
+
from adam.commands.deploy.code_utils import start_user_code, stop_user_codes
|
|
3
3
|
from adam.repl_state import ReplState, RequiredState
|
|
4
4
|
from adam.utils import log2
|
|
5
5
|
|
|
@@ -5,8 +5,8 @@ import subprocess
|
|
|
5
5
|
|
|
6
6
|
from adam.apps import Apps
|
|
7
7
|
from adam.config import Config
|
|
8
|
-
from adam.
|
|
9
|
-
from adam.
|
|
8
|
+
from adam.utils_k8s.ingresses import Ingresses
|
|
9
|
+
from adam.utils_k8s.services import Services
|
|
10
10
|
from adam.utils import log2, random_alphanumeric
|
|
11
11
|
|
|
12
12
|
def start_user_code(namespace: str):
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import click
|
|
2
|
+
|
|
3
|
+
from adam.commands.command import Command
|
|
4
|
+
from adam.commands.deploy.deploy_pg_agent import DeployPgAgent
|
|
5
|
+
from adam.commands.deploy.deploy_pod import DeployPod
|
|
6
|
+
from .deploy_frontend import DeployFrontend
|
|
7
|
+
from adam.repl_state import ReplState, RequiredState
|
|
8
|
+
|
|
9
|
+
class Deploy(Command):
|
|
10
|
+
COMMAND = 'deploy'
|
|
11
|
+
reaper_login = None
|
|
12
|
+
|
|
13
|
+
# the singleton pattern
|
|
14
|
+
def __new__(cls, *args, **kwargs):
|
|
15
|
+
if not hasattr(cls, 'instance'): cls.instance = super(Deploy, 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 Deploy.COMMAND
|
|
24
|
+
|
|
25
|
+
def required(self):
|
|
26
|
+
return RequiredState.NAMESPACE
|
|
27
|
+
|
|
28
|
+
def run(self, cmd: str, state: ReplState):
|
|
29
|
+
if not(args := self.args(cmd)):
|
|
30
|
+
return super().run(cmd, state)
|
|
31
|
+
|
|
32
|
+
if not self.validate_state(state):
|
|
33
|
+
return state
|
|
34
|
+
|
|
35
|
+
return super().intermediate_run(cmd, state, args, Deploy.cmd_list())
|
|
36
|
+
|
|
37
|
+
def cmd_list():
|
|
38
|
+
return [DeployFrontend(), DeployPod(), DeployPgAgent()]
|
|
39
|
+
|
|
40
|
+
def completion(self, state: ReplState):
|
|
41
|
+
if state.sts:
|
|
42
|
+
return super().completion(state)
|
|
43
|
+
|
|
44
|
+
return {}
|
|
45
|
+
|
|
46
|
+
class DeployCommandHelper(click.Command):
|
|
47
|
+
def get_help(self, ctx: click.Context):
|
|
48
|
+
Command.intermediate_help(super().get_help(ctx), Deploy.COMMAND, Deploy.cmd_list())
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.deploy.deploy_utils import deploy_frontend
|
|
3
|
+
from adam.config import Config
|
|
4
|
+
from adam.repl_state import ReplState, RequiredState
|
|
5
|
+
from adam.utils import log2
|
|
6
|
+
|
|
7
|
+
class DeployFrontend(Command):
|
|
8
|
+
COMMAND = 'deploy frontend'
|
|
9
|
+
|
|
10
|
+
# the singleton pattern
|
|
11
|
+
def __new__(cls, *args, **kwargs):
|
|
12
|
+
if not hasattr(cls, 'instance'): cls.instance = super(DeployFrontend, cls).__new__(cls)
|
|
13
|
+
|
|
14
|
+
return cls.instance
|
|
15
|
+
|
|
16
|
+
def __init__(self, successor: Command=None):
|
|
17
|
+
super().__init__(successor)
|
|
18
|
+
|
|
19
|
+
def command(self):
|
|
20
|
+
return DeployFrontend.COMMAND
|
|
21
|
+
|
|
22
|
+
def required(self):
|
|
23
|
+
return RequiredState.NAMESPACE
|
|
24
|
+
|
|
25
|
+
def run(self, cmd: str, state: ReplState):
|
|
26
|
+
if not(args := self.args(cmd)):
|
|
27
|
+
return super().run(cmd, state)
|
|
28
|
+
|
|
29
|
+
state, args = self.apply_state(args, state)
|
|
30
|
+
if not self.validate_state(state):
|
|
31
|
+
return state
|
|
32
|
+
|
|
33
|
+
log2('This will support c3/c3 only for demo.')
|
|
34
|
+
|
|
35
|
+
pod_name = Config().get('pod.name', 'ops')
|
|
36
|
+
label_selector = Config().get('pod.label-selector', 'run=ops')
|
|
37
|
+
try:
|
|
38
|
+
uri = deploy_frontend(pod_name, state.namespace, label_selector)
|
|
39
|
+
log2(f'Ops pod is available at {uri}.')
|
|
40
|
+
except Exception as e:
|
|
41
|
+
if e.status == 409:
|
|
42
|
+
log2(f"Error: '{pod_name}' already exists in namespace '{state.namespace}'.")
|
|
43
|
+
else:
|
|
44
|
+
log2(f"Error creating ingress or service: {e}")
|
|
45
|
+
|
|
46
|
+
return state
|
|
47
|
+
|
|
48
|
+
def completion(self, state: ReplState):
|
|
49
|
+
return super().completion(state)
|
|
50
|
+
|
|
51
|
+
def help(self, _: ReplState):
|
|
52
|
+
return f'{DeployFrontend.COMMAND}\t deploy Web frontend'
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.postgres.postgres_context import PostgresContext
|
|
3
|
+
from adam.config import Config
|
|
4
|
+
from adam.repl_state import ReplState, RequiredState
|
|
5
|
+
|
|
6
|
+
class DeployPgAgent(Command):
|
|
7
|
+
COMMAND = 'deploy pg-agent'
|
|
8
|
+
|
|
9
|
+
# the singleton pattern
|
|
10
|
+
def __new__(cls, *args, **kwargs):
|
|
11
|
+
if not hasattr(cls, 'instance'): cls.instance = super(DeployPgAgent, cls).__new__(cls)
|
|
12
|
+
|
|
13
|
+
return cls.instance
|
|
14
|
+
|
|
15
|
+
def __init__(self, successor: Command=None):
|
|
16
|
+
super().__init__(successor)
|
|
17
|
+
|
|
18
|
+
def command(self):
|
|
19
|
+
return DeployPgAgent.COMMAND
|
|
20
|
+
|
|
21
|
+
def required(self):
|
|
22
|
+
return RequiredState.NAMESPACE
|
|
23
|
+
|
|
24
|
+
def run(self, cmd: str, state: ReplState):
|
|
25
|
+
if not(args := self.args(cmd)):
|
|
26
|
+
return super().run(cmd, state)
|
|
27
|
+
|
|
28
|
+
state, args = self.apply_state(args, state)
|
|
29
|
+
if not self.validate_state(state):
|
|
30
|
+
return state
|
|
31
|
+
|
|
32
|
+
PostgresContext.deploy_pg_agent(Config().get('pg.agent.name', 'ops-pg-agent'), state.namespace)
|
|
33
|
+
|
|
34
|
+
def completion(self, state: ReplState):
|
|
35
|
+
return super().completion(state)
|
|
36
|
+
|
|
37
|
+
def help(self, _: ReplState):
|
|
38
|
+
return f'{DeployPgAgent.COMMAND}\t deploy Postgres agent'
|