Example usage for com.amazonaws.services.glacier.model InitiateJobResult getJobId

List of usage examples for com.amazonaws.services.glacier.model InitiateJobResult getJobId

Introduction

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

Prototype


public String getJobId() 

Source Link

Document

The ID of the job.

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 ****") //
    );//  w  w w. ja va  2  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  v  a2s .  com*/

    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 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) {
                        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/*  w  ww  .jav  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) {
                        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 va  2  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 String initiateJobRequest() {

    JobParameters jobParameters = new JobParameters().withType("inventory-retrieval").withSNSTopic(snsTopicARN);

    InitiateJobRequest request = new InitiateJobRequest().withVaultName(vaultName)
            .withJobParameters(jobParameters);

    InitiateJobResult response = client.initiateJob(request);

    return response.getJobId();
}

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

/**
 * Given a sns topic this creates a job to download.
 *
 * @param snsTopic is string sns topic for this region
 * @return jobid/*from   www .jav a  2 s.co m*/
 */
public String createDownloadJob(final String snsTopic) {
    JobParameters jobParameters = new JobParameters().withArchiveId(archiveId).withSNSTopic(snsTopic)
            //.withRetrievalByteRange("*** provide a retrieval range***")
            .withType("archive-retrieval");
    InitiateJobResult initiateJobResult = null;
    InitiateJobRequest iJobRequest = new InitiateJobRequest().withJobParameters(jobParameters)
            .withVaultName(vaultName);

    LGR.log(Level.FINE, "requesting job for vault {0} and archive {1}", new Object[] { vaultName, archiveId });
    try {
        initiateJobResult = GlacierFrame.getClient(getRegion()).initiateJob(iJobRequest);
    } catch (IllegalArgumentException e) {
        LGR.severe("This archive does not exist at AWS");
        LGR.log(Level.SEVERE, null, e);
    } catch (Exception e) {
        LGR.log(Level.SEVERE, null, e);
    }
    final String jobId = initiateJobResult == null ? null : initiateJobResult.getJobId();
    if (jobId != null) {
        LGR.log(Level.INFO, "download job id is {0}{1}", new Object[] { jobId.substring(0, 22), "..." });
    } else {
        LGR.severe("Job id not found");
    }
    return jobId;
}

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

/**
 * Start a job to get the inventory of a vault.
 *
 * @param sns_topic_string region appropriate SNS topic string
 * @return job id string if successful; null on error
 */// w w  w  .  j a  v  a2  s . c o m
public String makeVaultInventoryJob(final String sns_topic_string) {
    final JobParameters jp = new JobParameters().withType("inventory-retrieval").withSNSTopic(sns_topic_string);
    final InitiateJobRequest initJobRequest = new InitiateJobRequest().withVaultName(name)
            .withJobParameters(jp);
    InitiateJobResult JobResult = null;

    try {
        JobResult = GlacierFrame.getClient(region).initiateJob(initJobRequest);
    } catch (Exception e) {
        LGR.log(Level.SEVERE, null, e);
        return null;
    }
    return JobResult.getJobId();
}

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

License:Open Source License

public void startInventoryListing(final String vaultName) {
    log.info("Starting inventory listing for vault " + vaultName + "...");

    try {//from   ww w.j  a v a 2s .  c  o  m
        final InitiateJobRequest initJobRequest = new InitiateJobRequest().withVaultName(vaultName)
                .withJobParameters(new JobParameters().withType("inventory-retrieval"));

        final InitiateJobResult initJobResult = client.initiateJob(initJobRequest);
        final String jobId = initJobResult.getJobId();
        log.info("Inventory Job created with ID" + System.getProperty("line.separator") + jobId);
    } catch (final AmazonClientException e) {
        log.error(e.getLocalizedMessage(), e);
    }

    // TODO wait for job, but it could take about 4 hours says the SDK...
}

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

License:Open Source License

public void startInventoryListing(final URL endpointUrl, final String vaultName) {
    System.out.println("Starting inventory listing for vault " + vaultName + "...");
    client.setEndpoint(endpointUrl.toExternalForm());

    final InitiateJobRequest initJobRequest = new InitiateJobRequest().withVaultName(vaultName)
            .withJobParameters(new JobParameters().withType("inventory-retrieval"));

    final InitiateJobResult initJobResult = client.initiateJob(initJobRequest);
    final String jobId = initJobResult.getJobId();
    System.out.println("Inventory Job created with ID=" + jobId);

    // TODO wait for job, but it could take about 4 hours says the SDK...
}