Return-Path: X-Original-To: apmail-airavata-commits-archive@www.apache.org Delivered-To: apmail-airavata-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 026409C69 for ; Wed, 6 Mar 2013 15:58:22 +0000 (UTC) Received: (qmail 40990 invoked by uid 500); 6 Mar 2013 15:58:20 -0000 Delivered-To: apmail-airavata-commits-archive@airavata.apache.org Received: (qmail 40881 invoked by uid 500); 6 Mar 2013 15:58:17 -0000 Mailing-List: contact commits-help@airavata.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airavata.apache.org Delivered-To: mailing list commits@airavata.apache.org Received: (qmail 40420 invoked by uid 99); 6 Mar 2013 15:58:16 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Mar 2013 15:58:16 +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; Wed, 06 Mar 2013 15:58:14 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 003EE2388A33; Wed, 6 Mar 2013 15:57:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1453396 - in /airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl: AbstractProvider.java EC2Provider.java SSHProvider.java Date: Wed, 06 Mar 2013 15:57:54 -0000 To: commits@airavata.apache.org From: heshan@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130306155755.003EE2388A33@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: heshan Date: Wed Mar 6 15:57:54 2013 New Revision: 1453396 URL: http://svn.apache.org/r1453396 Log: Commenting out the SSHProvider as it should be updated and tested against the new gfac.core architecture. Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/AbstractProvider.java airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/EC2Provider.java airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/SSHProvider.java Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/AbstractProvider.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/AbstractProvider.java?rev=1453396&r1=1453395&r2=1453396&view=diff ============================================================================== --- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/AbstractProvider.java (original) +++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/AbstractProvider.java Wed Mar 6 15:57:54 2013 @@ -1,89 +1,89 @@ -/* - * - * 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.util.Map; - -import org.apache.airavata.common.workflow.execution.context.WorkflowContextHeaderBuilder; -import org.apache.airavata.core.gfac.context.invocation.InvocationContext; -import org.apache.airavata.core.gfac.exception.*; -import org.apache.airavata.core.gfac.notification.GFacNotifier; -import org.apache.airavata.core.gfac.provider.Provider; -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
- */ -public abstract class AbstractProvider implements Provider { - protected final Logger log = LoggerFactory.getLogger(this.getClass() + - "." + WorkflowContextHeaderBuilder.getCurrentContextHeader().getWorkflowMonitoringContext().getExperimentId()); - public void initialize(InvocationContext invocationContext) throws ProviderException { - /* - * Make a directory on the host - */ - makeDirectory(invocationContext); - } - - public void dispose(InvocationContext invocationContext) throws GfacException { - } - - public Map execute(InvocationContext invocationContext) throws ProviderException { - - processInput(invocationContext); - /* - * Setup necessary environment - */ - setupEnvironment(invocationContext); - - GFacNotifier notifier = invocationContext.getExecutionContext().getNotifier(); - - notifier.startExecution(invocationContext); - - /* - * Execution application - */ - executeApplication(invocationContext); - - notifier.finishExecution(invocationContext); - - /* - * Process output information - */ - return processOutput(invocationContext); - } - - protected abstract void makeDirectory(InvocationContext invocationContext) throws ProviderException; - - protected abstract void setupEnvironment(InvocationContext invocationContext) throws ProviderException; - - protected abstract void executeApplication(InvocationContext invocationContext) throws ProviderException; - - protected abstract Map processOutput(InvocationContext invocationContext) throws ProviderException; - - protected abstract Map processInput(InvocationContext invocationContext) throws ProviderException; -} +///* +// * +// * 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.util.Map; +// +//import org.apache.airavata.common.workflow.execution.context.WorkflowContextHeaderBuilder; +//import org.apache.airavata.core.gfac.context.invocation.InvocationContext; +//import org.apache.airavata.core.gfac.exception.*; +//import org.apache.airavata.core.gfac.notification.GFacNotifier; +//import org.apache.airavata.core.gfac.provider.Provider; +//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
+// */ +//public abstract class AbstractProvider implements Provider { +// protected final Logger log = LoggerFactory.getLogger(this.getClass() + +// "." + WorkflowContextHeaderBuilder.getCurrentContextHeader().getWorkflowMonitoringContext().getExperimentId()); +// public void initialize(InvocationContext invocationContext) throws ProviderException { +// /* +// * Make a directory on the host +// */ +// makeDirectory(invocationContext); +// } +// +// public void dispose(InvocationContext invocationContext) throws GfacException { +// } +// +// public Map execute(InvocationContext invocationContext) throws ProviderException { +// +// processInput(invocationContext); +// /* +// * Setup necessary environment +// */ +// setupEnvironment(invocationContext); +// +// GFacNotifier notifier = invocationContext.getExecutionContext().getNotifier(); +// +// notifier.startExecution(invocationContext); +// +// /* +// * Execution application +// */ +// executeApplication(invocationContext); +// +// notifier.finishExecution(invocationContext); +// +// /* +// * Process output information +// */ +// return processOutput(invocationContext); +// } +// +// protected abstract void makeDirectory(InvocationContext invocationContext) throws ProviderException; +// +// protected abstract void setupEnvironment(InvocationContext invocationContext) throws ProviderException; +// +// protected abstract void executeApplication(InvocationContext invocationContext) throws ProviderException; +// +// protected abstract Map processOutput(InvocationContext invocationContext) throws ProviderException; +// +// protected abstract Map processInput(InvocationContext invocationContext) throws ProviderException; +//} Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/EC2Provider.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/EC2Provider.java?rev=1453396&r1=1453395&r2=1453396&view=diff ============================================================================== --- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/EC2Provider.java (original) +++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/EC2Provider.java Wed Mar 6 15:57:54 2013 @@ -31,7 +31,10 @@ import org.apache.airavata.gfac.context. 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.utils.GramJobSubmissionListener; import org.bouncycastle.openssl.PEMWriter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.*; import java.security.KeyPairGenerator; @@ -43,7 +46,9 @@ import java.util.List; // TODO // import com.sshtools.j2ssh.util.Base64; -public class EC2Provider extends SSHProvider implements GFacProvider { +public class EC2Provider /*extends SSHProvider*/ implements GFacProvider { + + private static final Logger log = LoggerFactory.getLogger(EC2Provider.class); public static final int SLEEP_TIME_SECOND = 120; Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/SSHProvider.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/SSHProvider.java?rev=1453396&r1=1453395&r2=1453396&view=diff ============================================================================== --- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/SSHProvider.java (original) +++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/SSHProvider.java Wed Mar 6 15:57:54 2013 @@ -1,282 +1,282 @@ -/* - * - * 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.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.TimeUnit; - -import net.schmizz.sshj.SSHClient; -import net.schmizz.sshj.connection.ConnectionException; -import net.schmizz.sshj.connection.channel.direct.Session; -import net.schmizz.sshj.connection.channel.direct.Session.Command; -import net.schmizz.sshj.transport.TransportException; -import net.schmizz.sshj.userauth.keyprovider.KeyProvider; -import net.schmizz.sshj.xfer.scp.SCPFileTransfer; - -import org.apache.airavata.commons.gfac.type.ActualParameter; -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; -import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType; -import org.apache.airavata.schemas.gfac.NameValuePairType; -import org.apache.xmlbeans.XmlException; - -/** - * Execute application using remote SSH - */ -public class SSHProvider extends AbstractProvider { - - 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 SSHClient ssh; - - public SSHProvider() { - ssh = new SSHClient(); - } - - private Session getSession(InvocationContext context) throws IOException { - try { - - /* - * if it is connected, create a session Note: one client can have multiple session (on one channel) - */ - if (ssh.isConnected()) - return ssh.startSession(); - - if (sshContext == null) { - sshContext = ((SSHSecurityContextImpl) context.getSecurityContext(SSH_SECURITY_CONTEXT)); - } - - KeyProvider pkey = ssh.loadKeys(sshContext.getPrivateKeyLoc(), sshContext.getKeyPass()); - - ssh.loadKnownHosts(); - ssh.authPublickey(sshContext.getUsername(), pkey); - - ssh.connect(context.getExecutionDescription().getHost().getType().getHostAddress()); - return ssh.startSession(); - - } catch (NullPointerException ne) { - throw new SecurityException("Cannot load security context for SSH", ne); - } - } - - private void closeSession(Session session) { - if (session != null) { - try { - session.close(); - } catch (Exception e) { - log.warn("Cannot Close SSH Session"); - } - } - } - - public void makeDirectory(InvocationContext context) throws ProviderException { - ApplicationDeploymentDescriptionType app = context.getExecutionDescription().getApp().getType(); - - Session session = null; - try { - session = getSession(context); - - StringBuilder commandString = new StringBuilder(); - - commandString.append("mkdir -p "); - commandString.append(app.getScratchWorkingDirectory()); - commandString.append(" ; "); - commandString.append("mkdir -p "); - commandString.append(app.getStaticWorkingDirectory()); - commandString.append(" ; "); - commandString.append("mkdir -p "); - commandString.append(app.getInputDataDirectory()); - commandString.append(" ; "); - commandString.append("mkdir -p "); - commandString.append(app.getOutputDataDirectory()); - - Command cmd = session.exec(commandString.toString()); - cmd.join(COMMAND_EXECUTION_TIMEOUT, TimeUnit.SECONDS); - } catch (ConnectionException e) { - throw new ProviderException(e.getMessage(), e, context); - } catch (TransportException e) { - throw new ProviderException(e.getMessage(), e, context); - } catch (IOException e) { - throw new ProviderException(e.getMessage(), e, context); - } finally { - closeSession(session); - } - } - - public void setupEnvironment(InvocationContext context) throws ProviderException { - ApplicationDeploymentDescriptionType app = context.getExecutionDescription().getApp().getType(); - - // input parameter - ArrayList tmp = new ArrayList(); - for (Iterator iterator = context.getInput().getNames(); iterator.hasNext();) { - String key = iterator.next(); - tmp.add(context.getInput().getStringValue(key)); - } - - List cmdList = new ArrayList(); - - /* - * Builder Command - */ - cmdList.add(app.getExecutableLocation()); - cmdList.addAll(tmp); - - // create process builder from command - command = InputUtils.buildCommand(cmdList); - - // redirect StdOut and StdErr - // TODO: Make 1> and 2> into static constants. - // TODO: This only works for the BASH shell. CSH and TCSH will be - // different. - command += SPACE + "1>" + SPACE + app.getStandardOutput(); - command += SPACE + "2>" + SPACE + app.getStandardError(); - } - - public void executeApplication(InvocationContext context) throws ProviderException { - ApplicationDeploymentDescriptionType app = context.getExecutionDescription().getApp().getType(); - - Session session = null; - try { - session = getSession(context); - - /* - * Going to working Directory - */ - session.exec("cd " + app.getStaticWorkingDirectory()); - - // get the env of the host and the application - NameValuePairType[] env = app.getApplicationEnvironmentArray(); - - Map nv = new HashMap(); - if (env != null) { - for (int i = 0; i < env.length; i++) { - String key = env[i].getName(); - String value = env[i].getValue(); - nv.put(key, value); - } - } - // extra env's - nv.put(GFacConstants.INPUT_DATA_DIR_VAR_NAME, app.getInputDataDirectory()); - nv.put(GFacConstants.OUTPUT_DATA_DIR_VAR_NAME, app.getOutputDataDirectory()); - - /* - * Set environment - */ - log.debug("Command = " + command); - for (Entry entry : nv.entrySet()) { - log.debug("Env[" + entry.getKey() + "] = " + entry.getValue()); - session.setEnvVar(entry.getKey(), entry.getValue()); - } - - /* - * Execute - */ - Command cmd = session.exec(command); - log.debug("stdout=" + GfacUtils.readFromStream(session.getInputStream())); - cmd.join(COMMAND_EXECUTION_TIMEOUT, TimeUnit.SECONDS); - - /* - * check return value. usually not very helpful to draw conclusions based on return values so don't bother. - * just provide warning in the log messages - */ - if (cmd.getExitStatus() != 0) { - log.error("Process finished with non zero return value. Process may have failed"); - } else { - log.debug("Process finished with return value of zero."); - } - - } catch (ConnectionException e) { - throw new ProviderException(e.getMessage(), e, context); - } catch (TransportException e) { - throw new ProviderException(e.getMessage(), e, context); - } catch (IOException e) { - throw new ProviderException(e.getMessage(), e, context); - } finally { - closeSession(session); - } - } - - public Map processOutput(InvocationContext context) throws ProviderException { - ApplicationDeploymentDescriptionType app = context.getExecutionDescription().getApp().getType(); - try { - - // Get the Stdouts and StdErrs - String timeStampedServiceName = GfacUtils.createUniqueNameForService(context.getServiceName()); - File localStdOutFile = File.createTempFile(timeStampedServiceName, "stdout"); - File localStdErrFile = File.createTempFile(timeStampedServiceName, "stderr"); - - SCPFileTransfer fileTransfer = ssh.newSCPFileTransfer(); - fileTransfer.download(app.getStandardOutput(), localStdOutFile.getAbsolutePath()); - fileTransfer.download(app.getStandardError(), localStdErrFile.getAbsolutePath()); - - String stdOutStr = GfacUtils.readFileToString(localStdOutFile.getAbsolutePath()); - String stdErrStr = GfacUtils.readFileToString(localStdErrFile.getAbsolutePath()); - - return OutputUtils.fillOutputFromStdout(context. getOutput(), stdOutStr,stdErrStr); - - } catch (XmlException e) { - throw new ProviderException("Cannot read output:" + e.getMessage(), e, context); - } catch (ConnectionException e) { - throw new ProviderException(e.getMessage(), e, context); - } catch (TransportException e) { - throw new ProviderException(e.getMessage(), e, context); - } catch (IOException e) { - throw new ProviderException(e.getMessage(), e, context); - } catch (Exception e){ - throw new ProviderException("Error in retrieving results",e,context); - } - } - - public void dispose(InvocationContext invocationContext) throws GfacException { - super.dispose(invocationContext); - try { - if (ssh != null && ssh.isConnected()) { - ssh.disconnect(); - } - } catch (Exception e) { - log.warn("Cannot Close SSH Connection"); - } - } - - @Override - protected Map processInput(InvocationContext invocationContext) - throws ProviderException { - // TODO Auto-generated method stub - return null; - } -} +///* +// * +// * 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.File; +//import java.io.IOException; +//import java.util.ArrayList; +//import java.util.HashMap; +//import java.util.Iterator; +//import java.util.List; +//import java.util.Map; +//import java.util.Map.Entry; +//import java.util.concurrent.TimeUnit; +// +//import net.schmizz.sshj.SSHClient; +//import net.schmizz.sshj.connection.ConnectionException; +//import net.schmizz.sshj.connection.channel.direct.Session; +//import net.schmizz.sshj.connection.channel.direct.Session.Command; +//import net.schmizz.sshj.transport.TransportException; +//import net.schmizz.sshj.userauth.keyprovider.KeyProvider; +//import net.schmizz.sshj.xfer.scp.SCPFileTransfer; +// +//import org.apache.airavata.commons.gfac.type.ActualParameter; +//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; +//import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType; +//import org.apache.airavata.schemas.gfac.NameValuePairType; +//import org.apache.xmlbeans.XmlException; +// +///** +// * Execute application using remote SSH +// */ +//public class SSHProvider extends AbstractProvider { +// +// 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 SSHClient ssh; +// +// public SSHProvider() { +// ssh = new SSHClient(); +// } +// +// private Session getSession(InvocationContext context) throws IOException { +// try { +// +// /* +// * if it is connected, create a session Note: one client can have multiple session (on one channel) +// */ +// if (ssh.isConnected()) +// return ssh.startSession(); +// +// if (sshContext == null) { +// sshContext = ((SSHSecurityContextImpl) context.getSecurityContext(SSH_SECURITY_CONTEXT)); +// } +// +// KeyProvider pkey = ssh.loadKeys(sshContext.getPrivateKeyLoc(), sshContext.getKeyPass()); +// +// ssh.loadKnownHosts(); +// ssh.authPublickey(sshContext.getUsername(), pkey); +// +// ssh.connect(context.getExecutionDescription().getHost().getType().getHostAddress()); +// return ssh.startSession(); +// +// } catch (NullPointerException ne) { +// throw new SecurityException("Cannot load security context for SSH", ne); +// } +// } +// +// private void closeSession(Session session) { +// if (session != null) { +// try { +// session.close(); +// } catch (Exception e) { +// log.warn("Cannot Close SSH Session"); +// } +// } +// } +// +// public void makeDirectory(InvocationContext context) throws ProviderException { +// ApplicationDeploymentDescriptionType app = context.getExecutionDescription().getApp().getType(); +// +// Session session = null; +// try { +// session = getSession(context); +// +// StringBuilder commandString = new StringBuilder(); +// +// commandString.append("mkdir -p "); +// commandString.append(app.getScratchWorkingDirectory()); +// commandString.append(" ; "); +// commandString.append("mkdir -p "); +// commandString.append(app.getStaticWorkingDirectory()); +// commandString.append(" ; "); +// commandString.append("mkdir -p "); +// commandString.append(app.getInputDataDirectory()); +// commandString.append(" ; "); +// commandString.append("mkdir -p "); +// commandString.append(app.getOutputDataDirectory()); +// +// Command cmd = session.exec(commandString.toString()); +// cmd.join(COMMAND_EXECUTION_TIMEOUT, TimeUnit.SECONDS); +// } catch (ConnectionException e) { +// throw new ProviderException(e.getMessage(), e, context); +// } catch (TransportException e) { +// throw new ProviderException(e.getMessage(), e, context); +// } catch (IOException e) { +// throw new ProviderException(e.getMessage(), e, context); +// } finally { +// closeSession(session); +// } +// } +// +// public void setupEnvironment(InvocationContext context) throws ProviderException { +// ApplicationDeploymentDescriptionType app = context.getExecutionDescription().getApp().getType(); +// +// // input parameter +// ArrayList tmp = new ArrayList(); +// for (Iterator iterator = context.getInput().getNames(); iterator.hasNext();) { +// String key = iterator.next(); +// tmp.add(context.getInput().getStringValue(key)); +// } +// +// List cmdList = new ArrayList(); +// +// /* +// * Builder Command +// */ +// cmdList.add(app.getExecutableLocation()); +// cmdList.addAll(tmp); +// +// // create process builder from command +// command = InputUtils.buildCommand(cmdList); +// +// // redirect StdOut and StdErr +// // TODO: Make 1> and 2> into static constants. +// // TODO: This only works for the BASH shell. CSH and TCSH will be +// // different. +// command += SPACE + "1>" + SPACE + app.getStandardOutput(); +// command += SPACE + "2>" + SPACE + app.getStandardError(); +// } +// +// public void executeApplication(InvocationContext context) throws ProviderException { +// ApplicationDeploymentDescriptionType app = context.getExecutionDescription().getApp().getType(); +// +// Session session = null; +// try { +// session = getSession(context); +// +// /* +// * Going to working Directory +// */ +// session.exec("cd " + app.getStaticWorkingDirectory()); +// +// // get the env of the host and the application +// NameValuePairType[] env = app.getApplicationEnvironmentArray(); +// +// Map nv = new HashMap(); +// if (env != null) { +// for (int i = 0; i < env.length; i++) { +// String key = env[i].getName(); +// String value = env[i].getValue(); +// nv.put(key, value); +// } +// } +// // extra env's +// nv.put(GFacConstants.INPUT_DATA_DIR_VAR_NAME, app.getInputDataDirectory()); +// nv.put(GFacConstants.OUTPUT_DATA_DIR_VAR_NAME, app.getOutputDataDirectory()); +// +// /* +// * Set environment +// */ +// log.debug("Command = " + command); +// for (Entry entry : nv.entrySet()) { +// log.debug("Env[" + entry.getKey() + "] = " + entry.getValue()); +// session.setEnvVar(entry.getKey(), entry.getValue()); +// } +// +// /* +// * Execute +// */ +// Command cmd = session.exec(command); +// log.debug("stdout=" + GfacUtils.readFromStream(session.getInputStream())); +// cmd.join(COMMAND_EXECUTION_TIMEOUT, TimeUnit.SECONDS); +// +// /* +// * check return value. usually not very helpful to draw conclusions based on return values so don't bother. +// * just provide warning in the log messages +// */ +// if (cmd.getExitStatus() != 0) { +// log.error("Process finished with non zero return value. Process may have failed"); +// } else { +// log.debug("Process finished with return value of zero."); +// } +// +// } catch (ConnectionException e) { +// throw new ProviderException(e.getMessage(), e, context); +// } catch (TransportException e) { +// throw new ProviderException(e.getMessage(), e, context); +// } catch (IOException e) { +// throw new ProviderException(e.getMessage(), e, context); +// } finally { +// closeSession(session); +// } +// } +// +// public Map processOutput(InvocationContext context) throws ProviderException { +// ApplicationDeploymentDescriptionType app = context.getExecutionDescription().getApp().getType(); +// try { +// +// // Get the Stdouts and StdErrs +// String timeStampedServiceName = GfacUtils.createUniqueNameForService(context.getServiceName()); +// File localStdOutFile = File.createTempFile(timeStampedServiceName, "stdout"); +// File localStdErrFile = File.createTempFile(timeStampedServiceName, "stderr"); +// +// SCPFileTransfer fileTransfer = ssh.newSCPFileTransfer(); +// fileTransfer.download(app.getStandardOutput(), localStdOutFile.getAbsolutePath()); +// fileTransfer.download(app.getStandardError(), localStdErrFile.getAbsolutePath()); +// +// String stdOutStr = GfacUtils.readFileToString(localStdOutFile.getAbsolutePath()); +// String stdErrStr = GfacUtils.readFileToString(localStdErrFile.getAbsolutePath()); +// +// return OutputUtils.fillOutputFromStdout(context. getOutput(), stdOutStr,stdErrStr); +// +// } catch (XmlException e) { +// throw new ProviderException("Cannot read output:" + e.getMessage(), e, context); +// } catch (ConnectionException e) { +// throw new ProviderException(e.getMessage(), e, context); +// } catch (TransportException e) { +// throw new ProviderException(e.getMessage(), e, context); +// } catch (IOException e) { +// throw new ProviderException(e.getMessage(), e, context); +// } catch (Exception e){ +// throw new ProviderException("Error in retrieving results",e,context); +// } +// } +// +// public void dispose(InvocationContext invocationContext) throws GfacException { +// super.dispose(invocationContext); +// try { +// if (ssh != null && ssh.isConnected()) { +// ssh.disconnect(); +// } +// } catch (Exception e) { +// log.warn("Cannot Close SSH Connection"); +// } +// } +// +// @Override +// protected Map processInput(InvocationContext invocationContext) +// throws ProviderException { +// // TODO Auto-generated method stub +// return null; +// } +//}