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 2012/03/16 23:27:35 UTC
svn commit: r1301798 - in
/incubator/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/airavata:
AiravataClient.java WorkflowInput.java
Author: samindaw
Date: Fri Mar 16 22:27:35 2012
New Revision: 1301798
URL: http://svn.apache.org/viewvc?rev=1301798&view=rev
Log:
updating airavata client to list workflow ids, list inputs, run workflow given the workflow templateid & inputs
Added:
incubator/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/airavata/WorkflowInput.java
Modified:
incubator/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/airavata/AiravataClient.java
Modified: incubator/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/airavata/AiravataClient.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/airavata/AiravataClient.java?rev=1301798&r1=1301797&r2=1301798&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/airavata/AiravataClient.java (original)
+++ incubator/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/airavata/AiravataClient.java Fri Mar 16 22:27:35 2012
@@ -17,9 +17,35 @@
* specific language governing permissions and limitations
* under the License.
*
-*/
+ */
package org.apache.airavata.client.airavata;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.MappedByteBuffer;
+import java.nio.channels.FileChannel;
+import java.nio.charset.Charset;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.UUID;
+
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.ValueFormatException;
+import javax.xml.namespace.QName;
+
import org.apache.airavata.common.registry.api.exception.RegistryException;
import org.apache.airavata.registry.api.AiravataRegistry;
import org.apache.airavata.registry.api.WorkflowExecution;
@@ -33,239 +59,256 @@ import org.apache.airavata.xbaya.interpr
import org.apache.airavata.xbaya.interpretor.WorkflowInterpretorStub;
import org.apache.airavata.xbaya.wf.Workflow;
import org.apache.axis2.AxisFault;
+
import xsul5.MLogger;
-import javax.jcr.RepositoryException;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.net.*;
-import java.nio.MappedByteBuffer;
-import java.nio.channels.FileChannel;
-import java.nio.charset.Charset;
-import java.rmi.RemoteException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Properties;
+public class AiravataClient {
+ private static final MLogger log = MLogger.getLogger();
+ public static final String GFAC = "gfac";
+ public static final String JCR = "jcr";
+ public static final String PROXYSERVER = "proxyserver";
+ public static final String MSGBOX = "msgbox";
+ public static final String BROKER = "broker";
+ public static final String DEFAULT_GFAC_URL = "gfac.url";
+ public static final String DEFAULT_MYPROXY_SERVER = "myproxy.url";
+ public static final String DEFAULT_MESSAGE_BOX_URL = "messagebox.url";
+ public static final String DEFAULT_BROKER_URL = "messagebroker.url";
+ public static final String DEFAULT_JCR_URL = "jcr.url";
+ public static final String JCR_USERNAME = "jcr.username";
+ public static final String JCR_PASSWORD = "jcr.password";
+ public static final String MYPROXYUSERNAME = "myproxy.username";
+ public static final String MYPROXYPASS = "myproxy.password";
+ public static final String WITHLISTENER = "with.Listener";
+ public static final String WORKFLOWSERVICEURL = "xbaya.service.url";
+ private AiravataClientConfiguration clientConfiguration;
+ private static String workflow = "";
+
+ private AiravataRegistry registry;
+
+ private NameValue[] configurations = new NameValue[11];
+
+ // private NameValue[] configurations = new NameValue[7];
+
+ public AiravataClient(NameValue[] configuration)
+ throws MalformedURLException {
+ configurations = configuration;
+ updateClientConfiguration(configurations);
+ }
-public class AiravataClient {
- private static final MLogger log = MLogger.getLogger();
+ public AiravataClient(String fileName) throws RegistryException,
+ MalformedURLException, IOException {
+ URL url = this.getClass().getClassLoader().getResource(fileName);
+ if (url == null) {
+ url = (new File(fileName)).toURL();
+ }
+ Properties properties = new Properties();
+ properties.load(url.openStream());
- public static final String GFAC = "gfac";
- public static final String JCR = "jcr";
- public static final String PROXYSERVER = "proxyserver";
- public static final String MSGBOX = "msgbox";
- public static final String BROKER = "broker";
- public static final String DEFAULT_GFAC_URL = "gfac.url";
- public static final String DEFAULT_MYPROXY_SERVER = "myproxy.url";
- public static final String DEFAULT_MESSAGE_BOX_URL = "messagebox.url";
- public static final String DEFAULT_BROKER_URL = "messagebroker.url";
- public static final String DEFAULT_JCR_URL = "jcr.url";
- public static final String JCR_USERNAME = "jcr.username";
- public static final String JCR_PASSWORD= "jcr.password";
- public static final String MYPROXYUSERNAME = "myproxy.username";
- public static final String MYPROXYPASS = "myproxy.password";
- public static final String WITHLISTENER = "with.Listener";
- public static final String WORKFLOWSERVICEURL = "xbaya.service.url";
- private AiravataClientConfiguration clientConfiguration;
- private static String workflow = "";
-
- private AiravataRegistry registry;
-
- private NameValue[] configurations=new NameValue[11];
-
-// private NameValue[] configurations = new NameValue[7];
-
- public AiravataClient(NameValue[] configuration) throws MalformedURLException {
- configurations = configuration;
- updateClientConfiguration(configurations);
- }
-
- public AiravataClient(String fileName) throws RegistryException,MalformedURLException,IOException{
- URL url = this.getClass().getClassLoader().getResource(fileName);
- if(url == null){
- url = (new File(fileName)).toURL();
- }
- Properties properties = new Properties();
- properties.load(url.openStream());
-
- configurations[0] = new NameValue();
- configurations[0].setName(GFAC);
- configurations[0].setValue(validateAxisService(properties.getProperty(DEFAULT_GFAC_URL)));
-
- configurations[1] = new NameValue();
- configurations[1].setName(PROXYSERVER);
- configurations[1].setValue(properties.getProperty(DEFAULT_MYPROXY_SERVER));
-
- configurations[2] = new NameValue();
- configurations[2].setName(MSGBOX);
- configurations[2].setValue(validateAxisService(properties.getProperty(DEFAULT_MESSAGE_BOX_URL)));
-
- configurations[3] = new NameValue();
- configurations[3].setName(BROKER);
- configurations[3].setValue(validateAxisService(properties.getProperty(DEFAULT_BROKER_URL)));
-
- configurations[4] = new NameValue();
- configurations[4].setName(MYPROXYUSERNAME);
- configurations[4].setValue(properties.getProperty(MYPROXYUSERNAME));
-
- configurations[5] = new NameValue();
- configurations[5].setName(MYPROXYPASS);
- configurations[5].setValue(properties.getProperty(MYPROXYPASS));
-
- configurations[6] = new NameValue();
- configurations[6].setName(WORKFLOWSERVICEURL);
- configurations[6].setValue(validateAxisService(properties.getProperty(WORKFLOWSERVICEURL)));
-
- configurations[7] = new NameValue();
- configurations[7].setName(JCR);
- configurations[7].setValue(validateURL(properties.getProperty(DEFAULT_JCR_URL)));
-
- configurations[8] = new NameValue();
- configurations[8].setName(JCR_USERNAME);
- configurations[8].setValue(properties.getProperty(JCR_USERNAME));
-
- configurations[9] = new NameValue();
- configurations[9].setName(JCR_PASSWORD);
- configurations[9].setValue(properties.getProperty(JCR_PASSWORD));
-
- configurations[10] = new NameValue();
- configurations[10].setName(WITHLISTENER);
- configurations[10].setValue(properties.getProperty(WITHLISTENER));
+ configurations[0] = new NameValue();
+ configurations[0].setName(GFAC);
+ configurations[0].setValue(validateAxisService(properties
+ .getProperty(DEFAULT_GFAC_URL)));
+
+ configurations[1] = new NameValue();
+ configurations[1].setName(PROXYSERVER);
+ configurations[1].setValue(properties
+ .getProperty(DEFAULT_MYPROXY_SERVER));
+
+ configurations[2] = new NameValue();
+ configurations[2].setName(MSGBOX);
+ configurations[2].setValue(validateAxisService(properties
+ .getProperty(DEFAULT_MESSAGE_BOX_URL)));
+
+ configurations[3] = new NameValue();
+ configurations[3].setName(BROKER);
+ configurations[3].setValue(validateAxisService(properties
+ .getProperty(DEFAULT_BROKER_URL)));
+
+ configurations[4] = new NameValue();
+ configurations[4].setName(MYPROXYUSERNAME);
+ configurations[4].setValue(properties.getProperty(MYPROXYUSERNAME));
+
+ configurations[5] = new NameValue();
+ configurations[5].setName(MYPROXYPASS);
+ configurations[5].setValue(properties.getProperty(MYPROXYPASS));
+
+ configurations[6] = new NameValue();
+ configurations[6].setName(WORKFLOWSERVICEURL);
+ configurations[6].setValue(validateAxisService(properties
+ .getProperty(WORKFLOWSERVICEURL)));
+
+ configurations[7] = new NameValue();
+ configurations[7].setName(JCR);
+ configurations[7].setValue(validateURL(properties
+ .getProperty(DEFAULT_JCR_URL)));
+
+ configurations[8] = new NameValue();
+ configurations[8].setName(JCR_USERNAME);
+ configurations[8].setValue(properties.getProperty(JCR_USERNAME));
+
+ configurations[9] = new NameValue();
+ configurations[9].setName(JCR_PASSWORD);
+ configurations[9].setValue(properties.getProperty(JCR_PASSWORD));
+
+ configurations[10] = new NameValue();
+ configurations[10].setName(WITHLISTENER);
+ configurations[10].setValue(properties.getProperty(WITHLISTENER));
- updateClientConfiguration(configurations);
+ updateClientConfiguration(configurations);
- }
+ }
- private void updateClientConfiguration(NameValue[] configurations) throws MalformedURLException {
+ private void updateClientConfiguration(NameValue[] configurations)
+ throws MalformedURLException {
AiravataClientConfiguration clientConfiguration = getClientConfiguration();
- for (NameValue configuration : configurations) {
- if (configuration.getName().equals(GFAC)){
- clientConfiguration.setJcrURL(new URL(configuration.getValue()));
- }
- if (configuration.getName().equals(PROXYSERVER)){
- clientConfiguration.setMyproxyHost(configuration.getValue());
- }
- if (configuration.getName().equals(MSGBOX)){
- clientConfiguration.setMessageboxURL(new URL(configuration.getValue()));
- }
- if (configuration.getName().equals(BROKER)){
- clientConfiguration.setMessagebrokerURL(new URL(configuration.getValue()));
- }
- if (configuration.getName().equals(MYPROXYUSERNAME)){
- clientConfiguration.setMyproxyUsername(configuration.getValue());
- }
- if (configuration.getName().equals(MYPROXYPASS)){
- clientConfiguration.setMyproxyPassword(configuration.getValue());
- }
- if (configuration.getName().equals(WORKFLOWSERVICEURL)){
- clientConfiguration.setXbayaServiceURL(new URL(configuration.getValue()));
- }
- if (configuration.getName().equals(JCR)){
- clientConfiguration.setJcrURL(new URL(configuration.getValue()));
- }
- if (configuration.getName().equals(JCR_USERNAME)){
- clientConfiguration.setJcrUsername(configuration.getValue());
- }
- if (configuration.getName().equals(JCR_PASSWORD)){
- clientConfiguration.setJcrPassword(configuration.getValue());
- }
- }
-
- }
- public void loadWorkflowFromaFile(String workflowFile)throws URISyntaxException,IOException {
- File workflow = null;
- URL url = AiravataClient.class.getClassLoader().getResource(workflowFile);
- if(url == null){
- url = (new File(workflowFile)).toURL();
- }
- try {
- workflow = new File(url.toURI());
- } catch (URISyntaxException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- FileInputStream stream = new FileInputStream(workflow);
- try {
- FileChannel fc = stream.getChannel();
- MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
- /* Instead of using default, pass in a decoder. */
- this.workflow = Charset.defaultCharset().decode(bb).toString();
- } finally {
- stream.close();
- }
- }
-
- public void loadWorkflowasaString(String workflowAsaString) {
- this.workflow = workflowAsaString;
- }
-
-
- public NameValue[] setInputs(String fileName) throws IOException {
- URL url = this.getClass().getClassLoader().getResource(fileName);
- if(url == null){
- url = (new File(fileName)).toURL();
- }
- Properties properties = new Properties();
- properties.load(url.openStream());
- try {
- Workflow workflow = new Workflow(this.workflow);
- List<NodeImpl> inputs = workflow.getGraph().getNodes();
- int inputSize = 0;
- for (NodeImpl input : inputs) {
- if(input instanceof InputNode){
- inputSize++;
- }
- }
- NameValue[] inputNameVals = new NameValue[inputSize];
- int index =0;
- for (NodeImpl input : inputs) {
- if(input instanceof InputNode){
- inputNameVals[index] = new NameValue();
- String name = input.getName();
- inputNameVals[index].setName(name);
- inputNameVals[index].setValue(properties.getProperty(name));
- ((InputNode) input).setDefaultValue(properties.getProperty(name));
- index++;
- }
- }
-// setWorkflow(XMLUtil.xmlElementToString((workflow.toXML()));
- return inputNameVals;
- } catch (GraphException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- } catch (ComponentException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- return null;
- }
-
- public void setInputs(Properties inputList){
- try {
- Workflow workflow = new Workflow(this.workflow);
- List<WSComponentPort> inputs = workflow.getInputs();
- for (WSComponentPort input : inputs) {
- input.setValue(inputList.getProperty(input.getName()));
- }
- } catch (GraphException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- } catch (ComponentException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- }
- public String runWorkflow(String topic){
- return runWorkflow(topic,(String)null);
- }
-
- public String runWorkflow(String topic, String user){
- return runWorkflow(topic, user, null);
- }
- public String runWorkflow(String topic, String user, String metadata){
- String worflowoutput= null;
+ for (NameValue configuration : configurations) {
+ if (configuration.getName().equals(GFAC)) {
+ clientConfiguration
+ .setJcrURL(new URL(configuration.getValue()));
+ }
+ if (configuration.getName().equals(PROXYSERVER)) {
+ clientConfiguration.setMyproxyHost(configuration.getValue());
+ }
+ if (configuration.getName().equals(MSGBOX)) {
+ clientConfiguration.setMessageboxURL(new URL(configuration
+ .getValue()));
+ }
+ if (configuration.getName().equals(BROKER)) {
+ clientConfiguration.setMessagebrokerURL(new URL(configuration
+ .getValue()));
+ }
+ if (configuration.getName().equals(MYPROXYUSERNAME)) {
+ clientConfiguration
+ .setMyproxyUsername(configuration.getValue());
+ }
+ if (configuration.getName().equals(MYPROXYPASS)) {
+ clientConfiguration
+ .setMyproxyPassword(configuration.getValue());
+ }
+ if (configuration.getName().equals(WORKFLOWSERVICEURL)) {
+ clientConfiguration.setXbayaServiceURL(new URL(configuration
+ .getValue()));
+ }
+ if (configuration.getName().equals(JCR)) {
+ clientConfiguration
+ .setJcrURL(new URL(configuration.getValue()));
+ }
+ if (configuration.getName().equals(JCR_USERNAME)) {
+ clientConfiguration.setJcrUsername(configuration.getValue());
+ }
+ if (configuration.getName().equals(JCR_PASSWORD)) {
+ clientConfiguration.setJcrPassword(configuration.getValue());
+ }
+ }
+
+ }
+
+ public void loadWorkflowFromaFile(String workflowFile)
+ throws URISyntaxException, IOException {
+ File workflow = null;
+ URL url = AiravataClient.class.getClassLoader().getResource(
+ workflowFile);
+ if (url == null) {
+ url = (new File(workflowFile)).toURL();
+ }
+ try {
+ workflow = new File(url.toURI());
+ } catch (URISyntaxException e) {
+ e.printStackTrace(); // To change body of catch statement use File |
+ // Settings | File Templates.
+ }
+ FileInputStream stream = new FileInputStream(workflow);
+ try {
+ FileChannel fc = stream.getChannel();
+ MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0,
+ fc.size());
+ /* Instead of using default, pass in a decoder. */
+ this.workflow = Charset.defaultCharset().decode(bb).toString();
+ } finally {
+ stream.close();
+ }
+ }
+
+ public void loadWorkflowasaString(String workflowAsaString) {
+ this.workflow = workflowAsaString;
+ }
+
+ public NameValue[] setInputs(String fileName) throws IOException {
+ URL url = this.getClass().getClassLoader().getResource(fileName);
+ if (url == null) {
+ url = (new File(fileName)).toURL();
+ }
+ Properties properties = new Properties();
+ properties.load(url.openStream());
try {
- WorkflowInterpretorStub stub = new WorkflowInterpretorStub(getClientConfiguration().getXbayaServiceURL().toString());
- worflowoutput = stub.launchWorkflow(workflow, topic, getClientConfiguration().getMyproxyPassword(),getClientConfiguration().getMyproxyUsername(), null,
+ Workflow workflow = new Workflow(this.workflow);
+ List<NodeImpl> inputs = workflow.getGraph().getNodes();
+ int inputSize = 0;
+ for (NodeImpl input : inputs) {
+ if (input instanceof InputNode) {
+ inputSize++;
+ }
+ }
+ NameValue[] inputNameVals = new NameValue[inputSize];
+ int index = 0;
+ for (NodeImpl input : inputs) {
+ if (input instanceof InputNode) {
+ inputNameVals[index] = new NameValue();
+ String name = input.getName();
+ inputNameVals[index].setName(name);
+ inputNameVals[index].setValue(properties.getProperty(name));
+ ((InputNode) input).setDefaultValue(properties
+ .getProperty(name));
+ index++;
+ }
+ }
+ // setWorkflow(XMLUtil.xmlElementToString((workflow.toXML()));
+ return inputNameVals;
+ } catch (GraphException e) {
+ e.printStackTrace(); // To change body of catch statement use File |
+ // Settings | File Templates.
+ } catch (ComponentException e) {
+ e.printStackTrace(); // To change body of catch statement use File |
+ // Settings | File Templates.
+ }
+ return null;
+ }
+
+ public void setInputs(Properties inputList) {
+ try {
+ Workflow workflow = new Workflow(this.workflow);
+ List<WSComponentPort> inputs = workflow.getInputs();
+ for (WSComponentPort input : inputs) {
+ input.setValue(inputList.getProperty(input.getName()));
+ }
+ } catch (GraphException e) {
+ e.printStackTrace(); // To change body of catch statement use File |
+ // Settings | File Templates.
+ } catch (ComponentException e) {
+ e.printStackTrace(); // To change body of catch statement use File |
+ // Settings | File Templates.
+ }
+ }
+
+ public String runWorkflow(String topic) {
+ return runWorkflow(topic, (String) null);
+ }
+
+ public String runWorkflow(String topic, String user) {
+ return runWorkflow(topic, user, null);
+ }
+
+ public String runWorkflow(String topic, String user, String metadata) {
+ String worflowoutput = null;
+ try {
+ WorkflowInterpretorStub stub = new WorkflowInterpretorStub(
+ getClientConfiguration().getXbayaServiceURL().toString());
+ worflowoutput = stub.launchWorkflow(workflow, topic,
+ getClientConfiguration().getMyproxyPassword(),
+ getClientConfiguration().getMyproxyUsername(), null,
configurations);
- runPostWorkflowExecutionTasks(topic, user, metadata);
+ runPostWorkflowExecutionTasks(topic, user, metadata);
log.info("Workflow output : " + worflowoutput);
} catch (AxisFault e) {
log.fine(e.getMessage(), e);
@@ -279,26 +322,33 @@ public class AiravataClient {
private void runPostWorkflowExecutionTasks(String topic, String user,
String metadata) throws RegistryException {
- if (user!=null) {
+ if (user != null) {
getRegistry().saveWorkflowExecutionUser(topic, user);
}
- if (metadata!=null){
+ if (metadata != null) {
getRegistry().saveWorkflowExecutionMetadata(topic, metadata);
}
}
- public String runWorkflow(String topic, NameValue[] inputs){
- return runWorkflow(topic, inputs, null);
- }
- public String runWorkflow(String topic, NameValue[] inputs, String user){
- return runWorkflow(topic, inputs, user, null);
- }
- public String runWorkflow(String topic, NameValue[] inputs, String user, String metadata){
- String worflowoutput= null;
+
+ public String runWorkflow(String topic, NameValue[] inputs) {
+ return runWorkflow(topic, inputs, null);
+ }
+
+ public String runWorkflow(String topic, NameValue[] inputs, String user) {
+ return runWorkflow(topic, inputs, user, null);
+ }
+
+ public String runWorkflow(String topic, NameValue[] inputs, String user,
+ String metadata) {
+ String worflowoutput = null;
try {
- WorkflowInterpretorStub stub = new WorkflowInterpretorStub(getClientConfiguration().getXbayaServiceURL().toString());
- worflowoutput = stub.launchWorkflow(workflow, topic, getClientConfiguration().getMyproxyPassword(),getClientConfiguration().getMyproxyUsername(), inputs,
+ WorkflowInterpretorStub stub = new WorkflowInterpretorStub(
+ getClientConfiguration().getXbayaServiceURL().toString());
+ worflowoutput = stub.launchWorkflow(workflow, topic,
+ getClientConfiguration().getMyproxyPassword(),
+ getClientConfiguration().getMyproxyUsername(), inputs,
configurations);
- runPostWorkflowExecutionTasks(topic, user, metadata);
+ runPostWorkflowExecutionTasks(topic, user, metadata);
log.info("Workflow output : " + worflowoutput);
} catch (AxisFault e) {
log.fine(e.getMessage(), e);
@@ -310,42 +360,50 @@ public class AiravataClient {
return worflowoutput;
}
-
- public List<WorkflowExecution> getWorkflowExecutionDataByUser(String user) throws RegistryException{
- return getRegistry().getWorkflowExecutionByUser(user);
- }
-
- public WorkflowExecution getWorkflowExecutionData(String topic) throws RegistryException{
- return getRegistry().getWorkflowExecution(topic);
- }
-
- /**
- *
- * @param user
- * @param pageSize - number of executions to return (page size)
- * @param PageNo - which page to return to (>=0)
- * @return
- * @throws RegistryException
- */
- public List<WorkflowExecution> getWorkflowExecutionData(String user, int pageSize, int PageNo) throws RegistryException{
- return getRegistry().getWorkflowExecutionByUser(user, pageSize, PageNo);
- }
-
- public static String getWorkflow() {
- return workflow;
- }
-
- public static void setWorkflow(String workflow) {
- AiravataClient.workflow = workflow;
- }
+ public List<WorkflowExecution> getWorkflowExecutionDataByUser(String user)
+ throws RegistryException {
+ return getRegistry().getWorkflowExecutionByUser(user);
+ }
+
+ public WorkflowExecution getWorkflowExecutionData(String topic)
+ throws RegistryException {
+ return getRegistry().getWorkflowExecution(topic);
+ }
+
+ /**
+ *
+ * @param user
+ * @param pageSize
+ * - number of executions to return (page size)
+ * @param PageNo
+ * - which page to return to (>=0)
+ * @return
+ * @throws RegistryException
+ */
+ public List<WorkflowExecution> getWorkflowExecutionData(String user,
+ int pageSize, int PageNo) throws RegistryException {
+ return getRegistry().getWorkflowExecutionByUser(user, pageSize, PageNo);
+ }
+
+ public static String getWorkflow() {
+ return workflow;
+ }
+
+ public static void setWorkflow(String workflow) {
+ AiravataClient.workflow = workflow;
+ }
public AiravataRegistry getRegistry() {
- if (registry==null){
+ if (registry == null) {
try {
HashMap<String, String> map = new HashMap<String, String>();
- URI uri = getClientConfiguration().getJcrURL().toURI();
+ URI uri = getClientConfiguration().getJcrURL().toURI();
map.put("org.apache.jackrabbit.repository.uri", uri.toString());
- registry=new AiravataJCRRegistry(uri, "org.apache.jackrabbit.rmi.repository.RmiRepositoryFactory", getClientConfiguration().getJcrUsername(), getClientConfiguration().getJcrPassword(), map);
+ registry = new AiravataJCRRegistry(
+ uri,
+ "org.apache.jackrabbit.rmi.repository.RmiRepositoryFactory",
+ getClientConfiguration().getJcrUsername(),
+ getClientConfiguration().getJcrPassword(), map);
} catch (RepositoryException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
@@ -356,43 +414,162 @@ public class AiravataClient {
}
public AiravataClientConfiguration getClientConfiguration() {
- if (clientConfiguration==null){
- clientConfiguration=new AiravataClientConfiguration();
+ if (clientConfiguration == null) {
+ clientConfiguration = new AiravataClientConfiguration();
}
return clientConfiguration;
}
- private String validateAxisService(String urlString)throws RegistryException{
- if(!urlString.endsWith("?wsdl")){
- urlString = urlString + "?wsdl";
- }
- try {
- URL url = new URL(urlString);
- URLConnection conn = url.openConnection();
- conn.connect();
- } catch (MalformedURLException e) {
- // the URL is not in a valid form
- throw new RegistryException("Given Axis2 Service URL : " + urlString + " is Invalid",e);
- } catch (IOException e) {
- // the connection couldn't be established
- throw new RegistryException("Given Axis2 Service URL : " + urlString + " is Invalid",e);
- }
- return urlString;
- }
- private String validateURL(String urlString)throws RegistryException{
- try {
- URL url = new URL(urlString);
- URLConnection conn = url.openConnection();
- conn.connect();
- } catch (MalformedURLException e) {
- // the URL is not in a valid form
- throw new RegistryException("Given URL: " + urlString + " is Invalid",e);
- } catch (IOException e) {
- // the connection couldn't be established
- throw new RegistryException("Given URL: " + urlString + " is Invalid",e);
- }
- return urlString;
- }
+ private String validateAxisService(String urlString)
+ throws RegistryException {
+ if (!urlString.endsWith("?wsdl")) {
+ urlString = urlString + "?wsdl";
+ }
+ try {
+ URL url = new URL(urlString);
+ URLConnection conn = url.openConnection();
+ conn.connect();
+ } catch (MalformedURLException e) {
+ // the URL is not in a valid form
+ throw new RegistryException("Given Axis2 Service URL : "
+ + urlString + " is Invalid", e);
+ } catch (IOException e) {
+ // the connection couldn't be established
+ throw new RegistryException("Given Axis2 Service URL : "
+ + urlString + " is Invalid", e);
+ }
+ return urlString;
+ }
-}
+ private String validateURL(String urlString) throws RegistryException {
+ try {
+ URL url = new URL(urlString);
+ URLConnection conn = url.openConnection();
+ conn.connect();
+ } catch (MalformedURLException e) {
+ // the URL is not in a valid form
+ throw new RegistryException("Given URL: " + urlString
+ + " is Invalid", e);
+ } catch (IOException e) {
+ // the connection couldn't be established
+ throw new RegistryException("Given URL: " + urlString
+ + " is Invalid", e);
+ }
+ return urlString;
+ }
+
+ public List<String> getWorkflowTemplateIds() {
+ List<String> workflowList = new ArrayList<String>();
+ Map<QName, Node> workflows;
+ try {
+ workflows = getRegistry().getWorkflows(
+ getClientConfiguration().getJcrUsername());
+ for (QName qname : workflows.keySet()) {
+ workflowList.add(qname.getLocalPart());
+ }
+ } catch (RegistryException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return workflowList;
+ }
+
+ public String runWorkflow(String workflowTemplateId,List<WorkflowInput> inputs){
+ try {
+ List<WSComponentPort> ports = getWSComponentPortInputs(workflowTemplateId);
+ for (WorkflowInput input : inputs) {
+ WSComponentPort port = getWSComponentPort(input.getName(), ports);
+ if (port!=null){
+ port.setValue(input.getValue());
+ }
+ }
+ List<NameValue> inputValues=new ArrayList<NameValue>();
+ for (WSComponentPort port : ports) {
+ NameValue nameValue = new NameValue();
+ nameValue.setName(port.getName());
+ if (port.getValue()==null){
+ nameValue.setValue(port.getDefaultValue());
+ }else{
+ nameValue.setValue(port.getValue().toString());
+ }
+ inputValues.add(nameValue);
+ }
+ workflow=getWorkflowAsString(workflowTemplateId).getString();
+ String topic=workflowTemplateId+UUID.randomUUID();
+ return runWorkflow(topic, inputValues.toArray(new NameValue[]{}));
+ } catch (PathNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (GraphException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ComponentException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ValueFormatException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (RegistryException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (RepositoryException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private WSComponentPort getWSComponentPort(String name,List<WSComponentPort> ports){
+ for (WSComponentPort port : ports) {
+ if (port.getName().equals(name)){
+ return port;
+ }
+ }
+ return null;
+ }
+
+ public List<WorkflowInput> getWorkflowInputs(String workflowTemplateId){
+ try {
+ List<WSComponentPort> inputs = getWSComponentPortInputs(workflowTemplateId);
+ List<WorkflowInput> results=new ArrayList<WorkflowInput>();
+ for (WSComponentPort port : inputs) {
+ results.add(new WorkflowInput(port.getName(), port.getType().getLocalPart(), port.getDefaultValue(), port.getValue()));
+ }
+ return results;
+ } catch (GraphException e) {
+ e.printStackTrace(); // To change body of catch statement use File |
+ // Settings | File Templates.
+ } catch (ComponentException e) {
+ e.printStackTrace(); // To change body of catch statement use File |
+ // Settings | File Templates.
+ } catch (RegistryException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ValueFormatException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (RepositoryException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+ private List<WSComponentPort> getWSComponentPortInputs(
+ String workflowTemplateId) throws RegistryException,
+ PathNotFoundException, RepositoryException, GraphException,
+ ComponentException, ValueFormatException {
+ Property workflowAsString = getWorkflowAsString(workflowTemplateId);
+ Workflow workflow = new Workflow(workflowAsString.getString());
+ List<WSComponentPort> inputs = workflow.getInputs();
+ return inputs;
+ }
+
+ public Property getWorkflowAsString(String workflowTemplateId)
+ throws RegistryException, PathNotFoundException,
+ RepositoryException {
+ Node workflowNode = getRegistry().getWorkflow(new QName(workflowTemplateId), getClientConfiguration().getJcrUsername());
+ Property workflowAsString = workflowNode.getProperty("workflow");
+ return workflowAsString;
+ }
+}
Added: incubator/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/airavata/WorkflowInput.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/airavata/WorkflowInput.java?rev=1301798&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/airavata/WorkflowInput.java (added)
+++ incubator/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/airavata/WorkflowInput.java Fri Mar 16 22:27:35 2012
@@ -0,0 +1,68 @@
+/*
+ *
+ * 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.client.airavata;
+
+public class WorkflowInput {
+ private String name;
+ private String type;
+ private Object defaultValue;
+ private Object value;
+
+ public WorkflowInput(String name,String type,Object defaultValue,Object value) {
+ setName(name);
+ setType(type);
+ setDefaultValue(defaultValue);
+ setValue(value);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ private void setName(String name) {
+ this.name = name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ private void setType(String type) {
+ this.type = type;
+ }
+
+ public Object getDefaultValue() {
+ return defaultValue;
+ }
+
+ private void setDefaultValue(Object defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+}