Author: lahiru Date: Thu Jun 7 03:29:11 2012 New Revision: 1347355 URL: http://svn.apache.org/viewvc?rev=1347355&view=rev Log: fixing https://issues.apache.org/jira/browse/AIRAVATA-460. Modified: incubator/airavata/branches/0.3-incubating-snapshot/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/impl/GramProvider.java incubator/airavata/branches/0.3-incubating-snapshot/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/utils/GramRSLGenerator.java Modified: incubator/airavata/branches/0.3-incubating-snapshot/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/impl/GramProvider.java URL: http://svn.apache.org/viewvc/incubator/airavata/branches/0.3-incubating-snapshot/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/impl/GramProvider.java?rev=1347355&r1=1347354&r2=1347355&view=diff ============================================================================== --- incubator/airavata/branches/0.3-incubating-snapshot/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/impl/GramProvider.java (original) +++ incubator/airavata/branches/0.3-incubating-snapshot/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/impl/GramProvider.java Thu Jun 7 03:29:11 2012 @@ -21,9 +21,7 @@ package org.apache.airavata.core.gfac.provider.impl; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; +import java.io.*; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; @@ -252,6 +250,7 @@ public class GramProvider extends Abstra GlobusHostType host = (GlobusHostType) invocationContext.getExecutionDescription().getHost().getType(); ApplicationDeploymentDescriptionType app = invocationContext.getExecutionDescription().getApp().getType(); GridFtp ftp = new GridFtp(); + File localStdErrFile = null; try { GSSCredential gssCred = gssContext.getGssCredentails(); @@ -280,7 +279,7 @@ public class GramProvider extends Abstra String timeStampedServiceName = GfacUtils.createUniqueNameForService(invocationContext .getServiceName()); File localStdOutFile = File.createTempFile(timeStampedServiceName, "stdout"); - File localStdErrFile = File.createTempFile(timeStampedServiceName, "stderr"); + localStdErrFile = File.createTempFile(timeStampedServiceName, "stderr"); String stdout = ftp.readRemoteFile(stdoutURI, gssCred, localStdOutFile); String stderr = ftp.readRemoteFile(stderrURI, gssCred, localStdErrFile); @@ -309,7 +308,7 @@ public class GramProvider extends Abstra JobSubmissionFault error = new JobSubmissionFault(this, new Exception(errorMsg), "GFAC HOST", gateKeeper, job.getRSL()); errorReason(errCode, error); - invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,error,errorMsg); + invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,error,readLastLinesofStdOut(localStdErrFile.getPath(), 20)); throw error; } } @@ -332,29 +331,27 @@ public class GramProvider extends Abstra } } return stringMap; - }catch (XmlException e) { - invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,e,e.getMessage()); - throw new ProviderException(e.getMessage(), e); - } - catch (ToolsException e) { - invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,e,e.getMessage()); - throw new ProviderException(e.getMessage(), e); + } catch (URISyntaxException e) { - invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,e,e.getMessage()); + invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,e,readLastLinesofStdOut(localStdErrFile.getPath(), 20)); throw new ProviderException("URI is malformatted:" + e.getMessage(), e); } + catch (NullPointerException e) { + invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,e,readLastLinesofStdOut(localStdErrFile.getPath(), 20)); + throw new ProviderException("Empty output generated:" + e.getMessage(), e); + } catch (Exception e) { + invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext, e, readLastLinesofStdOut(localStdErrFile.getPath(), 20)); + throw new ProviderException(e.getMessage(), e); + } } - /* - * If the execution reach here, all GridFTP Endpoint is failed. - */ + /* + * If the execution reach here, all GridFTP Endpoint is failed. + */ throw pe; - } catch (IOException e) { - invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,e,e.getMessage()); - throw new ProviderException(e.getMessage(), e); - } catch (SecurityException e) { - invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,e,e.getMessage()); + } catch (Exception e) { + invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,e,readLastLinesofStdOut(localStdErrFile.getPath(), 20)); throw new ProviderException(e.getMessage(), e); } @@ -480,4 +477,37 @@ public class GramProvider extends Abstra gssCred, outputFile); return outputFileStagingPath + File.separator + fileName; } + + private String readLastLinesofStdOut(String path, int count) { + StringBuffer buffer = new StringBuffer(); + FileInputStream in = null; + try { + in = new FileInputStream(path); + } catch (FileNotFoundException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + List strLine = new ArrayList(); + String tmp = null; + int numberofLines = 0; + try { + while ((tmp = br.readLine()) != null) { + strLine.add(tmp); + numberofLines++; + } + } catch (IOException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + for (int i = numberofLines - count; i < numberofLines; i++) { + buffer.append(strLine.get(i)); + buffer.append("\n"); + } + try { + in.close(); + } catch (IOException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + return buffer.toString(); + } } + Modified: incubator/airavata/branches/0.3-incubating-snapshot/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/utils/GramRSLGenerator.java URL: http://svn.apache.org/viewvc/incubator/airavata/branches/0.3-incubating-snapshot/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/utils/GramRSLGenerator.java?rev=1347355&r1=1347354&r2=1347355&view=diff ============================================================================== --- incubator/airavata/branches/0.3-incubating-snapshot/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/utils/GramRSLGenerator.java (original) +++ incubator/airavata/branches/0.3-incubating-snapshot/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/utils/GramRSLGenerator.java Thu Jun 7 03:29:11 2012 @@ -26,11 +26,13 @@ import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; +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.ToolsException; import org.apache.airavata.core.gfac.utils.GFacConstants; import org.apache.airavata.schemas.gfac.GramApplicationDeploymentType; import org.apache.airavata.schemas.gfac.NameValuePairType; +import org.apache.airavata.schemas.wec.ContextHeaderDocument; import org.globus.gram.GramAttributes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -96,7 +98,23 @@ public class GramRSLGenerator { jobAttr.addArgument(context.getInput().getStringValue(key)); } } - + // Using the workflowContext Header values if user provided them in the request and overwrite the default values in DD + ContextHeaderDocument.ContextHeader currentContextHeader = WorkflowContextHeaderBuilder.getCurrentContextHeader(); + if (currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray() != null && + currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray().length > 0) { + try { + int cpuCount = currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray()[0].getCpuCount(); + app.setCpuCount(cpuCount); + } catch (NullPointerException e) { + log.info("No Value sent in WorkflowContextHeader for CPU Count, value in the Deployment Descriptor will be used"); + } + try { + int nodeCount = currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray()[0].getNodeCount(); + app.setNodeCount(nodeCount); + } catch (NullPointerException e) { + log.info("No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used"); + } + } if (app.getNodeCount() > 0) { jobAttr.set("hostCount", String.valueOf(app.getNodeCount())); }