kaqing 2.0.110__py3-none-any.whl → 2.0.184__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of kaqing might be problematic. Click here for more details.
- adam/__init__.py +0 -2
- adam/app_session.py +9 -12
- adam/apps.py +18 -4
- adam/batch.py +5 -5
- 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/alter_tables.py +33 -48
- adam/commands/app/__init__.py +0 -0
- adam/commands/app/app.py +38 -0
- adam/commands/{app_ping.py → app/app_ping.py} +7 -13
- 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/utils_app.py +98 -0
- adam/commands/audit/audit.py +27 -31
- adam/commands/audit/audit_repair_tables.py +14 -18
- adam/commands/audit/audit_run.py +16 -23
- adam/commands/audit/show_last10.py +4 -17
- 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/cat.py +36 -0
- adam/commands/cd.py +11 -95
- adam/commands/check.py +15 -24
- adam/commands/cli_commands.py +2 -3
- adam/commands/clipboard_copy.py +86 -0
- adam/commands/code.py +57 -0
- adam/commands/command.py +198 -40
- adam/commands/commands_utils.py +12 -27
- adam/commands/cql/cql_completions.py +27 -10
- adam/commands/cql/cqlsh.py +12 -30
- adam/commands/cql/utils_cql.py +297 -0
- adam/commands/deploy/code_start.py +7 -10
- adam/commands/deploy/code_stop.py +4 -21
- adam/commands/deploy/code_utils.py +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 +123 -0
- adam/commands/devices/device_app.py +163 -0
- adam/commands/devices/device_auit_log.py +49 -0
- adam/commands/devices/device_cass.py +179 -0
- adam/commands/devices/device_export.py +84 -0
- adam/commands/devices/device_postgres.py +150 -0
- adam/commands/devices/devices.py +25 -0
- adam/commands/download_file.py +47 -0
- adam/commands/exit.py +1 -4
- adam/commands/export/__init__.py +0 -0
- adam/commands/export/clean_up_all_export_sessions.py +37 -0
- adam/commands/export/clean_up_export_sessions.py +39 -0
- adam/commands/export/download_export_session.py +39 -0
- adam/commands/export/drop_export_database.py +39 -0
- adam/commands/export/drop_export_databases.py +37 -0
- adam/commands/export/export.py +53 -0
- adam/commands/export/export_databases.py +245 -0
- adam/commands/export/export_select.py +59 -0
- adam/commands/export/export_select_x.py +54 -0
- adam/commands/export/export_sessions.py +209 -0
- adam/commands/export/export_use.py +49 -0
- adam/commands/export/exporter.py +332 -0
- adam/commands/export/import_files.py +44 -0
- adam/commands/export/import_session.py +44 -0
- adam/commands/export/importer.py +81 -0
- adam/commands/export/importer_athena.py +177 -0
- adam/commands/export/importer_sqlite.py +67 -0
- adam/commands/export/show_column_counts.py +45 -0
- adam/commands/export/show_export_databases.py +38 -0
- adam/commands/export/show_export_session.py +39 -0
- adam/commands/export/show_export_sessions.py +37 -0
- adam/commands/export/utils_export.py +343 -0
- adam/commands/find_files.py +51 -0
- adam/commands/find_processes.py +76 -0
- adam/commands/head.py +36 -0
- adam/commands/help.py +5 -3
- adam/commands/intermediate_command.py +49 -0
- adam/commands/issues.py +11 -43
- adam/commands/kubectl.py +38 -0
- adam/commands/login.py +22 -24
- adam/commands/logs.py +3 -6
- adam/commands/ls.py +11 -116
- adam/commands/medusa/medusa.py +4 -22
- adam/commands/medusa/medusa_backup.py +20 -27
- adam/commands/medusa/medusa_restore.py +38 -37
- adam/commands/medusa/medusa_show_backupjobs.py +16 -18
- adam/commands/medusa/medusa_show_restorejobs.py +13 -18
- adam/commands/nodetool.py +11 -17
- adam/commands/param_get.py +11 -14
- adam/commands/param_set.py +8 -12
- adam/commands/postgres/postgres.py +45 -46
- adam/commands/postgres/postgres_databases.py +269 -0
- adam/commands/postgres/postgres_ls.py +4 -8
- adam/commands/postgres/postgres_preview.py +5 -9
- adam/commands/postgres/psql_completions.py +4 -3
- adam/commands/postgres/utils_postgres.py +70 -0
- adam/commands/preview_table.py +8 -44
- adam/commands/pwd.py +14 -46
- 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 +9 -32
- adam/commands/reaper/reaper_schedule_start.py +9 -32
- adam/commands/reaper/reaper_schedule_stop.py +9 -32
- adam/commands/reaper/reaper_schedules.py +4 -14
- adam/commands/reaper/reaper_status.py +8 -16
- adam/commands/reaper/utils_reaper.py +194 -0
- adam/commands/repair/repair.py +4 -22
- adam/commands/repair/repair_log.py +5 -11
- adam/commands/repair/repair_run.py +27 -34
- adam/commands/repair/repair_scan.py +32 -38
- adam/commands/repair/repair_stop.py +5 -11
- adam/commands/report.py +27 -29
- adam/commands/restart.py +25 -26
- adam/commands/rollout.py +19 -24
- adam/commands/shell.py +12 -4
- adam/commands/show/show.py +10 -25
- adam/commands/show/show_adam.py +3 -3
- adam/commands/show/show_cassandra_repairs.py +35 -0
- adam/commands/show/show_cassandra_status.py +33 -51
- adam/commands/show/show_cassandra_version.py +5 -18
- adam/commands/show/show_commands.py +20 -25
- adam/commands/show/show_host.py +1 -1
- adam/commands/show/show_login.py +20 -27
- adam/commands/show/show_params.py +2 -5
- adam/commands/show/show_processes.py +15 -19
- adam/commands/show/show_storage.py +10 -20
- adam/commands/watch.py +26 -29
- adam/config.py +5 -14
- adam/embedded_params.py +1 -1
- adam/log.py +4 -4
- adam/pod_exec_result.py +6 -3
- adam/repl.py +69 -115
- adam/repl_commands.py +52 -19
- adam/repl_state.py +161 -40
- 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 +3 -5
- adam/sso/idp.py +9 -12
- adam/utils.py +511 -9
- adam/utils_athena.py +145 -0
- adam/utils_audits.py +12 -103
- adam/utils_issues.py +32 -0
- adam/utils_k8s/app_clusters.py +28 -0
- adam/utils_k8s/app_pods.py +36 -0
- adam/utils_k8s/cassandra_clusters.py +30 -19
- adam/utils_k8s/cassandra_nodes.py +3 -3
- 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 +87 -0
- adam/utils_k8s/kube_context.py +2 -2
- adam/utils_k8s/pods.py +89 -78
- 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 +1 -12
- adam/utils_local.py +4 -0
- adam/utils_net.py +4 -4
- adam/utils_repl/__init__.py +0 -0
- adam/utils_repl/automata_completer.py +48 -0
- adam/utils_repl/repl_completer.py +46 -0
- adam/utils_repl/state_machine.py +173 -0
- adam/utils_sqlite.py +137 -0
- adam/version.py +1 -1
- {kaqing-2.0.110.dist-info → kaqing-2.0.184.dist-info}/METADATA +1 -1
- kaqing-2.0.184.dist-info/RECORD +244 -0
- adam/commands/app.py +0 -67
- adam/commands/bash.py +0 -150
- adam/commands/cp.py +0 -95
- adam/commands/cql/cql_utils.py +0 -112
- adam/commands/devices.py +0 -118
- adam/commands/postgres/postgres_context.py +0 -239
- adam/commands/postgres/postgres_utils.py +0 -31
- adam/commands/reaper/reaper_session.py +0 -159
- adam/commands/show/show_app_actions.py +0 -56
- adam/commands/show/show_repairs.py +0 -47
- kaqing-2.0.110.dist-info/RECORD +0 -187
- {kaqing-2.0.110.dist-info → kaqing-2.0.184.dist-info}/WHEEL +0 -0
- {kaqing-2.0.110.dist-info → kaqing-2.0.184.dist-info}/entry_points.txt +0 -0
- {kaqing-2.0.110.dist-info → kaqing-2.0.184.dist-info}/top_level.txt +0 -0
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import functools
|
|
2
|
-
import re
|
|
3
|
-
import subprocess
|
|
4
|
-
|
|
5
|
-
from adam.config import Config
|
|
6
|
-
from adam.utils_k8s.kube_context import KubeContext
|
|
7
|
-
from adam.utils_k8s.pods import Pods
|
|
8
|
-
from adam.utils_k8s.secrets import Secrets
|
|
9
|
-
from adam.utils import log2
|
|
10
|
-
|
|
11
|
-
class PostgresContext:
|
|
12
|
-
def apply(namespace: str, path: str, arg: str = None) -> 'PostgresContext':
|
|
13
|
-
context = PostgresContext(namespace, path)
|
|
14
|
-
|
|
15
|
-
if arg:
|
|
16
|
-
if arg == '..':
|
|
17
|
-
if context.db:
|
|
18
|
-
context.db = None
|
|
19
|
-
else:
|
|
20
|
-
context.host = None
|
|
21
|
-
else:
|
|
22
|
-
tks = arg.split('@')
|
|
23
|
-
if not context.host:
|
|
24
|
-
context.host = tks[0]
|
|
25
|
-
else:
|
|
26
|
-
context.db = tks[0]
|
|
27
|
-
|
|
28
|
-
if not namespace and tks[1]:
|
|
29
|
-
context.namespace = tks[1]
|
|
30
|
-
|
|
31
|
-
return context
|
|
32
|
-
|
|
33
|
-
def __init__(self, ns: str, path: str):
|
|
34
|
-
self.namespace = ns
|
|
35
|
-
self.conn_details = None
|
|
36
|
-
self.host = None
|
|
37
|
-
self.db = None
|
|
38
|
-
|
|
39
|
-
if path:
|
|
40
|
-
tks = path.split('/')
|
|
41
|
-
hn = tks[0].split('@')
|
|
42
|
-
self.host = hn[0]
|
|
43
|
-
if len(hn) > 1 and not ns:
|
|
44
|
-
self.namespace = hn[1]
|
|
45
|
-
|
|
46
|
-
if len(tks) > 1:
|
|
47
|
-
self.db = tks[1]
|
|
48
|
-
|
|
49
|
-
def path(self):
|
|
50
|
-
if not self.host:
|
|
51
|
-
return None
|
|
52
|
-
|
|
53
|
-
d = self.host
|
|
54
|
-
if not self.db:
|
|
55
|
-
return d
|
|
56
|
-
|
|
57
|
-
return f'{self.host}/{self.db}'
|
|
58
|
-
|
|
59
|
-
def hosts(ns: str):
|
|
60
|
-
return PostgresContext.hosts_for_namespace(ns)
|
|
61
|
-
|
|
62
|
-
@functools.lru_cache()
|
|
63
|
-
def hosts_for_namespace(ns: str):
|
|
64
|
-
ss = Secrets.list_secrets(ns, name_pattern=Config().get('pg.name-pattern', '^{namespace}.*k8spg.*'))
|
|
65
|
-
|
|
66
|
-
def excludes(name: str):
|
|
67
|
-
exs = Config().get('pg.excludes', '.helm., -admin-secret')
|
|
68
|
-
if exs:
|
|
69
|
-
for ex in exs.split(','):
|
|
70
|
-
if ex.strip(' ') in name:
|
|
71
|
-
return True
|
|
72
|
-
|
|
73
|
-
return False
|
|
74
|
-
|
|
75
|
-
return [s for s in ss if not excludes(s)]
|
|
76
|
-
|
|
77
|
-
def databases(self):
|
|
78
|
-
dbs = []
|
|
79
|
-
# List of databases
|
|
80
|
-
# Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges
|
|
81
|
-
# ---------------------------------------+----------+----------+-------------+-------------+------------+-----------------+-----------------------
|
|
82
|
-
# postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
|
|
83
|
-
# stgawsscpsr_c3_c3 | postgres | UTF8 | C | C | | libc |
|
|
84
|
-
# template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc | =c/postgres +
|
|
85
|
-
# | | | | | | | postgres=CTc/postgres
|
|
86
|
-
# (48 rows)
|
|
87
|
-
if r := self.run_sql('\l', show_out=False):
|
|
88
|
-
s = 0
|
|
89
|
-
for line in r.stdout.split('\n'):
|
|
90
|
-
line: str = line.strip(' \r')
|
|
91
|
-
if s == 0:
|
|
92
|
-
if 'List of databases' in line:
|
|
93
|
-
s = 1
|
|
94
|
-
elif s == 1:
|
|
95
|
-
if 'Name' in line and 'Owner' in line and 'Encoding' in line:
|
|
96
|
-
s = 2
|
|
97
|
-
elif s == 2:
|
|
98
|
-
if line.startswith('---------'):
|
|
99
|
-
s = 3
|
|
100
|
-
elif s == 3:
|
|
101
|
-
groups = re.match(r'^\s*(\S*)\s*\|\s*(\S*)\s*\|.*', line)
|
|
102
|
-
if groups and groups[1] != '|':
|
|
103
|
-
dbs.append({'name': groups[1], 'owner': groups[2]})
|
|
104
|
-
|
|
105
|
-
return dbs
|
|
106
|
-
|
|
107
|
-
def tables(self):
|
|
108
|
-
dbs = []
|
|
109
|
-
# List of relations
|
|
110
|
-
# Schema | Name | Type | Owner
|
|
111
|
-
# ----------+------------------------------------------------------------+-------+---------------
|
|
112
|
-
# postgres | c3_2_admin_aclpriv | table | postgres
|
|
113
|
-
# postgres | c3_2_admin_aclpriv_a | table | postgres
|
|
114
|
-
if r := self.run_sql('\dt', show_out=False):
|
|
115
|
-
s = 0
|
|
116
|
-
for line in r.stdout.split('\n'):
|
|
117
|
-
line: str = line.strip(' \r')
|
|
118
|
-
if s == 0:
|
|
119
|
-
if 'List of relations' in line:
|
|
120
|
-
s = 1
|
|
121
|
-
elif s == 1:
|
|
122
|
-
if 'Schema' in line and 'Name' in line and 'Type' in line:
|
|
123
|
-
s = 2
|
|
124
|
-
elif s == 2:
|
|
125
|
-
if line.startswith('---------'):
|
|
126
|
-
s = 3
|
|
127
|
-
elif s == 3:
|
|
128
|
-
groups = re.match(r'^\s*(\S*)\s*\|\s*(\S*)\s*\|.*', line)
|
|
129
|
-
if groups and groups[1] != '|':
|
|
130
|
-
dbs.append({'schema': groups[1], 'name': groups[2]})
|
|
131
|
-
|
|
132
|
-
return dbs
|
|
133
|
-
|
|
134
|
-
def run_sql(self, sql: str, show_out = True):
|
|
135
|
-
db = self.db if self.db else PostgresContext.default_db()
|
|
136
|
-
|
|
137
|
-
if KubeContext.in_cluster():
|
|
138
|
-
cmd1 = f'env PGPASSWORD={self.password()} psql -h {self.endpoint()} -p {self.port()} -U {self.username()} {db} --pset pager=off -c'
|
|
139
|
-
log2(f'{cmd1} "{sql}"')
|
|
140
|
-
# remove double quotes from the sql argument
|
|
141
|
-
cmd = cmd1.split(' ') + [sql]
|
|
142
|
-
r = subprocess.run(cmd, capture_output=True, text=True)
|
|
143
|
-
if show_out:
|
|
144
|
-
log2(r.stdout)
|
|
145
|
-
log2(r.stderr)
|
|
146
|
-
|
|
147
|
-
return r
|
|
148
|
-
else:
|
|
149
|
-
ns = self.namespace
|
|
150
|
-
pod_name = Config().get('pg.agent.name', 'ops-pg-agent')
|
|
151
|
-
|
|
152
|
-
if Config().get('pg.agent.just-in-time', False):
|
|
153
|
-
if not PostgresContext.deploy_pg_agent(pod_name, ns):
|
|
154
|
-
return
|
|
155
|
-
|
|
156
|
-
real_pod_name = pod_name
|
|
157
|
-
try:
|
|
158
|
-
# try with dedicated pg agent pod name configured
|
|
159
|
-
Pods.get(ns, pod_name)
|
|
160
|
-
except:
|
|
161
|
-
try:
|
|
162
|
-
# try with the ops pod
|
|
163
|
-
pod_name = Config().get('pod.name', 'ops')
|
|
164
|
-
real_pod_name = Pods.get_with_selector(ns, label_selector = Config().get('pod.label-selector', 'run=ops')).metadata.name
|
|
165
|
-
except:
|
|
166
|
-
log2(f"Could not locate {pod_name} pod.")
|
|
167
|
-
return None
|
|
168
|
-
|
|
169
|
-
cmd = f'PGPASSWORD="{self.password()}" psql -h {self.endpoint()} -p {self.port()} -U {self.username()} {db} --pset pager=off -c "{sql}"'
|
|
170
|
-
|
|
171
|
-
return Pods.exec(real_pod_name, pod_name, ns, cmd, show_out=show_out)
|
|
172
|
-
|
|
173
|
-
def deploy_pg_agent(pod_name: str, ns: str) -> str:
|
|
174
|
-
image = Config().get('pg.agent.image', 'seanahnsf/kaqing')
|
|
175
|
-
timeout = Config().get('pg.agent.timeout', 3600)
|
|
176
|
-
try:
|
|
177
|
-
Pods.create(ns, pod_name, image, ['sleep', f'{timeout}'], env={'NAMESPACE': ns}, sa_name='c3')
|
|
178
|
-
except Exception as e:
|
|
179
|
-
if e.status == 409:
|
|
180
|
-
if Pods.completed(ns, pod_name):
|
|
181
|
-
try:
|
|
182
|
-
Pods.delete(pod_name, ns)
|
|
183
|
-
Pods.create(ns, pod_name, image, ['sleep', f'{timeout}'], env={'NAMESPACE': ns}, sa_name='c3')
|
|
184
|
-
except Exception as e2:
|
|
185
|
-
log2("Exception when calling BatchV1Api->create_pod: %s\n" % e2)
|
|
186
|
-
|
|
187
|
-
return
|
|
188
|
-
else:
|
|
189
|
-
log2("Exception when calling BatchV1Api->create_pod: %s\n" % e)
|
|
190
|
-
|
|
191
|
-
return
|
|
192
|
-
|
|
193
|
-
Pods.wait_for_running(ns, pod_name)
|
|
194
|
-
|
|
195
|
-
return pod_name
|
|
196
|
-
|
|
197
|
-
def undeploy_pg_agent(pod_name: str, ns: str):
|
|
198
|
-
Pods.delete(pod_name, ns, grace_period_seconds=0)
|
|
199
|
-
|
|
200
|
-
def endpoint(self):
|
|
201
|
-
if not self.conn_details:
|
|
202
|
-
self.conn_details = Secrets.get_data(self.namespace, self.host)
|
|
203
|
-
|
|
204
|
-
endpoint_key = Config().get('pg.secret.endpoint-key', 'postgres-db-endpoint')
|
|
205
|
-
|
|
206
|
-
return self.conn_details[endpoint_key] if endpoint_key in self.conn_details else ''
|
|
207
|
-
|
|
208
|
-
def port(self):
|
|
209
|
-
if not self.conn_details:
|
|
210
|
-
self.conn_details = Secrets.get_data(self.namespace, self.host)
|
|
211
|
-
|
|
212
|
-
port_key = Config().get('pg.secret.port-key', 'postgres-db-port')
|
|
213
|
-
|
|
214
|
-
return self.conn_details[port_key] if port_key in self.conn_details else ''
|
|
215
|
-
|
|
216
|
-
def username(self):
|
|
217
|
-
if not self.conn_details:
|
|
218
|
-
self.conn_details = Secrets.get_data(self.namespace, self.host)
|
|
219
|
-
|
|
220
|
-
username_key = Config().get('pg.secret.username-key', 'postgres-admin-username')
|
|
221
|
-
|
|
222
|
-
return self.conn_details[username_key] if username_key in self.conn_details else ''
|
|
223
|
-
|
|
224
|
-
def password(self):
|
|
225
|
-
if not self.conn_details:
|
|
226
|
-
self.conn_details = Secrets.get_data(self.namespace, self.host)
|
|
227
|
-
|
|
228
|
-
password_key = Config().get('pg.secret.password-key', 'postgres-admin-password')
|
|
229
|
-
|
|
230
|
-
return self.conn_details[password_key] if password_key in self.conn_details else ''
|
|
231
|
-
|
|
232
|
-
def default_db():
|
|
233
|
-
return Config().get('pg.default-db', 'postgres')
|
|
234
|
-
|
|
235
|
-
def default_owner():
|
|
236
|
-
return Config().get('pg.default-owner', 'postgres')
|
|
237
|
-
|
|
238
|
-
def default_schema():
|
|
239
|
-
return Config().get('pg.default-schema', 'postgres')
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import functools
|
|
2
|
-
|
|
3
|
-
from adam.commands.postgres.postgres_context import PostgresContext
|
|
4
|
-
from adam.config import Config
|
|
5
|
-
|
|
6
|
-
TestPG = [False]
|
|
7
|
-
|
|
8
|
-
@functools.lru_cache()
|
|
9
|
-
def pg_database_names(ns: str, pg_path: str):
|
|
10
|
-
if TestPG[0]:
|
|
11
|
-
return ['azops88_c3ai_c3']
|
|
12
|
-
|
|
13
|
-
Config().wait_log('Inspecting Postgres Databases...')
|
|
14
|
-
|
|
15
|
-
pg = PostgresContext.apply(ns, pg_path)
|
|
16
|
-
return [db['name'] for db in pg.databases() if db['owner'] == PostgresContext.default_owner()]
|
|
17
|
-
|
|
18
|
-
@functools.lru_cache()
|
|
19
|
-
def pg_table_names(ns: str, pg_path: str):
|
|
20
|
-
if TestPG[0]:
|
|
21
|
-
return ['C3_2_XYZ1']
|
|
22
|
-
|
|
23
|
-
Config().wait_log('Inspecting Postgres Database...')
|
|
24
|
-
return [table['name'] for table in pg_tables(ns, pg_path) if table['schema'] == PostgresContext.default_schema()]
|
|
25
|
-
|
|
26
|
-
def pg_tables(ns: str, pg_path: str):
|
|
27
|
-
pg = PostgresContext.apply(ns, pg_path)
|
|
28
|
-
if pg.db:
|
|
29
|
-
return pg.tables()
|
|
30
|
-
|
|
31
|
-
return []
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
from collections.abc import Callable
|
|
2
|
-
import threading
|
|
3
|
-
from kubernetes import client
|
|
4
|
-
import portforward
|
|
5
|
-
import re
|
|
6
|
-
import requests
|
|
7
|
-
from typing import List, cast
|
|
8
|
-
|
|
9
|
-
from adam.config import Config
|
|
10
|
-
from adam.utils_k8s.kube_context import KubeContext
|
|
11
|
-
from adam.repl_state import ReplState
|
|
12
|
-
from adam.utils import lines_to_tabular, log2
|
|
13
|
-
|
|
14
|
-
class ReaperSession:
|
|
15
|
-
is_forwarding = False
|
|
16
|
-
stopping = threading.Event()
|
|
17
|
-
schedules_ids_by_cluster: dict[str, list[str]] = {}
|
|
18
|
-
|
|
19
|
-
def __init__(self, pod: str, headers: dict[str, str] = None):
|
|
20
|
-
self.pod = pod
|
|
21
|
-
self.headers = headers
|
|
22
|
-
|
|
23
|
-
def login(self, state: ReplState, local_addr: str, remote_addr: str, show_output = True) -> str :
|
|
24
|
-
user, pw = state.user_pass(secret_path='reaper.secret')
|
|
25
|
-
|
|
26
|
-
response = requests.post(f'http://{local_addr}/login', headers={
|
|
27
|
-
'Accept': '*'
|
|
28
|
-
},data={
|
|
29
|
-
'username':user,
|
|
30
|
-
'password':pw})
|
|
31
|
-
if show_output:
|
|
32
|
-
log2(f'POST {remote_addr}/login')
|
|
33
|
-
log2(f' username={user}&password={pw}')
|
|
34
|
-
|
|
35
|
-
if int(response.status_code / 100) != 2:
|
|
36
|
-
if show_output:
|
|
37
|
-
log2("login failed")
|
|
38
|
-
return None
|
|
39
|
-
|
|
40
|
-
return response.headers['Set-Cookie']
|
|
41
|
-
|
|
42
|
-
def port_forwarded(self, state: ReplState, path: str, body: Callable[[str, dict[str, str]], requests.Response], method: str = None, show_output = True):
|
|
43
|
-
local_port = Config().get('reaper.port-forward.local-port', 9001)
|
|
44
|
-
target_port = 8080
|
|
45
|
-
|
|
46
|
-
def f(local_addr: str, remote_addr: str):
|
|
47
|
-
if not self.headers:
|
|
48
|
-
self.headers = self.cookie_header(state, local_addr, remote_addr, show_output=show_output)
|
|
49
|
-
|
|
50
|
-
if show_output and method:
|
|
51
|
-
log2(f'{method} {remote_addr}/{path}')
|
|
52
|
-
response = body(f'http://{local_addr}/{path}', self.headers)
|
|
53
|
-
|
|
54
|
-
if response:
|
|
55
|
-
if int(response.status_code / 100) != 2:
|
|
56
|
-
if show_output:
|
|
57
|
-
log2(response.status_code)
|
|
58
|
-
return response
|
|
59
|
-
|
|
60
|
-
if show_output:
|
|
61
|
-
log2()
|
|
62
|
-
|
|
63
|
-
return response if response else 'no-response'
|
|
64
|
-
|
|
65
|
-
if KubeContext.in_cluster():
|
|
66
|
-
# cs-a526330d23-cs-a526330d23-default-sts-0 ->
|
|
67
|
-
# curl http://cs-a526330d23-cs-a526330d23-reaper-service.stgawsscpsr.svc.cluster.local:8080
|
|
68
|
-
groups = re.match(r'^(.*?-.*?-.*?-.*?-).*', state.sts)
|
|
69
|
-
if groups:
|
|
70
|
-
svc_name = Config().get('reaper.service-name', 'reaper-service')
|
|
71
|
-
svc = f'{groups[1]}{svc_name}.{state.namespace}.svc.cluster.local:{target_port}'
|
|
72
|
-
return f(local_addr=svc, remote_addr=svc)
|
|
73
|
-
else:
|
|
74
|
-
return None
|
|
75
|
-
else:
|
|
76
|
-
with portforward.forward(state.namespace, self.pod, local_port, target_port):
|
|
77
|
-
return f(local_addr=f'localhost:{local_port}', remote_addr=f'{self.pod}:{target_port}')
|
|
78
|
-
|
|
79
|
-
def cookie_header(self, state: ReplState, local_addr, remote_addr, show_output = True):
|
|
80
|
-
return {'Cookie': self.login(state, local_addr, remote_addr, show_output=show_output)}
|
|
81
|
-
|
|
82
|
-
def create(state: ReplState) -> 'ReaperSession':
|
|
83
|
-
pods = ReaperSession.list_reaper_pods(state.sts if state.sts else state.pod, state.namespace)
|
|
84
|
-
if pods:
|
|
85
|
-
return ReaperSession(pods[0].metadata.name)
|
|
86
|
-
else:
|
|
87
|
-
log2('No reaper found.')
|
|
88
|
-
|
|
89
|
-
return None
|
|
90
|
-
|
|
91
|
-
def list_reaper_pods(sts_name: str, namespace: str) -> List[client.V1Pod]:
|
|
92
|
-
v1 = client.CoreV1Api()
|
|
93
|
-
|
|
94
|
-
# k8ssandra.io/reaper: cs-d0767a536f-cs-d0767a536f-reaper
|
|
95
|
-
groups = re.match(Config().get('reaper.pod.cluster-regex', r'(.*?-.*?-.*?-.*?)-.*'), sts_name)
|
|
96
|
-
label_selector = Config().get('reaper.pod.label-selector', 'k8ssandra.io/reaper={cluster}-reaper').replace('{cluster}', groups[1])
|
|
97
|
-
|
|
98
|
-
return cast(List[client.V1Pod], v1.list_namespaced_pod(namespace, label_selector=label_selector).items)
|
|
99
|
-
|
|
100
|
-
def show_schedules(self, state: ReplState, filter: Callable[[list[dict]], dict] = None):
|
|
101
|
-
schedules = self.list_schedules(state, filter=filter)
|
|
102
|
-
# forced refresh of schedule list
|
|
103
|
-
if not filter:
|
|
104
|
-
self.schedules_ids_by_cluster[state.sts] = [schedule['id'] for schedule in schedules]
|
|
105
|
-
self.show_schedules_tabular(schedules)
|
|
106
|
-
|
|
107
|
-
def schedule_ids(self, state: ReplState, show_output = True, filter: Callable[[list[dict]], dict] = None):
|
|
108
|
-
schedules = self.list_schedules(state, show_output=show_output, filter=filter)
|
|
109
|
-
return [schedule['id'] for schedule in schedules]
|
|
110
|
-
|
|
111
|
-
def list_schedules(self, state: ReplState, show_output = True, filter: Callable[[list[dict]], dict] = None) -> list[dict]:
|
|
112
|
-
def body(uri: str, headers: dict[str, str]):
|
|
113
|
-
return requests.get(uri, headers=headers)
|
|
114
|
-
|
|
115
|
-
response = self.port_forwarded(state, 'repair_schedule', body, method='GET', show_output=show_output)
|
|
116
|
-
if not response:
|
|
117
|
-
return
|
|
118
|
-
|
|
119
|
-
res = response.json()
|
|
120
|
-
if filter:
|
|
121
|
-
res = filter(res)
|
|
122
|
-
|
|
123
|
-
return res
|
|
124
|
-
|
|
125
|
-
def show_schedules_tabular(self, schedules: list[dict]):
|
|
126
|
-
log2(lines_to_tabular([f"{schedule['id']} {schedule['state']} {schedule['cluster_name']} {schedule['keyspace_name']}" for schedule in schedules], 'ID STATE CLUSTER KEYSPACE'))
|
|
127
|
-
|
|
128
|
-
def show_schedule(self, state: ReplState, schedule_id: str):
|
|
129
|
-
def filter(schedules: list[dict]):
|
|
130
|
-
return [schedule for schedule in schedules if schedule['id'] == schedule_id]
|
|
131
|
-
|
|
132
|
-
self.show_schedules(state, filter)
|
|
133
|
-
|
|
134
|
-
def reaper_spec(self, state: ReplState) -> dict[str, any]:
|
|
135
|
-
user, pw = state.user_pass(secret_path='reaper.secret')
|
|
136
|
-
local_port = Config().get('reaper.port-forward.local-port', 9001)
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
'pod': self.pod,
|
|
140
|
-
'exec': f'kubectl exec -it {self.pod} -n {state.namespace} -- bash',
|
|
141
|
-
'forward': f'kubectl port-forward pods/{self.pod} -n {state.namespace} {local_port}:8080',
|
|
142
|
-
'web-uri': f'http://localhost:{local_port}/webui',
|
|
143
|
-
'username': user,
|
|
144
|
-
'password': pw
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
def cached_schedule_ids(state: ReplState) -> list[str]:
|
|
148
|
-
if state.sts in ReaperSession.schedules_ids_by_cluster:
|
|
149
|
-
return ReaperSession.schedules_ids_by_cluster[state.sts]
|
|
150
|
-
|
|
151
|
-
if reaper := ReaperSession.create(state):
|
|
152
|
-
Config().wait_log('Inspecting Cassandra Reaper...')
|
|
153
|
-
|
|
154
|
-
schedules = reaper.schedule_ids(state, show_output = False)
|
|
155
|
-
ReaperSession.schedules_ids_by_cluster[state.sts] = schedules
|
|
156
|
-
|
|
157
|
-
return schedules
|
|
158
|
-
|
|
159
|
-
return []
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
from adam.app_session import AppSession
|
|
2
|
-
from adam.apps import AppAction, Apps
|
|
3
|
-
from adam.commands.command import Command
|
|
4
|
-
from adam.config import Config
|
|
5
|
-
from adam.repl_state import ReplState
|
|
6
|
-
from adam.utils import lines_to_tabular, 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 self.args(cmd):
|
|
28
|
-
return super().run(cmd, state)
|
|
29
|
-
|
|
30
|
-
lines = []
|
|
31
|
-
for typ in Apps().app_types():
|
|
32
|
-
for action in typ.actions:
|
|
33
|
-
a: AppAction = action
|
|
34
|
-
args = ','.join(a.arguments())
|
|
35
|
-
if args:
|
|
36
|
-
line = f'{typ.name}.{a.name},{args}'
|
|
37
|
-
else:
|
|
38
|
-
line = f'{typ.name}.{a.name},'
|
|
39
|
-
if a.help:
|
|
40
|
-
line = f'{line},{a.help}'
|
|
41
|
-
lines.append(line)
|
|
42
|
-
log(lines_to_tabular(lines, 'ACTION,ARGS,DESCRIPTION', separator=','))
|
|
43
|
-
log()
|
|
44
|
-
|
|
45
|
-
app_session: AppSession = AppSession.create(state.app_env or 'c3', state.app_app or 'c3')
|
|
46
|
-
endpoint = Config().get('app.console-endpoint', 'https://{host}/{env}/{app}/static/console/index.html')
|
|
47
|
-
endpoint = endpoint.replace('{host}', app_session.host).replace('{env}', app_session.env).replace('{app}', state.app_app or 'c3')
|
|
48
|
-
log(lines_to_tabular([f'CONSOLE:,{endpoint}'], separator=','))
|
|
49
|
-
|
|
50
|
-
return lines
|
|
51
|
-
|
|
52
|
-
def completion(self, state: ReplState):
|
|
53
|
-
return super().completion(state)
|
|
54
|
-
|
|
55
|
-
def help(self, _: ReplState):
|
|
56
|
-
return f"{ShowAppActions.COMMAND}\t show app actions"
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
from adam.commands.command import Command
|
|
2
|
-
from adam.utils_k8s.cassandra_clusters import CassandraClusters
|
|
3
|
-
from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
4
|
-
from adam.repl_state import ReplState, RequiredState
|
|
5
|
-
|
|
6
|
-
class ShowRepairs(Command):
|
|
7
|
-
COMMAND = 'show cassandra repairs'
|
|
8
|
-
|
|
9
|
-
# the singleton pattern
|
|
10
|
-
def __new__(cls, *args, **kwargs):
|
|
11
|
-
if not hasattr(cls, 'instance'): cls.instance = super(ShowRepairs, 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 ShowRepairs.COMMAND
|
|
20
|
-
|
|
21
|
-
def required(self):
|
|
22
|
-
return RequiredState.CLUSTER_OR_POD
|
|
23
|
-
|
|
24
|
-
def run(self, cmd: str, state: ReplState):
|
|
25
|
-
if not(args := self.args(cmd)):
|
|
26
|
-
return super().run(cmd, state)
|
|
27
|
-
|
|
28
|
-
state, _ = state.apply_args(args)
|
|
29
|
-
if not self.validate_state(state):
|
|
30
|
-
return state
|
|
31
|
-
|
|
32
|
-
user, pw = state.user_pass()
|
|
33
|
-
command = f"nodetool -u {user} -pw {pw} repair_admin list"
|
|
34
|
-
|
|
35
|
-
if state.pod:
|
|
36
|
-
return CassandraNodes.exec(state.pod, state.namespace, command)
|
|
37
|
-
else:
|
|
38
|
-
return CassandraClusters.exec(state.sts, state.namespace, command, action='nodetool')
|
|
39
|
-
|
|
40
|
-
def completion(self, state: ReplState):
|
|
41
|
-
if state.sts:
|
|
42
|
-
return super().completion(state)
|
|
43
|
-
|
|
44
|
-
return {}
|
|
45
|
-
|
|
46
|
-
def help(self, _: ReplState):
|
|
47
|
-
return f'{ShowRepairs.COMMAND}\t show Cassandra repairs'
|