Search in sources :

Example 1 with S3ClientFactory

use of org.apache.hadoop.fs.s3a.S3ClientFactory in project kylo by Teradata.

the class S3FileSystemProvider method listFiles.

@Nonnull
@Override
public List<DataSetFile> listFiles(@Nonnull final Path path, @Nonnull final Configuration conf) {
    // Determine the credentials
    final AmazonS3 s3;
    final URI uri = path.toUri();
    if ("s3".equalsIgnoreCase(uri.getScheme()) || "s3bfs".equalsIgnoreCase(uri.getScheme()) || "s3n".equalsIgnoreCase(uri.getScheme())) {
        s3 = createS3Client(uri, conf);
    } else if ("s3a".equalsIgnoreCase(uri.getScheme())) {
        final Class<? extends S3ClientFactory> s3ClientFactoryClass = conf.getClass(Constants.S3_CLIENT_FACTORY_IMPL, Constants.DEFAULT_S3_CLIENT_FACTORY_IMPL, S3ClientFactory.class);
        try {
            s3 = ReflectionUtils.newInstance(s3ClientFactoryClass, conf).createS3Client(uri);
        } catch (final IOException e) {
            throw new IllegalArgumentException("Unable to create S3 client: " + e, e);
        }
    } else {
        log.debug("Scheme {} not supported for S3 path: {}", uri.getScheme(), path);
        throw new CatalogException("catalog.fs.s3.invalidScheme", uri.getScheme());
    }
    // Fetch the list of buckets
    try {
        return s3.listBuckets().stream().map(bucket -> {
            final DataSetFile file = new DataSetFile();
            file.setName(bucket.getName());
            file.setDirectory(true);
            file.setModificationTime(bucket.getCreationDate().getTime());
            file.setPath(uri.getScheme() + "://" + bucket.getName() + "/");
            return file;
        }).collect(Collectors.toList());
    } finally {
        s3.shutdown();
    }
}
Also used : InstanceProfileCredentialsProvider(com.amazonaws.auth.InstanceProfileCredentialsProvider) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) AWSCredentialsProviderChain(com.amazonaws.auth.AWSCredentialsProviderChain) LoggerFactory(org.slf4j.LoggerFactory) FileSystemProvider(com.thinkbiganalytics.kylo.catalog.spi.FileSystemProvider) BasicAWSCredentialsProvider(org.apache.hadoop.fs.s3a.BasicAWSCredentialsProvider) S3AUtils(org.apache.hadoop.fs.s3a.S3AUtils) ArrayList(java.util.ArrayList) CatalogException(com.thinkbiganalytics.kylo.catalog.CatalogException) Configuration(org.apache.hadoop.conf.Configuration) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Path(org.apache.hadoop.fs.Path) AmazonS3(com.amazonaws.services.s3.AmazonS3) URI(java.net.URI) Nonnull(javax.annotation.Nonnull) S3ClientFactory(org.apache.hadoop.fs.s3a.S3ClientFactory) Logger(org.slf4j.Logger) DataSetFile(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetFile) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Constants(org.apache.hadoop.fs.s3a.Constants) Component(org.springframework.stereotype.Component) List(java.util.List) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ReflectionUtils(org.apache.hadoop.util.ReflectionUtils) AmazonS3(com.amazonaws.services.s3.AmazonS3) S3ClientFactory(org.apache.hadoop.fs.s3a.S3ClientFactory) CatalogException(com.thinkbiganalytics.kylo.catalog.CatalogException) IOException(java.io.IOException) URI(java.net.URI) DataSetFile(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetFile) Nonnull(javax.annotation.Nonnull)

Aggregations

AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 AWSCredentialsProviderChain (com.amazonaws.auth.AWSCredentialsProviderChain)1 InstanceProfileCredentialsProvider (com.amazonaws.auth.InstanceProfileCredentialsProvider)1 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 CatalogException (com.thinkbiganalytics.kylo.catalog.CatalogException)1 DataSetFile (com.thinkbiganalytics.kylo.catalog.rest.model.DataSetFile)1 FileSystemProvider (com.thinkbiganalytics.kylo.catalog.spi.FileSystemProvider)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Nonnull (javax.annotation.Nonnull)1 Configuration (org.apache.hadoop.conf.Configuration)1 Path (org.apache.hadoop.fs.Path)1 BasicAWSCredentialsProvider (org.apache.hadoop.fs.s3a.BasicAWSCredentialsProvider)1 Constants (org.apache.hadoop.fs.s3a.Constants)1