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

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

Introduction

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

Prototype

@Override
public DescribeJobResult describeJob(DescribeJobRequest request) 

Source Link

Document

This operation returns information about a job you previously initiated, including the job initiation date, the user who initiated the job, the job status code/message and the Amazon SNS topic to notify after Amazon S3 Glacier (Glacier) completes the job.

Usage

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  w  w  .jav  a  2 s . c  om*/
        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 {//from www. j  ava  2s . 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 {// www. j a  v  a 2s .  com
        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 {/*  ww w.  j a va 2  s  . co  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);
    }
}