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.

Files changed (180) hide show
  1. adam/app_session.py +1 -1
  2. adam/apps.py +2 -2
  3. adam/batch.py +30 -31
  4. adam/checks/check_utils.py +4 -4
  5. adam/checks/compactionstats.py +1 -1
  6. adam/checks/cpu.py +2 -2
  7. adam/checks/disk.py +1 -1
  8. adam/checks/gossip.py +1 -1
  9. adam/checks/memory.py +3 -3
  10. adam/checks/status.py +1 -1
  11. adam/commands/alter_tables.py +81 -0
  12. adam/commands/app.py +3 -3
  13. adam/commands/app_ping.py +2 -2
  14. adam/commands/audit/audit.py +86 -0
  15. adam/commands/audit/audit_repair_tables.py +77 -0
  16. adam/commands/audit/audit_run.py +58 -0
  17. adam/commands/audit/show_last10.py +51 -0
  18. adam/commands/audit/show_slow10.py +50 -0
  19. adam/commands/audit/show_top10.py +48 -0
  20. adam/commands/audit/utils_show_top10.py +59 -0
  21. adam/commands/bash/bash.py +133 -0
  22. adam/commands/bash/bash_completer.py +93 -0
  23. adam/commands/cat.py +56 -0
  24. adam/commands/cd.py +12 -82
  25. adam/commands/check.py +6 -0
  26. adam/commands/cli_commands.py +3 -3
  27. adam/commands/code.py +60 -0
  28. adam/commands/command.py +48 -12
  29. adam/commands/commands_utils.py +4 -5
  30. adam/commands/cql/cql_completions.py +28 -0
  31. adam/commands/cql/cql_utils.py +209 -0
  32. adam/commands/{cqlsh.py → cql/cqlsh.py} +15 -10
  33. adam/commands/deploy/__init__.py +0 -0
  34. adam/commands/{frontend → deploy}/code_start.py +1 -1
  35. adam/commands/{frontend → deploy}/code_stop.py +1 -1
  36. adam/commands/{frontend → deploy}/code_utils.py +2 -2
  37. adam/commands/deploy/deploy.py +48 -0
  38. adam/commands/deploy/deploy_frontend.py +52 -0
  39. adam/commands/deploy/deploy_pg_agent.py +38 -0
  40. adam/commands/deploy/deploy_pod.py +110 -0
  41. adam/commands/deploy/deploy_utils.py +29 -0
  42. adam/commands/deploy/undeploy.py +48 -0
  43. adam/commands/deploy/undeploy_frontend.py +41 -0
  44. adam/commands/deploy/undeploy_pg_agent.py +42 -0
  45. adam/commands/deploy/undeploy_pod.py +51 -0
  46. adam/commands/devices/__init__.py +0 -0
  47. adam/commands/devices/device.py +27 -0
  48. adam/commands/devices/device_app.py +146 -0
  49. adam/commands/devices/device_auit_log.py +43 -0
  50. adam/commands/devices/device_cass.py +145 -0
  51. adam/commands/devices/device_export.py +86 -0
  52. adam/commands/devices/device_postgres.py +109 -0
  53. adam/commands/devices/devices.py +25 -0
  54. adam/commands/export/__init__.py +0 -0
  55. adam/commands/export/clean_up_export_session.py +53 -0
  56. adam/commands/{frontend/teardown_frontend.py → export/clean_up_export_sessions.py} +9 -11
  57. adam/commands/export/drop_export_database.py +58 -0
  58. adam/commands/export/drop_export_databases.py +46 -0
  59. adam/commands/export/export.py +83 -0
  60. adam/commands/export/export_databases.py +170 -0
  61. adam/commands/export/export_select.py +85 -0
  62. adam/commands/export/export_select_x.py +54 -0
  63. adam/commands/export/export_use.py +55 -0
  64. adam/commands/export/exporter.py +364 -0
  65. adam/commands/export/import_session.py +68 -0
  66. adam/commands/export/importer.py +67 -0
  67. adam/commands/export/importer_athena.py +80 -0
  68. adam/commands/export/importer_sqlite.py +47 -0
  69. adam/commands/export/show_column_counts.py +63 -0
  70. adam/commands/export/show_export_databases.py +39 -0
  71. adam/commands/export/show_export_session.py +51 -0
  72. adam/commands/export/show_export_sessions.py +47 -0
  73. adam/commands/export/utils_export.py +291 -0
  74. adam/commands/help.py +12 -7
  75. adam/commands/issues.py +6 -0
  76. adam/commands/kubectl.py +41 -0
  77. adam/commands/login.py +9 -5
  78. adam/commands/logs.py +2 -1
  79. adam/commands/ls.py +4 -107
  80. adam/commands/medusa/medusa.py +2 -26
  81. adam/commands/medusa/medusa_backup.py +2 -2
  82. adam/commands/medusa/medusa_restore.py +3 -4
  83. adam/commands/medusa/medusa_show_backupjobs.py +4 -3
  84. adam/commands/medusa/medusa_show_restorejobs.py +3 -3
  85. adam/commands/nodetool.py +9 -4
  86. adam/commands/param_set.py +1 -1
  87. adam/commands/postgres/postgres.py +42 -43
  88. adam/commands/postgres/postgres_context.py +248 -0
  89. adam/commands/postgres/postgres_preview.py +0 -1
  90. adam/commands/postgres/postgres_utils.py +31 -0
  91. adam/commands/postgres/psql_completions.py +10 -0
  92. adam/commands/preview_table.py +18 -40
  93. adam/commands/pwd.py +2 -28
  94. adam/commands/reaper/reaper.py +4 -24
  95. adam/commands/reaper/reaper_restart.py +1 -1
  96. adam/commands/reaper/reaper_session.py +2 -2
  97. adam/commands/repair/repair.py +3 -27
  98. adam/commands/repair/repair_log.py +1 -1
  99. adam/commands/repair/repair_run.py +2 -2
  100. adam/commands/repair/repair_scan.py +2 -7
  101. adam/commands/repair/repair_stop.py +1 -1
  102. adam/commands/report.py +6 -0
  103. adam/commands/restart.py +2 -2
  104. adam/commands/rollout.py +1 -1
  105. adam/commands/shell.py +33 -0
  106. adam/commands/show/show.py +11 -26
  107. adam/commands/show/show_app_actions.py +3 -0
  108. adam/commands/show/show_app_id.py +1 -1
  109. adam/commands/show/show_app_queues.py +3 -2
  110. adam/commands/show/show_cassandra_status.py +3 -3
  111. adam/commands/show/show_cassandra_version.py +3 -3
  112. adam/commands/show/show_commands.py +4 -1
  113. adam/commands/show/show_host.py +33 -0
  114. adam/commands/show/show_login.py +3 -0
  115. adam/commands/show/show_processes.py +1 -1
  116. adam/commands/show/show_repairs.py +2 -2
  117. adam/commands/show/show_storage.py +1 -1
  118. adam/commands/watch.py +1 -1
  119. adam/config.py +16 -3
  120. adam/embedded_params.py +1 -1
  121. adam/pod_exec_result.py +10 -2
  122. adam/repl.py +132 -117
  123. adam/repl_commands.py +62 -18
  124. adam/repl_state.py +276 -55
  125. adam/sql/__init__.py +0 -0
  126. adam/sql/sql_completer.py +120 -0
  127. adam/sql/sql_state_machine.py +617 -0
  128. adam/sql/term_completer.py +76 -0
  129. adam/sso/authenticator.py +1 -1
  130. adam/sso/authn_ad.py +36 -56
  131. adam/sso/authn_okta.py +6 -32
  132. adam/sso/cred_cache.py +1 -1
  133. adam/sso/idp.py +74 -9
  134. adam/sso/idp_login.py +2 -2
  135. adam/sso/idp_session.py +10 -7
  136. adam/utils.py +85 -4
  137. adam/utils_athena.py +145 -0
  138. adam/utils_audits.py +102 -0
  139. adam/utils_k8s/__init__.py +0 -0
  140. adam/utils_k8s/app_clusters.py +33 -0
  141. adam/utils_k8s/app_pods.py +31 -0
  142. adam/{k8s_utils → utils_k8s}/cassandra_clusters.py +6 -21
  143. adam/{k8s_utils → utils_k8s}/cassandra_nodes.py +12 -5
  144. adam/utils_k8s/config_maps.py +34 -0
  145. adam/utils_k8s/deployment.py +56 -0
  146. adam/{k8s_utils → utils_k8s}/jobs.py +1 -1
  147. adam/{k8s_utils → utils_k8s}/kube_context.py +1 -1
  148. adam/utils_k8s/pods.py +342 -0
  149. adam/{k8s_utils → utils_k8s}/secrets.py +4 -0
  150. adam/utils_k8s/service_accounts.py +169 -0
  151. adam/{k8s_utils → utils_k8s}/statefulsets.py +5 -4
  152. adam/{k8s_utils → utils_k8s}/volumes.py +9 -0
  153. adam/utils_net.py +24 -0
  154. adam/utils_repl/__init__.py +0 -0
  155. adam/utils_repl/automata_completer.py +48 -0
  156. adam/utils_repl/repl_completer.py +46 -0
  157. adam/utils_repl/state_machine.py +173 -0
  158. adam/utils_sqlite.py +101 -0
  159. adam/version.py +1 -1
  160. {kaqing-1.98.15.dist-info → kaqing-2.0.145.dist-info}/METADATA +1 -1
  161. kaqing-2.0.145.dist-info/RECORD +227 -0
  162. adam/commands/bash.py +0 -87
  163. adam/commands/cql_utils.py +0 -53
  164. adam/commands/devices.py +0 -89
  165. adam/commands/frontend/setup.py +0 -60
  166. adam/commands/frontend/setup_frontend.py +0 -58
  167. adam/commands/frontend/teardown.py +0 -61
  168. adam/commands/postgres/postgres_session.py +0 -225
  169. adam/commands/user_entry.py +0 -77
  170. adam/k8s_utils/pods.py +0 -211
  171. kaqing-1.98.15.dist-info/RECORD +0 -160
  172. /adam/commands/{frontend → audit}/__init__.py +0 -0
  173. /adam/{k8s_utils → commands/bash}/__init__.py +0 -0
  174. /adam/{medusa_show_restorejobs.py → commands/cql/__init__.py} +0 -0
  175. /adam/{k8s_utils → utils_k8s}/custom_resources.py +0 -0
  176. /adam/{k8s_utils → utils_k8s}/ingresses.py +0 -0
  177. /adam/{k8s_utils → utils_k8s}/services.py +0 -0
  178. {kaqing-1.98.15.dist-info → kaqing-2.0.145.dist-info}/WHEEL +0 -0
  179. {kaqing-1.98.15.dist-info → kaqing-2.0.145.dist-info}/entry_points.txt +0 -0
  180. {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.config import Config
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, _: ReplState, leaf: dict[str, any] = None) -> dict[str, any]:
32
- # COMMAND = 'reaper activate schedule'
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, pg_required: RequiredState = None, app_required: RequiredState = None):
43
- return state.validate(self.required(), pg_required=pg_required, app_required=app_required)
47
+ def validate_state(self, state: ReplState, show_err=True):
48
+ return state.validate(self.required(), show_err=show_err)
44
49
 
45
- @abstractmethod
46
- def help(self, state: ReplState) -> str:
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
- return state.apply_args(args, cmd=self.command_tokens(), resolve_pg=resolve_pg)
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()
@@ -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.k8s_utils.cassandra_nodes import CassandraNodes
10
- from adam.k8s_utils.pods import Pods
11
- from adam.k8s_utils.statefulsets import StatefulSets
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 convert_seconds, duration, lines_to_tabular, log, log2
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.cql_utils import run_cql
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 {Cqlsh.COMMAND: None} | {
58
- 'delete': {'from': None},
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'[{Cqlsh.COMMAND}] <cql-statements>\t run cqlsh with queries'
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.frontend.code_utils import start_user_code, stop_user_codes
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
 
@@ -1,5 +1,5 @@
1
1
  from adam.commands.command import Command
2
- from adam.commands.frontend.code_utils import stop_user_codes
2
+ from adam.commands.deploy.code_utils import stop_user_codes
3
3
  from adam.repl_state import ReplState, RequiredState
4
4
 
5
5
  class CodeStop(Command):
@@ -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.k8s_utils.ingresses import Ingresses
9
- from adam.k8s_utils.services import Services
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'