Search in sources :

Example 76 with ObjectMetadata

use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project adeptj-modules by AdeptJ.

the class AwsS3Service method createFolder.

/**
 * {@inheritDoc}
 */
@Override
public S3Response createFolder(String bucketName, String folderName) {
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setContentLength(0);
    try {
        return new S3Response().withPutObjectResult(this.s3Client.putObject(new PutObjectRequest(bucketName, folderName + PATH_SEPARATOR, new ByteArrayInputStream(new byte[0]), objectMetadata)));
    } catch (RuntimeException ex) {
        LOGGER.error("Exception while creating folder!!", ex);
        throw new AwsException(ex.getMessage(), ex);
    }
}
Also used : S3Response(com.adeptj.modules.aws.s3.S3Response) ByteArrayInputStream(java.io.ByteArrayInputStream) AwsException(com.adeptj.modules.aws.core.AwsException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 77 with ObjectMetadata

use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project sandbox by irof.

the class S3MultipartUploadTest method 比較用の通常のputObject.

@Ignore
@Test
public void 比較用の通常のputObject() throws Exception {
    byte[] bytes = new byte[5 * Constants.MB + 1];
    ObjectMetadata meta = new ObjectMetadata();
    meta.setContentLength(bytes.length);
    PutObjectRequest putObjectRequest = new PutObjectRequest("irof-sandbox", "S3MultipartUpload/basic-5MB.dat", new ByteArrayInputStream(bytes), meta);
    PutObjectResult result = new AmazonS3Client().putObject(putObjectRequest);
    logger.info(result.getETag());
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) ByteArrayInputStream(java.io.ByteArrayInputStream) PutObjectResult(com.amazonaws.services.s3.model.PutObjectResult) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 78 with ObjectMetadata

use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project sandbox by irof.

the class S3Test method putWithInputStream.

@Test
public void putWithInputStream() throws Exception {
    try (InputStream input = new ByteArrayInputStream("test".getBytes(StandardCharsets.UTF_8))) {
        ObjectMetadata metaData = new ObjectMetadata();
        // 可能なら設定する。設定しなかったらデフォルト値が使われる。
        metaData.setContentType("text/plain");
        // 設定しなくても計算されるぽいのでスルーでよさげ
        // metaData.setContentMD5("CY9rzUYh03PK3k6DJie09g==");
        // オプションだけど、できるかぎり設定する。
        // 設定しないとWARNログ出ちゃうし、違う値を設定すると例外出る。
        // metaData.setContentLength(3);
        PutObjectRequest request = new PutObjectRequest("irof-sandbox", "byteFile.txt", input, metaData);
        PutObjectResult result = s3.putObject(request);
        assertThat(result.getETag(), is("098f6bcd4621d373cade4e832627b4f6"));
    }
}
Also used : PutObjectResult(com.amazonaws.services.s3.model.PutObjectResult) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Test(org.junit.Test)

Example 79 with ObjectMetadata

use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project stocator by CODAIT.

the class COSAPIClient method isSparkOrigin.

/**
 * Checks if container/object exists and verifies that it contains
 * Data-Origin=stocator metadata If so, object was created by Spark.
 *
 * @param objectKey the key of the object
 * @param path the object path
 * @return boolean if object was created by Spark
 */
private boolean isSparkOrigin(String objectKey, String path) {
    LOG.debug("check spark origin for {}", objectKey);
    if (!objectKey.endsWith("/")) {
        LOG.debug("Key {} has no slash. Return false", objectKey);
        return false;
    } else {
        objectKey = objectKey.substring(0, objectKey.length() - 1);
    }
    if (mCachedSparkOriginated.containsKey(objectKey)) {
        boolean res = mCachedSparkOriginated.get(objectKey).booleanValue();
        LOG.debug("found cached for spark origin for {}. Status {}", objectKey, res);
        return res;
    }
    String key = getRealKey(objectKey);
    Boolean sparkOriginated = Boolean.FALSE;
    ObjectMetadata objMetadata = getObjectMetadata(key);
    if (objMetadata != null) {
        Object sparkOrigin = objMetadata.getUserMetaDataOf("data-origin");
        if (sparkOrigin != null) {
            String tmp = (String) sparkOrigin;
            if (tmp.equals("stocator")) {
                sparkOriginated = Boolean.TRUE;
            }
        }
    }
    mCachedSparkOriginated.put(key, sparkOriginated);
    LOG.debug("spark origin for {} is {} non cached", objectKey, sparkOriginated.booleanValue());
    return sparkOriginated.booleanValue();
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 80 with ObjectMetadata

use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project stocator by CODAIT.

the class COSAPIClient method createObject.

@Override
public FSDataOutputStream createObject(String objName, String contentType, Map<String, String> metadata, Statistics statistics) throws IOException {
    LOG.debug("Create object {}", objName);
    try {
        String objNameWithoutBuket = objName;
        if (objName.startsWith(mBucket + "/")) {
            objNameWithoutBuket = objName.substring(mBucket.length() + 1);
        }
        if (blockUploadEnabled) {
            return new FSDataOutputStream(new COSBlockOutputStream(this, objNameWithoutBuket, new SemaphoredDelegatingExecutor(threadPoolExecutor, blockOutputActiveBlocks, true), partSize, blockFactory, contentType, new WriteOperationHelper(objNameWithoutBuket), metadata), null);
        }
        if (!contentType.equals(Constants.APPLICATION_DIRECTORY)) {
            return new FSDataOutputStream(new COSOutputStream(mBucket, objName, mClient, contentType, metadata, transfers, this), statistics);
        } else {
            final InputStream im = new InputStream() {

                @Override
                public int read() throws IOException {
                    return -1;
                }
            };
            final ObjectMetadata om = new ObjectMetadata();
            om.setContentLength(0L);
            om.setContentType(contentType);
            om.setUserMetadata(metadata);
            // Remove the bucket name prefix from key path
            if (objName.startsWith(mBucket + "/")) {
                objName = objName.substring(mBucket.length() + 1);
            }
            /*
        if (!objName.endsWith("/")) {
          objName = objName + "/";
        }*/
            LOG.debug("bucket: {}, key {}", mBucket, objName);
            PutObjectRequest putObjectRequest = new PutObjectRequest(mBucket, objName, im, om);
            Upload upload = transfers.upload(putObjectRequest);
            upload.waitForUploadResult();
            OutputStream fakeStream = new OutputStream() {

                @Override
                public void write(int b) throws IOException {
                }

                @Override
                public void close() throws IOException {
                    super.close();
                }
            };
            return new FSDataOutputStream(fakeStream, statistics);
        }
    } catch (InterruptedException e) {
        throw new InterruptedIOException("Interrupted creating " + objName);
    } catch (IOException e) {
        LOG.error(e.getMessage());
        throw e;
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) COSInputStream(com.ibm.stocator.fs.cos.COSInputStream) InputStream(java.io.InputStream) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) OutputStream(java.io.OutputStream) Upload(com.amazonaws.services.s3.transfer.Upload) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Aggregations

ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)163 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)76 ByteArrayInputStream (java.io.ByteArrayInputStream)52 Test (org.junit.Test)47 IOException (java.io.IOException)33 File (java.io.File)27 AmazonClientException (com.amazonaws.AmazonClientException)25 AmazonServiceException (com.amazonaws.AmazonServiceException)22 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)21 InputStream (java.io.InputStream)20 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)18 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)15 Upload (com.amazonaws.services.s3.transfer.Upload)15 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)11 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)10 Date (java.util.Date)9 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)9 Copy (com.amazonaws.services.s3.transfer.Copy)8 S3Object (com.amazonaws.services.s3.model.S3Object)7 InterruptedIOException (java.io.InterruptedIOException)7