Example usage for com.amazonaws.services.s3.transfer TransferManager TransferManager

List of usage examples for com.amazonaws.services.s3.transfer TransferManager TransferManager

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.transfer TransferManager TransferManager.

Prototype

protected TransferManager(TransferManagerBuilder builder) 

Source Link

Document

Constructor for use by classes that need to extend the TransferManager.

Usage

From source file:com.ipcglobal.fredimportaws.TsvsToRedshift.java

License:Apache License

/**
 * Instantiates a new tsvs to redshift./*from ww  w .  j  a v a  2s .co m*/
 *
 * @param pathNameProperties the path name properties
 * @throws Exception the exception
 */
public TsvsToRedshift(String pathNameProperties) throws Exception {
    this.properties = new Properties();
    properties.load(new FileInputStream(pathNameProperties));
    String credentialsProfileName = this.properties.getProperty("credentialsProfileName").trim();
    this.awsBucketName = this.properties.getProperty("awsBucketName").trim();
    this.awsBucketTsvPrefix = this.properties.getProperty("awsBucketTsvPrefix").trim();

    String outputPath = FredUtils.readfixPath("outputPath", properties);
    String outputSubdirTableTsvFiles = FredUtils.readfixPath("outputSubdirTableTsvFiles", properties);
    this.pathTableTsvFiles = outputPath + outputSubdirTableTsvFiles;

    if (credentialsProfileName == null)
        this.credentialsProvider = AwsUtils.initCredentials();
    else
        this.credentialsProvider = AwsUtils.initProfileCredentialsProvider(credentialsProfileName);

    this.s3Client = new AmazonS3Client(credentialsProvider);
    this.transferManager = new TransferManager(credentialsProvider);
    this.stsClient = new AWSSecurityTokenServiceClient(credentialsProvider);
}

From source file:com.mesosphere.dcos.cassandra.executor.backup.S3StorageDriver.java

License:Apache License

private TransferManager getS3TransferManager(BackupRestoreContext ctx) {
    final String accessKey = ctx.getAccountId();
    final String secretKey = ctx.getSecretKey();

    final BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey);
    TransferManager tx = new TransferManager(basicAWSCredentials);
    return tx;/*from  w  ww .  jav a 2  s . co m*/
}

From source file:com.mweagle.tereus.aws.S3Resource.java

License:Open Source License

public Optional<String> upload() {
    try {/*from w  w  w.j  a va2 s.  c  o  m*/
        DefaultAWSCredentialsProviderChain credentialProviderChain = new DefaultAWSCredentialsProviderChain();
        final TransferManager transferManager = new TransferManager(credentialProviderChain.getCredentials());

        final ObjectMetadata metadata = new ObjectMetadata();
        if (this.inputStreamLength.isPresent()) {
            metadata.setContentLength(this.inputStreamLength.get());
        }
        final PutObjectRequest uploadRequest = new PutObjectRequest(bucketName, keyName, this.inputStream,
                metadata);
        final Upload templateUpload = transferManager.upload(uploadRequest);

        templateUpload.waitForUploadResult();
        this.resourceURL = Optional.of(getS3Path());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    return this.resourceURL;
}

From source file:com.netflix.hollow.example.producer.infrastructure.S3Publisher.java

License:Apache License

public S3Publisher(AWSCredentials credentials, String bucketName, String blobNamespace) {
    this.s3 = new AmazonS3Client(credentials);
    this.s3TransferManager = new TransferManager(s3);
    this.bucketName = bucketName;
    this.blobNamespace = blobNamespace;
    this.snapshotIndex = initializeSnapshotIndex();
}

From source file:com.nike.cerberus.operation.dashboard.PublishDashboardOperation.java

License:Apache License

@Inject
public PublishDashboardOperation(final ConfigStore configStore, final AmazonS3 amazonS3) {
    this.configStore = configStore;
    this.transferManager = new TransferManager(amazonS3);
    this.amazonS3 = amazonS3;
}

From source file:com.nike.cerberus.operation.gateway.PublishLambdaOperation.java

License:Apache License

@Inject
public PublishLambdaOperation(final ConfigStore configStore, final AmazonS3 amazonS3) {
    this.configStore = configStore;
    this.transferManager = new TransferManager(amazonS3);
    this.amazonS3 = amazonS3;
}

From source file:com.pinterest.secor.uploader.S3UploadManager.java

License:Apache License

public S3UploadManager(SecorConfig config) {
    super(config);

    final String accessKey = mConfig.getAwsAccessKey();
    final String secretKey = mConfig.getAwsSecretKey();
    final String endpoint = mConfig.getAwsEndpoint();
    final String region = mConfig.getAwsRegion();
    final String awsRole = mConfig.getAwsRole();

    s3Path = mConfig.getS3Path();

    AmazonS3 client;//w ww .  j  ava2s . c om
    AWSCredentialsProvider provider;

    ClientConfiguration clientConfiguration = new ClientConfiguration();
    boolean isHttpProxyEnabled = mConfig.getAwsProxyEnabled();

    //proxy settings
    if (isHttpProxyEnabled) {
        LOG.info("Http Proxy Enabled for S3UploadManager");
        String httpProxyHost = mConfig.getAwsProxyHttpHost();
        int httpProxyPort = mConfig.getAwsProxyHttpPort();
        clientConfiguration.setProxyHost(httpProxyHost);
        clientConfiguration.setProxyPort(httpProxyPort);
    }

    if (accessKey.isEmpty() || secretKey.isEmpty()) {
        provider = new DefaultAWSCredentialsProviderChain();
    } else {
        provider = new AWSCredentialsProvider() {
            public AWSCredentials getCredentials() {
                return new BasicAWSCredentials(accessKey, secretKey);
            }

            public void refresh() {
            }
        };
    }

    if (!awsRole.isEmpty()) {
        provider = new STSAssumeRoleSessionCredentialsProvider(provider, awsRole, "secor");
    }

    client = new AmazonS3Client(provider, clientConfiguration);

    if (!endpoint.isEmpty()) {
        client.setEndpoint(endpoint);
    } else if (!region.isEmpty()) {
        client.setRegion(Region.getRegion(Regions.fromName(region)));
    }

    mManager = new TransferManager(client);
}

From source file:com.projectlaver.service.ListingService.java

License:Open Source License

/**
 * Public methods//from   ww  w .  j  a va 2 s  .  com
 */

@Transactional(readOnly = false)
public Listing create(Listing listing) throws Exception {

    // set the expiration for one year from now if unset
    if (listing.getExpires() == null) {
        listing.setExpires(this.addDays(new Date(), 365));
    }

    // merge the user (reattach to DB)
    User user = listing.getSeller();
    User mergedUser = this.em.merge(user);
    listing.setSeller(mergedUser);

    if (listing.getImageAsFile() != null) {
        // upload the image preview to the public S3 bucket
        AWSCredentials myCredentials = new BasicAWSCredentials(this.s3accessKey, this.s3secretKey);
        TransferManager tx = new TransferManager(myCredentials);
        Upload myUpload = tx.upload(this.s3publicBucketName, listing.getImageFilename(),
                listing.getImageAsFile());
        myUpload.waitForCompletion();
    }

    if (listing.getContentFiles() != null && listing.getContentFiles().size() > 0) {

        Set<ContentFile> contentFiles = listing.getContentFiles();

        AWSCredentials myCredentials = new BasicAWSCredentials(this.s3accessKey, this.s3secretKey);
        TransferManager tx = new TransferManager(myCredentials);

        for (ContentFile file : contentFiles) {
            // upload the digital content to the private S3 bucket
            Upload myUpload = tx.upload(this.s3privateBucketName, file.getContentFilename(),
                    file.getDigitalContentAsFile());
            myUpload.waitForCompletion();
        }
    }

    return this.listingRepository.save(listing);
}

From source file:com.projectlaver.util.VoucherService.java

License:Open Source License

/**
 * Uploads the pdf file to the private S3 bucket.
 * /*from  w w  w .  j  av  a  2  s.c  o m*/
 * @param pdfFilename
 * @param pdf
 */
void savePdf(String pdfFilename, File pdf) {
    AWSCredentials myCredentials = new BasicAWSCredentials(this.s3accessKey, this.s3secretKey);
    TransferManager tx = new TransferManager(myCredentials);
    Upload myUpload = tx.upload(this.s3privateBucketName, pdfFilename, pdf);

    try {
        myUpload.waitForCompletion();
    } catch (Exception e) {
        this.logger.error(String.format(
                "Exception while trying to upload to S3 the PDF using the temp file with path: %s",
                pdf.getPath()), e);
        throw new RuntimeException("Unable to upload the PDF file to S3.", e);
    }
}

From source file:com.proofpoint.event.collector.MainModule.java

License:Apache License

@Provides
@Singleton
private TransferManager provideAmazonS3TransferManager(AWSCredentials credentials) {
    return new TransferManager(credentials);
}