Class GoogleStorageBucket
- java.lang.Object
-
- org.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>
-
- org.pipecraft.infra.storage.google_cs.GoogleStorageBucket
-
public class GoogleStorageBucket extends org.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>A storage bucket implementation based on Google Storage. This implementation supports all optionalBucketoperations, and maintains List-after-write consistency.- Author:
- Oren Peer, Eyal Schneider
-
-
Field Summary
Fields Modifier and Type Field Description static StringACL_PUBLIC_READstatic StringX_GOOG_ACL_HEADERstatic StringX_GOOG_CONTENT_LENGTH_RANGEstatic StringX_GOOG_RESUMABLE_HEADER
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description com.google.cloud.storage.Blobcompose(List<String> gsPaths, String composedFilePath, boolean removeComprisingFiles)voidcopyToAnotherBucket(String fromKey, String toBucket, String toKey)voiddelete(com.google.cloud.storage.Blob obj)voiddeleteAllByMetaInterruptibly(Collection<com.google.cloud.storage.Blob> fileRefs, int parallelism, int maxRetries, int initialRetrySleepSec, double waitTimeFactor)booleanexists(String key)URLgenerateReadOnlyUrl(String key, int expirationSeconds)URLgenerateResumableSignedUrlForUpload(String key, String contentType, int expirationSeconds, Long maxContentLengthInBytes, boolean isPublic)URLgenerateSignedUrl(String key, String contentType, int expirationSeconds, boolean isPublicRead)voidget(com.google.cloud.storage.Blob meta, File output)voidget(ExecutorService ex, String key, File output)Downloads a file from Google Storage, using sliced downloadvoidget(ExecutorService ex, String key, File output, int chunkSize)Downloads a file from Google Storage, using sliced download.Set<File>getAllRegularFilesByMetaInterruptibly(Collection<com.google.cloud.storage.Blob> metaObjects, File targetFolder, Function<String,String> fileNameResolver, int parallelism, int maxRetries, int initialRetrySleepSec, double waitTimeFactor)Retrieves a set of files from different paths, in an efficient manner.org.pipecraft.infra.io.SizedInputStreamgetAsStream(com.google.cloud.storage.Blob meta, int chunkSize)<C> CgetFromJson(String key, Class<C> clazz)LonggetLastUpdated(com.google.cloud.storage.Blob keyMetadata)longgetLength(com.google.cloud.storage.Blob keyMetadata)com.google.cloud.storage.BlobgetObjectMetadata(String key)Map<String,com.google.cloud.storage.Blob>getObjectMetadata(Collection<String> filePaths)OutputStreamgetOutputStream(String key, int chunkSize)StringgetPath(com.google.cloud.storage.Blob keyMetadata)voidgetSliced(String key, File output)Deprecated.Use the other get(ExecutorService ..) or getSliced(..) methods, as they handles better interrupted exceptionsvoidgetSliced(String key, File output, int chunkSize)Downloads a file from Google Storage, using sliced download.Iterator<com.google.cloud.storage.Blob>listObjects(String folderPath, boolean recursive)voidput(String key, InputStream input, long length, String contentType, boolean isPublic, boolean allowOverride)-
Methods inherited from class org.pipecraft.infra.storage.Bucket
copy, copyFolderRecursiveInterruptibly, copyFolderRecursiveInterruptibly, copyInterruptibly, copyInterruptibly, copyToAnotherBucketInterruptibly, copyToAnotherBucketInterruptibly, delete, deleteAllByMetaInterruptibly, deleteAllByMetaInterruptibly, deleteAllByMetaInterruptibly, deleteAllInterruptibly, deleteAllInterruptibly, deleteAllInterruptibly, deleteAllInterruptibly, deleteFolderRecursiveInterruptibly, deleteFolderRecursiveInterruptibly, deleteFolderRegularFiles, deleteInterruptibly, deleteInterruptibly, deleteInterruptibly, deleteInterruptibly, generateResumableSignedUrlForUpload, generateSignedUrl, get, getAllRegularFiles, getAllRegularFilesByMetaInterruptibly, getAllRegularFilesByMetaInterruptibly, getAllRegularFilesByMetaInterruptibly, getAllRegularFilesInterruptibly, getAllRegularFilesInterruptibly, getAllRegularFilesInterruptibly, getAllRegularFilesInterruptibly, getAllRegularFilesInterruptibly, getAllRegularFilesInterruptibly, getAllRegularFilesInterruptibly, getAsStream, getAsStream, getAsStream, getBucketName, getInterruptibly, getInterruptibly, getInterruptibly, getInterruptibly, getLastFile, getObjectMetadata, getOutputStream, isFile, isFilePath, isFolderPath, listFiles, listFiles, listFiles, listFilesRecursive, listFilesRecursive, listFilesRecursive, listFolders, listObjects, listObjects, moveFolderRecursive, moveFolderRecursive, moveInterruptibly, moveInterruptibly, normalizeFolderPath, put, putAllInterruptibly, putAllInterruptibly, putAllRecursiveInterruptibly, putAllRecursiveInterruptibly, putDoneFile, putEmptyFile, putFile, putFileInterruptibly, putFileInterruptibly, putLockFile, putPrivate, putPrivate, putPublic, putPublic, putUniquePrivate, putUniquePrivate, putUniquePrivate, putUniquePublic, putUniquePublic, putUniquePublic, validateNotFolderPath
-
-
-
-
Field Detail
-
X_GOOG_ACL_HEADER
public static final String X_GOOG_ACL_HEADER
- See Also:
- Constant Field Values
-
ACL_PUBLIC_READ
public static final String ACL_PUBLIC_READ
- See Also:
- Constant Field Values
-
X_GOOG_RESUMABLE_HEADER
public static final String X_GOOG_RESUMABLE_HEADER
- See Also:
- Constant Field Values
-
X_GOOG_CONTENT_LENGTH_RANGE
public static final String X_GOOG_CONTENT_LENGTH_RANGE
- See Also:
- Constant Field Values
-
-
Method Detail
-
put
public void put(String key, InputStream input, long length, String contentType, boolean isPublic, boolean allowOverride) throws IOException
- Specified by:
putin classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>- Throws:
IOException
-
getOutputStream
public OutputStream getOutputStream(String key, int chunkSize) throws IOException
- Specified by:
getOutputStreamin classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>- Throws:
IOException
-
get
public void get(com.google.cloud.storage.Blob meta, File output) throws IOException- Specified by:
getin classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>- Throws:
IOException
-
get
public void get(ExecutorService ex, String key, File output, int chunkSize) throws IOException, InterruptedException
Downloads a file from Google Storage, using sliced download. Retries are performed on individual slices.- Parameters:
ex- The executor to use for downloading the filekey- Google Storage key name (not including bucket)output- The target file to write to (overriding write). The file may not exist, but the folder must exist.chunkSize- The size (in bytes) of each chunk read from GS at once, or 0 for using the default one. It is recommended that the chunkSize size be between 2MB and 6MB. the memory usage will be at least MAX_THREAD_FOR_DOWNLOAD * chunkSize- Throws:
FileNotFoundException- In case that the key wasn't found in the bucketIOException- In case of IO error while reading the file, or in case that the thread has been interruptedInterruptedException- in case of an interruption while waiting for all slices to be downloaded
-
get
public void get(ExecutorService ex, String key, File output) throws IOException, InterruptedException
Downloads a file from Google Storage, using sliced download- Parameters:
ex- The executor to use for downloading the filekey- Google Storage key name (not including bucket)output- The target file to write to- Throws:
FileNotFoundException- In case that the key wasn't found in the bucketIOException- In case of IO error while reading the fileInterruptedException- in case of an interruption while waiting for all slices to be downloaded
-
getSliced
public void getSliced(String key, File output, int chunkSize) throws IOException, InterruptedException
Downloads a file from Google Storage, using sliced download. Uses a temporary pooled executor.- Overrides:
getSlicedin classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>- Parameters:
key- Google Storage key name (not including bucket)output- The target file to write tochunkSize- The size (in bytes) of each chunk read from GS at once, or 0 for using the default one. It is recommended that the chunkSize size be between 2MB and 6MB. the memory usage will be at least MAX_THREAD_FOR_DOWNLOAD * chunkSize- Throws:
FileNotFoundException- In case that the key wasn't found in the bucketIOException- In case of IO error while reading the fileInterruptedException- in case of an interruption while waiting for all slices to be downloaded
-
getSliced
@Deprecated public void getSliced(String key, File output) throws IOException
Deprecated.Use the other get(ExecutorService ..) or getSliced(..) methods, as they handles better interrupted exceptionsDownloads a file from Google Storage, using sliced download. Uses a temporary pooled executor, and default chunk size.- Overrides:
getSlicedin classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>- Parameters:
key- Google Storage key name (not including bucket)output- The target file to write to- Throws:
FileNotFoundException- In case that the key wasn't found in the bucketIOException- In case of IO error while reading the file, or if the thread is interrupted while waiting for all slices to download
-
getFromJson
public <C> C getFromJson(String key, Class<C> clazz) throws IOException, org.pipecraft.infra.storage.IllegalJsonException
- Overrides:
getFromJsonin classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>- Throws:
IOExceptionorg.pipecraft.infra.storage.IllegalJsonException
-
getAsStream
public org.pipecraft.infra.io.SizedInputStream getAsStream(com.google.cloud.storage.Blob meta, int chunkSize) throws IOException- Specified by:
getAsStreamin classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>- Throws:
IOException
-
getAllRegularFilesByMetaInterruptibly
public Set<File> getAllRegularFilesByMetaInterruptibly(Collection<com.google.cloud.storage.Blob> metaObjects, File targetFolder, Function<String,String> fileNameResolver, int parallelism, int maxRetries, int initialRetrySleepSec, double waitTimeFactor) throws IOException, InterruptedException
Retrieves a set of files from different paths, in an efficient manner. This method is intended to speed up multi file download, by applying concurrent sliced download on multiple files. The implementation bounds the total number of file handles (connections+local files) it opens at once. The bound is twice the value passed in the parallelism parameter. Expects a fileNameResolver, which allows assigning different names to target files. This may be useful for example when protecting from remote files with the same name to override each other.- Overrides:
getAllRegularFilesByMetaInterruptiblyin classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>- Parameters:
metaObjects- The collection of objects pointing to the remote files to downloadtargetFolder- The local target folder to write files to. Created if needed.fileNameResolver- A mapper between remote path (relative to bucket) to the local file name to assign to it (just name, without path).parallelism- The number of threads to use for the taskmaxRetries- Maximum number of retries in case of IOException (except forFileNotFoundExceptionwhich won't trigger retries).initialRetrySleepSec- The initial number of seconds to sleep between retries (increases exponentially)waitTimeFactor- A factor by which the sleep times between retries increases (millisecond precision)- Returns:
- The set of downloaded file objects
- Throws:
FileNotFoundException- In case that the one of the paths wasn't found in the bucketIOException- In case of IO error while downloading the filesInterruptedException- In case that the thread is interrupted
-
copyToAnotherBucket
public void copyToAnotherBucket(String fromKey, String toBucket, String toKey) throws IOException
- Specified by:
copyToAnotherBucketin classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>- Throws:
IOException
-
delete
public void delete(com.google.cloud.storage.Blob obj) throws IOException- Specified by:
deletein classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>- Throws:
IOException
-
deleteAllByMetaInterruptibly
public void deleteAllByMetaInterruptibly(Collection<com.google.cloud.storage.Blob> fileRefs, int parallelism, int maxRetries, int initialRetrySleepSec, double waitTimeFactor) throws IOException, InterruptedException
- Overrides:
deleteAllByMetaInterruptiblyin classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>- Throws:
IOExceptionInterruptedException
-
exists
public boolean exists(String key) throws IOException
- Specified by:
existsin classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>- Throws:
IOException
-
listObjects
public Iterator<com.google.cloud.storage.Blob> listObjects(String folderPath, boolean recursive) throws IOException
- Specified by:
listObjectsin classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>- Throws:
IOException
-
generateSignedUrl
public URL generateSignedUrl(String key, String contentType, int expirationSeconds, boolean isPublicRead)
- Specified by:
generateSignedUrlin classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>
-
generateReadOnlyUrl
public URL generateReadOnlyUrl(String key, int expirationSeconds)
- Specified by:
generateReadOnlyUrlin classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>
-
generateResumableSignedUrlForUpload
public URL generateResumableSignedUrlForUpload(String key, String contentType, int expirationSeconds, Long maxContentLengthInBytes, boolean isPublic) throws IOException
- Specified by:
generateResumableSignedUrlForUploadin classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>- Throws:
IOException
-
getObjectMetadata
public com.google.cloud.storage.Blob getObjectMetadata(String key) throws IOException
- Specified by:
getObjectMetadatain classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>- Throws:
IOException
-
getObjectMetadata
public Map<String,com.google.cloud.storage.Blob> getObjectMetadata(Collection<String> filePaths) throws IOException, InterruptedException
- Overrides:
getObjectMetadatain classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>- Throws:
IOExceptionInterruptedException
-
getPath
public String getPath(com.google.cloud.storage.Blob keyMetadata)
- Specified by:
getPathin classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>
-
getLength
public long getLength(com.google.cloud.storage.Blob keyMetadata)
- Specified by:
getLengthin classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>
-
getLastUpdated
public Long getLastUpdated(com.google.cloud.storage.Blob keyMetadata)
- Specified by:
getLastUpdatedin classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>
-
compose
public com.google.cloud.storage.Blob compose(List<String> gsPaths, String composedFilePath, boolean removeComprisingFiles) throws IOException
- Specified by:
composein classorg.pipecraft.infra.storage.Bucket<com.google.cloud.storage.Blob>- Throws:
IOException
-
-