Search in sources :

Example 1 with EC2InstanceResult

use of org.apache.airavata.xbaya.core.amazon.EC2InstanceResult in project airavata by apache.

the class EC2InstancesManagementWindow method initGUI.

private void initGUI() {
    this.list = new XbayaEnhancedList<EC2InstanceResult>();
    GridPanel mainPanel = new GridPanel();
    TitledBorder border = new TitledBorder(new EtchedBorder(), "My Instances");
    mainPanel.getSwingComponent().setBorder(border);
    mainPanel.add(this.list);
    mainPanel.layout(1, 1, 0, 0);
    /* Connect/Refresh Button */
    JButton refreshButton = new JButton("Refresh");
    refreshButton.addActionListener(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            /* Check if Credential is already set or not */
            if (credentialSet()) {
                InstancesLoader instancesLoader = new InstancesLoader(EC2InstancesManagementWindow.this.engine, EC2InstancesManagementWindow.this.dialog.getDialog());
                instancesLoader.load(EC2InstancesManagementWindow.this.list);
            }
        }
    });
    /* Launch Instance Button */
    JButton launchButton = new JButton("Launch");
    launchButton.addActionListener(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (credentialSet()) {
                EC2LaunchWindow ec2LaunchWindow = new EC2LaunchWindow(EC2InstancesManagementWindow.this.engine);
                ec2LaunchWindow.show();
            }
        }
    });
    /* Terminate Instance */
    JButton terminateButton = new JButton("Terminate");
    terminateButton.addActionListener(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            List<EC2InstanceResult> selected = EC2InstancesManagementWindow.this.list.getSelectedValues();
            if (selected.size() == 0) {
                EC2InstancesManagementWindow.this.engine.getGUI().getErrorWindow().info(EC2InstancesManagementWindow.this.dialog.getDialog(), "Warning", "No instances selected");
                return;
            }
            String text = "";
            List<String> requestIds = new ArrayList<String>();
            for (EC2InstanceResult ec2InstancesResult : selected) {
                requestIds.add(ec2InstancesResult.getInstance().getInstanceId());
                text += ec2InstancesResult.getInstance().getInstanceId() + ",";
            }
            // confirm from user
            int n = JOptionPane.showConfirmDialog(EC2InstancesManagementWindow.this.dialog.getDialog(), "Are you want to terminate instances:\n" + text, "Terminate Instances", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
            if (n == JOptionPane.YES_OPTION) {
                // terminate
                AmazonUtil.terminateInstances(requestIds);
                // reload
                InstancesLoader instancesLoader = new InstancesLoader(EC2InstancesManagementWindow.this.engine, EC2InstancesManagementWindow.this.dialog.getDialog());
                instancesLoader.load(EC2InstancesManagementWindow.this.list);
            }
        }
    });
    /* Close Button */
    JButton closeButton = new JButton("Close");
    closeButton.addActionListener(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            EC2InstancesManagementWindow.this.hide();
        }
    });
    JPanel buttonPanel = new JPanel();
    buttonPanel.add(refreshButton);
    buttonPanel.add(launchButton);
    buttonPanel.add(terminateButton);
    buttonPanel.add(closeButton);
    this.dialog = new XBayaDialog(this.engine.getGUI(), "Amazon EC2 Management Console", mainPanel, buttonPanel);
    int width = 800;
    int height = 500;
    this.dialog.getDialog().setPreferredSize(new Dimension(width, height));
    this.dialog.setDefaultButton(closeButton);
}
Also used : XBayaDialog(org.apache.airavata.xbaya.ui.dialogs.XBayaDialog) EC2InstanceResult(org.apache.airavata.xbaya.core.amazon.EC2InstanceResult) ActionEvent(java.awt.event.ActionEvent) TitledBorder(javax.swing.border.TitledBorder) EtchedBorder(javax.swing.border.EtchedBorder) GridPanel(org.apache.airavata.xbaya.ui.widgets.GridPanel) XbayaEnhancedList(org.apache.airavata.xbaya.ui.widgets.XbayaEnhancedList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with EC2InstanceResult

use of org.apache.airavata.xbaya.core.amazon.EC2InstanceResult in project airavata by apache.

the class InstancesLoader method load.

/**
 * Load instance list.
 *
 * @param list instance list
 */
public void load(final XbayaEnhancedList<EC2InstanceResult> list) {
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                List<EC2InstanceResult> tmpList = new ArrayList<EC2InstanceResult>();
                List<Instance> instances = AmazonUtil.loadInstances();
                for (Instance instance : instances) {
                    tmpList.add(new EC2InstanceResult(instance));
                }
                if (!InstancesLoader.this.canceled) {
                    list.setListData(tmpList);
                }
            } catch (AmazonServiceException ex) {
                InstancesLoader.this.engine.getGUI().getErrorWindow().error(InstancesLoader.this.parent, "Cannot load EC2 instances", ex);
            } catch (AmazonClientException ex) {
                InstancesLoader.this.engine.getGUI().getErrorWindow().error(InstancesLoader.this.parent, "Cannot load EC2 instances", ex);
            } finally {
                InstancesLoader.this.loadingDialog.hide();
            }
        }
    }).start();
    this.loadingDialog.show();
}
Also used : EC2InstanceResult(org.apache.airavata.xbaya.core.amazon.EC2InstanceResult) Instance(com.amazonaws.services.ec2.model.Instance) AmazonClientException(com.amazonaws.AmazonClientException) ArrayList(java.util.ArrayList) AmazonServiceException(com.amazonaws.AmazonServiceException)

Aggregations

ArrayList (java.util.ArrayList)2 EC2InstanceResult (org.apache.airavata.xbaya.core.amazon.EC2InstanceResult)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonServiceException (com.amazonaws.AmazonServiceException)1 Instance (com.amazonaws.services.ec2.model.Instance)1 ActionEvent (java.awt.event.ActionEvent)1 List (java.util.List)1 EtchedBorder (javax.swing.border.EtchedBorder)1 TitledBorder (javax.swing.border.TitledBorder)1 XBayaDialog (org.apache.airavata.xbaya.ui.dialogs.XBayaDialog)1 GridPanel (org.apache.airavata.xbaya.ui.widgets.GridPanel)1 XbayaEnhancedList (org.apache.airavata.xbaya.ui.widgets.XbayaEnhancedList)1