Example usage for com.amazonaws.services.s3.model ObjectMetadata getVersionId

List of usage examples for com.amazonaws.services.s3.model ObjectMetadata getVersionId

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model ObjectMetadata getVersionId.

Prototype

public String getVersionId() 

Source Link

Document

Gets the version ID of the associated Amazon S3 object if available.

Usage

From source file:com.emc.vipr.services.s3.ViPRS3Client.java

License:Open Source License

public UpdateObjectResult updateObject(UpdateObjectRequest request) throws AmazonClientException {
    ObjectMetadata returnedMetadata = doPut(request);
    UpdateObjectResult result = new UpdateObjectResult();
    result.setETag(returnedMetadata.getETag());
    result.setVersionId(returnedMetadata.getVersionId());
    result.setServerSideEncryption(returnedMetadata.getServerSideEncryption());
    result.setExpirationTime(returnedMetadata.getExpirationTime());
    result.setExpirationTimeRuleId(returnedMetadata.getExpirationTimeRuleId());
    return result;
}

From source file:com.emc.vipr.services.s3.ViPRS3Client.java

License:Open Source License

public AppendObjectResult appendObject(AppendObjectRequest request) throws AmazonClientException {
    ObjectMetadata returnedMetadata = doPut(request);
    AppendObjectResult result = new AppendObjectResult();
    result.setETag(returnedMetadata.getETag());
    result.setVersionId(returnedMetadata.getVersionId());
    result.setServerSideEncryption(returnedMetadata.getServerSideEncryption());
    result.setExpirationTime(returnedMetadata.getExpirationTime());
    result.setExpirationTimeRuleId(returnedMetadata.getExpirationTimeRuleId());
    result.setAppendOffset(// www  . j  av  a2  s.c  om
            Long.parseLong("" + returnedMetadata.getRawMetadata().get(ViPRConstants.APPEND_OFFSET_HEADER)));
    return result;
}

From source file:io.konig.camel.aws.s3.DeleteObjectEndpoint.java

License:Apache License

public Exchange createExchange(ExchangePattern pattern, final S3Object s3Object) {
    LOG.trace("Getting object with key [{}] from bucket [{}]...", s3Object.getKey(), s3Object.getBucketName());

    ObjectMetadata objectMetadata = s3Object.getObjectMetadata();

    LOG.trace("Got object [{}]", s3Object);

    Exchange exchange = super.createExchange(pattern);
    Message message = exchange.getIn();// www.  java 2  s  .co m

    if (configuration.isIncludeBody()) {
        message.setBody(s3Object.getObjectContent());
    } else {
        message.setBody(null);
    }

    message.setHeader(S3Constants.KEY, s3Object.getKey());
    message.setHeader(S3Constants.BUCKET_NAME, s3Object.getBucketName());
    message.setHeader(S3Constants.E_TAG, objectMetadata.getETag());
    message.setHeader(S3Constants.LAST_MODIFIED, objectMetadata.getLastModified());
    message.setHeader(S3Constants.VERSION_ID, objectMetadata.getVersionId());
    message.setHeader(S3Constants.CONTENT_TYPE, objectMetadata.getContentType());
    message.setHeader(S3Constants.CONTENT_MD5, objectMetadata.getContentMD5());
    message.setHeader(S3Constants.CONTENT_LENGTH, objectMetadata.getContentLength());
    message.setHeader(S3Constants.CONTENT_ENCODING, objectMetadata.getContentEncoding());
    message.setHeader(S3Constants.CONTENT_DISPOSITION, objectMetadata.getContentDisposition());
    message.setHeader(S3Constants.CACHE_CONTROL, objectMetadata.getCacheControl());
    message.setHeader(S3Constants.S3_HEADERS, objectMetadata.getRawMetadata());
    message.setHeader(S3Constants.SERVER_SIDE_ENCRYPTION, objectMetadata.getSSEAlgorithm());
    message.setHeader(S3Constants.USER_METADATA, objectMetadata.getUserMetadata());
    message.setHeader(S3Constants.EXPIRATION_TIME, objectMetadata.getExpirationTime());
    message.setHeader(S3Constants.REPLICATION_STATUS, objectMetadata.getReplicationStatus());
    message.setHeader(S3Constants.STORAGE_CLASS, objectMetadata.getStorageClass());

    /**
    * If includeBody != true, it is safe to close the object here. If
    * includeBody == true, the caller is responsible for closing the stream
    * and object once the body has been fully consumed. As of 2.17, the
    * consumer does not close the stream or object on commit.
    */
    if (!configuration.isIncludeBody()) {
        IOHelper.close(s3Object);
    } else {
        if (configuration.isAutocloseBody()) {
            exchange.addOnCompletion(new SynchronizationAdapter() {
                @Override
                public void onDone(Exchange exchange) {
                    IOHelper.close(s3Object);
                }
            });
        }
    }

    return exchange;
}

From source file:org.apache.camel.component.aws.s3.S3Endpoint.java

License:Apache License

public Exchange createExchange(ExchangePattern pattern, S3Object s3Object) {
    LOG.trace("Getting object with key [{}] from bucket [{}]...", s3Object.getKey(), s3Object.getBucketName());

    ObjectMetadata objectMetadata = s3Object.getObjectMetadata();

    LOG.trace("Got object [{}]", s3Object);

    Exchange exchange = new DefaultExchange(this, pattern);
    Message message = exchange.getIn();/*from  ww w . j  a  va 2s  . c o m*/
    message.setBody(s3Object.getObjectContent());
    message.setHeader(S3Constants.KEY, s3Object.getKey());
    message.setHeader(S3Constants.BUCKET_NAME, s3Object.getBucketName());
    message.setHeader(S3Constants.E_TAG, objectMetadata.getETag());
    message.setHeader(S3Constants.LAST_MODIFIED, objectMetadata.getLastModified());
    message.setHeader(S3Constants.VERSION_ID, objectMetadata.getVersionId());
    message.setHeader(S3Constants.CONTENT_TYPE, objectMetadata.getContentType());
    message.setHeader(S3Constants.CONTENT_MD5, objectMetadata.getContentMD5());
    message.setHeader(S3Constants.CONTENT_LENGTH, objectMetadata.getContentLength());
    message.setHeader(S3Constants.CONTENT_ENCODING, objectMetadata.getContentEncoding());
    message.setHeader(S3Constants.CONTENT_DISPOSITION, objectMetadata.getContentDisposition());
    message.setHeader(S3Constants.CACHE_CONTROL, objectMetadata.getCacheControl());

    return exchange;
}

From source file:org.apache.nifi.processors.aws.s3.FetchS3Object.java

License:Apache License

@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) {
    FlowFile flowFile = session.get();//from   ww w.  jav  a2 s .c o  m
    if (flowFile == null) {
        return;
    }

    final long startNanos = System.nanoTime();
    final String bucket = context.getProperty(BUCKET).evaluateAttributeExpressions(flowFile).getValue();
    final String key = context.getProperty(KEY).evaluateAttributeExpressions(flowFile).getValue();
    final String versionId = context.getProperty(VERSION_ID).evaluateAttributeExpressions(flowFile).getValue();

    final AmazonS3 client = getClient();
    final GetObjectRequest request;
    if (versionId == null) {
        request = new GetObjectRequest(bucket, key);
    } else {
        request = new GetObjectRequest(bucket, key, versionId);
    }

    final Map<String, String> attributes = new HashMap<>();
    try (final S3Object s3Object = client.getObject(request)) {
        flowFile = session.importFrom(s3Object.getObjectContent(), flowFile);
        attributes.put("s3.bucket", s3Object.getBucketName());

        final ObjectMetadata metadata = s3Object.getObjectMetadata();
        if (metadata.getContentDisposition() != null) {
            final String fullyQualified = metadata.getContentDisposition();
            final int lastSlash = fullyQualified.lastIndexOf("/");
            if (lastSlash > -1 && lastSlash < fullyQualified.length() - 1) {
                attributes.put(CoreAttributes.PATH.key(), fullyQualified.substring(0, lastSlash));
                attributes.put(CoreAttributes.ABSOLUTE_PATH.key(), fullyQualified);
                attributes.put(CoreAttributes.FILENAME.key(), fullyQualified.substring(lastSlash + 1));
            } else {
                attributes.put(CoreAttributes.FILENAME.key(), metadata.getContentDisposition());
            }
        }
        if (metadata.getContentMD5() != null) {
            attributes.put("hash.value", metadata.getContentMD5());
            attributes.put("hash.algorithm", "MD5");
        }
        if (metadata.getContentType() != null) {
            attributes.put(CoreAttributes.MIME_TYPE.key(), metadata.getContentType());
        }
        if (metadata.getETag() != null) {
            attributes.put("s3.etag", metadata.getETag());
        }
        if (metadata.getExpirationTime() != null) {
            attributes.put("s3.expirationTime", String.valueOf(metadata.getExpirationTime().getTime()));
        }
        if (metadata.getExpirationTimeRuleId() != null) {
            attributes.put("s3.expirationTimeRuleId", metadata.getExpirationTimeRuleId());
        }
        if (metadata.getUserMetadata() != null) {
            attributes.putAll(metadata.getUserMetadata());
        }
        if (metadata.getSSEAlgorithm() != null) {
            attributes.put("s3.sseAlgorithm", metadata.getSSEAlgorithm());
        }
        if (metadata.getVersionId() != null) {
            attributes.put("s3.version", metadata.getVersionId());
        }
    } catch (final IOException | AmazonClientException ioe) {
        getLogger().error("Failed to retrieve S3 Object for {}; routing to failure",
                new Object[] { flowFile, ioe });
        flowFile = session.penalize(flowFile);
        session.transfer(flowFile, REL_FAILURE);
        return;
    }

    if (!attributes.isEmpty()) {
        flowFile = session.putAllAttributes(flowFile, attributes);
    }

    session.transfer(flowFile, REL_SUCCESS);
    final long transferMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos);
    getLogger().info("Successfully retrieved S3 Object for {} in {} millis; routing to success",
            new Object[] { flowFile, transferMillis });
    session.getProvenanceReporter().fetch(flowFile, "http://" + bucket + ".amazonaws.com/" + key,
            transferMillis);
}

From source file:org.openflamingo.fs.s3.S3Utils.java

License:Apache License

/**
 * Bucket  ./*from  w  w  w . j  ava 2  s  .  c o m*/
 *
 * @param client     Amazon S3 Client
 * @param bucketName Bucket Name
 */
public static Map<String, String> getBucketInfo(AmazonS3Client client, String bucketName) {
    Bucket bucket = getBucket(client, bucketName);
    if (bucket == null) {
        return null;
    }

    ObjectMetadata objectMetadata = client.getObjectMetadata(bucketName, "");

    Map<String, String> map = new HashMap<String, String>();
    map.put("name", bucket.getName());
    map.put("ownerName", bucket.getOwner().getDisplayName());
    map.put("ownerId", bucket.getOwner().getId());
    setValue("create", bucket.getCreationDate(), map);
    setValue("location", client.getBucketLocation(bucketName), map);
    setValue("version", objectMetadata.getVersionId(), map);
    setValue("contentDisposition", objectMetadata.getContentDisposition(), map);
    setValue("contentType", objectMetadata.getContentType(), map);
    setValue("etag", objectMetadata.getETag(), map);
    setValue("contentEncoding", objectMetadata.getContentEncoding(), map);
    setValue("contentLength", objectMetadata.getContentLength(), map);
    setValue("lastModified", objectMetadata.getLastModified(), map);

    return map;
}

From source file:org.openflamingo.fs.s3.S3Utils.java

License:Apache License

/**
 * Object  ./*www.  j  a  va  2 s .  c o  m*/
 *
 * @param client     Amazon S3 Client
 * @param bucketName Bucket Name
 */
public static Map<String, String> getObject(AmazonS3Client client, String bucketName, String objectKey) {
    S3Object object = client.getObject(bucketName, objectKey);
    ObjectMetadata objectMetadata = object.getObjectMetadata();

    Map<String, String> map = new HashMap<String, String>();

    if (!object.getKey().endsWith("/")) {
        String qualifiedPath = "/" + bucketName + "/" + object.getKey();
        map.put("bucketName", object.getBucketName());
        map.put("name", FileUtils.getFilename(qualifiedPath));
        map.put("path", qualifiedPath);
    } else {
        map.put("bucketName", object.getBucketName());
        map.put("name", object.getKey());
        map.put("name", "/" + bucketName + "/" + object.getKey());
    }

    setValue("redirectionLocation", object.getRedirectLocation(), map);
    setValue("version", objectMetadata.getVersionId(), map);
    setValue("contentDisposition", objectMetadata.getContentDisposition(), map);
    setValue("contentType", objectMetadata.getContentType(), map);
    setValue("etag", objectMetadata.getETag(), map);
    setValue("contentEncoding", objectMetadata.getContentEncoding(), map);
    setValue("contentLength", objectMetadata.getContentLength(), map);
    setValue("lastModified", objectMetadata.getLastModified(), map);
    return map;
}

From source file:org.openflamingo.fs.s3.S3Utils.java

License:Apache License

/**
 * Object  ./*from  w w  w .  j  a v  a  2s.  c  om*/
 *
 * @param client     Amazon S3 Client
 * @param bucketName Bucket Name
 */
public static Map<String, String> getDirectory(AmazonS3Client client, String bucketName, String objectKey) {
    S3Object object = client.getObject(bucketName, objectKey);
    ObjectMetadata objectMetadata = object.getObjectMetadata();

    List<FileInfo> filesList = new ArrayList<FileInfo>();
    ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(object.getBucketName())
            .withPrefix(objectKey).withDelimiter("/");

    ObjectListing objectListing = null;

    do {
        objectListing = client.listObjects(listObjectsRequest);
        List<String> commonPrefixes = objectListing.getCommonPrefixes();
        List<S3ObjectSummary> summary = objectListing.getObjectSummaries();
        listObjectsRequest.setMarker(objectListing.getNextMarker());
    } while (objectListing.isTruncated());

    Map<String, String> map = new HashMap<String, String>();

    map.put("bucketName", object.getBucketName());
    map.put("name", object.getKey());
    map.put("redirectionLocation", object.getRedirectLocation());

    setValue("version", objectMetadata.getVersionId(), map);
    setValue("contentDisposition", objectMetadata.getContentDisposition(), map);
    setValue("contentType", objectMetadata.getContentType(), map);
    setValue("etag", objectMetadata.getETag(), map);
    setValue("contentEncoding", objectMetadata.getContentEncoding(), map);
    setValue("contentLength", objectMetadata.getContentLength(), map);
    setValue("lastModified", objectMetadata.getLastModified(), map);
    return null;
}

From source file:org.xmlsh.aws.util.AWSS3Command.java

License:BSD License

protected void writeMeta(ObjectMetadata m)
        throws InvalidArgumentException, XMLStreamException, SaxonApiException {

    mLogger.entry(m);//  w ww.  j a v a2s  .c  om
    startElement(sMetaDataElem);

    attribute("cache-control", m.getCacheControl());
    attribute("content-disposition", m.getContentDisposition());
    attribute("content-encoding", m.getContentEncoding());
    attribute("md5", m.getContentMD5());
    attribute("etag", m.getETag());
    attribute("version-id", m.getVersionId());
    attribute("content-length", String.valueOf(m.getContentLength()));
    attribute("last-modified", Util.formatXSDateTime(m.getLastModified()));
    attribute("expiration-time", Util.formatXSDateTime(m.getExpirationTime()));
    attribute("expiration-time-rule-id", m.getExpirationTimeRuleId());
    attribute("httpExpiresDate", Util.formatXSDateTime(m.getHttpExpiresDate()));
    attribute("ongoingRestore", m.getOngoingRestore());
    attribute("restore-expiration-time", Util.formatXSDateTime(m.getRestoreExpirationTime()));
    attribute("instance-length", m.getInstanceLength());
    attribute("sse-algorithm", m.getSSEAlgorithm());
    attribute("sse-aws-kms-key-id", m.getSSEAwsKmsKeyId());
    attribute("sse-customer-algorithm", m.getSSECustomerAlgorithm());
    attribute("sse-customer-key-md5", m.getSSECustomerKeyMd5());
    attribute("storage-class", m.getStorageClass());

    startElement("user-metadata");
    for (Entry<String, String> user : m.getUserMetadata().entrySet()) {
        startElement(sUserMetaDataElem);
        attribute("name", user.getKey());
        attribute("value", user.getValue());
        endElement();

    }
    endElement();
    endElement();

    mLogger.exit();
}