Skip to content

Commit 0003946

Browse files
authored
Add sync-to-seafowl CLI command (#775)
* Add sync-to-seafowl CLI command * Improve sync-to-seafowl command password handling and output
1 parent e037a65 commit 0003946

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

splitgraph/cloud/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
REPO_PARAMS,
6868
START_EXPORT,
6969
START_LOAD,
70+
START_SYNC_VDB_TO_SEAFOWL,
7071
)
7172
from splitgraph.config import CONFIG
7273
from splitgraph.config.config import (
@@ -1148,3 +1149,15 @@ def provision_ephemeral_tunnel(self) -> Tuple[str, str, int, str, int]:
11481149
response.json()["data"]["provisionEphemeralTunnel"]["privateAddressHost"],
11491150
response.json()["data"]["provisionEphemeralTunnel"]["privateAddressPort"],
11501151
)
1152+
1153+
def start_seafowl_sync(self, vdb_id: str, url: str, secret: str) -> str:
1154+
response = self._gql(
1155+
{
1156+
"query": START_SYNC_VDB_TO_SEAFOWL,
1157+
"operationName": "syncToSeafowl",
1158+
"variables": {"url": url, "secret": secret, "vdbId": vdb_id},
1159+
},
1160+
handle_errors=True,
1161+
anonymous_ok=False,
1162+
)
1163+
return cast(str, response.json()["data"]["syncToSeafowl"]["id"])

splitgraph/cloud/queries.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,16 @@
316316
}
317317
}
318318
"""
319+
320+
START_SYNC_VDB_TO_SEAFOWL = """mutation syncToSeafowl($url: String!, $secret: String!, $vdbId: String!) {
321+
syncToSeafowl(
322+
target: {
323+
url: $url,
324+
secret: $secret
325+
},
326+
vdbId: $vdbId
327+
) {
328+
id
329+
}
330+
}
331+
"""

splitgraph/commandline/cloud.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,31 @@ def tunnel_c(remote: str, local_address: str, namespace_and_repository: Optional
13101310
start_repository_tunnel(remote, local_address, namespace_and_repository)
13111311

13121312

1313+
@click.command("sync-to-seafowl")
1314+
@click.option("--remote", default="data.splitgraph.com", help="Name of the remote registry to use.")
1315+
@click.option("--password", prompt=True, hide_input=True, confirmation_prompt=False)
1316+
@click.argument("vdb_id", type=str)
1317+
@click.argument("seafowl_hostname", type=str)
1318+
def sync_to_seafowl_c(remote: str, password: str, vdb_id: str, seafowl_hostname: str):
1319+
"""
1320+
Sync the tables within a Splitgraph VDB to a Seafowl instance.
1321+
1322+
"""
1323+
1324+
from splitgraph.cloud import GQLAPIClient
1325+
1326+
client = GQLAPIClient(remote)
1327+
task_id = client.start_seafowl_sync(vdb_id, seafowl_hostname, password)
1328+
final_status = wait_for_job(task_id, lambda: client.get_export_job_status(task_id))
1329+
if final_status.status == "SUCCESS":
1330+
assert final_status.output
1331+
tables = [f"{sync_item[0]}.{sync_item[1]}" for sync_item in final_status.output["tables"]]
1332+
tables.sort()
1333+
click.echo("Sync complete for tables: %s" % ", ".join(tables))
1334+
else:
1335+
raise ValueError("Error running sync.")
1336+
1337+
13131338
@click.group("cloud")
13141339
def cloud_c():
13151340
"""Run actions on Splitgraph Cloud."""
@@ -1338,3 +1363,4 @@ def cloud_c():
13381363
cloud_c.add_command(validate_c)
13391364
cloud_c.add_command(seed_c)
13401365
cloud_c.add_command(tunnel_c)
1366+
cloud_c.add_command(sync_to_seafowl_c)

0 commit comments

Comments
 (0)