github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/clients/hadoopfs/src/main/java/io/lakefs/LakeFSLinker.java (about) 1 package io.lakefs; 2 3 import java.io.IOException; 4 import org.apache.hadoop.fs.Path; 5 import io.lakefs.clients.sdk.ApiException; 6 import io.lakefs.clients.sdk.StagingApi; 7 import io.lakefs.clients.sdk.model.StagingLocation; 8 import io.lakefs.clients.sdk.model.StagingMetadata; 9 import io.lakefs.utils.ObjectLocation; 10 11 public class LakeFSLinker { 12 private final StagingLocation stagingLocation; 13 private final ObjectLocation objectLoc; 14 private final LakeFSFileSystem lfs; 15 private final LakeFSClient lakeFSClient; 16 private final boolean overwrite; 17 18 public LakeFSLinker(LakeFSFileSystem lfs, LakeFSClient lfsClient, 19 ObjectLocation objectLoc, StagingLocation stagingLocation, boolean overwrite) { 20 this.objectLoc = objectLoc; 21 this.stagingLocation = stagingLocation; 22 this.lfs = lfs; 23 this.lakeFSClient = lfsClient; 24 this.overwrite = overwrite; 25 } 26 27 public void link(String eTag, long byteSize) throws IOException { 28 StagingApi staging = lakeFSClient.getStagingApi(); 29 StagingMetadata stagingMetadata = 30 new StagingMetadata().checksum(eTag).sizeBytes(byteSize).staging(stagingLocation); 31 try { 32 StagingApi.APIlinkPhysicalAddressRequest request = 33 staging.linkPhysicalAddress(objectLoc.getRepository(), objectLoc.getRef(), objectLoc.getPath(), stagingMetadata); 34 if (!overwrite) { 35 request.ifNoneMatch("*"); 36 } 37 request.execute(); 38 } catch (ApiException e) { 39 throw new IOException("link lakeFS path to physical address", e); 40 } 41 lfs.deleteEmptyDirectoryMarkers(new Path(objectLoc.toString()).getParent()); 42 } 43 }