public final class S3RestUtils extends 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 String |
ALLUXIO_USER_HEADER |
static String |
MULTIPART_UPLOADS_METADATA_DIR |
Modifier and Type | Method and Description |
---|---|
static <T> javax.ws.rs.core.Response |
call(String resource,
S3RestUtils.RestCallable<T> callable)
Calls the given
S3RestUtils.RestCallable and handles any exceptions thrown. |
static void |
checkPathIsAlluxioDirectory(FileSystem fs,
String bucketPath,
S3AuditContext auditContext)
Check if a path in alluxio is a directory.
|
static List<URIStatus> |
checkStatusesForUploadId(FileSystem metaFs,
FileSystem userFs,
AlluxioURI multipartTempDirUri,
String uploadId)
Fetches and returns the corresponding
URIStatus for both
the multipart upload temp directory and the Alluxio S3 metadata file. |
static FileSystem |
createFileSystemForUser(String user,
FileSystem fs) |
static 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,
Boolean recursive)
Delete an existing key.
|
static javax.ws.rs.core.MediaType |
deserializeContentType(Map<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(String taggingHeader,
int maxHeaderMetadataSize)
Given a URL-encoded Tagging header, parses and deserializes the Tagging metadata
into a
TaggingData object. |
static TaggingData |
deserializeTags(Map<String,byte[]> xAttr)
Given xAttr, parses and deserializes the Tagging metadata
into a
TaggingData object. |
static Map<String,String> |
fromMultiValueToSingleValueMap(javax.ws.rs.core.MultivaluedMap<String,String> queryParameters,
boolean lowerCase)
Convert MultivaluedMap to a single value map.
|
static String |
getEntityTag(URIStatus status)
This helper method is used to get the ETag xAttr on an object.
|
static String |
getMultipartMetaFilepathForUploadId(String uploadId) |
static String |
getMultipartTemporaryDirForObject(String bucketPath,
String objectKey,
String uploadId) |
static WritePType |
getS3WriteType() |
static String |
getUser(String authorization,
javax.ws.rs.container.ContainerRequestContext requestContext)
Get username from header info.
|
static String |
getUser(String authorization,
javax.servlet.http.HttpServletRequest request)
Get username from header info from HttpServletRequest.
|
static String |
getUserFromAuthorization(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 String |
parsePath(String bucketPath)
Format bucket path.
|
static void |
populateContentTypeInXAttr(Map<String,com.google.protobuf.ByteString> xattrMap,
String contentTypeHeader)
Populate xattr with content type info from header.
|
static void |
populateTaggingInXAttr(Map<String,com.google.protobuf.ByteString> xattrMap,
String taggingHeader,
S3AuditContext auditContext,
String objectPath)
Populate xattr map with tagging info from tagging header.
|
static void |
setEntityTag(FileSystem fs,
AlluxioURI objectUri,
String entityTag)
This helper method is used to set the ETag xAttr on an object.
|
static S3Exception |
toBucketS3Exception(Exception exception,
String resource)
Convert an exception to instance of
S3Exception . |
static S3Exception |
toBucketS3Exception(Exception exception,
String resource,
S3AuditContext auditContext)
Convert an exception to instance of
S3Exception . |
static S3Exception |
toObjectS3Exception(Exception exception,
String resource)
Convert an exception to instance of
S3Exception . |
static S3Exception |
toObjectS3Exception(Exception exception,
String resource,
S3AuditContext auditContext)
Convert an exception to instance of
S3Exception . |
static String |
toS3Date(long epoch) |
public static final String ALLUXIO_USER_HEADER
public static final String MULTIPART_UPLOADS_METADATA_DIR
public static <T> javax.ws.rs.core.Response call(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 String getMultipartTemporaryDirForObject(String bucketPath, String objectKey, 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 String getMultipartMetaFilepathForUploadId(String uploadId)
uploadId
- the upload IDpublic static String toS3Date(long epoch)
epoch
- the milliseconds from the epochpublic static String parsePath(String bucketPath)
bucketPath
- bucket pathpublic static S3Exception toBucketS3Exception(Exception exception, String resource)
S3Exception
.exception
- Exception thrown when process s3 object rest requestresource
- complete bucket pathS3Exception
public static S3Exception toBucketS3Exception(Exception exception, String resource, @Nonnull S3AuditContext auditContext)
S3Exception
.exception
- Exception thrown when process s3 object rest requestresource
- complete bucket pathauditContext
- the audit context for exceptionS3Exception
public static S3Exception toObjectS3Exception(Exception exception, String resource)
S3Exception
.exception
- Exception thrown when process s3 object rest requestresource
- object complete pathS3Exception
public static S3Exception toObjectS3Exception(Exception exception, String resource, @Nonnull S3AuditContext auditContext)
S3Exception
.exception
- Exception thrown when process s3 object rest requestresource
- object complete pathauditContext
- the audit context for exceptionS3Exception
public static void checkPathIsAlluxioDirectory(FileSystem fs, String bucketPath, @Nullable S3AuditContext auditContext) throws S3Exception
fs
- instance of FileSystem
bucketPath
- bucket complete pathauditContext
- the audit context for exceptionS3Exception
public static List<URIStatus> checkStatusesForUploadId(FileSystem metaFs, FileSystem userFs, AlluxioURI multipartTempDirUri, String uploadId) throws AlluxioException, 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 IdAlluxioException
IOException
public static void deleteExistObject(FileSystem fs, AlluxioURI objectURI) throws IOException, AlluxioException
fs
- instance of FileSystem
objectURI
- the key uriIOException
AlluxioException
public static void deleteExistObject(FileSystem fs, AlluxioURI objectURI, Boolean recursive) throws IOException, AlluxioException
fs
- instance of FileSystem
objectURI
- the key urirecursive
- if delete option is recursiveIOException
AlluxioException
public static WritePType getS3WriteType()
public static boolean isAuthenticationEnabled(AlluxioConfiguration conf)
conf
- Alluxio configurationpublic static FileSystem createFileSystemForUser(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 Map<String,String> fromMultiValueToSingleValueMap(javax.ws.rs.core.MultivaluedMap<String,String> queryParameters, boolean lowerCase)
queryParameters
- MultivaluedMaplowerCase
- whether to use lower casepublic static javax.ws.rs.core.MediaType deserializeContentType(Map<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(Map<String,byte[]> xAttr) throws IOException
TaggingData
object. Returns null if no data exists.xAttr
- the Inode's xAttrsTaggingData
objectIOException
public static TaggingData deserializeTaggingHeader(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
objectS3Exception
public static void setEntityTag(FileSystem fs, AlluxioURI objectUri, String entityTag) throws 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)IOException
AlluxioException
public static String getEntityTag(URIStatus status)
status
- The URIStatus
of the objectpublic static String getUser(String authorization, javax.ws.rs.container.ContainerRequestContext requestContext) throws S3Exception
authorization
- authorization inforequestContext
- request contextS3Exception
public static String getUser(String authorization, javax.servlet.http.HttpServletRequest request) throws S3Exception
authorization
- request
- S3Exception
public static String getUserFromAuthorization(String authorization, AlluxioConfiguration conf) throws S3Exception
authorization
- the authorization header stringconf
- the AlluxioConfiguration
Alluxio confS3Exception
public static void populateContentTypeInXAttr(Map<String,com.google.protobuf.ByteString> xattrMap, String contentTypeHeader)
xattrMap
- contentTypeHeader
- public static void populateTaggingInXAttr(Map<String,com.google.protobuf.ByteString> xattrMap, String taggingHeader, S3AuditContext auditContext, String objectPath) throws S3Exception
xattrMap
- taggingHeader
- auditContext
- objectPath
- S3Exception
public static Optional<com.google.common.util.concurrent.RateLimiter> createRateLimiter(long rate)
rate
- bytes per secondCopyright © 2023. All Rights Reserved.