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

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

Introduction

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

Prototype

AmazonGlacierAsyncClient(AwsAsyncClientParams asyncClientParams) 

Source Link

Document

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

Usage

From source file:opendap.aws.glacier.Download.java

License:Open Source License

protected boolean startJob(JobParameters jobParameters) throws IOException {

    _log.debug("startJob() - BEGIN ");

    if (_started)
        throw new IOException("Glacier inventory retrieval job has already been started!");

    AmazonGlacierAsyncClient client = new AmazonGlacierAsyncClient(getCredentials());
    client.setEndpoint(getEndpointUrl());

    InitiateJobRequest ijb = new InitiateJobRequest(getVaultName(), jobParameters);
    try {/*ww w  . j  a  va 2s  .c om*/

        _startDate = new Date();

        _initiateJobResult = client.initiateJob(ijb);

        _log.debug("startJob() - Glacier downloadJobOutput job started. jobId: {}",
                _initiateJobResult.getJobId());

        _started = true;

    } catch (Exception e) {
        _log.error("startJob() - Download failed to start! msg: {}", e.getMessage());
    }

    _log.debug("startJob() - END ");

    return _started;

}

From source file:opendap.aws.glacier.Download.java

License:Open Source License

public boolean jobCompleted() throws IOException {

    _log.debug("archiveRetrievalJobCompleted() - BEGIN ");

    if (!_started)
        throw new IOException("Glacier retrieval job has NOT been started!");

    AmazonGlacierAsyncClient client = new AmazonGlacierAsyncClient(getCredentials());
    client.setEndpoint(getEndpointUrl());

    InitiateJobResult initiateJobResult = getInitiateJobResult();

    long timeRemaining = estimatedTimeRemaining();

    _log.debug("archiveRetrievalJobCompleted() - Estimated Time Remaining: {} seconds  jobId: {}",
            timeRemaining, initiateJobResult.getJobId());

    DescribeJobRequest djr = new DescribeJobRequest(getVaultName(), initiateJobResult.getJobId());

    DescribeJobResult describeJobResult = client.describeJob(djr);

    _log.debug("archiveRetrievalJobCompleted() - DescribeJobResult: {}", describeJobResult.toString());
    _log.debug("archiveRetrievalJobCompleted() - DescribeJobResult.isCompleted(): {}",
            describeJobResult.isCompleted());
    _log.debug("archiveRetrievalJobCompleted() - DescribeJobResult.status(): {}",
            describeJobResult.getStatusCode());

    _log.debug("archiveRetrievalJobCompleted() - END ");

    return describeJobResult.isCompleted();

}

From source file:opendap.aws.glacier.Download.java

License:Open Source License

public boolean downloadJobOutput(File downloadFile) throws IOException {

    if (!jobCompleted()) {
        _log.warn("Glacier retrieval job has not completed!");
        return false;
    }//from  w w  w .java  2  s  .  co  m
    boolean success = false;

    String jobId = getInitiateJobResult().getJobId();

    _log.debug("downloadJobOutput() - BEGIN (Retrieving Glacier Job Result. JobID: {})", jobId);

    try {
        AmazonGlacierAsyncClient client = new AmazonGlacierAsyncClient(getCredentials());
        client.setEndpoint(getEndpointUrl());

        GetJobOutputRequest jobOutputRequest = new GetJobOutputRequest().withJobId(jobId)
                .withVaultName(getVaultName());
        GetJobOutputResult jobOutputResult = client.getJobOutput(jobOutputRequest);

        InputStream in = jobOutputResult.getBody();

        FileOutputStream out = new FileOutputStream(downloadFile);
        IOUtils.copy(in, out);

        _log.error("downloadJobOutput() - Retrieved Glacier job output. CacheFile: {}",
                downloadFile.getAbsolutePath());

        success = true;

    } catch (Exception e) {
        _log.error("downloadJobOutput() - Failed to retrieve Glacier job output. Msg: {}", e.getMessage());
    }

    _log.debug("downloadJobOutput() - END");

    return success;

}

From source file:opendap.aws.glacier.DownloadManager.java

License:Open Source License

public long initiateArchiveDownload(AWSCredentials glacierCreds, GlacierArchive gArc)
        throws JDOMException, IOException {

    _log.debug("initiateArchiveDownload() - BEGIN");

    String vaultName = gArc.getVaultName();
    String archiveId = gArc.getArchiveId();
    String resourceId = gArc.getResourceId();

    _log.debug("initiateArchiveDownload() -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -");
    _log.debug("initiateArchiveDownload() - Downloading resource from Glacier:  ");
    _log.debug("initiateArchiveDownload() -     Vault Name:  {}", vaultName);
    _log.debug("initiateArchiveDownload() -     Resource ID: {}", resourceId);
    _log.debug("initiateArchiveDownload() -     Archive ID:  {}", archiveId);

    long estimatedRetrievalTime = DEFAULT_GLACIER_ACCESS_DELAY;
    _managerLock.lock();/*  w w w  .j  a  v a  2s.co  m*/
    try {
        AmazonGlacierAsyncClient client = new AmazonGlacierAsyncClient(glacierCreds);
        client.setEndpoint(GlacierManager.theManager().getGlacierEndpoint());

        if (_activeArchiveDownloads.containsKey(resourceId)) {

            if (downloadArchive(resourceId)) {
                estimatedRetrievalTime = 0;
            } else {
                ArchiveDownload download = _activeArchiveDownloads.get(resourceId);
                estimatedRetrievalTime = download.estimatedTimeRemaining();

            }

        } else {

            ArchiveDownload ad = new ArchiveDownload(gArc, glacierCreds, DEFAULT_GLACIER_ACCESS_DELAY);

            if (ad.startJob()) {
                _activeArchiveDownloads.put(resourceId, ad);
                saveActiveArchiveDownloads();
                _log.debug("initiateArchiveDownload() - Active downloads saved.");
                estimatedRetrievalTime = ad.estimatedTimeRemaining();
            } else {
                estimatedRetrievalTime = -1;

            }

        }
    } finally {
        _managerLock.unlock();
    }

    _log.info("initiateArchiveDownload() - Archive Download for resource {} estimated complete in {} seconds.",
            resourceId, estimatedRetrievalTime);
    _log.debug("initiateArchiveDownload() - END");

    return estimatedRetrievalTime;
}