Example usage for org.apache.hadoop.fs.s3a Constants S3_CLIENT_FACTORY_IMPL

List of usage examples for org.apache.hadoop.fs.s3a Constants S3_CLIENT_FACTORY_IMPL

Introduction

In this page you can find the example usage for org.apache.hadoop.fs.s3a Constants S3_CLIENT_FACTORY_IMPL.

Prototype

String S3_CLIENT_FACTORY_IMPL

To view the source code for org.apache.hadoop.fs.s3a Constants S3_CLIENT_FACTORY_IMPL.

Click Source Link

Usage

From source file:com.thinkbiganalytics.kylo.catalog.aws.S3FileSystemProvider.java

License:Apache License

@Nonnull
@Override// w w  w  . j a  va  2  s .  c o  m
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();
    }
}

From source file:com.thinkbiganalytics.kylo.catalog.aws.S3FileSystemProviderTest.java

License:Apache License

/**
 * Verify listing buckets using the s3a scheme.
 *///  w  ww . j a v a2s . c o m
@Test
@SuppressWarnings("unchecked")
public void listFilesS3a() {
    // Setup configuration
    final Configuration conf = new Configuration(false);
    conf.setClass(Constants.S3_CLIENT_FACTORY_IMPL, MockS3ClientFactory.class, S3ClientFactory.class);

    // Test listing buckets
    final S3FileSystemProvider provider = new S3FileSystemProvider();
    final List<DataSetFile> files = provider.listFiles(new Path(S3A), conf);
    Assert.assertThat(files, CoreMatchers.hasItems(isDataSetFile(MockS3ClientFactory.BUCKET1),
            isDataSetFile(MockS3ClientFactory.BUCKET2)));
    Assert.assertEquals(2, files.size());
}