Author: lahiru
Date: Thu Feb 21 15:35:22 2013
New Revision: 1448682

URL: http://svn.apache.org/r1448682
Log:
committing shabhaz's patch.

Added:
    
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/BESProvider.java
    
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/BESProviderTest.java
    
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/JSDLGeneratorTest.java

Added: 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/BESProvider.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/BESProvider.java?rev=1448682&view=auto
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/BESProvider.java
 (added)
+++ 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/BESProvider.java
 Thu Feb 21 15:35:22 2013
@@ -0,0 +1,259 @@
+/*
+ *
+ * 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.gfac.provider.impl;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.airavata.gfac.context.GSISecurityContext;
+import org.apache.airavata.gfac.context.JobExecutionContext;
+import org.apache.airavata.gfac.provider.GFacProvider;
+import org.apache.airavata.gfac.provider.GFacProviderException;
+import org.apache.airavata.gfac.provider.utils.JSDLGenerator;
+import org.apache.airavata.schemas.gfac.UnicoreHostType;
+import org.ggf.schemas.bes.x2006.x08.besFactory.ActivityStateEnumeration;
+import org.ggf.schemas.bes.x2006.x08.besFactory.CreateActivityDocument;
+import org.ggf.schemas.bes.x2006.x08.besFactory.CreateActivityResponseDocument;
+import org.globus.gsi.GlobusCredential;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3.x2005.x08.addressing.EndpointReferenceType;
+
+import de.fzj.unicore.bes.client.FactoryClient;
+import de.fzj.unicore.bes.faults.InvalidRequestMessageFault;
+import de.fzj.unicore.bes.faults.NotAcceptingNewActivitiesFault;
+import de.fzj.unicore.bes.faults.UnsupportedFeatureFault;
+
+import de.fzj.unicore.wsrflite.xmlbeans.WSUtilities;
+import eu.emi.security.authn.x509.impl.CertificateUtils.Encoding;
+import eu.emi.security.authn.x509.impl.DirectoryCertChainValidator;
+import eu.emi.security.authn.x509.impl.PEMCredential;
+import eu.unicore.util.httpclient.DefaultClientConfiguration;
+
+
+
+public class BESProvider implements GFacProvider {
+    protected final Logger log = LoggerFactory.getLogger(this.getClass());
+
+    private DefaultClientConfiguration secProperties;
+
+    private String jobId;
+    
+    
+        
+    @Override
+       public void initialize(JobExecutionContext jobExecutionContext)
+                       throws GFacProviderException {
+               
+       log.info("Initializing GFAC's <<< UNICORE Provider >>>");
+       initSecurityProperties(jobExecutionContext);
+       log.debug("initialized security properties");
+
+       }
+
+       @Override
+       public void execute(JobExecutionContext jobExecutionContext)
+                       throws GFacProviderException {
+               UnicoreHostType host = (UnicoreHostType) 
jobExecutionContext.getApplicationContext().getHostDescription().getType();
+        
+        String factoryUrl = host.getUnicoreHostAddressArray()[0];
+
+        EndpointReferenceType eprt = 
EndpointReferenceType.Factory.newInstance();
+        eprt.addNewAddress().setStringValue(factoryUrl);
+        log.info("========================================");
+        log.info(String.format("Job Submitted to %s.\n", factoryUrl));
+
+        FactoryClient factory = null;
+        try {
+            factory = new FactoryClient(eprt, secProperties);
+        } catch (Exception e) {
+            throw new GFacProviderException("");
+        }
+        CreateActivityDocument cad = CreateActivityDocument.Factory
+                .newInstance();
+        
+        
+        try {
+                       cad.addNewCreateActivity().addNewActivityDocument()
+                               
.setJobDefinition(JSDLGenerator.buildJSDLInstance(jobExecutionContext).getJobDefinition());
+               } catch (Exception e1) {
+                       // TODO Auto-generated catch block
+                       e1.printStackTrace();
+               }
+        
+        CreateActivityResponseDocument response = null;
+        try {
+            response = factory.createActivity(cad);
+        } catch (NotAcceptingNewActivitiesFault 
notAcceptingNewActivitiesFault) {
+            notAcceptingNewActivitiesFault.printStackTrace();  //To change 
body of catch statement use File | Settings | File Templates.
+        } catch (InvalidRequestMessageFault invalidRequestMessageFault) {
+            invalidRequestMessageFault.printStackTrace();  //To change body of 
catch statement use File | Settings | File Templates.
+        } catch (UnsupportedFeatureFault unsupportedFeatureFault) {
+            unsupportedFeatureFault.printStackTrace();  //To change body of 
catch statement use File | Settings | File Templates.
+        }
+        EndpointReferenceType activityEpr = response
+                .getCreateActivityResponse().getActivityIdentifier();
+        
+        log.debug("Job EPR: "+activityEpr);
+        
+        log.info("Job: "+activityEpr.getAddress().getStringValue()+  " 
Submitted.");
+        
+        //factory.waitWhileActivityIsDone(activityEpr, 1000);
+        jobId = WSUtilities.extractResourceID(activityEpr);
+        if (jobId == null) {
+            jobId = new Long(Calendar.getInstance().getTimeInMillis())
+                    .toString();
+        }
+        
+
+        String status = String.format("Job %s is %s.\n", 
activityEpr.getAddress()
+                .getStringValue(), factory.getActivityStatus(activityEpr)
+                .toString()).toString();
+
+        
+        log.info(status);
+        
+        
+        while ((factory.getActivityStatus(activityEpr) != 
ActivityStateEnumeration.FINISHED) &&
+                (factory.getActivityStatus(activityEpr) != 
ActivityStateEnumeration.FAILED)){
+            status = String.format("Job %s is %s.\n", activityEpr.getAddress()
+                    .getStringValue(), factory.getActivityStatus(activityEpr)
+                    .toString()).toString();
+            try {
+               log.info(status);
+                Thread.sleep(1000);
+            } catch (InterruptedException e) {
+                e.printStackTrace();  //To change body of catch statement use 
File | Settings | File Templates.
+            }
+            continue;
+        }
+
+        status = String.format("Job %s is %s.\n", activityEpr.getAddress()
+                .getStringValue(), factory.getActivityStatus(activityEpr)
+                .toString()).toString();
+
+        log.info(status);
+
+       }
+
+       @Override
+       public void dispose(JobExecutionContext jobExecutionContext)
+                       throws GFacProviderException {
+               
+               secProperties = null;
+               
+       }
+       
+       
+       protected void initSecurityProperties(JobExecutionContext 
jobExecutionContext) throws GFacProviderException{
+               
+               if (secProperties != null) return;
+               
+               GSISecurityContext gssContext = new 
GSISecurityContext(jobExecutionContext.getGFacConfiguration());
+               GlobusCredential credentials = gssContext.getGlobusCredential();
+               ByteArrayOutputStream bos = new ByteArrayOutputStream();
+               
+               BufferedOutputStream bufos = new BufferedOutputStream(bos);
+               
+               ByteArrayInputStream bis = null;
+               BufferedInputStream bufis = null;
+               try{
+                       credentials.save(bufos);
+                       bufos.flush();
+                       
+                       //TODO: to be supported by airavata gsscredential class
+                       List<String> trustedCert = new ArrayList<String>();
+                       trustedCert.add(gssContext.getTrustedCertLoc()+"/*.0");
+                       
trustedCert.add(gssContext.getTrustedCertLoc()+"/*.pem");
+                       
+                       char[] c = null;
+                       
+                       DirectoryCertChainValidator dcValidator = new 
DirectoryCertChainValidator(trustedCert, Encoding.PEM, -1, 60000, null);
+                       bis = new ByteArrayInputStream(bos.toByteArray());
+                       bufis = new BufferedInputStream(bis);
+                       PEMCredential pem = new PEMCredential(bufis, c);
+                       
+                       secProperties = new 
DefaultClientConfiguration(dcValidator, pem);
+                       secProperties.doSSLAuthn();
+                       
+                       String[] outHandlers = 
secProperties.getOutHandlerClassNames();
+                       
+                       Set<String> outHandlerLst = null; 
+                       
+               if(outHandlers == null) {
+                       outHandlerLst = new HashSet<String>();
+               }
+               else  {
+                       outHandlerLst = new 
HashSet<String>(Arrays.asList(outHandlers));
+               }
+               
+               
outHandlerLst.add("de.fzj.unicore.uas.security.ProxyCertOutHandler");
+               
+               secProperties.setOutHandlerClassNames(outHandlerLst.toArray(new 
String[outHandlerLst.size()]));
+                       
+               }
+               catch (Exception e) {
+                       throw new GFacProviderException(e.getMessage(), e); 
+               } 
+               finally{
+                       try {
+                               if(bos!=null)bos.close();
+                               if(bufos!=null)bufos.close();
+                               if(bis!=null)bis.close();
+                               if(bufis!=null)bufis.close();
+                       } catch (IOException e) {
+                               e.printStackTrace();
+                       }
+               }
+       }
+       
+       
+//     public static void main(String[] args) throws Exception {
+//             
+//             
PropertyConfigurator.configure("src/test/resources/logging.properties");
+//             
+////           String url = 
"https://daemon.india.futuregrid.org:8081/INDIA/services/BESFactory?res=default_bes_factory";;
+//             
+//             String url = 
"https://zam1161v01.zam.kfa-juelich.de:8002/INTEROP1/services/BESFactory?res=default_bes_factory";;
+//             
+//             ClientProperties cp = new ClientProperties(new 
File("src/test/resources/sec.properties"));
+//             
+//             EndpointReferenceType epr = WSUtilities.makeServiceEPR(url);
+//             
+//             FactoryClient bes = new FactoryClient(url, epr, cp);
+//             
+//             System.out.println(bes.getFactoryAttributesDocument());
+//             
+//     }
+       
+       
+       
+       
+}

Added: 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/BESProviderTest.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/BESProviderTest.java?rev=1448682&view=auto
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/BESProviderTest.java
 (added)
+++ 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/BESProviderTest.java
 Thu Feb 21 15:35:22 2013
@@ -0,0 +1,217 @@
+//package org.apache.airavata.core.gfac.services.impl;
+//
+//import java.io.File;
+//import java.net.URL;
+//import java.util.ArrayList;
+//import java.util.Date;
+//import java.util.List;
+//import java.util.UUID;
+//
+//import org.apache.airavata.commons.gfac.type.ActualParameter;
+//import org.apache.airavata.commons.gfac.type.ApplicationDescription;
+//import org.apache.airavata.commons.gfac.type.HostDescription;
+//import org.apache.airavata.commons.gfac.type.ServiceDescription;
+//import org.apache.airavata.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.HpcApplicationDeploymentType;
+//import org.apache.airavata.schemas.gfac.InputParameterType;
+//import org.apache.airavata.schemas.gfac.JobTypeType;
+//import org.apache.airavata.schemas.gfac.OutputParameterType;
+//import org.apache.airavata.schemas.gfac.ProjectAccountType;
+//import org.apache.airavata.schemas.gfac.QueueType;
+//import org.apache.airavata.schemas.gfac.StringParameterType;
+//import org.apache.airavata.schemas.gfac.URIParameterType;
+//import org.apache.airavata.schemas.gfac.UnicoreHostType;
+//import org.apache.log4j.PropertyConfigurator;
+//import org.junit.Before;
+//import org.junit.Test;
+//
+//public class BESProviderTest {
+//     private JobExecutionContext jobExecutionContext;
+//
+//     private static final String[] hostArray = new String[] { 
"https://zam1161v01.zam.kfa-juelich.de:8002/INTEROP1/services/BESFactory?res=default_bes_factory";
 };
+//     private static final String gridftpAddress = 
"gsiftp://gridftp1.ls4.tacc.utexas.edu:2811";;
+//
+//     //directory where data will be copy into and copied out to unicore 
resources
+//
+//     // private static final String scratchDir = 
"/brashear/msmemon/airavata";
+//
+//     private static final String scratchDir = 
"/scratch/02055/msmemon/airavata";
+//
+//     private String remoteTempDir = null;
+//
+//     @Before
+//     public void initJobContext() throws Exception {
+//             
PropertyConfigurator.configure("src/test/resources/logging.properties");
+//
+//             /*
+//              * Default tmp location
+//              */
+//             String date = (new Date()).toString();
+//             date = date.replaceAll(" ", "_");
+//             date = date.replaceAll(":", "_");
+//
+//
+//             remoteTempDir = scratchDir + File.separator + "SimpleEcho" + 
"_" + date + "_"
+//                             + UUID.randomUUID();
+//
+//             jobExecutionContext = new JobExecutionContext(getGFACConfig(), 
getServiceDesc().getType().getName());
+//             
jobExecutionContext.setApplicationContext(getApplicationContext());
+//             jobExecutionContext.setInMessageContext(getInMessageContext());
+//             
jobExecutionContext.setOutMessageContext(getOutMessageContext());
+//     }
+//
+//     @Test
+//     public void testBESProvider() throws GFacException {
+////           GFacAPI gFacAPI = new GFacAPI();
+////           gFacAPI.submitJob(jobExecutionContext);
+//     }
+//
+//     private GFacConfiguration getGFACConfig() throws Exception{
+//        URL resource = 
BESProviderTest.class.getClassLoader().getResource("gfac-config.xml");
+//        System.out.println(resource.getFile());
+//        GFacConfiguration gFacConfiguration = GFacConfiguration.create(new 
File(resource.getPath()),null,null);
+//             gFacConfiguration.setMyProxyLifeCycle(3600);
+//             gFacConfiguration.setMyProxyServer("myproxy.teragrid.org");
+//             gFacConfiguration.setMyProxyUser("msmemon");
+//             gFacConfiguration.setMyProxyPassphrase("******");
+//             
gFacConfiguration.setTrustedCertLocation("/home/m.memon/.globus/certificates");
+//             return gFacConfiguration;
+//     }
+//
+//     private ApplicationContext getApplicationContext() {
+//             ApplicationContext applicationContext = new 
ApplicationContext();
+//             applicationContext.setHostDescription(getHostDesc());
+//             applicationContext
+//                             
.setApplicationDeploymentDescription(getApplicationDesc());
+//             applicationContext.setServiceDescription(getServiceDesc());
+//             return applicationContext;
+//     }
+//
+//     private ApplicationDescription getApplicationDesc() {
+//             ApplicationDescription appDesc = new ApplicationDescription(
+//                             HpcApplicationDeploymentType.type);
+//             HpcApplicationDeploymentType app = 
(HpcApplicationDeploymentType) appDesc
+//                             .getType();
+//             ApplicationDeploymentDescriptionType.ApplicationName name = 
ApplicationDeploymentDescriptionType.ApplicationName.Factory
+//                             .newInstance();
+//             name.setStringValue("Simple Cat");
+//             app.setApplicationName(name);
+//             ProjectAccountType projectAccountType = 
app.addNewProjectAccount();
+//             projectAccountType.setProjectAccountNumber("TG-AST110064");
+//
+//             QueueType queueType = app.addNewQueue();
+//             queueType.setQueueName("development");
+//
+//             app.setCpuCount(1);
+//             // TODO: also handle parallel jobs
+//             app.setJobType(JobTypeType.SERIAL);
+//             app.setNodeCount(1);
+//             app.setProcessorsPerNode(1);
+//
+//             /*
+//              * Use bat file if it is compiled on Windows
+//              */
+//             app.setExecutableLocation("/bin/cat");
+//
+//
+//             System.out.println(remoteTempDir);
+//
+//
+//             app.setScratchWorkingDirectory(remoteTempDir);
+//             app.setStaticWorkingDirectory(remoteTempDir);
+//
+//
+//             // this is required
+//             app.setInputDataDirectory(remoteTempDir + File.separator + 
"inputData");
+//             app.setOutputDataDirectory(remoteTempDir + File.separator + 
"outputData");
+//
+//             app.setStandardOutput(app.getOutputDataDirectory()+ 
File.separator + "stdout");
+//             app.setStandardError(app.getOutputDataDirectory()+ 
File.separator + "stderr");
+//
+//             return appDesc;
+//     }
+//
+//     private HostDescription getHostDesc() {
+//             HostDescription host = new 
HostDescription(UnicoreHostType.type);
+//             host.getType().setHostAddress("zam1161v01.zam.kfa-juelich.de");
+//             host.getType().setHostName("DEMO-INTEROP-SITE");
+//             ((UnicoreHostType) 
host.getType()).setUnicoreHostAddressArray(hostArray);
+//             ((UnicoreHostType) host.getType()).setGridFTPEndPointArray(new 
String[]{gridftpAddress});
+//             return host;
+//     }
+//
+//     private ServiceDescription getServiceDesc() {
+//             ServiceDescription serv = new ServiceDescription();
+//             serv.getType().setName("SimpleCat");
+//
+//             List<InputParameterType> inputList = new 
ArrayList<InputParameterType>();
+//             InputParameterType input = 
InputParameterType.Factory.newInstance();
+//             input.setParameterName("copy_input");
+//             input.setParameterType(URIParameterType.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);
+//             return serv;
+//     }
+//
+//     private MessageContext getInMessageContext() {
+//             MessageContext inMessage = new MessageContext();
+//
+//             ActualParameter copy_input = new ActualParameter();
+//        copy_input.getType().changeType(URIParameterType.type);
+//        
((URIParameterType)copy_input.getType()).setValue("file:///tmp/tmpstrace");
+//        inMessage.addParameter("f1", copy_input);
+//
+//     ActualParameter f2 = new ActualParameter();
+//        f2.getType().changeType(URIParameterType.type);
+//        
((URIParameterType)f2.getType()).setValue("http://unicore-dev.zam.kfa-juelich.de/maven/cog-globus/cog-jglobus/1.4/cog-jglobus-1.4.jar";);
+//        inMessage.addParameter("f2", f2);
+//
+//     ActualParameter f3 = new ActualParameter();
+//        f3.getType().changeType(URIParameterType.type);
+//        
((URIParameterType)f3.getType()).setValue(gridftpAddress+"/"+scratchDir+"/file1.txt");
+//        inMessage.addParameter("f3", f3);
+//
+//        ActualParameter a1 = new ActualParameter();
+//        a1.getType().changeType(StringParameterType.type);
+//        ((StringParameterType)a1.getType()).setValue("tmpstrace");
+//        inMessage.addParameter("arg1", a1);
+//
+//        return inMessage;
+//     }
+//
+//     private MessageContext getOutMessageContext() {
+//
+//             MessageContext outMessage = new MessageContext();
+//             ActualParameter a1 = new ActualParameter();
+//             a1.getType().changeType(StringParameterType.type);
+//             ((StringParameterType)a1.getType()).setValue("file1.txt");
+//             outMessage.addParameter("echo_output", a1);
+//
+//             ActualParameter o1 = new ActualParameter();
+//             o1.getType().changeType(URIParameterType.type);
+//             // this may be any gridftp / ftp directory
+//             
((URIParameterType)o1.getType()).setValue(gridftpAddress+"/"+remoteTempDir + 
"/" + "outputData"+"/"+"cog-jglobus-1.4.jar");
+//             outMessage.addParameter("o1", o1);
+//
+//             return outMessage;
+//     }
+//
+//}

Added: 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/JSDLGeneratorTest.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/JSDLGeneratorTest.java?rev=1448682&view=auto
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/JSDLGeneratorTest.java
 (added)
+++ 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/JSDLGeneratorTest.java
 Thu Feb 21 15:35:22 2013
@@ -0,0 +1,241 @@
+//package org.apache.airavata.core.gfac.services.impl;
+//
+//import static org.junit.Assert.assertEquals;
+//import static org.junit.Assert.assertTrue;
+//
+//import java.io.File;
+//import java.net.URL;
+//import java.util.ArrayList;
+//import java.util.Date;
+//import java.util.List;
+//import java.util.UUID;
+//
+//import org.apache.airavata.commons.gfac.type.ActualParameter;
+//import org.apache.airavata.commons.gfac.type.ApplicationDescription;
+//import org.apache.airavata.commons.gfac.type.HostDescription;
+//import org.apache.airavata.commons.gfac.type.ServiceDescription;
+//import org.apache.airavata.gfac.GFacConfiguration;
+//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.gfac.provider.utils.JSDLGenerator;
+//import org.apache.airavata.gfac.provider.utils.JSDLUtils;
+//import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
+//import org.apache.airavata.schemas.gfac.HpcApplicationDeploymentType;
+//import org.apache.airavata.schemas.gfac.InputParameterType;
+//import org.apache.airavata.schemas.gfac.JobTypeType;
+//import org.apache.airavata.schemas.gfac.OutputParameterType;
+//import org.apache.airavata.schemas.gfac.ProjectAccountType;
+//import org.apache.airavata.schemas.gfac.QueueType;
+//import org.apache.airavata.schemas.gfac.StringParameterType;
+//import org.apache.airavata.schemas.gfac.URIParameterType;
+//import org.apache.airavata.schemas.gfac.UnicoreHostType;
+//import org.apache.log4j.PropertyConfigurator;
+//import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionDocument;
+//import org.junit.Before;
+//import org.junit.Test;
+//
+//public class JSDLGeneratorTest {
+//
+//
+//     private static final String[] hostArray = new String[] { 
"https://zam1161v01.zam.kfa-juelich.de:8002/INTEROP1/services/BESFactory?res=default_bes_factory";
 };
+//     private static final String gridftpAddress = 
"gsiftp://gridftp.blacklight.psc.teragrid.org:2811";;
+//     private static final String hostAddress = 
"zam1161v01.zam.kfa-juelich.de";
+//     private static final String hostName = "DEMO-INTEROP-SITE";
+//     private static final String scratchDir = "/scratch/msmemon/airavata";
+//
+//     private JobExecutionContext jobExecutionContext;
+//
+//     @Test
+//     public void testJSDLUtils() throws Exception{
+//             JobDefinitionDocument jobDefDoc = 
JSDLGenerator.buildJSDLInstance(jobExecutionContext);
+//
+//             assertTrue 
(jobDefDoc.getJobDefinition().getJobDescription().getApplication().toString().contains("/bin/cat"));
+//             
assertTrue(jobDefDoc.getJobDefinition().getJobDescription().getDataStagingArray().length
 > 2);
+//
+//             
assertTrue(jobDefDoc.getJobDefinition().getJobDescription().getJobIdentification().getJobProjectArray().length
 > 0);
+//
+//             assertEquals("jsdl_stdout", 
JSDLUtils.getOrCreatePOSIXApplication(jobDefDoc.getJobDefinition()).getOutput().getStringValue().toString());
+//
+//             System.out.println(jobDefDoc);
+//
+//     }
+//
+//     @Before
+//     public void initJobContext() throws Exception {
+//             
PropertyConfigurator.configure("src/test/resources/logging.properties");
+//             jobExecutionContext = new JobExecutionContext(getGFACConfig(), 
getServiceDesc().getType().getName());
+//             
jobExecutionContext.setApplicationContext(getApplicationContext());
+//             jobExecutionContext.setInMessageContext(getInMessageContext());
+//             
jobExecutionContext.setOutMessageContext(getOutMessageContext());
+//     }
+//
+//     private GFacConfiguration getGFACConfig() throws Exception{
+//        URL resource = 
BESProviderTest.class.getClassLoader().getResource("gfac-config.xml");
+//        System.out.println(resource.getFile());
+//        GFacConfiguration gFacConfiguration = GFacConfiguration.create(new 
File(resource.getPath()),null,null);
+//             gFacConfiguration.setMyProxyLifeCycle(3600);
+//             gFacConfiguration.setMyProxyServer("");
+//             gFacConfiguration.setMyProxyUser("");
+//             gFacConfiguration.setMyProxyPassphrase("");
+//             gFacConfiguration.setTrustedCertLocation("");
+//             return gFacConfiguration;
+//     }
+//
+//
+//     private ApplicationContext getApplicationContext() {
+//             ApplicationContext applicationContext = new 
ApplicationContext();
+//             applicationContext.setHostDescription(getHostDesc());
+//             applicationContext
+//                             
.setApplicationDeploymentDescription(getApplicationDesc());
+//
+//             applicationContext.setServiceDescription(getServiceDesc());
+//             return applicationContext;
+//     }
+//
+//     private ApplicationDescription getApplicationDesc() {
+//             ApplicationDescription appDesc = new ApplicationDescription(
+//                             HpcApplicationDeploymentType.type);
+//             HpcApplicationDeploymentType app = 
(HpcApplicationDeploymentType) appDesc
+//                             .getType();
+//             ApplicationDeploymentDescriptionType.ApplicationName name = 
ApplicationDeploymentDescriptionType.ApplicationName.Factory
+//                             .newInstance();
+//             name.setStringValue("EchoLocal");
+//             app.setApplicationName(name);
+//             ProjectAccountType projectAccountType = 
app.addNewProjectAccount();
+//             projectAccountType.setProjectAccountNumber("TG-AST110064");
+//
+//             QueueType queueType = app.addNewQueue();
+//             queueType.setQueueName("development");
+//
+//             app.setCpuCount(1);
+//             // TODO: also handle parallel jobs
+//             app.setJobType(JobTypeType.SERIAL);
+//             app.setNodeCount(1);
+//             app.setProcessorsPerNode(1);
+//
+//             /*
+//              * Use bat file if it is compiled on Windows
+//              */
+//             app.setExecutableLocation("/bin/cat");
+//
+//             /*
+//              * Default tmp location
+//              */
+//             String date = (new Date()).toString();
+//             date = date.replaceAll(" ", "_");
+//             date = date.replaceAll(":", "_");
+//
+//             String remoteTempDir = scratchDir + File.separator + 
"SimpleEcho" + "_" + date + "_"
+//                             + UUID.randomUUID();
+//
+//             System.out.println(remoteTempDir);
+//
+//             // no need of these parameters, as unicore manages by itself
+//             app.setScratchWorkingDirectory(remoteTempDir);
+//             app.setStaticWorkingDirectory(remoteTempDir);
+//             app.setInputDataDirectory(remoteTempDir + File.separator + 
"inputData");
+//             app.setOutputDataDirectory(remoteTempDir + File.separator + 
"outputData");
+//
+//             
app.setStandardOutput(app.getOutputDataDirectory()+"/jsdl_stdout");
+//
+//             
app.setStandardError(app.getOutputDataDirectory()+"/jsdl_stderr");
+//
+//             return appDesc;
+//     }
+//
+//     private HostDescription getHostDesc() {
+//             HostDescription host = new 
HostDescription(UnicoreHostType.type);
+//             host.getType().setHostAddress(hostAddress);
+//             host.getType().setHostName(hostName);
+//             ((UnicoreHostType) 
host.getType()).setUnicoreHostAddressArray(hostArray);
+//             ((UnicoreHostType) host.getType()).setGridFTPEndPointArray(new 
String[]{gridftpAddress});
+//             return host;
+//     }
+//
+//     private ServiceDescription getServiceDesc() {
+//             ServiceDescription serv = new ServiceDescription();
+//             serv.getType().setName("SimpleCat");
+//
+//             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);
+//
+//
+//             return serv;
+//     }
+//
+//     private MessageContext getInMessageContext() {
+//             MessageContext inMessage = new MessageContext();
+//
+//        ActualParameter i1 = new ActualParameter();
+//        i1.getType().changeType(URIParameterType.type);
+//        ((URIParameterType)i1.getType()).setValue("file:///tmp/ifile1");
+//        inMessage.addParameter("i1", i1);
+//
+//        ActualParameter i2 = new ActualParameter();
+//        i2.getType().changeType(URIParameterType.type);
+//        ((URIParameterType)i2.getType()).setValue("file:///tmp/ifile2");
+//        inMessage.addParameter("i2", i2);
+//
+//        ActualParameter i3 = new ActualParameter();
+//        i2.getType().changeType(URIParameterType.type);
+//        ((URIParameterType)i2.getType()).setValue("///tmp/ifile2");
+//        inMessage.addParameter("i3", i2);
+//
+//        ActualParameter simpleArg = new ActualParameter();
+//        simpleArg.getType().changeType(StringParameterType.type);
+//        ((StringParameterType)simpleArg.getType()).setValue("argument1");
+//        inMessage.addParameter("a1", simpleArg);
+//
+//        ActualParameter nameValueArg = new ActualParameter();
+//        nameValueArg.getType().changeType(StringParameterType.type);
+//        
((StringParameterType)nameValueArg.getType()).setValue("name1=value1");
+//        inMessage.addParameter("nameValueArg", nameValueArg);
+//
+//             ActualParameter echo_input = new ActualParameter();
+//             ((StringParameterType) echo_input.getType())
+//                             .setValue("echo_output=hello");
+//             inMessage.addParameter("echo_input", echo_input);
+//
+//             return inMessage;
+//     }
+//
+//     private MessageContext getOutMessageContext() {
+//             MessageContext om1 = new MessageContext();
+//
+//             // TODO: Aint the output parameters are only the name of the 
files staged out to the gridftp endpoint?
+//             ActualParameter o1 = new ActualParameter();
+//             ((StringParameterType) o1.getType())
+//             .setValue("tempfile");
+//             om1.addParameter("o1", o1);
+//
+//             ActualParameter o2 = new ActualParameter();
+//             o2.getType().changeType(URIParameterType.type);
+//
+//             
((URIParameterType)o2.getType()).setValue("http://path/to/upload";);
+//             om1.addParameter("o2", o2);
+//
+//
+//
+//             return om1;
+//     }
+//
+//
+//
+//}


Reply via email to