kaqing 2.0.172__py3-none-any.whl → 2.0.186__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/app_session.py +2 -2
- adam/apps.py +18 -4
- adam/batch.py +1 -1
- adam/checks/check_utils.py +3 -1
- adam/commands/__init__.py +8 -2
- adam/commands/alter_tables.py +24 -35
- adam/commands/app/__init__.py +0 -0
- adam/commands/app/app.py +38 -0
- adam/commands/app/app_ping.py +38 -0
- adam/commands/app/show_app_actions.py +49 -0
- adam/commands/app/show_app_id.py +44 -0
- adam/commands/app/show_app_queues.py +38 -0
- adam/commands/app/utils_app.py +106 -0
- adam/commands/audit/audit.py +9 -27
- adam/commands/audit/audit_repair_tables.py +5 -7
- adam/commands/audit/audit_run.py +1 -1
- adam/commands/audit/completions_l.py +15 -0
- adam/commands/audit/show_last10.py +2 -14
- adam/commands/audit/show_slow10.py +2 -13
- adam/commands/audit/show_top10.py +2 -11
- adam/commands/audit/utils_show_top10.py +14 -1
- adam/commands/bash/bash.py +1 -1
- adam/commands/cat.py +5 -19
- adam/commands/cd.py +6 -8
- adam/commands/check.py +10 -18
- adam/commands/cli_commands.py +6 -1
- adam/commands/{cp.py → clipboard_copy.py} +34 -36
- adam/commands/code.py +2 -2
- adam/commands/command.py +94 -10
- adam/commands/commands_utils.py +19 -12
- adam/commands/cql/completions_c.py +28 -0
- adam/commands/cql/cqlsh.py +3 -7
- adam/commands/cql/utils_cql.py +22 -60
- adam/commands/deploy/deploy_pg_agent.py +2 -2
- adam/commands/deploy/undeploy_pg_agent.py +2 -2
- adam/commands/devices/device.py +39 -8
- adam/commands/devices/device_app.py +19 -29
- adam/commands/devices/device_auit_log.py +3 -3
- adam/commands/devices/device_cass.py +17 -23
- adam/commands/devices/device_export.py +12 -11
- adam/commands/devices/device_postgres.py +79 -63
- adam/commands/download_file.py +47 -0
- adam/commands/export/clean_up_all_export_sessions.py +3 -3
- adam/commands/export/clean_up_export_sessions.py +7 -19
- adam/commands/export/completions_x.py +11 -0
- adam/commands/export/download_export_session.py +40 -0
- adam/commands/export/drop_export_database.py +6 -22
- adam/commands/export/drop_export_databases.py +3 -9
- adam/commands/export/export.py +1 -17
- adam/commands/export/export_databases.py +93 -21
- adam/commands/export/export_select.py +8 -68
- adam/commands/export/export_sessions.py +209 -0
- adam/commands/export/export_use.py +13 -16
- adam/commands/export/export_x_select.py +48 -0
- adam/commands/export/exporter.py +108 -129
- adam/commands/export/import_files.py +44 -0
- adam/commands/export/import_session.py +10 -6
- adam/commands/export/importer.py +19 -5
- adam/commands/export/importer_athena.py +112 -41
- adam/commands/export/importer_sqlite.py +47 -19
- adam/commands/export/show_column_counts.py +11 -20
- adam/commands/export/show_export_databases.py +5 -2
- adam/commands/export/show_export_session.py +6 -15
- adam/commands/export/show_export_sessions.py +4 -11
- adam/commands/export/utils_export.py +46 -16
- adam/commands/find_files.py +51 -0
- adam/commands/find_processes.py +76 -0
- adam/commands/head.py +36 -0
- adam/commands/help.py +2 -2
- adam/commands/intermediate_command.py +6 -3
- adam/commands/ls.py +1 -1
- adam/commands/medusa/medusa_backup.py +13 -16
- adam/commands/medusa/medusa_restore.py +39 -32
- adam/commands/medusa/medusa_show_backupjobs.py +6 -4
- adam/commands/medusa/medusa_show_restorejobs.py +5 -3
- adam/commands/medusa/utils_medusa.py +15 -0
- adam/commands/nodetool.py +3 -8
- adam/commands/param_get.py +10 -12
- adam/commands/param_set.py +7 -10
- adam/commands/postgres/completions_p.py +22 -0
- adam/commands/postgres/postgres.py +25 -40
- adam/commands/postgres/postgres_databases.py +270 -0
- adam/commands/postgres/utils_postgres.py +33 -20
- adam/commands/preview_table.py +4 -2
- adam/commands/pwd.py +3 -3
- adam/commands/reaper/reaper_forward.py +2 -2
- adam/commands/reaper/reaper_run_abort.py +4 -10
- adam/commands/reaper/reaper_runs.py +3 -3
- adam/commands/reaper/reaper_schedule_activate.py +12 -12
- adam/commands/reaper/reaper_schedule_start.py +7 -12
- adam/commands/reaper/reaper_schedule_stop.py +7 -12
- adam/commands/reaper/utils_reaper.py +13 -6
- adam/commands/repair/repair_scan.py +0 -2
- adam/commands/repair/repair_stop.py +0 -1
- adam/commands/shell.py +7 -5
- adam/commands/show/show.py +1 -1
- adam/commands/show/show_adam.py +3 -3
- adam/commands/show/show_cassandra_repairs.py +5 -3
- adam/commands/show/show_cassandra_status.py +27 -20
- adam/commands/show/{show_commands.py → show_cli_commands.py} +2 -2
- adam/commands/show/show_login.py +2 -2
- adam/commands/show/show_params.py +2 -5
- adam/commands/show/show_processes.py +15 -14
- adam/commands/show/show_storage.py +9 -8
- adam/config.py +1 -0
- adam/embedded_params.py +1 -1
- adam/repl.py +20 -11
- adam/repl_commands.py +16 -9
- adam/repl_session.py +8 -1
- adam/repl_state.py +33 -10
- adam/sql/lark_completer.py +280 -0
- adam/sql/lark_parser.py +604 -0
- adam/sql/sql_state_machine.py +8 -2
- adam/utils.py +116 -29
- adam/utils_athena.py +7 -8
- adam/utils_issues.py +2 -2
- adam/utils_k8s/app_clusters.py +2 -2
- adam/utils_k8s/app_pods.py +5 -2
- adam/utils_k8s/cassandra_clusters.py +11 -3
- adam/utils_k8s/cassandra_nodes.py +2 -2
- adam/utils_k8s/k8s.py +14 -5
- adam/utils_k8s/kube_context.py +2 -2
- adam/utils_k8s/pods.py +23 -5
- adam/utils_k8s/statefulsets.py +5 -2
- adam/utils_local.py +4 -0
- adam/utils_repl/appendable_completer.py +6 -0
- adam/utils_repl/repl_completer.py +128 -2
- adam/utils_sqlite.py +14 -14
- adam/version.py +1 -1
- {kaqing-2.0.172.dist-info → kaqing-2.0.186.dist-info}/METADATA +1 -1
- kaqing-2.0.186.dist-info/RECORD +250 -0
- adam/commands/cql/cql_completions.py +0 -33
- adam/commands/export/export_handlers.py +0 -71
- adam/commands/export/export_select_x.py +0 -54
- adam/commands/postgres/postgres_context.py +0 -272
- adam/commands/postgres/psql_completions.py +0 -10
- kaqing-2.0.172.dist-info/RECORD +0 -230
- {kaqing-2.0.172.dist-info → kaqing-2.0.186.dist-info}/WHEEL +0 -0
- {kaqing-2.0.172.dist-info → kaqing-2.0.186.dist-info}/entry_points.txt +0 -0
- {kaqing-2.0.172.dist-info → kaqing-2.0.186.dist-info}/top_level.txt +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import pandas
|
|
2
2
|
|
|
3
|
+
from adam.commands.export.export_databases import export_db
|
|
3
4
|
from adam.commands.export.importer import Importer
|
|
4
|
-
from adam.
|
|
5
|
-
from adam.utils import
|
|
5
|
+
from adam.repl_state import ReplState
|
|
6
|
+
from adam.utils import GeneratorStream, bytes_generator_from_file, ing
|
|
6
7
|
from adam.utils_k8s.pods import Pods
|
|
7
8
|
from adam.utils_sqlite import SQLite, sqlite
|
|
8
9
|
|
|
@@ -10,30 +11,57 @@ class SqliteImporter(Importer):
|
|
|
10
11
|
def prefix(self):
|
|
11
12
|
return 's'
|
|
12
13
|
|
|
13
|
-
def import_from_csv(self,
|
|
14
|
+
def import_from_csv(self, state: ReplState, from_session: str,
|
|
15
|
+
keyspace: str, table: str, target_table: str, columns: str,
|
|
16
|
+
multi_tables = True, create_db = False):
|
|
14
17
|
csv_file = self.csv_file(from_session, table, target_table)
|
|
18
|
+
pod = state.pod
|
|
19
|
+
namespace = state.namespace
|
|
20
|
+
to_session = state.export_session
|
|
15
21
|
|
|
16
22
|
succeeded = False
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
try:
|
|
24
|
+
with ing(f'[{to_session}] Uploading to Sqlite', suppress_log=multi_tables):
|
|
25
|
+
# create a connection to single keyspace
|
|
26
|
+
with sqlite(to_session, keyspace) as conn:
|
|
20
27
|
bytes = Pods.read_file(pod, 'cassandra', namespace, csv_file)
|
|
21
28
|
df = pandas.read_csv(GeneratorStream(bytes))
|
|
22
|
-
|
|
23
29
|
df.to_sql(target_table, conn, index=False, if_exists='replace')
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
to, _ = self.move_to_done(state, from_session, keyspace, target_table)
|
|
32
|
+
|
|
33
|
+
succeeded = True
|
|
34
|
+
|
|
35
|
+
return to, to_session
|
|
36
|
+
finally:
|
|
37
|
+
if succeeded:
|
|
38
|
+
self.remove_csv(state, from_session, table, target_table, multi_tables)
|
|
39
|
+
SQLite.clear_cache()
|
|
40
|
+
|
|
41
|
+
if not multi_tables:
|
|
42
|
+
with export_db(state) as dbs:
|
|
43
|
+
dbs.sql(f'select * from {keyspace}.{target_table} limit 10')
|
|
44
|
+
|
|
45
|
+
def import_from_local_csv(self, state: ReplState,
|
|
46
|
+
keyspace: str, table: str, csv_file: str, multi_tables = True, create_db = False):
|
|
47
|
+
to_session = state.export_session
|
|
48
|
+
|
|
49
|
+
succeeded = False
|
|
50
|
+
try:
|
|
51
|
+
with ing(f'[{to_session}] Uploading to Sqlite', suppress_log=multi_tables):
|
|
52
|
+
# create a connection to single keyspace
|
|
53
|
+
with sqlite(to_session, keyspace) as conn:
|
|
54
|
+
bytes = bytes_generator_from_file(csv_file)
|
|
55
|
+
df = pandas.read_csv(GeneratorStream(bytes))
|
|
56
|
+
df.to_sql(table, conn, index=False, if_exists='replace')
|
|
26
57
|
|
|
27
|
-
|
|
58
|
+
succeeded = True
|
|
28
59
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
SQLite.clear_cache()
|
|
60
|
+
return csv_file, to_session
|
|
61
|
+
finally:
|
|
62
|
+
if succeeded:
|
|
63
|
+
SQLite.clear_cache()
|
|
34
64
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
log2(query)
|
|
39
|
-
SQLite.run_query_with_conn(conn, query)
|
|
65
|
+
if not multi_tables:
|
|
66
|
+
with export_db(state) as dbs:
|
|
67
|
+
dbs.sql(f'select * from {keyspace}.{table} limit 10')
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
from adam.commands import extract_trailing_options, validate_args
|
|
1
2
|
from adam.commands.command import Command
|
|
2
|
-
from adam.commands.
|
|
3
|
+
from adam.commands.cql.utils_cql import cassandra_table_names
|
|
4
|
+
from adam.commands.export.export_databases import ExportDatabases, export_db
|
|
3
5
|
from adam.config import Config
|
|
4
6
|
from adam.repl_state import ReplState, RequiredState
|
|
5
|
-
from adam.utils import log2
|
|
6
7
|
|
|
7
8
|
class ShowColumnCounts(Command):
|
|
8
9
|
COMMAND = 'show column counts on'
|
|
@@ -27,28 +28,18 @@ class ShowColumnCounts(Command):
|
|
|
27
28
|
return super().run(cmd, state)
|
|
28
29
|
|
|
29
30
|
with self.validate(args, state) as (args, state):
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
Command.display_help()
|
|
37
|
-
|
|
38
|
-
return 'command-missing'
|
|
39
|
-
|
|
40
|
-
table = args[0]
|
|
41
|
-
query = Config().get(f'export.column_counts_query', 'select id, count(id) as columns from {table} group by id')
|
|
42
|
-
query = query.replace('{table}', table)
|
|
43
|
-
ExportDatabases.run_query(query, state.export_session)
|
|
31
|
+
with extract_trailing_options(args, '&') as (args, backgrounded):
|
|
32
|
+
with validate_args(args, state, name='SQL statement') as table:
|
|
33
|
+
with export_db(state) as dbs:
|
|
34
|
+
query = Config().get(f'export.column_counts_query', 'select id, count(id) as columns from {table} group by id')
|
|
35
|
+
query = query.replace('{table}', table)
|
|
36
|
+
dbs.sql(query, state.export_session, backgrounded=backgrounded)
|
|
44
37
|
|
|
45
38
|
return state
|
|
46
39
|
|
|
47
40
|
def completion(self, state: ReplState):
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return super().completion(state, lambda: {t: None for t in ExportDatabases.table_names(state.export_session)})
|
|
41
|
+
return super().completion(state, lambda: {t: None for t in ExportDatabases.table_names(state.export_session)}, auto_key='x.tables')
|
|
42
|
+
# return {}
|
|
52
43
|
|
|
53
44
|
def help(self, _: ReplState):
|
|
54
45
|
return f'{ShowColumnCounts.COMMAND} <export-table-name>\t show column count per id'
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from adam.commands.command import Command
|
|
2
2
|
from adam.commands.devices.device_export import DeviceExport
|
|
3
|
+
from adam.commands.export.export_databases import export_db
|
|
3
4
|
from adam.repl_state import ReplState
|
|
4
5
|
|
|
5
6
|
class ShowExportDatabases(Command):
|
|
@@ -25,12 +26,14 @@ class ShowExportDatabases(Command):
|
|
|
25
26
|
return super().run(cmd, state)
|
|
26
27
|
|
|
27
28
|
with self.validate(args, state) as (args, state):
|
|
28
|
-
|
|
29
|
+
with export_db(state) as dbs:
|
|
30
|
+
dbs.show_databases()
|
|
29
31
|
|
|
30
32
|
return state
|
|
31
33
|
|
|
32
34
|
def completion(self, state: ReplState):
|
|
33
|
-
return
|
|
35
|
+
return {}
|
|
36
|
+
# return DeviceExport().ls_completion(ShowExportDatabases.COMMAND, state, default = super().completion(state))
|
|
34
37
|
|
|
35
38
|
def help(self, _: ReplState):
|
|
36
39
|
return f'{ShowExportDatabases.COMMAND}\t list export databases'
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
from adam.commands import validate_args
|
|
1
2
|
from adam.commands.command import Command
|
|
2
|
-
from adam.commands.export.
|
|
3
|
-
from adam.commands.export.exporter import Exporter
|
|
3
|
+
from adam.commands.export.export_sessions import ExportSessions, export_session
|
|
4
4
|
from adam.repl_state import ReplState, RequiredState
|
|
5
|
-
from adam.utils import log2
|
|
6
5
|
|
|
7
6
|
class ShowExportSession(Command):
|
|
8
7
|
COMMAND = 'show export session'
|
|
@@ -27,22 +26,14 @@ class ShowExportSession(Command):
|
|
|
27
26
|
return super().run(cmd, state)
|
|
28
27
|
|
|
29
28
|
with self.validate(args, state) as (args, state):
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
else:
|
|
34
|
-
log2('* Database name is missing.')
|
|
35
|
-
|
|
36
|
-
Command.display_help()
|
|
37
|
-
|
|
38
|
-
return 'command-missing'
|
|
39
|
-
|
|
40
|
-
ExportDatabases.disply_export_session(state.sts, state.pod, state.namespace, args[0])
|
|
29
|
+
with validate_args(args, state, name='export session') as session:
|
|
30
|
+
with export_session(state) as sessions:
|
|
31
|
+
sessions.show_session(session)
|
|
41
32
|
|
|
42
33
|
return state
|
|
43
34
|
|
|
44
35
|
def completion(self, state: ReplState):
|
|
45
|
-
return
|
|
36
|
+
return {}
|
|
46
37
|
|
|
47
38
|
def help(self, _: ReplState):
|
|
48
39
|
return f'{ShowExportSession.COMMAND} <export-session-name>\t show export session'
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
from adam.commands.command import Command
|
|
2
|
-
from adam.commands.export.
|
|
2
|
+
from adam.commands.export.export_sessions import export_session
|
|
3
3
|
from adam.repl_state import ReplState, RequiredState
|
|
4
|
-
from adam.utils import lines_to_tabular, log
|
|
5
|
-
from adam.utils_k8s.statefulsets import StatefulSets
|
|
6
4
|
|
|
7
5
|
class ShowExportSessions(Command):
|
|
8
6
|
COMMAND = 'show export sessions'
|
|
@@ -27,18 +25,13 @@ class ShowExportSessions(Command):
|
|
|
27
25
|
return super().run(cmd, state)
|
|
28
26
|
|
|
29
27
|
with self.validate(args, state) as (args, state):
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
pod = StatefulSets.pod_names(state.sts, state.namespace)[0]
|
|
33
|
-
|
|
34
|
-
sessions: dict[str, str] = Exporter.find_export_sessions(pod, state.namespace)
|
|
35
|
-
log(lines_to_tabular([f'{session}\t{export_state}' for session, export_state in sorted(sessions.items(), reverse=True)],
|
|
36
|
-
header='EXPORT_SESSION\tSTATUS', separator='\t'))
|
|
28
|
+
with export_session(state) as sessions:
|
|
29
|
+
sessions.show_all_sessions()
|
|
37
30
|
|
|
38
31
|
return state
|
|
39
32
|
|
|
40
33
|
def completion(self, state: ReplState):
|
|
41
|
-
return
|
|
34
|
+
return {}
|
|
42
35
|
|
|
43
36
|
def help(self, _: ReplState):
|
|
44
37
|
return f'{ShowExportSessions.COMMAND}\t list export sessions'
|
|
@@ -9,18 +9,27 @@ from adam.utils_k8s.pods import log_prefix
|
|
|
9
9
|
from adam.utils_k8s.statefulsets import StatefulSets
|
|
10
10
|
|
|
11
11
|
class ImportSpec:
|
|
12
|
-
def __init__(self, session: str, importer: str):
|
|
12
|
+
def __init__(self, table_name: str, session: str = None, files: list[str] = None, importer: str = None):
|
|
13
|
+
self.table_name = table_name
|
|
13
14
|
self.session = session
|
|
15
|
+
self.files = files
|
|
14
16
|
self.importer = importer
|
|
15
17
|
|
|
16
|
-
def parse_specs(specs_str: str):
|
|
17
|
-
|
|
18
|
+
def parse_specs(specs_str: str, files = False):
|
|
19
|
+
session_or_files: str = None
|
|
18
20
|
importer: str = None
|
|
21
|
+
table_name: str = None
|
|
19
22
|
|
|
20
23
|
if specs_str:
|
|
21
|
-
importer,
|
|
24
|
+
importer, rest = ImportSpec._extract_importer(specs_str.strip(' '))
|
|
25
|
+
|
|
26
|
+
if rest:
|
|
27
|
+
table_name, session_or_files = ImportSpec._extract_table_name(rest)
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
if not files:
|
|
30
|
+
return ImportSpec(table_name, session=session_or_files, importer=importer)
|
|
31
|
+
|
|
32
|
+
return ImportSpec(table_name, files=[f.strip(' ') for f in session_or_files.split(',')], importer=importer)
|
|
24
33
|
|
|
25
34
|
def _extract_importer(spec_str: str) -> tuple[str, str]:
|
|
26
35
|
importer = None
|
|
@@ -34,12 +43,25 @@ class ImportSpec:
|
|
|
34
43
|
|
|
35
44
|
return importer, rest
|
|
36
45
|
|
|
46
|
+
def _extract_table_name(spec_str: str) -> tuple[str, str]:
|
|
47
|
+
table_name = None
|
|
48
|
+
rest = spec_str
|
|
49
|
+
|
|
50
|
+
p = re.compile(r"(.*?)as\s+(.*)", re.IGNORECASE)
|
|
51
|
+
match = p.match(spec_str)
|
|
52
|
+
if match:
|
|
53
|
+
rest = match.group(1).strip(' ')
|
|
54
|
+
table_name = match.group(2).strip(' ')
|
|
55
|
+
|
|
56
|
+
return table_name, rest
|
|
57
|
+
|
|
37
58
|
class ExportSpec(ImportSpec):
|
|
38
59
|
def __init__(self, keyspace: str, consistency: str, importer: str, tables: list['ExportTableSpec'], session: str = None):
|
|
39
60
|
super().__init__(None, importer)
|
|
40
61
|
|
|
41
62
|
self.keyspace = keyspace
|
|
42
63
|
self.consistency = consistency
|
|
64
|
+
self.importer = importer
|
|
43
65
|
self.tables = tables
|
|
44
66
|
self.session = session
|
|
45
67
|
|
|
@@ -154,11 +176,12 @@ class ExportTableSpec:
|
|
|
154
176
|
return f'{self.keyspace}.{self.table}({self.columns}) as {self.target_table}'
|
|
155
177
|
|
|
156
178
|
class ExportTableStatus:
|
|
157
|
-
def __init__(self, keyspace: str, target_table: str, status: str, table: str = None):
|
|
179
|
+
def __init__(self, keyspace: str, target_table: str, status: str, table: str = None, csv_file: str = ''):
|
|
158
180
|
self.keyspace = keyspace
|
|
159
181
|
self.target_table = target_table
|
|
160
182
|
self.status = status
|
|
161
183
|
self.table = table
|
|
184
|
+
self.csv_file = csv_file
|
|
162
185
|
|
|
163
186
|
def __str__(self):
|
|
164
187
|
return f'{self.keyspace}.{self.table} as {self.target_table} = {self.status}'
|
|
@@ -169,7 +192,7 @@ class ExportTableStatus:
|
|
|
169
192
|
|
|
170
193
|
return False
|
|
171
194
|
|
|
172
|
-
def from_session(sts: str, pod: str, namespace: str, export_session: str):
|
|
195
|
+
def from_session(sts: str, pod: str, namespace: str, export_session: str) -> tuple['ExportTableStatus', str]:
|
|
173
196
|
statuses: list[ExportTableStatus] = []
|
|
174
197
|
|
|
175
198
|
status_in_whole = 'done'
|
|
@@ -204,8 +227,8 @@ class ExportTableStatus:
|
|
|
204
227
|
target_table = m.group(2)
|
|
205
228
|
state = m.group(3)
|
|
206
229
|
if state == '.pending_import':
|
|
207
|
-
|
|
208
|
-
return ExportTableStatus(keyspace, target_table, 'pending_import', table)
|
|
230
|
+
csv_files, table = get_csv_files_n_table(target_table)
|
|
231
|
+
return ExportTableStatus(keyspace, target_table, 'pending_import', table, csv_files[0] if csv_files else '')
|
|
209
232
|
elif state == '.done':
|
|
210
233
|
return ExportTableStatus(keyspace, target_table, 'done', target_table)
|
|
211
234
|
|
|
@@ -215,7 +238,7 @@ class ExportTableStatus:
|
|
|
215
238
|
if r.exit_code() == 0:
|
|
216
239
|
csv_files, table = get_csv_files_n_table(target_table)
|
|
217
240
|
if csv_files:
|
|
218
|
-
return ExportTableStatus(keyspace, target_table, 'exported', table)
|
|
241
|
+
return ExportTableStatus(keyspace, target_table, 'exported', table, csv_files[0])
|
|
219
242
|
else:
|
|
220
243
|
return ExportTableStatus(keyspace, target_table, 'imported', target_table)
|
|
221
244
|
else:
|
|
@@ -292,23 +315,30 @@ class GeneratorStream(io.RawIOBase):
|
|
|
292
315
|
self._buffer = self._buffer[size:]
|
|
293
316
|
return data
|
|
294
317
|
|
|
295
|
-
class
|
|
296
|
-
def __init__(self, state: ReplState):
|
|
318
|
+
class PodPushHandler:
|
|
319
|
+
def __init__(self, state: ReplState, pod: str = None):
|
|
297
320
|
self.state = state
|
|
321
|
+
self.pushed = False
|
|
322
|
+
self.pod = pod
|
|
298
323
|
|
|
299
324
|
def __enter__(self):
|
|
300
325
|
state = self.state
|
|
301
326
|
|
|
302
327
|
if not state.pod:
|
|
328
|
+
self.pushed = True
|
|
303
329
|
state.push()
|
|
304
|
-
|
|
330
|
+
|
|
331
|
+
if not self.pod:
|
|
332
|
+
self.pod = StatefulSets.pod_names(state.sts, state.namespace)[0]
|
|
333
|
+
state.pod = self.pod
|
|
305
334
|
|
|
306
335
|
return state
|
|
307
336
|
|
|
308
337
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
309
|
-
self.
|
|
338
|
+
if self.pushed:
|
|
339
|
+
self.state.pop()
|
|
310
340
|
|
|
311
341
|
return False
|
|
312
342
|
|
|
313
|
-
def state_with_pod(state: ReplState):
|
|
314
|
-
return
|
|
343
|
+
def state_with_pod(state: ReplState, pod: str = None):
|
|
344
|
+
return PodPushHandler(state, pod=pod)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from adam.commands.command import Command
|
|
4
|
+
from adam.repl_state import ReplState
|
|
5
|
+
from adam.utils import log2
|
|
6
|
+
from adam.utils_local import local_tmp_dir
|
|
7
|
+
|
|
8
|
+
class FindLocalFiles(Command):
|
|
9
|
+
COMMAND = 'find local'
|
|
10
|
+
|
|
11
|
+
# the singleton pattern
|
|
12
|
+
def __new__(cls, *args, **kwargs):
|
|
13
|
+
if not hasattr(cls, 'instance'): cls.instance = super(FindLocalFiles, cls).__new__(cls)
|
|
14
|
+
|
|
15
|
+
return cls.instance
|
|
16
|
+
|
|
17
|
+
def __init__(self, successor: Command=None):
|
|
18
|
+
super().__init__(successor)
|
|
19
|
+
|
|
20
|
+
def command(self):
|
|
21
|
+
return FindLocalFiles.COMMAND
|
|
22
|
+
|
|
23
|
+
def run(self, cmd: str, state: ReplState):
|
|
24
|
+
if not(args := self.args(cmd)):
|
|
25
|
+
return super().run(cmd, state)
|
|
26
|
+
|
|
27
|
+
with self.validate(args, state) as (args, state):
|
|
28
|
+
cmd = 'find'
|
|
29
|
+
|
|
30
|
+
if not args:
|
|
31
|
+
cmd = f'find {local_tmp_dir()}'
|
|
32
|
+
elif len(args) == 1:
|
|
33
|
+
cmd = f"find {local_tmp_dir()} -name '{args[0]}'"
|
|
34
|
+
else:
|
|
35
|
+
new_args = [f"'{arg}'" if '*' in arg else arg for arg in args]
|
|
36
|
+
cmd = 'find ' + ' '.join(new_args)
|
|
37
|
+
|
|
38
|
+
log2(cmd)
|
|
39
|
+
os.system(cmd)
|
|
40
|
+
|
|
41
|
+
return state
|
|
42
|
+
|
|
43
|
+
def completion(self, state: ReplState):
|
|
44
|
+
return super().completion(state, {
|
|
45
|
+
'*.csv': None,
|
|
46
|
+
'*.db': None,
|
|
47
|
+
'*': None
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
def help(self, _: ReplState):
|
|
51
|
+
return f'{FindLocalFiles.COMMAND} [linux-find-arguments]\t find files from local machine'
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from adam.commands import extract_options, validate_args
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.commands.devices.devices import Devices
|
|
4
|
+
from adam.commands.export.utils_export import state_with_pod
|
|
5
|
+
from adam.repl_state import ReplState, RequiredState
|
|
6
|
+
from adam.utils import log2, tabulize
|
|
7
|
+
|
|
8
|
+
class FindProcesses(Command):
|
|
9
|
+
COMMAND = 'find processes'
|
|
10
|
+
|
|
11
|
+
# the singleton pattern
|
|
12
|
+
def __new__(cls, *args, **kwargs):
|
|
13
|
+
if not hasattr(cls, 'instance'): cls.instance = super(FindProcesses, cls).__new__(cls)
|
|
14
|
+
|
|
15
|
+
return cls.instance
|
|
16
|
+
|
|
17
|
+
def __init__(self, successor: Command=None):
|
|
18
|
+
super().__init__(successor)
|
|
19
|
+
|
|
20
|
+
def command(self):
|
|
21
|
+
return FindProcesses.COMMAND
|
|
22
|
+
|
|
23
|
+
def required(self):
|
|
24
|
+
return [RequiredState.CLUSTER_OR_POD, RequiredState.APP_APP, ReplState.P]
|
|
25
|
+
|
|
26
|
+
def run(self, cmd: str, state: ReplState):
|
|
27
|
+
if not(args := self.args(cmd)):
|
|
28
|
+
return super().run(cmd, state)
|
|
29
|
+
|
|
30
|
+
with self.validate(args, state) as (args, state):
|
|
31
|
+
with extract_options(args, '-kill') as (args, kill):
|
|
32
|
+
with validate_args(args, state, name='words to look for'):
|
|
33
|
+
arg = ' | '.join([f'grep {a}' for a in args])
|
|
34
|
+
awk = "awk '{ print $1, $2, $8, $NF }'"
|
|
35
|
+
rs = Devices.device(state).bash(state, state, f"ps -ef | grep -v grep | {arg} | {awk}".split(' '))
|
|
36
|
+
|
|
37
|
+
lines: list[list[str]] = []
|
|
38
|
+
for r in rs:
|
|
39
|
+
for l in r.stdout.split('\n'):
|
|
40
|
+
l = l.strip(' \t\r\n')
|
|
41
|
+
if not l:
|
|
42
|
+
continue
|
|
43
|
+
|
|
44
|
+
tokens = [r.pod] + l.split(' ')
|
|
45
|
+
lines.append(tokens)
|
|
46
|
+
|
|
47
|
+
pids = []
|
|
48
|
+
for l in lines:
|
|
49
|
+
pids.append(f'{l[2]}@{l[0]}')
|
|
50
|
+
|
|
51
|
+
tabulize(lines, lambda l: '\t'.join(l), header = 'POD\tUSER\tPID\tCMD\tLAST_ARG', separator='\t')
|
|
52
|
+
log2()
|
|
53
|
+
log2(f'PIDS with {",".join(args)}: {",".join(pids)}')
|
|
54
|
+
|
|
55
|
+
if kill:
|
|
56
|
+
log2()
|
|
57
|
+
for pidp in pids:
|
|
58
|
+
pid_n_pod = pidp.split('@')
|
|
59
|
+
pid = pid_n_pod[0]
|
|
60
|
+
if len(pid_n_pod) < 2:
|
|
61
|
+
continue
|
|
62
|
+
|
|
63
|
+
pod = pid_n_pod[1]
|
|
64
|
+
|
|
65
|
+
log2(f'@{pod} bash kill -9 {pid}')
|
|
66
|
+
|
|
67
|
+
with state_with_pod(state, pod) as state1:
|
|
68
|
+
Devices.device(state).bash(state, state1, ['kill', '-9', pid])
|
|
69
|
+
|
|
70
|
+
return rs
|
|
71
|
+
|
|
72
|
+
def completion(self, state: ReplState):
|
|
73
|
+
return super().completion(state)
|
|
74
|
+
|
|
75
|
+
def help(self, _: ReplState):
|
|
76
|
+
return f'{FindProcesses.COMMAND} word... [-kill]\t find processes with words'
|
adam/commands/head.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
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.repl_state import ReplState, RequiredState
|
|
5
|
+
|
|
6
|
+
class Head(Command):
|
|
7
|
+
COMMAND = 'head'
|
|
8
|
+
|
|
9
|
+
# the singleton pattern
|
|
10
|
+
def __new__(cls, *args, **kwargs):
|
|
11
|
+
if not hasattr(cls, 'instance'): cls.instance = super(Head, 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 Head.COMMAND
|
|
20
|
+
|
|
21
|
+
def required(self):
|
|
22
|
+
return [RequiredState.CLUSTER_OR_POD, RequiredState.APP_APP, ReplState.P]
|
|
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='file'):
|
|
30
|
+
return Devices.device(state).bash(state, state, cmd.split(' '))
|
|
31
|
+
|
|
32
|
+
def completion(self, state: ReplState):
|
|
33
|
+
return super().completion(state, lambda: {f: None for f in Devices.device(state).files(state)}, pods=Devices.device(state).pods(state, '-'), auto='jit')
|
|
34
|
+
|
|
35
|
+
def help(self, _: ReplState):
|
|
36
|
+
return f'{Head.COMMAND} file [&]\t run head command on the pod'
|
adam/commands/help.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from adam.commands.command import Command
|
|
2
2
|
from adam.repl_commands import ReplCommands
|
|
3
3
|
from adam.repl_state import ReplState
|
|
4
|
-
from adam.utils import
|
|
4
|
+
from adam.utils import tabulize, log
|
|
5
5
|
|
|
6
6
|
class Help(Command):
|
|
7
7
|
COMMAND = 'help'
|
|
@@ -45,7 +45,7 @@ class Help(Command):
|
|
|
45
45
|
lines.append('')
|
|
46
46
|
lines.extend(section(ReplCommands.exit()))
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
tabulize(lines, separator='\t')
|
|
49
49
|
|
|
50
50
|
return lines
|
|
51
51
|
|
|
@@ -3,7 +3,7 @@ from abc import abstractmethod
|
|
|
3
3
|
from adam.commands.command import Command
|
|
4
4
|
from adam.commands.command_helpers import ClusterCommandHelper
|
|
5
5
|
from adam.repl_state import ReplState
|
|
6
|
-
from adam.utils import
|
|
6
|
+
from adam.utils import tabulize, log, log2
|
|
7
7
|
|
|
8
8
|
class IntermediateCommand(Command):
|
|
9
9
|
def run(self, cmd: str, state: ReplState):
|
|
@@ -12,6 +12,9 @@ class IntermediateCommand(Command):
|
|
|
12
12
|
|
|
13
13
|
return self.intermediate_run(cmd, state, args, self.cmd_list())
|
|
14
14
|
|
|
15
|
+
def completion(self, state: ReplState):
|
|
16
|
+
return {}
|
|
17
|
+
|
|
15
18
|
@abstractmethod
|
|
16
19
|
def cmd_list(self):
|
|
17
20
|
pass
|
|
@@ -21,7 +24,7 @@ class IntermediateCommand(Command):
|
|
|
21
24
|
|
|
22
25
|
if state.in_repl:
|
|
23
26
|
if display_help:
|
|
24
|
-
|
|
27
|
+
tabulize(cmds, lambda c: c.help(state), separator=separator)
|
|
25
28
|
|
|
26
29
|
return 'command-missing'
|
|
27
30
|
else:
|
|
@@ -43,7 +46,7 @@ class IntermediateCommand(Command):
|
|
|
43
46
|
log()
|
|
44
47
|
log('Sub-Commands:')
|
|
45
48
|
|
|
46
|
-
|
|
49
|
+
tabulize(cmd_list, lambda c: c.help(ReplState()).replace(f'{cmd} ', ' ', 1), separator=separator)
|
|
47
50
|
if show_cluster_help:
|
|
48
51
|
log()
|
|
49
52
|
ClusterCommandHelper.cluster_help()
|
adam/commands/ls.py
CHANGED
|
@@ -35,7 +35,7 @@ class Ls(Command):
|
|
|
35
35
|
return state
|
|
36
36
|
|
|
37
37
|
def completion(self, state: ReplState):
|
|
38
|
-
return
|
|
38
|
+
return super().completion(state, {'&': None}, pods=Devices.device(state).pods(state, '-'))
|
|
39
39
|
|
|
40
40
|
def help(self, _: ReplState):
|
|
41
41
|
return f'{Ls.COMMAND} [device:]\t list apps, envs, clusters, nodes, pg hosts/databases or export databases'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
|
-
import re
|
|
3
2
|
|
|
3
|
+
from adam.commands import validate_args
|
|
4
4
|
from adam.commands.command import Command
|
|
5
5
|
from adam.utils_k8s.statefulsets import StatefulSets
|
|
6
6
|
from adam.repl_state import ReplState, RequiredState
|
|
@@ -33,22 +33,19 @@ class MedusaBackup(Command):
|
|
|
33
33
|
ns = state.namespace
|
|
34
34
|
sts = state.sts
|
|
35
35
|
now_dtformat = datetime.now().strftime("%Y-%m-%d.%H.%M.%S")
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
log2("Exception: MedusaBackup failed: %s\n" % e)
|
|
48
|
-
finally:
|
|
49
|
-
CustomResources.clear_caches()
|
|
36
|
+
with validate_args(args, state, default='medusa-' + now_dtformat + 'full-backup-' + sts) as bkname:
|
|
37
|
+
dc = StatefulSets.get_datacenter(state.sts, ns)
|
|
38
|
+
if not dc:
|
|
39
|
+
return state
|
|
40
|
+
|
|
41
|
+
try:
|
|
42
|
+
CustomResources.create_medusa_backupjob(bkname, dc, ns)
|
|
43
|
+
except Exception as e:
|
|
44
|
+
log2("Exception: MedusaBackup failed: %s\n" % e)
|
|
45
|
+
finally:
|
|
46
|
+
CustomResources.clear_caches()
|
|
50
47
|
|
|
51
|
-
|
|
48
|
+
return state
|
|
52
49
|
|
|
53
50
|
def completion(self, state: ReplState):
|
|
54
51
|
return super().completion(state)
|