kaqing 2.0.98__py3-none-any.whl → 2.0.171__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.
Files changed (194) hide show
  1. adam/__init__.py +0 -2
  2. adam/app_session.py +9 -7
  3. adam/batch.py +4 -18
  4. adam/checks/check_utils.py +14 -46
  5. adam/checks/cpu.py +7 -1
  6. adam/checks/cpu_metrics.py +52 -0
  7. adam/columns/columns.py +3 -1
  8. adam/columns/cpu.py +3 -1
  9. adam/columns/cpu_metrics.py +22 -0
  10. adam/commands/__init__.py +15 -0
  11. adam/commands/alter_tables.py +50 -61
  12. adam/commands/app_cmd.py +38 -0
  13. adam/commands/app_ping.py +8 -14
  14. adam/commands/audit/audit.py +43 -30
  15. adam/commands/audit/audit_repair_tables.py +26 -46
  16. adam/commands/audit/audit_run.py +50 -0
  17. adam/commands/audit/show_last10.py +48 -0
  18. adam/commands/audit/show_slow10.py +47 -0
  19. adam/commands/audit/show_top10.py +45 -0
  20. adam/commands/audit/utils_show_top10.py +59 -0
  21. adam/commands/bash/__init__.py +5 -0
  22. adam/commands/bash/bash.py +36 -0
  23. adam/commands/bash/bash_completer.py +93 -0
  24. adam/commands/bash/utils_bash.py +16 -0
  25. adam/commands/cat.py +50 -0
  26. adam/commands/cd.py +15 -91
  27. adam/commands/check.py +23 -18
  28. adam/commands/cli_commands.py +2 -3
  29. adam/commands/code.py +57 -0
  30. adam/commands/command.py +96 -40
  31. adam/commands/commands_utils.py +9 -19
  32. adam/commands/cp.py +33 -39
  33. adam/commands/cql/cql_completions.py +30 -8
  34. adam/commands/cql/cqlsh.py +12 -27
  35. adam/commands/cql/utils_cql.py +343 -0
  36. adam/commands/deploy/code_start.py +7 -10
  37. adam/commands/deploy/code_stop.py +4 -21
  38. adam/commands/deploy/code_utils.py +3 -3
  39. adam/commands/deploy/deploy.py +4 -21
  40. adam/commands/deploy/deploy_frontend.py +14 -17
  41. adam/commands/deploy/deploy_pg_agent.py +3 -6
  42. adam/commands/deploy/deploy_pod.py +67 -73
  43. adam/commands/deploy/deploy_utils.py +14 -24
  44. adam/commands/deploy/undeploy.py +4 -21
  45. adam/commands/deploy/undeploy_frontend.py +4 -7
  46. adam/commands/deploy/undeploy_pg_agent.py +6 -8
  47. adam/commands/deploy/undeploy_pod.py +11 -12
  48. adam/commands/devices/device.py +118 -0
  49. adam/commands/devices/device_app.py +173 -0
  50. adam/commands/devices/device_auit_log.py +49 -0
  51. adam/commands/devices/device_cass.py +185 -0
  52. adam/commands/devices/device_export.py +86 -0
  53. adam/commands/devices/device_postgres.py +144 -0
  54. adam/commands/devices/devices.py +25 -0
  55. adam/commands/exit.py +1 -4
  56. adam/commands/export/__init__.py +0 -0
  57. adam/commands/export/clean_up_all_export_sessions.py +37 -0
  58. adam/commands/export/clean_up_export_sessions.py +51 -0
  59. adam/commands/export/drop_export_database.py +55 -0
  60. adam/commands/export/drop_export_databases.py +43 -0
  61. adam/commands/export/export.py +53 -0
  62. adam/commands/export/export_databases.py +170 -0
  63. adam/commands/export/export_handlers.py +71 -0
  64. adam/commands/export/export_select.py +81 -0
  65. adam/commands/export/export_select_x.py +54 -0
  66. adam/commands/export/export_use.py +52 -0
  67. adam/commands/export/exporter.py +352 -0
  68. adam/commands/export/import_session.py +40 -0
  69. adam/commands/export/importer.py +67 -0
  70. adam/commands/export/importer_athena.py +80 -0
  71. adam/commands/export/importer_sqlite.py +47 -0
  72. adam/commands/export/show_column_counts.py +54 -0
  73. adam/commands/export/show_export_databases.py +36 -0
  74. adam/commands/export/show_export_session.py +48 -0
  75. adam/commands/export/show_export_sessions.py +44 -0
  76. adam/commands/export/utils_export.py +314 -0
  77. adam/commands/help.py +10 -6
  78. adam/commands/intermediate_command.py +49 -0
  79. adam/commands/issues.py +14 -40
  80. adam/commands/kubectl.py +38 -0
  81. adam/commands/login.py +28 -24
  82. adam/commands/logs.py +4 -6
  83. adam/commands/ls.py +11 -116
  84. adam/commands/medusa/medusa.py +4 -22
  85. adam/commands/medusa/medusa_backup.py +20 -24
  86. adam/commands/medusa/medusa_restore.py +30 -32
  87. adam/commands/medusa/medusa_show_backupjobs.py +16 -17
  88. adam/commands/medusa/medusa_show_restorejobs.py +12 -17
  89. adam/commands/nodetool.py +11 -17
  90. adam/commands/param_get.py +11 -12
  91. adam/commands/param_set.py +9 -10
  92. adam/commands/postgres/postgres.py +43 -36
  93. adam/commands/postgres/{postgres_session.py → postgres_context.py} +80 -46
  94. adam/commands/postgres/postgres_ls.py +4 -8
  95. adam/commands/postgres/postgres_preview.py +5 -9
  96. adam/commands/postgres/psql_completions.py +2 -2
  97. adam/commands/postgres/utils_postgres.py +66 -0
  98. adam/commands/preview_table.py +8 -61
  99. adam/commands/pwd.py +14 -44
  100. adam/commands/reaper/reaper.py +4 -24
  101. adam/commands/reaper/reaper_forward.py +48 -55
  102. adam/commands/reaper/reaper_forward_session.py +6 -0
  103. adam/commands/reaper/reaper_forward_stop.py +10 -16
  104. adam/commands/reaper/reaper_restart.py +7 -14
  105. adam/commands/reaper/reaper_run_abort.py +11 -30
  106. adam/commands/reaper/reaper_runs.py +42 -57
  107. adam/commands/reaper/reaper_runs_abort.py +29 -49
  108. adam/commands/reaper/reaper_schedule_activate.py +11 -30
  109. adam/commands/reaper/reaper_schedule_start.py +10 -29
  110. adam/commands/reaper/reaper_schedule_stop.py +10 -29
  111. adam/commands/reaper/reaper_schedules.py +4 -14
  112. adam/commands/reaper/reaper_status.py +8 -16
  113. adam/commands/reaper/utils_reaper.py +196 -0
  114. adam/commands/repair/repair.py +4 -22
  115. adam/commands/repair/repair_log.py +4 -7
  116. adam/commands/repair/repair_run.py +27 -29
  117. adam/commands/repair/repair_scan.py +31 -34
  118. adam/commands/repair/repair_stop.py +4 -7
  119. adam/commands/report.py +25 -21
  120. adam/commands/restart.py +25 -26
  121. adam/commands/rollout.py +19 -24
  122. adam/commands/shell.py +5 -4
  123. adam/commands/show/show.py +6 -19
  124. adam/commands/show/show_app_actions.py +26 -22
  125. adam/commands/show/show_app_id.py +8 -11
  126. adam/commands/show/show_app_queues.py +7 -10
  127. adam/commands/show/{show_repairs.py → show_cassandra_repairs.py} +8 -17
  128. adam/commands/show/show_cassandra_status.py +29 -33
  129. adam/commands/show/show_cassandra_version.py +4 -14
  130. adam/commands/show/show_commands.py +19 -21
  131. adam/commands/show/show_host.py +1 -1
  132. adam/commands/show/show_login.py +26 -24
  133. adam/commands/show/show_processes.py +16 -18
  134. adam/commands/show/show_storage.py +10 -20
  135. adam/commands/watch.py +26 -29
  136. adam/config.py +5 -14
  137. adam/embedded_params.py +1 -1
  138. adam/pod_exec_result.py +7 -1
  139. adam/repl.py +95 -131
  140. adam/repl_commands.py +48 -20
  141. adam/repl_state.py +270 -61
  142. adam/sql/sql_completer.py +105 -63
  143. adam/sql/sql_state_machine.py +618 -0
  144. adam/sql/term_completer.py +3 -0
  145. adam/sso/authn_ad.py +6 -5
  146. adam/sso/authn_okta.py +3 -3
  147. adam/sso/cred_cache.py +3 -2
  148. adam/sso/idp.py +3 -3
  149. adam/utils.py +439 -3
  150. adam/utils_app.py +98 -0
  151. adam/utils_athena.py +140 -87
  152. adam/utils_audits.py +106 -0
  153. adam/utils_issues.py +32 -0
  154. adam/utils_k8s/app_clusters.py +28 -0
  155. adam/utils_k8s/app_pods.py +33 -0
  156. adam/utils_k8s/cassandra_clusters.py +22 -20
  157. adam/utils_k8s/cassandra_nodes.py +4 -4
  158. adam/utils_k8s/custom_resources.py +5 -0
  159. adam/utils_k8s/ingresses.py +2 -2
  160. adam/utils_k8s/k8s.py +87 -0
  161. adam/utils_k8s/pods.py +77 -68
  162. adam/utils_k8s/secrets.py +4 -4
  163. adam/utils_k8s/service_accounts.py +5 -4
  164. adam/utils_k8s/services.py +2 -2
  165. adam/utils_k8s/statefulsets.py +1 -12
  166. adam/utils_net.py +4 -4
  167. adam/utils_repl/__init__.py +0 -0
  168. adam/utils_repl/automata_completer.py +48 -0
  169. adam/utils_repl/repl_completer.py +46 -0
  170. adam/utils_repl/state_machine.py +173 -0
  171. adam/utils_sqlite.py +109 -0
  172. adam/version.py +1 -1
  173. {kaqing-2.0.98.dist-info → kaqing-2.0.171.dist-info}/METADATA +1 -1
  174. kaqing-2.0.171.dist-info/RECORD +236 -0
  175. adam/commands/app.py +0 -67
  176. adam/commands/bash.py +0 -92
  177. adam/commands/cql/cql_table_completer.py +0 -8
  178. adam/commands/cql/cql_utils.py +0 -115
  179. adam/commands/describe/describe.py +0 -47
  180. adam/commands/describe/describe_keyspace.py +0 -60
  181. adam/commands/describe/describe_keyspaces.py +0 -49
  182. adam/commands/describe/describe_schema.py +0 -49
  183. adam/commands/describe/describe_table.py +0 -60
  184. adam/commands/describe/describe_tables.py +0 -49
  185. adam/commands/devices.py +0 -118
  186. adam/commands/postgres/postgres_utils.py +0 -31
  187. adam/commands/postgres/psql_table_completer.py +0 -11
  188. adam/commands/reaper/reaper_session.py +0 -159
  189. adam/sql/state_machine.py +0 -460
  190. kaqing-2.0.98.dist-info/RECORD +0 -191
  191. /adam/commands/{describe → devices}/__init__.py +0 -0
  192. {kaqing-2.0.98.dist-info → kaqing-2.0.171.dist-info}/WHEEL +0 -0
  193. {kaqing-2.0.98.dist-info → kaqing-2.0.171.dist-info}/entry_points.txt +0 -0
  194. {kaqing-2.0.98.dist-info → kaqing-2.0.171.dist-info}/top_level.txt +0 -0
adam/sql/sql_completer.py CHANGED
@@ -1,78 +1,120 @@
1
- from typing import Callable, Iterable
2
- from prompt_toolkit.completion import CompleteEvent, Completer, Completion
3
- from prompt_toolkit.document import Document
1
+ from enum import Enum
2
+ from typing import Callable
3
+
4
4
  import sqlparse
5
- from sqlparse.sql import Statement
5
+ from sqlparse.sql import Statement, Token
6
6
 
7
- from adam.sql.state_machine import StateMachine, StateTo
8
7
  from adam.sql.term_completer import TermCompleter
8
+ from adam.utils_repl.automata_completer import AutomataCompleter
9
+ from adam.sql.sql_state_machine import AthenaStateMachine, CqlStateMachine, SqlStateMachine
10
+ from adam.utils_repl.state_machine import State
9
11
 
10
12
  __all__ = [
11
13
  "SqlCompleter",
12
14
  ]
13
15
 
14
- DML_COMPLETER = TermCompleter(['select', 'insert', 'delete', 'update'])
15
-
16
- def default_columns(tables: list[str]):
16
+ def default_columns(x: list[str]):
17
17
  return 'id,x.,y.,z.'.split(',')
18
18
 
19
- class SqlCompleter(Completer):
20
- def __init__(self, tables: Callable[[], list[str]], dml: str = None, columns: Callable[[list[str]], list[str]] = default_columns, debug = False):
21
- super().__init__()
22
- self.dml = dml
23
- self.tables = tables
24
- self.columns = columns
25
- self.debug = debug
26
- self.machine = StateMachine(debug=self.debug)
27
-
28
- def get_completions(
29
- self, document: Document, complete_event: CompleteEvent
30
- ) -> Iterable[Completion]:
31
- text = document.text_before_cursor.lstrip()
32
- state = ''
33
- if self.dml:
34
- state = f'{self.dml}_'
35
- text = f'{self.dml} {text}'
36
-
37
- completer: Completer = None
19
+ class SqlVariant(Enum):
20
+ SQL = 'sql'
21
+ CQL = 'cql'
22
+ ATHENA = 'athena'
23
+
24
+ class SqlCompleter(AutomataCompleter[Token]):
25
+ def tokens(self, text: str) -> list[Token]:
26
+ tokens = []
27
+
38
28
  stmts = sqlparse.parse(text)
39
29
  if not stmts:
40
- completer = DML_COMPLETER
30
+ tokens = []
41
31
  else:
42
32
  statement: Statement = stmts[0]
43
- state: StateTo = self.machine.traverse_tokens(statement.tokens, StateTo(state))
44
- if self.debug:
45
- print('\n =>', state.to_s if isinstance(state, StateTo) else '')
46
-
47
- if not state or not state.to_s:
48
- completer = DML_COMPLETER
49
-
50
- if state and state.to_s in self.machine.suggestions:
51
- terms = []
52
-
53
- for word in self.machine.suggestions[state.to_s].strip(' ').split(','):
54
- if word == 'tables':
55
- terms.extend(self.tables())
56
- elif word == 'columns':
57
- terms.extend(self.columns([]))
58
- elif word == 'single':
59
- terms.append("'")
60
- elif word == 'comma':
61
- terms.append(",")
62
- else:
63
- terms.append(word)
64
-
65
- if terms:
66
- completer = TermCompleter(terms)
67
-
68
- if completer:
69
- for c in completer.get_completions(document, complete_event):
70
- yield c
71
-
72
- def completions(table_names: Callable[[], list[str]], columns: Callable[[list[str]], list[str]] = default_columns):
33
+ tokens = statement.tokens
34
+
35
+ return tokens
36
+
37
+ def __init__(self,
38
+ tables: Callable[[], list[str]],
39
+ dml: str = None,
40
+ expandables: dict = {},
41
+ variant: SqlVariant = SqlVariant.SQL,
42
+ debug = False):
43
+ machine = SqlStateMachine(debug=debug)
44
+ if variant == SqlVariant.CQL:
45
+ machine = CqlStateMachine(debug=debug)
46
+ elif variant == SqlVariant.ATHENA:
47
+ machine = AthenaStateMachine(debug=debug)
48
+ super().__init__(machine, dml, debug)
49
+
50
+ self.tables = tables
51
+ if 'columns' not in expandables:
52
+ expandables['columns'] = default_columns
53
+ self.expandables = expandables
54
+ self.variant = variant
55
+ self.debug = debug
56
+
57
+ def suggestions_completer(self, state: State, suggestions: str) -> list[str]:
58
+ if not suggestions:
59
+ return None
60
+
61
+ terms = []
62
+ for suggestion in suggestions.split(','):
63
+ terms.extend(self._terms(state, suggestion))
64
+
65
+ return TermCompleter(terms)
66
+
67
+ def _terms(self, state: State, word: str) -> list[str]:
68
+ terms = []
69
+
70
+ if word.startswith('`') and word.endswith('`'):
71
+ terms.append(word.strip('`'))
72
+ elif word == 'tables':
73
+ terms.extend(self.tables())
74
+ elif word == 'columns':
75
+ if 'last_name' in state.context and (n := state.context['last_name']):
76
+ if 'last_namespace' in state.context and (ns := state.context['last_namespace']):
77
+ n = f'{ns}.{n}'
78
+ terms.extend(self._call_expandable(word, [n]))
79
+ else:
80
+ terms.extend(self._call_expandable(word, []))
81
+ elif word == 'partition-columns':
82
+ terms.extend(self._call_expandable(word, []))
83
+ elif word == 'table-props':
84
+ terms.extend(self._call_expandable(word).keys())
85
+ elif word == 'table-prop-values':
86
+ if 'last_name' in state.context and state.context['last_name']:
87
+ table_props = self._call_expandable('table-props')
88
+ terms.extend(table_props[state.context['last_name']])
89
+ elif word == 'single':
90
+ terms.append("'")
91
+ elif word == 'comma':
92
+ terms.append(",")
93
+ elif word in self.machine.expandable_names():
94
+ terms.extend(self._call_expandable(word))
95
+ else:
96
+ terms.append(word)
97
+
98
+ return terms
99
+
100
+ def _call_expandable(self, name: str, *args):
101
+ if name in self.expandables:
102
+ c = self.expandables[name]
103
+ if args:
104
+ return c(args)
105
+ else:
106
+ return c()
107
+
108
+ return []
109
+
110
+ def completions_for_nesting(self, dml: str = None):
111
+ if dml:
112
+ return {dml: SqlCompleter(self.tables, dml, expandables=self.expandables, variant=self.variant)}
113
+
73
114
  return {
74
- 'delete': SqlCompleter(table_names, 'delete', columns=columns),
75
- 'insert': SqlCompleter(table_names, 'insert', columns=columns),
76
- 'select': SqlCompleter(table_names, 'select', columns=columns),
77
- 'update': SqlCompleter(table_names, 'update', columns=columns),
78
- }
115
+ word: SqlCompleter(self.tables, word, expandables=self.expandables, variant=self.variant)
116
+ for word in self.machine.suggestions[''].strip(' ').split(',')
117
+ }
118
+
119
+ def __str__(self):
120
+ return f'{self.variant}, {self.first_term}'