Search in sources :

Example 1 with S3Bucket

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

the class Jets3tNativeFileSystemStore method initialize.

@Override
public void initialize(URI uri, Configuration conf) throws IOException {
    S3Credentials s3Credentials = new S3Credentials();
    s3Credentials.initialize(uri, conf);
    try {
        AWSCredentials awsCredentials = new AWSCredentials(s3Credentials.getAccessKey(), s3Credentials.getSecretAccessKey());
        this.s3Service = new RestS3Service(awsCredentials);
    } catch (S3ServiceException e) {
        handleException(e);
    }
    multipartEnabled = conf.getBoolean("fs.s3n.multipart.uploads.enabled", false);
    multipartBlockSize = Math.min(conf.getLong("fs.s3n.multipart.uploads.block.size", 64 * 1024 * 1024), MAX_PART_SIZE);
    multipartCopyBlockSize = Math.min(conf.getLong("fs.s3n.multipart.copy.block.size", MAX_PART_SIZE), MAX_PART_SIZE);
    serverSideEncryptionAlgorithm = conf.get("fs.s3n.server-side-encryption-algorithm");
    bucket = new S3Bucket(uri.getHost());
}
Also used : S3Bucket(org.jets3t.service.model.S3Bucket) RestS3Service(org.jets3t.service.impl.rest.httpclient.RestS3Service) S3ServiceException(org.jets3t.service.S3ServiceException) AWSCredentials(org.jets3t.service.security.AWSCredentials)

Example 2 with S3Bucket

use of org.jets3t.service.model.S3Bucket in project pentaho-kettle by pentaho.

the class S3ObjectsProviderTest method getS3ServiceMock.

private S3Service getS3ServiceMock(AWSCredentials credentials) throws Exception {
    S3Service service = mock(S3Service.class);
    when(service.listAllBuckets()).thenReturn(generateTestBuckets(TEST_USER_BUCKETS_NAMES));
    // BUCKET2 - not empty bucket
    when(service.listObjects((S3Bucket) argThat(this.new S3BucketArgumentMatcher(BUCKET2)))).thenReturn(bucket2Objects);
    // BUCKET3 - empty bucket
    when(service.listObjects((S3Bucket) argThat(this.new S3BucketArgumentMatcher(BUCKET3)))).thenReturn(bucket3Objects);
    when(service.getObject(any(S3Bucket.class), any(String.class), any(), any(), any(), any(), any(), any())).thenReturn(testObject);
    when(service.getObjectDetails(any(S3Bucket.class), any(String.class), any(), any(), any(), any())).thenReturn(testObject);
    return service;
}
Also used : S3Bucket(org.jets3t.service.model.S3Bucket) S3Service(org.jets3t.service.S3Service)

Example 3 with S3Bucket

use of org.jets3t.service.model.S3Bucket in project tutorials by eugenp.

the class JetS3tLiveTest method whenFileMoved_NewInstanceIsSame.

@Test
public void whenFileMoved_NewInstanceIsSame() throws Exception {
    // get a bucket
    S3Bucket bucket = createBucket();
    assertNotNull(bucket);
    // create another bucket
    S3Bucket tgtBucket = s3Service.createBucket(TgtBucket);
    // Put a binary file
    S3Object fileObject = new S3Object(new File("src/test/resources/test.jpg"));
    s3Service.putObject(BucketName, fileObject);
    // Copy it
    s3Service.moveObject(BucketName, "test.jpg", TgtBucket, new S3Object("spidey.jpg"), false);
    // Download
    S3Object newFileObject = s3Service.getObject(TgtBucket, "spidey.jpg");
    // Save to a different name
    File newFile = new File("src/test/resources/spidey.jpg");
    Files.copy(newFileObject.getDataInputStream(), newFile.toPath(), REPLACE_EXISTING);
    // Get hashes and compare
    String origMD5 = getFileMD5("src/test/resources/test.jpg");
    String newMD5 = getFileMD5("src/test/resources/spidey.jpg");
    assertTrue(origMD5.equals(newMD5));
    // Clean up
    deleteBucket();
    s3Service.deleteObject(TgtBucket, "spidey.jpg");
    s3Service.deleteBucket(TgtBucket);
}
Also used : S3Bucket(org.jets3t.service.model.S3Bucket) S3Object(org.jets3t.service.model.S3Object) Test(org.junit.Test)

Example 4 with S3Bucket

use of org.jets3t.service.model.S3Bucket in project tutorials by eugenp.

the class JetS3tLiveTest method whenFileRenamed_NewNameIsSame.

@Test
public void whenFileRenamed_NewNameIsSame() throws Exception {
    // get a bucket
    S3Bucket bucket = createBucket();
    assertNotNull(bucket);
    // Put a binary file
    S3Object fileObject = new S3Object(new File("src/test/resources/test.jpg"));
    s3Service.putObject(BucketName, fileObject);
    // Copy it
    s3Service.renameObject(BucketName, "test.jpg", new S3Object("spidey.jpg"));
    // Download
    S3Object newFileObject = s3Service.getObject(BucketName, "spidey.jpg");
    // Save to a different name
    File newFile = new File("src/test/resources/spidey.jpg");
    Files.copy(newFileObject.getDataInputStream(), newFile.toPath(), REPLACE_EXISTING);
    // Get hashes and compare
    String origMD5 = getFileMD5("src/test/resources/test.jpg");
    String newMD5 = getFileMD5("src/test/resources/spidey.jpg");
    assertTrue(origMD5.equals(newMD5));
    // Clean up
    deleteObject("test.jpg");
    deleteObject("spidey.jpg");
    deleteBucket();
}
Also used : S3Bucket(org.jets3t.service.model.S3Bucket) S3Object(org.jets3t.service.model.S3Object) Test(org.junit.Test)

Example 5 with S3Bucket

use of org.jets3t.service.model.S3Bucket in project tutorials by eugenp.

the class JetS3tLiveTest method whenFileCopied_CopyIsSame.

@Test
public void whenFileCopied_CopyIsSame() throws Exception {
    // get a bucket
    S3Bucket bucket = createBucket();
    assertNotNull(bucket);
    // Put a binary file
    S3Object fileObject = new S3Object(new File("src/test/resources/test.jpg"));
    s3Service.putObject(BucketName, fileObject);
    // Copy it
    S3Object targetObject = new S3Object("testcopy.jpg");
    s3Service.copyObject(BucketName, "test.jpg", BucketName, targetObject, false);
    // Download
    S3Object newFileObject = s3Service.getObject(BucketName, "testcopy.jpg");
    // Save to a different name
    File newFile = new File("src/test/resources/testcopy.jpg");
    Files.copy(newFileObject.getDataInputStream(), newFile.toPath(), REPLACE_EXISTING);
    // Get hashes and compare
    String origMD5 = getFileMD5("src/test/resources/test.jpg");
    String newMD5 = getFileMD5("src/test/resources/testcopy.jpg");
    assertTrue(origMD5.equals(newMD5));
    // Clean up
    deleteObject("test.jpg");
    deleteObject("testcopy.jpg");
    deleteBucket();
}
Also used : S3Bucket(org.jets3t.service.model.S3Bucket) S3Object(org.jets3t.service.model.S3Object) Test(org.junit.Test)

Aggregations

S3Bucket (org.jets3t.service.model.S3Bucket)14 S3Object (org.jets3t.service.model.S3Object)9 Test (org.junit.Test)8 S3Service (org.jets3t.service.S3Service)2 S3ServiceException (org.jets3t.service.S3ServiceException)2 RestS3Service (org.jets3t.service.impl.rest.httpclient.RestS3Service)2 AWSCredentials (org.jets3t.service.security.AWSCredentials)2 FileIteratingFirehose (io.druid.data.input.impl.FileIteratingFirehose)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 URI (java.net.URI)1 Date (java.util.Date)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 LineIterator (org.apache.commons.io.LineIterator)1 StorageObject (org.jets3t.service.model.StorageObject)1