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:S3TransferProgressSample.java

License:Open Source License

public static void main(String[] args) throws Exception {
    /*//from  w  w  w  .j  a  v a2s.  c  o  m
     * The ProfileCredentialsProvider will return your [default]
     * credential profile by reading from the credentials file located at
     * (/Users/zunzunwang/.aws/credentials).
     *
     * TransferManager manages a pool of threads, so we create a
     * single instance and share it throughout our application.
     */
    try {
        credentials = new ProfileCredentialsProvider("default").getCredentials();
    } catch (Exception e) {
        throw new AmazonClientException("Cannot load the credentials from the credential profiles file. "
                + "Please make sure that your credentials file is at the correct "
                + "location (/Users/zunzunwang/.aws/credentials), and is in valid format.", e);
    }

    AmazonS3 s3 = new AmazonS3Client(credentials);
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    s3.setRegion(usWest2);
    tx = new TransferManager(s3);

    bucketName = "s3-upload-sdk-sample-" + credentials.getAWSAccessKeyId().toLowerCase();

    new S3TransferProgressSample();
}

From source file:alluxio.underfs.s3a.S3AUnderFileSystem.java

License:Apache License

/**
 * Constructs a new instance of {@link S3AUnderFileSystem}.
 *
 * @param uri the {@link AlluxioURI} for this UFS
 *///from   w  w  w  . j  a  v a 2  s .  com
public S3AUnderFileSystem(AlluxioURI uri) {
    super(uri);
    mBucketName = uri.getHost();
    mBucketPrefix = PathUtils.normalizePath(Constants.HEADER_S3A + mBucketName, PATH_SEPARATOR);

    // Set the aws credential system properties based on Alluxio properties, if they are set
    if (Configuration.containsKey(PropertyKey.S3A_ACCESS_KEY)) {
        System.setProperty(SDKGlobalConfiguration.ACCESS_KEY_SYSTEM_PROPERTY,
                Configuration.get(PropertyKey.S3A_ACCESS_KEY));
    }
    if (Configuration.containsKey(PropertyKey.S3A_SECRET_KEY)) {
        System.setProperty(SDKGlobalConfiguration.SECRET_KEY_SYSTEM_PROPERTY,
                Configuration.get(PropertyKey.S3A_SECRET_KEY));
    }

    // Checks, in order, env variables, system properties, profile file, and instance profile
    AWSCredentialsProvider credentials = new AWSCredentialsProviderChain(
            new DefaultAWSCredentialsProviderChain());

    // Set the client configuration based on Alluxio configuration values
    ClientConfiguration clientConf = new ClientConfiguration();

    // Socket timeout
    clientConf.setSocketTimeout(Configuration.getInt(PropertyKey.UNDERFS_S3A_SOCKET_TIMEOUT_MS));

    // HTTP protocol
    if (Configuration.getBoolean(PropertyKey.UNDERFS_S3A_SECURE_HTTP_ENABLED)) {
        clientConf.setProtocol(Protocol.HTTPS);
    } else {
        clientConf.setProtocol(Protocol.HTTP);
    }

    // Proxy host
    if (Configuration.containsKey(PropertyKey.UNDERFS_S3_PROXY_HOST)) {
        clientConf.setProxyHost(Configuration.get(PropertyKey.UNDERFS_S3_PROXY_HOST));
    }

    // Proxy port
    if (Configuration.containsKey(PropertyKey.UNDERFS_S3_PROXY_PORT)) {
        clientConf.setProxyPort(Configuration.getInt(PropertyKey.UNDERFS_S3_PROXY_PORT));
    }

    mClient = new AmazonS3Client(credentials, clientConf);
    if (Configuration.containsKey(PropertyKey.UNDERFS_S3_ENDPOINT)) {
        mClient.setEndpoint(Configuration.get(PropertyKey.UNDERFS_S3_ENDPOINT));
    }
    mManager = new TransferManager(mClient);

    TransferManagerConfiguration transferConf = new TransferManagerConfiguration();
    transferConf.setMultipartCopyThreshold(MULTIPART_COPY_THRESHOLD);
    mManager.setConfiguration(transferConf);

    mAccountOwnerId = mClient.getS3AccountOwner().getId();
    // Gets the owner from user-defined static mapping from S3 canonical user id  to Alluxio
    // user name.
    String owner = CommonUtils.getValueFromStaticMapping(
            Configuration.get(PropertyKey.UNDERFS_S3_OWNER_ID_TO_USERNAME_MAPPING), mAccountOwnerId);
    // If there is no user-defined mapping, use the display name.
    if (owner == null) {
        owner = mClient.getS3AccountOwner().getDisplayName();
    }
    mAccountOwner = owner == null ? mAccountOwnerId : owner;

    AccessControlList acl = mClient.getBucketAcl(mBucketName);
    mBucketMode = S3AUtils.translateBucketAcl(acl, mAccountOwnerId);
}

From source file:aws.sample.S3TransferProgressSample.java

License:Open Source License

public static void main(String[] args) throws Exception {
    credentials = new PropertiesCredentials(
            S3TransferProgressSample.class.getResourceAsStream("AwsCredentials.properties"));

    // TransferManager manages a pool of threads, so we create a
    // single instance and share it throughout our application.
    tx = new TransferManager(credentials);

    bucketName = "s3-upload-sdk-sample-" + credentials.getAWSAccessKeyId().toLowerCase();

    new S3TransferProgressSample();
}

From source file:be.ugent.intec.halvade.uploader.AWSUploader.java

License:Open Source License

public AWSUploader(String existingBucketName, boolean sse, String profile) throws IOException {
    SSE = sse;//from  ww w  .j  av a2s.c o m
    this.profile = profile;
    this.existingBucketName = existingBucketName;
    AWSCredentials c;
    try {
        DefaultAWSCredentialsProviderChain prov = new DefaultAWSCredentialsProviderChain();
        c = prov.getCredentials();
    } catch (AmazonClientException ex) {
        // read from ~/.aws/credentials
        String access = null;
        String secret = null;
        try (BufferedReader br = new BufferedReader(
                new FileReader(System.getProperty("user.home") + "/.aws/credentials"))) {
            String line;
            while ((line = br.readLine()) != null && !line.contains("[" + this.profile + "]")) {
            }
            line = br.readLine();
            if (line != null)
                access = line.split(" = ")[1];
            line = br.readLine();
            if (line != null)
                secret = line.split(" = ")[1];
        }
        c = new BasicAWSCredentials(access, secret);
    }
    this.tm = new TransferManager(c);
}

From source file:be.ugent.intec.halvade.uploader.CopyOfAWSUploader.java

License:Open Source License

public CopyOfAWSUploader(String existingBucketName) throws IOException {
    this.existingBucketName = existingBucketName;
    AWSCredentials c;/*  w ww .ja  v  a2s .com*/
    try {
        DefaultAWSCredentialsProviderChain prov = new DefaultAWSCredentialsProviderChain();
        c = prov.getCredentials();
    } catch (AmazonClientException ex) {
        // read from ~/.aws/credentials
        String access = null;
        String secret = null;
        try (BufferedReader br = new BufferedReader(
                new FileReader(System.getProperty("user.home") + "/.aws/credentials"))) {
            String line;
            while ((line = br.readLine()) != null && !line.contains("[default]")) {
            }
            line = br.readLine();
            if (line != null)
                access = line.split(" = ")[1];
            line = br.readLine();
            if (line != null)
                secret = line.split(" = ")[1];
        }
        c = new BasicAWSCredentials(access, secret);
    }
    this.tm = new TransferManager(c);
}

From source file:beanstalk.BeanstalkDeploy.java

License:Apache License

public boolean deploy(String war, String AWSKeyId, String AWSSecretKey, String applicationname,
        String applicationversion, String environment, String bucket, String host) {//throws Exception {

    boolean ret = false;
    //  credentials = new PropertiesCredentials(BeanstalkDeploy.class.getResourceAsStream("AwsCredentials.properties"))
    BasicAWSCredentials basic_credentials = new BasicAWSCredentials(AWSKeyId, AWSSecretKey);

    // TransferManager manages a pool of threads, so we create a
    // single instance and share it throughout our application.
    tx = new TransferManager(basic_credentials);

    appname = applicationname;//from ww  w .  j ava2s  .  co  m
    appversion = applicationversion;
    accessKeyId = AWSKeyId;
    secretAccessKey = AWSSecretKey;
    bucketName = bucket;
    environment_name = environment;
    host_name = host;

    //STEP 1: UPLOAD

    //STEP 2: CREATE APP VERSION

    //STEP 3: DEPLOY

    //    if(war.equalsIgnoreCase("")){
    //    NoGUI ngui= new NoGUI();

    //    ngui.performDeploydeploy("/home/jled/NetBeansProjects/WebApplication1/dist/WebApplication1.war",accessKeyId , secretAccessKey, appname, appversion,
    // environment_name,bucketName, host_name);

    //   }

    //TODO
    //take war file path from args
    //local_filename_and_path ="../sdsdsds/sts.war";

    /// new BeanstalkDeploy(args);

    return ret;
}

From source file:beanstalk.BeanstalkDeployGUI.java

License:Apache License

public boolean deploy(String war, String AWSKeyId, String AWSSecretKey, String applicationname,
        String applicationversion, String environment, String bucket, String host) {//throws Exception {

    boolean ret = false;
    //  credentials = new PropertiesCredentials(BeanstalkDeploy.class.getResourceAsStream("AwsCredentials.properties"))
    BasicAWSCredentials basic_credentials = new BasicAWSCredentials(AWSKeyId, AWSSecretKey);

    // TransferManager manages a pool of threads, so we create a
    // single instance and share it throughout our application.
    tx = new TransferManager(basic_credentials);

    appname = applicationname;/*from  www. j  av a  2 s  .c o  m*/
    appversion = applicationversion;
    accessKeyId = AWSKeyId;
    secretAccessKey = AWSSecretKey;
    bucketName = bucket;
    environment_name = environment;
    host_name = host;

    //STEP 1: UPLOAD

    //STEP 2: CREATE APP VERSION

    //STEP 3: DEPLOY

    //TODO
    //take war file path from args
    //local_filename_and_path ="../sdsdsds/sts.war";

    /// new BeanstalkDeploy(args);

    return ret;
}

From source file:beanstalk.BeanstalkFirstDeploymentNoGUI.java

License:Apache License

public boolean deploy(String war, String AWSKeyId, String AWSSecretKey, String applicationname,
        String applicationversion, String environment, String bucket, String host)
        throws BeanstalkAdapterException {

    boolean ret = false;
    //  credentials = new PropertiesCredentials(BeanstalkDeploy.class.getResourceAsStream("AwsCredentials.properties"))
    BasicAWSCredentials basic_credentials = new BasicAWSCredentials(AWSKeyId, AWSSecretKey);

    // TransferManager manages a pool of threads, so we create a
    // single instance and share it throughout our application.
    tx = new TransferManager(basic_credentials);

    appname = applicationname;//w  w  w  .  j  a v a  2  s  .  c  o m
    appversion = applicationversion;
    accessKeyId = AWSKeyId;
    secretAccessKey = AWSSecretKey;
    bucketName = bucket;
    environment_name = environment;
    host_name = host;
    war_name_on_s3 = war;
    //STEP 1: UPLOAD

    //STEP 2: CREATE APP VERSION

    //STEP 3: DEPLOY

    //TODO
    //take war file path from args
    //local_filename_and_path ="../sdsdsds/sts.war";

    actionPerformed(war_name_on_s3, accessKeyId, secretAccessKey, appname, appversion, environment_name,
            bucketName, host_name);

    return ret;
}

From source file:biz.neustar.webmetrics.plugins.neustar_s3_maven_plugin.S3UploadMojo.java

License:Apache License

/** */
private boolean upload(AmazonS3 s3, String bucketName, File sourceFile, String targetPath)
        throws MojoExecutionException {

    TransferManager mgr = new TransferManager(s3);
    Transfer transfer = null;/*from  w ww .j  a  v a 2s  . c o  m*/
    transfer = mgr.upload(bucketName, targetPath, sourceFile);

    try {
        transfer.waitForCompletion();
        getLog().info("Transferred " + transfer.getProgress().getBytesTransfered() + " bytes.");
    } catch (AmazonServiceException e) {
        e.printStackTrace();
        return false;
    } catch (AmazonClientException e) {
        e.printStackTrace();
        return false;
    } catch (InterruptedException e) {
        e.printStackTrace();
        return false;
    }

    return true;
}

From source file:br.com.ingenieux.mojo.aws.util.BeanstalkerS3Client.java

License:Apache License

protected void init(Region region) {
    transferManager = new TransferManager(this);
    TransferManagerConfiguration configuration = new TransferManagerConfiguration();
    configuration.setMultipartUploadThreshold(100 * Constants.KB);
    transferManager.setConfiguration(configuration);
    this.setRegion(region);
}