Search in sources :

Example 81 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project beam by apache.

the class S3FileSystemTest method matchNonGlobWithS3Options.

@Test
public void matchNonGlobWithS3Options() {
    S3FileSystem s3FileSystem = buildMockedS3FileSystem(s3Options());
    S3ResourceId path = S3ResourceId.fromUri("s3://testbucket/testdirectory/filethatexists");
    long lastModifiedMillis = 1540000000000L;
    ObjectMetadata s3ObjectMetadata = new ObjectMetadata();
    s3ObjectMetadata.setContentLength(100);
    s3ObjectMetadata.setContentEncoding("read-seek-efficient");
    s3ObjectMetadata.setLastModified(new Date(lastModifiedMillis));
    when(s3FileSystem.getAmazonS3Client().getObjectMetadata(argThat(new GetObjectMetadataRequestMatcher(new GetObjectMetadataRequest(path.getBucket(), path.getKey()))))).thenReturn(s3ObjectMetadata);
    MatchResult result = s3FileSystem.matchNonGlobPath(path);
    assertThat(result, MatchResultMatcher.create(ImmutableList.of(MatchResult.Metadata.builder().setSizeBytes(100).setLastModifiedMillis(lastModifiedMillis).setResourceId(path).setIsReadSeekEfficient(true).build())));
}
Also used : GetObjectMetadataRequest(com.amazonaws.services.s3.model.GetObjectMetadataRequest) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) MatchResult(org.apache.beam.sdk.io.fs.MatchResult) Date(java.util.Date) S3TestUtils.buildMockedS3FileSystem(org.apache.beam.sdk.io.aws.s3.S3TestUtils.buildMockedS3FileSystem) Test(org.junit.Test)

Example 82 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project beam by apache.

the class S3FileSystemTest method matchNonGlobNotReadSeekEfficientWithS3Options.

@Test
public void matchNonGlobNotReadSeekEfficientWithS3Options() {
    S3FileSystem s3FileSystem = buildMockedS3FileSystem(s3Options());
    S3ResourceId path = S3ResourceId.fromUri("s3://testbucket/testdirectory/filethatexists");
    long lastModifiedMillis = 1540000000000L;
    ObjectMetadata s3ObjectMetadata = new ObjectMetadata();
    s3ObjectMetadata.setContentLength(100);
    s3ObjectMetadata.setLastModified(new Date(lastModifiedMillis));
    s3ObjectMetadata.setContentEncoding("gzip");
    when(s3FileSystem.getAmazonS3Client().getObjectMetadata(argThat(new GetObjectMetadataRequestMatcher(new GetObjectMetadataRequest(path.getBucket(), path.getKey()))))).thenReturn(s3ObjectMetadata);
    MatchResult result = s3FileSystem.matchNonGlobPath(path);
    assertThat(result, MatchResultMatcher.create(ImmutableList.of(MatchResult.Metadata.builder().setSizeBytes(100).setLastModifiedMillis(lastModifiedMillis).setResourceId(path).setIsReadSeekEfficient(false).build())));
}
Also used : GetObjectMetadataRequest(com.amazonaws.services.s3.model.GetObjectMetadataRequest) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) MatchResult(org.apache.beam.sdk.io.fs.MatchResult) Date(java.util.Date) S3TestUtils.buildMockedS3FileSystem(org.apache.beam.sdk.io.aws.s3.S3TestUtils.buildMockedS3FileSystem) Test(org.junit.Test)

Example 83 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project beam by apache.

the class S3FileSystemTest method testMultipartCopy.

private void testMultipartCopy(S3FileSystem s3FileSystem, SSECustomerKey sseCustomerKey, long s3UploadBufferSizeBytes) {
    S3ResourceId sourcePath = S3ResourceId.fromUri(s3FileSystem.getScheme() + "://bucket/from");
    S3ResourceId destinationPath = S3ResourceId.fromUri(s3FileSystem.getScheme() + "://bucket/to");
    InitiateMultipartUploadResult initiateMultipartUploadResult = new InitiateMultipartUploadResult();
    initiateMultipartUploadResult.setUploadId("upload-id");
    String sseCustomerKeyMd5 = toMd5(sseCustomerKey);
    if (sseCustomerKeyMd5 != null) {
        initiateMultipartUploadResult.setSSECustomerKeyMd5(sseCustomerKeyMd5);
    }
    when(s3FileSystem.getAmazonS3Client().initiateMultipartUpload(any(InitiateMultipartUploadRequest.class))).thenReturn(initiateMultipartUploadResult);
    assertEquals(sseCustomerKeyMd5, s3FileSystem.getAmazonS3Client().initiateMultipartUpload(new InitiateMultipartUploadRequest(destinationPath.getBucket(), destinationPath.getKey())).getSSECustomerKeyMd5());
    ObjectMetadata sourceObjectMetadata = new ObjectMetadata();
    sourceObjectMetadata.setContentLength((long) (s3UploadBufferSizeBytes * 1.5));
    sourceObjectMetadata.setContentEncoding("read-seek-efficient");
    if (sseCustomerKeyMd5 != null) {
        sourceObjectMetadata.setSSECustomerKeyMd5(sseCustomerKeyMd5);
    }
    assertGetObjectMetadata(s3FileSystem, createObjectMetadataRequest(sourcePath, sseCustomerKey), sseCustomerKeyMd5, sourceObjectMetadata);
    CopyPartResult copyPartResult1 = new CopyPartResult();
    copyPartResult1.setETag("etag-1");
    CopyPartResult copyPartResult2 = new CopyPartResult();
    copyPartResult1.setETag("etag-2");
    if (sseCustomerKeyMd5 != null) {
        copyPartResult1.setSSECustomerKeyMd5(sseCustomerKeyMd5);
        copyPartResult2.setSSECustomerKeyMd5(sseCustomerKeyMd5);
    }
    CopyPartRequest copyPartRequest = new CopyPartRequest();
    copyPartRequest.setSourceSSECustomerKey(sseCustomerKey);
    when(s3FileSystem.getAmazonS3Client().copyPart(any(CopyPartRequest.class))).thenReturn(copyPartResult1).thenReturn(copyPartResult2);
    assertEquals(sseCustomerKeyMd5, s3FileSystem.getAmazonS3Client().copyPart(copyPartRequest).getSSECustomerKeyMd5());
    s3FileSystem.multipartCopy(sourcePath, destinationPath, sourceObjectMetadata);
    verify(s3FileSystem.getAmazonS3Client(), times(1)).completeMultipartUpload(any(CompleteMultipartUploadRequest.class));
}
Also used : CopyPartRequest(com.amazonaws.services.s3.model.CopyPartRequest) InitiateMultipartUploadResult(com.amazonaws.services.s3.model.InitiateMultipartUploadResult) InitiateMultipartUploadRequest(com.amazonaws.services.s3.model.InitiateMultipartUploadRequest) CopyPartResult(com.amazonaws.services.s3.model.CopyPartResult) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) CompleteMultipartUploadRequest(com.amazonaws.services.s3.model.CompleteMultipartUploadRequest)

Example 84 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project beam by apache.

the class S3FileSystemTest method matchGlobWithSlashesWithS3Options.

@Test
public void matchGlobWithSlashesWithS3Options() throws IOException {
    S3FileSystem s3FileSystem = buildMockedS3FileSystem(s3Options());
    S3ResourceId path = S3ResourceId.fromUri("s3://testbucket/foo/bar\\baz*");
    ListObjectsV2Request request = new ListObjectsV2Request().withBucketName(path.getBucket()).withPrefix(path.getKeyNonWildcardPrefix()).withContinuationToken(null);
    // Expected to be returned; prefix and wildcard/regex match
    S3ObjectSummary firstMatch = new S3ObjectSummary();
    firstMatch.setBucketName(path.getBucket());
    firstMatch.setKey("foo/bar\\baz0");
    firstMatch.setSize(100);
    firstMatch.setLastModified(new Date(1540000000001L));
    // Expected to not be returned; prefix matches, but substring after wildcard does not
    S3ObjectSummary secondMatch = new S3ObjectSummary();
    secondMatch.setBucketName(path.getBucket());
    secondMatch.setKey("foo/bar/baz1");
    secondMatch.setSize(200);
    secondMatch.setLastModified(new Date(1540000000002L));
    // Expected first request returns continuation token
    ListObjectsV2Result result = new ListObjectsV2Result();
    result.getObjectSummaries().add(firstMatch);
    result.getObjectSummaries().add(secondMatch);
    when(s3FileSystem.getAmazonS3Client().listObjectsV2(argThat(new ListObjectsV2RequestArgumentMatches(request)))).thenReturn(result);
    // Expect object metadata queries for content encoding
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentEncoding("");
    when(s3FileSystem.getAmazonS3Client().getObjectMetadata(anyObject())).thenReturn(metadata);
    assertThat(s3FileSystem.matchGlobPaths(ImmutableList.of(path)).get(0), MatchResultMatcher.create(ImmutableList.of(MatchResult.Metadata.builder().setIsReadSeekEfficient(true).setResourceId(S3ResourceId.fromComponents("s3", firstMatch.getBucketName(), firstMatch.getKey())).setSizeBytes(firstMatch.getSize()).setLastModifiedMillis(firstMatch.getLastModified().getTime()).build())));
}
Also used : ListObjectsV2Request(com.amazonaws.services.s3.model.ListObjectsV2Request) ListObjectsV2Result(com.amazonaws.services.s3.model.ListObjectsV2Result) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Date(java.util.Date) S3TestUtils.buildMockedS3FileSystem(org.apache.beam.sdk.io.aws.s3.S3TestUtils.buildMockedS3FileSystem) Test(org.junit.Test)

Example 85 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project jackrabbit by apache.

the class S3RequestDecorator method decorate.

/**
 * Set encryption in {@link PutObjectRequest}
 */
public PutObjectRequest decorate(PutObjectRequest request) {
    switch(getDataEncryption()) {
        case SSE_S3:
            ObjectMetadata metadata = request.getMetadata() == null ? new ObjectMetadata() : request.getMetadata();
            metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
            request.setMetadata(metadata);
            break;
        case NONE:
            break;
    }
    return request;
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Aggregations

ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)566 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)191 ByteArrayInputStream (java.io.ByteArrayInputStream)157 Test (org.junit.Test)143 IOException (java.io.IOException)101 InputStream (java.io.InputStream)80 File (java.io.File)62 AmazonClientException (com.amazonaws.AmazonClientException)61 AmazonServiceException (com.amazonaws.AmazonServiceException)61 S3Object (com.amazonaws.services.s3.model.S3Object)59 AmazonS3 (com.amazonaws.services.s3.AmazonS3)54 Date (java.util.Date)46 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)34 GetObjectMetadataRequest (com.amazonaws.services.s3.model.GetObjectMetadataRequest)33 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)32 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)30 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)29 Upload (com.amazonaws.services.s3.transfer.Upload)26 SdkClientException (com.amazonaws.SdkClientException)24 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)24