Search in sources :

Example 61 with ObjectMetadata

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

the class S3Backend method touch.

@Override
public void touch(DataIdentifier identifier, long minModifiedDate) throws DataStoreException {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        final long start = System.currentTimeMillis();
        final String key = getKeyName(identifier);
        if (minModifiedDate > 0 && minModifiedDate > getLastModified(identifier)) {
            CopyObjectRequest copReq = new CopyObjectRequest(bucket, key, bucket, key);
            copReq.setNewObjectMetadata(new ObjectMetadata());
            Copy copy = tmx.copy(s3ReqDecorator.decorate(copReq));
            copy.waitForCompletion();
            LOG.debug("[{}] touched. time taken [{}] ms ", new Object[] { identifier, (System.currentTimeMillis() - start) });
        } else {
            LOG.trace("[{}] touch not required. time taken [{}] ms ", new Object[] { identifier, (System.currentTimeMillis() - start) });
        }
    } catch (Exception e) {
        throw new DataStoreException("Error occured in touching key [" + identifier.toString() + "]", e);
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}
Also used : CopyObjectRequest(com.amazonaws.services.s3.model.CopyObjectRequest) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) Copy(com.amazonaws.services.s3.transfer.Copy) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) AmazonServiceException(com.amazonaws.AmazonServiceException) IOException(java.io.IOException) AmazonClientException(com.amazonaws.AmazonClientException)

Example 62 with ObjectMetadata

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

the class S3Backend method exists.

@Override
public boolean exists(DataIdentifier identifier, boolean touch) throws DataStoreException {
    long start = System.currentTimeMillis();
    String key = getKeyName(identifier);
    ObjectMetadata objectMetaData = null;
    boolean retVal = false;
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        objectMetaData = s3service.getObjectMetadata(bucket, key);
        if (objectMetaData != null) {
            retVal = true;
            if (touch) {
                CopyObjectRequest copReq = new CopyObjectRequest(bucket, key, bucket, key);
                copReq.setNewObjectMetadata(objectMetaData);
                Copy copy = tmx.copy(s3ReqDecorator.decorate(copReq));
                copy.waitForCopyResult();
                LOG.debug("[{}] touched took [{}] ms. ", identifier, (System.currentTimeMillis() - start));
            }
        } else {
            retVal = false;
        }
    } catch (AmazonServiceException e) {
        if (e.getStatusCode() == 404 || e.getStatusCode() == 403) {
            retVal = false;
        } else {
            throw new DataStoreException("Error occured to find exists for key [" + identifier.toString() + "]", e);
        }
    } catch (Exception e) {
        throw new DataStoreException("Error occured to find exists for key  " + identifier.toString(), e);
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
    LOG.debug("exists [{}]: [{}] took [{}] ms.", new Object[] { identifier, retVal, (System.currentTimeMillis() - start) });
    return retVal;
}
Also used : CopyObjectRequest(com.amazonaws.services.s3.model.CopyObjectRequest) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) Copy(com.amazonaws.services.s3.transfer.Copy) AmazonServiceException(com.amazonaws.AmazonServiceException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) AmazonServiceException(com.amazonaws.AmazonServiceException) IOException(java.io.IOException) AmazonClientException(com.amazonaws.AmazonClientException)

Example 63 with ObjectMetadata

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

the class S3RequestDecorator method decorate.

/**
     * Set encryption in {@link CopyObjectRequest}
     */
public CopyObjectRequest decorate(CopyObjectRequest request) {
    switch(getDataEncryption()) {
        case SSE_S3:
            ObjectMetadata metadata = request.getNewObjectMetadata() == null ? new ObjectMetadata() : request.getNewObjectMetadata();
            metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
            request.setNewObjectMetadata(metadata);
            break;
        case NONE:
            break;
    }
    return request;
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 64 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project jackrabbit-oak by apache.

the class S3RequestDecorator method decorate.

/**
     * Set encryption in {@link PutObjectRequest}
     */
public PutObjectRequest decorate(PutObjectRequest request) {
    switch(getDataEncryption()) {
        case SSE_S3:
            ObjectMetadata metadata = request.getMetadata() == null ? new ObjectMetadata() : request.getMetadata();
            metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
            request.setMetadata(metadata);
            break;
        case NONE:
            break;
    }
    return request;
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 65 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project jackrabbit-oak by apache.

the class S3Backend method getMetadataRecord.

@Override
public DataRecord getMetadataRecord(String name) {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        ObjectMetadata meta = s3service.getObjectMetadata(bucket, addMetaKeyPrefix(name));
        return new S3DataRecord(this, s3service, bucket, new DataIdentifier(name), meta.getLastModified().getTime(), meta.getContentLength(), true);
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Aggregations

ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)75 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)26 IOException (java.io.IOException)19 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)18 AmazonClientException (com.amazonaws.AmazonClientException)17 AmazonServiceException (com.amazonaws.AmazonServiceException)17 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)10 Upload (com.amazonaws.services.s3.transfer.Upload)10 ByteArrayInputStream (java.io.ByteArrayInputStream)10 InputStream (java.io.InputStream)9 Copy (com.amazonaws.services.s3.transfer.Copy)8 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)7 File (java.io.File)5 InterruptedIOException (java.io.InterruptedIOException)5 Date (java.util.Date)5 Path (org.apache.hadoop.fs.Path)5 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)4 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)3 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)3 InitiateMultipartUploadRequest (com.amazonaws.services.s3.model.InitiateMultipartUploadRequest)3