forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Kunal Kotwani <kkotwani@amazon.com>
- Loading branch information
1 parent
57d5e90
commit f01530b
Showing
14 changed files
with
659 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
server/src/main/java/org/opensearch/common/blobstore/stream/read/ReadContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common.blobstore.stream.read; | ||
|
||
import org.apache.lucene.store.Directory; | ||
import org.opensearch.common.CheckedConsumer; | ||
import org.opensearch.common.Nullable; | ||
import org.opensearch.common.StreamContext; | ||
import org.opensearch.common.blobstore.stream.write.StreamContextSupplier; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* WriteContext is used to encapsulate all data needed by <code>BlobContainer#readStreams</code> | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class ReadContext { | ||
|
||
private final String fileName; | ||
private final String remoteFileName; | ||
private final StreamContextSupplier streamContextSupplier; | ||
private final long fileSize; | ||
private final boolean failIfAlreadyExists; | ||
private final CheckedConsumer<Boolean, IOException> downloadFinalizer; | ||
private final boolean doRemoteDataIntegrityCheck; | ||
private final Long expectedChecksum; | ||
private Directory localDirectory; | ||
|
||
/** | ||
* Construct a new WriteContext object | ||
* | ||
* @param fileName The name of the file being downloaded | ||
* @param streamContextSupplier A supplier that will provide StreamContext to the plugin | ||
* @param fileSize The total size of the file being downloaded | ||
* @param failIfAlreadyExists A boolean to fail the download if the file exists | ||
* @param doRemoteDataIntegrityCheck A boolean to inform vendor plugins whether remote data integrity checks need to be done | ||
* @param expectedChecksum This parameter expected only when the vendor plugin is expected to do server side data integrity verification | ||
*/ | ||
public ReadContext( | ||
String remoteFileName, | ||
String fileName, | ||
StreamContextSupplier streamContextSupplier, | ||
long fileSize, | ||
boolean failIfAlreadyExists, | ||
CheckedConsumer<Boolean, IOException> downloadFinalizer, | ||
boolean doRemoteDataIntegrityCheck, | ||
@Nullable Long expectedChecksum | ||
) { | ||
this.remoteFileName = remoteFileName; | ||
this.fileName = fileName; | ||
this.streamContextSupplier = streamContextSupplier; | ||
this.fileSize = fileSize; | ||
this.failIfAlreadyExists = failIfAlreadyExists; | ||
this.downloadFinalizer = downloadFinalizer; | ||
this.doRemoteDataIntegrityCheck = doRemoteDataIntegrityCheck; | ||
this.expectedChecksum = expectedChecksum; | ||
} | ||
|
||
public void setLocalDirectory(Directory directory) { | ||
this.localDirectory = directory; | ||
} | ||
|
||
public Directory getLocalDirectory() { | ||
return this.localDirectory; | ||
} | ||
|
||
/** | ||
* @return The file name | ||
*/ | ||
public String getFileName() { | ||
return fileName; | ||
} | ||
|
||
public String getRemoteFileName() { | ||
return remoteFileName; | ||
} | ||
|
||
/** | ||
* @return The boolean representing whether to fail the file upload if it exists | ||
*/ | ||
public boolean isFailIfAlreadyExists() { | ||
return failIfAlreadyExists; | ||
} | ||
|
||
/** | ||
* @param partSize The size of a single part to be uploaded | ||
* @return The stream context which will be used by the plugin to initialize streams from the file | ||
*/ | ||
public StreamContext getStreamProvider(long partSize) { | ||
return streamContextSupplier.supplyStreamContext(partSize); | ||
} | ||
|
||
/** | ||
* @return The total size of the file | ||
*/ | ||
public long getFileSize() { | ||
return fileSize; | ||
} | ||
|
||
/** | ||
* @return The <code>UploadFinalizer</code> for this upload | ||
*/ | ||
public CheckedConsumer<Boolean, IOException> getDownloadFinalizer() { | ||
return downloadFinalizer; | ||
} | ||
|
||
/** | ||
* @return A boolean for whether remote data integrity check has to be done for this upload or not | ||
*/ | ||
public boolean doRemoteDataIntegrityCheck() { | ||
return doRemoteDataIntegrityCheck; | ||
} | ||
|
||
/** | ||
* @return The CRC32 checksum associated with this file | ||
*/ | ||
public Long getExpectedChecksum() { | ||
return expectedChecksum; | ||
} | ||
} |
Oops, something went wrong.