@InterfaceAudience.Private @InterfaceStability.Evolving public final class S3AUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
S3AUtils.CallOnLocatedFileStatus
An interface for use in lambda-expressions working with
directory tree listings.
|
static interface |
S3AUtils.LocatedFileStatusMap<T>
An interface for use in lambda-expressions working with
directory tree listings.
|
| Modifier and Type | Field and Description |
|---|---|
static org.apache.hadoop.fs.PathFilter |
ACCEPT_ALL
A Path filter which accepts all filenames.
|
static org.apache.hadoop.fs.PathFilter |
HIDDEN_FILE_FILTER
Path filter which ignores any file which starts with .
|
static String |
SSE_C_NO_KEY_ERROR
Encryption SSE-C used but the config lacks an encryption key.
|
static String |
SSE_S3_WITH_KEY_ERROR
Encryption SSE-S3 is used but the caller also set an encryption key.
|
| Modifier and Type | Method and Description |
|---|---|
static long |
applyLocatedFiles(org.apache.hadoop.fs.RemoteIterator<org.apache.hadoop.fs.LocatedFileStatus> iterator,
S3AUtils.CallOnLocatedFileStatus eval)
Apply an operation to every
LocatedFileStatus in a remote
iterator. |
static void |
clearBucketOption(org.apache.hadoop.conf.Configuration conf,
String bucket,
String genericKey)
Clear a bucket-specific property.
|
static void |
closeAll(org.slf4j.Logger log,
Closeable... closeables)
Close the Closeable objects and ignore any Exception or
null pointers.
|
static void |
closeAutocloseables(org.slf4j.Logger log,
AutoCloseable... closeables)
Close the Closeable objects and ignore any Exception or
null pointers.
|
static com.amazonaws.ClientConfiguration |
createAwsConf(org.apache.hadoop.conf.Configuration conf,
String bucket)
Create a new AWS
ClientConfiguration. |
static com.amazonaws.auth.AWSCredentialsProvider |
createAWSCredentialProvider(org.apache.hadoop.conf.Configuration conf,
Class<?> credClass,
URI uri)
Create an AWS credential provider from its class by using reflection.
|
static AWSCredentialProviderList |
createAWSCredentialProviderSet(URI binding,
org.apache.hadoop.conf.Configuration conf)
Create the AWS credentials from the providers, the URI and
the key
Constants.AWS_CREDENTIALS_PROVIDER in the configuration. |
static S3AFileStatus |
createFileStatus(org.apache.hadoop.fs.Path keyPath,
com.amazonaws.services.s3.model.S3ObjectSummary summary,
long blockSize,
String owner)
Create a files status instance from a listing.
|
static S3AFileStatus |
createUploadFileStatus(org.apache.hadoop.fs.Path keyPath,
boolean isDir,
long size,
long blockSize,
String owner)
Create a file status for object we just uploaded.
|
static long |
dateToLong(Date date)
Date to long conversion.
|
static void |
deleteQuietly(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path,
boolean recursive)
Delete a path quietly: failures are logged at DEBUG.
|
static void |
deleteWithWarning(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path,
boolean recursive)
Delete a path: failures are logged at WARN.
|
static int |
ensureOutputParameterInRange(String name,
long size)
Ensure that the long value is in the range of an integer.
|
static IOException |
extractException(String operation,
String path,
ExecutionException ee)
Extract an exception from a failed future, and convert to an IOE.
|
static <T> List<T> |
flatmapLocatedFiles(org.apache.hadoop.fs.RemoteIterator<org.apache.hadoop.fs.LocatedFileStatus> iterator,
S3AUtils.LocatedFileStatusMap<Optional<T>> eval)
Map an operation to every
LocatedFileStatus in a remote
iterator, returning a list of the all results which were not empty. |
static S3xLoginHelper.Login |
getAWSAccessKeys(URI name,
org.apache.hadoop.conf.Configuration conf)
Return the access key and secret for S3 API use.
|
static String |
getBucketOption(org.apache.hadoop.conf.Configuration conf,
String bucket,
String genericKey)
Get a bucket-specific property.
|
static long |
getMultipartSizeProperty(org.apache.hadoop.conf.Configuration conf,
String property,
long defVal)
Get a size property from the configuration: this property must
be at least equal to
Constants.MULTIPART_MIN_SIZE. |
static void |
initConnectionSettings(org.apache.hadoop.conf.Configuration conf,
com.amazonaws.ClientConfiguration awsConf)
Initializes all AWS SDK settings related to connection management.
|
static void |
initProxySupport(org.apache.hadoop.conf.Configuration conf,
String bucket,
com.amazonaws.ClientConfiguration awsConf)
Initializes AWS SDK proxy support in the AWS client configuration
if the S3A settings enable it.
|
static boolean |
isThrottleException(Exception ex)
Is the exception an instance of a throttling exception.
|
static List<org.apache.hadoop.fs.LocatedFileStatus> |
listAndFilter(org.apache.hadoop.fs.FileSystem fileSystem,
org.apache.hadoop.fs.Path path,
boolean recursive,
org.apache.hadoop.fs.PathFilter filter)
List located files and filter them as a classic listFiles(path, filter)
would do.
|
static Class<?>[] |
loadAWSProviderClasses(org.apache.hadoop.conf.Configuration conf,
String key,
Class<?>... defaultValue)
Load list of AWS credential provider/credential provider factory classes.
|
static long |
longBytesOption(org.apache.hadoop.conf.Configuration conf,
String key,
long defVal,
long min)
Get a long option >= the minimum allowed value, supporting memory
prefixes K,M,G,T,P.
|
static String |
lookupPassword(String bucket,
org.apache.hadoop.conf.Configuration conf,
String baseKey)
Get a password from a configuration, including JCEKS files, handling both
the absolute key and bucket override.
|
static String |
lookupPassword(String bucket,
org.apache.hadoop.conf.Configuration conf,
String baseKey,
String overrideVal)
Deprecated.
|
static String |
lookupPassword(String bucket,
org.apache.hadoop.conf.Configuration conf,
String baseKey,
String overrideVal,
String defVal)
Get a password from a configuration, including JCEKS files, handling both
the absolute key and bucket override.
|
static <T> List<T> |
mapLocatedFiles(org.apache.hadoop.fs.RemoteIterator<org.apache.hadoop.fs.LocatedFileStatus> iterator,
S3AUtils.LocatedFileStatusMap<T> eval)
Map an operation to every
LocatedFileStatus in a remote
iterator, returning a list of the results. |
static <T> Optional<T> |
maybe(boolean include,
T value)
Convert a value into a non-empty Optional instance if
the value of
include is true. |
static boolean |
objectRepresentsDirectory(String name,
long size)
Predicate: does the object represent a directory?.
|
static org.apache.hadoop.conf.Configuration |
propagateBucketOptions(org.apache.hadoop.conf.Configuration source,
String bucket)
Propagates bucket-specific settings into generic S3A configuration keys.
|
static void |
setBucketOption(org.apache.hadoop.conf.Configuration conf,
String bucket,
String genericKey,
String value)
Set a bucket-specific property to a particular value.
|
static boolean |
signifiesConnectionBroken(com.amazonaws.SdkBaseException ex)
Cue that an AWS exception is likely to be an EOF Exception based
on the message coming back from an XML/JSON parser.
|
static String |
stringify(com.amazonaws.services.s3.model.AmazonS3Exception e)
Get low level details of an amazon exception for logging; multi-line.
|
static String |
stringify(com.amazonaws.AmazonServiceException e)
Get low level details of an amazon exception for logging; multi-line.
|
static String |
stringify(com.amazonaws.services.s3.model.S3ObjectSummary summary)
String information about a summary entry for debug messages.
|
static IOException |
translateDynamoDBException(String path,
String message,
com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException ddbException)
Translate a DynamoDB exception into an IOException.
|
static IOException |
translateException(String operation,
org.apache.hadoop.fs.Path path,
com.amazonaws.AmazonClientException exception)
Translate an exception raised in an operation into an IOException.
|
static IOException |
translateException(String operation,
String path,
com.amazonaws.SdkBaseException exception)
Translate an exception raised in an operation into an IOException.
|
static IOException |
translateMultiObjectDeleteException(String message,
com.amazonaws.services.s3.model.MultiObjectDeleteException ex)
A MultiObjectDeleteException is raised if one or more delete objects
listed in a bulk DELETE operation failed.
|
public static final String SSE_C_NO_KEY_ERROR
public static final String SSE_S3_WITH_KEY_ERROR
public static final org.apache.hadoop.fs.PathFilter HIDDEN_FILE_FILTER
public static final org.apache.hadoop.fs.PathFilter ACCEPT_ALL
public static IOException translateException(String operation, org.apache.hadoop.fs.Path path, com.amazonaws.AmazonClientException exception)
AmazonClientException passed in, and any status codes included
in the operation. That is: HTTP error codes are examined and can be
used to build a more specific response.operation - operationpath - path operated on (must not be null)exception - amazon exception raisedpublic static IOException translateException(@Nullable String operation, String path, com.amazonaws.SdkBaseException exception)
AmazonClientException passed in, and any status codes included
in the operation. That is: HTTP error codes are examined and can be
used to build a more specific response.operation - operationpath - path operated on (may be null)exception - amazon exception raisedpublic static IOException extractException(String operation, String path, ExecutionException ee)
operation - operation which failedpath - path operated on (may be null)ee - execution exceptionpublic static boolean isThrottleException(Exception ex)
AWSServiceThrottledException,
or anything which the AWS SDK's RetryUtils considers to be
a throttling exception.ex - exception to examinepublic static boolean signifiesConnectionBroken(com.amazonaws.SdkBaseException ex)
ex - exceptionpublic static IOException translateDynamoDBException(String path, String message, com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException ddbException)
path - path in the DDBmessage - preformatted message for the exceptionddbException - exceptionpublic static IOException translateMultiObjectDeleteException(String message, com.amazonaws.services.s3.model.MultiObjectDeleteException ex)
message - text for the exceptionex - exception to translatepublic static String stringify(com.amazonaws.AmazonServiceException e)
e - exceptionpublic static String stringify(com.amazonaws.services.s3.model.AmazonS3Exception e)
e - exceptionpublic static S3AFileStatus createFileStatus(org.apache.hadoop.fs.Path keyPath, com.amazonaws.services.s3.model.S3ObjectSummary summary, long blockSize, String owner)
keyPath - path to entrysummary - summary from AWSblockSize - block size to declare.owner - owner of the filepublic static S3AFileStatus createUploadFileStatus(org.apache.hadoop.fs.Path keyPath, boolean isDir, long size, long blockSize, String owner)
keyPath - path for created objectisDir - true iff directorysize - file lengthblockSize - block size for file statusowner - Hadoop usernamepublic static boolean objectRepresentsDirectory(String name, long size)
name - object namesize - object sizepublic static long dateToLong(Date date)
date - date from AWS querypublic static AWSCredentialProviderList createAWSCredentialProviderSet(URI binding, org.apache.hadoop.conf.Configuration conf) throws IOException
Constants.AWS_CREDENTIALS_PROVIDER in the configuration.binding - Binding URI, may contain user:pass login details;
may be nullconf - filesystem configurationIOException - Problems loading the providers (including reading
secrets from credential files).public static Class<?>[] loadAWSProviderClasses(org.apache.hadoop.conf.Configuration conf, String key, Class<?>... defaultValue) throws IOException
conf - configurationkey - keydefaultValue - list of default valuesIOException - on a failure to load the list.public static com.amazonaws.auth.AWSCredentialsProvider createAWSCredentialProvider(org.apache.hadoop.conf.Configuration conf,
Class<?> credClass,
URI uri)
throws IOException
conf - configurationcredClass - credential classuri - URI of the FSIOException - on any instantiation failure.public static S3xLoginHelper.Login getAWSAccessKeys(URI name, org.apache.hadoop.conf.Configuration conf) throws IOException
name - the URI for which we need the access keys; may be nullconf - the Configuration object to interrogate for keys.IOException - problems retrieving passwords from KMS.@Deprecated public static String lookupPassword(String bucket, org.apache.hadoop.conf.Configuration conf, String baseKey, String overrideVal) throws IOException
bucket - bucket or "" if none knownconf - configurationbaseKey - base key to look up, e.g "fs.s3a.secret.key"overrideVal - override value: if non empty this is used instead of
querying the configuration.IOException - on any IO problemIllegalArgumentException - bad argumentspublic static String lookupPassword(String bucket, org.apache.hadoop.conf.Configuration conf, String baseKey) throws IOException
bucket - bucket or "" if none knownconf - configurationbaseKey - base key to look up, e.g "fs.s3a.secret.key"IOException - on any IO problemIllegalArgumentException - bad argumentspublic static String lookupPassword(String bucket, org.apache.hadoop.conf.Configuration conf, String baseKey, String overrideVal, String defVal) throws IOException
bucket - bucket or "" if none knownconf - configurationbaseKey - base key to look up, e.g "fs.s3a.secret.key"overrideVal - override value: if non empty this is used instead of
querying the configuration.defVal - value to return if there is no passwordIOException - on any IO problemIllegalArgumentException - bad argumentspublic static String stringify(com.amazonaws.services.s3.model.S3ObjectSummary summary)
summary - summary objectpublic static long longBytesOption(org.apache.hadoop.conf.Configuration conf,
String key,
long defVal,
long min)
conf - configurationkey - key to look updefVal - default valuemin - minimum valueIllegalArgumentException - if the value is below the minimumpublic static long getMultipartSizeProperty(org.apache.hadoop.conf.Configuration conf,
String property,
long defVal)
Constants.MULTIPART_MIN_SIZE.
If it is too small, it is rounded up to that minimum, and a warning
printed.conf - configurationproperty - property namedefVal - default valuepublic static int ensureOutputParameterInRange(String name, long size)
name - property name for error messagessize - original sizepublic static org.apache.hadoop.conf.Configuration propagateBucketOptions(org.apache.hadoop.conf.Configuration source,
String bucket)
fs.s3a.bucket.${bucket}.key to
fs.s3a.key, for all values of "key" other than a small set
of unmodifiable values.
The source of the updated property is set to the key name of the bucket
property, to aid in diagnostics of where things came from.
Returns a new configuration. Why the clone?
You can use the same conf for different filesystems, and the original
values are not updated.
The fs.s3a.impl property cannot be set, nor can
any with the prefix fs.s3a.bucket.
This method does not propagate security provider path information from
the S3A property into the Hadoop common provider: callers must call
patchSecurityCredentialProviders(Configuration) explicitly.source - Source Configuration object.bucket - bucket name. Must not be empty.public static void deleteQuietly(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path,
boolean recursive)
fs - filesystempath - pathrecursive - recursive?public static void deleteWithWarning(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path,
boolean recursive)
fs - filesystempath - pathrecursive - recursive?public static com.amazonaws.ClientConfiguration createAwsConf(org.apache.hadoop.conf.Configuration conf,
String bucket)
throws IOException
ClientConfiguration.
All clients to AWS services MUST use this for consistent setup
of connectivity, UA, proxy settings.conf - The Hadoop configurationbucket - Optional bucket to use to look up per-bucket proxy secretsIOExceptionpublic static void initConnectionSettings(org.apache.hadoop.conf.Configuration conf,
com.amazonaws.ClientConfiguration awsConf)
conf - Hadoop configurationawsConf - AWS SDK configurationpublic static void initProxySupport(org.apache.hadoop.conf.Configuration conf,
String bucket,
com.amazonaws.ClientConfiguration awsConf)
throws IllegalArgumentException,
IOException
conf - Hadoop configurationbucket - Optional bucket to use to look up per-bucket proxy secretsawsConf - AWS SDK configuration to updateIllegalArgumentException - if misconfiguredIOException - problem getting username/secret from password source.public static long applyLocatedFiles(org.apache.hadoop.fs.RemoteIterator<org.apache.hadoop.fs.LocatedFileStatus> iterator,
S3AUtils.CallOnLocatedFileStatus eval)
throws IOException
LocatedFileStatus in a remote
iterator.iterator - iterator from a listeval - closure to evaluateIOException - anything in the closure, or iteration logic.public static <T> List<T> mapLocatedFiles(org.apache.hadoop.fs.RemoteIterator<org.apache.hadoop.fs.LocatedFileStatus> iterator, S3AUtils.LocatedFileStatusMap<T> eval) throws IOException
LocatedFileStatus in a remote
iterator, returning a list of the results.T - return type of mapiterator - iterator from a listeval - closure to evaluateIOException - anything in the closure, or iteration logic.public static <T> List<T> flatmapLocatedFiles(org.apache.hadoop.fs.RemoteIterator<org.apache.hadoop.fs.LocatedFileStatus> iterator, S3AUtils.LocatedFileStatusMap<Optional<T>> eval) throws IOException
LocatedFileStatus in a remote
iterator, returning a list of the all results which were not empty.T - return type of mapiterator - iterator from a listeval - closure to evaluateIOException - anything in the closure, or iteration logic.public static List<org.apache.hadoop.fs.LocatedFileStatus> listAndFilter(org.apache.hadoop.fs.FileSystem fileSystem, org.apache.hadoop.fs.Path path, boolean recursive, org.apache.hadoop.fs.PathFilter filter) throws IOException
fileSystem - filesystempath - path to listrecursive - recursive listing?filter - filter for the filenameIOException - IO failure.public static <T> Optional<T> maybe(boolean include, T value)
include is true.T - type of option.include - flag to indicate the value is to be included.value - value to returnpublic static void closeAll(org.slf4j.Logger log,
Closeable... closeables)
IOUtils).log - the log to log at debug level. Can be null.closeables - the objects to closepublic static void closeAutocloseables(org.slf4j.Logger log,
AutoCloseable... closeables)
IOUtils).log - the log to log at debug level. Can be null.closeables - the objects to closepublic static void setBucketOption(org.apache.hadoop.conf.Configuration conf,
String bucket,
String genericKey,
String value)
fs.s3a. prefix,
that's stripped off, so that when the the bucket properties are propagated
down to the generic values, that value gets copied down.conf - configuration to setbucket - bucket namegenericKey - key; can start with "fs.s3a."value - value to setpublic static void clearBucketOption(org.apache.hadoop.conf.Configuration conf,
String bucket,
String genericKey)
fs.s3a. prefix,
that's stripped off, so that when the the bucket properties are propagated
down to the generic values, that value gets copied down.conf - configuration to setbucket - bucket namegenericKey - key; can start with "fs.s3a."public static String getBucketOption(org.apache.hadoop.conf.Configuration conf, String bucket, String genericKey)
fs.s3a. prefix,
that's stripped off.conf - configuration to setbucket - bucket namegenericKey - key; can start with "fs.s3a."Copyright © 2008–2021 Apache Software Foundation. All rights reserved.