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

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

Introduction

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

Prototype

String OFF

To view the source code for com.amazonaws.services.s3.model BucketVersioningConfiguration OFF.

Click Source Link

Document

S3 bucket versioning status indicating that versioning is off for a bucket.

Usage

From source file:com.emc.ecs.sync.target.S3Target.java

License:Open Source License

@Override
public void configure(SyncSource source, Iterator<SyncFilter> filters, SyncTarget target) {
    Assert.hasText(accessKey, "accessKey is required");
    Assert.hasText(secretKey, "secretKey is required");
    Assert.hasText(bucketName, "bucketName is required");
    Assert.isTrue(bucketName.matches("[A-Za-z0-9._-]+"), bucketName + " is not a valid bucket name");

    AWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
    ClientConfiguration config = new ClientConfiguration();

    if (protocol != null)
        config.setProtocol(Protocol.valueOf(protocol.toUpperCase()));

    if (legacySignatures)
        config.setSignerOverride("S3SignerType");

    if (socketTimeoutMs >= 0)
        config.setSocketTimeout(socketTimeoutMs);

    s3 = new AmazonS3Client(creds, config);

    if (endpoint != null)
        s3.setEndpoint(endpoint);/*w ww  . j av  a 2s  . co m*/

    // TODO: generalize uri translation
    AwsS3Util.S3Uri s3Uri = new AwsS3Util.S3Uri();
    s3Uri.protocol = protocol;
    s3Uri.endpoint = endpoint;
    s3Uri.accessKey = accessKey;
    s3Uri.secretKey = secretKey;
    s3Uri.rootKey = rootKey;
    if (targetUri == null)
        targetUri = s3Uri.toUri();

    if (disableVHosts) {
        log.info(
                "The use of virtual hosted buckets on the s3 source has been DISABLED.  Path style buckets will be used.");
        S3ClientOptions opts = new S3ClientOptions();
        opts.setPathStyleAccess(true);
        s3.setS3ClientOptions(opts);
    }

    // for version support. TODO: genericize version support
    if (source instanceof S3Source) {
        s3Source = (S3Source) source;
        if (!s3Source.isVersioningEnabled())
            includeVersions = false; // don't include versions if source versioning is off
    } else if (includeVersions) {
        throw new ConfigurationException(
                "Object versions are currently only supported with the S3 source & target plugins.");
    }

    if (!s3.doesBucketExist(bucketName)) {
        if (createBucket) {
            s3.createBucket(bucketName);
            if (includeVersions)
                s3.setBucketVersioningConfiguration(new SetBucketVersioningConfigurationRequest(bucketName,
                        new BucketVersioningConfiguration(BucketVersioningConfiguration.ENABLED)));
        } else {
            throw new ConfigurationException("The bucket " + bucketName + " does not exist.");
        }
    }

    if (rootKey == null)
        rootKey = ""; // make sure rootKey isn't null

    if (includeVersions) {
        String status = s3.getBucketVersioningConfiguration(bucketName).getStatus();
        if (BucketVersioningConfiguration.OFF.equals(status))
            throw new ConfigurationException("The specified bucket does not have versioning enabled.");
    }

    if (mpuThresholdMB > AwsS3Util.MAX_PUT_SIZE_MB) {
        log.warn("{}MB is above the maximum PUT size of {}MB. the maximum will be used instead", mpuThresholdMB,
                AwsS3Util.MAX_PUT_SIZE_MB);
        mpuThresholdMB = AwsS3Util.MAX_PUT_SIZE_MB;
    }
    if (mpuPartSizeMB < AwsS3Util.MIN_PART_SIZE_MB) {
        log.warn("{}MB is below the minimum MPU part size of {}MB. the minimum will be used instead",
                mpuPartSizeMB, AwsS3Util.MIN_PART_SIZE_MB);
        mpuPartSizeMB = AwsS3Util.MIN_PART_SIZE_MB;
    }
}

From source file:org.chodavarapu.jgitaws.repositories.PackRepository.java

License:Eclipse Distribution License

public DfsOutputStream savePack(String repositoryName, String packName, long length) throws IOException {
    PipedInputStream pipedInputStream = new PipedInputStream(configuration.getStreamingBlockSize());

    ObjectMetadata metaData = new ObjectMetadata();
    metaData.setContentLength(length);//from  www.j  av a2  s  . c  o  m

    String objectName = objectName(repositoryName, packName);

    Async.fromAction(() -> {
        logger.debug("Attempting to save pack {} to S3 bucket", objectName);
        try {
            configuration.getS3Client().putObject(configuration.getPacksBucketName(), objectName,
                    pipedInputStream, metaData);
        } catch (AmazonServiceException e) {
            if ("InvalidBucketName".equals(e.getErrorCode()) || "InvalidBucketState".equals(e.getErrorCode())) {
                logger.debug("S3 packs bucket does not exist yet, creating it");
                configuration.getS3Client()
                        .createBucket(new CreateBucketRequest(configuration.getPacksBucketName()));
                configuration.getS3Client().setBucketVersioningConfiguration(
                        new SetBucketVersioningConfigurationRequest(configuration.getPacksBucketName(),
                                new BucketVersioningConfiguration(BucketVersioningConfiguration.OFF)));

                logger.debug("Created bucket, saving pack {}", objectName);
                configuration.getS3Client().putObject(configuration.getPacksBucketName(), objectName,
                        pipedInputStream, metaData);
            } else {
                throw e;
            }
        }
    }, null, Schedulers.io());

    return new PipedDfsOutputStream(pipedInputStream, objectName, (int) length,
            configuration.getStreamingBlockSize());
}

From source file:org.mule.module.s3.simpleapi.SimpleAmazonS3AmazonDevKitImpl.java

License:Open Source License

public void deleteBucketAndObjects(@NotNull String bucketName)

{
    Validate.notNull(bucketName);/*  w  w w. ja  v a  2s.  c o m*/
    if (!s3.getBucketVersioningConfiguration(bucketName).getStatus()
            .equals(BucketVersioningConfiguration.OFF)) {
        ListVersionsRequest request = new ListVersionsRequest().withBucketName(bucketName);
        for (S3VersionSummary summary : listObjectVersions(request)) {
            s3.deleteVersion(bucketName, summary.getKey(), summary.getVersionId());
        }
    } else {
        ListObjectsRequest request = new ListObjectsRequest().withBucketName(bucketName);
        for (S3ObjectSummary summary : listObjects(request)) {
            s3.deleteObject(bucketName, summary.getKey());
        }
    }
    deleteBucket(bucketName);
}