Example usage for com.amazonaws.services.glacier AmazonGlacierClient AmazonGlacierClient

List of usage examples for com.amazonaws.services.glacier AmazonGlacierClient AmazonGlacierClient

Introduction

In this page you can find the example usage for com.amazonaws.services.glacier AmazonGlacierClient AmazonGlacierClient.

Prototype

AmazonGlacierClient(AwsSyncClientParams clientParams) 

Source Link

Document

Constructs a new client to invoke service methods on Amazon Glacier using the specified parameters.

Usage

From source file:ai.serotonin.backup.Base.java

License:Mozilla Public License

private void createGlacierClient() {
    final String accessKey = configRoot.get("glacier").get("accessKey").asText();
    final String secretKey = configRoot.get("glacier").get("secretKey").asText();
    final String endpoint = configRoot.get("glacier").get("endpoint").asText();
    credentials = new BasicAWSCredentials(accessKey, secretKey);
    client = new AmazonGlacierClient(credentials) //
            .withEndpoint(endpoint);//  w w w .  ja  va  2 s.  com
}

From source file:baldrickv.s3streamingtool.S3StreamingTool.java

License:Open Source License

public static void main(String args[]) throws Exception {
    BasicParser p = new BasicParser();

    Options o = getOptions();//w  w  w . j  a v a  2 s .  com

    CommandLine cl = p.parse(o, args);

    if (cl.hasOption('h')) {
        HelpFormatter hf = new HelpFormatter();
        hf.setWidth(80);

        StringBuilder sb = new StringBuilder();

        sb.append("\n");
        sb.append("Upload:\n");
        sb.append("    -u -r creds -s 50M -b my_bucket -f hda1.dump -t 10\n");
        sb.append("Download:\n");
        sb.append("    -d -r creds -s 50M -b my_bucket -f hda1.dump -t 10\n");
        sb.append("Upload encrypted:\n");
        sb.append("    -u -r creds -z -k secret_key -s 50M -b my_bucket -f hda1.dump -t 10\n");
        sb.append("Download encrypted:\n");
        sb.append("    -d -r creds -z -k secret_key -s 50M -b my_bucket -f hda1.dump -t 10\n");
        sb.append("Cleanup in-progress multipart uploads\n");
        sb.append("    -c -r creds -b my_bucket\n");
        System.out.println(sb.toString());

        hf.printHelp("See above", o);

        return;
    }

    int n = 0;
    if (cl.hasOption('d'))
        n++;
    if (cl.hasOption('u'))
        n++;
    if (cl.hasOption('c'))
        n++;
    if (cl.hasOption('m'))
        n++;

    if (n != 1) {
        System.err.println("Must specify at exactly one of -d, -u, -c or -m");
        System.exit(-1);
    }

    if (cl.hasOption('m')) {
        //InputStream in = new java.io.BufferedInputStream(System.in,1024*1024*2);
        InputStream in = System.in;
        System.out.println(TreeHashGenerator.calculateTreeHash(in));
        return;
    }

    require(cl, 'b');

    if (cl.hasOption('d') || cl.hasOption('u')) {
        require(cl, 'f');
    }
    if (cl.hasOption('z')) {
        require(cl, 'k');
    }

    AWSCredentials creds = null;

    if (cl.hasOption('r')) {
        creds = Utils.loadAWSCredentails(cl.getOptionValue('r'));
    } else {
        if (cl.hasOption('i') && cl.hasOption('e')) {
            creds = new BasicAWSCredentials(cl.getOptionValue('i'), cl.getOptionValue('e'));
        } else {

            System.out.println("Must specify either credential file (-r) or AWS key ID and secret (-i and -e)");
            System.exit(-1);
        }
    }

    S3StreamConfig config = new S3StreamConfig();
    config.setEncryption(false);
    if (cl.hasOption('z')) {
        config.setEncryption(true);
        config.setSecretKey(Utils.loadSecretKey(cl.getOptionValue("k")));
    }

    if (cl.hasOption("encryption-mode")) {
        config.setEncryptionMode(cl.getOptionValue("encryption-mode"));
    }
    config.setS3Bucket(cl.getOptionValue("bucket"));
    if (cl.hasOption("file")) {
        config.setS3File(cl.getOptionValue("file"));
    }

    if (cl.hasOption("threads")) {
        config.setIOThreads(Integer.parseInt(cl.getOptionValue("threads")));
    }

    if (cl.hasOption("blocksize")) {
        String s = cl.getOptionValue("blocksize");
        s = s.toUpperCase();
        int multi = 1;

        int end = 0;
        while ((end < s.length()) && (s.charAt(end) >= '0') && (s.charAt(end) <= '9')) {
            end++;
        }
        int size = Integer.parseInt(s.substring(0, end));

        if (end < s.length()) {
            String m = s.substring(end);
            if (m.equals("K"))
                multi = 1024;
            else if (m.equals("M"))
                multi = 1048576;
            else if (m.equals("G"))
                multi = 1024 * 1024 * 1024;
            else if (m.equals("KB"))
                multi = 1024;
            else if (m.equals("MB"))
                multi = 1048576;
            else if (m.equals("GB"))
                multi = 1024 * 1024 * 1024;
            else {
                System.out.println("Unknown suffix on block size.  Only K,M and G understood.");
                System.exit(-1);
            }

        }
        size *= multi;
        config.setBlockSize(size);
    }

    Logger.getLogger("").setLevel(Level.FINE);

    S3StreamingDownload.log.setLevel(Level.FINE);
    S3StreamingUpload.log.setLevel(Level.FINE);

    config.setS3Client(new AmazonS3Client(creds));
    config.setGlacierClient(new AmazonGlacierClient(creds));
    config.getGlacierClient().setEndpoint("glacier.us-west-2.amazonaws.com");

    if (cl.hasOption("glacier")) {
        config.setGlacier(true);
        config.setStorageInterface(new StorageGlacier(config.getGlacierClient()));
    } else {
        config.setStorageInterface(new StorageS3(config.getS3Client()));
    }
    if (cl.hasOption("bwlimit")) {
        config.setMaxBytesPerSecond(Double.parseDouble(cl.getOptionValue("bwlimit")));

    }

    if (cl.hasOption('c')) {
        if (config.getGlacier()) {
            GlacierCleanupMultipart.cleanup(config);
        } else {
            S3CleanupMultipart.cleanup(config);
        }
        return;
    }
    if (cl.hasOption('d')) {
        config.setOutputStream(System.out);
        S3StreamingDownload.download(config);
        return;
    }
    if (cl.hasOption('u')) {
        config.setInputStream(System.in);
        S3StreamingUpload.upload(config);
        return;
    }

}

From source file:co.upet.extensions.glacierbkuploader.glacier.GlacierManager.java

@Inject
public GlacierManager(Configuration conf) {
    BasicAWSCredentials awsCreds = new BasicAWSCredentials(conf.awsAccessKey(), conf.awsSecretKey());
    glacierClient = new AmazonGlacierClient(awsCreds);
    glacierClient.setEndpoint(conf.glacierEndPoint());
    transferManager = new ArchiveTransferManager(glacierClient, awsCreds);
}

From source file:com.brianmcmichael.sagu.SAGU.java

License:Open Source License

private AmazonGlacierClient makeClient(String accessorString, String secretiveString, int regionIndex) {
    BasicAWSCredentials credentials = new BasicAWSCredentials(accessorString, secretiveString);
    client = new AmazonGlacierClient(credentials);
    client.setEndpoint(Endpoint.getByIndex(regionIndex).getGlacierEndpoint());
    return client;
}

From source file:com.brianmcmichael.sagu.SimpleGlacierUploader.java

License:Open Source License

public AmazonGlacierClient makeClient(String accessorString, String secretiveString, int regionIndex) {
    BasicAWSCredentials credentials = new BasicAWSCredentials(accessorString, secretiveString);
    client = new AmazonGlacierClient(credentials);
    client.setEndpoint(Endpoint.getByIndex(regionIndex).getGlacierEndpoint());
    return client;
}

From source file:com.brianmcmichael.SimpleGlacierUploader.SimpleGlacierUploader.java

License:Open Source License

public AmazonGlacierClient makeClient(String accessorString, String secretiveString, int region) {
    // AmazonGlacierClient client;
    BasicAWSCredentials credentials = new BasicAWSCredentials(accessorString, secretiveString);
    client = new AmazonGlacierClient(credentials);
    // int locInt = locationChoice.getSelectedIndex();
    Endpoints ep = new Endpoints(region);
    // String endpointUrl = ep.Endpoint(region);
    client.setEndpoint(ep.Endpoint());

    return client;
}

From source file:com.connexience.server.model.archive.glacier.SetupUtils.java

License:Open Source License

public static void setupVault(String accessKey, String secretKey, String domainName, String vaultName,
        String topicARN) {//  www  . ja  va 2 s. com
    try {
        AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);

        AmazonGlacierClient amazonGlacierClient = new AmazonGlacierClient(awsCredentials);
        amazonGlacierClient.setEndpoint("https://glacier." + domainName + ".amazonaws.com/");

        CreateVaultRequest createVaultRequest = new CreateVaultRequest();
        createVaultRequest.withVaultName(vaultName);

        CreateVaultResult createVaultResult = amazonGlacierClient.createVault(createVaultRequest);
        if (createVaultResult != null) {
            VaultNotificationConfig vaultNotificationConfig = new VaultNotificationConfig();
            vaultNotificationConfig.withSNSTopic(topicARN);
            vaultNotificationConfig.withEvents("ArchiveRetrievalCompleted", "InventoryRetrievalCompleted");

            SetVaultNotificationsRequest setVaultNotificationsRequest = new SetVaultNotificationsRequest();
            setVaultNotificationsRequest.withVaultName(vaultName);
            setVaultNotificationsRequest.withVaultNotificationConfig(vaultNotificationConfig);

            amazonGlacierClient.setVaultNotifications(setVaultNotificationsRequest);
        } else
            logger.warn("Unable to create vault: \"" + vaultName + "\"");

        amazonGlacierClient.shutdown();
    } catch (AmazonServiceException amazonServiceException) {
        logger.warn("AmazonServiceException: " + amazonServiceException);
        logger.debug(amazonServiceException);
    } catch (IllegalArgumentException illegalArgumentException) {
        logger.warn("IllegalArgumentException: " + illegalArgumentException);
        logger.debug(illegalArgumentException);
    } catch (AmazonClientException amazonClientException) {
        logger.warn("AmazonClientException: " + amazonClientException);
        logger.debug(amazonClientException);
    } catch (Throwable throwable) {
        logger.warn("Throwable: " + throwable);
        logger.debug(throwable);
    }
}

From source file:com.github.abhinavmishra14.aws.glacier.service.impl.GlacierArchiveServiceImpl.java

License:Open Source License

/**
 * The Constructor.<br/>//from  w  ww  .j a  va 2s .c o m
 * This Constructor will return glacier client using accessKey and secretKey.<br/>
 * Additionally it will set the given endPoint for performing upload operation over vault.<br/>
 * Default endpoint will be always: "https://glacier.us-east-1.amazonaws.com/"
 * SSL Certificate checking will be disabled based on provided flag.
 *
 * @param accessKey the access key
 * @param secretKey the secret key
 * @param disableCertCheck the disable cert check
 * @param endpoint the endpoint
 */
public GlacierArchiveServiceImpl(final String accessKey, final String secretKey, final boolean disableCertCheck,
        final String endpoint) {
    super();
    AWSUtil.notNull(accessKey, ERR_MSG_ACCESSKEY);
    AWSUtil.notNull(secretKey, ERR_MSG_SECRETKEY);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("GlacierArchiveServiceImpl is initializing using keys..");
    }
    final AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
    final AWSCredentialsProvider credentialsProvider = new StaticCredentialsProvider(credentials);
    glacierClient = new AmazonGlacierClient(credentialsProvider);
    sqsClient = new AmazonSQSClient(credentialsProvider);
    snsClient = new AmazonSNSClient(credentialsProvider);
    if (disableCertCheck) {
        System.setProperty(DISABLE_CERT_PARAM, TRUE);//Disable cert check
    }
    if (StringUtils.isNotBlank(endpoint)) {
        glacierClient.setEndpoint(endpoint);
    }
}

From source file:com.github.abhinavmishra14.aws.glacier.service.impl.GlacierVaultServiceImpl.java

License:Open Source License

/**
 * The Constructor.<br/>/*  w  ww.ja  v a2  s  . c  om*/
 * This Constructor will return glacier client using accessKey and secretKey.<br/>
 * Additionally it will set the given endPoint for performing operations over vault.<br/>
 * Default endpoint will be always: "https://glacier.us-east-1.amazonaws.com/"
 * SSL Certificate checking will be disabled based on provided flag.
 *
 * @param accessKey the access key
 * @param secretKey the secret key
 * @param disableCertCheck the disable cert check
 * @param endpoint the endpoint
 */
public GlacierVaultServiceImpl(final String accessKey, final String secretKey, final boolean disableCertCheck,
        final String endpoint) {
    super();
    AWSUtil.notNull(accessKey, ERR_MSG_ACCESSKEY);
    AWSUtil.notNull(secretKey, ERR_MSG_SECRETKEY);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("GlacierVaultServiceImpl is initializing using keys..");
    }
    final AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
    final AWSCredentialsProvider credentialsProvider = new StaticCredentialsProvider(credentials);
    glacierClient = new AmazonGlacierClient(credentialsProvider);
    if (disableCertCheck) {
        System.setProperty(DISABLE_CERT_PARAM, TRUE);//Disable cert check
    }
    if (StringUtils.isNotBlank(endpoint)) {
        glacierClient.setEndpoint(endpoint);
    }
}

From source file:com.leverno.ysbos.archive.example.AmazonGlacierDownloadInventoryWithSQSPolling.java

License:Open Source License

public static void main(String[] args) throws IOException {

    AWSCredentials credentials = AwsUtil.getCredentials();

    client = new AmazonGlacierClient(credentials);
    client.setEndpoint("https://glacier." + region + ".amazonaws.com");
    sqsClient = new AmazonSQSClient(credentials);
    sqsClient.setEndpoint("https://sqs." + region + ".amazonaws.com");
    snsClient = new AmazonSNSClient(credentials);
    snsClient.setEndpoint("https://sns." + region + ".amazonaws.com");

    try {/*from w w  w .j  a v a  2  s .  co m*/
        setupSQS();

        setupSNS();

        String jobId = initiateJobRequest();
        System.out.println("Jobid = " + jobId);

        Boolean success = waitForJobToComplete(jobId, sqsQueueURL);
        if (!success) {
            throw new Exception("Job did not complete successfully.");
        }

        downloadJobOutput(jobId);

        cleanUp();

    } catch (Exception e) {
        System.err.println("Inventory retrieval failed.");
        System.err.println(e);
    }
}