You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by la...@apache.org on 2012/11/30 13:56:57 UTC

svn commit: r1415607 - in /airavata/trunk/modules/gfac-core: ./ src/main/java/org/apache/airavata/core/gfac/provider/impl/ src/main/java/org/apache/airavata/core/gfac/provider/utils/

Author: lahiru
Date: Fri Nov 30 12:56:56 2012
New Revision: 1415607

URL: http://svn.apache.org/viewvc?rev=1415607&view=rev
Log:
Adding jdsl Provider.

Added:
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/impl/JSDLProvider.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/utils/BESJob.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/utils/JSDLGenerator.java
Modified:
    airavata/trunk/modules/gfac-core/pom.xml

Modified: airavata/trunk/modules/gfac-core/pom.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/pom.xml?rev=1415607&r1=1415606&r2=1415607&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/pom.xml (original)
+++ airavata/trunk/modules/gfac-core/pom.xml Fri Nov 30 12:56:56 2012
@@ -140,11 +140,63 @@
             <version>0.2.9</version>
             <type>jar</type>
         </dependency>
-         <!--dependency>
-            <groupId>org.apache.airavata</groupId>
-            <artifactId>airavata-jpa-registry</artifactId>
-            <version>${project.version}</version>
-        </dependency-->
+        <!-- Unicore dependencies -->
+        <dependency>
+            <groupId>eu.unicore</groupId>
+            <artifactId>ogsabes-client</artifactId>
+            <version>1.5.1-rc3</version>
+        </dependency>
+        <dependency>
+            <groupId>eu.unicore</groupId>
+            <artifactId>ogsabes-types</artifactId>
+            <version>1.5.1-rc3</version>
+        </dependency>
+        <dependency>
+            <groupId>eu.unicore</groupId>
+            <artifactId>uas-client</artifactId>
+            <version>1.5.1-rc3</version>
+        </dependency>
+        <dependency>
+            <groupId>de.fzj.unicore</groupId>
+            <artifactId>jsdl-xmlbeans</artifactId>
+            <version>2.1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>eu.unicore</groupId>
+            <artifactId>cis-u6-infoprovider-types</artifactId>
+            <version>1.5.1-rc3</version>
+        </dependency>
+        <dependency>
+            <groupId>eu.unicore</groupId>
+            <artifactId>uas-types</artifactId>
+            <version>1.5.1-rc3</version>
+        </dependency>
+        <dependency>
+            <groupId>eu.unicore</groupId>
+            <artifactId>uas-types</artifactId>
+            <version>1.5.1-rc3</version>
+        </dependency>
+        <dependency>
+            <groupId>eu.unicore</groupId>
+            <artifactId>cis-u6-infoprovider-types</artifactId>
+            <version>1.5.1-rc3</version>
+        </dependency>
+        <dependency>
+            <groupId>eu.unicore.services</groupId>
+            <artifactId>use-wsrfclient</artifactId>
+            <version>2.1.1</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.0.1</version>
+        </dependency>
+        <dependency>
+            <groupId>eu.unicore</groupId>
+            <artifactId>uftp</artifactId>
+            <version>1.2.1</version>
+        </dependency>
+        <!-- unicore dependencies finished -->
     </dependencies>
 
 </project>

Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/impl/JSDLProvider.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/impl/JSDLProvider.java?rev=1415607&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/impl/JSDLProvider.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/impl/JSDLProvider.java Fri Nov 30 12:56:56 2012
@@ -0,0 +1,242 @@
+/*
+ *
+ * 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.provider.impl;
+
+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.uas.security.ClientProperties;
+import de.fzj.unicore.wsrflite.xmlbeans.WSUtilities;
+import eu.unicore.security.util.client.IClientProperties;
+import org.apache.airavata.core.gfac.context.invocation.InvocationContext;
+import org.apache.airavata.core.gfac.context.security.impl.GSISecurityContext;
+import org.apache.airavata.core.gfac.exception.*;
+import org.apache.airavata.core.gfac.external.GridFtp;
+import org.apache.airavata.core.gfac.provider.utils.BESJob;
+import org.apache.airavata.core.gfac.provider.utils.JobSubmissionListener;
+import org.apache.airavata.core.gfac.provider.utils.JSDLGenerator;
+import org.apache.airavata.core.gfac.utils.GfacUtils;
+import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
+import org.apache.airavata.schemas.gfac.GlobusHostType;
+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.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionDocument;
+import org.ietf.jgss.GSSCredential;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3.x2005.x08.addressing.EndpointReferenceType;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Calendar;
+
+public class JSDLProvider {
+    protected final Logger log = LoggerFactory.getLogger(this.getClass());
+
+    public static final String MYPROXY_SECURITY_CONTEXT = "myproxy";
+    private IClientProperties securityProperties;
+    private String unicoreHost;
+    private JobSubmissionListener listener;
+    private BESJob job;
+    private String jobId;
+    private GSISecurityContext gssContext;
+
+    public void makeDirectory(InvocationContext invocationContext) throws ProviderException {
+        GlobusHostType host = (GlobusHostType) invocationContext.getExecutionDescription().getHost().getType();
+        ApplicationDeploymentDescriptionType app = invocationContext.getExecutionDescription().getApp().getType();
+
+        GridFtp ftp = new GridFtp();
+
+        try {
+            gssContext = (GSISecurityContext)invocationContext.getSecurityContext(MYPROXY_SECURITY_CONTEXT);
+            GSSCredential gssCred = gssContext.getGssCredentails();
+            String[] hostgridFTP = host.getGridFTPEndPointArray();
+            if (hostgridFTP == null || hostgridFTP.length == 0) {
+                hostgridFTP = new String[] { host.getHostAddress() };
+            }
+
+            boolean success = false;
+            ProviderException pe = null;// = new ProviderException("");
+
+            for (String endpoint : host.getGridFTPEndPointArray()) {
+                try {
+
+                    URI tmpdirURI = GfacUtils.createGsiftpURI(endpoint, app.getScratchWorkingDirectory());
+                    URI workingDirURI = GfacUtils.createGsiftpURI(endpoint, app.getStaticWorkingDirectory());
+                    URI inputURI = GfacUtils.createGsiftpURI(endpoint, app.getInputDataDirectory());
+                    URI outputURI = GfacUtils.createGsiftpURI(endpoint, app.getOutputDataDirectory());
+
+                    log.info("Host FTP = " + hostgridFTP);
+                    log.info("temp directory = " + tmpdirURI);
+                    log.info("Working directory = " + workingDirURI);
+                    log.info("Input directory = " + inputURI);
+                    log.info("Output directory = " + outputURI);
+
+                    ftp.makeDir(tmpdirURI, gssCred);
+                    ftp.makeDir(workingDirURI, gssCred);
+                    ftp.makeDir(inputURI, gssCred);
+                    ftp.makeDir(outputURI, gssCred);
+
+                    success = true;
+                    break;
+                } catch (URISyntaxException e) {
+                    pe = new ProviderException("URI is malformatted:" + e.getMessage(), e,invocationContext);
+
+                } catch (ToolsException e) {
+                    pe = new ProviderException(e.getMessage(), e,invocationContext);
+                }
+            }
+            if (success == false) {
+                throw pe;
+            }
+        } catch (org.apache.airavata.core.gfac.exception.SecurityException e) {
+            throw new ProviderException(e.getMessage(), e,invocationContext);
+        }
+    }
+
+    public void setupEnvironment(InvocationContext invocationContext) throws ProviderException {
+        UnicoreHostType host = (UnicoreHostType) invocationContext.getExecutionDescription().getHost().getType();
+
+        log.info("Searching for Gate Keeper");
+
+
+        String tmp[] = host.getUnicoreHostAddressArray();
+        if (tmp == null || tmp.length == 0) {
+            unicoreHost = host.getHostAddress();
+        }else{
+            /*
+             * TODO: algorithm for correct gatekeeper selection
+             */
+            unicoreHost = tmp[0];
+        }
+        log.info("Using Globus GateKeeper " + unicoreHost);
+
+        try {
+            JobDefinitionDocument jsdl = JSDLGenerator.configureRemoteJob(invocationContext);
+            log.info("JSDL = " + jsdl.toString());
+
+            job = new BESJob();
+            job.setJobDoc(jsdl);
+            job.setFactory(unicoreHost);
+//            listener = new JobSubmissionListener(job, invocationContext);
+//            job.addListener(listener);
+
+        } catch (ToolsException te) {
+            throw new ProviderException(te.getMessage(), te, invocationContext);
+        }
+
+    }
+
+    public void executeApplication(InvocationContext invocationContext) throws ProviderException {
+        GlobusHostType host = (GlobusHostType) invocationContext.getExecutionDescription().getHost().getType();
+        ApplicationDeploymentDescriptionType app = invocationContext.getExecutionDescription().getApp().getType();
+        StringBuffer buf = new StringBuffer();
+            /*
+             * Set Security
+             */
+            securityProperties = initSecurityProperties();
+            String factoryUrl = job.getFactoryUrl();
+            EndpointReferenceType eprt = EndpointReferenceType.Factory
+                    .newInstance();
+            eprt.addNewAddress().setStringValue(factoryUrl);
+            System.out.println("========================================");
+            System.out.println(String.format("Job Submitted to %s.\n", factoryUrl));
+            FactoryClient factory = null;
+            try {
+                factory = new FactoryClient(eprt, securityProperties);
+            } catch (Exception e) {
+                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+            }
+            CreateActivityDocument cad = CreateActivityDocument.Factory
+                    .newInstance();
+            cad.addNewCreateActivity().addNewActivityDocument()
+                    .setJobDefinition(job.getJobDoc().getJobDefinition());
+            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();
+            //factory.waitWhileActivityIsDone(activityEpr, 1000);
+            jobId = WSUtilities.extractResourceID(activityEpr);
+            if (jobId == null) {
+                jobId = new Long(Calendar.getInstance().getTimeInMillis())
+                        .toString();
+            }
+            ActivityStateEnumeration.Enum state = factory.getActivityStatus(activityEpr);
+
+            String status;
+
+            status = String.format("Job %s is %s.\n", activityEpr.getAddress()
+                    .getStringValue(), factory.getActivityStatus(activityEpr)
+                    .toString()).toString();
+
+
+            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 {
+                    Thread.sleep(500);
+                } 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("Request to contact:" + unicoreHost);
+
+            buf.append("Finished launching job, Host = ").append(host.getHostAddress()).append(" JSDL = ")
+                    .append(job.getJobDoc().toString()).append(" working directory = ").append(app.getStaticWorkingDirectory())
+                    .append(" temp directory = ").append(app.getScratchWorkingDirectory())
+                    .append(" Unicore Endpoint = ").append(unicoreHost);
+            invocationContext.getExecutionContext().getNotifier().info(invocationContext, buf.toString());
+            invocationContext.getExecutionContext().getNotifier().info(invocationContext, "JobID=" + jobId);
+            log.info(buf.toString());
+    }
+
+    protected ClientProperties initSecurityProperties() {
+        //todo provide a proper way of specified credentials
+		ClientProperties sp = new ClientProperties();
+		sp.setSslEnabled(true);
+		sp.setSignMessage(true);
+		sp.setKeystore("src/test/resources/demo-keystore.jks");
+		sp.setKeystorePassword("654321");
+		sp.setKeystoreAlias("demouser-new");
+		sp.setKeystoreType("JKS");
+		return sp;
+	}
+
+}

Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/utils/BESJob.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/utils/BESJob.java?rev=1415607&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/utils/BESJob.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/utils/BESJob.java Fri Nov 30 12:56:56 2012
@@ -0,0 +1,55 @@
+/*
+ *
+ * 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.provider.utils;
+
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionDocument;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BESJob {
+    protected final Logger log = LoggerFactory.getLogger(this.getClass());
+
+	private String factoryUrl;
+
+	private JobDefinitionDocument jobDoc;
+
+	public BESJob() {
+
+	}
+
+	public String getFactoryUrl() {
+		return factoryUrl;
+	}
+
+	public void setFactory(String factoryUrl) {
+		this.factoryUrl = factoryUrl;
+	}
+
+	public JobDefinitionDocument getJobDoc() {
+		return jobDoc;
+	}
+
+	public void setJobDoc(JobDefinitionDocument jobDoc) {
+		this.jobDoc = jobDoc;
+	}
+
+}
+

Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/utils/JSDLGenerator.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/utils/JSDLGenerator.java?rev=1415607&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/utils/JSDLGenerator.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/utils/JSDLGenerator.java Fri Nov 30 12:56:56 2012
@@ -0,0 +1,65 @@
+/*
+ *
+ * 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.provider.utils;
+
+import org.apache.airavata.core.gfac.context.invocation.InvocationContext;
+import org.apache.airavata.core.gfac.exception.ToolsException;
+import org.apache.airavata.schemas.gfac.GramApplicationDeploymentType;
+import org.apache.xmlbeans.XmlException;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.ApplicationType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionDocument;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDescriptionType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdlPosix.POSIXApplicationDocument;
+import org.ggf.schemas.jsdl.x2005.x11.jsdlPosix.POSIXApplicationType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JSDLGenerator {
+    protected final Logger log = LoggerFactory.getLogger(this.getClass());
+
+    public static JobDefinitionDocument configureRemoteJob(InvocationContext context) throws ToolsException {
+        //todo read the InvocationContext and generate JSDL and return
+        try {
+//            GramApplicationDeploymentType app = (GramApplicationDeploymentType) context.getExecutionDescription().getApp().getType();
+//            JobDefinitionDocument jobDefinitionDocument = JobDefinitionDocument.Factory.newInstance();
+//            JobDefinitionType jobDefinitionType = jobDefinitionDocument.addNewJobDefinition();
+//            JobDescriptionType jobDescriptionType = jobDefinitionType.addNewJobDescription();
+//            POSIXApplicationDocument posixApplicationDocument = POSIXApplicationDocument.Factory.newInstance();
+//            POSIXApplicationType posixApplicationType = posixApplicationDocument.addNewPOSIXApplication();
+//            posixApplicationType.addNewExecutable().setFilesystemName(app.getExecutableLocation());
+//            jobDescriptionType.setApplication(posixApplicationType);
+            return JobDefinitionDocument.Factory.parse("<jsdl:JobDefinition xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:app=\"http://schemas.ggf.org/jsdl/2006/07/jsdl-hpcpa\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" xmlns:jsdl=\"http://schemas.ggf.org/jsdl/2005/11/jsdl\" xmlns:bes=\"http://schemas.ggf.org/bes/2006/08/bes-factory\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" xmlns=\"http://schemas.ggf.org/jsdl/2005/11/jsdl-posix\">\n" +
+                    "  <jsdl:JobDescription>\n" +
+                    "    <jsdl:Application>\n" +
+                    "      <POSIXApplication>\n" +
+                    "        <Executable>/bin/date</Executable>\n" +
+                    "      </POSIXApplication>\n" +
+                    "    </jsdl:Application>\n" +
+                    "  </jsdl:JobDescription>\n" +
+                    "</jsdl:JobDefinition>");
+        } catch (XmlException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+        }
+        return null;
+    }
+
+}