Package com.amazonaws.services.s3

Examples of com.amazonaws.services.s3.AmazonS3


            getLog().info("Per configuration, we will NOTE perform any remote operations on the S3 repository.");
            logPrefix = "SKIPPING: ";
        }
        final S3RepositoryPath targetRepository = context.getS3RepositoryPath();
        final String targetBucket = targetRepository.getBucketName();
        AmazonS3 s3Session = context.getS3Session();
        for (File toUpload : ExtraIOUtils.listAllFiles(stagingDirectory)) {
            String bucketKey = localFileToTargetS3BucketKey(toUpload, targetRepository);
            getLog().info(logPrefix + "Uploading: " + toUpload.getName() + " => s3://" + targetRepository.getBucketName() + "/" + bucketKey + "...");
            if (!doNotUpload) {
                s3Session.putObject(new PutObjectRequest(targetBucket, bucketKey, toUpload));
            }
        }
    }
View Full Code Here


            getLog().info("Per configuration, we will NOTE perform any remote operations on the S3 repository.");
            logPrefix = "SKIPPING: ";
        }
        final S3RepositoryPath targetRepository = context.getS3RepositoryPath();
        final String targetBucket = targetRepository.getBucketName();
        AmazonS3 s3Session = context.getS3Session();
        for (File toUpload : ExtraIOUtils.listAllFiles(stagingDirectory)) {
            String bucketKey = localFileToTargetS3BucketKey(toUpload, targetRepository);
            getLog().info(logPrefix + "Uploading: " + toUpload.getName() + " => s3://" + targetRepository.getBucketName() + "/" + bucketKey + "...");
            if (!doNotUpload) {
                s3Session.putObject(new PutObjectRequest(targetBucket, bucketKey, toUpload));
            }
        }
    }
View Full Code Here

            getLog().info("Per configuration, we will NOT perform any remote operations on the S3 repository.");
            logPrefix = "SKIPPING: ";
        }
        final S3RepositoryPath targetRepository = context.getS3TargetRepositoryPath();
        final String targetBucket = targetRepository.getBucketName();
        AmazonS3 s3Session = context.getS3Session();
        File directoryToUpload = uploadMetadataOnly
                ? context.getLocalYumRepo().repoDataDirectory() // only the repodata directory
                : stagingDirectory; // the entire staging directory/bucket
        if (!allowCreateRepository && !context.getLocalYumRepo().isRepoDataExists()) {
            throw new MojoExecutionException("refusing to create new repo: " + targetRepository +
                " (use s3repo.allowCreateRepository = true to force)");
        }
        for (File toUpload : ExtraIOUtils.listAllFiles(directoryToUpload)) {
            final String bucketKey = localFileToTargetS3BucketKey(toUpload, context);
            getLog().info(logPrefix + "Uploading: " + toUpload.getName() + " => s3://" + targetRepository.getBucketName() + "/" + bucketKey + "...");
            if (!doNotUpload) {
                s3Session.putObject(new PutObjectRequest(targetBucket, bucketKey, toUpload));
            }
        }
        if (uploadMetadataOnly && !context.sourceAndTargetRepositoryAreSame()) {
            // we just uploaded metadata but there are files in the source repository
            // that don't exist in the target, so we upload those here.
            for (File toUpload : ExtraIOUtils.listAllFiles(stagingDirectory)) {
                if (!context.getFilesFromTargetRepo().contains(toUpload)) {
                    // upload if it's not already in the target repo.
                    final String bucketKey = localFileToTargetS3BucketKey(toUpload, context);
                    getLog().info(logPrefix + "Uploading: " + toUpload.getName()
                        + " => s3://" + targetRepository.getBucketName() + "/" + bucketKey + "...");
                    if (!doNotUpload) {
                        s3Session.putObject(new PutObjectRequest(targetBucket, bucketKey, toUpload));
                    }
                }
            }
        }
        // delete any excluded files remotely from the TARGET only.
        for (String repoRelativePath : context.getExcludedFilesToDeleteFromTarget()) {
            final String bucketKey = toBucketKey(targetRepository, repoRelativePath);
            getLog().info(logPrefix + "Deleting: "
                + "s3://" + targetRepository.getBucketName() + "/" + bucketKey + " (excluded file)");
            if (!doNotUpload) {
                context.getS3Session().deleteObject(targetBucket, bucketKey);
            }
        }
        // and finally, delete any remote bucket keys we wish to remove (e.g., old snaphots)...from the TARGET only.
        for (SnapshotDescription toDelete : context.getSnapshotsToDeleteRemotely()) {
            getLog().info(logPrefix + "Deleting: "
                + "s3://" + targetRepository.getBucketName() + "/" + toDelete.getBucketKey() + " (excluded file)");
            getLog().info(logPrefix + "Deleting: " + toDelete + " (old snapshot)");
            if (!doNotUpload) {
                context.getS3Session().deleteObject(targetBucket, toDelete.getBucketKey());
            }
        }
        // rename any snapshots...in TARGET only.
        for (RemoteSnapshotRename toRename : context.getSnapshotsToRenameRemotely()) {
            final String sourceBucketKey = toRename.getSource().getBucketKey();
            final String targetBucketKey = toRename.getNewBucketKey();
            getLog().info(logPrefix + "Renaming: "
                + "s3://" + targetRepository.getBucketName() + "/" + sourceBucketKey
                + " => s3://" + targetRepository.getBucketName() + "/" + targetBucketKey);
            if (!doNotUpload) {
                s3Session.copyObject(targetBucket, sourceBucketKey, targetBucket, targetBucketKey);
                s3Session.deleteObject(targetBucket, sourceBucketKey);
            }
        }
    }
View Full Code Here

        assert isNotBlank(bucketName);
        assert isNotBlank(key);
        assert targetDirectory != null && targetDirectory.isDirectory();
        assert namingStrategy != null;

        final AmazonS3 connection = acquireClient(clientOptions);

        File tempFile = null;
        try {

            tempFile = createTempFile(
                    join("-", targetDirectory.getName(), currentTimeMillis(),
                            "part"), "tmp", targetDirectory);
            tempFile.deleteOnExit();

            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(format(
                        "Downloading object %1$s from bucket %2$s to temp file %3$s",
                        key, bucketName, tempFile.getName()));
            }

            try {
                connection.getObject(new GetObjectRequest(bucketName, key), tempFile);
            } catch (AmazonClientException ex) {
                // hack to handle different ETAG format generated from RiakCS for multi-part uploaded object
                String msg = ex.getMessage();
                if (!msg.contains("verify integrity")){
                    throw ex;
View Full Code Here

        assert clientOptions != null;
        assert isNotBlank(bucketName);
        assert isNotBlank(sourcePath);
        assert targetDirectory != null;

        final AmazonS3 connection = acquireClient(clientOptions);

        // List the objects in the source directory on S3
        final List<S3ObjectSummary> objectSummaries = listDirectory(bucketName,
                sourcePath, connection);
        final List<File> files = new ArrayList<File>();
View Full Code Here

            final String bucketName, final String sourcePath){
        assert clientOptions != null;
        assert isNotBlank(bucketName);
        assert isNotBlank(sourcePath);

        final AmazonS3 connection = acquireClient(clientOptions);

        // List the objects in the source directory on S3
        return listDirectory(bucketName, sourcePath, connection);
    }
View Full Code Here

        // Skip spinning up an S3 connection when no files will be sent ...
        if (isEmpty(files)) {
            return;
        }

        final AmazonS3 client = acquireClient(clientOptions);

        // Send the files to S3 using the passed ObjectNaming strategy to
        // determine the key ...
        for (final File file : files) {
            final String key = namingStrategy.determineKey(file);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(format(
                        "Putting file %1$s into bucket %2$s with key %3$s.",
                        file.getAbsolutePath(), bucketName, key));
            }
            client.putObject(bucketName, key, file);
        }

    }
View Full Code Here

        assert clientOptions != null;
        assert isNotBlank(bucketName);
        assert isNotBlank(key);

        final AmazonS3 client = acquireClient(clientOptions);

        client.deleteObject(bucketName, key);

    }
View Full Code Here

        assert clientOptions != null;
        assert isNotBlank(bucketName);
        assert isNotBlank(directoryName);

        final AmazonS3 client = acquireClient(clientOptions);

        final List<S3ObjectSummary> objects = listDirectory(bucketName,
                directoryName, client);

        for (final S3ObjectSummary object : objects) {

            client.deleteObject(bucketName, object.getKey());

        }

        client.deleteObject(bucketName, directoryName);

    }
View Full Code Here

        assert clientOptions != null;
        assert isNotBlank(bucketName);

        try {

            final AmazonS3 client = acquireClient(clientOptions);

            final String fileContent = "testing put and delete";
            final InputStream inputStream = new ByteArrayInputStream(
                    fileContent.getBytes());
            final String key = UUID.randomUUID().toString() + ".txt";

            final ObjectMetadata metadata = new ObjectMetadata();
            metadata.setContentLength(fileContent.length());

            client.putObject(bucketName, key, inputStream, metadata);
            client.deleteObject(bucketName, key);

            return true;

        } catch (AmazonClientException e) {
View Full Code Here

TOP

Related Classes of com.amazonaws.services.s3.AmazonS3

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.