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.
- adam/__init__.py +0 -2
- adam/app_session.py +8 -11
- adam/batch.py +3 -3
- adam/checks/check_utils.py +14 -46
- adam/checks/cpu.py +7 -1
- adam/checks/cpu_metrics.py +52 -0
- adam/checks/disk.py +2 -3
- adam/columns/columns.py +3 -1
- adam/columns/cpu.py +3 -1
- adam/columns/cpu_metrics.py +22 -0
- adam/columns/memory.py +3 -4
- adam/commands/__init__.py +18 -0
- adam/commands/alter_tables.py +43 -47
- adam/commands/audit/audit.py +22 -23
- adam/commands/audit/audit_repair_tables.py +14 -17
- adam/commands/audit/audit_run.py +15 -23
- adam/commands/audit/show_last10.py +10 -13
- adam/commands/audit/show_slow10.py +10 -13
- adam/commands/audit/show_top10.py +10 -13
- adam/commands/audit/utils_show_top10.py +2 -3
- adam/commands/bash/__init__.py +5 -0
- adam/commands/bash/bash.py +7 -104
- adam/commands/bash/utils_bash.py +16 -0
- adam/commands/cat.py +13 -19
- adam/commands/cd.py +8 -10
- adam/commands/check.py +20 -21
- adam/commands/cli_commands.py +2 -3
- adam/commands/code.py +20 -23
- adam/commands/command.py +120 -39
- adam/commands/commands_utils.py +8 -17
- adam/commands/cp.py +33 -39
- adam/commands/cql/cql_completions.py +9 -4
- adam/commands/cql/cqlsh.py +10 -30
- adam/commands/cql/{cql_utils.py → utils_cql.py} +149 -15
- adam/commands/deploy/code_start.py +7 -10
- adam/commands/deploy/code_stop.py +4 -21
- adam/commands/deploy/code_utils.py +3 -3
- adam/commands/deploy/deploy.py +4 -27
- adam/commands/deploy/deploy_frontend.py +14 -17
- adam/commands/deploy/deploy_pg_agent.py +2 -5
- adam/commands/deploy/deploy_pod.py +64 -68
- adam/commands/deploy/undeploy.py +4 -27
- adam/commands/deploy/undeploy_frontend.py +4 -7
- adam/commands/deploy/undeploy_pg_agent.py +4 -7
- adam/commands/deploy/undeploy_pod.py +9 -12
- adam/commands/devices/device.py +93 -2
- adam/commands/devices/device_app.py +37 -10
- adam/commands/devices/device_auit_log.py +8 -2
- adam/commands/devices/device_cass.py +47 -7
- adam/commands/devices/device_export.py +2 -2
- adam/commands/devices/device_postgres.py +41 -6
- adam/commands/exit.py +1 -4
- adam/commands/export/clean_up_all_export_sessions.py +37 -0
- adam/commands/export/clean_up_export_sessions.py +18 -7
- adam/commands/export/drop_export_database.py +15 -18
- adam/commands/export/drop_export_databases.py +6 -9
- adam/commands/export/export.py +8 -38
- adam/commands/export/export_databases.py +16 -12
- adam/commands/export/export_handlers.py +71 -0
- adam/commands/export/export_select.py +33 -24
- adam/commands/export/export_use.py +12 -15
- adam/commands/export/exporter.py +37 -48
- adam/commands/export/import_session.py +4 -32
- adam/commands/export/importer_athena.py +4 -7
- adam/commands/export/importer_sqlite.py +19 -27
- adam/commands/export/show_column_counts.py +13 -22
- adam/commands/export/show_export_databases.py +3 -6
- adam/commands/export/show_export_session.py +10 -13
- adam/commands/export/show_export_sessions.py +8 -11
- adam/commands/export/utils_export.py +24 -1
- adam/commands/intermediate_command.py +49 -0
- adam/commands/issues.py +11 -43
- adam/commands/kubectl.py +3 -6
- adam/commands/login.py +22 -24
- adam/commands/logs.py +3 -6
- adam/commands/ls.py +8 -9
- adam/commands/medusa/medusa.py +4 -22
- adam/commands/medusa/medusa_backup.py +20 -24
- adam/commands/medusa/medusa_restore.py +29 -33
- adam/commands/medusa/medusa_show_backupjobs.py +14 -18
- adam/commands/medusa/medusa_show_restorejobs.py +11 -18
- adam/commands/nodetool.py +6 -15
- adam/commands/param_get.py +11 -12
- adam/commands/param_set.py +9 -10
- adam/commands/postgres/postgres.py +29 -37
- adam/commands/postgres/postgres_context.py +47 -23
- adam/commands/postgres/postgres_ls.py +4 -8
- adam/commands/postgres/postgres_preview.py +5 -9
- adam/commands/postgres/psql_completions.py +1 -1
- adam/commands/postgres/utils_postgres.py +66 -0
- adam/commands/preview_table.py +5 -44
- adam/commands/pwd.py +13 -16
- adam/commands/reaper/reaper.py +4 -27
- adam/commands/reaper/reaper_forward.py +48 -55
- adam/commands/reaper/reaper_forward_session.py +6 -0
- adam/commands/reaper/reaper_forward_stop.py +10 -16
- adam/commands/reaper/reaper_restart.py +7 -14
- adam/commands/reaper/reaper_run_abort.py +11 -30
- adam/commands/reaper/reaper_runs.py +42 -57
- adam/commands/reaper/reaper_runs_abort.py +29 -49
- adam/commands/reaper/reaper_schedule_activate.py +11 -30
- adam/commands/reaper/reaper_schedule_start.py +10 -29
- adam/commands/reaper/reaper_schedule_stop.py +10 -29
- adam/commands/reaper/reaper_schedules.py +4 -14
- adam/commands/reaper/reaper_status.py +8 -16
- adam/commands/reaper/utils_reaper.py +196 -0
- adam/commands/repair/repair.py +4 -22
- adam/commands/repair/repair_log.py +5 -11
- adam/commands/repair/repair_run.py +27 -34
- adam/commands/repair/repair_scan.py +32 -38
- adam/commands/repair/repair_stop.py +5 -11
- adam/commands/report.py +27 -29
- adam/commands/restart.py +25 -26
- adam/commands/rollout.py +19 -24
- adam/commands/shell.py +10 -4
- adam/commands/show/show.py +10 -26
- adam/commands/show/show_cassandra_repairs.py +35 -0
- adam/commands/show/show_cassandra_status.py +32 -43
- adam/commands/show/show_cassandra_version.py +5 -18
- adam/commands/show/show_commands.py +19 -24
- adam/commands/show/show_host.py +1 -1
- adam/commands/show/show_login.py +20 -27
- adam/commands/show/show_processes.py +15 -19
- adam/commands/show/show_storage.py +10 -20
- adam/commands/watch.py +26 -29
- adam/config.py +4 -16
- adam/embedded_params.py +1 -1
- adam/log.py +4 -4
- adam/pod_exec_result.py +3 -3
- adam/repl.py +29 -32
- adam/repl_commands.py +11 -11
- adam/repl_state.py +52 -26
- adam/sql/sql_completer.py +4 -6
- adam/sql/sql_state_machine.py +21 -14
- adam/sso/authn_ad.py +6 -8
- adam/sso/authn_okta.py +4 -6
- adam/sso/cred_cache.py +3 -5
- adam/sso/idp.py +9 -12
- adam/utils.py +393 -33
- adam/utils_athena.py +14 -13
- adam/utils_audits.py +12 -12
- adam/utils_issues.py +32 -0
- adam/utils_k8s/app_clusters.py +13 -18
- adam/utils_k8s/app_pods.py +2 -0
- adam/utils_k8s/cassandra_clusters.py +21 -18
- adam/utils_k8s/custom_resources.py +16 -17
- adam/utils_k8s/ingresses.py +2 -2
- adam/utils_k8s/jobs.py +7 -11
- adam/utils_k8s/k8s.py +87 -0
- adam/utils_k8s/pods.py +14 -76
- adam/utils_k8s/secrets.py +4 -4
- adam/utils_k8s/service_accounts.py +5 -4
- adam/utils_k8s/services.py +2 -2
- adam/utils_k8s/statefulsets.py +1 -12
- adam/utils_repl/state_machine.py +3 -3
- adam/utils_sqlite.py +78 -42
- adam/version.py +1 -1
- {kaqing-2.0.145.dist-info → kaqing-2.0.172.dist-info}/METADATA +1 -1
- kaqing-2.0.172.dist-info/RECORD +230 -0
- adam/commands/app.py +0 -67
- adam/commands/app_ping.py +0 -44
- adam/commands/export/clean_up_export_session.py +0 -53
- adam/commands/postgres/postgres_utils.py +0 -31
- adam/commands/reaper/reaper_session.py +0 -159
- adam/commands/show/show_app_actions.py +0 -56
- adam/commands/show/show_app_id.py +0 -47
- adam/commands/show/show_app_queues.py +0 -45
- adam/commands/show/show_repairs.py +0 -47
- kaqing-2.0.145.dist-info/RECORD +0 -227
- {kaqing-2.0.145.dist-info → kaqing-2.0.172.dist-info}/WHEEL +0 -0
- {kaqing-2.0.145.dist-info → kaqing-2.0.172.dist-info}/entry_points.txt +0 -0
- {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
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
username: str = os.getenv('USERNAME')
|
|
47
|
+
if len(args) > 0:
|
|
48
|
+
username = args[0]
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
57
|
-
|
|
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
|
-
|
|
59
|
+
log(f'IDP_TOKEN={login.ser() if login else ""}')
|
|
62
60
|
|
|
63
|
-
|
|
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
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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))
|
adam/commands/medusa/medusa.py
CHANGED
|
@@ -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(
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
51
|
+
return state
|
|
53
52
|
|
|
54
53
|
def completion(self, state: ReplState):
|
|
55
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
46
|
+
return state
|
|
49
47
|
|
|
50
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
62
|
+
return state
|
|
67
63
|
|
|
68
64
|
def completion(self, state: ReplState):
|
|
69
|
-
if state
|
|
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
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
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
|
-
|
|
47
|
-
if state.sts:
|
|
48
|
-
return super().completion(state)
|
|
43
|
+
return state
|
|
49
44
|
|
|
50
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
39
|
+
return state
|
|
44
40
|
|
|
45
41
|
def completion(self, state: ReplState):
|
|
46
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
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
|
|
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)}
|
adam/commands/param_get.py
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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()}}
|
adam/commands/param_set.py
CHANGED
|
@@ -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
|
-
|
|
25
|
+
with self.validate(args, state) as (args, state):
|
|
26
|
+
if len(args) < 2:
|
|
27
|
+
log2('set <key> <value>')
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
log2('set <key> <value>')
|
|
29
|
+
return 'invalid args'
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
key = args[0]
|
|
32
|
+
value = args[1]
|
|
33
|
+
Config().set(key, value)
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
value = args[1]
|
|
34
|
-
Config().set(key, value)
|
|
35
|
+
log(Config().get(key, None))
|
|
35
36
|
|
|
36
|
-
|
|
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.
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
66
|
-
if args and args[-1] == '&':
|
|
67
|
-
args = args[:-1]
|
|
68
|
-
background = True
|
|
59
|
+
return state
|
|
69
60
|
|
|
70
|
-
|
|
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
|
-
|
|
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')
|