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/23 18:48:19 UTC
[05/20] introducing workflow support in airavata api + other related
modules
http://git-wip-us.apache.org/repos/asf/airavata/blob/a8974b7c/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/interpretor/WorkflowInterpreterSkeleton2.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/interpretor/WorkflowInterpreterSkeleton2.java b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/interpretor/WorkflowInterpreterSkeleton2.java
new file mode 100644
index 0000000..8da619e
--- /dev/null
+++ b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/interpretor/WorkflowInterpreterSkeleton2.java
@@ -0,0 +1,498 @@
+package org.apache.airavata.workflow.engine.interpretor;
+///*
+// *
+// * 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.interpretor;
+//
+//import java.io.IOException;
+//import java.net.URI;
+//import java.net.URISyntaxException;
+//import java.net.URL;
+//import java.util.ArrayList;
+//import java.util.HashMap;
+//import java.util.Iterator;
+//import java.util.List;
+//import java.util.Map;
+//
+//import javax.xml.namespace.QName;
+//import javax.xml.stream.XMLInputFactory;
+//import javax.xml.stream.XMLStreamException;
+//import javax.xml.stream.XMLStreamReader;
+//
+//import org.apache.airavata.client.AiravataAPIFactory;
+//import org.apache.airavata.client.api.AiravataAPI;
+//import org.apache.airavata.client.api.exception.AiravataAPIInvocationException;
+//import org.apache.airavata.client.stub.interpretor.NameValue;
+//import org.apache.airavata.client.tools.PeriodicExecutorThread;
+//import org.apache.airavata.common.exception.ApplicationSettingsException;
+//import org.apache.airavata.common.utils.ServerSettings;
+//import org.apache.airavata.common.workflow.execution.context.WorkflowContextHeaderBuilder;
+//import org.apache.airavata.model.workspace.experiment.Experiment;
+//import org.apache.airavata.orchestrator.cpi.OrchestratorService;
+//import org.apache.airavata.schemas.wec.ContextHeaderDocument;
+//import org.apache.airavata.workflow.model.component.ComponentException;
+//import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+//import org.apache.airavata.workflow.model.graph.GraphException;
+//import org.apache.airavata.workflow.model.graph.system.InputNode;
+//import org.apache.airavata.workflow.model.ode.ODEClient;
+//import org.apache.airavata.workflow.model.wf.Workflow;
+//import org.apache.airavata.workflow.model.wf.WorkflowExecutionState;
+//import org.apache.airavata.ws.monitor.MonitorException;
+//import org.apache.airavata.xbaya.XBayaConfiguration;
+//import org.apache.airavata.xbaya.XBayaConstants;
+//import org.apache.airavata.xbaya.concurrent.PredicatedTaskRunner;
+//import org.apache.axiom.om.OMElement;
+//import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+//import org.apache.axiom.om.impl.llom.util.AXIOMUtil;
+//import org.apache.axiom.soap.SOAPHeader;
+//import org.apache.axis2.context.ConfigurationContext;
+//import org.apache.axis2.context.MessageContext;
+//import org.apache.axis2.description.AxisService;
+//import org.apache.xmlbeans.XmlException;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+////import org.apache.airavata.registry.api.AiravataRegistry2;
+//
+///**
+// * WorkflowInterpretorSkeleton java skeleton for the axisService
+// */
+//public class WorkflowInterpreterSkeleton2 {
+// private static final Logger log = LoggerFactory.getLogger(WorkflowInterpreterSkeleton2.class);
+//
+//// public static final String PROXYSERVER = "myproxy.url";
+// public static final String MSGBOX = "msgbox";
+// public static final String GFAC = "gfac";
+// public static final String BROKER = "broker";
+// public static final String MYPROXY_USER = "myproxy.user";
+// public static final String MYPROXY_PASS = "myproxy.pass";
+// public static final String MYPROXY_SERVER = "myproxy.server";
+// public static final String MYPROXY_LIFETIME = "myproxy.life";
+// public static final String TRUSTED_CERT_LOCATION = "trusted.cert.location";
+//
+// public static boolean provenance = false;
+// public static final String PROVENANCE = "provenance";
+// public static String systemUserName = "";
+// public static String systemUserPW = "";
+// public static boolean runInThread = false;
+// public static final String RUN_IN_THREAD = "runInThread";
+// public static Boolean gfacEmbeddedMode = true;
+// private static PredicatedTaskRunner runner = null;
+//// public static JCRComponentRegistry jcrComponentRegistry = null;
+// private static AiravataAPI airavataAPI=null;
+// public static int provenanceWriterThreadPoolSize = 1;
+// public static final String PROVENANCE_WRITER_THREAD_POOL_SIZE = "provenanceWriterThreadPoolSize";
+// public static final int JCR_AVAIALABILITY_WAIT_INTERVAL = 1000 * 10;
+// public static final String GFAC_EMBEDDED = "gfac.embedded";
+// public static ConfigurationContext configurationContext;
+// public static final String SERVICE_NAME="WorkflowInterpretor";
+// public static boolean notInterrupted = true;
+// public Map<String, WorkflowInterpreterConfiguration> workflowConfigurations=new HashMap<String, WorkflowInterpreterConfiguration>();
+// private WorkflowInterpreterInteractor interactor;
+// private String gateway;
+//
+// protected static final String SERVICE_URL = "interpreter_service_url";
+//
+// protected static final String JCR_REG = "jcr_registry";
+//
+// protected WIServiceThread thread;
+//
+// private AiravataAPI getAiravataAPI(){
+// if (airavataAPI==null) {
+// try {
+// systemUserName = ServerSettings.getSystemUser();
+// systemUserPW = ServerSettings.getSystemUserPassword();
+// gateway = ServerSettings.getSystemUserGateway();
+// airavataAPI = AiravataAPIFactory.getAPI(gateway, systemUserName);
+// } catch (ApplicationSettingsException e) {
+// log.error("Unable to read the properties file", e);
+// } catch (AiravataAPIInvocationException e) {
+// log.error("Unable to create Airavata API", e);
+// }
+// }
+// return airavataAPI;
+// }
+//
+// private WorkflowInterpreterInteractor getInteractor(){
+// if (interactor==null){
+// interactor=new SSWorkflowInterpreterInteractorImpl();
+// }
+// return interactor;
+// }
+//
+//
+// public void suspendWorkflow(String experimentId)throws Exception{
+// if (workflowConfigurations.containsKey(experimentId)){
+// if (getInteractor().isExecutionPaused(workflowConfigurations.get(experimentId))){
+// throw new Exception("Experiment '"+experimentId+"' is already paused!!!");
+// }else{
+// log.info("Suspending workflow execution "+experimentId+"...");
+// getInteractor().pauseExecution(workflowConfigurations.get(experimentId));
+// }
+// }else{
+// throw new Exception("Invalid Experiment id: Experiment "+experimentId+" not running");
+// }
+// }
+//
+// public void resumeWorkflow(String experimentId)throws Exception{
+// if (workflowConfigurations.containsKey(experimentId)){
+// if (getInteractor().isExecutionPaused(workflowConfigurations.get(experimentId)) || workflowConfigurations.get(experimentId).getWorkflow().getExecutionState()==WorkflowExecutionState.STOPPED){
+// log.info("Resuming workflow execution "+experimentId+"...");
+// getInteractor().resumeExecution(workflowConfigurations.get(experimentId));
+//
+// }else{
+// throw new Exception("Experiment '"+experimentId+"' is not suspended!!!");
+// }
+// }else{
+// //TODO chk to see if the experiment is present in registry if so reload it and resume execution else error
+// throw new Exception("Invalid Experiment id: Experiment "+experimentId+" not running");
+// }
+// }
+//
+// public void haltWorkflow(String experimentId)throws Exception{
+// if (workflowConfigurations.containsKey(experimentId)){
+// log.info("Terminating workflow execution "+experimentId+"...");
+// getInteractor().terminateExecution(workflowConfigurations.get(experimentId));
+// }else{
+// throw new Exception("Invalid Experiment id: Experiment "+experimentId+" not running");
+// }
+// }
+//
+// /**
+// * @param workflowAsString
+// * @param topic
+// * @param inputs
+// * @return
+// * @throws XMLStreamException
+// */
+// public java.lang.String launchWorkflow(Experiment experiment, String workflowName, OrchestratorService.Client orchestratorClient) throws XMLStreamException {
+// OMElement workflowContext = getWorkflowContextHeader();
+// if(workflowContext == null){
+// workflowContext = AXIOMUtil.stringToOM("<wor:context-header xmlns:wor=\"http://airavata.apache.org/schemas/wec/2012/05\">\n" +
+// " <wor:soa-service-eprs>\n" +
+// " <wor:gfac-url></wor:gfac-url>\n" +
+// " <wor:registry-url></wor:registry-url>\n" +
+// " </wor:soa-service-eprs>\n" +
+// " <wor:workflow-monitoring-context>\n" +
+// " <wor:experiment-id></wor:experiment-id>\n" +
+// " <wor:workflow-instance-id xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:nil=\"true\" />\n" +
+// " <wor:event-publish-epr></wor:event-publish-epr>\n" +
+// " <wor:msg-box-epr></wor:msg-box-epr>\n" +
+// " </wor:workflow-monitoring-context>\n" +
+// " <wor:workflow-scheduling-context />\n" +
+// " <wor:security-context />\n" +
+// "</wor:context-header>");
+// }
+// Map<String, String> configuration = new HashMap<String, String>();
+// WorkflowContextHeaderBuilder workflowContextHeaderBuilder = parseContextHeader(workflowContext, configuration);
+// String user = workflowContextHeaderBuilder.getSubmissionUser();
+//
+// String s = null;
+// try {
+// s = setupAndLaunch(workflowAsString, topic, ServerSettings.getSystemUserGateway(),
+// user,inputs, configuration, runInThread, workflowContextHeaderBuilder);
+// } catch (AiravataAPIInvocationException e) {
+// log.error(e.getMessage());
+// } catch (ApplicationSettingsException e) {
+// log.error(e.getMessage());
+// }
+// return s;
+// }
+//
+// private OMElement getWorkflowContextHeader() {
+// MessageContext currentMessageContext = MessageContext.getCurrentMessageContext();
+// SOAPHeader header = currentMessageContext.getEnvelope().getHeader();
+// Iterator<?> childrenWithName = header.getChildrenWithName(new QName("http://airavata.apache.org/schemas/wec/2012/05", "context-header"));
+// if (childrenWithName.hasNext()) {
+// return (OMElement) childrenWithName.next();
+// } else {
+// return null;
+// }
+// }
+//
+// private WorkflowContextHeaderBuilder parseContextHeader(OMElement workflowContext, Map<String, String> configuration) throws XMLStreamException {
+// ContextHeaderDocument parse = null;
+// try {
+// parse = ContextHeaderDocument.Factory.parse(workflowContext.toStringWithConsume());
+// String msgBox = parse.getContextHeader().getWorkflowMonitoringContext().getMsgBoxEpr();
+// if(msgBox == null || "".equals(msgBox)){
+// msgBox = getAiravataAPI().getAiravataManager().getMessageBoxServiceURL().toASCIIString();
+// }
+// String msgBroker = parse.getContextHeader().getWorkflowMonitoringContext().getEventPublishEpr();
+// if(msgBroker == null || "".equals(msgBroker)){
+// msgBroker = getAiravataAPI().getAiravataManager().getEventingServiceURL().toASCIIString();
+// }
+// String gfac = parse.getContextHeader().getSoaServiceEprs().getGfacUrl();
+//// if(gfac == null || "".equals(gfac)){
+//// gfac = getAiravataAPI().getAiravataManager().getGFaCURLs().get(0).toString();
+//// }
+// configuration.put(BROKER, msgBroker);
+// configuration.put(GFAC, gfac);
+// configuration.put(MSGBOX, msgBox);
+// } catch (XmlException e) {
+// log.error(e.getMessage());
+// } catch (AiravataAPIInvocationException e) {
+// log.error(e.getMessage());
+// }
+// String submissionUser = workflowContext.getAttributeValue(new QName(workflowContext.getNamespace().getNamespaceURI(), "submissionUser"));
+// WorkflowContextHeaderBuilder workflowContextHeaderBuilder = new WorkflowContextHeaderBuilder(parse.getContextHeader());
+// workflowContextHeaderBuilder.setSubmissionUser(submissionUser);
+// return workflowContextHeaderBuilder;
+// }
+//
+// public String setupAndLaunch(String workflowAsString, String experimentId, String gatewayId, String username,
+// Map<String,String> inputs,boolean inNewThread,WorkflowContextHeaderBuilder builder) throws AiravataAPIInvocationException{
+// List<NameValue> inputData=new ArrayList<NameValue>();
+// for (String inputName : inputs.keySet()) {
+// NameValue input = new NameValue();
+// input.setName(inputName);
+// input.setValue(inputs.get(inputName));
+// inputData.add(input);
+// }
+// Map<String, String> configuration = new HashMap<String, String>();
+// configuration.put(BROKER, getAiravataAPI().getAiravataManager().getEventingServiceURL().toASCIIString());
+// configuration.put(MSGBOX, getAiravataAPI().getAiravataManager().getMessageBoxServiceURL().toASCIIString());
+//
+// return setupAndLaunch(workflowAsString, experimentId, gatewayId, username, inputData.toArray(new NameValue[]{}), configuration, inNewThread, builder);
+// }
+//
+// private String setupAndLaunch(String workflowAsString, String topic, String gatewayId, String username,
+// NameValue[] inputs,Map<String,String>configurations,boolean inNewThread,
+// WorkflowContextHeaderBuilder builder) throws AiravataAPIInvocationException{
+// log.debug("Launch is called for topic:"+topic);
+//
+// Workflow workflow = null;
+// try {
+// workflow = new Workflow(workflowAsString);
+// log.debug("Workflow Object created");
+// } catch (GraphException e1) {
+// e1.printStackTrace();
+// } catch (ComponentException e1) {
+// e1.printStackTrace();
+// }
+// log.debug("Setting Input values");
+// List<InputNode> inputNodes = new ODEClient().getInputNodes(workflow);
+// for (InputNode inputNode : inputNodes) {
+// for (NameValue input : inputs) {
+// if (inputNode.getID().equals(input.getName())) {
+// inputNode.setDefaultValue(input.getValue());
+// break;
+// }
+// }
+// if (inputNode.getDefaultValue() == null) {
+// throw new WorkflowRuntimeException("Could not find a input value for component with name :" + inputNode.getName());
+// }
+//
+// }
+// log.debug("Input all set");
+//
+// XBayaConfiguration conf = null;
+// try {
+// conf = getConfiguration(configurations);
+// conf.setTopic(topic);
+// conf.setRunWithCrossProduct(true);
+// } catch (URISyntaxException e1) {
+// throw new WorkflowRuntimeException(e1);
+// }
+// WorkflowInterpretorEventListener listener = null;
+// WorkflowInterpreter interpreter = null;
+// AiravataAPI airavataAPI = AiravataAPIFactory.getAPI(gatewayId, username);
+// WorkflowInterpreterConfiguration workflowInterpreterConfiguration = new WorkflowInterpreterConfiguration(workflow, topic, conf.getMessageBoxURL(), conf.getBrokerURL(), airavataAPI, conf, null, null);
+// workflowInterpreterConfiguration.setGfacEmbeddedMode(gfacEmbeddedMode);
+// workflowInterpreterConfiguration.setActOnProvenance(provenance);
+//
+// if (builder.getSecurityContext().getAmazonWebservices() != null) {
+// workflowInterpreterConfiguration.setAwsSecretKey(builder.getSecurityContext().getAmazonWebservices().getSecretAccessKey());
+// workflowInterpreterConfiguration.setAwsAccessKey(builder.getSecurityContext().getAmazonWebservices().getAccessKeyId());
+// }
+// // WorkflowInterpreter object should create prior creation of Listener, because listener needs the threadlocal variable
+// interpreter = new WorkflowInterpreter(workflowInterpreterConfiguration, getInteractor());
+// listener = new WorkflowInterpretorEventListener(workflow, conf);
+// try {
+// log.debug("start listener set");
+// listener.start();
+// } catch (MonitorException e1) {
+// e1.printStackTrace();
+// }
+//
+// WorkflowContextHeaderBuilder.setCurrentContextHeader(builder.getContextHeader());
+//
+// final WorkflowInterpretorEventListener finalListener = listener;
+// conf.setAiravataAPI(getAiravataAPI());
+//
+// final WorkflowInterpreter finalInterpreter = interpreter;
+//// interpreter.setActOnProvenance(provenance);
+// interpreter.setProvenanceWriter(runner);
+// final String experimentId = topic;
+// log.debug("Created the interpreter");
+// if(inNewThread){
+// runInThread(finalInterpreter,finalListener,experimentId,builder);
+// }else{
+// executeWorkflow(finalInterpreter, finalListener, experimentId);
+// }
+// log.info("Experiment launched :" + topic);
+// return topic;
+// }
+//
+// private void runInThread(final WorkflowInterpreter interpreter,final WorkflowInterpretorEventListener listener,final String experimentId,final WorkflowContextHeaderBuilder builder) {
+// new Thread(new Runnable() {
+//
+// public void run() {
+// WorkflowContextHeaderBuilder.setCurrentContextHeader(builder.getContextHeader());
+// executeWorkflow(interpreter, listener, experimentId);
+// }
+// }).start();
+// }
+//
+// private void executeWorkflow(WorkflowInterpreter interpreter, WorkflowInterpretorEventListener listener,String experimentId) {
+// try {
+// workflowConfigurations.put(experimentId,interpreter.getConfig());
+// interpreter.scheduleDynamically();
+// log.debug("Interpreter invoked...");
+// } catch (Exception e) {
+// throw new WorkflowRuntimeException(e);
+// } finally {
+// if (workflowConfigurations.containsKey(experimentId)){
+// workflowConfigurations.remove(experimentId);
+// }
+// /*
+// * stop listener no matter what happens
+// */
+//// try {
+//// if(listener != null)
+//// listener.stop();
+//// } catch (MonitorException e) {
+//// e.printStackTrace();
+//// }
+// }
+// }
+//
+// public XBayaConfiguration getConfiguration(Map<String,String> vals) throws URISyntaxException {
+// XBayaConfiguration configuration = new XBayaConfiguration();
+// configuration.setBrokerURL(new URI(findValue(vals, BROKER, XBayaConstants.DEFAULT_BROKER_URL.toString())));
+// configuration.setGFacURL(new URI(findValue(vals, GFAC, XBayaConstants.DEFAULT_GFAC_URL.toString())));
+// configuration.setMessageBoxURL(new URI(findValue(vals, MSGBOX, XBayaConstants.DEFAULT_MESSAGE_BOX_URL.toString())));
+// configuration.setMyProxyLifetime(XBayaConstants.DEFAULT_MYPROXY_LIFTTIME);
+// configuration.setMyProxyPort(XBayaConstants.DEFAULT_MYPROXY_PORT);
+// //This null check will fix some test failures
+// if (WorkflowInterpreterSkeleton2.configurationContext != null) {
+// configuration.setMyProxyServer(findValue(vals, MYPROXY_SERVER, (String) WorkflowInterpreterSkeleton2.configurationContext.getProperty(MYPROXY_SERVER)));
+// configuration.setMyProxyPassphrase(findValue(vals, MYPROXY_PASS, (String) WorkflowInterpreterSkeleton2.configurationContext.getProperty(MYPROXY_PASS)));
+// configuration.setMyProxyUsername(findValue(vals, MYPROXY_USER, (String) WorkflowInterpreterSkeleton2.configurationContext.getProperty(MYPROXY_USER)));
+// configuration.setTrustedCertLocation(findValue(vals, TRUSTED_CERT_LOCATION, (String) WorkflowInterpreterSkeleton2.configurationContext.getProperty(TRUSTED_CERT_LOCATION)));
+// configuration.setTrustedCertLocation(findValue(vals, MYPROXY_LIFETIME, (String) WorkflowInterpreterSkeleton2.configurationContext.getProperty(MYPROXY_LIFETIME)));
+// }
+// return configuration;
+// }
+//
+// private String findValue(Map<String,String> vals, String key, String defaultVal) {
+// if(vals.get(key) != null) {
+// return vals.get(key);
+// }
+// return defaultVal;
+// }
+//
+// public void shutDown(ConfigurationContext configctx, AxisService service) {
+// URI gfacURL = (URI) configctx.getProperty(SERVICE_URL);
+// if (getAiravataAPI() != null && thread != null) {
+// AiravataAPI registry = getAiravataAPI();
+// try {
+// registry.getAiravataManager().removeWorkflowInterpreterURI(gfacURL);
+// } catch (AiravataAPIInvocationException e) {
+// e.printStackTrace();
+// }
+// thread.interrupt();
+// try {
+// thread.join();
+// } catch (InterruptedException e) {
+// log.warn("GFacURL update thread is interrupted");
+// }
+// }
+// if (runner != null) {
+// runner.shutDown();
+// }
+//
+// notInterrupted = false;
+// }
+//
+// private List<HostDescription> getDefinedHostDescriptions() {
+// URL url = this.getClass().getClassLoader().getResource("host.xml");
+// ArrayList<HostDescription> hostDescriptions = new ArrayList<HostDescription>();
+// XMLStreamReader reader = null;
+// try {
+// if (url != null) {
+// reader = XMLInputFactory.newInstance().createXMLStreamReader(url.openStream());
+// } else {
+// throw new RuntimeException("Error retrieving host.xml file. Should reside in " +
+// "$SERVER_HOME/webapps/axis2/WEB-INF/classes/host.xml");
+// }
+// } catch (XMLStreamException e) {
+// e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+// } catch (IOException e) {
+// e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+// }
+// StAXOMBuilder builder = new StAXOMBuilder(reader);
+// OMElement documentElement = builder.getDocumentElement();
+// Iterator<?> server = documentElement.getChildrenWithName(new QName("server"));
+// while (server.hasNext()) {
+// HostDescription hostDescription = new HostDescription();
+// OMElement next = (OMElement) server.next();
+// if (next.getFirstChildWithName(new QName("gram.endpoint")) != null &&
+// "globus".equals(next.getFirstChildWithName(new QName("type")).getText())) {
+// hostDescription.getType().changeType(GlobusHostType.type);
+// ((GlobusHostType) hostDescription.getType()).addGlobusGateKeeperEndPoint(next.getFirstChildWithName(new QName("gram.endpoint")).getText());
+// ((GlobusHostType) hostDescription.getType()).addGridFTPEndPoint(next.getFirstChildWithName(new QName("gridftp.endpoint")).getText());
+// } else if("ssh".equals(next.getFirstChildWithName(new QName("type")).getText())) {
+// hostDescription.getType().changeType(SSHHostType.type);
+// if(next.getFirstChildWithName(new QName("hpc.resource")) != null){
+// if("true".equals(next.getFirstChildWithName(new QName("gram.endpoint")))){
+// ((SSHHostType) hostDescription.getType()).setHpcResource(true);
+// }
+// }
+// ((SSHHostType) hostDescription.getType()).setHpcResource(false);
+// } else if("gsissh".equals(next.getFirstChildWithName(new QName("type")).getText())) {
+// hostDescription.getType().changeType(GsisshHostType.type);
+// }
+// (hostDescription.getType()).setHostName(next.getFirstChildWithName(new QName("name")).getText());
+// (hostDescription.getType()).setHostAddress(next.getFirstChildWithName(new QName("host")).getText());
+// hostDescriptions.add(hostDescription);
+// }
+// return hostDescriptions;
+// }
+//
+// public static final int URL_UPDATE_INTERVAL = 1000 * 60 * 60 * 3;
+//
+// class WIServiceThread extends PeriodicExecutorThread {
+// private ConfigurationContext context = null;
+//
+// WIServiceThread(AiravataAPI registry, ConfigurationContext context) {
+// super(registry);
+// this.context = context;
+// }
+//
+// @Override
+// protected void updateRegistry(AiravataAPI registry) throws Exception {
+// URI localAddress = (URI) this.context.getProperty(SERVICE_URL);
+// registry.getAiravataManager().addWorkflowInterpreterURI(localAddress);
+// log.debug("Updated Workflow Interpreter service URL in to Repository");
+//
+// }
+// }
+//}
http://git-wip-us.apache.org/repos/asf/airavata/blob/a8974b7c/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/AsynchronousInvoker.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/AsynchronousInvoker.java b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/AsynchronousInvoker.java
new file mode 100644
index 0000000..fa0709d
--- /dev/null
+++ b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/AsynchronousInvoker.java
@@ -0,0 +1,118 @@
+/*
+ *
+ * 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.workflow.engine.invoker;
+
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.workflow.model.exceptions.WorkflowException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import xsul.wsdl.WsdlDefinitions;
+import xsul.wsif.WSIFMessage;
+import xsul.wsif.WSIFOperation;
+import xsul.xwsif_runtime_async.WSIFAsyncResponsesCorrelator;
+import xsul.xwsif_runtime_async_http.XsulSoapHttpWsaResponsesCorrelator;
+
+public class AsynchronousInvoker extends SimpleInvoker {
+
+ private static final Logger logger = LoggerFactory.getLogger(AsynchronousInvoker.class);
+
+ private String messageBoxURL;
+
+ /**
+ * Constructs an AsynchronousInvoker.
+ *
+ * @param definitions
+ */
+ public AsynchronousInvoker(WsdlDefinitions definitions) {
+ this(definitions, null);
+ }
+
+ /**
+ * Constructs an AsynchronousInvoker.
+ *
+ * @param definitions
+ * @param messageBoxURL
+ */
+ public AsynchronousInvoker(WsdlDefinitions definitions, String messageBoxURL) {
+ super(definitions);
+ this.messageBoxURL = messageBoxURL;
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.engine.invoker.SimpleInvoker#setup()
+ */
+ @Override
+ public void setup() throws WorkflowException {
+ super.setup();
+ /* Set the output message to null to set teh output from async Listener */
+ WSIFAsyncResponsesCorrelator correlator;
+ if (this.messageBoxURL == null || this.messageBoxURL.length() == 0) {
+ correlator = new XsulSoapHttpWsaResponsesCorrelator();
+ String serverLoc = ((XsulSoapHttpWsaResponsesCorrelator) correlator).getServerLocation();
+ logger.debug("using async correlator at " + serverLoc);
+ } else {
+ correlator = new MsgBoxWsaResponsesCorrelator(this.messageBoxURL,this);
+ logger.debug("using message box at " + this.messageBoxURL);
+ }
+ this.client.useAsyncMessaging(correlator);
+ }
+
+ public boolean invoke() throws WorkflowException {
+ final WSIFOperation operation = this.getOperation();
+ final WSIFMessage inputMessage = this.getInputMessage();
+ this.setOutputMessage(null);
+ try {
+ new Thread() {
+ @Override
+ public void run() {
+ try {
+ operation.executeInputOnlyOperation(inputMessage);
+ } catch (Exception e) {
+ // Ignore the error.
+ logger.error("Error invoking GFac Service",e);
+ }
+ }
+ }.start();
+
+ while(this.getOutputMessage() == null){
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ logger.error("Error Waiting for the response from backend");
+ }
+ }
+ // Gfac operation failed, so xbaya side throws this exception
+ if("ErrorResponse".equals(XMLUtil.stringToXmlElement3(this.getOutputMessage().toString()).getName())){
+ // Here we do not throw an exception, because if we throw an exception Interpreter will catch it and do the unsubscription,
+ // which is not needed because if there's an gfac side error gfac will send a failure and unsubscription will be done in monitoring
+ // so if we send an exception we are attempting to do two unsubscriptions which will cause a one unsubscription to fail.
+ return false;
+ }
+
+ return true;
+ } catch (RuntimeException e) {
+ String message = "Error in invoking a service.";
+ throw new WorkflowException(message, e);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/a8974b7c/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/DynamicInvoker.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/DynamicInvoker.java b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/DynamicInvoker.java
new file mode 100644
index 0000000..b9466c4
--- /dev/null
+++ b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/DynamicInvoker.java
@@ -0,0 +1,167 @@
+/*
+ *
+ * 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.workflow.engine.invoker;
+
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import org.apache.airavata.workflow.model.exceptions.WorkflowException;
+
+import xsul.wsif.WSIFMessage;
+import xsul.xwsif_runtime.WSIFClient;
+
+public class DynamicInvoker implements Invoker {
+
+ private URL jarUrl;
+
+ private String className;
+
+ private String operationName;
+
+ private Object[] inputs;
+
+ private Object result;
+
+ /**
+ * Constructs a DynamicInvoker.
+ *
+ * @param className
+ * @param jarUrl
+ * @param operationName
+ */
+ public DynamicInvoker(String className, URL jarUrl, String operationName, Object[] inputs) {
+ this.className = className;
+ this.jarUrl = jarUrl;
+ this.operationName = operationName;
+ this.inputs = inputs;
+ }
+
+ /**
+ * @see org.apache.airavata.xbaya.invoker.WorkflowInvoker#getOutput(java.lang.String)
+ */
+ public Object getOutput(String name) throws WorkflowException {
+ waitToFinish();
+ return result;
+ }
+
+ /**
+ * @see org.apache.airavata.xbaya.invoker.WorkflowInvoker#invoke()
+ */
+ public boolean invoke() throws WorkflowException {
+ try {
+ Class<?> targetClass = Class.forName(this.className);
+ Object obj = targetClass.newInstance();
+
+ Method[] methods = targetClass.getDeclaredMethods();
+ Method targetMethod = null;
+ for (Method method : methods) {
+ if (this.operationName.equals(method.getName())) {
+ targetMethod = method;
+ break;
+ }
+ }
+ if (targetMethod == null) {
+ throw new WorkflowException("Could not find the method using reflection: " + this.operationName);
+ }
+
+ targetMethod.setAccessible(true);
+ this.result = targetMethod.invoke(obj, inputs);
+
+ } catch (Exception e) {
+ throw new WorkflowException(e);
+ }
+ return true;
+ }
+
+ /**
+ * @see org.apache.airavata.xbaya.invoker.WorkflowInvoker#setInput(java.lang.String, java.lang.Object)
+ */
+ public void setInput(String name, Object value) throws WorkflowException {
+
+ }
+
+ /**
+ * @see org.apache.airavata.xbaya.invoker.WorkflowInvoker#setOperation(java.lang.String)
+ */
+ public void setOperation(String operationName) throws WorkflowException {
+ this.operationName = operationName;
+ }
+
+ /**
+ * @see org.apache.airavata.xbaya.invoker.WorkflowInvoker#setup()
+ */
+ public void setup() throws WorkflowException {
+ Class[] parameters = new Class[] { URL.class };
+ URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
+ Class sysclass = URLClassLoader.class;
+
+ try {
+ Method method = sysclass.getDeclaredMethod("addURL", parameters);
+ method.setAccessible(true);
+ method.invoke(sysloader, new Object[] { this.jarUrl });
+ } catch (Throwable t) {
+ t.printStackTrace();
+ throw new WorkflowException("Error, could not add URL to system classloader");
+ }
+ }
+
+ /**
+ * @see org.apache.airavata.xbaya.invoker.WorkflowInvoker#waitToFinish()
+ */
+ public void waitToFinish() throws WorkflowException {
+ while (this.result == null) {
+ try {
+ Thread.sleep(200);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ /**
+ * @see org.apache.airavata.xbaya.invoker.WorkflowInvoker#getOutputs()
+ */
+ public WSIFMessage getOutputs() throws WorkflowException {
+ waitToFinish();
+ return (WSIFMessage) this.result;
+
+ }
+
+ @Override
+ public WSIFClient getClient() {
+ return null;
+ }
+
+ @Override
+ public WSIFMessage getInputs() throws WorkflowException {
+ return null;
+ }
+
+ @Override
+ public WSIFMessage getFault() throws WorkflowException {
+ return null;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/a8974b7c/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/Invoker.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/Invoker.java b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/Invoker.java
new file mode 100644
index 0000000..cdd47e7
--- /dev/null
+++ b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/Invoker.java
@@ -0,0 +1,105 @@
+/*
+ *
+ * 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.workflow.engine.invoker;
+
+import org.apache.airavata.workflow.model.exceptions.WorkflowException;
+
+import xsul.wsif.WSIFMessage;
+import xsul.xwsif_runtime.WSIFClient;
+
+public interface Invoker {
+
+ /**
+ * Sets up the service.
+ *
+ * @throws WorkflowException
+ */
+ public void setup() throws WorkflowException;
+
+ /**
+ * @return The WSIFClient.
+ */
+ public WSIFClient getClient();
+
+ /**
+ * Sets the operation name to invoke.
+ *
+ * @param operationName
+ * The name of the operation
+ * @throws WorkflowException
+ */
+ public void setOperation(String operationName) throws WorkflowException;
+
+ /**
+ * Sets an input parameter
+ *
+ * @param name
+ * The name of the input parameter
+ * @param value
+ * The value of the input parameter
+ * @throws WorkflowException
+ */
+ public void setInput(String name, Object value) throws WorkflowException;
+
+ /**
+ * Returns the all input parameters
+ *
+ * @return The input parameters
+ * @throws WorkflowException
+ */
+ public WSIFMessage getInputs() throws WorkflowException;
+
+ /**
+ * Invokes the service.
+ *
+ * @return true if the invocation succeeds; fase otherwise
+ * @throws WorkflowException
+ */
+ public boolean invoke() throws WorkflowException;
+
+ /**
+ * Returns the all output parameters
+ *
+ * @return The output parameters
+ * @throws WorkflowException
+ */
+ public WSIFMessage getOutputs() throws WorkflowException;
+
+ /**
+ * Returns the output of a specified name.
+ *
+ * @param name
+ * The name of the output parameter
+ * @return The value of the output
+ * @throws WorkflowException
+ */
+ public Object getOutput(String name) throws WorkflowException;
+
+ /**
+ * Returns the fault message.
+ *
+ * @return The fault message
+ * @throws WorkflowException
+ */
+ public WSIFMessage getFault() throws WorkflowException;
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/a8974b7c/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/MsgBoxWsaResponsesCorrelator.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/MsgBoxWsaResponsesCorrelator.java b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/MsgBoxWsaResponsesCorrelator.java
new file mode 100644
index 0000000..80825d8
--- /dev/null
+++ b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/MsgBoxWsaResponsesCorrelator.java
@@ -0,0 +1,140 @@
+/*
+ *
+ * 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.workflow.engine.invoker;
+
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.wsmg.msgbox.client.MsgBoxClient;
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.addressing.EndpointReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xmlpull.v1.builder.XmlDocument;
+import org.xmlpull.v1.builder.XmlElement;
+import org.xmlpull.v1.builder.XmlInfosetBuilder;
+import xsul.MLogger;
+import xsul.XmlConstants;
+import xsul.XsulException;
+import xsul.processor.DynamicInfosetProcessorException;
+import xsul.ws_addressing.WsaEndpointReference;
+import xsul.ws_addressing.WsaMessageInformationHeaders;
+import xsul.wsif.WSIFMessage;
+import xsul.wsif.impl.WSIFMessageElement;
+import xsul.xwsif_runtime_async.WSIFAsyncResponseListener;
+import xsul.xwsif_runtime_async.WSIFAsyncResponsesCorrelator;
+import xsul.xwsif_runtime_async.WSIFAsyncWsaResponsesCorrelatorBase;
+
+import javax.xml.stream.XMLStreamException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class MsgBoxWsaResponsesCorrelator extends WSIFAsyncWsaResponsesCorrelatorBase
+ implements WSIFAsyncResponsesCorrelator, Runnable
+{
+ private static final Logger logger = LoggerFactory.getLogger(MsgBoxWsaResponsesCorrelator.class);
+ private final static XmlInfosetBuilder builder = XmlConstants.BUILDER;
+
+ private String msgBoxServiceLoc;
+ private MsgBoxClient msgBoxClient;
+ EndpointReference msgBoxAddr;
+ private Thread messageBoxDonwloader;
+
+ private AsynchronousInvoker invoker;
+
+ public MsgBoxWsaResponsesCorrelator(String msgBoxServiceLoc,AsynchronousInvoker output)
+ throws DynamicInfosetProcessorException
+ {
+ this.invoker = output;
+ this.msgBoxServiceLoc = msgBoxServiceLoc;
+ msgBoxClient = new MsgBoxClient();
+ try {
+ msgBoxAddr = msgBoxClient.createMessageBox(msgBoxServiceLoc,5000L);
+ try {
+ setReplyTo(new WsaEndpointReference(new URI(msgBoxAddr.getAddress())));
+ } catch (URISyntaxException e) {
+ logger.error(e.getLocalizedMessage(),e); //To change body of catch statement use File | Settings | File Templates.
+ }
+ messageBoxDonwloader = new Thread(this, Thread.currentThread().getName()+"-async-msgbox-correlator");
+ messageBoxDonwloader.setDaemon(true);
+ messageBoxDonwloader.start();
+ } catch (RemoteException e) {
+ logger.error(e.getLocalizedMessage(),e); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+
+// public void setMsgBoxAddr(WsaEndpointReference msgBoxAddr) {
+// this.msgBoxAddr = msgBoxAddr;
+// }
+
+
+
+ public void run() {
+ while(true) {
+ try {
+ Iterator<OMElement> omElementIterator = msgBoxClient.takeMessagesFromMsgBox(msgBoxAddr, 5000L);
+ List<XmlElement> xmlArrayList = new ArrayList<XmlElement>();
+ while (omElementIterator.hasNext()){
+ OMElement next = omElementIterator.next();
+ String message = next.toStringWithConsume();
+ xmlArrayList.add(XMLUtil.stringToXmlElement3(message));
+ }
+ // now hard work: find callbacks
+ for (int i = 0; i < xmlArrayList.size(); i++) {
+ XmlElement m = xmlArrayList.get(i);
+ try {
+ logger.debug(Thread.currentThread().getName());
+ WSIFMessageElement e = new WSIFMessageElement(m);
+ this.invoker.setOutputMessage(e);
+ //ideally there are no multiple messages, so we can return from this thread at this point
+ //otherwise this thread will keep running forever for each worfklow node, so there can be large
+ // number of waiting threads in an airavata deployment
+ return;
+ } catch (Throwable e) {
+ logger.error(e.getLocalizedMessage(),e); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+ try {
+ Thread.currentThread().sleep(1000L); //do not overload msg box service ...
+ } catch (InterruptedException e) {
+ break;
+ }
+ } catch (XsulException e) {
+ logger.error("could not retrieve messages");
+ break;
+ } catch (RemoteException e) {
+ logger.error("could not retrieve messages");
+ break;
+ } catch (XMLStreamException e) {
+ logger.error("could not retrieve messages");
+ break;
+ } catch (Exception e){
+ logger.error("could not retrieve messages");
+ break;
+ }
+ }
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/a8974b7c/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/SimpleInvoker.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/SimpleInvoker.java b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/SimpleInvoker.java
new file mode 100644
index 0000000..70be0e9
--- /dev/null
+++ b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/SimpleInvoker.java
@@ -0,0 +1,260 @@
+/*
+ *
+ * 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.workflow.engine.invoker;
+
+import java.util.Iterator;
+
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.workflow.model.exceptions.WorkflowException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xmlpull.v1.builder.XmlElement;
+
+import xsul.wsdl.WsdlDefinitions;
+import xsul.wsif.WSIFMessage;
+import xsul.wsif.WSIFOperation;
+import xsul.wsif.WSIFPort;
+import xsul.wsif.WSIFService;
+import xsul.wsif.WSIFServiceFactory;
+import xsul.wsif.spi.WSIFProviderManager;
+import xsul.xwsif_runtime.WSIFClient;
+import xsul.xwsif_runtime.WSIFRuntime;
+
+public class SimpleInvoker implements Invoker {
+
+ private static final Logger log = LoggerFactory.getLogger(SimpleInvoker.class);
+
+ protected WSIFClient client;
+
+ private WsdlDefinitions definitions;
+
+ private WSIFOperation operation;
+
+ private WSIFMessage inputMessage;
+
+ private volatile WSIFMessage outputMessage;
+
+ private WSIFMessage faultMessage;
+
+ private boolean lock = false;
+
+ static {
+ WSIFProviderManager.getInstance().addProvider(new xsul.wsif_xsul_soap_http.Provider());
+ }
+
+ /**
+ * Constructs a SimpleInvoker.
+ *
+ * @param definitions
+ */
+ public SimpleInvoker(WsdlDefinitions definitions) {
+ this.definitions = definitions;
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.engine.invoker.Invoker#setup()
+ */
+ public void setup() throws WorkflowException {
+ try {
+ WSIFService service = WSIFServiceFactory.newInstance().getService(this.definitions);
+ WSIFPort port = service.getPort();
+ this.client = WSIFRuntime.getDefault().newClientFor(port);
+ this.client.setAsyncResponseTimeoutInMs(999999999);
+ } catch (RuntimeException e) {
+ String message = "The WSDL is in the wrong format";
+ throw new WorkflowException(message, e);
+ }
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.engine.invoker.Invoker#getClient()
+ */
+ public WSIFClient getClient() {
+ return this.client;
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.engine.invoker.Invoker#setOperation(java.lang.String)
+ */
+ public void setOperation(String operationName) throws WorkflowException {
+ try {
+ WSIFPort port = this.client.getPort();
+ this.operation = port.createOperation(operationName);
+ this.inputMessage = this.operation.createInputMessage();
+ this.outputMessage = this.operation.createOutputMessage();
+ this.faultMessage = this.operation.createFaultMessage();
+ } catch (RuntimeException e) {
+ String message = "The WSDL does not conform to the invoking service.";
+ throw new WorkflowException(message, e);
+ }
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.engine.invoker.Invoker#setInput(java.lang.String, java.lang.Object)
+ */
+ public void setInput(String name, Object value) throws WorkflowException {
+ try {
+ if (value instanceof XmlElement) {
+ // If the value is a complex type, change the name of the
+ // element to the correct one.
+ XmlElement valueElement = (XmlElement) value;
+ valueElement.setName(name);
+ } else if (value instanceof String) {
+ if(XMLUtil.isXML((String)value)){
+ XmlElement valueElement = XMLUtil.stringToXmlElement3((String) value);
+ valueElement.setName(name);
+ value = valueElement;
+ }
+ // Simple case.
+ } else {
+ // convert int, doule to string.
+ value = "" + value;
+ }
+ this.inputMessage.setObjectPart(name, value);
+ } catch (RuntimeException e) {
+ String message = "Error in setting an input. name: " + name + " value: " + value;
+ throw new WorkflowException(message, e);
+ }
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.engine.invoker.Invoker#getInputs()
+ */
+ public WSIFMessage getInputs() {
+ return this.inputMessage;
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.engine.invoker.Invoker#invoke()
+ */
+ public boolean invoke() throws WorkflowException {
+ try {
+ boolean success = this.operation.executeRequestResponseOperation(this.inputMessage, this.outputMessage,
+ this.faultMessage);
+ while(this.outputMessage == null){
+
+ }
+ return success;
+ } catch (RuntimeException e) {
+ String message = "Error in invoking a service.";
+ throw new WorkflowException(message, e);
+ }
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.engine.invoker.Invoker#getOutputs()
+ */
+ public WSIFMessage getOutputs() {
+ if (lock) {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ return this.outputMessage;
+ }
+
+
+ /**
+ * @see org.apache.airavata.workflow.engine.invoker.Invoker#getOutput(java.lang.String)
+ */
+ public Object getOutput(String name) throws WorkflowException {
+ try {
+ // This code doesn't work when the output is a complex type.
+ // Object output = this.outputMessage.getObjectPart(name);
+ // return output;
+
+ XmlElement outputElement = (XmlElement) this.outputMessage;
+ XmlElement valueElement = outputElement.element(null, name);
+ Iterator childIt = valueElement.children();
+ int numberOfChildren = 0;
+ while (childIt.hasNext()) {
+ childIt.next();
+ numberOfChildren++;
+ }
+ if (numberOfChildren == 1) {
+ Object child = valueElement.children().next();
+ if (child instanceof String) {
+ // Value is a simple type. Return the string.
+ String value = (String) child;
+ return value;
+ }
+ if (child instanceof XmlElement) {
+ log.debug("output: " + XMLUtil.xmlElementToString((XmlElement) child));
+ Object child1 = ((XmlElement) child).children().next();
+ if (child1 instanceof String) {
+ // Value is a simple type. Return the string.
+ String value = (String) child1;
+ return value;
+ }
+ }
+ }
+ // Value is a complex type. Return the whole XmlElement so that we
+ // can set it to the next service as it is.
+ return valueElement;
+ } catch (RuntimeException e) {
+ String message = "Error in getting output. name: " + name;
+ throw new WorkflowException(message, e);
+ }
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.engine.invoker.Invoker#getFault()
+ */
+ public WSIFMessage getFault() {
+ return this.faultMessage;
+ }
+
+ public WsdlDefinitions getDefinitions() {
+ return definitions;
+ }
+
+ public WSIFOperation getOperation() {
+ return operation;
+ }
+
+ public WSIFMessage getInputMessage() {
+ return inputMessage;
+ }
+
+ public synchronized WSIFMessage getOutputMessage() {
+ return outputMessage;
+ }
+
+ public WSIFMessage getFaultMessage() {
+ return faultMessage;
+ }
+
+ public synchronized void setOutputMessage(WSIFMessage outputMessage) {
+ log.debug("Setting output message");
+ this.outputMessage = outputMessage;
+ }
+
+ public void setLock(boolean lock) {
+ this.lock = lock;
+ }
+
+ public boolean isLock() {
+ return lock;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/a8974b7c/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/WorkflowInputUtil.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/WorkflowInputUtil.java b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/WorkflowInputUtil.java
new file mode 100644
index 0000000..13eb884
--- /dev/null
+++ b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/invoker/WorkflowInputUtil.java
@@ -0,0 +1,52 @@
+/*
+ *
+ * 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.workflow.engine.invoker;
+
+import org.apache.airavata.common.utils.StringUtil;
+import org.apache.airavata.workflow.model.component.ws.WSComponentPort;
+
+public class WorkflowInputUtil {
+
+ public static String createInputForGFacService(WSComponentPort port,String input){
+ String paramType = port.getType().getLocalPart();
+ StringBuffer inputString = new StringBuffer("<");
+ if("StringParameterType".equals(paramType) || "URIParameterType".equals(paramType) ||
+ "DoubleParameterType".equals(paramType) || "IntegerParameterType".equals(paramType)
+ || "FloatParameterType".equals(paramType)|| "BooleanParameterType".equals(paramType)
+ || "FileParameterType".equals(paramType)){
+ inputString.append(port.getName()).append(">").
+ append(getValueElement(input)).append("</").append(port.getName()).append(">");
+ }else if(paramType.endsWith("ArrayType")){
+ inputString.append(port.getName()).append(">");
+ String[] valueList = StringUtil.getElementsFromString(input);
+ for(String inputValue:valueList){
+ inputString.append(getValueElement(inputValue));
+ }
+ inputString.append(getValueElement(port.getName()));
+ }
+ inputString.append(">");
+ return inputString.toString();
+ }
+
+ private static String getValueElement(String value){
+ return "<value>" + value + "</value>";
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/a8974b7c/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/util/AmazonUtil.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/util/AmazonUtil.java b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/util/AmazonUtil.java
new file mode 100644
index 0000000..5609a39
--- /dev/null
+++ b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/util/AmazonUtil.java
@@ -0,0 +1,150 @@
+/*
+ *
+ * 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.workflow.engine.util;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.airavata.workflow.engine.core.amazon.AmazonCredential;
+
+import com.amazonaws.auth.BasicAWSCredentials;
+import com.amazonaws.services.ec2.AmazonEC2;
+import com.amazonaws.services.ec2.AmazonEC2Client;
+import com.amazonaws.services.ec2.model.DescribeInstancesResult;
+import com.amazonaws.services.ec2.model.DescribeKeyPairsResult;
+import com.amazonaws.services.ec2.model.Instance;
+import com.amazonaws.services.ec2.model.KeyPairInfo;
+import com.amazonaws.services.ec2.model.Reservation;
+import com.amazonaws.services.ec2.model.RunInstancesRequest;
+import com.amazonaws.services.ec2.model.RunInstancesResult;
+import com.amazonaws.services.ec2.model.TerminateInstancesRequest;
+
+public class AmazonUtil {
+
+ /**
+ * Amazon EC2 instance type
+ */
+ public final static String[] INSTANCE_TYPE = { "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge",
+ "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge" };
+
+ private static AmazonEC2 getEC2Client() {
+ AmazonEC2 ec2 = new AmazonEC2Client(new BasicAWSCredentials(AmazonCredential.getInstance().getAwsAccessKeyId(),
+ AmazonCredential.getInstance().getAwsSecretAccessKey()));
+ return ec2;
+ }
+
+ /**
+ * Launch a new EC2 instance
+ *
+ * @param AMI_ID
+ * @param type
+ * @param number
+ * @return list of newly launched instances
+ */
+ public static List<Instance> launchInstance(String AMI_ID, String type, Integer number) {
+ List<Instance> resultList = new ArrayList<Instance>();
+
+ RunInstancesRequest request = new RunInstancesRequest(AMI_ID, number, number);
+ request.setInstanceType(type);
+
+ RunInstancesResult result = getEC2Client().runInstances(request);
+ resultList.addAll(result.getReservation().getInstances());
+ return resultList;
+ }
+
+ /**
+ * Launch a new EC2 instance
+ *
+ * @param AMI_ID
+ * @param type
+ * @param number
+ * @param keyname
+ * @return list of newly launched instances
+ */
+ public static List<Instance> launchInstance(String AMI_ID, String type, Integer number, String keyname) {
+ List<Instance> resultList = new ArrayList<Instance>();
+
+ RunInstancesRequest request = new RunInstancesRequest(AMI_ID, number, number);
+ request.setInstanceType(type);
+ request.setKeyName(keyname);
+
+ RunInstancesResult result = getEC2Client().runInstances(request);
+ resultList.addAll(result.getReservation().getInstances());
+ return resultList;
+ }
+
+ /**
+ * Load instances
+ *
+ * @return list of instances
+ */
+ public static List<Instance> loadInstances() {
+ List<Instance> resultList = new ArrayList<Instance>();
+ DescribeInstancesResult describeInstancesResult = getEC2Client().describeInstances();
+ List<Reservation> reservations = describeInstancesResult.getReservations();
+ for (Iterator<Reservation> iterator = reservations.iterator(); iterator.hasNext();) {
+ Reservation reservation = iterator.next();
+ for (Instance instance : reservation.getInstances()) {
+ resultList.add(instance);
+ }
+ }
+ return resultList;
+ }
+
+ /**
+ * Load keypairs
+ *
+ * @return list of keypairs
+ */
+ public static List<String> loadKeypairs() {
+ List<String> resultList = new ArrayList<String>();
+ DescribeKeyPairsResult results = getEC2Client().describeKeyPairs();
+ for (KeyPairInfo key : results.getKeyPairs()) {
+ resultList.add(key.getKeyName());
+ }
+ return resultList;
+ }
+
+ /**
+ * Terminate instances
+ *
+ * @param instanceIds
+ */
+ public static void terminateInstances(List<String> instanceIds) {
+ // terminate
+ TerminateInstancesRequest request = new TerminateInstancesRequest(instanceIds);
+ getEC2Client().terminateInstances(request);
+ }
+
+ /**
+ * Terminate instances
+ *
+ * @param instanceIds
+ */
+ public static void terminateInstances(String... instanceIds) {
+ // terminate
+ TerminateInstancesRequest request = new TerminateInstancesRequest();
+ getEC2Client().terminateInstances(request.withInstanceIds(instanceIds));
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/a8974b7c/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/util/Data.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/util/Data.java b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/util/Data.java
new file mode 100644
index 0000000..3a2da0b
--- /dev/null
+++ b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/util/Data.java
@@ -0,0 +1,70 @@
+/*
+ *
+ * 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.workflow.engine.util;
+
+public class Data {
+ private String destination_path;
+ private String verify_size;
+ private String source_path;
+ private boolean recursive;
+ private String DATA_TYPE;
+
+ public String getDestination_path() {
+ return destination_path;
+ }
+
+ public void setDestination_path(String destination_path) {
+ this.destination_path = destination_path;
+ }
+
+ public String getVerify_size() {
+ return verify_size;
+ }
+
+ public void setVerify_size(String verify_size) {
+ this.verify_size = verify_size;
+ }
+
+ public String getSource_path() {
+ return source_path;
+ }
+
+ public void setSource_path(String source_path) {
+ this.source_path = source_path;
+ }
+
+ public boolean getRecursive() {
+ return recursive;
+ }
+
+ public void setRecursive(boolean recursive) {
+ this.recursive = recursive;
+ }
+
+ public String getDATA_TYPE() {
+ return DATA_TYPE;
+ }
+
+ public void setDATA_TYPE(String DATA_TYPE) {
+ this.DATA_TYPE = DATA_TYPE;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/a8974b7c/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/util/GOConstants.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/util/GOConstants.java b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/util/GOConstants.java
new file mode 100644
index 0000000..909e04c
--- /dev/null
+++ b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/util/GOConstants.java
@@ -0,0 +1,30 @@
+/*
+ *
+ * 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.workflow.engine.util;
+
+public class GOConstants {
+ public static final String BASEURL = "https://transfer.api.globusonline.org/v0.10";
+ public static final String NEXUS_API_HOST = "nexus.api.globusonline.org";
+ public static final int NEXUS_API_PORT = 443;
+ public static final String NEXUS_API_SCHEMA = "https";
+ public static final String GOAUTH_TOKEN_REQ_URL = "/goauth/token?grant_type=client_credentials";
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/a8974b7c/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/util/GlobusOnlineUtils.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/util/GlobusOnlineUtils.java b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/util/GlobusOnlineUtils.java
new file mode 100644
index 0000000..4c22667
--- /dev/null
+++ b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/util/GlobusOnlineUtils.java
@@ -0,0 +1,246 @@
+package org.apache.airavata.workflow.engine.util;
+///*
+// *
+// * 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.util;
+//
+//import org.apache.http.HttpEntity;
+//import org.apache.http.HttpHost;
+//import org.apache.http.auth.AuthScope;
+//import org.apache.http.auth.UsernamePasswordCredentials;
+//import org.apache.http.client.AuthCache;
+//import org.apache.http.client.ClientProtocolException;
+//import org.apache.http.client.CredentialsProvider;
+//import org.apache.http.client.methods.CloseableHttpResponse;
+//import org.apache.http.client.methods.HttpGet;
+//import org.apache.http.client.protocol.HttpClientContext;
+//import org.apache.http.impl.auth.BasicScheme;
+//import org.apache.http.impl.client.BasicAuthCache;
+//import org.apache.http.impl.client.BasicCredentialsProvider;
+//import org.apache.http.impl.client.CloseableHttpClient;
+//import org.apache.http.impl.client.HttpClients;
+//import org.apache.http.util.EntityUtils;
+//import org.globusonline.transfer.APIError;
+//import org.globusonline.transfer.Authenticator;
+//import org.globusonline.transfer.GoauthAuthenticator;
+//import org.globusonline.transfer.JSONTransferAPIClient;
+//import org.json.JSONArray;
+//import org.json.JSONException;
+//import org.json.JSONObject;
+//import org.json.JSONTokener;
+//
+//import java.io.File;
+//import java.io.IOException;
+//import java.io.InputStream;
+//import java.io.InputStreamReader;
+//import java.security.GeneralSecurityException;
+//import java.security.KeyManagementException;
+//import java.security.NoSuchAlgorithmException;
+//import java.text.DateFormat;
+//import java.text.SimpleDateFormat;
+//import java.util.*;
+//
+//public class GlobusOnlineUtils {
+// public static final String ACCESS_TOKEN = "access_token";
+//
+// private static String goUserName;
+// private static String goPWD;
+//
+// public static void main(String[] args) {
+//// String s = appendFileName("/~/Desktop/1.docx", "/~/");
+//// System.out.println(s);
+//
+// }
+//
+// public GlobusOnlineUtils(String goUsername, String goPwd) {
+// goUserName = goUsername;
+// goPWD = goPwd;
+// }
+//
+// public String getAuthenticationToken() {
+// String token = null;
+// HttpHost targetHost = new HttpHost(GOConstants.NEXUS_API_HOST, GOConstants.NEXUS_API_PORT, GOConstants.NEXUS_API_SCHEMA);
+// CredentialsProvider credsProvider = new BasicCredentialsProvider();
+// credsProvider.setCredentials(
+// new AuthScope(targetHost.getHostName(), targetHost.getPort()),
+// new UsernamePasswordCredentials(goUserName, goPWD));
+//
+// CloseableHttpClient httpclient = HttpClients.custom()
+// .setDefaultCredentialsProvider(credsProvider).build();
+// try {
+//
+// // Create AuthCache instance
+// AuthCache authCache = new BasicAuthCache();
+// // Generate BASIC scheme object and add it to the local
+// // auth cache
+// BasicScheme basicScheme = new BasicScheme();
+// authCache.put(targetHost, basicScheme);
+//
+// // Add AuthCache to the execution context
+// HttpClientContext localContext = HttpClientContext.create();
+// localContext.setAuthCache(authCache);
+//
+// HttpGet httpget = new HttpGet(GOConstants.GOAUTH_TOKEN_REQ_URL);
+// httpget.addHeader("accept", "application/json");
+// System.out.println("executing request: " + httpget.getRequestLine());
+// System.out.println("to target: " + targetHost);
+//
+// CloseableHttpResponse response = httpclient.execute(targetHost, httpget, localContext);
+// try {
+// HttpEntity entity = response.getEntity();
+// InputStream entityContent = entity.getContent();
+// InputStreamReader reader = new InputStreamReader(entityContent);
+// JSONTokener tokenizer = new JSONTokener(reader);
+// JSONObject json = new JSONObject(tokenizer);
+// token = (String)json.get(ACCESS_TOKEN);
+// entityContent.close();
+// EntityUtils.consume(entity);
+//
+// } catch (JSONException e) {
+// e.printStackTrace();
+// } finally {
+// response.close();
+// }
+// //}
+// } catch (ClientProtocolException e) {
+// e.printStackTrace();
+// } catch (IOException e) {
+// e.printStackTrace();
+// } finally {
+// try {
+// httpclient.close();
+// } catch (IOException e) {
+// e.printStackTrace();
+// }
+// }
+// return token;
+// }
+//
+// public JSONTransferAPIClient getAuthenticated (){
+// JSONTransferAPIClient jsonTransferAPIClient = null;
+// try {
+// String authenticationToken = getAuthenticationToken();
+// Authenticator authenticator = new GoauthAuthenticator(authenticationToken);
+// jsonTransferAPIClient = new JSONTransferAPIClient(goUserName,
+// null, GOConstants.BASEURL);
+// jsonTransferAPIClient.setAuthenticator(authenticator);
+// } catch (KeyManagementException e) {
+// e.printStackTrace();
+// } catch (NoSuchAlgorithmException e) {
+// e.printStackTrace();
+// }
+// return jsonTransferAPIClient;
+// }
+//
+// public String transferFiles (TransferFile tf){
+// String taskId = null;
+// try {
+// JSONTransferAPIClient apiClient = getAuthenticated();
+// String submissionId = apiClient.getSubmissionId();
+// tf.setSubmission_id(submissionId);
+// JSONObject jsonObject = new JSONObject(tf);
+// JSONTransferAPIClient.Result result = apiClient.transfer(jsonObject);
+// taskId = (String)result.document.get("task_id");
+// } catch (IOException e) {
+// e.printStackTrace();
+// } catch (GeneralSecurityException e) {
+// e.printStackTrace();
+// } catch (JSONException e) {
+// e.printStackTrace();
+// } catch (APIError apiError) {
+// apiError.printStackTrace();
+// }
+// return taskId;
+// }
+//
+// public TransferFile getTransferFile (String sourceEp,
+// String destEp,
+// String sourcePath,
+// String destPath,
+// String label){
+//
+// TransferFile transferFile = new TransferFile();
+//
+//
+// transferFile.setPreserve_timestamp(false);
+// transferFile.setDATA_TYPE("transfer");
+// transferFile.setEncrypt_data(false);
+// transferFile.setSync_level(null);
+// transferFile.setSource_endpoint(sourceEp);
+// transferFile.setLabel(label);
+// transferFile.setDestination_endpoint(destEp);
+// transferFile.setLength(2);
+// transferFile.setDeadline(getDeadlineForTransfer());
+// transferFile.setNotify_on_succeeded(true);
+// transferFile.setNotify_on_failed(true);
+// transferFile.setVerify_checksum(false);
+// transferFile.setDelete_destination_extra(false);
+// Data[] datas = new Data[1];
+// Data data = new Data();
+// data.setDATA_TYPE("transfer_item");
+// data.setDestination_path(appendFileName(sourcePath, destPath));
+// data.setVerify_size(null);
+// data.setSource_path(sourcePath);
+// data.setRecursive(false);
+// datas[0] = data;
+// transferFile.setDATA(datas);
+// return transferFile;
+// }
+//
+// private static String appendFileName(String sourcePath, String destPath){
+// String[] split = sourcePath.split(File.separator);
+// String fileName = split[split.length - 1];
+// if (destPath.endsWith(File.separator)){
+// destPath = destPath.concat(fileName);
+// }else {
+// destPath = destPath.concat("/" + fileName);
+// }
+// System.out.println(destPath);
+// return destPath;
+// }
+//
+// private String getDeadlineForTransfer (){
+// DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+// Calendar calendar = Calendar.getInstance();
+// calendar.add(calendar.DAY_OF_MONTH, 1);
+// Date tomorrow = calendar.getTime();
+// String date = dateFormat.format(tomorrow);
+// System.out.println(date);
+// return date;
+// }
+//
+// public List<String> getEPList() throws IOException, APIError, GeneralSecurityException, JSONException {
+// List<String> epList = new ArrayList<String>();
+// Map<String, String> params = new HashMap<String, String>();
+// params.put("limit", "0");
+// JSONTransferAPIClient transferAPIClient = getAuthenticated();
+// JSONTransferAPIClient.Result result = transferAPIClient.getResult("/endpoint_list", params);
+// JSONObject document = result.document;
+// JSONArray dataArray = document.getJSONArray("DATA");
+// for (int i = 0; i < dataArray.length(); i++ ){
+// JSONObject jsonObject = dataArray.getJSONObject(i);
+// String epName = (String)jsonObject.get("canonical_name");
+// epList.add(epName);
+// }
+// return epList;
+// }
+//
+//}