Search in sources :

Example 1 with AmazonSNSClient

use of com.amazonaws.services.sns.AmazonSNSClient in project glacier-cli by carlossg.

the class Glacier method inventory.

public void inventory(String vaultName, String snsTopicName, String sqsQueueName, String fileName) {
    String msg = "Requesting inventory from Glacier vault " + vaultName + ". It might take around 4 hours.";
    System.out.println(msg);
    sqsClient = new AmazonSQSClient(credentials);
    sqsClient.setEndpoint("https://sqs." + region + ".amazonaws.com");
    snsClient = new AmazonSNSClient(credentials);
    snsClient.setEndpoint("https://sns." + region + ".amazonaws.com");
    try {
        QueueConfig config = setupSQS(sqsQueueName);
        config = setupSNS(config, snsTopicName);
        String jobId = initiateJobRequest(vaultName, config.snsTopicARN);
        System.out.println("Jobid = " + jobId);
        Boolean success = waitForJobToComplete(jobId, config.sqsQueueURL);
        if (!success) {
            throw new Exception("Job did not complete successfully.");
        }
        downloadJobOutput(vaultName, jobId, fileName);
        cleanUp(config);
    } catch (Exception e) {
        System.err.println("Archive retrieval failed.");
        System.err.println(e);
    }
}
Also used : AmazonSQSClient(com.amazonaws.services.sqs.AmazonSQSClient) AmazonSNSClient(com.amazonaws.services.sns.AmazonSNSClient) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException)

Example 2 with AmazonSNSClient

use of com.amazonaws.services.sns.AmazonSNSClient in project SAGU by brianmcmichael.

the class AmazonDownloadRequest method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == jbtDownload) {
        archiveId = jtfDownloadField.getText().trim();
        if ((archiveId.equals(""))) {
            JOptionPane.showMessageDialog(null, "Enter the Archive ID of the file to be requested.", "Error", JOptionPane.ERROR_MESSAGE);
        } else {
            SwingWorker<Object, Void> downloadWorker = new SwingWorker<Object, Void>() {

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

                @Override
                protected Void doInBackground() throws Exception {
                    // Create dumb progressbar
                    JFrame downloadFrame = new JFrame("Downloading");
                    {
                        downloadFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                        final JProgressBar dumJProgressBar = new JProgressBar(JProgressBar.HORIZONTAL);
                        dumJProgressBar.setIndeterminate(true);
                        downloadFrame.add(dumJProgressBar, BorderLayout.NORTH);
                        downloadFrame.setSize(300, 60);
                    }
                    centerDefineFrame(downloadFrame, 300, 50);
                    try {
                        String vaultName = dlVault;
                        FileDialog fd = new FileDialog(new Frame(), "Save Archive As...", FileDialog.SAVE);
                        fd.setFile("Save Archive As...");
                        fd.setDirectory(System.getProperty("user.dir"));
                        fd.setLocation(50, 50);
                        fd.setVisible(true);
                        String filePath = "" + fd.getDirectory() + System.getProperty("file.separator") + fd.getFile();
                        File outFile = new File(filePath);
                        if (outFile != null) {
                            downloadFrame.setTitle("Downloading " + outFile.toString());
                            downloadFrame.setVisible(true);
                            final Endpoint endpoint = Endpoint.getByIndex(locationChoice);
                            AmazonSQSClient dlSQS = new AmazonSQSClient(dlCredentials);
                            AmazonSNSClient dlSNS = new AmazonSNSClient(dlCredentials);
                            dlSQS.setEndpoint(endpoint.getSQSEndpoint());
                            dlSNS.setEndpoint(endpoint.getSNSEndpoint());
                            // ArchiveTransferManager atm = new
                            // ArchiveTransferManager(dlClient,
                            // dlCredentials);
                            ArchiveTransferManager atm = new ArchiveTransferManager(dlClient, dlSQS, dlSNS);
                            atm.download("-", vaultName, archiveId, outFile);
                            JOptionPane.showMessageDialog(null, "Sucessfully downloaded " + outFile.toString(), "Success", JOptionPane.INFORMATION_MESSAGE);
                            downloadFrame.setVisible(false);
                        }
                    } catch (AmazonServiceException k) {
                        JOptionPane.showMessageDialog(null, "The server returned an error. Wait 24 hours after submitting an archive to attempt a download. Also check that correct location of archive has been set on the previous page.", "Error", JOptionPane.ERROR_MESSAGE);
                        System.out.println("" + k);
                        downloadFrame.setVisible(false);
                    } catch (AmazonClientException i) {
                        JOptionPane.showMessageDialog(null, "Client Error. Check that all fields are correct. Archive not downloaded.", "Error", JOptionPane.ERROR_MESSAGE);
                        downloadFrame.setVisible(false);
                    } catch (Exception j) {
                        JOptionPane.showMessageDialog(null, "Archive not found. Unspecified Error.", "Error", JOptionPane.ERROR_MESSAGE);
                        downloadFrame.setVisible(false);
                    }
                    return null;
                }
            };
            downloadWorker.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.");
    }
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) AmazonSQSClient(com.amazonaws.services.sqs.AmazonSQSClient) AmazonSNSClient(com.amazonaws.services.sns.AmazonSNSClient) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonClientException(com.amazonaws.AmazonClientException) ArchiveTransferManager(com.amazonaws.services.glacier.transfer.ArchiveTransferManager) Endpoint(com.brianmcmichael.sagu.Endpoint) AmazonServiceException(com.amazonaws.AmazonServiceException) File(java.io.File)

Example 3 with AmazonSNSClient

use of com.amazonaws.services.sns.AmazonSNSClient in project glacier-cli by carlossg.

the class Glacier method download.

public void download(String vaultName, String archiveId, String downloadFilePath) {
    String msg = "Downloading " + archiveId + " from Glacier vault " + vaultName;
    System.out.println(msg);
    sqsClient = new AmazonSQSClient(credentials);
    sqsClient.setEndpoint("https://sqs." + region + ".amazonaws.com");
    snsClient = new AmazonSNSClient(credentials);
    snsClient.setEndpoint("https://sns." + region + ".amazonaws.com");
    try {
        ArchiveTransferManager atm = new ArchiveTransferManager(client, sqsClient, snsClient);
        atm.download(vaultName, archiveId, new File(downloadFilePath));
    } catch (Exception e) {
        throw new RuntimeException("Error " + msg, e);
    }
}
Also used : ArchiveTransferManager(com.amazonaws.services.glacier.transfer.ArchiveTransferManager) AmazonSQSClient(com.amazonaws.services.sqs.AmazonSQSClient) AmazonSNSClient(com.amazonaws.services.sns.AmazonSNSClient) File(java.io.File) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException)

Example 4 with AmazonSNSClient

use of com.amazonaws.services.sns.AmazonSNSClient in project camel by apache.

the class SnsEndpoint method createSNSClient.

/**
     * Provide the possibility to override this method for an mock implementation
     *
     * @return AmazonSNSClient
     */
AmazonSNS createSNSClient() {
    AmazonSNS client = null;
    ClientConfiguration clientConfiguration = null;
    boolean isClientConfigFound = false;
    if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
        clientConfiguration = new ClientConfiguration();
        clientConfiguration.setProxyHost(configuration.getProxyHost());
        clientConfiguration.setProxyPort(configuration.getProxyPort());
        isClientConfigFound = true;
    }
    if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) {
        AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
        if (isClientConfigFound) {
            client = new AmazonSNSClient(credentials, clientConfiguration);
        } else {
            client = new AmazonSNSClient(credentials);
        }
    } else {
        if (isClientConfigFound) {
            client = new AmazonSNSClient();
        } else {
            client = new AmazonSNSClient(clientConfiguration);
        }
    }
    return client;
}
Also used : AmazonSNSClient(com.amazonaws.services.sns.AmazonSNSClient) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) ClientConfiguration(com.amazonaws.ClientConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AmazonSNS(com.amazonaws.services.sns.AmazonSNS)

Example 5 with AmazonSNSClient

use of com.amazonaws.services.sns.AmazonSNSClient in project metacat by Netflix.

the class SNSNotificationServiceImplProvider method get.

/**
     * {@inheritDoc}
     */
@Override
public NotificationService get() {
    if (this.config.isSnsNotificationEnabled()) {
        final String tableArn = this.config.getSnsTopicTableArn();
        if (StringUtils.isEmpty(tableArn)) {
            throw new ProvisionException("SNS Notifications are enabled but no table ARN provided. Unable to configure.");
        }
        final String partitionArn = this.config.getSnsTopicPartitionArn();
        if (StringUtils.isEmpty(partitionArn)) {
            throw new ProvisionException("SNS Notifications are enabled but no partition ARN provided. Unable to configure.");
        }
        log.info("SNS notifications are enabled. Providing SNSNotificationServiceImpl implementation.");
        return new SNSNotificationServiceImpl(new AmazonSNSClient(), tableArn, partitionArn, this.mapper, registry);
    } else {
        log.info("SNS notifications are not enabled. Ignoring and providing default implementation.");
        return new DefaultNotificationServiceImpl();
    }
}
Also used : ProvisionException(com.google.inject.ProvisionException) DefaultNotificationServiceImpl(com.netflix.metacat.main.services.notifications.DefaultNotificationServiceImpl) AmazonSNSClient(com.amazonaws.services.sns.AmazonSNSClient)

Aggregations

AmazonSNSClient (com.amazonaws.services.sns.AmazonSNSClient)5 AmazonSQSClient (com.amazonaws.services.sqs.AmazonSQSClient)3 ArchiveTransferManager (com.amazonaws.services.glacier.transfer.ArchiveTransferManager)2 File (java.io.File)2 IOException (java.io.IOException)2 UnrecognizedOptionException (org.apache.commons.cli.UnrecognizedOptionException)2 JsonParseException (org.codehaus.jackson.JsonParseException)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonServiceException (com.amazonaws.AmazonServiceException)1 ClientConfiguration (com.amazonaws.ClientConfiguration)1 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 AmazonSNS (com.amazonaws.services.sns.AmazonSNS)1 Endpoint (com.brianmcmichael.sagu.Endpoint)1 ProvisionException (com.google.inject.ProvisionException)1 DefaultNotificationServiceImpl (com.netflix.metacat.main.services.notifications.DefaultNotificationServiceImpl)1