Search in sources :

Example 1 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project camel by apache.

the class S3Producer method processSingleOp.

public void processSingleOp(final Exchange exchange) throws Exception {
    ObjectMetadata objectMetadata = determineMetadata(exchange);
    File filePayload = null;
    InputStream is = null;
    Object obj = exchange.getIn().getMandatoryBody();
    PutObjectRequest putObjectRequest = null;
    // Need to check if the message body is WrappedFile
    if (obj instanceof WrappedFile) {
        obj = ((WrappedFile<?>) obj).getFile();
    }
    if (obj instanceof File) {
        filePayload = (File) obj;
        is = new FileInputStream(filePayload);
    } else {
        is = exchange.getIn().getMandatoryBody(InputStream.class);
    }
    putObjectRequest = new PutObjectRequest(getConfiguration().getBucketName(), determineKey(exchange), is, objectMetadata);
    String storageClass = determineStorageClass(exchange);
    if (storageClass != null) {
        putObjectRequest.setStorageClass(storageClass);
    }
    String cannedAcl = exchange.getIn().getHeader(S3Constants.CANNED_ACL, String.class);
    if (cannedAcl != null) {
        CannedAccessControlList objectAcl = CannedAccessControlList.valueOf(cannedAcl);
        putObjectRequest.setCannedAcl(objectAcl);
    }
    AccessControlList acl = exchange.getIn().getHeader(S3Constants.ACL, AccessControlList.class);
    if (acl != null) {
        // note: if cannedacl and acl are both specified the last one will be used. refer to
        // PutObjectRequest#setAccessControlList for more details
        putObjectRequest.setAccessControlList(acl);
    }
    LOG.trace("Put object [{}] from exchange [{}]...", putObjectRequest, exchange);
    PutObjectResult putObjectResult = getEndpoint().getS3Client().putObject(putObjectRequest);
    LOG.trace("Received result [{}]", putObjectResult);
    Message message = getMessageForResponse(exchange);
    message.setHeader(S3Constants.E_TAG, putObjectResult.getETag());
    if (putObjectResult.getVersionId() != null) {
        message.setHeader(S3Constants.VERSION_ID, putObjectResult.getVersionId());
    }
    if (getConfiguration().isDeleteAfterWrite() && filePayload != null) {
        // close streams
        IOHelper.close(putObjectRequest.getInputStream());
        IOHelper.close(is);
        FileUtil.deleteFile(filePayload);
    }
}
Also used : CannedAccessControlList(com.amazonaws.services.s3.model.CannedAccessControlList) AccessControlList(com.amazonaws.services.s3.model.AccessControlList) Message(org.apache.camel.Message) WrappedFile(org.apache.camel.WrappedFile) PutObjectResult(com.amazonaws.services.s3.model.PutObjectResult) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CannedAccessControlList(com.amazonaws.services.s3.model.CannedAccessControlList) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) File(java.io.File) WrappedFile(org.apache.camel.WrappedFile) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) FileInputStream(java.io.FileInputStream)

Example 2 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project hadoop by apache.

the class S3AFileSystem method getObjectMetadata.

/**
   * Request object metadata; increments counters in the process.
   * @param key key
   * @return the metadata
   */
protected ObjectMetadata getObjectMetadata(String key) {
    incrementStatistic(OBJECT_METADATA_REQUESTS);
    GetObjectMetadataRequest request = new GetObjectMetadataRequest(bucket, key);
    //SSE-C requires to be filled in if enabled for object metadata
    if (S3AEncryptionMethods.SSE_C.equals(serverSideEncryptionAlgorithm) && StringUtils.isNotBlank(getServerSideEncryptionKey(getConf()))) {
        request.setSSECustomerKey(generateSSECustomerKey());
    }
    ObjectMetadata meta = s3.getObjectMetadata(request);
    incrementReadOperations();
    return meta;
}
Also used : GetObjectMetadataRequest(com.amazonaws.services.s3.model.GetObjectMetadataRequest) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 3 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project hadoop by apache.

the class S3AFileSystem method copyFile.

/**
   * Copy a single object in the bucket via a COPY operation.
   * @param srcKey source object path
   * @param dstKey destination object path
   * @param size object size
   * @throws AmazonClientException on failures inside the AWS SDK
   * @throws InterruptedIOException the operation was interrupted
   * @throws IOException Other IO problems
   */
private void copyFile(String srcKey, String dstKey, long size) throws IOException, InterruptedIOException, AmazonClientException {
    LOG.debug("copyFile {} -> {} ", srcKey, dstKey);
    try {
        ObjectMetadata srcom = getObjectMetadata(srcKey);
        ObjectMetadata dstom = cloneObjectMetadata(srcom);
        setOptionalObjectMetadata(dstom);
        CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucket, srcKey, bucket, dstKey);
        setOptionalCopyObjectRequestParameters(copyObjectRequest);
        copyObjectRequest.setCannedAccessControlList(cannedACL);
        copyObjectRequest.setNewObjectMetadata(dstom);
        ProgressListener progressListener = new ProgressListener() {

            public void progressChanged(ProgressEvent progressEvent) {
                switch(progressEvent.getEventType()) {
                    case TRANSFER_PART_COMPLETED_EVENT:
                        incrementWriteOperations();
                        break;
                    default:
                        break;
                }
            }
        };
        Copy copy = transfers.copy(copyObjectRequest);
        copy.addProgressListener(progressListener);
        try {
            copy.waitForCopyResult();
            incrementWriteOperations();
            instrumentation.filesCopied(1, size);
        } catch (InterruptedException e) {
            throw new InterruptedIOException("Interrupted copying " + srcKey + " to " + dstKey + ", cancelling");
        }
    } catch (AmazonClientException e) {
        throw translateException("copyFile(" + srcKey + ", " + dstKey + ")", srcKey, e);
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) CopyObjectRequest(com.amazonaws.services.s3.model.CopyObjectRequest) ProgressListener(com.amazonaws.event.ProgressListener) Copy(com.amazonaws.services.s3.transfer.Copy) AmazonClientException(com.amazonaws.AmazonClientException) ProgressEvent(com.amazonaws.event.ProgressEvent) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 4 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project hadoop by apache.

the class S3AFileSystem method newPutObjectRequest.

/**
   * Create a {@link PutObjectRequest} request.
   * The metadata is assumed to have been configured with the size of the
   * operation.
   * @param key key of object
   * @param metadata metadata header
   * @param inputStream source data.
   * @return the request
   */
private PutObjectRequest newPutObjectRequest(String key, ObjectMetadata metadata, InputStream inputStream) {
    Preconditions.checkNotNull(inputStream);
    PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, inputStream, metadata);
    setOptionalPutRequestParameters(putObjectRequest);
    putObjectRequest.setCannedAcl(cannedACL);
    return putObjectRequest;
}
Also used : PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 5 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project hadoop by apache.

the class ITestS3AEncryptionSSEKMSDefaultKey method assertEncrypted.

@Override
protected void assertEncrypted(Path path) throws IOException {
    ObjectMetadata md = getFileSystem().getObjectMetadata(path);
    assertEquals("aws:kms", md.getSSEAlgorithm());
    assertThat(md.getSSEAwsKmsKeyId(), containsString("arn:aws:kms:"));
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Aggregations

ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)64 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)20 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)18 AmazonServiceException (com.amazonaws.AmazonServiceException)17 AmazonClientException (com.amazonaws.AmazonClientException)15 IOException (java.io.IOException)13 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)10 Copy (com.amazonaws.services.s3.transfer.Copy)8 Upload (com.amazonaws.services.s3.transfer.Upload)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 InputStream (java.io.InputStream)8 Date (java.util.Date)6 File (java.io.File)5 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)4 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)4 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)3 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)3 S3Object (com.amazonaws.services.s3.model.S3Object)3 InterruptedIOException (java.io.InterruptedIOException)3 ProgressEvent (com.amazonaws.event.ProgressEvent)2