Search in sources :

Example 11 with Copy

use of com.amazonaws.services.s3.transfer.Copy in project jackrabbit-oak 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) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonClientException(com.amazonaws.AmazonClientException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) IOException(java.io.IOException)

Example 12 with Copy

use of com.amazonaws.services.s3.transfer.Copy in project aws-doc-sdk-examples by awsdocs.

the class CopyObject method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "To run this example, supply the name (key) of an S3 object, the bucket name\n" + "that it's contained within, and the bucket to copy it to.\n" + "\n" + "Ex: CopyObject <objectname> <frombucket> <tobucket>\n";
    if (args.length < 3) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String object_key = args[0];
    String from_bucket = args[1];
    String to_bucket = args[2];
    System.out.format("Copying object %s from bucket %s to %s\n", object_key, from_bucket, to_bucket);
    final AmazonS3 s3 = new AmazonS3Client();
    try {
        s3.copyObject(from_bucket, object_key, to_bucket, object_key);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) AmazonServiceException(com.amazonaws.AmazonServiceException)

Example 13 with Copy

use of com.amazonaws.services.s3.transfer.Copy in project hadoop by apache.

the class S3AFileSystem method setOptionalCopyObjectRequestParameters.

protected void setOptionalCopyObjectRequestParameters(CopyObjectRequest copyObjectRequest) throws IOException {
    switch(serverSideEncryptionAlgorithm) {
        case SSE_KMS:
            copyObjectRequest.setSSEAwsKeyManagementParams(generateSSEAwsKeyParams());
            break;
        case SSE_C:
            if (StringUtils.isNotBlank(getServerSideEncryptionKey(getConf()))) {
                //at the moment, only supports copy using the same key
                SSECustomerKey customerKey = generateSSECustomerKey();
                copyObjectRequest.setSourceSSECustomerKey(customerKey);
                copyObjectRequest.setDestinationSSECustomerKey(customerKey);
            }
            break;
        default:
    }
}
Also used : SSECustomerKey(com.amazonaws.services.s3.model.SSECustomerKey)

Example 14 with Copy

use of com.amazonaws.services.s3.transfer.Copy in project symmetric-ds by JumpMind.

the class RedshiftBulkDatabaseWriter method flush.

protected void flush() {
    if (loadedRows > 0) {
        stagedInputFile.close();
        statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS);
        AmazonS3 s3client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey));
        if (isNotBlank(s3Endpoint)) {
            s3client.setEndpoint(s3Endpoint);
        }
        String objectKey = stagedInputFile.getFile().getName();
        try {
            s3client.putObject(bucket, objectKey, stagedInputFile.getFile());
        } catch (AmazonServiceException ase) {
            log.error("Exception from AWS service: " + ase.getMessage());
        } catch (AmazonClientException ace) {
            log.error("Exception from AWS client: " + ace.getMessage());
        }
        try {
            JdbcSqlTransaction jdbcTransaction = (JdbcSqlTransaction) transaction;
            Connection c = jdbcTransaction.getConnection();
            String sql = "COPY " + getTargetTable().getFullyQualifiedTableName() + " (" + Table.getCommaDeliminatedColumns(table.getColumns()) + ") FROM 's3://" + bucket + "/" + objectKey + "' CREDENTIALS 'aws_access_key_id=" + accessKey + ";aws_secret_access_key=" + secretKey + "' CSV DATEFORMAT 'YYYY-MM-DD HH:MI:SS' " + (needsExplicitIds ? "EXPLICIT_IDS" : "") + (isNotBlank(appendToCopyCommand) ? (" " + appendToCopyCommand) : "");
            Statement stmt = c.createStatement();
            log.debug(sql);
            stmt.execute(sql);
            stmt.close();
            transaction.commit();
        } catch (SQLException ex) {
            throw platform.getSqlTemplate().translate(ex);
        } finally {
            statistics.get(batch).stopTimer(DataWriterStatisticConstants.DATABASEMILLIS);
        }
        stagedInputFile.delete();
        try {
            s3client.deleteObject(bucket, objectKey);
        } catch (AmazonServiceException ase) {
            log.error("Exception from AWS service: " + ase.getMessage());
        } catch (AmazonClientException ace) {
            log.error("Exception from AWS client: " + ace.getMessage());
        }
        createStagingFile();
        loadedRows = 0;
        loadedBytes = 0;
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) SQLException(java.sql.SQLException) Statement(java.sql.Statement) AmazonClientException(com.amazonaws.AmazonClientException) AmazonServiceException(com.amazonaws.AmazonServiceException) Connection(java.sql.Connection) JdbcSqlTransaction(org.jumpmind.db.sql.JdbcSqlTransaction) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 15 with Copy

use of com.amazonaws.services.s3.transfer.Copy 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)

Aggregations

AmazonClientException (com.amazonaws.AmazonClientException)10 AmazonServiceException (com.amazonaws.AmazonServiceException)10 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)9 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)9 Copy (com.amazonaws.services.s3.transfer.Copy)9 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)7 IOException (java.io.IOException)6 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)4 DeleteObjectsRequest (com.amazonaws.services.s3.model.DeleteObjectsRequest)4 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)4 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)4 ArrayList (java.util.ArrayList)4 ExecutorService (java.util.concurrent.ExecutorService)4 DeleteObjectsResult (com.amazonaws.services.s3.model.DeleteObjectsResult)3 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)3 Upload (com.amazonaws.services.s3.transfer.Upload)3 NamedThreadFactory (org.apache.jackrabbit.core.data.util.NamedThreadFactory)3 AmazonS3 (com.amazonaws.services.s3.AmazonS3)2 TransferManager (com.amazonaws.services.s3.transfer.TransferManager)2 AsyncUploadResult (org.apache.jackrabbit.core.data.AsyncUploadResult)2