You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sa...@apache.org on 2014/07/12 00:21:20 UTC
[07/20] updating xbaya gui to the new airavata
http://git-wip-us.apache.org/repos/asf/airavata/blob/3e6c815a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/descriptors/ApplicationDescriptionDialog.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/descriptors/ApplicationDescriptionDialog.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/descriptors/ApplicationDescriptionDialog.java
deleted file mode 100644
index ca72e5f..0000000
--- a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/descriptors/ApplicationDescriptionDialog.java
+++ /dev/null
@@ -1,822 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.airavata.xbaya.ui.dialogs.descriptors;
-
-import java.awt.Color;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.FocusAdapter;
-import java.awt.event.FocusEvent;
-import java.awt.event.KeyAdapter;
-import java.awt.event.KeyEvent;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.io.File;
-import java.util.List;
-
-import javax.swing.BorderFactory;
-import javax.swing.JButton;
-import javax.swing.JComboBox;
-import javax.swing.JDialog;
-import javax.swing.JFileChooser;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JSeparator;
-import javax.swing.JTextField;
-import javax.swing.ProgressMonitor;
-import javax.swing.SwingConstants;
-
-import org.apache.airavata.client.api.AiravataAPI;
-import org.apache.airavata.client.api.exception.AiravataAPIInvocationException;
-import org.apache.airavata.common.utils.SwingUtil;
-import org.apache.airavata.commons.gfac.type.ApplicationDescription;
-import org.apache.airavata.commons.gfac.type.HostDescription;
-import org.apache.airavata.commons.gfac.type.ServiceDescription;
-import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
-import org.apache.airavata.schemas.gfac.GlobusHostType;
-import org.apache.airavata.schemas.gfac.GsisshHostType;
-import org.apache.airavata.schemas.gfac.HpcApplicationDeploymentType;
-import org.apache.airavata.schemas.gfac.SSHHostType;
-import org.apache.airavata.xbaya.XBayaEngine;
-import org.apache.airavata.xbaya.ui.menues.MenuIcons;
-import org.apache.airavata.xbaya.ui.widgets.GridPanel;
-import org.apache.airavata.xbaya.ui.widgets.XBayaLabel;
-import org.apache.airavata.xbaya.ui.widgets.XBayaLinkButton;
-import org.apache.airavata.xbaya.ui.widgets.XBayaTextField;
-import org.apache.xmlbeans.XmlException;
-//import org.apache.airavata.registry.api.AiravataRegistry2;
-
-public class ApplicationDescriptionDialog extends JDialog implements ActionListener {
- /**
- *
- */
- private static final long serialVersionUID = -2745085755585610025L;
- private XBayaTextField txtExecPath;
- private XBayaTextField txtAppName;
- private XBayaTextField txtTempDir;
-
- private AiravataAPI registry;
- private ApplicationDescription shellApplicationDescription;
- private JLabel lblError;
- private boolean applcationDescCreated = false;
- private JButton okButton;
-
- private String serviceName;
- private String hostName;
- private JComboBox cmbHostName;
-
- private XBayaEngine engine;
- private JButton btnHostAdvanceOptions;
- private boolean newDescritor;
- private ApplicationDescription originalDescription;
- private String originalHost;
- private String originalService;
- private ServiceDescription serviceDescription=null;
- private JButton btnTmpDirBrowse;
- private JButton btnExecBrowse;
-
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- try {
- ApplicationDescriptionDialog dialog = new ApplicationDescriptionDialog(null);
- dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
- dialog.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public ApplicationDescriptionDialog(XBayaEngine engine) {
- this(engine,true,null,null,null);
- }
- /**
- * Create the dialog.
- */
- public ApplicationDescriptionDialog(XBayaEngine engine, boolean newDescritor, ApplicationDescription originalDescription, String originalHost, String originalService) {
- setNewDescritor(newDescritor);
- setOriginalDescription(originalDescription);
- setOriginalHost(originalHost);
- setOriginalService(originalService);
- setRegistry(engine.getConfiguration().getAiravataAPI());
- addWindowListener(new WindowAdapter() {
- @Override
- public void windowOpened(WindowEvent arg0) {
- if (isNewDescritor()) {
- String baseName = "Application";
- int i = 1;
- String defaultName = baseName + i;
- try {
- ApplicationDescription applicationDescription = getRegistry()
- .getApplicationManager().getApplicationDescription(getServiceName(),
- getHostName());
- while (true) {
- boolean notFound = true;
- if (applicationDescription.getType()
- .getApplicationName().getStringValue()
- .equals(defaultName)) {
- notFound = false;
- break;
- }
- if (notFound) {
- break;
- }
- defaultName = baseName + (++i);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- txtAppName.setText(defaultName);
- setApplicationName(txtAppName.getText());
- }
- }
- });
- this.engine=engine;
- iniGUI();
- if (originalService!=null){
- try {
- ServiceDescription disc = getRegistry().getApplicationManager().getServiceDescription(originalService);
- if(disc!=null){
- setServiceDescription(disc);
- }
- throw new AiravataAPIInvocationException(new Exception("Service Description not found in registry."));
- } catch (AiravataAPIInvocationException e) {
- e.printStackTrace();
- }
- }
- }
-
- public void open() {
- setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
- setVisible(true);
- }
-
- protected ApplicationDescriptionDialog getDialog() {
- return this;
- }
-
- private void iniGUI() {
- if (isNewDescritor()) {
- setTitle("Application Description");
- }else{
- setTitle("Update Application Description: "+ getOriginalDescription().getType().getApplicationName().getStringValue());
- }
- setBounds(100, 100, 600, 620);
- setModal(true);
- setLocationRelativeTo(null);
- GridPanel buttonPane = new GridPanel();
-// getContentPane().setLayout(new BorderLayout());
- {
-
-// buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
-// getContentPane().add(buttonPane, BorderLayout.SOUTH);
-
- lblError = new JLabel("");
- lblError.setForeground(Color.RED);
- buttonPane.add(lblError);
- if (!isNewDescritor()){
- JButton resetButton = new JButton("Reset");
- resetButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- loadData();
- }
- });
- buttonPane.add(resetButton);
- }
- {
- okButton = new JButton("Save");
- if (!isNewDescritor()){
- okButton.setText("Update");
- }
- okButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- saveApplicationDescription();
- close();
- }
- });
- okButton.setEnabled(false);
- okButton.setActionCommand("OK");
- buttonPane.add(okButton);
- getRootPane().setDefaultButton(okButton);
- }
- {
- JButton cancelButton = new JButton("Cancel");
- cancelButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- setApplicationDescCreated(false);
- close();
- }
- });
- cancelButton.setActionCommand("Cancel");
- buttonPane.add(cancelButton);
- }
- }
- {
-// JPanel panel = new JPanel();
-// getContentPane().add(panel, BorderLayout.CENTER);
- JPanel execPath=new JPanel();
- txtExecPath = new XBayaTextField();
- txtExecPath.getTextField().addKeyListener(new KeyAdapter() {
- @Override
- public void keyReleased(KeyEvent e) {
- setExecutablePath(txtExecPath.getText());
- }
- });
- txtExecPath.getTextField().addFocusListener(new FocusAdapter() {
- @Override
- public void focusLost(FocusEvent e) {
- super.focusLost(e);
- updateTempDirWithExecPath(txtExecPath.getText());
- }
- });
- txtExecPath.setColumns(10);
- btnExecBrowse=new JButton(MenuIcons.OPEN_ICON);
- btnExecBrowse.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent arg0) {
- JFileChooser c = new JFileChooser();
- int rVal = c.showOpenDialog(null);
- if (rVal == JFileChooser.APPROVE_OPTION) {
- txtExecPath.setText(c.getSelectedFile().toString());
- setExecutablePath(txtExecPath.getText());
- }
- }
- });
- execPath.add(txtExecPath.getSwingComponent());
- execPath.add(btnExecBrowse);
- JButton btnIOParameters = new JButton("IO Parameters...");
- btnIOParameters.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent event) {
- try {
- ServiceDescriptionDialog serviceDescriptionDialog = new ServiceDescriptionDialog(getRegistry(),getServiceDescription()==null,getServiceDescription(),false,getApplicationName());
- serviceDescriptionDialog.setLocationRelativeTo(getContentPane());
- serviceDescriptionDialog.open();
- if (serviceDescriptionDialog.isServiceCreated()) {
- setServiceDescription(serviceDescriptionDialog.getServiceDescription());
- }
- } catch (Exception e1) {
- e1.printStackTrace();
- JOptionPane.showMessageDialog(null, e1.getLocalizedMessage());
- }
- }
- });
- execPath.add(new JLabel(" "));
- execPath.add(btnIOParameters);
-
- setupLayoutForBrowse(execPath,txtExecPath.getSwingComponent());
-
- txtAppName = new XBayaTextField();
- txtAppName.getTextField().addKeyListener(new KeyAdapter() {
- @Override
- public void keyReleased(KeyEvent arg0) {
- setApplicationName(txtAppName.getText());
- }
- });
- txtAppName.setColumns(10);
- XBayaLabel lblApplicationName = new XBayaLabel("Application name",txtAppName);
- JLabel lblExecutablePath = new JLabel("Executable path");
- JPanel tmpDirPath=new JPanel();
-
- txtTempDir = new XBayaTextField();
- txtTempDir.getTextField().addKeyListener(new KeyAdapter() {
- @Override
- public void keyReleased(KeyEvent e) {
- setTempDir(txtTempDir.getText());
- }
- });
- txtTempDir.setColumns(10);
- btnTmpDirBrowse=new JButton(MenuIcons.OPEN_DIR_ICON);
- btnTmpDirBrowse.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent arg0) {
- JFileChooser c = new JFileChooser();
- c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
- int rVal = c.showOpenDialog(null);
- if (rVal == JFileChooser.APPROVE_OPTION) {
- txtTempDir.setText(c.getSelectedFile().toString());
- setTempDir(txtTempDir.getText());
- }
- }
- });
- JTextField component = txtTempDir.getSwingComponent();
- tmpDirPath.add(component);
- tmpDirPath.add(btnTmpDirBrowse);
-// tmpDirPath.layout(1, 2, 0, 0);
-
- setupLayoutForBrowse(tmpDirPath, component);
-
-
- JLabel lblTemporaryDirectory = new JLabel("Scratch working directory");
-
- JButton btnAdvance = new JButton("Advanced application configurations...");
- btnAdvance.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- ApplicationDescriptionAdvancedOptionDialog serviceDescriptionDialog = new ApplicationDescriptionAdvancedOptionDialog(
- getRegistry(), getShellApplicationDescription());
- serviceDescriptionDialog.open();
- } catch (Exception e1) {
- e1.printStackTrace();
- JOptionPane.showMessageDialog(null, e1.getLocalizedMessage());
- }
- }
- });
-
-// cmbServiceName.setRenderer(new DefaultListCellRenderer());
- cmbHostName = new JComboBox();
- cmbHostName.addActionListener(this);
-
- XBayaLabel lblHostName = new XBayaLabel("Application host",cmbHostName);
-// lblHostName.getSwingComponent().setFont(new Font("Tahoma", Font.ITALIC, 11));
- XBayaLinkButton lnkNewHost = new XBayaLinkButton("New button");
- lnkNewHost.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- HostDescriptionDialog hostDescriptionDialog = new HostDescriptionDialog(engine.getConfiguration().getAiravataAPI(), null);
- hostDescriptionDialog.setLocationRelativeTo(getContentPane());
- hostDescriptionDialog.open();
-
- if (hostDescriptionDialog.isHostCreated()) {
- ProgressMonitor progressMonitor = new ProgressMonitor(getContentPane(), "Host Descriptions", "Refreshing host list..", 0, 200);
- int progress=1;
- progressMonitor.setProgress(progress++);
- while(cmbHostName.getSelectedIndex()==-1 || !cmbHostName.getSelectedItem().toString().equals(hostDescriptionDialog.getHostLocation())){
- loadHostDescriptions();
- cmbHostName.setSelectedItem(hostDescriptionDialog.getHostLocation());
- progressMonitor.setProgress(progress++);
- Thread.sleep(50);
- }
- progressMonitor.setProgress(200);
- }
- } catch (Exception e1) {
- e1.printStackTrace();
- JOptionPane.showMessageDialog(null, e1.getLocalizedMessage());
- }
- }
- });
- lnkNewHost.setText("Create new host...");
- lnkNewHost.setHorizontalAlignment(SwingConstants.TRAILING);
-
-// JLabel lblBindThisDeployment = new JLabel("Bind this deployment description to:");
-// lblBindThisDeployment.setFont(new Font("Tahoma", Font.BOLD, 11));
-
- btnHostAdvanceOptions=new JButton("HPC Configuration...");
- btnHostAdvanceOptions.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- try {
- ApplicationDescriptionHostAdvancedOptionDialog hostAdvancedOptionsDialog = new ApplicationDescriptionHostAdvancedOptionDialog(getRegistry(),getShellApplicationDescription());
- hostAdvancedOptionsDialog.open();
- } catch (Exception e1) {
- e1.printStackTrace();
- JOptionPane.showMessageDialog(null, e1.getLocalizedMessage());
- }
- }
- });
- btnHostAdvanceOptions.setVisible(false);
- GridPanel hostPanel=new GridPanel();
- hostPanel.add(cmbHostName);
- hostPanel.add(btnHostAdvanceOptions);
-
- SwingUtil.layoutToGrid(hostPanel.getSwingComponent(), 1, 2, 0, 0);
- GridPanel infoPanel0 = new GridPanel();
-
- infoPanel0.add(lblApplicationName);
- infoPanel0.add(txtAppName);
-
- GridPanel infoPanel1 = new GridPanel();
-
-
- infoPanel1.add(lblExecutablePath);
- infoPanel1.add(execPath);
-// infoPanel1.add(new JLabel());
-// infoPanel1.add(btnIOParameters);
- infoPanel1.add(lblTemporaryDirectory);
- infoPanel1.add(tmpDirPath);
-// infoPanel1.add(new JLabel());
-// infoPanel1.add(btnAdvance);
-
-// GridPanel infoPanel2 = new GridPanel();
-// infoPanel2.add(new JSeparator());
-// infoPanel2.add(lblBindThisDeployment);
-
- GridPanel infoPanel3 = new GridPanel();
-
- infoPanel3.add(lblHostName);
- infoPanel3.add(hostPanel);
- infoPanel3.add(new JLabel());
- infoPanel3.add(lnkNewHost);
-
- GridPanel infoPanel4=new GridPanel();
- infoPanel4.add(new JLabel());
- infoPanel4.add(btnAdvance);
- infoPanel4.layout(1, 2, 0, 0);
-
- SwingUtil.layoutToGrid(infoPanel0.getSwingComponent(), 1, 2, SwingUtil.WEIGHT_NONE, 1);
-
- SwingUtil.layoutToGrid(infoPanel1.getSwingComponent(), 4, 1, SwingUtil.WEIGHT_NONE, 0);
-// SwingUtil.layoutToGrid(infoPanel2.getSwingComponent(), 1, 1, SwingUtil.WEIGHT_NONE, 0);
- SwingUtil.layoutToGrid(infoPanel3.getSwingComponent(), 2, 2, SwingUtil.WEIGHT_NONE, 1);
-
- GridPanel infoPanel = new GridPanel();
- infoPanel.add(infoPanel0);
- infoPanel.add(new JSeparator());
- infoPanel.add(infoPanel1);
- infoPanel.add(new JSeparator());
-// infoPanel.add(infoPanel2);
- infoPanel.add(infoPanel3);
-
-
- infoPanel.add(new JSeparator());
- infoPanel.add(infoPanel4);
-
- SwingUtil.layoutToGrid(infoPanel.getSwingComponent(), 7, 1, SwingUtil.WEIGHT_NONE, 0);
- SwingUtil.layoutToGrid(buttonPane.getSwingComponent(), 1, buttonPane.getContentPanel().getComponentCount(),SwingUtil.WEIGHT_NONE,0);
- getContentPane().add(infoPanel.getSwingComponent());
- getContentPane().add(buttonPane.getSwingComponent());
-
- buttonPane.getSwingComponent().setBorder(BorderFactory.createEtchedBorder());
- infoPanel.getSwingComponent().setBorder(BorderFactory.createEtchedBorder());
-
- SwingUtil.layoutToGrid(getContentPane(), 2, 1, -1, 0);
-// loadServiceDescriptions();
- loadHostDescriptions();
- }
- setResizable(true);
- getRootPane().setDefaultButton(okButton);
- if (!isNewDescritor()){
- loadData();
- }
- pack();
- if (getSize().getWidth()<500){
- setSize(500, getSize().height);
- }
- }
-
- private void setupLayoutForBrowse(JPanel tmpDirPath, JTextField component) {
- GridBagLayout layout;
- GridBagConstraints constraints;
- layout = new GridBagLayout();
- constraints = new GridBagConstraints();
- constraints.fill = GridBagConstraints.BOTH;
- constraints.weightx = 1;
- layout.setConstraints(component, constraints);
- tmpDirPath.setLayout(layout);
- }
-
-// private void loadServiceDescriptions() {
-// cmbServiceName.removeAllItems();
-// setServiceName(null);
-// try {
-// List<ServiceDescription> serviceDescriptions = getRegistry().searchServiceDescription("");
-// for (ServiceDescription serviceDescription : serviceDescriptions) {
-// cmbServiceName.addItem(serviceDescription.getType().getName());
-// }
-// } catch (Exception e) {
-// setError(e.getLocalizedMessage());
-// }
-// updateServiceName();
-// }
-
- private void loadData(){
- txtAppName.setText(getOriginalDescription().getType().getApplicationName().getStringValue());
- setApplicationName(txtAppName.getText());
- txtExecPath.setText(getOriginalDescription().getType().getExecutableLocation());
- setExecutablePath(txtExecPath.getText());
- txtTempDir.setText(getOriginalDescription().getType().getScratchWorkingDirectory());
- setTempDir(txtTempDir.getText());
-
- cmbHostName.setSelectedItem(getOriginalHost());
- setHostName(cmbHostName.getSelectedItem().toString());
-// cmbServiceName.setSelectedItem(getOriginalService());
- setServiceName(null);
- txtAppName.setEditable(isNewDescritor());
- }
-
- private void loadHostDescriptions() {
- cmbHostName.removeAllItems();
- setHostName(null);
- try {
- List<HostDescription> hostDescriptions = getRegistry().getApplicationManager().getAllHostDescriptions();
- for (HostDescription hostDescription : hostDescriptions) {
- if (hostDescription.getType().getHostName() == null) {
- cmbHostName.addItem(hostDescription.getType().getHostName());
- } else {
- cmbHostName.addItem(hostDescription.getType().getHostName());
- }
- }
- } catch (Exception e) {
- setError(e.getLocalizedMessage());
- }
- updateHostName();
- }
-
- public ApplicationDescription getShellApplicationDescription() {
- if(shellApplicationDescription == null){
- if (isNewDescritor()) {
- shellApplicationDescription = new ApplicationDescription();
- }else{
- try {
- shellApplicationDescription= ApplicationDescription.fromXML(getOriginalDescription().toXML());
- } catch (XmlException e) {
- //shouldn't happen (hopefully)
- }
- }
- }
- return shellApplicationDescription;
- }
-
- public ApplicationDeploymentDescriptionType getApplicationDescriptionType() {
- return getShellApplicationDescription().getType();
- }
-
- public String getApplicationName() {
- return getApplicationDescriptionType().getApplicationName().getStringValue();
- }
-
- public void setApplicationName(String applicationName) {
-// ApplicationDeploymentDescriptionType.ApplicationName applicationName1 = getApplicationDescriptionType().addNewApplicationName();
-// applicationName1.setStringValue(applicationName);
- if (getApplicationDescriptionType().getApplicationName()==null){
- getApplicationDescriptionType().addNewApplicationName();
- }
- getApplicationDescriptionType().getApplicationName().setStringValue(applicationName);
- updateDialogStatus();
- }
-
- public String getExecutablePath() {
- return getApplicationDescriptionType().getExecutableLocation();
- }
-
- public void setExecutablePath(String executablePath) {
- getApplicationDescriptionType().setExecutableLocation(executablePath);
- updateTempDirWithExecPath(executablePath);
- updateDialogStatus();
- }
-
- private void updateTempDirWithExecPath(String executablePath) {
- if (!executablePath.trim().equals("") && (!txtExecPath.getSwingComponent().isFocusOwner()) &&
- (getApplicationDescriptionType().getScratchWorkingDirectory()==null || getApplicationDescriptionType().getScratchWorkingDirectory().trim().equalsIgnoreCase(""))){
- String temp_location = "workflow_runs";
- String tempDir = new File(new File(executablePath).getParentFile(),temp_location).toString();
- txtTempDir.setText(tempDir);
- txtTempDir.getSwingComponent().setSelectionStart(tempDir.length()-temp_location.length());
- txtTempDir.getSwingComponent().setSelectionEnd(tempDir.length());
- setTempDir(txtTempDir.getText());
- txtTempDir.getSwingComponent().requestFocus();
- }
- }
-
- public String getTempDir() {
- return getApplicationDescriptionType().getScratchWorkingDirectory();
- }
-
- public void setTempDir(String tempDir) {
- getApplicationDescriptionType().setScratchWorkingDirectory(tempDir);
- updateDialogStatus();
- }
-
- public void close() {
- getDialog().setVisible(false);
- }
-
- public void saveApplicationDescription() {
- try {
- try {
- getRegistry().getApplicationManager().saveApplicationDescription(getServiceName(), getHostName(), getShellApplicationDescription());
- } catch (AiravataAPIInvocationException e) {
- getRegistry().getApplicationManager().updateApplicationDescriptor(getServiceName(), getHostName(), getShellApplicationDescription());
- }
- if (!isNewDescritor() && (!getServiceName().equals(getOriginalService()) || !getHostName().equals(getOriginalHost()))) {
- try {
- getRegistry().getApplicationManager().deleteApplicationDescription(getOriginalService(),
- getOriginalHost(), getOriginalDescription().getType()
- .getApplicationName().getStringValue());
- } catch (AiravataAPIInvocationException e) {
- engine.getGUI().getErrorWindow().error(e);
- }
- }
- setApplicationDescCreated(true);
- } catch (AiravataAPIInvocationException e) {
- engine.getGUI().getErrorWindow().error(e);
- }
- }
-
- public boolean isApplicationDescCreated() {
- return applcationDescCreated;
- }
-
- public void setApplicationDescCreated(boolean applicationDescCreated) {
- this.applcationDescCreated = applicationDescCreated;
- }
-
- private void setError(String errorMessage) {
- if (errorMessage == null || errorMessage.trim().equals("")) {
- lblError.setText("");
- } else {
- lblError.setText(errorMessage.trim());
- }
- }
-
- private void updateDialogStatus() {
- String message = null;
- try {
- validateDialog();
- } catch (Exception e) {
- message = e.getLocalizedMessage();
- }
- okButton.setEnabled(message == null);
- setError(message);
- }
-
- private void validateDialog() throws Exception {
- if (getApplicationName() == null || getApplicationName().trim().equals("")) {
- throw new Exception("Name of the application cannot be empty!!!");
- }
-
- ApplicationDescription descriptions = null;
- try {
- descriptions = getRegistry().getApplicationManager().getApplicationDescriptor(getServiceName(), getHostName(),
- getApplicationName());
- } catch (AiravataAPIInvocationException e) {
- throw e;
- }
- if (descriptions !=null && (isNewDescritor() || (!getServiceName().equals(getOriginalService()) || !getHostName().equals(getOriginalHost())))) {
- throw new Exception("Application name already exists for the selected service & host!!!");
- }
-
- if (getExecutablePath() == null || getExecutablePath().trim().equals("")) {
- throw new Exception("Executable path cannot be empty!!!");
- }
-
- if (getTempDir() == null || getTempDir().trim().equals("")) {
- throw new Exception("Temporary directory location cannot be empty!!!");
- }
-
- if (getServiceName() == null || getServiceName().trim().equals("")) {
- throw new Exception("Click on IO Parameters... to define parameters for the application");
- }
-
- if (getHostName() == null || getHostName().trim().equals("")) {
- throw new Exception("Please select/create host to bind to this deployment description");
- }
-
- }
-
- public String getServiceName() {
- return serviceName;
- }
-
- public void setServiceName(String serviceName) {
- this.serviceName = serviceName;
- updateDialogStatus();
- }
-
- public String getHostName() {
- return hostName;
- }
-
- public void setHostName(String hostName) {
- this.hostName = hostName;
- if (hostName!=null) {
- HostDescription hostDescription;
- try {
- hostDescription = registry.getApplicationManager().getHostDescription(hostName);
- if (hostDescription.getType() instanceof GlobusHostType) {
- getShellApplicationDescription().getType().changeType(
- HpcApplicationDeploymentType.type);
- } else if (hostDescription.getType() instanceof GsisshHostType) {
- getShellApplicationDescription().getType().changeType(
- HpcApplicationDeploymentType.type);
- } else if (hostDescription.getType() instanceof SSHHostType && ((SSHHostType)hostDescription.getType()).getHpcResource()) {
- getShellApplicationDescription().getType().changeType(
- HpcApplicationDeploymentType.type);
- } else {
- getShellApplicationDescription().getType().changeType(
- ApplicationDeploymentDescriptionType.type);
- }
- btnHostAdvanceOptions.setVisible(getShellApplicationDescription().getType() instanceof HpcApplicationDeploymentType);
- String hostAddress = hostDescription.getType().getHostAddress();
- boolean isLocal = isLocalAddress(hostAddress);
- btnExecBrowse.setVisible(isLocal);
- btnTmpDirBrowse.setVisible(isLocal);
-
- } catch (AiravataAPIInvocationException e) {
- //not there - ouch
- }
- }
- updateDialogStatus();
- }
-
- private boolean isLocalAddress(String hostAddress) {
- return hostAddress.equalsIgnoreCase("localhost") || hostAddress.equalsIgnoreCase("127.0.0.1");
- }
-
- private void updateServiceName() {
- if (getServiceDescription() == null) {
- setServiceName(null);
- }else{
- setServiceName(getServiceDescription().getType().getName());
- }
- }
-
- private void updateHostName() {
- if (cmbHostName.getSelectedItem() != null) {
- setHostName(cmbHostName.getSelectedItem().toString());
- }
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
-// if (e.getSource() == cmbServiceName) {
-// updateServiceName();
-// }
- if (e.getSource() == cmbHostName) {
- updateHostName();
- }
- if (e.getSource() == txtAppName) {
- setApplicationName(txtAppName.getText());
- }
- if (e.getSource() == txtExecPath) {
- setExecutablePath(txtExecPath.getText());
- }
- if (e.getSource() == txtTempDir) {
- setTempDir(txtTempDir.getText());
- }
- }
-
- public AiravataAPI getRegistry() {
- return registry;
- }
-
- public void setRegistry(AiravataAPI registry) {
- this.registry = registry;
- }
-
- public boolean isNewDescritor() {
- return newDescritor;
- }
-
- public void setNewDescritor(boolean newDescritor) {
- this.newDescritor = newDescritor;
- }
-
- public ApplicationDescription getOriginalDescription() {
- return originalDescription;
- }
-
- public void setOriginalDescription(
- ApplicationDescription originalDescription) {
- this.originalDescription = originalDescription;
- }
-
- public String getOriginalService() {
- return originalService;
- }
-
- public void setOriginalService(String originalService) {
- this.originalService = originalService;
- }
-
- public String getOriginalHost() {
- return originalHost;
- }
-
- public void setOriginalHost(String originalHost) {
- this.originalHost = originalHost;
- }
-
- public ServiceDescription getServiceDescription() {
- return serviceDescription;
- }
-
- private void setServiceDescription(ServiceDescription serviceDescription) {
- this.serviceDescription = serviceDescription;
- updateServiceName();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/3e6c815a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/descriptors/ApplicationDescriptionHostAdvancedOptionDialog.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/descriptors/ApplicationDescriptionHostAdvancedOptionDialog.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/descriptors/ApplicationDescriptionHostAdvancedOptionDialog.java
deleted file mode 100644
index ac7d234..0000000
--- a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/descriptors/ApplicationDescriptionHostAdvancedOptionDialog.java
+++ /dev/null
@@ -1,459 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.airavata.xbaya.ui.dialogs.descriptors;
-
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.swing.BorderFactory;
-import javax.swing.DefaultComboBoxModel;
-import javax.swing.JButton;
-import javax.swing.JDialog;
-import javax.swing.JOptionPane;
-import javax.swing.JScrollPane;
-
-import org.apache.airavata.client.api.AiravataAPI;
-import org.apache.airavata.common.utils.SwingUtil;
-import org.apache.airavata.commons.gfac.type.ApplicationDescription;
-import org.apache.airavata.schemas.gfac.HpcApplicationDeploymentType;
-import org.apache.airavata.schemas.gfac.JobTypeType;
-import org.apache.airavata.schemas.gfac.JobTypeType.Enum;
-import org.apache.airavata.schemas.gfac.ProjectAccountType;
-import org.apache.airavata.schemas.gfac.QueueType;
-import org.apache.airavata.xbaya.ui.widgets.GridPanel;
-import org.apache.airavata.xbaya.ui.widgets.XBayaComboBox;
-import org.apache.airavata.xbaya.ui.widgets.XBayaLabel;
-import org.apache.airavata.xbaya.ui.widgets.XBayaTextField;
-//import org.apache.airavata.registry.api.AiravataRegistry2;
-
-public class ApplicationDescriptionHostAdvancedOptionDialog extends JDialog {
- private static final long serialVersionUID = 3920479739097405014L;
- private XBayaComboBox cmbJobType;
- private XBayaTextField txtProjectAccountNumber;
- private XBayaTextField txtProjectAccountDescription;
- private XBayaTextField txtQueueType;
- private XBayaTextField txtMaxWallTime = new XBayaTextField();
- private XBayaTextField txtMinMemory = new XBayaTextField();
- private XBayaTextField txtMaxMemory = new XBayaTextField();
- private XBayaTextField txtCpuCount = new XBayaTextField();
- private XBayaTextField txtNodeCount = new XBayaTextField();
- private XBayaTextField txtProcessorsPerNode = new XBayaTextField();
- private JButton okButton;
- private AiravataAPI registry;
- private ApplicationDescription descriptor;
- private XBayaLabel lblCpuCount;
- private XBayaLabel lblProcessorPerNode;
- private XBayaLabel lbNodeCount;
- private XBayaTextField txtjobSubmitterCommand;
- private XBayaTextField txtinstalledParentPath;
-
- /**
- * Create the dialog.
- */
- public ApplicationDescriptionHostAdvancedOptionDialog(AiravataAPI registry, ApplicationDescription descriptor) {
- addWindowListener(new WindowAdapter() {
- @Override
- public void windowOpened(WindowEvent arg0) {
- loadApplicationDescriptionAdvancedOptions();
- }
- });
- setRegistry(registry);
- setShellApplicationDescription(descriptor);
- initGUI();
- }
-
- public void open() {
- setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
- setVisible(true);
- }
-
- protected ApplicationDescriptionHostAdvancedOptionDialog getDialog() {
- return this;
- }
-
- public void close() {
- getDialog().setVisible(false);
- }
-
- private void initGUI() {
- setTitle("HPC Configuration Options");
- setModal(true);
- setBounds(100, 100, 500, 500);
- setLocationRelativeTo(null);
- GridPanel buttonPane = new GridPanel();
- okButton = new JButton("Update");
- okButton.setActionCommand("OK");
- okButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if (saveApplicationDescriptionAdvancedOptions()){
- close();
- }
- }
- });
- getRootPane().setDefaultButton(okButton);
-
- JButton cancelButton = new JButton("Cancel");
- cancelButton.setActionCommand("Cancel");
- cancelButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- close();
- }
- });
-
-
- GridPanel panel = new GridPanel();
- txtProjectAccountNumber = new XBayaTextField();
- txtProjectAccountDescription = new XBayaTextField();
-
- txtQueueType = new XBayaTextField();
- txtMaxWallTime = new XBayaTextField();
- txtMinMemory = new XBayaTextField();
- txtMaxMemory = new XBayaTextField();
- txtCpuCount = new XBayaTextField();
- txtProcessorsPerNode = new XBayaTextField();
- txtNodeCount = new XBayaTextField();
- txtjobSubmitterCommand = new XBayaTextField();
- txtinstalledParentPath = new XBayaTextField();
-
-
- DefaultComboBoxModel cmbModelJobType = new DefaultComboBoxModel(getJobTypesAsStrings());
- cmbJobType = new XBayaComboBox(cmbModelJobType);
- cmbJobType.setEditable(false);
- //FIXME:: Machines like trestles are mandating to have cpu and node types set. So better to have these enabled.
-// cmbJobType.getSwingComponent().addActionListener(new ActionListener(){
-// @Override
-// public void actionPerformed(ActionEvent arg0) {
-// boolean disabled=cmbJobType.getText().equalsIgnoreCase(JobTypeType.SERIAL.toString()) || cmbJobType.getText().equalsIgnoreCase(JobTypeType.SINGLE.toString());
-// txtCpuCount.setEnabled(!disabled);
-// txtProcessorsPerNode.setEnabled(!disabled);
-// lblCpuCount.getSwingComponent().setEnabled(!disabled);
-// lblProcessorPerNode.getSwingComponent().setEnabled(!disabled);
-// }
-// });
-
- XBayaLabel lbljobType = new XBayaLabel("Job Type",cmbJobType);
- XBayaLabel lblProjectAccountNumber = new XBayaLabel("Project Account Number *",txtProjectAccountNumber);
- XBayaLabel lblProjectAccountDescription = new XBayaLabel("Project Account Description",txtProjectAccountDescription);
- XBayaLabel lblQueueType = new XBayaLabel("Queue Type *",txtQueueType);
- XBayaLabel lblMaxWallTime = new XBayaLabel("Max Wall Time",txtMaxWallTime);
- lblCpuCount = new XBayaLabel("CPU Count",txtCpuCount);
- lblProcessorPerNode = new XBayaLabel("Processor Per Node", txtProcessorsPerNode);
- XBayaLabel lblMinMemory = new XBayaLabel("Min Memory",txtMinMemory);
- XBayaLabel lblMaxMemory = new XBayaLabel("Max Memory",txtMaxMemory);
- lbNodeCount = new XBayaLabel("Node Count", txtNodeCount);
- XBayaLabel lbljobSubmitterCommand = new XBayaLabel("Job Submitter Command",txtjobSubmitterCommand);
- XBayaLabel lblinstalledParentPath = new XBayaLabel("Installed Parent Path",txtinstalledParentPath);
-
- panel.add(lbljobType);
- panel.add(cmbJobType);
- panel.add(lblProjectAccountNumber);
- panel.add(txtProjectAccountNumber);
- panel.add(lblProjectAccountDescription);
- panel.add(txtProjectAccountDescription);
- panel.add(lblQueueType);
- panel.add(txtQueueType);
- panel.add(lblMaxWallTime);
- panel.add(txtMaxWallTime);
- panel.add(lblCpuCount);
- panel.add(txtCpuCount);
- panel.add(lbNodeCount);
- panel.add(txtNodeCount);
- panel.add(lblProcessorPerNode);
- panel.add(txtProcessorsPerNode);
- panel.add(lblMinMemory);
- panel.add(txtMinMemory);
- panel.add(lblMaxMemory);
- panel.add(txtMaxMemory);
- panel.add(lbljobSubmitterCommand);
- panel.add(txtjobSubmitterCommand);
- panel.add(lblinstalledParentPath);
- panel.add(txtinstalledParentPath);
- panel.getSwingComponent().setBorder(BorderFactory.createEtchedBorder());
- buttonPane.getSwingComponent().setBorder(BorderFactory.createEtchedBorder());
-
- SwingUtil.layoutToGrid(panel.getSwingComponent(), 12, 2, SwingUtil.WEIGHT_NONE, 1);
-
- buttonPane.add(okButton);
- buttonPane.add(cancelButton);
-
- JScrollPane thePane = new JScrollPane(panel.getSwingComponent());
-
- getContentPane().add(thePane);
- getContentPane().add(buttonPane.getSwingComponent());
- SwingUtil.layoutToGrid(getContentPane(), 2, 1, 0, 0);
- setResizable(true);
- getRootPane().setDefaultButton(okButton);
- }
-
- private static List<JobTypeType.Enum> jobTypes;
-
- private List<JobTypeType.Enum> getJobTypes() {
- if (jobTypes==null){
- jobTypes = new ArrayList<Enum>();
- jobTypes.add(JobTypeType.SERIAL);
- jobTypes.add(JobTypeType.OPEN_MP);
- jobTypes.add(JobTypeType.MPI);
-// jobTypes.add(JobTypeType.SINGLE);
- }
- return jobTypes;
- }
-
- private String[] getJobTypesAsStrings() {
- List<String> typeList=new ArrayList<String>();
- for (Enum jtype : getJobTypes()) {
- typeList.add(jtype.toString());
- }
- return typeList.toArray(new String[]{});
- }
-
- private Enum getJobTypeEnum(String jobTypeString){
- for (Enum jtype : getJobTypes()) {
- if (jtype.toString().equalsIgnoreCase(jobTypeString)){
- return jtype;
- }
- }
- return null;
- }
-
- public ApplicationDescription getApplicationDescription() {
- return descriptor;
- }
-
- public HpcApplicationDeploymentType getHPCApplicationDescriptionType() {
- return (HpcApplicationDeploymentType)descriptor.getType();
- }
-
- public void setShellApplicationDescription(ApplicationDescription shellApplicationDescription) {
- this.descriptor = shellApplicationDescription;
- }
-
- private boolean isValueNotEmpty(String s){
- return !s.trim().isEmpty();
- }
-
- private void showError(String message, String title){
- JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
- }
- private boolean saveApplicationDescriptionAdvancedOptions() {
- if (isValueNotEmpty(cmbJobType.getText())) {
- getHPCApplicationDescriptionType().setJobType(
- getJobTypeEnum(cmbJobType.getText()));
- }
- try {
- if (isValueNotEmpty(txtMaxWallTime.getText())) {
- getHPCApplicationDescriptionType().setMaxWallTime(
- Integer.parseInt(txtMaxWallTime.getText()));
- }
- } catch (NumberFormatException e) {
- showError("Max wall time must be a number", "Invalid value");
- return false;
- }
- try {
- if (isValueNotEmpty(txtCpuCount.getText())) {
- getHPCApplicationDescriptionType().setCpuCount(
- Integer.parseInt(txtCpuCount.getText()));
- }
- } catch (NumberFormatException e) {
- showError("CPU count must be a number", "Invalid value");
- return false;
- }
- try {
- if (isValueNotEmpty(txtProcessorsPerNode.getText())) {
- getHPCApplicationDescriptionType().setProcessorsPerNode(
- Integer.parseInt(txtProcessorsPerNode.getText()));
- }
- } catch (NumberFormatException e) {
- showError("Processors per node must be a number", "Invalid value");
- return false;
- }
- try {
- if (isValueNotEmpty(txtNodeCount.getText())) {
- getHPCApplicationDescriptionType().setNodeCount(
- Integer.parseInt(txtNodeCount.getText()));
- }
- } catch (NumberFormatException e) {
- showError("Node count must be a number", "Invalid value");
- return false;
- }
- try {
- if (isValueNotEmpty(txtMinMemory.getText())) {
- getHPCApplicationDescriptionType().setMinMemory(
- Integer.parseInt(txtMinMemory.getText()));
- }
- } catch (NumberFormatException e) {
- showError("Minimum memory must be a number", "Invalid value");
- return false;
- }
- try {
- if (isValueNotEmpty(txtMaxMemory.getText())) {
- getHPCApplicationDescriptionType().setMaxMemory(
- Integer.parseInt(txtMaxMemory.getText()));
- }
- } catch (NumberFormatException e) {
- showError("Maximum memory must be a number", "Invalid value");
- return false;
- }
- try {
- if (isValueNotEmpty(txtjobSubmitterCommand.getText())) {
- getHPCApplicationDescriptionType().setJobSubmitterCommand(
- txtjobSubmitterCommand.getText());
- }else{
- getHPCApplicationDescriptionType().setJobSubmitterCommand(null);
- }
- } catch (NumberFormatException e) {
- showError("Maximum memory must be a number", "Invalid value");
- return false;
- }
- try {
- if (isValueNotEmpty(txtinstalledParentPath.getText())) {
- getHPCApplicationDescriptionType().setInstalledParentPath(
- txtinstalledParentPath.getText());
- }else{
- getHPCApplicationDescriptionType().setInstalledParentPath(null);
- }
- } catch (NumberFormatException e) {
- showError("Maximum memory must be a number", "Invalid value");
- return false;
- }
- ProjectAccountType projectAccount = getProjectAccountType();
- if (isValueNotEmpty(txtProjectAccountNumber.getText())) {
- projectAccount.setProjectAccountNumber(txtProjectAccountNumber
- .getText());
- }
- if (isValueNotEmpty(txtProjectAccountDescription.getText())) {
- projectAccount
- .setProjectAccountDescription(txtProjectAccountDescription
- .getText());
- }
- if (isValueNotEmpty(txtQueueType.getText())) {
- QueueType queueName = getQueueName();
- queueName.setQueueName(txtQueueType.getText());
- }
- return true;
- }
-
- private QueueType getQueueName() {
- if (getHPCApplicationDescriptionType().getQueue()==null){
- getHPCApplicationDescriptionType().addNewQueue();
- }
- return getHPCApplicationDescriptionType().getQueue();
- }
-
- private ProjectAccountType getProjectAccountType() {
- if (getHPCApplicationDescriptionType().getProjectAccount()==null){
- getHPCApplicationDescriptionType().addNewProjectAccount();
- }
- return getHPCApplicationDescriptionType().getProjectAccount();
- }
-
- private String getPropValue(int num){
- if (num==0){
- return "";
- }else{
- return String.valueOf(num);
- }
- }
-
- private void loadApplicationDescriptionAdvancedOptions() {
- HpcApplicationDeploymentType hpcAppType = getHPCApplicationDescriptionType();
- if (hpcAppType.getJobType()!=null) {
- cmbJobType.setSelectedItem(hpcAppType
- .getJobType().toString());
- }
- txtMaxWallTime.setText(getPropValue(hpcAppType.getMaxWallTime()));
- txtCpuCount.setText(getPropValue(hpcAppType.getCpuCount()));
- txtNodeCount.setText(getPropValue(hpcAppType.getNodeCount()));
- txtProcessorsPerNode.setText(getPropValue(hpcAppType.getProcessorsPerNode()));
- txtMinMemory.setText(getPropValue(hpcAppType.getMinMemory()));
- txtMaxMemory.setText(getPropValue(hpcAppType.getMaxMemory()));
- txtNodeCount.setText(getPropValue(hpcAppType.getNodeCount()));
- txtjobSubmitterCommand.setText(hpcAppType.getJobSubmitterCommand()==null?"":hpcAppType.getJobSubmitterCommand());
- txtinstalledParentPath.setText(hpcAppType.getInstalledParentPath()==null?"":hpcAppType.getInstalledParentPath());
- ProjectAccountType projectAccount = getProjectAccountType();
-
- txtProjectAccountNumber.setText(projectAccount.getProjectAccountNumber()==null? "":projectAccount.getProjectAccountNumber());
- txtProjectAccountDescription.setText(projectAccount.getProjectAccountDescription()==null? "":projectAccount.getProjectAccountDescription());
-
- QueueType queueName = getQueueName();
- txtQueueType.setText(queueName.getQueueName()==null?"":queueName.getQueueName());
- }
-
- public AiravataAPI getRegistry() {
- return registry;
- }
-
- public void setRegistry(AiravataAPI registry) {
- this.registry = registry;
- }
-
- // private void updateDialogStatus(){
- // String message=null;
- // try {
- // validateDialog();
- // } catch (Exception e) {
- // message=e.getLocalizedMessage();
- // }
- // okButton.setEnabled(message==null);
- // setError(message);
- // }
- //
- // private void validateDialog() throws Exception{
- // if (getApplicationName()==null || getApplicationName().trim().equals("")){
- // throw new Exception("Name of the application cannot be empty!!!");
- // }
- //
- // List<ApplicationDeploymentDescription> deploymentDescriptions=null;
- // try {
- // deploymentDescriptions = getJCRComponentRegistry().getRegistry().searchApplicationDescription(getServiceName(),
- // getHostName(), Pattern.quote(getApplicationName()));
- // } catch (PathNotFoundException e) {
- // //what we want
- // } catch (Exception e){
- // throw e;
- // }
- // if (deploymentDescriptions.size()>0){
- // throw new Exception("Application descriptor with the given name already exists!!!");
- // }
- //
- // if (getExecutablePath()==null || getExecutablePath().trim().equals("")){
- // throw new Exception("Executable path cannot be empty!!!");
- // }
- //
- // if (getTempDir()==null || getTempDir().trim().equals("")){
- // throw new Exception("Temporary directory location cannot be empty!!!");
- // }
- //
- // if (getServiceName()==null || getServiceName().trim().equals("")){
- // throw new Exception("Please select/create service to bind to this deployment description");
- // }
- //
- // if (getHostName()==null || getHostName().trim().equals("")){
- // throw new Exception("Please select/create host to bind to this deployment description");
- // }
- //
- // }
-
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/3e6c815a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/descriptors/DeploymentDescriptionDialog.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/descriptors/DeploymentDescriptionDialog.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/descriptors/DeploymentDescriptionDialog.java
deleted file mode 100644
index 8b52d01..0000000
--- a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/descriptors/DeploymentDescriptionDialog.java
+++ /dev/null
@@ -1,816 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.airavata.xbaya.ui.dialogs.descriptors;
-
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.KeyAdapter;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.swing.*;
-import javax.swing.event.ListSelectionEvent;
-import javax.swing.event.ListSelectionListener;
-import javax.swing.event.TableModelEvent;
-import javax.swing.event.TableModelListener;
-import javax.swing.table.DefaultTableModel;
-import javax.swing.table.TableColumn;
-import javax.xml.namespace.QName;
-
-import org.apache.airavata.client.api.AiravataAPI;
-import org.apache.airavata.client.api.exception.AiravataAPIInvocationException;
-import org.apache.airavata.commons.gfac.type.ApplicationDescription;
-import org.apache.airavata.common.utils.SwingUtil;
-import org.apache.airavata.commons.gfac.type.ServiceDescription;
-//import org.apache.airavata.registry.api.AiravataRegistry2;
-import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
-import org.apache.airavata.schemas.gfac.DataType;
-import org.apache.airavata.schemas.gfac.HostDescriptionType;
-import org.apache.airavata.schemas.gfac.InputParameterType;
-import org.apache.airavata.schemas.gfac.OutputParameterType;
-import org.apache.airavata.schemas.gfac.ParameterType;
-import org.apache.airavata.schemas.gfac.ServiceDescriptionType;
-import org.apache.airavata.xbaya.ui.dialogs.descriptors.HostDeploymentDialog.HostDeployment;
-import org.apache.airavata.xbaya.ui.widgets.GridPanel;
-import org.apache.airavata.xbaya.ui.widgets.XBayaLabel;
-import org.apache.airavata.xbaya.ui.widgets.XBayaTextField;
-import org.apache.xmlbeans.XmlCursor;
-
-public class DeploymentDescriptionDialog extends JDialog {
-
- private static final long serialVersionUID = 2705760838264284423L;
- private final GridPanel contentPanel = new GridPanel();
- private XBayaLabel lblServiceName;
- private XBayaTextField txtApplicationServiceName;
- private JTable tblParameters;
- private boolean serviceCreated = false;
- private JLabel lblError;
- private ServiceDescription serviceDescription;
- private ServiceDescription orginalServiceDescription;
- private JButton okButton;
- private JButton btnDeleteParameter;
- private DefaultTableModel defaultTableModel;
- private AiravataAPI registry;
- private boolean newDescription;
- private boolean ignoreTableChanges=false;
- private JCheckBox chkForceFileStagingToWorkDir;
- private String suggestedNamePrefix;
- private String titlePrefix;
- private Map<String,HostDeployment> deployments;
- private JTable tblHosts;
- private DefaultTableModel tblModelHosts;
-
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- try {
- DeploymentDescriptionDialog dialog = new DeploymentDescriptionDialog(null,true,null,null);
- dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
- dialog.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public DeploymentDescriptionDialog(JFrame parent, AiravataAPI registry) {
- this(registry, true, null, parent);
- }
-
-// public DeploymentDescriptionDialog(Frame parent) {
-// super(parent);
-// }
-
- /**
- * Create the dialog.
- */
- public DeploymentDescriptionDialog(AiravataAPI registry, boolean newDescription, ServiceDescription serviceDescription, JFrame parent) {
- super(parent);
- setNewDescription(newDescription);
- this.setOrginalServiceDescription(serviceDescription);
- setSuggestedNamePrefix(suggestedNamePrefix);
-
- if (isNewDescription()) {
- setTitlePrefix("Register Application");
- }else{
- setTitlePrefix("Update Application: "+getOrginalServiceDescription().getType().getName());
- }
- addWindowListener(new WindowAdapter() {
- @Override
- public void windowOpened(WindowEvent arg0) {
-// if (isNewDescription()) {
-// String baseName = "Application";
-// int i;
-// String defaultName;
-// i = 1;
-// defaultName = baseName+i;
-// try {
-// while (getRegistry().getServiceDescription(defaultName) != null) {
-// defaultName = baseName + (++i);
-// }
-// } catch (Exception e) {
-// }
-// txtApplicationServiceName.setText(defaultName);
-// setServiceName(txtApplicationServiceName.getText());
-// }
- }
- });
- setRegistry(registry);
- initGUI();
-
- }
-
- public void open() {
-// pack();
-// setAlwaysOnTop(true);
- setLocationRelativeTo(getOwner());
- setModal(true);
- setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
- setVisible(true);
- }
-
- protected DeploymentDescriptionDialog getDialog() {
- return this;
- }
-
- private void initGUI() {
- setTitle(getTitlePrefix());
- setBounds(100, 100, 463, 459);
- setModal(true);
- setLocationRelativeTo(null);
- BorderLayout borderLayout = new BorderLayout();
- borderLayout.setVgap(5);
- borderLayout.setHgap(5);
- getContentPane().setLayout(borderLayout);
-
- txtApplicationServiceName = new XBayaTextField();
- txtApplicationServiceName.getSwingComponent().addKeyListener(new KeyAdapter() {
- @Override
- public void keyReleased(KeyEvent e) {
- setServiceName(txtApplicationServiceName.getText());
- }
- });
- txtApplicationServiceName.setColumns(10);
- lblServiceName = new XBayaLabel("Application name",txtApplicationServiceName);
- JLabel lblInputParameters = new JLabel("Application Parameters");
- lblInputParameters.setFont(new Font("Tahoma", Font.BOLD, 11));
-
- JScrollPane scrollPane = new JScrollPane();
- tblParameters=createParameterTableControls();
- scrollPane.setViewportView(tblParameters);
-
- chkForceFileStagingToWorkDir=new JCheckBox("Advanced: Force input file staging to working directory");
- chkForceFileStagingToWorkDir.addActionListener(new ActionListener(){
-
- public void actionPerformed(ActionEvent arg0) {
- setForceFileStagingToWorkDir(chkForceFileStagingToWorkDir.isSelected());
- }
-
- });
- GridPanel buttonPane = new GridPanel();
- {
- GridBagLayout gbl_buttonPane = new GridBagLayout();
- gbl_buttonPane.columnWidths = new int[] { 307, 136, 0 };
- gbl_buttonPane.rowHeights = new int[] { 33, 0 };
- gbl_buttonPane.columnWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
- gbl_buttonPane.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
-
-
- lblError = new JLabel("");
- lblError.setForeground(Color.RED);
- GridBagConstraints gbc_lblError = new GridBagConstraints();
- gbc_lblError.insets = new Insets(0, 0, 0, 5);
- gbc_lblError.gridx = 0;
- gbc_lblError.gridy = 0;
- buttonPane.add(lblError);
- JPanel panel = new JPanel();
- GridBagConstraints gbc_panel = new GridBagConstraints();
- gbc_panel.anchor = GridBagConstraints.NORTHWEST;
- gbc_panel.gridx = 1;
- gbc_panel.gridy = 0;
- buttonPane.add(panel);
- {
- JButton resetButton = new JButton("Reset");
- resetButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- loadData();
- }
- });
- panel.add(resetButton);
- }
- {
- okButton = new JButton("Register");
- if (!isNewDescription()){
- okButton.setText("Update");
- }
- okButton.setEnabled(false);
- okButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- if ("Register".equals(okButton.getText())) {
- saveServiceDescription(false);
- } else {
- saveServiceDescription(true);
- }
- close();
- } catch (AiravataAPIInvocationException e1) {
- e1.printStackTrace();
- }
- }
- });
- panel.add(okButton);
- okButton.setActionCommand("OK");
- getRootPane().setDefaultButton(okButton);
- }
- {
- JButton cancelButton = new JButton("Cancel");
- cancelButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- setServiceCreated(false);
- close();
- }
- });
- panel.add(cancelButton);
- cancelButton.setActionCommand("Cancel");
- }
- }
- contentPanel.add(lblServiceName);
- contentPanel.add(txtApplicationServiceName);
- GridPanel pnlTables=new GridPanel();
-
- GridPanel parameterPanel=new GridPanel();
- parameterPanel.add(lblInputParameters);
- parameterPanel.add(scrollPane);
- parameterPanel.add(btnDeleteParameter);
- parameterPanel.add(chkForceFileStagingToWorkDir);
-
- SwingUtil.layoutToGrid(contentPanel.getSwingComponent(), 1, 2, SwingUtil.WEIGHT_NONE, 1);
- SwingUtil.layoutToGrid(parameterPanel.getSwingComponent(), 4, 1, 1, 0);
-
- pnlTables.add(parameterPanel);
- pnlTables.add(createHostDeploymentTable());
-
- pnlTables.layout(2, 1, SwingUtil.WEIGHT_EQUALLY, 0);
-
- GridPanel infoPanel = new GridPanel();
- infoPanel.add(contentPanel);
- infoPanel.add(pnlTables);
- infoPanel.getSwingComponent().setBorder(BorderFactory.createEtchedBorder());
- infoPanel.layout(2, 1, 1, 0);
- getContentPane().add(infoPanel.getSwingComponent());
- getContentPane().add(buttonPane.getSwingComponent());
- buttonPane.getSwingComponent().setBorder(BorderFactory.createEtchedBorder());
- SwingUtil.layoutToGrid(getContentPane(), 2, 1, 0, 0);
- setResizable(true);
- getRootPane().setDefaultButton(okButton);
- if (!isNewDescription()){
- loadData();
- }
- }
-
- private GridPanel createHostDeploymentTable() {
- tblHosts = new JTable();
- tblHosts.setTableHeader(null);
- tblHosts.setFillsViewportHeight(true);
- tblModelHosts = new DefaultTableModel(new Object[][] {}, new String[] { "Host"}){
- private static final long serialVersionUID = -5973463590447809117L;
- @Override
- public boolean isCellEditable(int row, int column) {
- return false;
- }
- };
- tblHosts.setModel(tblModelHosts);
-
- ListSelectionModel selectionModel = tblHosts.getSelectionModel();
- selectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
-
- JButton btnNewDeployment = new JButton("New deployment");
- btnNewDeployment.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- HostDeploymentDialog hostDeploymentDialog = new HostDeploymentDialog(getRegistry(),true,null,null,Arrays.asList(getDeployments().keySet().toArray(new String[]{})));
- try {
- HostDeployment deployDesc = hostDeploymentDialog.execute();
- if (deployDesc!=null){
- ApplicationDeploymentDescriptionType appType = deployDesc.getApplicationDescription().getType();
- if (appType.getApplicationName()==null){
- appType.addNewApplicationName();
- }
- HostDescriptionType hostType = deployDesc.getHostDescription().getType();
- appType.getApplicationName().setStringValue(hostType.getHostName()+"_application");
- getDeployments().put(hostType.getHostName(), deployDesc);
- updateDeploymentTable();
- }
- } catch (AiravataAPIInvocationException e1) {
- setError(e1.getLocalizedMessage());
- e1.printStackTrace();
- }
- }
- });
-
- final JButton btnEditDeployment = new JButton("Edit deployment");
- btnEditDeployment.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- editSelectedDeployment();
- }
- });
-
- final JButton btnDeleteDeployment = new JButton("Delete deployment");
- btnDeleteDeployment.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String hostName = tblModelHosts.getValueAt(tblHosts.getSelectedRow(),0).toString();
- int result = JOptionPane.showConfirmDialog(null, "Are you sure you want to remove the host deployment '"+hostName+"'?", "Remove Host Deployment",
- JOptionPane.YES_NO_OPTION);
- if (result==JOptionPane.YES_OPTION){
- tblModelHosts.removeRow(tblHosts.getSelectedRow());
- getDeployments().remove(hostName);
- }
- }
- });
-
- selectionModel.addListSelectionListener(new ListSelectionListener() {
- public void valueChanged(ListSelectionEvent e) {
- btnEditDeployment.setEnabled(tblHosts.getSelectedRows().length > 0);
- btnDeleteDeployment.setEnabled(tblHosts.getSelectedRows().length > 0);
- }
-
- });
- tblHosts.addMouseListener(new MouseAdapter(){
- @Override
- public void mouseClicked(MouseEvent e) {
- if (e.getClickCount()==2 && tblHosts.getSelectedRows().length>0){
- editSelectedDeployment();
- }
- }
- });
- JScrollPane scrollPane = new JScrollPane();
- scrollPane.setViewportView(tblHosts);
-
- GridPanel pnlTableButtons = new GridPanel();
- pnlTableButtons.add(btnNewDeployment);
- pnlTableButtons.add(btnEditDeployment);
- pnlTableButtons.add(btnDeleteDeployment);
- pnlTableButtons.layout(1, 3,SwingUtil.WEIGHT_NONE,SwingUtil.WEIGHT_EQUALLY);
-
- GridPanel pnlMainPanel = new GridPanel();
- pnlMainPanel.add(scrollPane);
-
- pnlMainPanel.add(pnlTableButtons);
- pnlMainPanel.layout(2, 1, 0, 0);
- btnEditDeployment.setEnabled(false);
- btnDeleteDeployment.setEnabled(false);
- return pnlMainPanel;
- }
-
- private void updateDeploymentTable(){
- List<String> hosts=new ArrayList<String>();
- for (int i = 0; i < tblModelHosts.getRowCount(); i++) {
- hosts.add((String) tblModelHosts.getValueAt(i, 0));
- }
- for (String hostName : getDeployments().keySet()) {
- if (!hosts.contains(hostName)){
- tblModelHosts.addRow(new Object[] { hostName });
- }
- }
- }
-
- private JTable createParameterTableControls() {
- final JTable tblParameters = new JTable();
- tblParameters.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
- tblParameters.setFillsViewportHeight(true);
- defaultTableModel = new DefaultTableModel(new Object[][] { { null, null, null, null }, }, new String[] { "I/O",
- "Parameter Name", "Type", "Description" });
- tblParameters.setModel(defaultTableModel);
- defaultTableModel.addTableModelListener(new TableModelListener() {
-
- public void tableChanged(TableModelEvent arg0) {
- if (!ignoreTableChanges) {
- int selectedRow = tblParameters.getSelectedRow();
- if (selectedRow != -1
- && defaultTableModel.getRowCount() > 0) {
- Object parameterIOType = defaultTableModel.getValueAt(
- selectedRow, 0);
- Object parameterDataType = defaultTableModel
- .getValueAt(selectedRow, 2);
- if (parameterIOType == null
- || parameterIOType.equals("")) {
- defaultTableModel.setValueAt(getIOStringList()[0],
- selectedRow, 0);
- }
- if (parameterDataType == null
- || parameterDataType.equals("")) {
- defaultTableModel.setValueAt(getDataTypes()[0],
- selectedRow, 2);
- }
- }
- addNewRowIfLastIsNotEmpty();
- }
- }
-
- });
- TableColumn ioColumn = tblParameters.getColumnModel().getColumn(0);
- String[] ioStringList = getIOStringList();
- ioColumn.setCellEditor(new StringArrayComboBoxEditor(ioStringList));
-
- TableColumn datatypeColumn = tblParameters.getColumnModel().getColumn(2);
- String[] dataTypeStringList = getDataTypes();
- datatypeColumn.setCellEditor(new StringArrayComboBoxEditor(dataTypeStringList));
-
- TableColumn parameterNameCol = tblParameters.getColumnModel().getColumn(1);
- parameterNameCol.setPreferredWidth(190);
- ListSelectionModel selectionModel = tblParameters.getSelectionModel();
- selectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
-
- selectionModel.addListSelectionListener(new ListSelectionListener() {
- public void valueChanged(ListSelectionEvent e) {
- btnDeleteParameter.setEnabled(tblParameters.getSelectedRows().length > 0);
- }
-
- });
-
- btnDeleteParameter = new JButton("Delete parameter");
- btnDeleteParameter.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- deleteSelectedRows();
- }
- });
- btnDeleteParameter.setEnabled(false);
- return tblParameters;
- }
-
- private void loadData() {
- ServiceDescriptionType descType = getOrginalServiceDescription().getType();
- txtApplicationServiceName.setText(descType.getName());
- setServiceName(txtApplicationServiceName.getText());
-
- txtApplicationServiceName.setEditable(isNewDescription());
- ignoreTableChanges=true;
- updateIODataTable(descType);
- getDeployments().clear();
- try {
- Map<String, ApplicationDescription> descs = getRegistry().getApplicationManager().getApplicationDescriptors(descType.getName());
- for (String hostDescName : descs.keySet()) {
- getDeployments().put(hostDescName, new HostDeployment(getRegistry().getApplicationManager().getHostDescription(hostDescName), descs.get(hostDescName)));
- }
-
- updateDeploymentTable();
- Boolean selected = false;
- if (descType.getPortType()!=null && descType.getPortType().getMethod()!=null) {
- XmlCursor cursor = descType.getPortType().getMethod().newCursor();
- String value = cursor.getAttributeText(new QName("forceFileStagingToWorkDir"));
- cursor.dispose();
- selected = false;
- if (value != null) {
- selected = Boolean.parseBoolean(value);
- }
- }
- chkForceFileStagingToWorkDir.setSelected(selected);
- setForceFileStagingToWorkDir(selected);
- ignoreTableChanges=false;
- } catch (AiravataAPIInvocationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- private void updateIODataTable(ServiceDescriptionType descType) {
- while(defaultTableModel.getRowCount()>0){
- defaultTableModel.removeRow(0);
- }
- InputParameterType[] iparameters = descType.getInputParametersArray();
- for (InputParameterType parameter : iparameters) {
- defaultTableModel.addRow(new Object[] { getIOStringList()[0], parameter.getParameterName(),parameter.getParameterType().getName(),parameter.getParameterDescription()});
- }
- OutputParameterType[] oparameters = descType.getOutputParametersArray();
- for (OutputParameterType parameter : oparameters) {
- defaultTableModel.addRow(new Object[] { getIOStringList()[1], parameter.getParameterName(), parameter.getParameterType().getName(),parameter.getParameterDescription()});
- }
- addNewRowIfLastIsNotEmpty();
- }
-
- private String[] getIOStringList() {
- String[] ioStringList = new String[] { "Input", "Output" };
- return ioStringList;
- }
-
- private String[] getDataTypes() {
- String[] type = new String[DataType.Enum.table.lastInt()];
- for (int i = 1; i <= DataType.Enum.table.lastInt(); i++) {
- type[i - 1] = DataType.Enum.forInt(i).toString();
- }
- return type;
- }
-
- public boolean isServiceCreated() {
- return serviceCreated;
- }
-
- public void setServiceCreated(boolean serviceCreated) {
- this.serviceCreated = serviceCreated;
- }
-
- public ServiceDescription getServiceDescription() {
- if (serviceDescription == null) {
- serviceDescription = new ServiceDescription();
- }
- return serviceDescription;
- }
-
- public ServiceDescriptionType getServiceDescriptionType() {
- return getServiceDescription().getType();
- }
-
- public String getServiceName() {
- return getServiceDescription().getType().getName();
- }
-
- public void setServiceName(String serviceName) {
- getServiceDescription().getType().setName(serviceName);
- updateDialogStatus();
- }
-
- private void setupMethod(){
- if (getServiceDescriptionType().getPortType()==null){
- getServiceDescriptionType().setPortType(getServiceDescriptionType().addNewPortType());
- }
- if (getServiceDescriptionType().getPortType().getMethod()==null){
- getServiceDescriptionType().getPortType().setMethod(getServiceDescriptionType().getPortType().addNewMethod());
- }
- }
- public void setForceFileStagingToWorkDir(Boolean force){
- setupMethod();
- XmlCursor cursor = getServiceDescriptionType().getPortType().getMethod().newCursor();
- cursor.toNextToken();
- if (!cursor.setAttributeText(new QName("http://airavata.apache.org/schemas/gfac/2012/12","forceFileStagingToWorkDir"),force.toString())){
- cursor.insertAttributeWithValue("forceFileStagingToWorkDir",force.toString());
- }
- cursor.dispose();
- }
-
- public Boolean getForceFileStagingToWorkDir(){
- setupMethod();
- XmlCursor cursor = getServiceDescriptionType().getPortType().getMethod().newCursor();
- cursor.toNextToken();
- String value = cursor.getAttributeText(new QName("forceFileStagingToWorkDir"));
- cursor.dispose();
- if (value==null){
- return false;
- }else{
- return Boolean.parseBoolean(value);
- }
-
- }
-
- private void updateDialogStatus() {
- String message = null;
- try {
- validateDialog();
- } catch (Exception e) {
- message = e.getLocalizedMessage();
- }
- okButton.setEnabled(message == null);
- setError(message);
- }
-
- private void validateDialog() throws Exception {
- if (getServiceName() == null || getServiceName().trim().equals("")) {
- throw new Exception("Name of the application cannot be empty!!!");
- }
- ServiceDescription serviceDescription2 = null;
- serviceDescription2 = getRegistry().getApplicationManager().getServiceDescription(getServiceName());
- if (isNewDescription() && serviceDescription2 != null) {
- throw new Exception("Service descriptor with the given name already exists!!!");
- }
- }
-
- public void saveServiceDescription(boolean update) throws AiravataAPIInvocationException {
- List<InputParameterType> inputParameters = new ArrayList<InputParameterType>();
- List<OutputParameterType> outputParameters = new ArrayList<OutputParameterType>();
-
- for (int i = 0; i < defaultTableModel.getRowCount(); i++) {
- String parameterName = (String) defaultTableModel.getValueAt(i, 1);
- String paramType = (String) defaultTableModel.getValueAt(i, 2);
- String parameterDescription = (String) defaultTableModel.getValueAt(i, 3);
- if (parameterName != null && !parameterName.trim().equals("")) {
- // todo how to handle Enum
- if (getIOStringList()[0].equals(defaultTableModel.getValueAt(i, 0))) {
- InputParameterType parameter = InputParameterType.Factory.newInstance();
- parameter.setParameterName(parameterName);
- parameter.setParameterDescription(parameterDescription);
- ParameterType parameterType = parameter.addNewParameterType();
- parameterType.setType(DataType.Enum.forString(paramType));
- parameterType.setName(paramType);
- inputParameters.add(parameter);
-
- } else {
- OutputParameterType parameter = OutputParameterType.Factory.newInstance();
- parameter.setParameterName(parameterName);
- parameter.setParameterDescription(parameterDescription);
- ParameterType parameterType = parameter.addNewParameterType();
- parameterType.setType(DataType.Enum.forString(paramType));
- parameterType.setName(paramType);
- outputParameters.add(parameter);
- }
- }
- }
- getServiceDescriptionType().setInputParametersArray(inputParameters.toArray(new InputParameterType[] {}));
- getServiceDescriptionType().setOutputParametersArray(outputParameters.toArray(new OutputParameterType[] {}));
- if (update) {
- getRegistry().getApplicationManager().updateServiceDescriptor(getServiceDescription());
- } else {
- getRegistry().getApplicationManager().saveServiceDescription(getServiceDescription());
- }
- if (!isNewDescription()) {
- Map<String, ApplicationDescription> descs = getRegistry().getApplicationManager().getApplicationDescriptors(getServiceName());
- for (String hostDescName : descs.keySet()) {
- getRegistry().getApplicationManager().deleteApplicationDescription(getServiceName(), hostDescName, descs.get(hostDescName).getType().getApplicationName().getStringValue());
- }
- }
- for (String hostName : getDeployments().keySet()) {
- getRegistry().getApplicationManager().saveApplicationDescription(getServiceName(), hostName, getDeployments().get(hostName).getApplicationDescription());
- }
- setServiceCreated(true);
- JOptionPane.showMessageDialog(this, "Application '" + getServiceName() + "' is registered Successfully !");
- }
-
- public void saveServiceDescription() throws AiravataAPIInvocationException {
- List<InputParameterType> inputParameters = new ArrayList<InputParameterType>();
- List<OutputParameterType> outputParameters = new ArrayList<OutputParameterType>();
-
- for (int i = 0; i < defaultTableModel.getRowCount(); i++) {
- String parameterName = (String) defaultTableModel.getValueAt(i, 1);
- String paramType = (String) defaultTableModel.getValueAt(i, 2);
- String parameterDescription = (String) defaultTableModel.getValueAt(i, 3);
- if (parameterName != null && !parameterName.trim().equals("")) {
- // todo how to handle Enum
- if (getIOStringList()[0].equals(defaultTableModel.getValueAt(i, 0))) {
- InputParameterType parameter = InputParameterType.Factory.newInstance();
- parameter.setParameterName(parameterName);
- parameter.setParameterDescription(parameterDescription);
- ParameterType parameterType = parameter.addNewParameterType();
- parameterType.setType(DataType.Enum.forString(paramType));
- parameterType.setName(paramType);
- inputParameters.add(parameter);
-
- } else {
- OutputParameterType parameter = OutputParameterType.Factory.newInstance();
- parameter.setParameterName(parameterName);
- parameter.setParameterDescription(parameterDescription);
- ParameterType parameterType = parameter.addNewParameterType();
- parameterType.setType(DataType.Enum.forString(paramType));
- parameterType.setName(paramType);
- outputParameters.add(parameter);
- }
- }
- }
- getServiceDescriptionType().setInputParametersArray(inputParameters.toArray(new InputParameterType[] {}));
- getServiceDescriptionType().setOutputParametersArray(outputParameters.toArray(new OutputParameterType[] {}));
- getRegistry().getApplicationManager().saveServiceDescription(getServiceDescription());
- if (!isNewDescription()) {
- Map<String, ApplicationDescription> descs = getRegistry().getApplicationManager().getApplicationDescriptors(getServiceName());
- for (String hostDescName : descs.keySet()) {
- getRegistry().getApplicationManager().deleteApplicationDescription(getServiceName(), hostDescName, descs.get(hostDescName).getType().getApplicationName().getStringValue());
- }
- }
- for (String hostName : getDeployments().keySet()) {
- getRegistry().getApplicationManager().saveApplicationDescription(getServiceName(), hostName, getDeployments().get(hostName).getApplicationDescription());
- }
- setServiceCreated(true);
- JOptionPane.showMessageDialog(this, "Application '" + getServiceName() + "' is registered Successfully !");
- }
- public void close() {
- getDialog().setVisible(false);
- }
-
- private void setError(String errorMessage) {
- if (errorMessage == null || errorMessage.trim().equals("")) {
- lblError.setText("");
- } else {
- lblError.setText(errorMessage.trim());
- }
- }
-
- private void deleteSelectedRows() {
- // TODO confirm deletion of selected rows
- int selectedRow = tblParameters.getSelectedRow();
- while (selectedRow >= 0 && tblParameters.getRowCount()>0) {
- defaultTableModel.removeRow(selectedRow);
- selectedRow = tblParameters.getSelectedRow();
- }
- addNewRowIfLastIsNotEmpty();
- }
-
- private void addNewRowIfLastIsNotEmpty() {
-
- if (defaultTableModel.getRowCount()>0) {
- Object parameterName = defaultTableModel.getValueAt(
- defaultTableModel.getRowCount() - 1, 1);
- if (parameterName != null && !parameterName.equals("")) {
- defaultTableModel
- .addRow(new Object[] { null, null, null, null });
- }
- }else{
- if (tblParameters.getSelectedRow()==-1){
- defaultTableModel.addRow(new Object[] { null, null, null, null });
- }
-
- }
- }
-
- public AiravataAPI getRegistry() {
- return registry;
- }
-
- public void setRegistry(AiravataAPI registry) {
- this.registry = registry;
- }
-
- public boolean isNewDescription() {
- return newDescription;
- }
-
- public void setNewDescription(boolean newDescription) {
- this.newDescription = newDescription;
- }
-
- public ServiceDescription getOrginalServiceDescription() {
- return orginalServiceDescription;
- }
-
- public void setOrginalServiceDescription(ServiceDescription orginalServiceDescription) {
- this.orginalServiceDescription = orginalServiceDescription;
- }
-
- public String getSuggestedNamePrefix() {
- return suggestedNamePrefix;
- }
-
- public void setSuggestedNamePrefix(String suggestedNamePrefix) {
- this.suggestedNamePrefix = suggestedNamePrefix;
- }
-
- public String getTitlePrefix() {
- return titlePrefix;
- }
-
- public void setTitlePrefix(String titlePrefix) {
- this.titlePrefix = titlePrefix;
- }
-
- public Map<String,HostDeployment> getDeployments() {
- if (deployments==null){
- deployments=new HashMap<String, HostDeployment>();
- }
- return deployments;
- }
-
- private void editSelectedDeployment() {
- String hostName = tblModelHosts.getValueAt(tblHosts.getSelectedRow(),0).toString();
- HostDeploymentDialog hostDeploymentDialog = new HostDeploymentDialog(getRegistry(),false,getDeployments().get(hostName).getApplicationDescription(),hostName,Arrays.asList(getDeployments().keySet().toArray(new String[]{})));
- try {
- HostDeployment deployDesc = hostDeploymentDialog.execute();
- if (deployDesc!=null){
- getDeployments().put(deployDesc.getHostDescription().getType().getHostName(), deployDesc);
- updateDeploymentTable();
- }
- } catch (AiravataAPIInvocationException e1) {
- setError(e1.getLocalizedMessage());
- e1.printStackTrace();
- }
- }
-
- private class StringArrayComboBoxEditor extends DefaultCellEditor {
- private static final long serialVersionUID = -304464739219209395L;
-
- public StringArrayComboBoxEditor(Object[] items) {
- super(new JComboBox(items));
- }
- }
-}