Example usage for com.amazonaws.services.glacier.model DescribeJobRequest DescribeJobRequest

List of usage examples for com.amazonaws.services.glacier.model DescribeJobRequest DescribeJobRequest

Introduction

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

Prototype

public DescribeJobRequest(String vaultName, String jobId) 

Source Link

Document

Constructs a new DescribeJobRequest object.

Usage

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

License:Mozilla Public License

void waitForJob(final String vaultName, final String jobId) throws Exception {
    while (true) {
        final DescribeJobResult describeJobResult = client
                .describeJob(new DescribeJobRequest(vaultName, jobId));
        final Boolean completed = describeJobResult.getCompleted();
        if (completed != null && completed)
            break;
        LOG.info("Job not completed. Waiting 15 minutes...");
        Thread.sleep(1000 * 60 * 15);
    }//from   www  .ja v a 2  s . c  o m
}

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

License:Open Source License

private boolean waitForJob(AmazonGlacierClient client, String vaultName, String jobId) {
    boolean inventoryReady = false;
    try {/*from w ww.j  ava2s .co  m*/
        DescribeJobRequest djRequest = new DescribeJobRequest(vaultName, jobId);
        DescribeJobResult djResult = client.describeJob(djRequest);
        inventoryReady = djResult.getCompleted();
    } catch (Exception e) {
    }

    return inventoryReady;
}

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

License:Open Source License

private boolean waitForJob(AmazonGlacierClient client, String vaultName, String jobId) {
    boolean inventoryReady = false;
    try {//w w  w .  j  a  v a 2  s . c  o  m
        DescribeJobRequest djRequest = new DescribeJobRequest(vaultName, jobId);
        DescribeJobResult djResult = client.describeJob(djRequest);
        inventoryReady = djResult.getCompleted();
    } catch (Exception e) {
    }
    ;

    return inventoryReady;
}

From source file:maebackup.MaeBackup.java

License:Open Source License

public static void download(String filename, String jobid) {
    try {//from   w ww  .  ja v a 2  s . c  o m
        System.out.println("Starting download...");
        ClientConfiguration config = new ClientConfiguration();
        config.setProtocol(Protocol.HTTPS);
        AmazonGlacierClient client = new AmazonGlacierClient(credentials, config);
        client.setEndpoint(endpoint);

        if (jobid == null || jobid == "") {
            String archiveid;
            // Yes, this will screw up on actual 138-character file names, but... yeah.
            if (filename.length() == 138) {
                archiveid = filename;
            } else {
                File listfile = new File(cachedir, "archives.lst");
                Map<File, String> filemap = loadHashes(listfile);
                archiveid = filemap.get(filename);
                if (archiveid == null) {
                    System.err.println("Error: Could not find archive ID for file " + filename);
                    System.exit(1);
                    return;
                }
            }

            InitiateJobResult result = client.initiateJob(new InitiateJobRequest(vaultname,
                    new JobParameters().withType("archive-retrieval").withArchiveId(archiveid)));
            jobid = result.getJobId();
            System.out.println("Started download job as ID " + jobid);
        } else {
            DescribeJobResult djres = client.describeJob(new DescribeJobRequest(vaultname, jobid));
            if (!djres.getStatusCode().equals("Succeeded")) {
                System.out.println("Job is not listed as Succeeded. It is: " + djres.getStatusCode());
                System.out.println(djres.getStatusMessage());
                System.exit(2);
            }
            long size = djres.getArchiveSizeInBytes();
            long chunks = size / chunksize;
            while (chunks > 10000) {
                chunksize <<= 1;
                chunks = size / chunksize;
            }
            RandomAccessFile raf = new RandomAccessFile(filename, "w");
            raf.setLength(size);
            byte[] buffer = new byte[chunksize];

            for (int x = 0; x < chunks; x++) {
                try {
                    System.out.println("Downloading chunk " + x + " of " + chunks);
                    String range = "bytes " + (x * chunksize) + "-" + ((x + 1) * chunksize - 1) + "/*";

                    GetJobOutputResult gjores = client
                            .getJobOutput(new GetJobOutputRequest(vaultname, jobid, range));

                    gjores.getBody().read(buffer);

                    MessageDigest md = MessageDigest.getInstance("SHA-256");
                    md.update(buffer, 0, chunksize);

                    byte[] hash = md.digest();

                    StringBuffer sb = new StringBuffer();
                    for (byte b : hash) {
                        sb.append(String.format("%02x", b));
                    }
                    if (!sb.toString().equalsIgnoreCase(gjores.getChecksum())) {
                        System.err.println("Error: Chunk " + x + " does not match SHA-256. Retrying.");
                        x--;
                        continue;
                    }

                    raf.seek(x * chunksize);
                    raf.write(buffer);
                } catch (Exception e) {
                    System.err.println("Error: Exception while downloading chunk " + x + ". Retrying.");
                    x--;
                }
            }

            if (size > chunks * chunksize) {
                do {
                    try {
                        System.out.println("Downloading final partial chunk");
                        String range = "bytes " + (chunks * chunksize) + "-" + (size - 1) + "/*";

                        GetJobOutputResult gjores = client
                                .getJobOutput(new GetJobOutputRequest(vaultname, jobid, range));

                        int bytes = gjores.getBody().read(buffer);

                        MessageDigest md = MessageDigest.getInstance("SHA-256");
                        md.update(buffer, 0, bytes);

                        byte[] hash = md.digest();

                        StringBuffer sb = new StringBuffer();
                        for (byte b : hash) {
                            sb.append(String.format("%02x", b));
                        }
                        if (!sb.toString().equalsIgnoreCase(gjores.getChecksum())) {
                            System.err.println("Error: Final chunk does not match SHA-256. Retrying.");
                            continue;
                        }

                        raf.seek(chunks * chunksize);
                        raf.write(buffer, 0, bytes);
                    } catch (Exception e) {
                        System.err.println("Error: Exception while downloading final chunk. Retrying.");
                        continue;
                    }
                } while (false);
            }
            raf.close();

            String treehash = TreeHashGenerator.calculateTreeHash(new File(filename));
            if (!treehash.equalsIgnoreCase(djres.getSHA256TreeHash())) {
                System.err.println("Error: File failed final tree hash check.");
                System.exit(3);
            }

            System.out.println("Download complete.");
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:maebackup.MaeBackup.java

License:Open Source License

public static void list(String arg) {
    try {/*w ww  . j  av a  2s .  c  o m*/
        System.out.println("Listing Glacier vault...");
        ClientConfiguration config = new ClientConfiguration();
        config.setProtocol(Protocol.HTTPS);
        AmazonGlacierClient client = new AmazonGlacierClient(credentials, config);
        client.setEndpoint(endpoint);

        if (arg == null || arg == "") {
            InitiateJobResult result = client.initiateJob(
                    new InitiateJobRequest(vaultname, new JobParameters().withType("inventory-retrieval")));
            String jobid = result.getJobId();
            System.out.println("Started inventory retrival job as ID " + jobid);
        } else {
            DescribeJobResult djres = client.describeJob(new DescribeJobRequest(vaultname, arg));
            if (!djres.getStatusCode().equals("Succeeded")) {
                System.out.println("Job is not listed as Succeeded. It is: " + djres.getStatusCode());
                System.out.println(djres.getStatusMessage());
                System.exit(2);
            }

            GetJobOutputResult gjores = client
                    .getJobOutput(new GetJobOutputRequest().withVaultName(vaultname).withJobId(arg));
            byte[] buffer = new byte[1024];
            int bytes;
            while ((bytes = gjores.getBody().read(buffer)) > 0) {
                System.out.write(buffer, 0, bytes);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

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();

}