Search in sources :

Example 1 with ApplicationException

use of nl.sidnlabs.entrada.exception.ApplicationException in project entrada by SIDN.

the class AmazonInitializer method initializeStorage.

@Override
public boolean initializeStorage() {
    log.info("Provision AWS storage");
    // create local storage locations
    super.initializeStorage();
    if (!fileManager.supported(output)) {
        throw new ApplicationException("Selected mode is AWS but the ENTRADA output location does not use S3, cannot continue");
    }
    // check if the s3 bucket and required directories exist and if not create these
    if (!BucketNameUtils.isValidV2BucketName(bucket)) {
        throw new ApplicationException("\"" + bucket + "\" is not a valid S3 bucket name, for bucket restrictions and limitations, see: " + bucketRules);
    }
    // only create bucket and lifecycle rules if we are managing the bucket
    if (!manageBucket) {
        return true;
    }
    if (!amazonS3.doesBucketExistV2(bucket)) {
        log.info("Create bucket: " + bucket);
        amazonS3.createBucket(bucket);
        // make sure to block all public access to the bucket
        amazonS3.setPublicAccessBlock(new SetPublicAccessBlockRequest().withBucketName(bucket).withPublicAccessBlockConfiguration(new PublicAccessBlockConfiguration().withBlockPublicAcls(Boolean.TRUE).withIgnorePublicAcls(Boolean.TRUE).withBlockPublicPolicy(Boolean.TRUE).withRestrictPublicBuckets(Boolean.TRUE)));
        enableEncryption();
    }
    // also make sure pcap files archived on S3 have a expiration lifecycle policy
    return amazonS3.doesBucketExistV2(bucket) && enableBucketLifecycle(athenaOutputLocation, "Delete Athena results", outputExpiration, false) && enableBucketLifecycle(archive, "Delete archived pcap-files", archiveExpiration, true);
}
Also used : PublicAccessBlockConfiguration(com.amazonaws.services.s3.model.PublicAccessBlockConfiguration) ApplicationException(nl.sidnlabs.entrada.exception.ApplicationException) SetPublicAccessBlockRequest(com.amazonaws.services.s3.model.SetPublicAccessBlockRequest)

Example 2 with ApplicationException

use of nl.sidnlabs.entrada.exception.ApplicationException in project entrada by SIDN.

the class HDFSFileManagerImpl method createSecureFS.

private FileSystem createSecureFS() {
    Configuration conf = conf();
    conf.set("hadoop.security.authentication", "kerberos");
    UserGroupInformation.setConfiguration(conf);
    try {
        if (StringUtils.isNotBlank(krbKeyTab)) {
            UserGroupInformation.loginUserFromKeytab(hdfsUsername, krbKeyTab);
        }
        // https://stackoverflow.com/questions/20057881/hadoop-filesystem-closed-exception-when-doing-bufferedreader-close/20061797#20061797
        return FileSystem.newInstance(new URI(hdfsNameservice), conf);
    } catch (Exception e) {
        throw new ApplicationException("Cannot create secure HDFS filesystem", e);
    }
}
Also used : ApplicationException(nl.sidnlabs.entrada.exception.ApplicationException) Configuration(org.apache.hadoop.conf.Configuration) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) ApplicationException(nl.sidnlabs.entrada.exception.ApplicationException) IOException(java.io.IOException)

Example 3 with ApplicationException

use of nl.sidnlabs.entrada.exception.ApplicationException in project entrada by SIDN.

the class HDFSFileManagerImpl method conf.

private Configuration conf() {
    Configuration conf = new Configuration();
    conf.set("fs.defaultFS", hdfsNameservice);
    String coreSiteXml = confDir + "/core-site.xml";
    if (!new File(coreSiteXml).exists()) {
        throw new ApplicationException("Missing core-site.xml, add this to the conf directory");
    }
    String hdfsSiteXml = confDir + "/hdfs-site.xml";
    if (!new File(hdfsSiteXml).exists()) {
        throw new ApplicationException("Missing hdfs-site.xml, add this to the conf directory");
    }
    conf.addResource(new Path("file://" + hdfsSiteXml));
    conf.addResource(new Path("file://" + coreSiteXml));
    return conf;
}
Also used : Path(org.apache.hadoop.fs.Path) ApplicationException(nl.sidnlabs.entrada.exception.ApplicationException) Configuration(org.apache.hadoop.conf.Configuration) File(java.io.File)

Example 4 with ApplicationException

use of nl.sidnlabs.entrada.exception.ApplicationException in project entrada by SIDN.

the class AbstractParquetRowWriter method schema.

public Schema schema(String schema) {
    if (avroSchema != null) {
        // use cached version of schema
        return avroSchema;
    }
    try {
        Parser parser = new Schema.Parser().setValidate(true);
        avroSchema = parser.parse(new ClassPathResource(schema, getClass()).getInputStream());
    } catch (IOException e) {
        throw new ApplicationException("Cannot load schema from file: " + schema, e);
    }
    return avroSchema;
}
Also used : ApplicationException(nl.sidnlabs.entrada.exception.ApplicationException) Schema(org.apache.avro.Schema) Parser(org.apache.avro.Schema.Parser) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) Parser(org.apache.avro.Schema.Parser)

Example 5 with ApplicationException

use of nl.sidnlabs.entrada.exception.ApplicationException in project entrada by SIDN.

the class HDFSFileManagerImpl method createNonSecureFS.

private FileSystem createNonSecureFS() {
    Configuration conf = conf();
    System.setProperty("HADOOP_USER_NAME", hdfsUsername);
    try {
        // https://stackoverflow.com/questions/20057881/hadoop-filesystem-closed-exception-when-doing-bufferedreader-close/20061797#20061797
        return FileSystem.newInstance(conf);
    } catch (IOException e) {
        throw new ApplicationException("Cannot create non-secure HDFS filesystem", e);
    }
}
Also used : ApplicationException(nl.sidnlabs.entrada.exception.ApplicationException) Configuration(org.apache.hadoop.conf.Configuration) IOException(java.io.IOException)

Aggregations

ApplicationException (nl.sidnlabs.entrada.exception.ApplicationException)7 IOException (java.io.IOException)4 Configuration (org.apache.hadoop.conf.Configuration)3 File (java.io.File)2 Schema (org.apache.avro.Schema)2 Parser (org.apache.avro.Schema.Parser)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 PublicAccessBlockConfiguration (com.amazonaws.services.s3.model.PublicAccessBlockConfiguration)1 SetPublicAccessBlockRequest (com.amazonaws.services.s3.model.SetPublicAccessBlockRequest)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Path (org.apache.hadoop.fs.Path)1