kaqing 2.0.145__py3-none-any.whl → 2.0.172__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 (172) hide show
  1. adam/__init__.py +0 -2
  2. adam/app_session.py +8 -11
  3. adam/batch.py +3 -3
  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/checks/disk.py +2 -3
  8. adam/columns/columns.py +3 -1
  9. adam/columns/cpu.py +3 -1
  10. adam/columns/cpu_metrics.py +22 -0
  11. adam/columns/memory.py +3 -4
  12. adam/commands/__init__.py +18 -0
  13. adam/commands/alter_tables.py +43 -47
  14. adam/commands/audit/audit.py +22 -23
  15. adam/commands/audit/audit_repair_tables.py +14 -17
  16. adam/commands/audit/audit_run.py +15 -23
  17. adam/commands/audit/show_last10.py +10 -13
  18. adam/commands/audit/show_slow10.py +10 -13
  19. adam/commands/audit/show_top10.py +10 -13
  20. adam/commands/audit/utils_show_top10.py +2 -3
  21. adam/commands/bash/__init__.py +5 -0
  22. adam/commands/bash/bash.py +7 -104
  23. adam/commands/bash/utils_bash.py +16 -0
  24. adam/commands/cat.py +13 -19
  25. adam/commands/cd.py +8 -10
  26. adam/commands/check.py +20 -21
  27. adam/commands/cli_commands.py +2 -3
  28. adam/commands/code.py +20 -23
  29. adam/commands/command.py +120 -39
  30. adam/commands/commands_utils.py +8 -17
  31. adam/commands/cp.py +33 -39
  32. adam/commands/cql/cql_completions.py +9 -4
  33. adam/commands/cql/cqlsh.py +10 -30
  34. adam/commands/cql/{cql_utils.py → utils_cql.py} +149 -15
  35. adam/commands/deploy/code_start.py +7 -10
  36. adam/commands/deploy/code_stop.py +4 -21
  37. adam/commands/deploy/code_utils.py +3 -3
  38. adam/commands/deploy/deploy.py +4 -27
  39. adam/commands/deploy/deploy_frontend.py +14 -17
  40. adam/commands/deploy/deploy_pg_agent.py +2 -5
  41. adam/commands/deploy/deploy_pod.py +64 -68
  42. adam/commands/deploy/undeploy.py +4 -27
  43. adam/commands/deploy/undeploy_frontend.py +4 -7
  44. adam/commands/deploy/undeploy_pg_agent.py +4 -7
  45. adam/commands/deploy/undeploy_pod.py +9 -12
  46. adam/commands/devices/device.py +93 -2
  47. adam/commands/devices/device_app.py +37 -10
  48. adam/commands/devices/device_auit_log.py +8 -2
  49. adam/commands/devices/device_cass.py +47 -7
  50. adam/commands/devices/device_export.py +2 -2
  51. adam/commands/devices/device_postgres.py +41 -6
  52. adam/commands/exit.py +1 -4
  53. adam/commands/export/clean_up_all_export_sessions.py +37 -0
  54. adam/commands/export/clean_up_export_sessions.py +18 -7
  55. adam/commands/export/drop_export_database.py +15 -18
  56. adam/commands/export/drop_export_databases.py +6 -9
  57. adam/commands/export/export.py +8 -38
  58. adam/commands/export/export_databases.py +16 -12
  59. adam/commands/export/export_handlers.py +71 -0
  60. adam/commands/export/export_select.py +33 -24
  61. adam/commands/export/export_use.py +12 -15
  62. adam/commands/export/exporter.py +37 -48
  63. adam/commands/export/import_session.py +4 -32
  64. adam/commands/export/importer_athena.py +4 -7
  65. adam/commands/export/importer_sqlite.py +19 -27
  66. adam/commands/export/show_column_counts.py +13 -22
  67. adam/commands/export/show_export_databases.py +3 -6
  68. adam/commands/export/show_export_session.py +10 -13
  69. adam/commands/export/show_export_sessions.py +8 -11
  70. adam/commands/export/utils_export.py +24 -1
  71. adam/commands/intermediate_command.py +49 -0
  72. adam/commands/issues.py +11 -43
  73. adam/commands/kubectl.py +3 -6
  74. adam/commands/login.py +22 -24
  75. adam/commands/logs.py +3 -6
  76. adam/commands/ls.py +8 -9
  77. adam/commands/medusa/medusa.py +4 -22
  78. adam/commands/medusa/medusa_backup.py +20 -24
  79. adam/commands/medusa/medusa_restore.py +29 -33
  80. adam/commands/medusa/medusa_show_backupjobs.py +14 -18
  81. adam/commands/medusa/medusa_show_restorejobs.py +11 -18
  82. adam/commands/nodetool.py +6 -15
  83. adam/commands/param_get.py +11 -12
  84. adam/commands/param_set.py +9 -10
  85. adam/commands/postgres/postgres.py +29 -37
  86. adam/commands/postgres/postgres_context.py +47 -23
  87. adam/commands/postgres/postgres_ls.py +4 -8
  88. adam/commands/postgres/postgres_preview.py +5 -9
  89. adam/commands/postgres/psql_completions.py +1 -1
  90. adam/commands/postgres/utils_postgres.py +66 -0
  91. adam/commands/preview_table.py +5 -44
  92. adam/commands/pwd.py +13 -16
  93. adam/commands/reaper/reaper.py +4 -27
  94. adam/commands/reaper/reaper_forward.py +48 -55
  95. adam/commands/reaper/reaper_forward_session.py +6 -0
  96. adam/commands/reaper/reaper_forward_stop.py +10 -16
  97. adam/commands/reaper/reaper_restart.py +7 -14
  98. adam/commands/reaper/reaper_run_abort.py +11 -30
  99. adam/commands/reaper/reaper_runs.py +42 -57
  100. adam/commands/reaper/reaper_runs_abort.py +29 -49
  101. adam/commands/reaper/reaper_schedule_activate.py +11 -30
  102. adam/commands/reaper/reaper_schedule_start.py +10 -29
  103. adam/commands/reaper/reaper_schedule_stop.py +10 -29
  104. adam/commands/reaper/reaper_schedules.py +4 -14
  105. adam/commands/reaper/reaper_status.py +8 -16
  106. adam/commands/reaper/utils_reaper.py +196 -0
  107. adam/commands/repair/repair.py +4 -22
  108. adam/commands/repair/repair_log.py +5 -11
  109. adam/commands/repair/repair_run.py +27 -34
  110. adam/commands/repair/repair_scan.py +32 -38
  111. adam/commands/repair/repair_stop.py +5 -11
  112. adam/commands/report.py +27 -29
  113. adam/commands/restart.py +25 -26
  114. adam/commands/rollout.py +19 -24
  115. adam/commands/shell.py +10 -4
  116. adam/commands/show/show.py +10 -26
  117. adam/commands/show/show_cassandra_repairs.py +35 -0
  118. adam/commands/show/show_cassandra_status.py +32 -43
  119. adam/commands/show/show_cassandra_version.py +5 -18
  120. adam/commands/show/show_commands.py +19 -24
  121. adam/commands/show/show_host.py +1 -1
  122. adam/commands/show/show_login.py +20 -27
  123. adam/commands/show/show_processes.py +15 -19
  124. adam/commands/show/show_storage.py +10 -20
  125. adam/commands/watch.py +26 -29
  126. adam/config.py +4 -16
  127. adam/embedded_params.py +1 -1
  128. adam/log.py +4 -4
  129. adam/pod_exec_result.py +3 -3
  130. adam/repl.py +29 -32
  131. adam/repl_commands.py +11 -11
  132. adam/repl_state.py +52 -26
  133. adam/sql/sql_completer.py +4 -6
  134. adam/sql/sql_state_machine.py +21 -14
  135. adam/sso/authn_ad.py +6 -8
  136. adam/sso/authn_okta.py +4 -6
  137. adam/sso/cred_cache.py +3 -5
  138. adam/sso/idp.py +9 -12
  139. adam/utils.py +393 -33
  140. adam/utils_athena.py +14 -13
  141. adam/utils_audits.py +12 -12
  142. adam/utils_issues.py +32 -0
  143. adam/utils_k8s/app_clusters.py +13 -18
  144. adam/utils_k8s/app_pods.py +2 -0
  145. adam/utils_k8s/cassandra_clusters.py +21 -18
  146. adam/utils_k8s/custom_resources.py +16 -17
  147. adam/utils_k8s/ingresses.py +2 -2
  148. adam/utils_k8s/jobs.py +7 -11
  149. adam/utils_k8s/k8s.py +87 -0
  150. adam/utils_k8s/pods.py +14 -76
  151. adam/utils_k8s/secrets.py +4 -4
  152. adam/utils_k8s/service_accounts.py +5 -4
  153. adam/utils_k8s/services.py +2 -2
  154. adam/utils_k8s/statefulsets.py +1 -12
  155. adam/utils_repl/state_machine.py +3 -3
  156. adam/utils_sqlite.py +78 -42
  157. adam/version.py +1 -1
  158. {kaqing-2.0.145.dist-info → kaqing-2.0.172.dist-info}/METADATA +1 -1
  159. kaqing-2.0.172.dist-info/RECORD +230 -0
  160. adam/commands/app.py +0 -67
  161. adam/commands/app_ping.py +0 -44
  162. adam/commands/export/clean_up_export_session.py +0 -53
  163. adam/commands/postgres/postgres_utils.py +0 -31
  164. adam/commands/reaper/reaper_session.py +0 -159
  165. adam/commands/show/show_app_actions.py +0 -56
  166. adam/commands/show/show_app_id.py +0 -47
  167. adam/commands/show/show_app_queues.py +0 -45
  168. adam/commands/show/show_repairs.py +0 -47
  169. kaqing-2.0.145.dist-info/RECORD +0 -227
  170. {kaqing-2.0.145.dist-info → kaqing-2.0.172.dist-info}/WHEEL +0 -0
  171. {kaqing-2.0.145.dist-info → kaqing-2.0.172.dist-info}/entry_points.txt +0 -0
  172. {kaqing-2.0.145.dist-info → kaqing-2.0.172.dist-info}/top_level.txt +0 -0
adam/commands/kubectl.py CHANGED
@@ -25,13 +25,10 @@ class Kubectl(Command):
25
25
  if not(args := self.args(cmd)):
26
26
  return super().run(cmd, state)
27
27
 
28
- state, args = self.apply_state(args, state)
29
- if not self.validate_state(state):
30
- return state
31
-
32
- subprocess.run(["kubectl"] + args)
28
+ with self.validate(args, state) as (args, state):
29
+ subprocess.run(["kubectl"] + args)
33
30
 
34
- return state
31
+ return state
35
32
 
36
33
  def completion(self, state: ReplState):
37
34
  return super().completion(state)
adam/commands/login.py CHANGED
@@ -1,15 +1,15 @@
1
1
  import os
2
2
  import signal
3
- import traceback
4
3
 
5
4
  from adam.app_session import AppSession
6
5
  from adam.apps import Apps
6
+ from adam.commands import extract_options
7
7
  from adam.config import Config
8
8
  from adam.sso.idp import Idp
9
9
  from adam.sso.idp_login import IdpLogin
10
10
  from adam.commands.command import Command
11
- from adam.repl_state import ReplState, RequiredState
12
- from adam.utils import log, log2
11
+ from adam.repl_state import ReplState
12
+ from adam.utils import log, log2, log_exc
13
13
 
14
14
  class Login(Command):
15
15
  COMMAND = 'login'
@@ -30,37 +30,35 @@ class Login(Command):
30
30
  return ReplState.NON_L
31
31
 
32
32
  def run(self, cmd: str, state: ReplState):
33
+ if not(args := self.args(cmd)):
34
+ return super().run(cmd, state)
35
+
33
36
  def custom_handler(signum, frame):
34
37
  AppSession.ctrl_c_entered = True
35
38
 
36
39
  signal.signal(signal.SIGINT, custom_handler)
37
40
 
38
- if not(args := self.args(cmd)):
39
- return super().run(cmd, state)
40
-
41
- state, args = self.apply_state(args, state)
42
- args, debug = Command.extract_options(args, ['d'])
43
- if debug:
44
- Config().set('debug', True)
41
+ with self.validate(args, state) as (args, state):
42
+ with extract_options(args, 'd') as (args, debug):
43
+ if debug:
44
+ Config().set('debug', True)
45
45
 
46
- username: str = os.getenv('USERNAME')
47
- if len(args) > 0:
48
- username = args[0]
46
+ username: str = os.getenv('USERNAME')
47
+ if len(args) > 0:
48
+ username = args[0]
49
49
 
50
- login: IdpLogin = None
51
- try:
52
- if not(host := Apps.app_host('c3', 'c3', state.namespace)):
53
- log2('Cannot locate ingress for app.')
54
- return state
50
+ login: IdpLogin = None
51
+ with log_exc(True):
52
+ if not(host := Apps.app_host('c3', 'c3', state.namespace)):
53
+ log2('Cannot locate ingress for app.')
54
+ return state
55
55
 
56
- if not (login := Idp.login(host, username=username, use_token_from_env=False)):
57
- log2('Invalid username/password. Please try again.')
58
- except:
59
- log2(traceback.format_exc())
56
+ if not (login := Idp.login(host, username=username, use_token_from_env=False)):
57
+ log2('Invalid username/password. Please try again.')
60
58
 
61
- log(f'IDP_TOKEN={login.ser() if login else ""}')
59
+ log(f'IDP_TOKEN={login.ser() if login else ""}')
62
60
 
63
- return state
61
+ return state
64
62
 
65
63
  def completion(self, state: ReplState):
66
64
  return super().completion(state)
adam/commands/logs.py CHANGED
@@ -25,12 +25,9 @@ class Logs(Command):
25
25
  if not(args := self.args(cmd)):
26
26
  return super().run(cmd, state)
27
27
 
28
- state, args = self.apply_state(args, state)
29
- if not self.validate_state(state):
30
- return state
31
-
32
- path = Config().get('logs.path', '/c3/cassandra/logs/system.log')
33
- return CassandraNodes.exec(state.pod, state.namespace, f'cat {path}')
28
+ with self.validate(args, state) as (args, state):
29
+ path = Config().get('logs.path', '/c3/cassandra/logs/system.log')
30
+ return CassandraNodes.exec(state.pod, state.namespace, f'cat {path}')
34
31
 
35
32
  def completion(self, _: ReplState):
36
33
  # available only on cli
adam/commands/ls.py CHANGED
@@ -23,17 +23,16 @@ class Ls(Command):
23
23
  if not(args := self.args(cmd)):
24
24
  return super().run(cmd, state)
25
25
 
26
- state, args = self.apply_state(args, state)
26
+ with self.validate(args, state) as (args, state):
27
+ if len(args) > 0:
28
+ arg = args[0]
29
+ if arg in ['p:', 'c:'] and arg != f'{state.device}:':
30
+ state = copy.copy(state)
31
+ state.device = arg.replace(':', '')
27
32
 
28
- if len(args) > 0:
29
- arg = args[0]
30
- if arg in ['p:', 'c:'] and arg != f'{state.device}:':
31
- state = copy.copy(state)
32
- state.device = arg.replace(':', '')
33
+ Devices.device(state).ls(cmd, state)
33
34
 
34
- Devices.device(state).ls(cmd, state)
35
-
36
- return state
35
+ return state
37
36
 
38
37
  def completion(self, state: ReplState):
39
38
  return Devices.device(state).ls_completion(Ls.COMMAND, state, default = super().completion(state))
@@ -1,13 +1,13 @@
1
1
  import click
2
2
 
3
3
  from adam.commands.command import Command
4
+ from adam.commands.intermediate_command import IntermediateCommand
4
5
  from .medusa_backup import MedusaBackup
5
6
  from .medusa_restore import MedusaRestore
6
7
  from .medusa_show_backupjobs import MedusaShowBackupJobs
7
8
  from .medusa_show_restorejobs import MedusaShowRestoreJobs
8
- from adam.repl_state import ReplState, RequiredState
9
9
 
10
- class Medusa(Command):
10
+ class Medusa(IntermediateCommand):
11
11
  COMMAND = 'medusa'
12
12
 
13
13
  # the singleton pattern
@@ -16,30 +16,12 @@ class Medusa(Command):
16
16
 
17
17
  return cls.instance
18
18
 
19
- def __init__(self, successor: Command=None):
20
- super().__init__(successor)
21
-
22
19
  def command(self):
23
20
  return Medusa.COMMAND
24
21
 
25
- def required(self):
26
- return RequiredState.CLUSTER
27
-
28
- def run(self, cmd: str, state: ReplState):
29
- if not(args := self.args(cmd)):
30
- return super().run(cmd, state)
31
-
32
- return super().intermediate_run(cmd, state, args, Medusa.cmd_list())
33
-
34
- def cmd_list():
22
+ def cmd_list(self):
35
23
  return [MedusaBackup(), MedusaRestore(), MedusaShowBackupJobs(), MedusaShowRestoreJobs()]
36
24
 
37
- def completion(self, state: ReplState):
38
- if state.sts:
39
- return super().completion(state)
40
-
41
- return {}
42
-
43
25
  class MedusaCommandHelper(click.Command):
44
26
  def get_help(self, ctx: click.Context):
45
- Command.intermediate_help(super().get_help(ctx), Medusa.COMMAND, Medusa.cmd_list(), show_cluster_help=True)
27
+ IntermediateCommand.intermediate_help(super().get_help(ctx), Medusa.COMMAND, Medusa().cmd_list(), show_cluster_help=True)
@@ -7,7 +7,6 @@ from adam.repl_state import ReplState, RequiredState
7
7
  from adam.utils_k8s.custom_resources import CustomResources
8
8
  from adam.utils import log2
9
9
 
10
-
11
10
  class MedusaBackup(Command):
12
11
  COMMAND = 'backup'
13
12
 
@@ -29,33 +28,30 @@ class MedusaBackup(Command):
29
28
  def run(self, cmd: str, state: ReplState):
30
29
  if not(args := self.args(cmd)):
31
30
  return super().run(cmd, state)
32
- state, args = self.apply_state(args, state)
33
- if not self.validate_state(state):
34
- return state
35
-
36
- ns = state.namespace
37
- sts = state.sts
38
- now_dtformat = datetime.now().strftime("%Y-%m-%d.%H.%M.%S")
39
- bkname = 'medusa-' + now_dtformat + 'full-backup-' + sts
40
- if len(args) == 1:
41
- bkname = str(args[0])
42
- groups = re.match(r'^(.*?-.*?-).*', sts)
43
- dc = StatefulSets.get_datacenter(state.sts, ns)
44
- if not dc:
45
- return state
46
31
 
47
- try:
48
- CustomResources.create_medusa_backupjob(bkname, dc, ns)
49
- except Exception as e:
50
- log2("Exception: MedusaBackup failed: %s\n" % e)
32
+ with self.validate(args, state) as (args, state):
33
+ ns = state.namespace
34
+ sts = state.sts
35
+ now_dtformat = datetime.now().strftime("%Y-%m-%d.%H.%M.%S")
36
+ bkname = 'medusa-' + now_dtformat + 'full-backup-' + sts
37
+ if len(args) == 1:
38
+ bkname = str(args[0])
39
+ groups = re.match(r'^(.*?-.*?-).*', sts)
40
+ dc = StatefulSets.get_datacenter(state.sts, ns)
41
+ if not dc:
42
+ return state
43
+
44
+ try:
45
+ CustomResources.create_medusa_backupjob(bkname, dc, ns)
46
+ except Exception as e:
47
+ log2("Exception: MedusaBackup failed: %s\n" % e)
48
+ finally:
49
+ CustomResources.clear_caches()
51
50
 
52
- return state
51
+ return state
53
52
 
54
53
  def completion(self, state: ReplState):
55
- if state.sts:
56
- return super().completion(state)
57
-
58
- return {}
54
+ return super().completion(state)
59
55
 
60
56
  def help(self, _: ReplState):
61
57
  return f'{MedusaBackup.COMMAND}\t start a backup job'
@@ -5,7 +5,7 @@ from adam.utils_k8s.statefulsets import StatefulSets
5
5
  from adam.repl_state import ReplState, RequiredState
6
6
  from adam.utils_k8s.custom_resources import CustomResources
7
7
  from adam.config import Config
8
- from adam.utils import lines_to_tabular, log2
8
+ from adam.utils import lines_to_tabular, log2, log_exc
9
9
 
10
10
  class MedusaRestore(Command):
11
11
  COMMAND = 'restore'
@@ -28,47 +28,43 @@ class MedusaRestore(Command):
28
28
  def run(self, cmd: str, state: ReplState):
29
29
  if not(args := self.args(cmd)):
30
30
  return super().run(cmd, state)
31
- state, args = self.apply_state(args, state)
32
- if not self.validate_state(state):
33
- return state
34
31
 
35
- ns = state.namespace
36
- dc = StatefulSets.get_datacenter(state.sts, ns)
37
- if not dc:
38
- return state
32
+ with self.validate(args, state) as (args, state):
33
+ ns = state.namespace
34
+ dc: str = StatefulSets.get_datacenter(state.sts, ns)
35
+ if not dc:
36
+ return state
39
37
 
40
- if len(args) == 1:
41
- bkname = args[0]
42
- job = CustomResources.medusa_get_backupjob(dc, ns, bkname)
43
- if not job:
44
- log2('\n* Backup job name is not valid.')
45
- bklist = [f"{x['metadata']['name']}\t{x['metadata']['creationTimestamp']}\t{x['status'].get('finishTime', '')}" for x in CustomResources.medusa_show_backupjobs(dc, ns)]
46
- log2(lines_to_tabular(bklist, 'NAME\tCREATED\tFINISHED', separator='\t'))
38
+ if len(args) == 1:
39
+ bkname = args[0]
40
+ job = CustomResources.medusa_get_backupjob(dc, ns, bkname)
41
+ if not job:
42
+ log2('\n* Backup job name is not valid.')
43
+ bklist = [f"{x['metadata']['name']}\t{x['metadata']['creationTimestamp']}\t{x['status'].get('finishTime', '')}" for x in CustomResources.medusa_show_backupjobs(dc, ns)]
44
+ log2(lines_to_tabular(bklist, 'NAME\tCREATED\tFINISHED', separator='\t'))
47
45
 
48
- return state
46
+ return state
49
47
 
50
- if not input(f"Restoring from {bkname} created at {job['metadata']['creationTimestamp']}. Please enter Yes to continue: ").lower() in ['y', 'yes']:
48
+ if not input(f"Restoring from {bkname} created at {job['metadata']['creationTimestamp']}. Please enter Yes to continue: ").lower() in ['y', 'yes']:
49
+ return state
50
+ else:
51
+ bklist = [f"{x['metadata']['name']}\t{x['metadata']['creationTimestamp']}\t{x['status'].get('finishTime', '')}" for x in CustomResources.medusa_show_backupjobs(dc, ns)]
52
+ log2('\n* Missing Backup Name')
53
+ log2('Usage: qing medusa restore <backup> <sts@name_space>\n')
54
+ log2(lines_to_tabular(bklist, 'NAME\tCREATED\tFINISHED', separator='\t'))
51
55
  return state
52
- else:
53
- bklist = [f"{x['metadata']['name']}\t{x['metadata']['creationTimestamp']}\t{x['status'].get('finishTime', '')}" for x in CustomResources.medusa_show_backupjobs(dc, ns)]
54
- log2('\n* Missing Backup Name')
55
- log2('Usage: qing medusa restore <backup> <sts@name_space>\n')
56
- log2(lines_to_tabular(bklist, 'NAME\tCREATED\tFINISHED', separator='\t'))
57
- return state
58
56
 
59
- now_dtformat = datetime.now().strftime("%Y-%m-%d.%H.%M.%S")
60
- rtname = 'medusa-' + now_dtformat + '-restore-from-' + bkname
61
- try:
62
- CustomResources.create_medusa_restorejob(rtname, bkname, dc, ns)
63
- except Exception as e:
64
- log2("Exception: MedusaRestore failed: %s\n" % e)
57
+ now_dtformat = datetime.now().strftime("%Y-%m-%d.%H.%M.%S")
58
+ rtname = 'medusa-' + now_dtformat + '-restore-from-' + bkname
59
+ with log_exc(lambda e: "Exception: MedusaRestore failed: %s\n" % e):
60
+ CustomResources.create_medusa_restorejob(rtname, bkname, dc, ns)
65
61
 
66
- return state
62
+ return state
67
63
 
68
64
  def completion(self, state: ReplState):
69
- if state.sts:
65
+ if sc := super().completion(state):
70
66
  ns = state.namespace
71
- dc = StatefulSets.get_datacenter(state.sts, ns)
67
+ dc: str = StatefulSets.get_datacenter(state.sts, ns)
72
68
  if not dc:
73
69
  return {}
74
70
 
@@ -77,7 +73,7 @@ class MedusaRestore(Command):
77
73
 
78
74
  return super().completion(state, leaf)
79
75
  else:
80
- return super().completion(state)
76
+ return sc
81
77
 
82
78
  return {}
83
79
 
@@ -2,7 +2,7 @@ from adam.commands.command import Command
2
2
  from adam.utils_k8s.statefulsets import StatefulSets
3
3
  from adam.repl_state import ReplState, RequiredState
4
4
  from adam.utils_k8s.custom_resources import CustomResources
5
- from adam.utils import lines_to_tabular, log2
5
+ from adam.utils import lines_to_tabular, log2, log_exc
6
6
 
7
7
 
8
8
  class MedusaShowBackupJobs(Command):
@@ -26,28 +26,24 @@ class MedusaShowBackupJobs(Command):
26
26
  def run(self, cmd: str, state: ReplState):
27
27
  if not(args := self.args(cmd)):
28
28
  return super().run(cmd, state)
29
- state, args = self.apply_state(args, state)
30
- if not self.validate_state(state):
31
- return state
32
29
 
33
- ns = state.namespace
34
- dc = StatefulSets.get_datacenter(state.sts, ns)
35
- if not dc:
36
- return state
30
+ with self.validate(args, state) as (args, state):
31
+ ns = state.namespace
32
+ dc = StatefulSets.get_datacenter(state.sts, ns)
33
+ if not dc:
34
+ return state
37
35
 
38
- try:
39
- bklist = [f"{x['metadata']['name']}\t{x['metadata']['creationTimestamp']}\t{x['status'].get('finishTime', '')}" for x in CustomResources.medusa_show_backupjobs(dc, ns)]
40
- log2(lines_to_tabular(bklist, 'NAME\tCREATED\tFINISHED', separator='\t'))
41
- except Exception as e:
42
- log2("Exception: MedusaShowBackupJobs failed: %s\n" % e)
36
+ # try:
37
+ with log_exc(lambda e: "Exception: MedusaShowBackupJobs failed: %s\n" % e):
38
+ CustomResources.clear_caches()
43
39
 
44
- return state
40
+ bklist = [f"{x['metadata']['name']}\t{x['metadata']['creationTimestamp']}\t{x['status'].get('finishTime', '') if 'status' in x else 'unknown'}" for x in CustomResources.medusa_show_backupjobs(dc, ns)]
41
+ log2(lines_to_tabular(bklist, 'NAME\tCREATED\tFINISHED', separator='\t'))
45
42
 
46
- def completion(self, state: ReplState):
47
- if state.sts:
48
- return super().completion(state)
43
+ return state
49
44
 
50
- return {}
45
+ def completion(self, state: ReplState):
46
+ return super().completion(state)
51
47
 
52
48
  def help(self, _: ReplState):
53
49
  return f'{MedusaShowBackupJobs.COMMAND}\t show Medusa backups'
@@ -2,7 +2,7 @@ from adam.commands.command import Command
2
2
  from adam.utils_k8s.statefulsets import StatefulSets
3
3
  from adam.repl_state import ReplState, RequiredState
4
4
  from adam.utils_k8s.custom_resources import CustomResources
5
- from adam.utils import lines_to_tabular, log2
5
+ from adam.utils import lines_to_tabular, log2, log_exc
6
6
 
7
7
  class MedusaShowRestoreJobs(Command):
8
8
  COMMAND = 'show restores'
@@ -25,28 +25,21 @@ class MedusaShowRestoreJobs(Command):
25
25
  def run(self, cmd: str, state: ReplState):
26
26
  if not(args := self.args(cmd)):
27
27
  return super().run(cmd, state)
28
- state, args = self.apply_state(args, state)
29
- if not self.validate_state(state):
30
- return state
31
28
 
32
- ns = state.namespace
33
- dc = StatefulSets.get_datacenter(state.sts, ns)
34
- if not dc:
35
- return state
29
+ with self.validate(args, state) as (args, state):
30
+ ns = state.namespace
31
+ dc = StatefulSets.get_datacenter(state.sts, ns)
32
+ if not dc:
33
+ return state
36
34
 
37
- try:
38
- rtlist = CustomResources.medusa_show_restorejobs(dc, ns)
39
- log2(lines_to_tabular(rtlist, 'NAME\tCREATED\tFINISHED', separator='\t'))
40
- except Exception as e:
41
- log2("Exception: MedusaShowRestoreJobs failed: %s\n" % e)
35
+ with log_exc(lambda e: "Exception: MedusaShowRestoreJobs failed: %s\n" % e):
36
+ rtlist = CustomResources.medusa_show_restorejobs(dc, ns)
37
+ log2(lines_to_tabular(rtlist, 'NAME\tCREATED\tFINISHED', separator='\t'))
42
38
 
43
- return state
39
+ return state
44
40
 
45
41
  def completion(self, state: ReplState):
46
- if state.sts:
47
- return super().completion(state)
48
-
49
- return {}
42
+ return super().completion(state)
50
43
 
51
44
  def help(self, _: ReplState):
52
45
  return f'{MedusaShowRestoreJobs.COMMAND}\t show Medusa restores'
adam/commands/nodetool.py CHANGED
@@ -2,10 +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_cql import cassandra
5
6
  from adam.commands.nodetool_commands import NODETOOL_COMMANDS
6
7
  from adam.config import Config
7
- from adam.utils_k8s.cassandra_clusters import CassandraClusters
8
- from adam.utils_k8s.cassandra_nodes import CassandraNodes
9
8
  from adam.repl_state import ReplState, RequiredState
10
9
  from adam.utils import log
11
10
  from adam.utils_k8s.statefulsets import StatefulSets
@@ -32,22 +31,14 @@ class NodeTool(Command):
32
31
  if not(args := self.args(cmd)):
33
32
  return super().run(cmd, state)
34
33
 
35
- state, args = self.apply_state(args, state)
36
- if not self.validate_state(state):
37
- return state
38
-
39
- user, pw = state.user_pass()
40
- command = f"nodetool -u {user} -pw {pw} {' '.join(args)}"
34
+ with self.validate(args, state) as (args, state):
35
+ with cassandra(state) as pods:
36
+ pods.nodetool(' '.join(args))
41
37
 
42
- if state.pod:
43
- return CassandraNodes.exec(state.pod, state.namespace, command, show_out=True)
44
- elif state.sts:
45
- return CassandraClusters.exec(state.sts, state.namespace, command, action='nodetool', show_out=True)
46
-
47
- return state
38
+ return state
48
39
 
49
40
  def completion(self, state: ReplState):
50
- if state.pod or state.sts:
41
+ if super().completion(state):
51
42
  d = {c: {'&': None} for c in NODETOOL_COMMANDS}
52
43
  return {NodeTool.COMMAND: {'help': None} | d} | \
53
44
  {f'@{p}': {NodeTool.COMMAND: d} for p in StatefulSets.pod_names(state.sts, state.namespace)}
@@ -22,21 +22,20 @@ class GetParam(Command):
22
22
  if not(args := self.args(cmd)):
23
23
  return super().run(cmd, state)
24
24
 
25
- state, args = self.apply_state(args, state)
25
+ with self.validate(args, state) as (args, state):
26
+ if len(args) < 1:
27
+ lines = [f'{key}\t{Config().get(key, None)}' for key in Config().keys()]
28
+ log(lines_to_tabular(lines, separator='\t'))
26
29
 
27
- if len(args) < 1:
28
- lines = [f'{key}\t{Config().get(key, None)}' for key in Config().keys()]
29
- log(lines_to_tabular(lines, separator='\t'))
30
+ return state
30
31
 
31
- return state
32
+ key = args[0]
33
+ if v := Config().get(key, None):
34
+ log(v)
35
+ else:
36
+ log2(f'{key} is not set.')
32
37
 
33
- key = args[0]
34
- if v := Config().get(key, None):
35
- log(v)
36
- else:
37
- log2(f'{key} is not set.')
38
-
39
- return v if v else state
38
+ return v if v else state
40
39
 
41
40
  def completion(self, _: ReplState):
42
41
  return {GetParam.COMMAND: {key: None for key in Config().keys()}}
@@ -22,20 +22,19 @@ class SetParam(Command):
22
22
  if not(args := self.args(cmd)):
23
23
  return super().run(cmd, state)
24
24
 
25
- state, args = self.apply_state(args, state)
25
+ with self.validate(args, state) as (args, state):
26
+ if len(args) < 2:
27
+ log2('set <key> <value>')
26
28
 
27
- if len(args) < 2:
28
- log2('set <key> <value>')
29
+ return 'invalid args'
29
30
 
30
- return 'invalid args'
31
+ key = args[0]
32
+ value = args[1]
33
+ Config().set(key, value)
31
34
 
32
- key = args[0]
33
- value = args[1]
34
- Config().set(key, value)
35
+ log(Config().get(key, None))
35
36
 
36
- log(Config().get(key, None))
37
-
38
- return value
37
+ return value
39
38
 
40
39
  def completion(self, _: ReplState):
41
40
  return {SetParam.COMMAND: {key: ({'true': None, 'false': None} if Config().get(key, None) in [True, False] else None) for key in Config().keys()}}
@@ -1,17 +1,18 @@
1
1
  import click
2
2
 
3
+ from adam.commands import extract_trailing_options
3
4
  from adam.commands.command import Command
5
+ from adam.commands.intermediate_command import IntermediateCommand
4
6
  from adam.commands.postgres.psql_completions import psql_completions
5
- from adam.commands.postgres.postgres_utils import pg_table_names
7
+ from adam.commands.postgres.utils_postgres import pg_table_names, postgres
6
8
  from .postgres_ls import PostgresLs
7
9
  from .postgres_preview import PostgresPreview
8
10
  from .postgres_context import PostgresContext
9
11
  from adam.repl_state import ReplState
10
12
  from adam.utils import log, log2
11
13
 
12
- class Postgres(Command):
14
+ class Postgres(IntermediateCommand):
13
15
  COMMAND = 'pg'
14
- reaper_login = None
15
16
 
16
17
  # the singleton pattern
17
18
  def __new__(cls, *args, **kwargs):
@@ -29,45 +30,36 @@ class Postgres(Command):
29
30
  if not(args := self.args(cmd)):
30
31
  return super().run(cmd, state)
31
32
 
32
- state, args = self.apply_state(args, state)
33
+ with self.validate(args, state) as (args, state):
34
+ with extract_trailing_options(args, '&') as (args, backgrounded):
35
+ if not args:
36
+ if state.in_repl:
37
+ log2('Please use SQL statement. e.g. pg \l')
38
+ else:
39
+ log2('* Command or SQL statements is missing.')
40
+ Command.display_help()
33
41
 
34
- if not args:
35
- if state.in_repl:
36
- log2('Please use SQL statement. e.g. pg \l')
37
- else:
38
- log2('* Command or SQL statements is missing.')
39
- Command.display_help()
42
+ return 'command-missing'
40
43
 
41
- return 'command-missing'
44
+ if not state.pg_path:
45
+ if state.in_repl:
46
+ log2('Enter "use <pg-name>" first.')
47
+ else:
48
+ log2('* pg-name is missing.')
42
49
 
43
- if state.in_repl:
44
- self.run_sql(state, args)
45
- else:
46
- # head with the Chain of Responsibility pattern
47
- cmds = Command.chain(Postgres.cmd_list())
48
- if not cmds.run(cmd, state) :
49
- self.run_sql(state, args)
50
-
51
- return state
52
-
53
- def cmd_list():
54
- return [PostgresLs(), PostgresPreview(), PostgresPg()]
55
-
56
- def run_sql(self, state: ReplState, args: list[str]):
57
- if not state.pg_path:
58
- if state.in_repl:
59
- log2('Enter "use <pg-name>" first.')
60
- else:
61
- log2('* pg-name is missing.')
50
+ return state
62
51
 
63
- return state
52
+ if state.in_repl:
53
+ with postgres(state) as pod:
54
+ pod.sql(args, background=backgrounded)
55
+ elif not self.run_subcommand(cmd, state):
56
+ with postgres(state) as pod:
57
+ pod.sql(args, background=backgrounded)
64
58
 
65
- background = False
66
- if args and args[-1] == '&':
67
- args = args[:-1]
68
- background = True
59
+ return state
69
60
 
70
- PostgresContext.apply(state.namespace, state.pg_path).run_sql(' '.join(args), background=background)
61
+ def cmd_list(self):
62
+ return [PostgresLs(), PostgresPreview(), PostgresPg()]
71
63
 
72
64
  def completion(self, state: ReplState):
73
65
  if state.device != state.P:
@@ -95,7 +87,7 @@ class Postgres(Command):
95
87
 
96
88
  class PostgresCommandHelper(click.Command):
97
89
  def get_help(self, ctx: click.Context):
98
- Command.intermediate_help(super().get_help(ctx), Postgres.COMMAND, Postgres.cmd_list(), show_cluster_help=True)
90
+ IntermediateCommand.intermediate_help(super().get_help(ctx), Postgres.COMMAND, Postgres().cmd_list(), show_cluster_help=True)
99
91
  log('PG-Name: Kubernetes secret for Postgres credentials')
100
92
  log(' e.g. stgawsscpsr-c3-c3-k8spg-cs-001')
101
93
  log('Database: Postgres database name within a host')