public final class S3RestUtils
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
S3RestUtils.RestCallable<T>
An interface representing a callable.
|
static class |
S3RestUtils.URIStatusNameComparator
Comparator based on uri nameļ¼ treat uri name as a Long number.
|
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ALLUXIO_USER_HEADER |
static java.lang.String |
MULTIPART_UPLOADS_METADATA_DIR |
| Modifier and Type | Method and Description |
|---|---|
static <T> javax.ws.rs.core.Response |
call(java.lang.String resource,
S3RestUtils.RestCallable<T> callable)
Calls the given
S3RestUtils.RestCallable and handles any exceptions thrown. |
static void |
checkPathIsAlluxioDirectory(FileSystem fs,
java.lang.String bucketPath,
S3AuditContext auditContext)
Check if a path in alluxio is a directory.
|
static void |
checkPathIsAlluxioDirectory(FileSystem fs,
java.lang.String bucketPath,
S3AuditContext auditContext,
com.google.common.cache.Cache<java.lang.String,java.lang.Boolean> bucketPathCache)
Check if a path in alluxio is a directory.
|
static java.util.List<URIStatus> |
checkStatusesForUploadId(FileSystem metaFs,
FileSystem userFs,
AlluxioURI multipartTempDirUri,
java.lang.String uploadId)
Fetches and returns the corresponding
URIStatus for both
the multipart upload temp directory and the Alluxio S3 metadata file. |
static FileSystem |
createFileSystemForUser(java.lang.String user,
FileSystem fs) |
static java.util.Optional<com.google.common.util.concurrent.RateLimiter> |
createRateLimiter(long rate)
Create a rate limiter for given rate.
|
static void |
deleteExistObject(FileSystem fs,
AlluxioURI objectURI)
Delete an existing key.
|
static void |
deleteExistObject(FileSystem fs,
AlluxioURI objectURI,
java.lang.Boolean recursive)
Delete an existing key.
|
static javax.ws.rs.core.MediaType |
deserializeContentType(java.util.Map<java.lang.String,byte[]> xAttr)
Given xAttr, parses and returns the Content-Type header metadata
as its corresponding
MediaType, or otherwise defaults
to MediaType.APPLICATION_OCTET_STREAM_TYPE. |
static TaggingData |
deserializeTaggingHeader(java.lang.String taggingHeader,
int maxHeaderMetadataSize)
Given a URL-encoded Tagging header, parses and deserializes the Tagging metadata
into a
TaggingData object. |
static TaggingData |
deserializeTags(java.util.Map<java.lang.String,byte[]> xAttr)
Given xAttr, parses and deserializes the Tagging metadata
into a
TaggingData object. |
static java.util.Map<java.lang.String,java.lang.String> |
fromMultiValueToSingleValueMap(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> queryParameters,
boolean lowerCase)
Convert MultivaluedMap to a single value map.
|
static java.lang.String |
getEntityTag(URIStatus status)
This helper method is used to get the ETag xAttr on an object.
|
static java.lang.String |
getMultipartMetaFilepathForUploadId(java.lang.String uploadId) |
static java.lang.String |
getMultipartTemporaryDirForObject(java.lang.String bucketPath,
java.lang.String objectKey,
java.lang.String uploadId) |
static WritePType |
getS3WriteType() |
static java.lang.String |
getUser(java.lang.String authorization,
javax.ws.rs.container.ContainerRequestContext requestContext)
Get username from header info.
|
static java.lang.String |
getUser(java.lang.String authorization,
javax.servlet.http.HttpServletRequest request)
Get username from header info from HttpServletRequest.
|
static java.lang.String |
getUserFromAuthorization(java.lang.String authorization,
AlluxioConfiguration conf)
Gets the user from the authorization header string for AWS Signature Version 4.
|
static boolean |
isAuthenticationEnabled(AlluxioConfiguration conf)
Checks if authentication is enabled.
|
static java.lang.String |
parsePath(java.lang.String bucketPath)
Format bucket path.
|
static void |
populateContentTypeInXAttr(java.util.Map<java.lang.String,com.google.protobuf.ByteString> xattrMap,
java.lang.String contentTypeHeader)
Populate xattr with content type info from header.
|
static void |
populateTaggingInXAttr(java.util.Map<java.lang.String,com.google.protobuf.ByteString> xattrMap,
java.lang.String taggingHeader,
S3AuditContext auditContext,
java.lang.String objectPath)
Populate xattr map with tagging info from tagging header.
|
static void |
setEntityTag(FileSystem fs,
AlluxioURI objectUri,
java.lang.String entityTag)
This helper method is used to set the ETag xAttr on an object.
|
static S3Exception |
toBucketS3Exception(java.lang.Exception exception,
java.lang.String resource)
Convert an exception to instance of
S3Exception. |
static S3Exception |
toBucketS3Exception(java.lang.Exception exception,
java.lang.String resource,
S3AuditContext auditContext)
Convert an exception to instance of
S3Exception. |
static S3Exception |
toObjectS3Exception(java.lang.Exception exception,
java.lang.String resource)
Convert an exception to instance of
S3Exception. |
static S3Exception |
toObjectS3Exception(java.lang.Exception exception,
java.lang.String resource,
S3AuditContext auditContext)
Convert an exception to instance of
S3Exception. |
static java.lang.String |
toS3Date(long epoch) |
public static final java.lang.String ALLUXIO_USER_HEADER
public static final java.lang.String MULTIPART_UPLOADS_METADATA_DIR
public static <T> javax.ws.rs.core.Response call(java.lang.String resource,
S3RestUtils.RestCallable<T> callable)
S3RestUtils.RestCallable and handles any exceptions thrown.T - the return type of the callableresource - the resource (bucket or object) to be operated oncallable - the callable to callpublic static java.lang.String getMultipartTemporaryDirForObject(java.lang.String bucketPath,
java.lang.String objectKey,
java.lang.String uploadId)
bucketPath - the bucket path like "/bucket", "/mount/point/bucket"objectKey - the object key like "img/2017/9/1/s3.jpg"uploadId - the upload IDpublic static java.lang.String getMultipartMetaFilepathForUploadId(java.lang.String uploadId)
uploadId - the upload IDpublic static java.lang.String toS3Date(long epoch)
epoch - the milliseconds from the epochpublic static java.lang.String parsePath(java.lang.String bucketPath)
bucketPath - bucket pathpublic static S3Exception toBucketS3Exception(java.lang.Exception exception, java.lang.String resource)
S3Exception.exception - Exception thrown when process s3 object rest requestresource - complete bucket pathS3Exceptionpublic static S3Exception toBucketS3Exception(java.lang.Exception exception, java.lang.String resource, @Nonnull S3AuditContext auditContext)
S3Exception.exception - Exception thrown when process s3 object rest requestresource - complete bucket pathauditContext - the audit context for exceptionS3Exceptionpublic static S3Exception toObjectS3Exception(java.lang.Exception exception, java.lang.String resource)
S3Exception.exception - Exception thrown when process s3 object rest requestresource - object complete pathS3Exceptionpublic static S3Exception toObjectS3Exception(java.lang.Exception exception, java.lang.String resource, @Nonnull S3AuditContext auditContext)
S3Exception.exception - Exception thrown when process s3 object rest requestresource - object complete pathauditContext - the audit context for exceptionS3Exceptionpublic static void checkPathIsAlluxioDirectory(FileSystem fs, java.lang.String bucketPath, @Nullable S3AuditContext auditContext) throws S3Exception
fs - instance of FileSystembucketPath - bucket complete pathauditContext - the audit context for exceptionS3Exceptionpublic static void checkPathIsAlluxioDirectory(FileSystem fs, java.lang.String bucketPath, @Nullable S3AuditContext auditContext, com.google.common.cache.Cache<java.lang.String,java.lang.Boolean> bucketPathCache) throws S3Exception
fs - instance of FileSystembucketPath - bucket complete pathauditContext - the audit context for exceptionbucketPathCache - cache the bucket path for a certain time periodS3Exceptionpublic static java.util.List<URIStatus> checkStatusesForUploadId(FileSystem metaFs, FileSystem userFs, AlluxioURI multipartTempDirUri, java.lang.String uploadId) throws AlluxioException, java.io.IOException
URIStatus for both
the multipart upload temp directory and the Alluxio S3 metadata file.metaFs - instance of FileSystem - used for metadata operationsuserFs - instance of FileSystem - under the scope of a user agentmultipartTempDirUri - multipart upload tmp directory URIuploadId - multipart upload IdAlluxioExceptionjava.io.IOExceptionpublic static void deleteExistObject(FileSystem fs, AlluxioURI objectURI) throws java.io.IOException, AlluxioException
fs - instance of FileSystemobjectURI - the key urijava.io.IOExceptionAlluxioExceptionpublic static void deleteExistObject(FileSystem fs, AlluxioURI objectURI, java.lang.Boolean recursive) throws java.io.IOException, AlluxioException
fs - instance of FileSystemobjectURI - the key urirecursive - if delete option is recursivejava.io.IOExceptionAlluxioExceptionpublic static WritePType getS3WriteType()
public static boolean isAuthenticationEnabled(AlluxioConfiguration conf)
conf - Alluxio configurationpublic static FileSystem createFileSystemForUser(java.lang.String user, FileSystem fs)
user - the Subject name of the filesystem userfs - the source FileSystem to base off ofFileSystem with the subject set to the provided userpublic static java.util.Map<java.lang.String,java.lang.String> fromMultiValueToSingleValueMap(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> queryParameters,
boolean lowerCase)
queryParameters - MultivaluedMaplowerCase - whether to use lower casepublic static javax.ws.rs.core.MediaType deserializeContentType(java.util.Map<java.lang.String,byte[]> xAttr)
MediaType, or otherwise defaults
to MediaType.APPLICATION_OCTET_STREAM_TYPE.xAttr - the Inode's xAttrsMediaType corresponding to the Content-Type headerpublic static TaggingData deserializeTags(java.util.Map<java.lang.String,byte[]> xAttr) throws java.io.IOException
TaggingData object. Returns null if no data exists.xAttr - the Inode's xAttrsTaggingData objectjava.io.IOExceptionpublic static TaggingData deserializeTaggingHeader(java.lang.String taggingHeader, int maxHeaderMetadataSize) throws S3Exception
TaggingData object. Returns null on empty strings.taggingHeader - the URL-encoded Tagging headermaxHeaderMetadataSize - Header user-metadata size limit validation (default max: 2 KB)
- https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingMetadata.htmlTaggingData objectS3Exceptionpublic static void setEntityTag(FileSystem fs, AlluxioURI objectUri, java.lang.String entityTag) throws java.io.IOException, AlluxioException
fs - The FileSystem used to make the gRPC requestobjectUri - The AlluxioURI for the object to updateentityTag - The entity tag of the object (MD5 checksum of the object contents)java.io.IOExceptionAlluxioExceptionpublic static java.lang.String getEntityTag(URIStatus status)
status - The URIStatus of the objectpublic static java.lang.String getUser(java.lang.String authorization,
javax.ws.rs.container.ContainerRequestContext requestContext)
throws S3Exception
authorization - authorization inforequestContext - request contextS3Exceptionpublic static java.lang.String getUser(java.lang.String authorization,
javax.servlet.http.HttpServletRequest request)
throws S3Exception
authorization - request - S3Exceptionpublic static java.lang.String getUserFromAuthorization(java.lang.String authorization,
AlluxioConfiguration conf)
throws S3Exception
authorization - the authorization header stringconf - the AlluxioConfiguration Alluxio confS3Exceptionpublic static void populateContentTypeInXAttr(java.util.Map<java.lang.String,com.google.protobuf.ByteString> xattrMap,
java.lang.String contentTypeHeader)
xattrMap - contentTypeHeader - public static void populateTaggingInXAttr(java.util.Map<java.lang.String,com.google.protobuf.ByteString> xattrMap,
java.lang.String taggingHeader,
S3AuditContext auditContext,
java.lang.String objectPath)
throws S3Exception
xattrMap - taggingHeader - auditContext - objectPath - S3Exceptionpublic static java.util.Optional<com.google.common.util.concurrent.RateLimiter> createRateLimiter(long rate)
rate - bytes per secondCopyright © 2024. All Rights Reserved.