Search in sources :

Example 1 with ExtraHadoopConfiguration

use of org.talend.components.simplefileio.runtime.ExtraHadoopConfiguration 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 ExtraHadoopConfiguration

use of org.talend.components.simplefileio.runtime.ExtraHadoopConfiguration in project components by Talend.

the class S3OutputRuntime method runAtDriver.

/**
 * If overwriting a file, causes any any files at the existing location to be deleted.
 *
 * This action occurs before running the job.
 */
@Override
public void runAtDriver(RuntimeContainer container) {
    if (properties.overwrite.getValue()) {
        try {
            Path p = new Path(S3Connection.getUriPath(properties.getDatasetProperties()));
            // Add the AWS configuration to the Hadoop filesystem.
            ExtraHadoopConfiguration awsConf = new ExtraHadoopConfiguration();
            S3Connection.setS3Configuration(awsConf, properties.getDatasetProperties());
            Configuration hadoopConf = new Configuration();
            awsConf.addTo(hadoopConf);
            FileSystem fs = p.getFileSystem(hadoopConf);
            if (fs.exists(p)) {
                boolean deleted = fs.delete(p, true);
                if (!deleted)
                    throw SimpleFileIOErrorCode.createOutputNotAuthorized(null, null, p.toString());
            }
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw TalendRuntimeException.createUnexpectedException(e);
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) ExtraHadoopConfiguration(org.talend.components.simplefileio.runtime.ExtraHadoopConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) ExtraHadoopConfiguration(org.talend.components.simplefileio.runtime.ExtraHadoopConfiguration) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException)

Aggregations

Configuration (org.apache.hadoop.conf.Configuration)2 ExtraHadoopConfiguration (org.talend.components.simplefileio.runtime.ExtraHadoopConfiguration)2 S3AFileSystem (com.talend.shaded.org.apache.hadoop.fs.s3a.S3AFileSystem)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 TalendRuntimeException (org.talend.daikon.exception.TalendRuntimeException)1