From airavata-commits-return-463-apmail-incubator-airavata-commits-archive=incubator.apache.org@incubator.apache.org Tue Sep 13 19:54:10 2011 Return-Path: X-Original-To: apmail-incubator-airavata-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-airavata-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 363898E1A for ; Tue, 13 Sep 2011 19:54:10 +0000 (UTC) Received: (qmail 47689 invoked by uid 500); 13 Sep 2011 19:54:09 -0000 Delivered-To: apmail-incubator-airavata-commits-archive@incubator.apache.org Received: (qmail 47629 invoked by uid 500); 13 Sep 2011 19:54:09 -0000 Mailing-List: contact airavata-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: airavata-dev@incubator.apache.org Delivered-To: mailing list airavata-commits@incubator.apache.org Received: (qmail 47621 invoked by uid 99); 13 Sep 2011 19:54:09 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Sep 2011 19:54:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Sep 2011 19:54:06 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id CB8F1238889B; Tue, 13 Sep 2011 19:53:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1170323 - in /incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac: provider/ services/impl/ utils/ Date: Tue, 13 Sep 2011 19:53:46 -0000 To: airavata-commits@incubator.apache.org From: patanachai@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110913195346.CB8F1238889B@eris.apache.org> Author: patanachai Date: Tue Sep 13 19:53:45 2011 New Revision: 1170323 URL: http://svn.apache.org/viewvc?rev=1170323&view=rev Log: New provider interface Added: incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/utils/InputUtils.java Modified: incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/AbstractProvider.java incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/GramProvider.java incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/LocalProvider.java incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/Provider.java incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/SSHProvider.java incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/services/impl/AbstractSimpleService.java incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/utils/OutputUtils.java Modified: incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/AbstractProvider.java URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/AbstractProvider.java?rev=1170323&r1=1170322&r2=1170323&view=diff ============================================================================== --- incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/AbstractProvider.java (original) +++ incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/AbstractProvider.java Tue Sep 13 19:53:45 2011 @@ -21,36 +21,44 @@ package org.apache.airavata.core.gfac.provider; +import java.util.Map; + import org.apache.airavata.core.gfac.context.invocation.InvocationContext; +import org.apache.airavata.core.gfac.exception.GfacException; import org.apache.airavata.core.gfac.exception.ProviderException; import org.apache.airavata.core.gfac.notification.Notifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * AbstractProvider wraps up steps of execution for Provider. - * The steps in execution are - * - makeDirectory - * - setupEnvironment - * - executeApplication - * - retrieveOutput + * AbstractProvider wraps up steps of execution for Provider.
+ * The steps in execution are
+ * - makeDirectory
+ * - setupEnvironment
+ * - executeApplication
+ * - retrieveOutput
*/ public abstract class AbstractProvider implements Provider { protected final Logger log = LoggerFactory.getLogger(this.getClass()); - public void execute(InvocationContext invocationContext) throws ProviderException{ - - Notifier notifier = invocationContext.getExecutionContext().getNotifier(); - + public void initialize(InvocationContext invocationContext) throws ProviderException { /* * Make a directory on the host */ - makeDirectory(invocationContext); + makeDirectory(invocationContext); + } + + public void dispose(InvocationContext invocationContext) throws GfacException { + } + + public Map execute(InvocationContext invocationContext) throws ProviderException{ /* * Setup necessary environment */ setupEnvironment(invocationContext); + + Notifier notifier = invocationContext.getExecutionContext().getNotifier(); notifier.startExecution(this, invocationContext); @@ -65,14 +73,14 @@ public abstract class AbstractProvider i /* * Process output information */ - retrieveOutput(invocationContext); + return processOutput(invocationContext); } + + protected abstract void makeDirectory(InvocationContext invocationContext) throws ProviderException; - public abstract void makeDirectory(InvocationContext invocationContext) throws ProviderException; - - public abstract void setupEnvironment(InvocationContext invocationContext) throws ProviderException; + protected abstract void setupEnvironment(InvocationContext invocationContext) throws ProviderException; - public abstract void executeApplication(InvocationContext invocationContext) throws ProviderException; + protected abstract void executeApplication(InvocationContext invocationContext) throws ProviderException; - public abstract void retrieveOutput(InvocationContext invocationContext) throws ProviderException; + protected abstract Map processOutput(InvocationContext invocationContext) throws ProviderException; } Modified: incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/GramProvider.java URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/GramProvider.java?rev=1170323&r1=1170322&r2=1170323&view=diff ============================================================================== --- incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/GramProvider.java (original) +++ incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/GramProvider.java Tue Sep 13 19:53:45 2011 @@ -24,6 +24,7 @@ package org.apache.airavata.core.gfac.pr import java.io.File; import java.net.URI; import java.net.URISyntaxException; +import java.util.Map; import javax.xml.namespace.QName; @@ -32,7 +33,6 @@ import org.apache.airavata.commons.gfac. import org.apache.airavata.commons.gfac.type.parameter.AbstractParameter; 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.GfacException; import org.apache.airavata.core.gfac.exception.JobSubmissionFault; import org.apache.airavata.core.gfac.exception.ProviderException; import org.apache.airavata.core.gfac.exception.SecurityException; @@ -54,19 +54,11 @@ import org.ietf.jgss.GSSException; public class GramProvider extends AbstractProvider { public static final String MYPROXY_SECURITY_CONTEXT = "myproxy"; + private GSISecurityContext gssContext; private GramJob job; private String gateKeeper; private JobSubmissionListener listener; - public void initialize(InvocationContext invocationContext) throws ProviderException { - } - - public void dispose(InvocationContext invocationContext) throws GfacException { - } - - public void abort(InvocationContext invocationContext) throws GfacException { - } - public void makeDirectory(InvocationContext invocationContext) throws ProviderException { GlobusHost host = (GlobusHost) invocationContext.getExecutionDescription().getHost(); ShellApplicationDeployment app = (ShellApplicationDeployment) invocationContext.getExecutionDescription() @@ -75,8 +67,9 @@ public class GramProvider extends Abstra GridFtp ftp = new GridFtp(); try { - GSSCredential gssCred = ((GSISecurityContext) invocationContext - .getSecurityContext(MYPROXY_SECURITY_CONTEXT)).getGssCredentails(); + gssContext = (GSISecurityContext) invocationContext + .getSecurityContext(MYPROXY_SECURITY_CONTEXT); + GSSCredential gssCred = gssContext.getGssCredentails(); String hostgridFTP = host.getGridFTPEndPoint(); if (host.getGridFTPEndPoint() == null) { @@ -144,15 +137,19 @@ public class GramProvider extends Abstra /* * Set Security */ - GSSCredential gssCred = ((GSISecurityContext) invocationContext - .getSecurityContext(MYPROXY_SECURITY_CONTEXT)).getGssCredentails(); + GSSCredential gssCred = gssContext.getGssCredentails(); job.setCredentials(gssCred); log.info("Request to contact:" + gateKeeper); - buf.append("Finished launching job, Host = ").append(host.getName()).append(" RSL = ").append(job.getRSL()) - .append(" working directory = ").append(app.getWorkingDir()).append(" tempDirectory = ") - .append(app.getTmpDir()).append(" Globus GateKeeper cantact = ").append(gateKeeper); + buf.append("Finished launching job, Host = ") + .append(host.getName()).append(" RSL = ") + .append(job.getRSL()) + .append(" working directory = ") + .append(app.getWorkingDir()).append(" tempDirectory = ") + .append(app.getTmpDir()) + .append(" Globus GateKeeper cantact = ") + .append(gateKeeper); invocationContext.getExecutionContext().getNotifier().info(this, invocationContext, buf.toString()); /* @@ -225,15 +222,12 @@ public class GramProvider extends Abstra } - public void retrieveOutput(InvocationContext invocationContext) throws ProviderException { - GlobusHost host = (GlobusHost) invocationContext.getExecutionDescription().getHost(); - ShellApplicationDeployment app = (ShellApplicationDeployment) invocationContext.getExecutionDescription() - .getApp(); + public Map processOutput(InvocationContext context) throws ProviderException { + GlobusHost host = (GlobusHost) context.getExecutionDescription().getHost(); + ShellApplicationDeployment app = (ShellApplicationDeployment) context.getExecutionDescription().getApp(); GridFtp ftp = new GridFtp(); - try { - GSSCredential gssCred = ((GSISecurityContext) invocationContext - .getSecurityContext(MYPROXY_SECURITY_CONTEXT)).getGssCredentails(); + GSSCredential gssCred = gssContext.getGssCredentails(); /* * Stdout and Stderror @@ -256,7 +250,7 @@ public class GramProvider extends Abstra } // Get the Stdouts and StdErrs - QName x = QName.valueOf(invocationContext.getServiceName()); + QName x = QName.valueOf(context.getServiceName()); String timeStampedServiceName = GfacUtils.createServiceDirName(x); File localStdOutFile = new File(logDir, timeStampedServiceName + ".stdout"); File localStdErrFile = new File(logDir, timeStampedServiceName + ".stderr"); @@ -264,9 +258,8 @@ public class GramProvider extends Abstra String stdout = ftp.readRemoteFile(stdoutURI, gssCred, localStdOutFile); String stderr = ftp.readRemoteFile(stderrURI, gssCred, localStdErrFile); - // set to context - OutputUtils.fillOutputFromStdout(invocationContext. getOutput(), stdout, stderr); - + return OutputUtils.fillOutputFromStdout(context. getOutput(), stdout); + } catch (URISyntaxException e) { throw new ProviderException("URI is malformatted:" + e.getMessage(), e); } catch (SecurityException e) { @@ -275,5 +268,4 @@ public class GramProvider extends Abstra throw new ProviderException(e.getMessage(), e); } } - } Modified: incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/LocalProvider.java URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/LocalProvider.java?rev=1170323&r1=1170322&r2=1170323&view=diff ============================================================================== --- incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/LocalProvider.java (original) +++ incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/LocalProvider.java Tue Sep 13 19:53:45 2011 @@ -26,6 +26,7 @@ import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Iterator; @@ -36,39 +37,66 @@ import org.apache.airavata.commons.gfac. import org.apache.airavata.commons.gfac.type.app.ShellApplicationDeployment; import org.apache.airavata.commons.gfac.type.parameter.AbstractParameter; import org.apache.airavata.core.gfac.context.invocation.InvocationContext; -import org.apache.airavata.core.gfac.exception.GfacException; import org.apache.airavata.core.gfac.exception.ProviderException; import org.apache.airavata.core.gfac.utils.GFacConstants; import org.apache.airavata.core.gfac.utils.GfacUtils; +import org.apache.airavata.core.gfac.utils.InputUtils; import org.apache.airavata.core.gfac.utils.OutputUtils; /** * {@link LocalProvider} will execute jobs (application) on local machine. - * + * */ public class LocalProvider extends AbstractProvider { - private static final String SPACE = " "; private ProcessBuilder builder; private List cmdList; - private String buildCommand(List cmdList) { - StringBuffer buff = new StringBuffer(); - for (String string : cmdList) { - buff.append(string); - buff.append(SPACE); + private class ReadStreamWriteFile extends Thread { + private BufferedReader in; + private BufferedWriter out; + + public ReadStreamWriteFile(InputStream in, String out) throws IOException { + this.in = new BufferedReader(new InputStreamReader(in)); + this.out = new BufferedWriter(new FileWriter(out)); } - return buff.toString(); - } - - public void initialize(InvocationContext invocationContext) throws ProviderException { - } - public void dispose(InvocationContext invocationContext) throws GfacException { + public void run() { + try { + String line = null; + while ((line = in.readLine()) != null) { + log.debug(line); + out.write(line); + out.newLine(); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (in != null) { + try { + in.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + if (out != null) { + try { + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } } - public void abort(InvocationContext invocationContext) throws GfacException { - + private void makeFileSystemDir(String dir) throws ProviderException { + File f = new File(dir); + if (f.isDirectory() && f.exists()) { + return; + } else if (!new File(dir).mkdir()) { + throw new ProviderException("Cannot make directory"); + } } public void makeDirectory(InvocationContext invocationContext) throws ProviderException { @@ -77,10 +105,10 @@ public class LocalProvider extends Abstr log.info("working diectroy = " + app.getWorkingDir()); log.info("temp directory = " + app.getTmpDir()); - new File(app.getWorkingDir()).mkdir(); - new File(app.getTmpDir()).mkdir(); - new File(app.getInputDir()).mkdir(); - new File(app.getOutputDir()).mkdir(); + makeFileSystemDir(app.getWorkingDir()); + makeFileSystemDir(app.getTmpDir()); + makeFileSystemDir(app.getInputDir()); + makeFileSystemDir(app.getOutputDir()); } public void setupEnvironment(InvocationContext context) throws ProviderException { @@ -116,7 +144,7 @@ public class LocalProvider extends Abstr builder.directory(new File(app.getWorkingDir())); // log info - log.info("Command = " + buildCommand(cmdList)); + log.info("Command = " + InputUtils.buildCommand(cmdList)); log.info("Working dir = " + builder.directory()); for (String key : builder.environment().keySet()) { log.info("Env[" + key + "] = " + builder.environment().get(key)); @@ -130,75 +158,8 @@ public class LocalProvider extends Abstr // running cmd Process process = builder.start(); - final BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream())); - final BufferedReader err = new BufferedReader(new InputStreamReader(process.getErrorStream())); - final BufferedWriter stdoutWtiter = new BufferedWriter(new FileWriter(app.getStdOut())); - final BufferedWriter stdErrWtiter = new BufferedWriter(new FileWriter(app.getStdErr())); - - Thread t1 = new Thread(new Runnable() { - - public void run() { - try { - String line = null; - while ((line = in.readLine()) != null) { - log.debug(line); - stdoutWtiter.write(line); - stdoutWtiter.newLine(); - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - if (in != null) { - try { - in.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - if (stdoutWtiter != null) { - try { - stdoutWtiter.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } - - }); - - Thread t2 = new Thread(new Runnable() { - - public void run() { - try { - String line = null; - while ((line = err.readLine()) != null) { - log.debug(line); - stdErrWtiter.write(line); - stdErrWtiter.newLine(); - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - if (err != null) { - try { - err.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - if (stdErrWtiter != null) { - try { - stdErrWtiter.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - } - - }); + Thread t1 = new ReadStreamWriteFile(process.getInputStream(), app.getStdOut()); + Thread t2 = new ReadStreamWriteFile(process.getErrorStream(), app.getStdErr()); // start output threads t1.setDaemon(true); @@ -225,30 +186,31 @@ public class LocalProvider extends Abstr } StringBuffer buf = new StringBuffer(); - buf.append("Executed ").append(buildCommand(cmdList)).append(" on the localHost, working directory = ") - .append(app.getWorkingDir()).append(" tempDirectory = ").append(app.getTmpDir()) - .append(" With the status ").append(String.valueOf(returnValue)); + buf.append("Executed ").append(InputUtils.buildCommand(cmdList)) + .append(" on the localHost, working directory = ").append(app.getWorkingDir()) + .append(" tempDirectory = ").append(app.getTmpDir()).append(" With the status ") + .append(String.valueOf(returnValue)); log.info(buf.toString()); } catch (IOException io) { - + throw new ProviderException(io.getMessage(), io); } catch (InterruptedException e) { + throw new ProviderException(e.getMessage(), e); } } - public void retrieveOutput(InvocationContext context) throws ProviderException { + public Map processOutput(InvocationContext context) throws ProviderException { ShellApplicationDeployment app = (ShellApplicationDeployment) context.getExecutionDescription().getApp(); try { String stdOutStr = GfacUtils.readFileToString(app.getStdOut()); - String stdErrStr = GfacUtils.readFileToString(app.getStdErr()); // set to context - OutputUtils.fillOutputFromStdout(context. getOutput(), stdOutStr, stdErrStr); + return OutputUtils.fillOutputFromStdout(context. getOutput(), stdOutStr); } catch (IOException io) { - + throw new ProviderException(io.getMessage(), io); } } } Modified: incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/Provider.java URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/Provider.java?rev=1170323&r1=1170322&r2=1170323&view=diff ============================================================================== --- incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/Provider.java (original) +++ incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/Provider.java Tue Sep 13 19:53:45 2011 @@ -21,6 +21,8 @@ package org.apache.airavata.core.gfac.provider; +import java.util.Map; + import org.apache.airavata.commons.gfac.type.ApplicationDeploymentDescription; import org.apache.airavata.core.gfac.context.invocation.InvocationContext; import org.apache.airavata.core.gfac.exception.GfacException; @@ -32,11 +34,28 @@ import org.apache.airavata.core.gfac.exc */ public interface Provider { + /** + * The method is used for initialization step. + * + * @param invocationContext + * @throws ProviderException + */ void initialize(InvocationContext invocationContext) throws ProviderException; - void execute(InvocationContext invocationContext) throws ProviderException; - + /** + * Execution step + * + * @param invocationContext + * @return result of execution in Map as key and value pair + * @throws ProviderException + */ + Map execute(InvocationContext invocationContext) throws ProviderException; + + /** + * Dispose is always called whether there is an exception or not. + * + * @param invocationContext + * @throws GfacException + */ void dispose(InvocationContext invocationContext) throws GfacException; - - void abort(InvocationContext invocationContext) throws GfacException; } Modified: incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/SSHProvider.java URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/SSHProvider.java?rev=1170323&r1=1170322&r2=1170323&view=diff ============================================================================== --- incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/SSHProvider.java (original) +++ incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/SSHProvider.java Tue Sep 13 19:53:45 2011 @@ -44,10 +44,10 @@ import org.apache.airavata.commons.gfac. import org.apache.airavata.commons.gfac.type.parameter.AbstractParameter; import org.apache.airavata.core.gfac.context.invocation.InvocationContext; import org.apache.airavata.core.gfac.context.security.impl.SSHSecurityContextImpl; -import org.apache.airavata.core.gfac.exception.GfacException; import org.apache.airavata.core.gfac.exception.ProviderException; import org.apache.airavata.core.gfac.utils.GFacConstants; import org.apache.airavata.core.gfac.utils.GfacUtils; +import org.apache.airavata.core.gfac.utils.InputUtils; import org.apache.airavata.core.gfac.utils.OutputUtils; /** @@ -58,22 +58,15 @@ public class SSHProvider extends Abstrac private static final String SPACE = " "; private static final String SSH_SECURITY_CONTEXT = "ssh"; private static final int COMMAND_EXECUTION_TIMEOUT = 5; - + private SSHSecurityContextImpl sshContext; private String command; - private String buildCommand(List cmdList) { - StringBuffer buff = new StringBuffer(); - for (String string : cmdList) { - buff.append(string); - buff.append(SPACE); - } - return buff.toString(); - } - private void initSSHSecurity(InvocationContext context, SSHClient ssh) throws IOException { try { - SSHSecurityContextImpl sshContext = ((SSHSecurityContextImpl) context - .getSecurityContext(SSH_SECURITY_CONTEXT)); + + if(sshContext == null){ + sshContext = ((SSHSecurityContextImpl) context.getSecurityContext(SSH_SECURITY_CONTEXT)); + } KeyProvider pkey = ssh.loadKeys(sshContext.getPrivateKeyLoc(), sshContext.getKeyPass()); @@ -86,18 +79,6 @@ public class SSHProvider extends Abstrac } - public void initialize(InvocationContext context) throws ProviderException { - } - - public void execute(InvocationContext context) throws ProviderException { - } - - public void dispose(InvocationContext invocationContext) throws GfacException { - } - - public void abort(InvocationContext invocationContext) throws GfacException { - } - // TODO: This method has a try/catch embedded in 'finally' method. Is there // a way // TODO: to force cleanup on failed connections? @@ -167,7 +148,7 @@ public class SSHProvider extends Abstrac cmdList.addAll(tmp); // create process builder from command - command = buildCommand(cmdList); + command = InputUtils.buildCommand(cmdList); // redirect StdOut and StdErr // TODO: Make 1> and 2> into static constants. @@ -251,7 +232,7 @@ public class SSHProvider extends Abstrac } } - public void retrieveOutput(InvocationContext context) throws ProviderException { + public Map processOutput(InvocationContext context) throws ProviderException { HostDescription host = context.getExecutionDescription().getHost(); ShellApplicationDeployment app = (ShellApplicationDeployment) context.getExecutionDescription().getApp(); SSHClient ssh = new SSHClient(); @@ -288,7 +269,7 @@ public class SSHProvider extends Abstrac String stdErrStr = GfacUtils.readFileToString(localStdErrFile.getAbsolutePath()); // set to context - OutputUtils.fillOutputFromStdout(context. getOutput(), stdOutStr, stdErrStr); + return OutputUtils.fillOutputFromStdout(context. getOutput(), stdOutStr); } catch (ConnectionException e) { throw e; Modified: incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/services/impl/AbstractSimpleService.java URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/services/impl/AbstractSimpleService.java?rev=1170323&r1=1170322&r2=1170323&view=diff ============================================================================== --- incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/services/impl/AbstractSimpleService.java (original) +++ incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/services/impl/AbstractSimpleService.java Tue Sep 13 19:53:45 2011 @@ -21,6 +21,9 @@ package org.apache.airavata.core.gfac.services.impl; +import java.util.Map; +import java.util.Map.Entry; + import org.apache.airavata.core.gfac.context.invocation.InvocationContext; import org.apache.airavata.core.gfac.exception.ExtensionException; import org.apache.airavata.core.gfac.exception.GfacException; @@ -37,17 +40,17 @@ import org.slf4j.LoggerFactory; /** * The abstract service wraps up steps of execution for {@link GenericService}. - * Also, it adds input/output plug-ins before/after {@link Provider} execution. - * The steps in execution are - * - preProcess - * - Determine Provider (Scheduling) - * - {@link DataServiceChain} Plugins - * - {@link Provider} initialization - * - {@link PreExecuteChain} Plugins - * - {@link Provider} execution - * - {@link PostExecuteChain} Plugins - * - {@link Provider} disposal - * - postProcess + * Also, it adds input/output plug-ins before/after {@link Provider} execution.
+ * The steps in execution are
+ * - preProcess
+ * - Determine Provider (Scheduling)
+ * - {@link DataServiceChain} Plugins
+ * - {@link Provider} initialization
+ * - {@link PreExecuteChain} Plugins
+ * - {@link Provider} execution
+ * - {@link PostExecuteChain} Plugins
+ * - {@link Provider} disposal
+ * - postProcess
*/ public abstract class AbstractSimpleService implements GenericService { @@ -107,26 +110,36 @@ public abstract class AbstractSimpleServ log.debug("After pre-execution chain, try to execute provider"); - /* - * Execute - */ - provider.execute(context); - - log.debug("After provider execution, try to run post-execution chain"); - - /* - * Post-Execution - */ - buildChains(getPostExecuteSteps(context)).start(context); - - log.debug("After pre-execution chain, try to dispose provider"); - - /* - * Destroy - */ - provider.dispose(context); + try { + /* + * Execute + */ + Map result = provider.execute(context); + + log.debug("After provider execution, try to run post-execution chain"); + + /* + * Fill MessageContext with the output from Provider + */ + for (Entry entry : result.entrySet()) { + context.getOutput().setValue(entry.getKey(), entry.getValue()); + } + + /* + * Post-Execution + */ + buildChains(getPostExecuteSteps(context)).start(context); + + log.debug("After pre-execution chain, try to dispose provider"); + + } finally { + /* + * Destroy + */ + provider.dispose(context); - log.debug("After provider disposal, try to run postprocess"); + log.debug("After provider disposal, try to run postprocess"); + } /* * Pre-Process @@ -142,7 +155,7 @@ public abstract class AbstractSimpleServ * Validation check and return doing-nothing chain object */ if (list == null || list.length == 0) { - return new NullChain(); + return new NullChain(); } ExitableChain currentPoint = list[0]; Added: incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/utils/InputUtils.java URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/utils/InputUtils.java?rev=1170323&view=auto ============================================================================== --- incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/utils/InputUtils.java (added) +++ incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/utils/InputUtils.java Tue Sep 13 19:53:45 2011 @@ -0,0 +1,38 @@ +/* + * + * 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.utils; + +import java.util.List; + +public class InputUtils { + + private static final String SPACE = " "; + + public static String buildCommand(List cmdList) { + StringBuffer buff = new StringBuffer(); + for (String string : cmdList) { + buff.append(string); + buff.append(SPACE); + } + return buff.toString(); + } +} Modified: incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/utils/OutputUtils.java URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/utils/OutputUtils.java?rev=1170323&r1=1170322&r2=1170323&view=diff ============================================================================== --- incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/utils/OutputUtils.java (original) +++ incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/utils/OutputUtils.java Tue Sep 13 19:53:45 2011 @@ -21,17 +21,21 @@ package org.apache.airavata.core.gfac.utils; +import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.airavata.commons.gfac.type.parameter.AbstractParameter; import org.apache.airavata.core.gfac.context.message.MessageContext; -public class OutputUtils { - - public static void fillOutputFromStdout(MessageContext outMessage, String stdout, String stderr) { +public class OutputUtils { + + public static Map fillOutputFromStdout(MessageContext outMessage, String stdout) { + Map result = new HashMap(); + for (Iterator iterator = outMessage.getNames(); iterator.hasNext();) { String parameterName = iterator.next(); @@ -42,7 +46,9 @@ public class OutputUtils { AbstractParameter x = outMessage.getValue(parameterName); x.parseStringVal(parseStdout(stdout, parameterName)); + result.put(parameterName, x); } + return result; } private static String parseStdout(String stdout, String outParam) {