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.

Files changed (204) hide show
  1. adam/__init__.py +0 -2
  2. adam/app_session.py +9 -12
  3. adam/apps.py +18 -4
  4. adam/batch.py +5 -5
  5. adam/checks/check_utils.py +16 -46
  6. adam/checks/cpu.py +7 -1
  7. adam/checks/cpu_metrics.py +52 -0
  8. adam/checks/disk.py +2 -3
  9. adam/columns/columns.py +3 -1
  10. adam/columns/cpu.py +3 -1
  11. adam/columns/cpu_metrics.py +22 -0
  12. adam/columns/memory.py +3 -4
  13. adam/commands/__init__.py +24 -0
  14. adam/commands/alter_tables.py +33 -48
  15. adam/commands/app/__init__.py +0 -0
  16. adam/commands/app/app.py +38 -0
  17. adam/commands/{app_ping.py → app/app_ping.py} +7 -13
  18. adam/commands/app/show_app_actions.py +49 -0
  19. adam/commands/{show → app}/show_app_id.py +8 -11
  20. adam/commands/{show → app}/show_app_queues.py +7 -14
  21. adam/commands/app/utils_app.py +98 -0
  22. adam/commands/audit/audit.py +27 -31
  23. adam/commands/audit/audit_repair_tables.py +14 -18
  24. adam/commands/audit/audit_run.py +16 -23
  25. adam/commands/audit/show_last10.py +4 -17
  26. adam/commands/audit/show_slow10.py +4 -17
  27. adam/commands/audit/show_top10.py +4 -16
  28. adam/commands/audit/utils_show_top10.py +15 -3
  29. adam/commands/bash/__init__.py +5 -0
  30. adam/commands/bash/bash.py +36 -0
  31. adam/commands/bash/bash_completer.py +93 -0
  32. adam/commands/bash/utils_bash.py +16 -0
  33. adam/commands/cat.py +36 -0
  34. adam/commands/cd.py +11 -95
  35. adam/commands/check.py +15 -24
  36. adam/commands/cli_commands.py +2 -3
  37. adam/commands/clipboard_copy.py +86 -0
  38. adam/commands/code.py +57 -0
  39. adam/commands/command.py +198 -40
  40. adam/commands/commands_utils.py +12 -27
  41. adam/commands/cql/cql_completions.py +27 -10
  42. adam/commands/cql/cqlsh.py +12 -30
  43. adam/commands/cql/utils_cql.py +297 -0
  44. adam/commands/deploy/code_start.py +7 -10
  45. adam/commands/deploy/code_stop.py +4 -21
  46. adam/commands/deploy/code_utils.py +3 -3
  47. adam/commands/deploy/deploy.py +4 -27
  48. adam/commands/deploy/deploy_frontend.py +14 -17
  49. adam/commands/deploy/deploy_pg_agent.py +3 -6
  50. adam/commands/deploy/deploy_pod.py +65 -73
  51. adam/commands/deploy/deploy_utils.py +14 -24
  52. adam/commands/deploy/undeploy.py +4 -27
  53. adam/commands/deploy/undeploy_frontend.py +4 -7
  54. adam/commands/deploy/undeploy_pg_agent.py +6 -8
  55. adam/commands/deploy/undeploy_pod.py +11 -12
  56. adam/commands/devices/__init__.py +0 -0
  57. adam/commands/devices/device.py +123 -0
  58. adam/commands/devices/device_app.py +163 -0
  59. adam/commands/devices/device_auit_log.py +49 -0
  60. adam/commands/devices/device_cass.py +179 -0
  61. adam/commands/devices/device_export.py +84 -0
  62. adam/commands/devices/device_postgres.py +150 -0
  63. adam/commands/devices/devices.py +25 -0
  64. adam/commands/download_file.py +47 -0
  65. adam/commands/exit.py +1 -4
  66. adam/commands/export/__init__.py +0 -0
  67. adam/commands/export/clean_up_all_export_sessions.py +37 -0
  68. adam/commands/export/clean_up_export_sessions.py +39 -0
  69. adam/commands/export/download_export_session.py +39 -0
  70. adam/commands/export/drop_export_database.py +39 -0
  71. adam/commands/export/drop_export_databases.py +37 -0
  72. adam/commands/export/export.py +53 -0
  73. adam/commands/export/export_databases.py +245 -0
  74. adam/commands/export/export_select.py +59 -0
  75. adam/commands/export/export_select_x.py +54 -0
  76. adam/commands/export/export_sessions.py +209 -0
  77. adam/commands/export/export_use.py +49 -0
  78. adam/commands/export/exporter.py +332 -0
  79. adam/commands/export/import_files.py +44 -0
  80. adam/commands/export/import_session.py +44 -0
  81. adam/commands/export/importer.py +81 -0
  82. adam/commands/export/importer_athena.py +177 -0
  83. adam/commands/export/importer_sqlite.py +67 -0
  84. adam/commands/export/show_column_counts.py +45 -0
  85. adam/commands/export/show_export_databases.py +38 -0
  86. adam/commands/export/show_export_session.py +39 -0
  87. adam/commands/export/show_export_sessions.py +37 -0
  88. adam/commands/export/utils_export.py +343 -0
  89. adam/commands/find_files.py +51 -0
  90. adam/commands/find_processes.py +76 -0
  91. adam/commands/head.py +36 -0
  92. adam/commands/help.py +5 -3
  93. adam/commands/intermediate_command.py +49 -0
  94. adam/commands/issues.py +11 -43
  95. adam/commands/kubectl.py +38 -0
  96. adam/commands/login.py +22 -24
  97. adam/commands/logs.py +3 -6
  98. adam/commands/ls.py +11 -116
  99. adam/commands/medusa/medusa.py +4 -22
  100. adam/commands/medusa/medusa_backup.py +20 -27
  101. adam/commands/medusa/medusa_restore.py +38 -37
  102. adam/commands/medusa/medusa_show_backupjobs.py +16 -18
  103. adam/commands/medusa/medusa_show_restorejobs.py +13 -18
  104. adam/commands/nodetool.py +11 -17
  105. adam/commands/param_get.py +11 -14
  106. adam/commands/param_set.py +8 -12
  107. adam/commands/postgres/postgres.py +45 -46
  108. adam/commands/postgres/postgres_databases.py +269 -0
  109. adam/commands/postgres/postgres_ls.py +4 -8
  110. adam/commands/postgres/postgres_preview.py +5 -9
  111. adam/commands/postgres/psql_completions.py +4 -3
  112. adam/commands/postgres/utils_postgres.py +70 -0
  113. adam/commands/preview_table.py +8 -44
  114. adam/commands/pwd.py +14 -46
  115. adam/commands/reaper/reaper.py +4 -27
  116. adam/commands/reaper/reaper_forward.py +49 -56
  117. adam/commands/reaper/reaper_forward_session.py +6 -0
  118. adam/commands/reaper/reaper_forward_stop.py +10 -16
  119. adam/commands/reaper/reaper_restart.py +7 -14
  120. adam/commands/reaper/reaper_run_abort.py +8 -33
  121. adam/commands/reaper/reaper_runs.py +43 -58
  122. adam/commands/reaper/reaper_runs_abort.py +29 -49
  123. adam/commands/reaper/reaper_schedule_activate.py +9 -32
  124. adam/commands/reaper/reaper_schedule_start.py +9 -32
  125. adam/commands/reaper/reaper_schedule_stop.py +9 -32
  126. adam/commands/reaper/reaper_schedules.py +4 -14
  127. adam/commands/reaper/reaper_status.py +8 -16
  128. adam/commands/reaper/utils_reaper.py +194 -0
  129. adam/commands/repair/repair.py +4 -22
  130. adam/commands/repair/repair_log.py +5 -11
  131. adam/commands/repair/repair_run.py +27 -34
  132. adam/commands/repair/repair_scan.py +32 -38
  133. adam/commands/repair/repair_stop.py +5 -11
  134. adam/commands/report.py +27 -29
  135. adam/commands/restart.py +25 -26
  136. adam/commands/rollout.py +19 -24
  137. adam/commands/shell.py +12 -4
  138. adam/commands/show/show.py +10 -25
  139. adam/commands/show/show_adam.py +3 -3
  140. adam/commands/show/show_cassandra_repairs.py +35 -0
  141. adam/commands/show/show_cassandra_status.py +33 -51
  142. adam/commands/show/show_cassandra_version.py +5 -18
  143. adam/commands/show/show_commands.py +20 -25
  144. adam/commands/show/show_host.py +1 -1
  145. adam/commands/show/show_login.py +20 -27
  146. adam/commands/show/show_params.py +2 -5
  147. adam/commands/show/show_processes.py +15 -19
  148. adam/commands/show/show_storage.py +10 -20
  149. adam/commands/watch.py +26 -29
  150. adam/config.py +5 -14
  151. adam/embedded_params.py +1 -1
  152. adam/log.py +4 -4
  153. adam/pod_exec_result.py +6 -3
  154. adam/repl.py +69 -115
  155. adam/repl_commands.py +52 -19
  156. adam/repl_state.py +161 -40
  157. adam/sql/sql_completer.py +52 -27
  158. adam/sql/sql_state_machine.py +131 -19
  159. adam/sso/authn_ad.py +6 -8
  160. adam/sso/authn_okta.py +4 -6
  161. adam/sso/cred_cache.py +3 -5
  162. adam/sso/idp.py +9 -12
  163. adam/utils.py +511 -9
  164. adam/utils_athena.py +145 -0
  165. adam/utils_audits.py +12 -103
  166. adam/utils_issues.py +32 -0
  167. adam/utils_k8s/app_clusters.py +28 -0
  168. adam/utils_k8s/app_pods.py +36 -0
  169. adam/utils_k8s/cassandra_clusters.py +30 -19
  170. adam/utils_k8s/cassandra_nodes.py +3 -3
  171. adam/utils_k8s/custom_resources.py +16 -17
  172. adam/utils_k8s/ingresses.py +2 -2
  173. adam/utils_k8s/jobs.py +7 -11
  174. adam/utils_k8s/k8s.py +87 -0
  175. adam/utils_k8s/kube_context.py +2 -2
  176. adam/utils_k8s/pods.py +89 -78
  177. adam/utils_k8s/secrets.py +4 -4
  178. adam/utils_k8s/service_accounts.py +5 -4
  179. adam/utils_k8s/services.py +2 -2
  180. adam/utils_k8s/statefulsets.py +1 -12
  181. adam/utils_local.py +4 -0
  182. adam/utils_net.py +4 -4
  183. adam/utils_repl/__init__.py +0 -0
  184. adam/utils_repl/automata_completer.py +48 -0
  185. adam/utils_repl/repl_completer.py +46 -0
  186. adam/utils_repl/state_machine.py +173 -0
  187. adam/utils_sqlite.py +137 -0
  188. adam/version.py +1 -1
  189. {kaqing-2.0.110.dist-info → kaqing-2.0.184.dist-info}/METADATA +1 -1
  190. kaqing-2.0.184.dist-info/RECORD +244 -0
  191. adam/commands/app.py +0 -67
  192. adam/commands/bash.py +0 -150
  193. adam/commands/cp.py +0 -95
  194. adam/commands/cql/cql_utils.py +0 -112
  195. adam/commands/devices.py +0 -118
  196. adam/commands/postgres/postgres_context.py +0 -239
  197. adam/commands/postgres/postgres_utils.py +0 -31
  198. adam/commands/reaper/reaper_session.py +0 -159
  199. adam/commands/show/show_app_actions.py +0 -56
  200. adam/commands/show/show_repairs.py +0 -47
  201. kaqing-2.0.110.dist-info/RECORD +0 -187
  202. {kaqing-2.0.110.dist-info → kaqing-2.0.184.dist-info}/WHEEL +0 -0
  203. {kaqing-2.0.110.dist-info → kaqing-2.0.184.dist-info}/entry_points.txt +0 -0
  204. {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'