Search in sources :

Example 6 with S3Object

use of org.jets3t.service.model.S3Object in project druid by druid-io.

the class S3TimestampVersionedDataFinderTest method testMissing.

@Test
public void testMissing() throws S3ServiceException {
    String bucket = "bucket";
    String keyPrefix = "prefix/dir/0";
    RestS3Service s3Client = EasyMock.createStrictMock(RestS3Service.class);
    S3Object object0 = new S3Object(), object1 = new S3Object();
    object0.setBucketName(bucket);
    object0.setKey(keyPrefix + "/renames-0.gz");
    object0.setLastModifiedDate(new Date(0));
    object1.setBucketName(bucket);
    object1.setKey(keyPrefix + "/renames-1.gz");
    object1.setLastModifiedDate(new Date(1));
    EasyMock.expect(s3Client.listObjects(EasyMock.eq(bucket), EasyMock.anyString(), EasyMock.<String>isNull())).andReturn(null).once();
    S3TimestampVersionedDataFinder finder = new S3TimestampVersionedDataFinder(s3Client);
    Pattern pattern = Pattern.compile("renames-[0-9]*\\.gz");
    EasyMock.replay(s3Client);
    URI latest = finder.getLatestVersion(URI.create(String.format("s3://%s/%s", bucket, keyPrefix)), pattern);
    EasyMock.verify(s3Client);
    Assert.assertEquals(null, latest);
}
Also used : Pattern(java.util.regex.Pattern) RestS3Service(org.jets3t.service.impl.rest.httpclient.RestS3Service) S3Object(org.jets3t.service.model.S3Object) URI(java.net.URI) Date(java.util.Date) Test(org.junit.Test)

Example 7 with S3Object

use of org.jets3t.service.model.S3Object in project druid by druid-io.

the class S3TimestampVersionedDataFinderTest method testFindSelf.

@Test
public void testFindSelf() throws S3ServiceException {
    String bucket = "bucket";
    String keyPrefix = "prefix/dir/0";
    RestS3Service s3Client = EasyMock.createStrictMock(RestS3Service.class);
    S3Object object0 = new S3Object();
    object0.setBucketName(bucket);
    object0.setKey(keyPrefix + "/renames-0.gz");
    object0.setLastModifiedDate(new Date(0));
    EasyMock.expect(s3Client.listObjects(EasyMock.eq(bucket), EasyMock.anyString(), EasyMock.<String>isNull())).andReturn(new S3Object[] { object0 }).once();
    S3TimestampVersionedDataFinder finder = new S3TimestampVersionedDataFinder(s3Client);
    Pattern pattern = Pattern.compile("renames-[0-9]*\\.gz");
    EasyMock.replay(s3Client);
    URI latest = finder.getLatestVersion(URI.create(String.format("s3://%s/%s", bucket, keyPrefix)), pattern);
    EasyMock.verify(s3Client);
    URI expected = URI.create(String.format("s3://%s/%s", bucket, object0.getKey()));
    Assert.assertEquals(expected, latest);
}
Also used : Pattern(java.util.regex.Pattern) RestS3Service(org.jets3t.service.impl.rest.httpclient.RestS3Service) S3Object(org.jets3t.service.model.S3Object) URI(java.net.URI) Date(java.util.Date) Test(org.junit.Test)

Example 8 with S3Object

use of org.jets3t.service.model.S3Object in project hadoop by apache.

the class Jets3tNativeFileSystemStore method copy.

@Override
public void copy(String srcKey, String dstKey) throws IOException {
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Copying srcKey: " + srcKey + "to dstKey: " + dstKey + "in bucket: " + bucket.getName());
        }
        if (multipartEnabled) {
            S3Object object = s3Service.getObjectDetails(bucket, srcKey, null, null, null, null);
            if (multipartCopyBlockSize > 0 && object.getContentLength() > multipartCopyBlockSize) {
                copyLargeFile(object, dstKey);
                return;
            }
        }
        S3Object dstObject = new S3Object(dstKey);
        dstObject.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
        s3Service.copyObject(bucket.getName(), srcKey, bucket.getName(), dstObject, false);
    } catch (ServiceException e) {
        handleException(e, srcKey);
    }
}
Also used : ServiceException(org.jets3t.service.ServiceException) S3ServiceException(org.jets3t.service.S3ServiceException) S3Object(org.jets3t.service.model.S3Object)

Example 9 with S3Object

use of org.jets3t.service.model.S3Object in project hadoop by apache.

the class Jets3tNativeFileSystemStore method storeLargeFile.

public void storeLargeFile(String key, File file, byte[] md5Hash) throws IOException {
    S3Object object = new S3Object(key);
    object.setDataInputFile(file);
    object.setContentType("binary/octet-stream");
    object.setContentLength(file.length());
    object.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
    if (md5Hash != null) {
        object.setMd5Hash(md5Hash);
    }
    List<StorageObject> objectsToUploadAsMultipart = new ArrayList<StorageObject>();
    objectsToUploadAsMultipart.add(object);
    MultipartUtils mpUtils = new MultipartUtils(multipartBlockSize);
    try {
        mpUtils.uploadObjects(bucket.getName(), s3Service, objectsToUploadAsMultipart, null);
    } catch (Exception e) {
        handleException(e, key);
    }
}
Also used : StorageObject(org.jets3t.service.model.StorageObject) ArrayList(java.util.ArrayList) S3Object(org.jets3t.service.model.S3Object) MultipartUtils(org.jets3t.service.utils.MultipartUtils) ServiceException(org.jets3t.service.ServiceException) HttpException(org.jets3t.service.impl.rest.HttpException) S3ServiceException(org.jets3t.service.S3ServiceException) IOException(java.io.IOException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) AccessControlException(org.apache.hadoop.security.AccessControlException)

Example 10 with S3Object

use of org.jets3t.service.model.S3Object in project hadoop by apache.

the class Jets3tNativeFileSystemStore method retrieve.

/**
   * @param key
   * The key is the object name that is being retrieved from the S3 bucket
   * @return
   * This method returns null if the key is not found
   * @throws IOException
   */
@Override
public InputStream retrieve(String key) throws IOException {
    try {
        LOG.debug("Getting key: {} from bucket: {}", key, bucket.getName());
        S3Object object = s3Service.getObject(bucket.getName(), key);
        return object.getDataInputStream();
    } catch (ServiceException e) {
        handleException(e, key);
        //return null if key not found
        return null;
    }
}
Also used : ServiceException(org.jets3t.service.ServiceException) S3ServiceException(org.jets3t.service.S3ServiceException) S3Object(org.jets3t.service.model.S3Object)

Aggregations

S3Object (org.jets3t.service.model.S3Object)39 Test (org.junit.Test)16 S3ServiceException (org.jets3t.service.S3ServiceException)11 ServiceException (org.jets3t.service.ServiceException)11 RestS3Service (org.jets3t.service.impl.rest.httpclient.RestS3Service)11 S3Bucket (org.jets3t.service.model.S3Bucket)9 Date (java.util.Date)8 File (java.io.File)6 IOException (java.io.IOException)6 DataSegment (io.druid.timeline.DataSegment)5 URI (java.net.URI)5 StorageObject (org.jets3t.service.model.StorageObject)5 InputStream (java.io.InputStream)4 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)3 Pattern (java.util.regex.Pattern)3 S3Service (org.jets3t.service.S3Service)3 AWSCredentials (org.jets3t.service.security.AWSCredentials)3 FileUtils (io.druid.java.util.common.FileUtils)2 BufferedReader (java.io.BufferedReader)2