Skip to content

Commit

Permalink
Use new exportToSeafowl gql mutation for Seafowl VDB exports
Browse files Browse the repository at this point in the history
  • Loading branch information
neumark committed Apr 26, 2023
1 parent 04a2b9f commit 5765451
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
8 changes: 4 additions & 4 deletions splitgraph/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
REPO_CONDITIONS,
REPO_PARAMS,
START_EXPORT,
START_EXPORT_VDB_TO_SEAFOWL,
START_LOAD,
START_SYNC_VDB_TO_SEAFOWL,
)
from splitgraph.config import CONFIG
from splitgraph.config.config import (
Expand Down Expand Up @@ -1155,11 +1155,11 @@ def provision_ephemeral_tunnel(self) -> Tuple[str, str, int, str, int]:
def start_seafowl_sync(self, vdb_id: str, url: str, secret: str) -> str:
response = self._gql(
{
"query": START_SYNC_VDB_TO_SEAFOWL,
"operationName": "syncToSeafowl",
"query": START_EXPORT_VDB_TO_SEAFOWL,
"operationName": "exportToSeafowl",
"variables": {"url": url, "secret": secret, "vdbId": vdb_id},
},
handle_errors=True,
anonymous_ok=False,
)
return cast(str, response.json()["data"]["syncToSeafowl"]["id"])
return cast(str, response.json()["data"]["exportToSeafowl"]["vdbs"][0]["jobId"])
23 changes: 14 additions & 9 deletions splitgraph/cloud/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,20 @@
}
"""

START_SYNC_VDB_TO_SEAFOWL = """mutation syncToSeafowl($url: String!, $secret: String!, $vdbId: String!) {
syncToSeafowl(
target: {
url: $url,
secret: $secret
},
vdbId: $vdbId
) {
id
START_EXPORT_VDB_TO_SEAFOWL = """mutation exportToSeafowl(
$url: String!
$secret: String!
$vdbId: String!
) {
exportToSeafowl(
seafowlInstance: {
selfHosted: { url: $url, secret: $secret}
}
vdbs: [{ source: { vdbId: $vdbId } }]
) {
vdbs {
jobId
}
}
}
"""
9 changes: 5 additions & 4 deletions splitgraph/commandline/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -1310,12 +1310,12 @@ def tunnel_c(remote: str, local_address: str, namespace_and_repository: Optional
start_repository_tunnel(remote, local_address, namespace_and_repository)


@click.command("sync-to-seafowl")
@click.command("export-to-seafowl")
@click.option("--remote", default="data.splitgraph.com", help="Name of the remote registry to use.")
@click.option("--password", prompt=True, hide_input=True, confirmation_prompt=False)
@click.argument("vdb_id", type=str)
@click.argument("seafowl_hostname", type=str)
def sync_to_seafowl_c(remote: str, password: str, vdb_id: str, seafowl_hostname: str):
def export_to_seafowl_c(remote: str, password: str, vdb_id: str, seafowl_hostname: str):
"""
Sync the tables within a Splitgraph VDB to a Seafowl instance.
Expand All @@ -1328,7 +1328,8 @@ def sync_to_seafowl_c(remote: str, password: str, vdb_id: str, seafowl_hostname:
final_status = wait_for_job(task_id, lambda: client.get_export_job_status(task_id))
if final_status.status == "SUCCESS":
assert final_status.output
tables = [f"{sync_item[0]}.{sync_item[1]}" for sync_item in final_status.output["tables"]]
# final_status.output["tables"] : [(source_query, target_dbname, target_schema, target_table, download_url)]
tables = [f"{sync_item[2]}.{sync_item[3]}" for sync_item in final_status.output["tables"]]
tables.sort()
click.echo("Sync complete for tables: %s" % ", ".join(tables))
else:
Expand Down Expand Up @@ -1363,4 +1364,4 @@ def cloud_c():
cloud_c.add_command(validate_c)
cloud_c.add_command(seed_c)
cloud_c.add_command(tunnel_c)
cloud_c.add_command(sync_to_seafowl_c)
cloud_c.add_command(export_to_seafowl_c)

0 comments on commit 5765451

Please sign in to comment.