Search in sources :

Example 1 with S3AFileSystem

use of com.talend.shaded.org.apache.hadoop.fs.s3a.S3AFileSystem in project components by Talend.

the class S3Connection method createFileSystem.

public static S3AFileSystem createFileSystem(S3DatasetProperties properties) throws IOException {
    Configuration config = new Configuration(true);
    ExtraHadoopConfiguration extraConfig = new ExtraHadoopConfiguration();
    S3Connection.setS3Configuration(extraConfig, properties);
    extraConfig.addTo(config);
    try {
        return (S3AFileSystem) FileSystem.get(new URI(Constants.FS_S3A + "://" + properties.bucket.getValue()), config);
    } catch (URISyntaxException e) {
        // The URI is constant, so this exception should never occur.
        throw new RuntimeException(e);
    }
}
Also used : S3AFileSystem(com.talend.shaded.org.apache.hadoop.fs.s3a.S3AFileSystem) ExtraHadoopConfiguration(org.talend.components.simplefileio.runtime.ExtraHadoopConfiguration) Configuration(org.apache.hadoop.conf.Configuration) URISyntaxException(java.net.URISyntaxException) ExtraHadoopConfiguration(org.talend.components.simplefileio.runtime.ExtraHadoopConfiguration) URI(java.net.URI)

Example 2 with S3AFileSystem

use of com.talend.shaded.org.apache.hadoop.fs.s3a.S3AFileSystem in project components by Talend.

the class S3TestResource method getObjectMetadata.

/**
 * Get the ObjectMetadata from S3 for the first file found on the path specified by the S3DatasetProperties.
 */
public ObjectMetadata getObjectMetadata(S3DatasetProperties datasetProps) throws IOException {
    S3AFileSystem fs = S3Connection.createFileSystem(datasetProps);
    // The current path is a directory, so get a file to check the encryption.
    Path path = new Path(S3Connection.getUriPath(datasetProps));
    FileStatus[] files = fs.listStatus(path);
    assertThat(files, arrayWithSize(greaterThan(0)));
    return fs.getObjectMetadata(files[0].getPath());
}
Also used : S3AFileSystem(com.talend.shaded.org.apache.hadoop.fs.s3a.S3AFileSystem) Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus)

Example 3 with S3AFileSystem

use of com.talend.shaded.org.apache.hadoop.fs.s3a.S3AFileSystem in project components by Talend.

the class S3TestResource method after.

/**
 * Remove any resources created on the S3 bucket.
 */
@Override
protected void after() {
    try {
        S3DatasetProperties datasetProps = createS3DatasetProperties();
        S3AFileSystem fs = S3Connection.createFileSystem(datasetProps);
        Path path = new Path(S3Connection.getUriPath(datasetProps));
        if (fs.exists(path)) {
            fs.delete(path, true);
        }
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
Also used : S3AFileSystem(com.talend.shaded.org.apache.hadoop.fs.s3a.S3AFileSystem) Path(org.apache.hadoop.fs.Path) S3DatasetProperties(org.talend.components.simplefileio.s3.S3DatasetProperties) IOException(java.io.IOException)

Aggregations

S3AFileSystem (com.talend.shaded.org.apache.hadoop.fs.s3a.S3AFileSystem)3 Path (org.apache.hadoop.fs.Path)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Configuration (org.apache.hadoop.conf.Configuration)1 FileStatus (org.apache.hadoop.fs.FileStatus)1 ExtraHadoopConfiguration (org.talend.components.simplefileio.runtime.ExtraHadoopConfiguration)1 S3DatasetProperties (org.talend.components.simplefileio.s3.S3DatasetProperties)1