Author: lahiru
Date: Tue Jan 29 17:41:15 2013
New Revision: 1440024

URL: http://svn.apache.org/viewvc?rev=1440024&view=rev
Log:
adding a test case to test LocalProvider with new gfac changes.

Added:
    
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/LocalProviderTest.java
    
airavata/trunk/modules/gfac-core/src/test/resources/airavata-client.properties
Modified:
    
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/Constants.java
    
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacAPI.java
    
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/AbstractContext.java
    
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/notification/listeners/WorkflowTrackingListener.java
    
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/LocalProvider.java

Modified: 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/Constants.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/Constants.java?rev=1440024&r1=1440023&r2=1440024&view=diff
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/Constants.java
 (original)
+++ 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/Constants.java
 Tue Jan 29 17:41:15 2013
@@ -36,4 +36,8 @@ public class Constants {
     public static final int DEFAULT_GSI_FTP_PORT = 2811;
     public static final String _127_0_0_1 = "127.0.0.1";
     public static final String LOCALHOST = "localhost";
-}
+
+    public static final String PROP_WORKFLOW_INSTANCE_ID = 
"workflow.instance.id";
+    public static final String PROP_WORKFLOW_NODE_ID = "workflow.node.id";
+    public static final String PROP_BROKER_URL = "broker.url";
+    public static final String PROP_TOPIC = "topic";}

Modified: 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacAPI.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacAPI.java?rev=1440024&r1=1440023&r2=1440024&view=diff
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacAPI.java
 (original)
+++ 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacAPI.java
 Tue Jan 29 17:41:15 2013
@@ -38,16 +38,13 @@ import java.util.List;
 public class GFacAPI {
     private static final Logger log = LoggerFactory.getLogger(GFacAPI.class);
 
-    public static final String PROP_WORKFLOW_INSTANCE_ID = 
"workflow.instance.id";
-    public static final String PROP_WORKFLOW_NODE_ID = "workflow.node.id";
-    public static final String PROP_BROKER_URL = "broker.url";
-    public static final String PROP_TOPIC = "topic";
+
 
     public void submitJob(JobExecutionContext jobExecutionContext) throws 
GFacException {
         // We need to check whether this job is submitted as a part of a large 
workflow. If yes,
         // we need to setup workflow tracking listerner.
         String workflowInstanceID = null;
-        if ((workflowInstanceID = (String) 
jobExecutionContext.getProperty(PROP_WORKFLOW_INSTANCE_ID)) != null) {
+        if ((workflowInstanceID = (String) 
jobExecutionContext.getProperty(Constants.PROP_WORKFLOW_INSTANCE_ID)) != null) {
             // This mean we need to register workflow tracking listener.
             registerWorkflowTrackingListener(workflowInstanceID, 
jobExecutionContext);
         }
@@ -102,9 +99,9 @@ public class GFacAPI {
     }
 
     private void registerWorkflowTrackingListener(String workflowInstanceID, 
JobExecutionContext jobExecutionContext) {
-        String workflowNodeID = (String) 
jobExecutionContext.getProperty(PROP_WORKFLOW_NODE_ID);
-        String topic = (String) jobExecutionContext.getProperty(PROP_TOPIC);
-        String brokerUrl = (String) 
jobExecutionContext.getProperty(PROP_BROKER_URL);
+        String workflowNodeID = (String) 
jobExecutionContext.getProperty(Constants.PROP_WORKFLOW_NODE_ID);
+        String topic = (String) 
jobExecutionContext.getProperty(Constants.PROP_TOPIC);
+        String brokerUrl = (String) 
jobExecutionContext.getProperty(Constants.PROP_BROKER_URL);
         jobExecutionContext.getNotificationService().registerListener(
                 new WorkflowTrackingListener(workflowInstanceID, 
workflowNodeID, brokerUrl, topic));
 

Modified: 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/AbstractContext.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/AbstractContext.java?rev=1440024&r1=1440023&r2=1440024&view=diff
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/AbstractContext.java
 (original)
+++ 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/AbstractContext.java
 Tue Jan 29 17:41:15 2013
@@ -43,4 +43,8 @@ public abstract class AbstractContext {
     public AbstractContext getParent() {
         return parent;
     }
+
+    public void setProperty(String name, Object value) {
+        properties.put(name, value);
+    }
 }

Modified: 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/notification/listeners/WorkflowTrackingListener.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/notification/listeners/WorkflowTrackingListener.java?rev=1440024&r1=1440023&r2=1440024&view=diff
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/notification/listeners/WorkflowTrackingListener.java
 (original)
+++ 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/notification/listeners/WorkflowTrackingListener.java
 Tue Jan 29 17:41:15 2013
@@ -59,10 +59,9 @@ public class WorkflowTrackingListener {
         URI initiatorServiceID = URI.create(topic);
         String initiatorWorkflowNodeID = workflowNodeID;
         Integer initiatorWorkflowTimeStep = null;
-        this.context.setTopic(topic);
-
         this.context = this.notifier.createTrackingContext(new Properties(), 
brokerURL, initiatorWorkflowID, initiatorServiceID,
                 initiatorWorkflowNodeID, initiatorWorkflowTimeStep);
+        this.context.setTopic(topic);
         this.initiator = this.notifier.createEntity(initiatorWorkflowID, 
initiatorServiceID, initiatorWorkflowNodeID,
                 initiatorWorkflowTimeStep);
 

Modified: 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/LocalProvider.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/LocalProvider.java?rev=1440024&r1=1440023&r2=1440024&view=diff
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/LocalProvider.java
 (original)
+++ 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/LocalProvider.java
 Tue Jan 29 17:41:15 2013
@@ -21,6 +21,7 @@
 package org.apache.airavata.gfac.provider.impl;
 
 import org.apache.airavata.commons.gfac.type.ActualParameter;
+import org.apache.airavata.commons.gfac.type.MappingFactory;
 import org.apache.airavata.gfac.Constants;
 import org.apache.airavata.gfac.context.JobExecutionContext;
 import org.apache.airavata.gfac.context.MessageContext;
@@ -141,7 +142,6 @@ public class LocalProvider implements GF
     private List<String> getInputParameters(JobExecutionContext 
jobExecutionContext) throws GFacProviderException {
         List<String> parameters = new ArrayList<String>();
         MessageContext inMessageContext = 
jobExecutionContext.getInMessageContext();
-
         InputParameterType[] inputParamDefinitionArray = 
jobExecutionContext.getApplicationContext().
                 getServiceDescription().getType().getInputParametersArray();
         for (InputParameterType inputParam : inputParamDefinitionArray) {
@@ -151,7 +151,7 @@ public class LocalProvider implements GF
                 throw new GFacProviderException("Cannot find required input 
parameter " + parameterName + ".");
             }
 
-            parameters.add(parameter.toString());
+            parameters.add(MappingFactory.toString(parameter));
         }
 
         return parameters;

Added: 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/LocalProviderTest.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/LocalProviderTest.java?rev=1440024&view=auto
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/LocalProviderTest.java
 (added)
+++ 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/LocalProviderTest.java
 Tue Jan 29 17:41:15 2013
@@ -0,0 +1,151 @@
+/*
+ *
+ * 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.core.gfac.services.impl;
+
+import org.apache.airavata.client.AiravataAPIFactory;
+import org.apache.airavata.client.api.AiravataAPI;
+import org.apache.airavata.commons.gfac.type.*;
+import org.apache.airavata.gfac.Constants;
+import org.apache.airavata.gfac.GFacAPI;
+import org.apache.airavata.gfac.GFacConfiguration;
+import org.apache.airavata.gfac.GFacException;
+import org.apache.airavata.gfac.context.ApplicationContext;
+import org.apache.airavata.gfac.context.JobExecutionContext;
+import org.apache.airavata.gfac.context.MessageContext;
+import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
+import org.apache.airavata.schemas.gfac.InputParameterType;
+import org.apache.airavata.schemas.gfac.OutputParameterType;
+import org.apache.airavata.schemas.gfac.StringParameterType;
+import org.apache.commons.lang.SystemUtils;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+public class LocalProviderTest {
+    private JobExecutionContext jobExecutionContext;
+    @Before
+    public void setUp() throws Exception {
+
+        GFacConfiguration gFacConfiguration = new GFacConfiguration(null);
+        //have to set InFlwo Handlers and outFlowHandlers
+        jobExecutionContext = new JobExecutionContext(gFacConfiguration);
+        ApplicationContext applicationContext = new ApplicationContext();
+        jobExecutionContext.setApplicationContext(applicationContext);
+        /*
+           * Host
+           */
+        HostDescription host = new HostDescription();
+        host.getType().setHostName("localhost");
+        host.getType().setHostAddress("localhost");
+        applicationContext.setHostDescription(host);
+        /*
+           * App
+           */
+        ApplicationDescription appDesc = new ApplicationDescription();
+        ApplicationDeploymentDescriptionType app = appDesc.getType();
+        ApplicationDeploymentDescriptionType.ApplicationName name = 
ApplicationDeploymentDescriptionType.ApplicationName.Factory.newInstance();
+        name.setStringValue("EchoLocal");
+        app.setApplicationName(name);
+
+        /*
+           * Use bat file if it is compiled on Windows
+           */
+        if (SystemUtils.IS_OS_WINDOWS) {
+            URL url = this.getClass().getClassLoader().getResource("echo.bat");
+            app.setExecutableLocation(url.getFile());
+        } else {
+            //for unix and Mac
+            app.setExecutableLocation("/bin/echo");
+        }
+
+        /*
+           * Default tmp location
+           */
+        String tempDir = System.getProperty("java.io.tmpdir");
+        if (tempDir == null) {
+            tempDir = "/tmp";
+        }
+
+        app.setScratchWorkingDirectory(tempDir);
+        app.setStaticWorkingDirectory(tempDir);
+        app.setInputDataDirectory(tempDir + File.separator + "input");
+        app.setOutputDataDirectory(tempDir + File.separator + "output");
+        app.setStandardOutput(tempDir + File.separator + "echo.stdout");
+        app.setStandardError(tempDir + File.separator + "echo.stderr");
+
+        applicationContext.setApplicationDeploymentDescription(appDesc);
+
+        /*
+           * Service
+           */
+        ServiceDescription serv = new ServiceDescription();
+        serv.getType().setName("SimpleEcho");
+
+        List<InputParameterType> inputList = new 
ArrayList<InputParameterType>();
+        InputParameterType input = InputParameterType.Factory.newInstance();
+        input.setParameterName("echo_input");
+        input.setParameterType(StringParameterType.Factory.newInstance());
+        inputList.add(input);
+        InputParameterType[] inputParamList = inputList.toArray(new 
InputParameterType[inputList
+                .size()]);
+
+        List<OutputParameterType> outputList = new 
ArrayList<OutputParameterType>();
+        OutputParameterType output = OutputParameterType.Factory.newInstance();
+        output.setParameterName("echo_output");
+        output.setParameterType(StringParameterType.Factory.newInstance());
+        outputList.add(output);
+        OutputParameterType[] outputParamList = outputList
+                .toArray(new OutputParameterType[outputList.size()]);
+
+        serv.getType().setInputParametersArray(inputParamList);
+        serv.getType().setOutputParametersArray(outputParamList);
+
+        applicationContext.setServiceDescription(serv);
+
+        MessageContext inMessage = new MessageContext();
+        ActualParameter echo_input = new ActualParameter();
+               
((StringParameterType)echo_input.getType()).setValue("echo_output=hello");
+        inMessage.addParameter("echo_input", echo_input);
+
+        jobExecutionContext.setInMessageContext(inMessage);
+
+        MessageContext outMessage = new MessageContext();
+        ActualParameter echo_out = new ActualParameter();
+//             
((StringParameterType)echo_input.getType()).setValue("echo_output=hello");
+        outMessage.addParameter("echo_output", echo_out);
+
+        jobExecutionContext.setOutMessageContext(outMessage);
+
+    }
+
+    @Test
+    public void testLocalProvider() throws GFacException {
+        GFacAPI gFacAPI = new GFacAPI();
+        gFacAPI.submitJob(jobExecutionContext);
+        MessageContext outMessageContext = 
jobExecutionContext.getOutMessageContext();
+        
Assert.assertEquals(MappingFactory.toString((ActualParameter)outMessageContext.getParameter("echo_output")),
 "hello");
+    }
+}

Added: 
airavata/trunk/modules/gfac-core/src/test/resources/airavata-client.properties
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/test/resources/airavata-client.properties?rev=1440024&view=auto
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/test/resources/airavata-client.properties 
(added)
+++ 
airavata/trunk/modules/gfac-core/src/test/resources/airavata-client.properties 
Tue Jan 29 17:41:15 2013
@@ -0,0 +1,66 @@
+#
+#
+# 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.
+#
+
+###########################################################################
+#
+#  This properties file provides configuration for Airavata Clients:
+#  XBaya and Airavata API
+#
+###########################################################################
+
+###---------------------------REGISTRY API 
IMPLEMENTATION---------------------------###
+
+class.registry.accessor=org.apache.airavata.persistance.registry.jpa.impl.AiravataJPARegistry
+#class.registry.accessor=org.apache.airavata.rest.client.RegistryClient
+
+###---------------------REGISTRY API IMPLEMENTATION - CUSTOM 
SETTINGS----------------------###
+
+#for mysql [AiravataJPARegistry]
+#registry.jdbc.driver=com.mysql.jdbc.Driver
+#registry.jdbc.url=jdbc:mysql://localhost:3306/persistent_data
+
+#for derby [AiravataJPARegistry]
+registry.jdbc.driver=org.apache.derby.jdbc.ClientDriver
+registry.jdbc.url=jdbc:derby://localhost:1527/persistent_data;create=true;user=airavata;password=airavata
+registry.jdbc.user=airavata
+registry.jdbc.password=airavata
+start.derby.server.mode=true
+
+default.registry.user=admin
+default.registry.password=admin
+default.registry.password.hash.method=SHA
+default.registry.gateway=default
+
+#for xbaya
+xbaya.registry.user=admin
+xbaya.registry.url=http://localhost:8080/airavata-registry/api
+xbaya.default.gateway=default
+
+trust.store=aiaravata.jks
+trust.store.password=airavata
+
+#user defined registry accessor classes
+#class.provenance.registry.accessor=org.apache.airavata.persistance.registry.jpa.impl.AiravataJPARegistry
+#class.configuration.registry.accessor=org.apache.airavata.persistance.registry.jpa.impl.AiravataJPARegistry
+#class.descriptor.registry.accessor=org.apache.airavata.persistance.registry.jpa.impl.AiravataJPARegistry
+#class.project.registry.accessor=org.apache.airavata.persistance.registry.jpa.impl.AiravataJPARegistry
+#class.user.workflow.registry.accessor=org.apache.airavata.persistance.registry.jpa.impl.AiravataJPARegistry
+#class.published.workflow.registry.accessor=org.apache.airavata.persistance.registry.jpa.impl.AiravataJPARegistry
+


Reply via email to