Search in sources :

Example 6 with S3ServiceException

use of org.jets3t.service.S3ServiceException in project hadoop by apache.

the class Jets3tNativeFileSystemStore method dump.

@Override
public void dump() throws IOException {
    StringBuilder sb = new StringBuilder("S3 Native Filesystem, ");
    sb.append(bucket.getName()).append("\n");
    try {
        S3Object[] objects = s3Service.listObjects(bucket.getName());
        for (S3Object object : objects) {
            sb.append(object.getKey()).append("\n");
        }
    } catch (S3ServiceException e) {
        handleException(e);
    }
    System.out.println(sb);
}
Also used : S3Object(org.jets3t.service.model.S3Object) S3ServiceException(org.jets3t.service.S3ServiceException)

Example 7 with S3ServiceException

use of org.jets3t.service.S3ServiceException in project pentaho-kettle by pentaho.

the class S3CsvInputMetaTest method testGetS3Service_notEncryptedKeys.

@Test
public void testGetS3Service_notEncryptedKeys() {
    S3CsvInputMeta s3CvsInput = new S3CsvInputMeta();
    s3CvsInput.setAwsAccessKey(TEST_ACCESS_KEY);
    s3CvsInput.setAwsSecretKey(TEST_AWS_SECRET_KEY);
    try {
        S3Service s3Service = s3CvsInput.getS3Service(new Variables());
        assertNotNull(s3Service);
        assertEquals(TEST_ACCESS_KEY, s3Service.getProviderCredentials().getAccessKey());
        assertEquals(TEST_AWS_SECRET_KEY, s3Service.getProviderCredentials().getSecretKey());
    } catch (S3ServiceException e) {
        fail("No exception should be thrown. But it was:" + e.getLocalizedMessage());
    }
}
Also used : Variables(org.pentaho.di.core.variables.Variables) S3ServiceException(org.jets3t.service.S3ServiceException) S3Service(org.jets3t.service.S3Service) Test(org.junit.Test)

Example 8 with S3ServiceException

use of org.jets3t.service.S3ServiceException in project pentaho-kettle by pentaho.

the class S3CsvInputMetaTest method testGetS3Service_WithEncryptedKeys.

@Test
public void testGetS3Service_WithEncryptedKeys() {
    S3CsvInputMeta s3CvsInput = new S3CsvInputMeta();
    s3CvsInput.setAwsAccessKey(TEST_ACCESS_KEY_ENCRYPTED);
    s3CvsInput.setAwsSecretKey(TEST_AWS_SECRET_KEY_ENCRYPTED);
    try {
        S3Service s3Service = s3CvsInput.getS3Service(new Variables());
        assertNotNull(s3Service);
        assertEquals(TEST_ACCESS_KEY, s3Service.getProviderCredentials().getAccessKey());
        assertEquals(TEST_AWS_SECRET_KEY, s3Service.getProviderCredentials().getSecretKey());
    } catch (S3ServiceException e) {
        fail("No exception should be thrown. But it was:" + e.getLocalizedMessage());
    }
}
Also used : Variables(org.pentaho.di.core.variables.Variables) S3ServiceException(org.jets3t.service.S3ServiceException) S3Service(org.jets3t.service.S3Service) Test(org.junit.Test)

Example 9 with S3ServiceException

use of org.jets3t.service.S3ServiceException in project airavata by apache.

the class BucketsLoader method load.

/**
 * @param s3 S3Service
 * @param s3Tree S3Tree
 */
public void load(final S3Service s3, final S3Tree s3Tree) {
    new Thread(new Runnable() {

        @Override
        public void run() {
            S3Bucket[] bucketArray;
            try {
                bucketArray = s3.listAllBuckets();
                for (S3Bucket s3Bucket : bucketArray) {
                    DefaultMutableTreeNode tempTreeNode = s3Tree.addObject((DefaultMutableTreeNode) null, s3Bucket.getName());
                    if (BucketsLoader.this.canceled)
                        return;
                    S3Object[] s3ObjectArray = s3.listObjects(s3Bucket.getName());
                    for (S3Object s3Object : s3ObjectArray) {
                        String keyName = s3Object.getName();
                        if (keyName.contains("$")) {
                            keyName = keyName.substring(0, keyName.indexOf('_'));
                        }
                        s3Tree.addObject(tempTreeNode, keyName);
                    }
                }
                s3Tree.refresh();
                if (bucketArray.length == 0) {
                    JOptionPane.showMessageDialog(BucketsLoader.this.parent, "Connection Failed!", "Error", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                JOptionPane.showMessageDialog(BucketsLoader.this.parent, "Connection Successfully!", "Info", JOptionPane.INFORMATION_MESSAGE);
                // already connect
                S3TreeModel.getInstance().connect();
            } catch (S3ServiceException ex) {
                BucketsLoader.this.xbayaGUI.getErrorWindow().error(BucketsLoader.this.parent, "Cannot List S3 buckets", ex);
            } finally {
                BucketsLoader.this.loadingDialog.hide();
            }
        }
    }).start();
    this.loadingDialog.show();
}
Also used : S3Bucket(org.jets3t.service.model.S3Bucket) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) S3Object(org.jets3t.service.model.S3Object) S3ServiceException(org.jets3t.service.S3ServiceException)

Example 10 with S3ServiceException

use of org.jets3t.service.S3ServiceException in project airavata by apache.

the class S3FileChooser method initGUI.

private void initGUI() {
    /*
         * ScrollPane for S3 Tree
         */
    // add tree listener to this
    this.s3Tree = new S3Tree();
    this.s3Tree.addTreeSelectionListener(this);
    JScrollPane scrollPane = new JScrollPane(this.s3Tree);
    /*
         * Button Panel
         */
    JButton refreshButton = new JButton("Connect/Refresh");
    refreshButton.addActionListener(new AbstractAction() {

        private ChangeCredentialWindow credentialWindow;

        @Override
        public void actionPerformed(ActionEvent e) {
            if (AmazonCredential.getInstance().getAwsAccessKeyId().isEmpty() || AmazonCredential.getInstance().getAwsSecretAccessKey().isEmpty()) {
                S3FileChooser.this.xbayaGUI.getErrorWindow().warning(S3FileChooser.this.dialog.getDialog(), "Error", "Aws Access Key not set!");
                if (this.credentialWindow == null) {
                    this.credentialWindow = new ChangeCredentialWindow(S3FileChooser.this.dialog.getDialog());
                }
                try {
                    this.credentialWindow.show();
                } catch (Exception e1) {
                    S3FileChooser.this.xbayaGUI.getErrorWindow().error(e1);
                }
                return;
            }
            S3FileChooser.this.s3Tree.clean();
            try {
                // create S3Service
                S3Service s3Service = new RestS3Service(new AWSCredentials(AmazonCredential.getInstance().getAwsAccessKeyId(), AmazonCredential.getInstance().getAwsSecretAccessKey()));
                BucketsLoader bucketsLoader = new BucketsLoader(S3FileChooser.this.xbayaGUI, S3FileChooser.this.dialog.getDialog());
                bucketsLoader.load(s3Service, S3FileChooser.this.s3Tree);
            } catch (S3ServiceException s3ex) {
                S3FileChooser.this.xbayaGUI.getErrorWindow().error(s3ex);
            }
        }
    });
    JButton okButton = new JButton("Ok");
    okButton.addActionListener(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (S3FileChooser.this.chosenFile != null) {
                S3FileChooser.this.inputNode.setDefaultValue(new String(S3FileChooser.this.chosenFile));
            }
            hide();
        }
    });
    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            hide();
        }
    });
    JPanel buttonPanel = new JPanel();
    buttonPanel.add(refreshButton);
    buttonPanel.add(okButton);
    buttonPanel.add(cancelButton);
    this.dialog = new XBayaDialog(this.xbayaGUI, "Amazon S3 Input Chooser", scrollPane, buttonPanel);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) XBayaDialog(org.apache.airavata.xbaya.ui.dialogs.XBayaDialog) S3Tree(org.apache.airavata.xbaya.ui.widgets.amazon.S3Tree) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) S3ServiceException(org.jets3t.service.S3ServiceException) AWSCredentials(org.jets3t.service.security.AWSCredentials) S3ServiceException(org.jets3t.service.S3ServiceException) BucketsLoader(org.apache.airavata.xbaya.ui.dialogs.amazon.BucketsLoader) RestS3Service(org.jets3t.service.impl.rest.httpclient.RestS3Service) ChangeCredentialWindow(org.apache.airavata.xbaya.ui.dialogs.amazon.ChangeCredentialWindow) AbstractAction(javax.swing.AbstractAction) RestS3Service(org.jets3t.service.impl.rest.httpclient.RestS3Service) S3Service(org.jets3t.service.S3Service)

Aggregations

S3ServiceException (org.jets3t.service.S3ServiceException)10 S3Object (org.jets3t.service.model.S3Object)5 S3Service (org.jets3t.service.S3Service)4 RestS3Service (org.jets3t.service.impl.rest.httpclient.RestS3Service)4 AWSCredentials (org.jets3t.service.security.AWSCredentials)3 Test (org.junit.Test)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 ServiceException (org.jets3t.service.ServiceException)2 S3Bucket (org.jets3t.service.model.S3Bucket)2 Variables (org.pentaho.di.core.variables.Variables)2 FileUtils (io.druid.java.util.common.FileUtils)1 ActionEvent (java.awt.event.ActionEvent)1 EOFException (java.io.EOFException)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Date (java.util.Date)1