kaqing 2.0.174__py3-none-any.whl → 2.0.188__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 (138) hide show
  1. adam/app_session.py +2 -2
  2. adam/apps.py +18 -4
  3. adam/batch.py +1 -1
  4. adam/checks/check_utils.py +3 -1
  5. adam/commands/__init__.py +4 -2
  6. adam/commands/app/__init__.py +0 -0
  7. adam/commands/app/app.py +38 -0
  8. adam/commands/app/app_ping.py +38 -0
  9. adam/commands/app/show_app_actions.py +49 -0
  10. adam/commands/app/show_app_id.py +44 -0
  11. adam/commands/app/show_app_queues.py +38 -0
  12. adam/commands/app/utils_app.py +106 -0
  13. adam/commands/audit/audit.py +9 -27
  14. adam/commands/audit/audit_repair_tables.py +5 -7
  15. adam/commands/audit/audit_run.py +1 -1
  16. adam/commands/audit/completions_l.py +15 -0
  17. adam/commands/audit/show_last10.py +2 -14
  18. adam/commands/audit/show_slow10.py +2 -13
  19. adam/commands/audit/show_top10.py +2 -11
  20. adam/commands/audit/utils_show_top10.py +14 -1
  21. adam/commands/bash/bash.py +1 -1
  22. adam/commands/cat.py +3 -7
  23. adam/commands/check.py +2 -2
  24. adam/commands/cli_commands.py +6 -1
  25. adam/commands/{cp.py → clipboard_copy.py} +18 -12
  26. adam/commands/code.py +2 -2
  27. adam/commands/command.py +61 -11
  28. adam/commands/commands_utils.py +19 -12
  29. adam/commands/cql/completions_c.py +28 -0
  30. adam/commands/cql/cqlsh.py +3 -7
  31. adam/commands/cql/utils_cql.py +22 -58
  32. adam/commands/deploy/deploy_pg_agent.py +2 -2
  33. adam/commands/deploy/undeploy_pg_agent.py +2 -2
  34. adam/commands/devices/device.py +39 -8
  35. adam/commands/devices/device_app.py +18 -28
  36. adam/commands/devices/device_auit_log.py +3 -3
  37. adam/commands/devices/device_cass.py +16 -22
  38. adam/commands/devices/device_export.py +6 -3
  39. adam/commands/devices/device_postgres.py +79 -63
  40. adam/commands/download_file.py +47 -0
  41. adam/commands/export/clean_up_all_export_sessions.py +3 -3
  42. adam/commands/export/clean_up_export_sessions.py +5 -10
  43. adam/commands/export/completions_x.py +11 -0
  44. adam/commands/export/download_export_session.py +40 -0
  45. adam/commands/export/export.py +0 -16
  46. adam/commands/export/export_databases.py +26 -9
  47. adam/commands/export/export_select.py +9 -58
  48. adam/commands/export/export_sessions.py +90 -5
  49. adam/commands/export/export_use.py +13 -10
  50. adam/commands/export/export_x_select.py +48 -0
  51. adam/commands/export/exporter.py +60 -22
  52. adam/commands/export/import_files.py +44 -0
  53. adam/commands/export/import_session.py +8 -4
  54. adam/commands/export/importer.py +7 -0
  55. adam/commands/export/importer_athena.py +101 -34
  56. adam/commands/export/importer_sqlite.py +30 -5
  57. adam/commands/export/show_column_counts.py +11 -11
  58. adam/commands/export/show_export_databases.py +5 -3
  59. adam/commands/export/show_export_session.py +5 -6
  60. adam/commands/export/show_export_sessions.py +4 -11
  61. adam/commands/export/utils_export.py +42 -14
  62. adam/commands/find_files.py +51 -0
  63. adam/commands/find_processes.py +76 -0
  64. adam/commands/head.py +36 -0
  65. adam/commands/help.py +2 -2
  66. adam/commands/intermediate_command.py +6 -3
  67. adam/commands/ls.py +1 -1
  68. adam/commands/medusa/medusa_backup.py +12 -14
  69. adam/commands/medusa/medusa_restore.py +20 -15
  70. adam/commands/medusa/medusa_show_backupjobs.py +6 -4
  71. adam/commands/medusa/medusa_show_restorejobs.py +5 -3
  72. adam/commands/medusa/utils_medusa.py +15 -0
  73. adam/commands/nodetool.py +3 -8
  74. adam/commands/param_get.py +2 -3
  75. adam/commands/param_set.py +1 -1
  76. adam/commands/postgres/completions_p.py +22 -0
  77. adam/commands/postgres/postgres.py +14 -21
  78. adam/commands/postgres/postgres_databases.py +270 -0
  79. adam/commands/postgres/utils_postgres.py +29 -20
  80. adam/commands/preview_table.py +3 -1
  81. adam/commands/pwd.py +3 -3
  82. adam/commands/reaper/reaper_forward.py +2 -2
  83. adam/commands/reaper/reaper_runs.py +3 -3
  84. adam/commands/reaper/reaper_schedule_activate.py +6 -2
  85. adam/commands/reaper/reaper_schedule_start.py +1 -2
  86. adam/commands/reaper/reaper_schedule_stop.py +1 -2
  87. adam/commands/reaper/utils_reaper.py +13 -6
  88. adam/commands/repair/repair_scan.py +0 -2
  89. adam/commands/repair/repair_stop.py +0 -1
  90. adam/commands/shell.py +7 -5
  91. adam/commands/show/show.py +1 -1
  92. adam/commands/show/show_adam.py +3 -3
  93. adam/commands/show/show_cassandra_repairs.py +5 -3
  94. adam/commands/show/show_cassandra_status.py +27 -20
  95. adam/commands/show/{show_commands.py → show_cli_commands.py} +2 -2
  96. adam/commands/show/show_login.py +2 -2
  97. adam/commands/show/show_params.py +2 -5
  98. adam/commands/show/show_processes.py +15 -14
  99. adam/commands/show/show_storage.py +9 -8
  100. adam/config.py +1 -0
  101. adam/embedded_params.py +1 -1
  102. adam/repl.py +16 -9
  103. adam/repl_commands.py +16 -9
  104. adam/repl_session.py +8 -1
  105. adam/repl_state.py +33 -10
  106. adam/sql/lark_completer.py +284 -0
  107. adam/sql/lark_parser.py +604 -0
  108. adam/sql/sql_state_machine.py +8 -2
  109. adam/utils.py +116 -29
  110. adam/utils_athena.py +7 -8
  111. adam/utils_issues.py +2 -2
  112. adam/utils_k8s/app_clusters.py +2 -2
  113. adam/utils_k8s/app_pods.py +5 -2
  114. adam/utils_k8s/cassandra_clusters.py +11 -3
  115. adam/utils_k8s/cassandra_nodes.py +2 -2
  116. adam/utils_k8s/k8s.py +9 -0
  117. adam/utils_k8s/kube_context.py +2 -2
  118. adam/utils_k8s/pods.py +23 -5
  119. adam/utils_k8s/statefulsets.py +5 -2
  120. adam/utils_local.py +4 -0
  121. adam/utils_repl/appendable_completer.py +6 -0
  122. adam/utils_repl/repl_completer.py +128 -2
  123. adam/utils_sqlite.py +2 -2
  124. adam/version.py +1 -1
  125. {kaqing-2.0.174.dist-info → kaqing-2.0.188.dist-info}/METADATA +1 -1
  126. kaqing-2.0.188.dist-info/RECORD +253 -0
  127. kaqing-2.0.188.dist-info/top_level.txt +2 -0
  128. teddy/__init__.py +0 -0
  129. teddy/lark_parser.py +436 -0
  130. teddy/lark_parser2.py +618 -0
  131. adam/commands/cql/cql_completions.py +0 -32
  132. adam/commands/export/export_select_x.py +0 -54
  133. adam/commands/postgres/postgres_context.py +0 -272
  134. adam/commands/postgres/psql_completions.py +0 -10
  135. kaqing-2.0.174.dist-info/RECORD +0 -230
  136. kaqing-2.0.174.dist-info/top_level.txt +0 -1
  137. {kaqing-2.0.174.dist-info → kaqing-2.0.188.dist-info}/WHEEL +0 -0
  138. {kaqing-2.0.174.dist-info → kaqing-2.0.188.dist-info}/entry_points.txt +0 -0
@@ -5,7 +5,7 @@ from adam.commands.command import Command, InvalidStateException
5
5
  from adam.commands.devices.device import Device
6
6
  from adam.config import Config
7
7
  from adam.repl_state import ReplState
8
- from adam.utils import lines_to_tabular, log, wait_log
8
+ from adam.utils import tabulize, log, wait_log
9
9
  from adam.utils_k8s.app_pods import AppPods
10
10
  from adam.utils_k8s.ingresses import Ingresses
11
11
 
@@ -38,13 +38,20 @@ class DeviceApp(Command, Device):
38
38
  def help(self, _: ReplState):
39
39
  return f'{DeviceApp.COMMAND}\t move to App Operations device'
40
40
 
41
+ def pod(self, state: ReplState) -> str:
42
+ return state.app_pod
43
+
44
+ def pod_names(self, state: ReplState) -> list[str]:
45
+ return AppPods.pod_names(state.namespace, state.app_env, state.app_app)
46
+
47
+ def default_container(self, state: ReplState) -> str:
48
+ return Config().get('app.container-name', 'c3-server')
49
+
41
50
  def ls(self, cmd: str, state: ReplState):
42
51
  if state.app_pod:
43
52
  return self.bash(state, state, cmd.split(' '))
44
53
  elif state.app_app:
45
- pods = AppPods.pod_names(state.namespace, state.app_env, state.app_app)
46
-
47
- log(lines_to_tabular(pods, 'POD_NAME'))
54
+ tabulize(self.pod_names(state), header='POD_NAME')
48
55
  elif state.app_env:
49
56
  def line(n: str, ns: str):
50
57
  host = Ingresses.get_host(Config().get('app.login.ingress', '{app_id}-k8singr-appleader-001').replace('{app_id}', f'{ns}-{n}'), ns)
@@ -59,30 +66,13 @@ class DeviceApp(Command, Device):
59
66
 
60
67
  svcs = [l for l in [line(n, ns) for n, ns in Apps.apps(state.app_env)] if l]
61
68
 
62
- log(lines_to_tabular(svcs, 'APP,HOST,ENDPOINT', separator=','))
69
+ tabulize(svcs, header='APP,HOST,ENDPOINT', separator=',')
63
70
  else:
64
- svcs = [n for n, ns in Apps.envs()]
65
-
66
- log(lines_to_tabular(svcs, 'ENV', separator=','))
71
+ tabulize(Apps.envs(), lambda a: a[0], header='ENV', separator=',')
67
72
 
68
73
  def ls_completion(self, cmd, state, default: dict = {}):
69
74
  if state.app_app:
70
- def pod_names():
71
- return [p for p in AppPods.pod_names(state.namespace, state.app_env, state.app_app)]
72
-
73
- return super().completion(state) | {f'@{p}': {cmd: None} for p in pod_names()}
74
-
75
- return default
76
-
77
- def cat(self, cmd: str, state: ReplState):
78
- if state.app_pod:
79
- return self.bash(state, state, cmd.split(' '))
80
-
81
- raise InvalidStateException()
82
-
83
- def cat_completion(self, cmd: str, state: ReplState, default: dict = {}):
84
- if state.app_app:
85
- return {f'@{p}': {cmd: None} for p in AppPods.pod_names(state.namespace, state.app_env, state.app_app)}
75
+ return super().completion(state) | {f'@{p}': {cmd: None} for p in self.pod_names(state)}
86
76
 
87
77
  return default
88
78
 
@@ -112,7 +102,7 @@ class DeviceApp(Command, Device):
112
102
 
113
103
  def cd_completion(self, cmd: str, state: ReplState, default: dict = {}):
114
104
  if state.app_app:
115
- return {cmd: {'..': None} | {pod: None for pod in AppPods.pod_names(state.namespace, state.app_env, state.app_app)}}
105
+ return {cmd: {'..': None} | {pod: None for pod in self.pod_names(state)}}
116
106
  elif state.app_env:
117
107
  return {cmd: {'..': None} | {app[0].split('-')[1]: None for app in Apps.apps(state.app_env)}}
118
108
  else:
@@ -126,7 +116,7 @@ class DeviceApp(Command, Device):
126
116
  if state.app_app:
127
117
  words.append(f'app/{state.app_app}')
128
118
 
129
- return '\t'.join([f'{ReplState.X}:>'] + (words if words else ['/']))
119
+ return '\t'.join([f'{ReplState.A}:>'] + (words if words else ['/']))
130
120
 
131
121
  def try_fallback_action(self, chain: Command, state: ReplState, cmd: str):
132
122
  if state.app_app:
@@ -144,7 +134,7 @@ class DeviceApp(Command, Device):
144
134
  state.app_app = ea[1]
145
135
  state.app_pod = ea[2]
146
136
  if state.app_pod == '*':
147
- if (pods := AppPods.pod_names(state.namespace, ea[0], ea[1])):
137
+ if (pods := self.pod_names(state)):
148
138
  state.app_pod = pods[0]
149
139
  wait_log(f'Moving to {state.app_env}/{state.app_app}/{state.app_pod}...')
150
140
  else:
@@ -170,4 +160,4 @@ class DeviceApp(Command, Device):
170
160
 
171
161
  def bash_completion(self, cmd: str, state: ReplState, default: dict = {}):
172
162
  return {cmd: BashCompleter(lambda: [])} | \
173
- {f'@{p}': {cmd: BashCompleter(lambda: [])} for p in AppPods.pod_names(state.namespace, state.app_env, state.app_app)}
163
+ {f'@{p}': {cmd: BashCompleter(lambda: [])} for p in self.pod_names(state)}
@@ -1,7 +1,7 @@
1
1
  from adam.commands.command import Command
2
2
  from adam.commands.devices.device import Device
3
3
  from adam.repl_state import ReplState
4
- from adam.utils import lines_to_tabular, log
4
+ from adam.utils import tabulize, log
5
5
  from adam.utils_athena import Athena
6
6
 
7
7
  class DeviceAuditLog(Command, Device):
@@ -34,7 +34,7 @@ class DeviceAuditLog(Command, Device):
34
34
  return f'{DeviceAuditLog.COMMAND}\t move to Audit Log Operations device'
35
35
 
36
36
  def ls(self, cmd: str, _: ReplState):
37
- log(lines_to_tabular(Athena.table_names(), 'NAME', separator=','))
37
+ tabulize(Athena.table_names(), header='NAME', separator=',')
38
38
 
39
39
  def pwd(self, _: ReplState):
40
40
  return '\t'.join([f'{ReplState.L}:>', '/'])
@@ -43,7 +43,7 @@ class DeviceAuditLog(Command, Device):
43
43
  return True, chain.run(f'audit {cmd}', state)
44
44
 
45
45
  def show_tables(self, _: ReplState):
46
- log(lines_to_tabular(Athena.table_names(), separator=','))
46
+ tabulize(Athena.table_names(), separator=',')
47
47
 
48
48
  def show_table_preview(self, _: ReplState, table: str, rows: int):
49
49
  Athena.run_query(f'select * from {table} limit {rows}')
@@ -5,7 +5,7 @@ from adam.commands.cql.utils_cql import cassandra, cassandra_table_names
5
5
  from adam.commands.devices.device import Device
6
6
  from adam.config import Config
7
7
  from adam.repl_state import ReplState
8
- from adam.utils import lines_to_tabular, log, log2, wait_log
8
+ from adam.utils import tabulize, log, log2, wait_log
9
9
  from adam.utils_k8s.cassandra_clusters import CassandraClusters
10
10
  from adam.utils_k8s.custom_resources import CustomResources
11
11
  from adam.utils_k8s.kube_context import KubeContext
@@ -34,12 +34,21 @@ class DeviceCass(Command, Device):
34
34
 
35
35
  return state
36
36
 
37
+ def pod(self, state: ReplState) -> str:
38
+ return state.pod
39
+
40
+ def pod_names(self, state: ReplState) -> list[str]:
41
+ return StatefulSets.pod_names(state.sts, state.namespace)
42
+
37
43
  def completion(self, state: ReplState):
38
44
  return super().completion(state)
39
45
 
40
46
  def help(self, _: ReplState):
41
47
  return f'{DeviceCass.COMMAND}\t move to Cassandra Operations device'
42
48
 
49
+ def default_container(self, _: ReplState) -> str:
50
+ return 'cassandra'
51
+
43
52
  def ls(self, cmd: str, state: ReplState):
44
53
  if state.pod:
45
54
  return self.bash(state, state, cmd.split(' '))
@@ -50,26 +59,11 @@ class DeviceCass(Command, Device):
50
59
  self.show_statefulsets()
51
60
 
52
61
  def ls_completion(self, cmd: str, state: ReplState, default: dict = {}):
53
- def pod_names():
54
- return [p for p in StatefulSets.pod_names(state.sts, state.namespace)]
55
-
56
62
  if state.sts:
57
- return super().completion(state) | {f'@{p}': {'ls': None} for p in pod_names()}
63
+ return super().completion(state) | {f'@{p}': {'ls': None} for p in self.pod_names(state)}
58
64
  else:
59
65
  return {cmd: {n: None for n in StatefulSets.list_sts_names()}}
60
66
 
61
- def cat(self, cmd: str, state: ReplState):
62
- if state.pod:
63
- return self.bash(state, state, cmd.split(' '))
64
-
65
- raise InvalidStateException()
66
-
67
- def cat_completion(self, cmd: str, state: ReplState, default: dict = {}):
68
- if state.sts:
69
- return {f'@{p}': {cmd: None} for p in StatefulSets.pod_names(state.sts, state.namespace)}
70
-
71
- return default
72
-
73
67
  def show_statefulsets(self):
74
68
  ss = StatefulSets.list_sts_names()
75
69
  if len(ss) == 0:
@@ -88,7 +82,7 @@ class DeviceCass(Command, Device):
88
82
  header = 'STATEFULSET_NAME@NAMESPACE APP_ID'
89
83
  if KubeContext.in_cluster_namespace():
90
84
  header = 'STATEFULSET_NAME APP_ID'
91
- log(lines_to_tabular(list, header))
85
+ tabulize(list, header=header)
92
86
 
93
87
  def cd(self, dir: str, state: ReplState):
94
88
  if dir == '':
@@ -110,7 +104,7 @@ class DeviceCass(Command, Device):
110
104
  if p:
111
105
  state.pod = p
112
106
  else:
113
- names = CassandraClusters.pod_names_by_host_id(state.sts, state.namespace);
107
+ names = CassandraClusters.pod_names_by_host_id(state.sts, state.namespace)
114
108
  if dir in names:
115
109
  state.pod = names[dir]
116
110
  else:
@@ -120,7 +114,7 @@ class DeviceCass(Command, Device):
120
114
  if state.pod:
121
115
  return {cmd: {'..': None}}
122
116
  elif state.sts:
123
- return {cmd: {'..': None} | {p: None for p in StatefulSets.pod_names(state.sts, state.namespace)}}
117
+ return {cmd: {'..': None} | {p: None for p in self.pod_names(state)}}
124
118
  else:
125
119
  return {cmd: {p: None for p in StatefulSets.list_sts_names()}}
126
120
 
@@ -158,7 +152,7 @@ class DeviceCass(Command, Device):
158
152
  wait_log(f'Moving to the only Cassandra cluster: {state.sts}@{state.namespace}...')
159
153
 
160
154
  def show_tables(self, state: ReplState):
161
- log(lines_to_tabular(cassandra_table_names(state), separator=','))
155
+ tabulize(cassandra_table_names(state), separator=',')
162
156
 
163
157
  def show_table_preview(self, state: ReplState, table: str, rows: int):
164
158
  with cassandra(state) as pods:
@@ -179,7 +173,7 @@ class DeviceCass(Command, Device):
179
173
  completions = {cmd: BashCompleter(lambda: [])}
180
174
 
181
175
  if state.sts and state.namespace:
182
- completions |= {f'@{p}': {cmd: BashCompleter(lambda: [])} for p in StatefulSets.pod_names(state.sts, state.namespace)}
176
+ completions |= {f'@{p}': {cmd: BashCompleter(lambda: [])} for p in self.pod_names(state)}
183
177
 
184
178
  return completions
185
179
 
@@ -3,7 +3,7 @@ from adam.commands.devices.device import Device
3
3
  from adam.commands.export.export_databases import ExportDatabases, export_db
4
4
  from adam.config import Config
5
5
  from adam.repl_state import ReplState
6
- from adam.utils import lines_to_tabular, log, log2, wait_log
6
+ from adam.utils import tabulize, log2, wait_log
7
7
 
8
8
  class DeviceExport(Command, Device):
9
9
  COMMAND = f'{ReplState.X}:'
@@ -36,7 +36,7 @@ class DeviceExport(Command, Device):
36
36
 
37
37
  def ls(self, cmd: str, state: ReplState):
38
38
  if state.export_session:
39
- log(lines_to_tabular(ExportDatabases.table_names(state.export_session), 'NAME', separator=','))
39
+ tabulize(ExportDatabases.table_names(state.export_session), header='NAME', separator=',')
40
40
  else:
41
41
  ExportDatabases.show_databases()
42
42
 
@@ -66,7 +66,10 @@ class DeviceExport(Command, Device):
66
66
  return '\t'.join([f'{ReplState.X}:>'] + (words if words else ['/']))
67
67
 
68
68
  def try_fallback_action(self, chain: Command, state: ReplState, cmd: str):
69
- result = chain.run(f'.{cmd}', state)
69
+ if cmd.startswith('select '):
70
+ cmd = f'xelect {cmd[7:]}'
71
+
72
+ result = chain.run(cmd, state)
70
73
  if type(result) is ReplState:
71
74
  if state.export_session and not result.export_session:
72
75
  state.export_session = None
@@ -1,11 +1,10 @@
1
1
  from adam.commands.bash.bash_completer import BashCompleter
2
- from adam.commands.command import Command, InvalidStateException
2
+ from adam.commands.command import Command
3
3
  from adam.commands.devices.device import Device
4
- from adam.commands.postgres.postgres_context import PostgresContext
4
+ from adam.commands.postgres.postgres_databases import PostgresDatabases, pg_path
5
5
  from adam.commands.postgres.utils_postgres import pg_database_names, pg_table_names, postgres
6
6
  from adam.repl_state import ReplState
7
- from adam.utils import lines_to_tabular, log, log2, wait_log
8
- from adam.utils_k8s.pods import Pods
7
+ from adam.utils import tabulize, log2, wait_log
9
8
 
10
9
  class DevicePostgres(Command, Device):
11
10
  COMMAND = f'{ReplState.P}:'
@@ -36,79 +35,98 @@ class DevicePostgres(Command, Device):
36
35
  def help(self, _: ReplState):
37
36
  return f'{DevicePostgres.COMMAND}\t move to Postgres Operations device'
38
37
 
39
- def ls(self, cmd: str, state: ReplState):
40
- if state.pg_path:
41
- pg: PostgresContext = PostgresContext.apply(state.namespace, state.pg_path)
42
- if pg.db:
43
- self.show_pg_tables(pg)
44
- else:
45
- self.show_pg_databases(pg)
46
- else:
47
- self.show_pg_hosts(state)
38
+ def pod(self, state: ReplState) -> str:
39
+ pod, _ = PostgresDatabases.pod_and_container(state.namespace)
40
+ return pod
48
41
 
49
- def cat(self, cmd: str, state: ReplState):
50
- if state.pod:
51
- return self.bash(state, state, cmd.split(' '))
42
+ def pod_names(self, state: ReplState) -> list[str]:
43
+ return [self.pod(state)]
52
44
 
53
- raise InvalidStateException()
45
+ def default_container(self, state: ReplState) -> str:
46
+ _, container = PostgresDatabases.pod_and_container(state.namespace)
47
+ return container
48
+
49
+ def ls(self, cmd: str, state: ReplState):
50
+ if state.pod_targetted:
51
+ self.bash(state, state, ['ls'])
52
+ return
53
+
54
+ with pg_path(state) as (host, database):
55
+ if database:
56
+ tabulize(pg_table_names(state), header='NAME', separator=',')
57
+ elif host:
58
+ tabulize(pg_database_names(state), header='DATABASE', separator=',')
59
+ else:
60
+ self.show_pg_hosts(state)
54
61
 
55
62
  def show_pg_hosts(self, state: ReplState):
56
63
  if state.namespace:
57
- def line(pg: PostgresContext):
58
- return f'{pg.path()},{pg.endpoint()}:{pg.port()},{pg.username()},{pg.password()}'
59
-
60
- lines = [line(PostgresContext.apply(state.namespace, pg)) for pg in PostgresContext.hosts(state.namespace)]
61
-
62
- log(lines_to_tabular(lines, 'NAME,ENDPOINT,USERNAME,PASSWORD', separator=','))
64
+ tabulize(PostgresDatabases.hosts(state),
65
+ lambda p: f'{p.host},{p.endpoint()}:{p.port()},{p.username()},{p.password()}',
66
+ header='NAME,ENDPOINT,USERNAME,PASSWORD',
67
+ separator=',')
63
68
  else:
64
- def line(pg: PostgresContext):
65
- return f'{pg.path()},{pg.namespace},{pg.endpoint()}:{pg.port()},{pg.username()},{pg.password()}'
66
-
67
- lines = [line(PostgresContext.apply(state.namespace, pg)) for pg in PostgresContext.hosts(state.namespace)]
68
-
69
- log(lines_to_tabular(lines, 'NAME,NAMESPACE,ENDPOINT,USERNAME,PASSWORD', separator=','))
70
-
71
- def show_pg_databases(self, pg: PostgresContext):
72
- log(lines_to_tabular(pg_database_names(pg.namespace, pg.path()), 'DATABASE', separator=','))
73
-
74
- def show_pg_tables(self, pg: PostgresContext):
75
- log(lines_to_tabular(pg_table_names(pg.namespace, pg.path()), 'NAME', separator=','))
69
+ tabulize(PostgresDatabases.hosts(state),
70
+ lambda p: f'{p.host},{p.namespace},{p.endpoint()}:{p.port()},{p.username()},{p.password()}',
71
+ header='NAME,NAMESPACE,ENDPOINT,USERNAME,PASSWORD',
72
+ separator=',')
76
73
 
77
74
  def cd(self, dir: str, state: ReplState):
78
75
  if dir == '':
79
76
  state.pg_path = None
80
- else:
81
- context: PostgresContext = PostgresContext.apply(state.namespace, state.pg_path, arg=dir)
82
- # patch up state.namespace from pg cd
83
- if not state.namespace and context.namespace:
84
- state.namespace = context.namespace
85
- state.pg_path = context.path()
77
+ return
78
+
79
+ with pg_path(state) as (host, database):
80
+ if dir == '..':
81
+ if database:
82
+ database = None
83
+ else:
84
+ host = None
85
+ else:
86
+ tks = dir.split('@')
87
+ if not host:
88
+ host = tks[0]
89
+ else:
90
+ database = tks[0]
91
+
92
+ if len(tks) > 1:
93
+ state.namespace = tks[1]
94
+
95
+ if database:
96
+ state.pg_path = f'{host}/{database}'
97
+ else:
98
+ state.pg_path = host
86
99
 
87
100
  def cd_completion(self, cmd: str, state: ReplState, default: dict = {}):
88
- pg: PostgresContext = PostgresContext.apply(state.namespace, state.pg_path) if state.pg_path else None
89
- if pg and pg.db:
90
- return {cmd: {'..': None}}
91
- elif pg and pg.host:
92
- return {cmd: {'..': None} | {p: None for p in pg_database_names(state.namespace, pg.path())}}
93
- else:
94
- return {cmd: {p: None for p in PostgresContext.hosts(state.namespace)}}
101
+ return {cmd: {d: None for d in self.direct_dirs(cmd, state, default=default)}}
102
+
103
+ def direct_dirs(self, cmd: str, state: ReplState, default: dict = {}) -> list[str]:
104
+ with pg_path(state) as (host, database):
105
+ if database:
106
+ return ['..']
107
+ elif host:
108
+ return ['..'] + [p for p in pg_database_names(state)]
109
+ else:
110
+ return [p for p in PostgresDatabases.host_names(state.namespace)]
95
111
 
96
112
  def pwd(self, state: ReplState):
97
113
  words = []
98
114
 
99
- pg: PostgresContext = PostgresContext.apply(state.namespace, state.pg_path)
115
+ with pg_path(state) as (host, database):
116
+ if host:
117
+ words.append(f'host/{host}')
118
+ if database:
119
+ words.append(f'database/{database}')
100
120
 
101
- if pg.host:
102
- words.append(f'host/{pg.host}')
103
- if pg.db:
104
- words.append(f'database/{pg.db}')
105
-
106
- return '\t'.join([f'{ReplState.P}:>'] + (words if words else ['/']))
121
+ return '\t'.join([f'{ReplState.P}:>'] + (words if words else ['/']))
107
122
 
108
123
  def try_fallback_action(self, chain: Command, state: ReplState, cmd: str):
109
- pg: PostgresContext = PostgresContext.apply(state.namespace, state.pg_path)
110
- if pg.db:
111
- return True, chain.run(f'pg {cmd}', state)
124
+ with pg_path(state) as (_, database):
125
+ if not database:
126
+ database = PostgresDatabases.default_db()
127
+
128
+ if database:
129
+ return True, chain.run(f'pg {cmd}', state)
112
130
 
113
131
  return False, None
114
132
 
@@ -116,15 +134,13 @@ class DevicePostgres(Command, Device):
116
134
  wait_log('Inspecting postgres database instances...')
117
135
 
118
136
  def show_tables(self, state: ReplState):
119
- pg = PostgresContext.apply(state.namespace, state.pg_path)
120
- lines = [db["name"] for db in pg.tables() if db["schema"] == PostgresContext.default_schema()]
121
- log(lines_to_tabular(lines, separator=','))
137
+ tabulize(PostgresDatabases.tables(state, default_schema=True), lambda d: d['name'], separator=',')
122
138
 
123
139
  def show_table_preview(self, state: ReplState, table: str, rows: int):
124
- PostgresContext.apply(state.namespace, state.pg_path).run_sql(f'select * from {table} limit {rows}')
140
+ PostgresDatabases.run_sql(state, f'select * from {table} limit {rows}')
125
141
 
126
142
  def bash(self, s0: ReplState, s1: ReplState, args: list[str]):
127
- pod, container = PostgresContext.pod_and_container(s1.namespace)
143
+ pod, container = PostgresDatabases.pod_and_container(s1.namespace)
128
144
  log2(f'Running on {pod}(container:{container})...')
129
145
 
130
146
  return super().bash(s0, s1, args)
@@ -0,0 +1,47 @@
1
+ from adam.commands import validate_args
2
+ from adam.commands.command import Command
3
+ from adam.commands.devices.devices import Devices
4
+ from adam.config import Config
5
+ from adam.pod_exec_result import PodExecResult
6
+ from adam.repl_state import ReplState, RequiredState
7
+ from adam.utils import log2
8
+ from adam.utils_k8s.pods import Pods
9
+
10
+ class DownloadFile(Command):
11
+ COMMAND = 'download file'
12
+
13
+ # the singleton pattern
14
+ def __new__(cls, *args, **kwargs):
15
+ if not hasattr(cls, 'instance'): cls.instance = super(DownloadFile, 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 DownloadFile.COMMAND
24
+
25
+ def required(self):
26
+ return [RequiredState.CLUSTER_OR_POD, RequiredState.APP_APP, ReplState.P]
27
+
28
+ def run(self, cmd: str, state: ReplState):
29
+ if not(args := self.args(cmd)):
30
+ return super().run(cmd, state)
31
+
32
+ with self.validate(args, state) as (args, state):
33
+ with validate_args(args, state, name='file'):
34
+ to_file = Pods.download_file(Devices.device(state).pod(state),
35
+ Devices.device(state).default_container(state),
36
+ state.namespace,
37
+ args[0],
38
+ args[1] if len(args) > 1 else None)
39
+ log2(f'Downloaded to {to_file}.')
40
+
41
+ return state
42
+
43
+ def completion(self, state: ReplState):
44
+ return super().completion(state, lambda: {f: None for f in Devices.device(state).files(state)}, pods=Devices.device(state).pods(state, '-'), auto='jit')
45
+
46
+ def help(self, _: ReplState):
47
+ return f'{DownloadFile.COMMAND} from-file [to-file]\t download file from pod'
@@ -1,5 +1,5 @@
1
1
  from adam.commands.command import Command
2
- from adam.commands.export.export_sessions import ExportSessions
2
+ from adam.commands.export.export_sessions import export_session
3
3
  from adam.repl_state import ReplState, RequiredState
4
4
 
5
5
  class CleanUpAllExportSessions(Command):
@@ -25,8 +25,8 @@ class CleanUpAllExportSessions(Command):
25
25
  return super().run(cmd, state)
26
26
 
27
27
  with self.validate(args, state) as (args, state):
28
- if ExportSessions.clean_up_all_sessions(state.sts, state.pod, state.namespace):
29
- ExportSessions.clear_export_session_cache()
28
+ with export_session(state) as sessions:
29
+ sessions.clean_up_all()
30
30
 
31
31
  return state
32
32
 
@@ -1,9 +1,7 @@
1
1
  from adam.commands import validate_args
2
2
  from adam.commands.command import Command
3
- from adam.commands.export.export_sessions import ExportSessions
4
- from adam.commands.export.exporter import Exporter
3
+ from adam.commands.export.export_sessions import export_session
5
4
  from adam.repl_state import ReplState, RequiredState
6
- from adam.utils import log, log2
7
5
 
8
6
  class CleanUpExportSessions(Command):
9
7
  COMMAND = 'clean up export sessions'
@@ -28,12 +26,9 @@ class CleanUpExportSessions(Command):
28
26
  return super().run(cmd, state)
29
27
 
30
28
  with self.validate(args, state) as (args, state):
31
- with validate_args(args, state, name='export session') as arg_str:
32
- sessions = [arg.strip(' ') for arg in arg_str.split(',')]
33
- csv_cnt, log_cnt = ExportSessions.clean_up_sessions(state.sts, state.pod, state.namespace, sessions)
34
- log(f'Removed {csv_cnt} csv and {log_cnt} log files.')
35
-
36
- ExportSessions.clear_export_session_cache()
29
+ with validate_args(args, state, name='export session', separator=',') as session_names:
30
+ with export_session(state) as sessions:
31
+ sessions.clean_up(session_names)
37
32
 
38
33
  return state
39
34
 
@@ -41,4 +36,4 @@ class CleanUpExportSessions(Command):
41
36
  return {}
42
37
 
43
38
  def help(self, _: ReplState):
44
- return f'{CleanUpExportSessions.COMMAND} <export-session-name>\t clean up export session'
39
+ return f'{CleanUpExportSessions.COMMAND} <export-session-name,...>\t clean up export sessions'
@@ -0,0 +1,11 @@
1
+ from adam.commands.export.export_databases import ExportDatabases
2
+ from adam.repl_state import ReplState
3
+ from adam.sql.lark_completer import LarkCompleter
4
+ from adam.utils_athena import Athena
5
+
6
+ def completions_x(state: ReplState):
7
+ return LarkCompleter(expandables={
8
+ 'tables': lambda x: ExportDatabases.table_names(state.export_session),
9
+ 'export-databases': lambda x: ExportDatabases.database_names(),
10
+ 'columns': lambda x: Athena.column_names(database=state.export_session, function='export'),
11
+ }, variant=ReplState.X).completions_for_nesting()
@@ -0,0 +1,40 @@
1
+ from adam.commands import validate_args
2
+ from adam.commands.command import Command
3
+ from adam.commands.export.export_sessions import ExportSessions, export_session
4
+ from adam.repl_state import ReplState, RequiredState
5
+
6
+ class DownloadExportSession(Command):
7
+ COMMAND = 'download export session'
8
+
9
+ # the singleton pattern
10
+ def __new__(cls, *args, **kwargs):
11
+ if not hasattr(cls, 'instance'): cls.instance = super(DownloadExportSession, 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 DownloadExportSession.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
+ with self.validate(args, state) as (args, state):
29
+ with validate_args(args, state, name='export session') as session:
30
+ with export_session(state) as sessions:
31
+ sessions.download_session(session)
32
+
33
+ return state
34
+
35
+ def completion(self, state: ReplState):
36
+ return {}
37
+ # return super().completion(state, {session: None for session in ExportSessions.export_session_names(state.sts, state.pod, state.namespace, export_state='pending_import')})
38
+
39
+ def help(self, _: ReplState):
40
+ return f'{DownloadExportSession.COMMAND} <export-session-name>\t download csv files in export session'
@@ -1,12 +1,7 @@
1
1
  from adam.commands import extract_options
2
2
  from adam.commands.command import Command
3
- from adam.commands.cql.utils_cql import cassandra_keyspaces, cassandra_table_names
4
- from adam.commands.export.export_databases import ExportDatabases
5
3
  from adam.commands.export.exporter import export
6
4
  from adam.repl_state import ReplState, RequiredState
7
- from adam.sql.sql_completer import SqlCompleter, SqlVariant
8
- from adam.utils import log
9
- from adam.utils_k8s.statefulsets import StatefulSets
10
5
 
11
6
  class ExportTables(Command):
12
7
  COMMAND = 'export'
@@ -36,17 +31,6 @@ class ExportTables(Command):
36
31
  return exporter.export(args, export_only=export_only)
37
32
 
38
33
  def completion(self, state: ReplState):
39
- def sc():
40
- return SqlCompleter(lambda: cassandra_table_names(state), expandables={
41
- 'dml':'export',
42
- 'columns': lambda table: ['id', '*'],
43
- 'keyspaces': lambda: cassandra_keyspaces(state),
44
- 'export-dbs': lambda: ExportDatabases.database_names(),
45
- }, variant=SqlVariant.CQL)
46
-
47
- if super().completion(state):
48
- return {f'@{p}': {ExportTables.COMMAND: sc()} for p in StatefulSets.pod_names(state.sts, state.namespace)}
49
-
50
34
  return {}
51
35
 
52
36
  def help(self, _: ReplState):