Search in sources :

Example 6 with S3DatasetProperties

use of org.talend.components.simplefileio.s3.S3DatasetProperties in project components by Talend.

the class S3RoundTripRuntimeTestIT method testAvro_noEncryption.

/**
 * Basic Avro test.
 */
@Test
public void testAvro_noEncryption() throws IOException {
    S3DatasetProperties datasetProps = s3.createS3DatasetProperties();
    datasetProps.format.setValue(SimpleFileIOFormat.AVRO);
    test_noEncryption(datasetProps);
    // Get some object metadata from the results.
    ObjectMetadata md = s3.getObjectMetadata(datasetProps);
    assertThat(md.getSSEAlgorithm(), nullValue());
    assertThat(md.getSSEAwsKmsKeyId(), nullValue());
}
Also used : S3DatasetProperties(org.talend.components.simplefileio.s3.S3DatasetProperties) ObjectMetadata(com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata) Test(org.junit.Test)

Example 7 with S3DatasetProperties

use of org.talend.components.simplefileio.s3.S3DatasetProperties in project components by Talend.

the class S3RoundTripRuntimeTestIT method testAvro_sseKmsEncryption.

/**
 * Basic Avro test with sseKmsEncryption.
 */
@Test
public void testAvro_sseKmsEncryption() throws IOException {
    S3DatasetProperties datasetProps = s3.createS3DatasetProperties(true, false);
    datasetProps.format.setValue(SimpleFileIOFormat.AVRO);
    test_noEncryption(datasetProps);
    // Get some object metadata from the results.
    ObjectMetadata md = s3.getObjectMetadata(datasetProps);
    assertThat(md.getSSEAlgorithm(), is("aws:kms"));
    assertThat(md.getSSEAwsKmsKeyId(), is(datasetProps.kmsForDataAtRest.getValue()));
}
Also used : S3DatasetProperties(org.talend.components.simplefileio.s3.S3DatasetProperties) ObjectMetadata(com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata) Test(org.junit.Test)

Example 8 with S3DatasetProperties

use of org.talend.components.simplefileio.s3.S3DatasetProperties in project components by Talend.

the class S3Connection method createClient.

public static AmazonS3 createClient(S3OutputProperties properties) {
    S3DatasetProperties data_set = properties.getDatasetProperties();
    S3DatastoreProperties data_store = properties.getDatasetProperties().getDatastoreProperties();
    com.amazonaws.auth.AWSCredentials credentials = new com.amazonaws.auth.BasicAWSCredentials(data_store.accessKey.getValue(), data_store.secretKey.getValue());
    Region region = RegionUtils.getRegion(data_set.region.getValue().getValue());
    Boolean clientSideEnc = data_set.encryptDataInMotion.getValue();
    AmazonS3 conn = null;
    if (clientSideEnc != null && clientSideEnc) {
        String kms_cmk = data_set.kmsForDataInMotion.getValue();
        KMSEncryptionMaterialsProvider encryptionMaterialsProvider = new KMSEncryptionMaterialsProvider(kms_cmk);
        conn = new AmazonS3EncryptionClient(credentials, encryptionMaterialsProvider, new CryptoConfiguration().withAwsKmsRegion(region));
    } else {
        AWSCredentialsProvider basicCredentialsProvider = new StaticCredentialsProvider(credentials);
        conn = new AmazonS3Client(basicCredentialsProvider);
    }
    conn.setRegion(region);
    return conn;
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) AmazonS3EncryptionClient(com.amazonaws.services.s3.AmazonS3EncryptionClient) StaticCredentialsProvider(com.amazonaws.internal.StaticCredentialsProvider) KMSEncryptionMaterialsProvider(com.amazonaws.services.s3.model.KMSEncryptionMaterialsProvider) CryptoConfiguration(com.amazonaws.services.s3.model.CryptoConfiguration) S3DatasetProperties(org.talend.components.simplefileio.s3.S3DatasetProperties) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) Region(com.amazonaws.regions.Region) S3DatastoreProperties(org.talend.components.simplefileio.s3.S3DatastoreProperties) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 9 with S3DatasetProperties

use of org.talend.components.simplefileio.s3.S3DatasetProperties in project components by Talend.

the class PropertiesPreparer method createS3OtuputProperties.

public static S3OutputProperties createS3OtuputProperties() {
    S3OutputProperties properties = new S3OutputProperties("s3output");
    S3DatasetProperties dataset = new S3DatasetProperties("dataset");
    S3DatastoreProperties datastore = new S3DatastoreProperties("datastore");
    properties.setDatasetProperties(dataset);
    dataset.setDatastoreProperties(datastore);
    datastore.accessKey.setValue(accessKey);
    datastore.secretKey.setValue(secretkey);
    dataset.region.setValue(S3Region.valueOf(region));
    dataset.bucket.setValue(bucket);
    dataset.kmsForDataInMotion.setValue(ssekmskey);
    dataset.kmsForDataAtRest.setValue(csekmskey);
    dataset.object.setValue(objectkey);
    return properties;
}
Also used : S3DatasetProperties(org.talend.components.simplefileio.s3.S3DatasetProperties) S3OutputProperties(org.talend.components.simplefileio.s3.output.S3OutputProperties) S3DatastoreProperties(org.talend.components.simplefileio.s3.S3DatastoreProperties)

Example 10 with S3DatasetProperties

use of org.talend.components.simplefileio.s3.S3DatasetProperties in project components by Talend.

the class S3OutputWriter method close.

/**
 * not sure the method is called one or two times, it depend on the platform
 */
@Override
public Result close() throws IOException {
    if (closed) {
        return result;
    }
    closed = true;
    try {
        if (writer != null) {
            writer.flush();
            writer.close();
        }
        S3DatasetProperties data_set = properties.getDatasetProperties();
        PutObjectRequest request = new PutObjectRequest(data_set.bucket.getValue(), data_set.object.getValue(), data_file);
        Boolean serverSideEnc = data_set.encryptDataAtRest.getValue();
        if (serverSideEnc != null && serverSideEnc) {
            request.withSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(data_set.kmsForDataAtRest.getValue()));
        }
        s3_client.putObject(request);
    } finally {
        writer = null;
        data_file.delete();
        if (s3_client != null) {
            s3_client.shutdown();
            s3_client = null;
        }
    }
    result.successCount = result.totalCount;
    return result;
}
Also used : S3DatasetProperties(org.talend.components.simplefileio.s3.S3DatasetProperties) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) SSEAwsKeyManagementParams(com.amazonaws.services.s3.model.SSEAwsKeyManagementParams)

Aggregations

S3DatasetProperties (org.talend.components.simplefileio.s3.S3DatasetProperties)22 Test (org.junit.Test)16 Ignore (org.junit.Ignore)7 S3OutputProperties (org.talend.components.simplefileio.s3.output.S3OutputProperties)6 IndexedRecord (org.apache.avro.generic.IndexedRecord)5 ObjectMetadata (com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata)4 Pipeline (org.apache.beam.sdk.Pipeline)3 FileSystem (org.apache.hadoop.fs.FileSystem)3 ConvertToIndexedRecord (org.talend.components.adapter.beam.transform.ConvertToIndexedRecord)3 S3DatastoreProperties (org.talend.components.simplefileio.s3.S3DatastoreProperties)3 Schema (org.apache.avro.Schema)2 S3InputProperties (org.talend.components.simplefileio.s3.input.S3InputProperties)2 RecordSet (org.talend.components.test.RecordSet)2 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 StaticCredentialsProvider (com.amazonaws.internal.StaticCredentialsProvider)1 Region (com.amazonaws.regions.Region)1 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)1 AmazonS3EncryptionClient (com.amazonaws.services.s3.AmazonS3EncryptionClient)1 CryptoConfiguration (com.amazonaws.services.s3.model.CryptoConfiguration)1