Example usage for com.amazonaws.services.s3.model BucketVersioningConfiguration BucketVersioningConfiguration

List of usage examples for com.amazonaws.services.s3.model BucketVersioningConfiguration BucketVersioningConfiguration

Introduction

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

Prototype

public BucketVersioningConfiguration() 

Source Link

Document

Creates a new bucket versioning configuration object which defaults to #OFF status.

Usage

From source file:com.eucalyptus.objectstorage.providers.s3.S3ProviderClient.java

License:Open Source License

@Override
public SetBucketVersioningStatusResponseType setBucketVersioningStatus(SetBucketVersioningStatusType request)
        throws S3Exception {
    SetBucketVersioningStatusResponseType reply = request.getReply();
    User requestUser = getRequestUser(request);
    OsgInternalS3Client internalS3Client = null;

    try {//from   w  w w  . j  av a2s  .c  o m
        internalS3Client = getS3Client(requestUser);
        AmazonS3Client s3Client = internalS3Client.getS3Client();
        BucketVersioningConfiguration config = new BucketVersioningConfiguration()
                .withStatus(request.getVersioningStatus());
        SetBucketVersioningConfigurationRequest configRequest = new SetBucketVersioningConfigurationRequest(
                request.getBucket(), config);
        s3Client.setBucketVersioningConfiguration(configRequest);
    } catch (AmazonServiceException e) {
        LOG.debug("Error from backend", e);
        throw S3ExceptionMapper.fromAWSJavaSDK(e);
    }

    return reply;
}

From source file:com.nike.cerberus.operation.core.EnableConfigReplicationOperation.java

License:Apache License

private String createReplicationBucket(final EnableConfigReplicationCommand command) {
    final Region originalRegion = s3Client.getRegion();
    try {/*from   w  w  w . j  av  a2s  . co m*/
        s3Client.setRegion(
                com.amazonaws.regions.Region.getRegion(Regions.fromName(command.getReplicationRegion())));

        // 1. Create the replication bucket.
        final String bucketName = String.format(replicationBucketNameTemplate, environmentMetadata.getName(),
                uuidSupplier.get());

        final CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);

        logger.info("Creating the replication bucket, {}", bucketName);
        s3Client.createBucket(createBucketRequest);

        // 2. Enable versioning on the replication bucket.
        final BucketVersioningConfiguration configuration = new BucketVersioningConfiguration()
                .withStatus("Enabled");
        final SetBucketVersioningConfigurationRequest setBucketVersioningConfigurationRequest = new SetBucketVersioningConfigurationRequest(
                bucketName, configuration);

        logger.info("Enabling versioning on the replication bucket.");
        s3Client.setBucketVersioningConfiguration(setBucketVersioningConfigurationRequest);

        return bucketName;
    } finally {
        s3Client.setRegion(originalRegion.toAWSRegion());
    }
}

From source file:org.yardstickframework.spark.S3MasterUrlProvider.java

License:Apache License

/**
 * Method init amazon s3 API.//from   ww  w . j  a v  a  2 s . co m
 */
private void initAwsClient() {
    if (clientInit)
        return;

    String awsAccessKey = System.getenv("AWS_ACCESS_KEY");

    String awsSecretKey = System.getenv("AWS_SECRET_KEY");

    AWSCredentials cred;

    if (awsAccessKey == null || awsAccessKey.isEmpty() || awsSecretKey == null || awsSecretKey.isEmpty())
        throw new IllegalArgumentException("AWS credentials are not set.");
    else
        cred = new BasicAWSCredentials(awsAccessKey, awsSecretKey);

    if (bucketName == null || bucketName.isEmpty())
        throw new IllegalArgumentException("Bucket name is null or empty (provide bucket name and restart).");

    s3 = new AmazonS3Client(cred);

    if (!s3.doesBucketExist(bucketName)) {
        try {
            s3.createBucket(bucketName);

            BucketVersioningConfiguration verCfg = new BucketVersioningConfiguration();

            verCfg.setStatus(BucketVersioningConfiguration.ENABLED);

            s3.setBucketVersioningConfiguration(
                    new SetBucketVersioningConfigurationRequest(bucketName, verCfg));

            println("Created S3 bucket: " + bucketName);

            while (!s3.doesBucketExist(bucketName))
                try {
                    TimeUnit.MILLISECONDS.sleep(200L);
                } catch (Exception e) {
                    throw new RuntimeException("Thread has been interrupted.", e);
                }
        } catch (AmazonClientException e) {
            if (!s3.doesBucketExist(bucketName)) {
                s3 = null;

                throw new RuntimeException("Failed to create bucket: " + bucketName, e);
            }
        }
    }

    // Client init success.
    clientInit = true;
}