Skip to content

Commit

Permalink
Add remote instance creation in complete endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
JBorrow committed Feb 29, 2024
1 parent 4fc262d commit f15e8c5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
8 changes: 6 additions & 2 deletions hera_librarian/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ def ingest_manifest_entry(
uploader: str,
source: str,
deletion_policy: DeletionPolicy,
source_transfer_id: int,
local_path: Path,
):
"""
Expand All @@ -936,6 +937,8 @@ def ingest_manifest_entry(
The source of the file.
deletion_policy : DeletionPolicy
The deletion policy of the instance.
source_transfer_id : int
The ID of the outgoing transfer.
local_path : Path
The path to the instance on the store.
"""
Expand All @@ -948,12 +951,13 @@ def ingest_manifest_entry(
upload_checksum=checksum,
upload_name=name.name,
destination_location=name,
# Uploader is SPECIFICALLY kept as a param here because it
# Uploader is SPECIFICALLY kept as a param here because it is the
# source librarian, not us doing the ingestion.
uploader=uploader,
source=source,
# TODO: As part of the manifest generation process, we should generate
# outbound transfers for all the files.
source_transfer_id=-1,
source_transfer_id=source_transfer_id,
)

initiaton_response: CloneInitiationResponse = self.post(
Expand Down
2 changes: 2 additions & 0 deletions hera_librarian/models/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class CloneCompleteRequest(BaseModel):
"The ID of the transfer. Note that this is the OutgoingTransfer ID."
destination_transfer_id: int
"The ID of the transfer. Note that this is the IncomingTransfer ID."
store_id: int
"The ID of the store that was the ultimate destination of the transfer."


class CloneCompleteResponse(BaseModel):
Expand Down
1 change: 1 addition & 0 deletions librarian_background/recieve_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def core(self, session: Session):
request = CloneCompleteRequest(
source_transfer_id=transfer.id,
destination_instance_id=instance.id,
store_id=store.id,
)

try:
Expand Down
14 changes: 13 additions & 1 deletion librarian_server/api/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from ..database import yield_session
from ..logger import log
from ..orm.file import File
from ..orm.instance import RemoteInstance
from ..orm.storemetadata import StoreMetadata
from ..orm.transfer import IncomingTransfer, OutgoingTransfer, TransferStatus
from .auth import CallbackUserDependency, ReadappendUserDependency
Expand Down Expand Up @@ -335,7 +336,8 @@ def complete(
):
"""
The callback from librarian B to librarian A that it has completed the
transfer. Used to update anything in our OutgiongTransfers that needs it.
transfer. Used to update anything in our OutgiongTransfers that needs it,
as well as create the appropriate remote instances.
Possible response codes:
Expand Down Expand Up @@ -388,6 +390,16 @@ def complete(
)

transfer.status = TransferStatus.COMPLETED

# Create new remote instance for this file that was just completed.
remote_instance = RemoteInstance.new_instance(
file=transfer.file,
store_id=request.store_id,
librarian=transfer.destination,
)

session.add(remote_instance)

session.commit()

response.status_code = status.HTTP_200_OK
Expand Down
2 changes: 2 additions & 0 deletions tests/server_unit_test/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ def test_incoming_transfer_endpoints(
request = CloneCompleteRequest(
source_transfer_id=transfer_id,
destination_transfer_id=transfer_id,
store_id=store.id,
)

response = test_client.post_with_auth(
Expand Down Expand Up @@ -366,6 +367,7 @@ def test_complete_no_transfer(test_client, test_server, test_orm):
request = CloneCompleteRequest(
source_transfer_id=-1,
destination_transfer_id=-1,
store_id=-1,
)

response = test_client.post_with_auth(
Expand Down

0 comments on commit f15e8c5

Please sign in to comment.