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

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

Introduction

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

Prototype

public GetJobOutputRequest() 

Source Link

Document

Default constructor for GetJobOutputRequest object.

Usage

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

License:Mozilla Public License

List<Archive> getInventory() throws Exception {
    final String vaultName = getVaultName();

    final InitiateJobRequest initJobRequest = new InitiateJobRequest() //
            .withVaultName(vaultName) //
            .withJobParameters(new JobParameters() //
                    .withType("inventory-retrieval") //
    //.withSNSTopic("*** provide SNS topic ARN ****") //
    );/*ww  w  .  j av  a2  s  . c o m*/

    String jobId;
    try {
        LOG.info("Initiating inventory job...");
        final InitiateJobResult initJobResult = client.initiateJob(initJobRequest);
        jobId = initJobResult.getJobId();
    } catch (final ResourceNotFoundException e) {
        // Ignore. No inventory is available.
        LOG.warn("Inventory not available: " + e.getErrorMessage());
        return null;
    }

    // Wait for the inventory job to complete.
    waitForJob(vaultName, jobId);

    // Get the output of the inventory job.
    LOG.info("Inventory job completed. Getting output...");
    final GetJobOutputRequest jobOutputRequest = new GetJobOutputRequest().withVaultName(vaultName)
            .withJobId(jobId);
    final GetJobOutputResult jobOutputResult = client.getJobOutput(jobOutputRequest);

    final ObjectMapper mapper = new ObjectMapper();
    final ObjectNode rootNode = mapper.readValue(jobOutputResult.getBody(), ObjectNode.class);

    final List<Archive> archives = new ArrayList<>();
    for (final JsonNode archiveNode : rootNode.get("ArchiveList"))
        archives.add(new Archive(archiveNode));
    Collections.sort(archives);

    return archives;
}

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

License:Mozilla Public License

private File retrieveArchive(final String id, final String filename) throws Exception {
    final String vaultName = getVaultName();

    final InitiateJobRequest initJobRequest = new InitiateJobRequest() //
            .withVaultName(vaultName) //
            .withJobParameters(new JobParameters() //
                    .withType("archive-retrieval") //
                    .withArchiveId(id) //
    //.withSNSTopic("*** provide SNS topic ARN ****") //
    //.withDescription("archive retrieval")
    );//from   w ww  .  j  a  va  2 s. co  m

    LOG.info("Initiating archive retrieval job...");
    final InitiateJobResult initJobResult = client.initiateJob(initJobRequest);
    final String jobId = initJobResult.getJobId();

    // Wait for the job to complete.
    waitForJob(vaultName, jobId);

    // Get the output of the retrieval job.
    LOG.info("Archive retrieval job completed. Getting output...");
    final GetJobOutputRequest jobOutputRequest = new GetJobOutputRequest().withVaultName(vaultName)
            .withJobId(jobId);
    final GetJobOutputResult jobOutputResult = client.getJobOutput(jobOutputRequest);

    final File file = new File(filename);
    try (final FileOutputStream fos = new FileOutputStream(file)) {
        IOUtils.copy(jobOutputResult.getBody(), fos);
    }

    return file;
}

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

License:Open Source License

@Override
public void actionPerformed(ActionEvent e) {

    if (e.getSource() == jbtInventoryRequest) {
        SwingWorker inventoryWorker = new SwingWorker() {

            @Override/*from w ww.  j ava2 s .c o m*/
            protected Object doInBackground() throws Exception {

                //Create dumb progressbar
                Date d = new Date();
                JFrame inventoryFrame = new JFrame("Waiting for inventory");
                {
                    inventoryFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(d);
                    cal.add(Calendar.MINUTE, 250);
                    String doneString = cal.getTime().toString();
                    JLabel doneTimeLabel = new JLabel("<html><body>Inventory of vault " + irVault
                            + " requested.<br>Estimated completion by " + doneString + "</html></body>");
                    final JProgressBar dumJProgressBar = new JProgressBar(JProgressBar.HORIZONTAL);
                    dumJProgressBar.setIndeterminate(true);
                    inventoryFrame.add(dumJProgressBar, BorderLayout.NORTH);
                    inventoryFrame.add(doneTimeLabel, BorderLayout.CENTER);
                    inventoryFrame.setBackground(wc);
                    inventoryFrame.setSize(300, 60);
                }
                centerDefineFrame(inventoryFrame, 500, 100);
                inventoryFrame.setVisible(true);

                try {
                    JobParameters jParameters = new JobParameters().withType("inventory-retrieval");

                    InitiateJobRequest initJobRequest = new InitiateJobRequest().withVaultName(irVault)
                            .withJobParameters(jParameters);

                    InitiateJobResult initJobResult = irClient.initiateJob(initJobRequest);
                    String thisJobId = initJobResult.getJobId();

                    Thread.sleep(12600000);

                    Boolean success = waitForJob(irClient, irVault, thisJobId);

                    while (!success) {
                        Thread.sleep(WAIT_TIME);
                        success = waitForJob(irClient, irVault, thisJobId);
                    }

                    GetJobOutputRequest gjoRequest = new GetJobOutputRequest().withVaultName(irVault)
                            .withJobId(thisJobId);
                    GetJobOutputResult gjoResult = irClient.getJobOutput(gjoRequest);

                    Format formatter = new SimpleDateFormat("yyyyMMMdd_HHmmss");
                    String fileDate = formatter.format(d);

                    String fileName = irVault + fileDate + ".txt";

                    String filePath = "" + curDir + System.getProperty("file.separator") + fileName;

                    FileWriter fileStream = new FileWriter(filePath);

                    BufferedWriter out = new BufferedWriter(fileStream);

                    BufferedReader in = new BufferedReader(new InputStreamReader(gjoResult.getBody()));

                    String inputLine;

                    while ((inputLine = in.readLine()) != null) {
                        out.write(inputLine);
                    }
                    out.close();

                    inventoryFrame.setVisible(false);

                    JOptionPane.showMessageDialog(null,
                            "Successfully exported " + irVault + " inventory to " + filePath.toString(),
                            "Saved", JOptionPane.INFORMATION_MESSAGE);

                    return null;

                } catch (AmazonServiceException k) {
                    JOptionPane.showMessageDialog(null,
                            "The server returned an error. Files will not be inventoried for 24 hours after upload. Also check that correct location of vault has been set on the previous page.",
                            "Error", JOptionPane.ERROR_MESSAGE);
                    System.out.println("" + k);
                    inventoryFrame.setVisible(false);
                } catch (AmazonClientException i) {
                    JOptionPane.showMessageDialog(null,
                            "Client Error. Check that all fields are correct. Inventory not requested.",
                            "Error", JOptionPane.ERROR_MESSAGE);
                    inventoryFrame.setVisible(false);
                } catch (Exception j) {
                    JOptionPane.showMessageDialog(null, "Inventory not found. Unspecified Error.", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    inventoryFrame.setVisible(false);
                }
                return null;

            }
        };
        inventoryWorker.execute();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }

        this.setVisible(false);
        dispose();
    } else if (e.getSource() == jbtBack) {
        this.setVisible(false);
        dispose();
    } else {
        JOptionPane.showMessageDialog(this, "Please choose a valid action.");
    }

}

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

License:Open Source License

@Override
public void actionPerformed(ActionEvent e) {

    if (e.getSource() == jbtInventoryRequest) {
        SwingWorker<Object, Void> inventoryWorker = new SwingWorker<Object, Void>() {

            @Override//from  w  w  w  .j  av  a  2 s.c  om
            protected Object doInBackground() throws Exception {

                //Create dumb progressbar
                Date d = new Date();
                JFrame inventoryFrame = new JFrame("Waiting for inventory");
                {
                    inventoryFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(d);
                    cal.add(Calendar.MINUTE, 250);
                    String doneString = cal.getTime().toString();
                    JLabel doneTimeLabel = new JLabel("<html><body>Inventory of vault " + irVault
                            + " requested.<br>Estimated completion by " + doneString + "</html></body>");
                    final JProgressBar dumJProgressBar = new JProgressBar(JProgressBar.HORIZONTAL);
                    dumJProgressBar.setIndeterminate(true);
                    inventoryFrame.add(dumJProgressBar, BorderLayout.NORTH);
                    inventoryFrame.add(doneTimeLabel, BorderLayout.CENTER);
                    inventoryFrame.setBackground(wc);
                    inventoryFrame.setSize(300, 60);
                }
                centerDefineFrame(inventoryFrame, 500, 100);
                inventoryFrame.setVisible(true);

                try {
                    JobParameters jParameters = new JobParameters().withType("inventory-retrieval");

                    InitiateJobRequest initJobRequest = new InitiateJobRequest().withVaultName(irVault)
                            .withJobParameters(jParameters);

                    InitiateJobResult initJobResult = irClient.initiateJob(initJobRequest);
                    String thisJobId = initJobResult.getJobId();

                    Thread.sleep(12600000);

                    Boolean success = waitForJob(irClient, irVault, thisJobId);

                    while (!success) {
                        Thread.sleep(WAIT_TIME);
                        success = waitForJob(irClient, irVault, thisJobId);
                    }

                    GetJobOutputRequest gjoRequest = new GetJobOutputRequest().withVaultName(irVault)
                            .withJobId(thisJobId);
                    GetJobOutputResult gjoResult = irClient.getJobOutput(gjoRequest);

                    Format formatter = new SimpleDateFormat("yyyyMMMdd_HHmmss");
                    String fileDate = formatter.format(d);

                    String fileName = irVault + fileDate + ".txt";

                    String filePath = "" + CUR_DIR + System.getProperty("file.separator") + fileName;

                    FileWriter fileStream = new FileWriter(filePath);

                    BufferedWriter out = new BufferedWriter(fileStream);

                    BufferedReader in = new BufferedReader(new InputStreamReader(gjoResult.getBody()));

                    String inputLine;

                    while ((inputLine = in.readLine()) != null) {
                        out.write(inputLine);
                    }
                    out.close();

                    inventoryFrame.setVisible(false);

                    JOptionPane.showMessageDialog(null,
                            "Successfully exported " + irVault + " inventory to " + filePath.toString(),
                            "Saved", JOptionPane.INFORMATION_MESSAGE);

                    return null;

                } catch (AmazonServiceException k) {
                    JOptionPane.showMessageDialog(null,
                            "The server returned an error. Files will not be inventoried for 24 hours after upload. Also check that correct location of vault has been set on the previous page.",
                            "Error", JOptionPane.ERROR_MESSAGE);
                    System.out.println("" + k);
                    inventoryFrame.setVisible(false);
                } catch (AmazonClientException i) {
                    JOptionPane.showMessageDialog(null,
                            "Client Error. Check that all fields are correct. Inventory not requested.",
                            "Error", JOptionPane.ERROR_MESSAGE);
                    inventoryFrame.setVisible(false);
                } catch (Exception j) {
                    JOptionPane.showMessageDialog(null, "Inventory not found. Unspecified Error.", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    inventoryFrame.setVisible(false);
                }
                return null;

            }
        };
        inventoryWorker.execute();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }

        this.setVisible(false);
        dispose();
    } else if (e.getSource() == jbtBack) {
        this.setVisible(false);
        dispose();
    } else {
        JOptionPane.showMessageDialog(this, "Please choose a valid action.");
    }

}

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

License:Open Source License

@Override
public void actionPerformed(ActionEvent e) {

    if (e.getSource() == jbtInventoryRequest) {
        SwingWorker inventoryWorker = new SwingWorker() {

            //private String archiveId = jtfDownloadField.getText().trim();

            @Override/* w  w w .  j  a  v  a2 s.  c  o  m*/
            protected Object doInBackground() throws Exception {

                //Create dumb progressbar
                Date d = new Date();
                JFrame inventoryFrame = new JFrame("Waiting for inventory");
                {
                    inventoryFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(d);
                    cal.add(Calendar.MINUTE, 250);
                    String doneString = cal.getTime().toString();
                    JLabel doneTimeLabel = new JLabel("<html><body>Inventory of vault " + irVault
                            + " requested.<br>Estimated completion by " + doneString + "</html></body>");
                    final JProgressBar dumJProgressBar = new JProgressBar(JProgressBar.HORIZONTAL);
                    dumJProgressBar.setIndeterminate(true);
                    inventoryFrame.add(dumJProgressBar, BorderLayout.NORTH);
                    inventoryFrame.add(doneTimeLabel, BorderLayout.CENTER);
                    inventoryFrame.setBackground(wc);
                    inventoryFrame.setSize(300, 60);
                }
                centerDefineFrame(inventoryFrame, 500, 100);
                inventoryFrame.setVisible(true);

                try {
                    JobParameters jParameters = new JobParameters().withType("inventory-retrieval");

                    InitiateJobRequest initJobRequest = new InitiateJobRequest().withVaultName(irVault)
                            .withJobParameters(jParameters);

                    InitiateJobResult initJobResult = irClient.initiateJob(initJobRequest);
                    String thisJobId = initJobResult.getJobId();

                    Thread.sleep(12600000);

                    Boolean success = waitForJob(irClient, irVault, thisJobId);

                    while (success == false) {
                        Thread.sleep(WAIT_TIME);
                        success = waitForJob(irClient, irVault, thisJobId);
                    }

                    GetJobOutputRequest gjoRequest = new GetJobOutputRequest().withVaultName(irVault)
                            .withJobId(thisJobId);
                    GetJobOutputResult gjoResult = irClient.getJobOutput(gjoRequest);

                    Format formatter = new SimpleDateFormat("yyyyMMMdd_HHmmss");
                    String fileDate = formatter.format(d);

                    String fileName = irVault + fileDate + ".txt";

                    String filePath = "" + curDir + System.getProperty("file.separator") + fileName;

                    FileWriter fileStream = new FileWriter(filePath);

                    BufferedWriter out = new BufferedWriter(fileStream);

                    BufferedReader in = new BufferedReader(new InputStreamReader(gjoResult.getBody()));

                    String inputLine;

                    while ((inputLine = in.readLine()) != null) {
                        out.write(inputLine);
                    }
                    out.close();

                    inventoryFrame.setVisible(false);

                    JOptionPane.showMessageDialog(null,
                            "Successfully exported " + irVault + " inventory to " + filePath.toString(),
                            "Saved", JOptionPane.INFORMATION_MESSAGE);

                    return null;

                } catch (AmazonServiceException k) {
                    JOptionPane.showMessageDialog(null,
                            "The server returned an error. Files will not be inventoried for 24 hours after upload. Also check that correct location of vault has been set on the previous page.",
                            "Error", JOptionPane.ERROR_MESSAGE);
                    System.out.println("" + k);
                    inventoryFrame.setVisible(false);
                } catch (AmazonClientException i) {
                    JOptionPane.showMessageDialog(null,
                            "Client Error. Check that all fields are correct. Inventory not requested.",
                            "Error", JOptionPane.ERROR_MESSAGE);
                    inventoryFrame.setVisible(false);
                } catch (Exception j) {
                    JOptionPane.showMessageDialog(null, "Inventory not found. Unspecified Error.", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    inventoryFrame.setVisible(false);
                }
                return null;

            }
        };
        inventoryWorker.execute();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }

        this.setVisible(false);
        dispose();
    }

    else if (e.getSource() == jbtBack) {
        this.setVisible(false);
        dispose();
    } else {
        JOptionPane.showMessageDialog(this, "Please choose a valid action.");
    }

}

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

License:Open Source License

private static void downloadJobOutput(String jobId) throws IOException {

    GetJobOutputRequest getJobOutputRequest = new GetJobOutputRequest().withVaultName(vaultName)
            .withJobId(jobId);/*  www  .  j  a  v a2  s  .  c  o  m*/
    GetJobOutputResult getJobOutputResult = client.getJobOutput(getJobOutputRequest);

    FileWriter fstream = new FileWriter(fileName);
    BufferedWriter out = new BufferedWriter(fstream);
    BufferedReader in = new BufferedReader(new InputStreamReader(getJobOutputResult.getBody()));
    String inputLine;
    try {
        while ((inputLine = in.readLine()) != null) {
            out.write(inputLine);
        }
    } catch (IOException e) {
        throw new AmazonClientException("Unable to save archive", e);
    } finally {
        try {
            in.close();
        } catch (Exception e) {
        }
        try {
            out.close();
        } catch (Exception e) {
        }
    }
    System.out.println("Retrieved inventory to " + fileName);
}

From source file:com.vrane.metaGlacier.Archive.java

/**
 * Downloads an archive to a given file object.
 *
 * @param fileObj represents the downloaded file
 * @return true on success; false on any error.
 * @throws Exception/*from ww  w .  ja v a 2s . co m*/
 */
public boolean download(final File fileObj) throws Exception {
    GetJobOutputRequest getJobOutputRequest = new GetJobOutputRequest().withVaultName(vaultName)
            .withJobId(downloadJobId);
    boolean error = true;
    Exception exception = null;
    String error_message = null;
    OutputStream output = null;

    if (downloadJobId == null) {
        return false;
    }

    GetJobOutputResult getJobOutputResult = GlacierFrame.getClient(getRegion())
            .getJobOutput(getJobOutputRequest);
    InputStream input = new BufferedInputStream(getJobOutputResult.getBody());
    progress_reporter.setFileSize(size);
    long total_read = 0;
    long start = System.currentTimeMillis();
    try {
        output = new BufferedOutputStream(new FileOutputStream(fileObj));
        byte[] buffer = new byte[BYTE_BUFFER];
        int bytesRead = 0;
        do {
            bytesRead = input.read(buffer);
            if (bytesRead <= 0) {
                break;
            }
            total_read += bytesRead;
            long now = System.currentTimeMillis();
            long delta = now - start;
            if (delta > UPDATE_RATE_INTERVAL) {
                start = now;
                progress_reporter.setFilePosition(total_read);
            }
            output.write(buffer, 0, bytesRead);
        } while (bytesRead > 0);
        error = false;
    } catch (IOException e) {
        error_message = "Unable to save archive";
        exception = e;
    } catch (Exception e) {
        error_message = "Error saving archive";
        exception = e;
    } finally {
        try {
            input.close();
        } catch (Exception e) {
            error_message = "Unable to close input";
            exception = e;
        }
        try {
            if (null != output) {
                output.close();
            }
        } catch (Exception e) {
            error_message = "Unable to close output";
            exception = e;
        }
    }
    if (error) {
        if (error_message != null) {
            LGR.severe(error_message);
            throw exception;
        }
        return false;
    }
    return true;
}

From source file:com.vrane.metaGlacier.Vault.java

/**
 * Gets job output result from AWS.// w w  w.ja va2 s.c  om
 *
 * @param jid job id string
 * @return
 */
public GetJobOutputResult getJobOutput(final String jid) {
    GetJobOutputRequest jor = new GetJobOutputRequest().withVaultName(name).withJobId(jid);
    return GlacierFrame.getClient(region).getJobOutput(jor);
}

From source file:de.kopis.glacier.commands.ReceiveArchivesListCommand.java

License:Open Source License

public void retrieveInventoryListing(final String vaultName, final String jobId) {
    log.info("Retrieving inventory for job id " + jobId + "...");

    try {// w w w  . j  a v  a 2s  . c  o  m
        final GetJobOutputRequest jobOutputRequest = new GetJobOutputRequest().withVaultName(vaultName)
                .withJobId(jobId);
        final GetJobOutputResult jobOutputResult = client.getJobOutput(jobOutputRequest);
        final BufferedReader reader = new BufferedReader(new InputStreamReader(jobOutputResult.getBody()));
        String content = "";
        String line = null;
        while ((line = reader.readLine()) != null) {
            content += line;
        }
        reader.close();
        // TODO use dependency injection here
        printer.setInventory(content);
        printer.printInventory(System.out);
    } catch (final AmazonClientException e) {
        log.error(e.getLocalizedMessage(), e);
    } catch (final JSONException e) {
        log.error(e.getLocalizedMessage(), e);
    } catch (final IOException e) {
        log.error(e.getLocalizedMessage(), e);
    }
}

From source file:de.kopis.glacier.VaultInventoryLister.java

License:Open Source License

public void retrieveInventoryListing(final URL endpointUrl, final String vaultName, final String jobId) {
    System.out.println("Retrieving inventory for job id " + jobId + "...");
    client.setEndpoint(endpointUrl.toExternalForm());

    final GetJobOutputRequest jobOutputRequest = new GetJobOutputRequest().withVaultName(vaultName)
            .withJobId(jobId);/*from   w  w w  .  java2  s. co m*/
    final GetJobOutputResult jobOutputResult = client.getJobOutput(jobOutputRequest);
    final BufferedReader reader = new BufferedReader(new InputStreamReader(jobOutputResult.getBody()));
    String line = null;
    try {
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
    } catch (final IOException e) {
        System.err.println("Something went wrong while reading inventory.");
        e.printStackTrace();
    }
}