You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sm...@apache.org on 2012/11/10 03:50:26 UTC

svn commit: r1407721 - in /airavata/sandbox/grid-tools: ./ gram-client/ gram-client/config/ gram-client/src/ gram-client/src/main/ gram-client/src/main/java/ gram-client/src/main/java/org/ gram-client/src/main/java/org/apache/ gram-client/src/main/java...

Author: smarru
Date: Sat Nov 10 02:50:24 2012
New Revision: 1407721

URL: http://svn.apache.org/viewvc?rev=1407721&view=rev
Log:
adding sandbox area for grid-tools and gram client

Added:
    airavata/sandbox/grid-tools/
    airavata/sandbox/grid-tools/gram-client/
    airavata/sandbox/grid-tools/gram-client/config/
    airavata/sandbox/grid-tools/gram-client/config/gramclient.properties
    airavata/sandbox/grid-tools/gram-client/pom.xml
    airavata/sandbox/grid-tools/gram-client/run.sh   (with props)
    airavata/sandbox/grid-tools/gram-client/src/
    airavata/sandbox/grid-tools/gram-client/src/main/
    airavata/sandbox/grid-tools/gram-client/src/main/java/
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/CancelJob.java
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobListener.java
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobStatus.java
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobSubmission.java
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/context/
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/context/ApplicationContext.java
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/context/CertificateManager.java   (with props)
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/context/MyProxyCredentials.java
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/ExectionContext.java
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/FileTransfer.java
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/GramJobSubmission.java
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/JobSubmissionListener.java
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/JobSubmittionListener.java
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/utils/
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/utils/GridFTPContactInfo.java
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/utils/GridFtp.java
    airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/utils/ServiceConstants.java
    airavata/sandbox/grid-tools/gram-client/testFileTransfer.sh
    airavata/sandbox/grid-tools/gridftp-client/

Added: airavata/sandbox/grid-tools/gram-client/config/gramclient.properties
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/config/gramclient.properties?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/config/gramclient.properties (added)
+++ airavata/sandbox/grid-tools/gram-client/config/gramclient.properties Sat Nov 10 02:50:24 2012
@@ -0,0 +1,24 @@
+trustedCertsFile=./certificates/
+myproxyServer=myproxy.teragrid.org
+myproxy_lifetime=17280000
+myproxyUserName=
+myproxyPasswd=
+myproxyPort=7512
+
+#gateway=login5.ranger.tacc.utexas.edu:2120/jobmanager-sge
+#gateway=gatekeeper.lonestar.tacc.teragrid.org:2120/jobmanager-lsf
+#gateway=queenbee.loni-lsu.teragrid.org:2120/jobmanager-pbs
+gateway=gatekeeper.ranger.tacc.teragrid.org:2120/jobmanager-sge
+execution=/bin/sleep
+arguments=30
+queue=normal
+project_number=
+jobtype=single
+maxwalltime=1
+processors=1
+hosts=1
+gridftpserverSource=gsiftp://gridftp.ranger.tacc.teragrid.org:2812/
+gridftpSourcePath=/share/home/01314/ultrasca/qwtplot3d-0.2.6.tgz
+gridftpserverDest=gsiftp://trestles-dm1.sdsc.edu:2811/
+gsiftp://trestles.sdsc.edu:2811/
+gridftpDestPath=/oasis/projects/nsf/uot111/us3/jobs/US-SOMO_Thu_May_10_14_46_38_EST_2012_57f53af6-7e8d-44a4-acb2-144d59475d54/qwtplot3d-0.2.6.tgz
\ No newline at end of file

Added: airavata/sandbox/grid-tools/gram-client/pom.xml
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/pom.xml?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/pom.xml (added)
+++ airavata/sandbox/grid-tools/gram-client/pom.xml Sat Nov 10 02:50:24 2012
@@ -0,0 +1,199 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<!-- the version of maven's project object model -->
+
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>org.apache.airavata</groupId>
+	<artifactId>airavata-gram-client</artifactId>
+	<name>Airavata Gram Client</name>
+	<description>Standalone test client to experiment and test GRAM .</description>
+	<version>0.1-SNAPSHOT</version>
+	<packaging>jar</packaging>
+
+	<repositories>
+		<repository>
+			<name>ogce.m2.all</name>
+			<id>ogce.m2.all</id>
+			<url>http://community.ucs.indiana.edu:9090/archiva/repository/ogce.m2.all</url>
+		</repository>
+	</repositories>
+
+
+	<dependencies>
+
+		<dependency>
+			<groupId>cog-jglobus</groupId>
+			<artifactId>cog-jglobus</artifactId>
+			<version>1.8.0_1</version>
+		</dependency>
+
+		<dependency>
+			<groupId>cog-4_1_6_rc2</groupId>
+			<artifactId>puretls</artifactId>
+			<type>jar</type>
+			<version>cog-4_1_6</version>
+		</dependency>
+
+		<dependency>
+			<groupId>cog-4_1_6_rc2</groupId>
+			<artifactId>cryptix32</artifactId>
+			<type>jar</type>
+			<version>cog-4_1_6</version>
+		</dependency>
+
+		<dependency>
+			<groupId>cog-4_1_6_rc2</groupId>
+			<artifactId>jce-jdk13</artifactId>
+			<version>131</version>
+			<type>jar</type>
+		</dependency>
+
+		<dependency>
+			<groupId>cog-4_1_6_rc2</groupId>
+			<artifactId>cryptix-asn1</artifactId>
+			<type>jar</type>
+			<version>cog-4_1_6</version>
+		</dependency>
+		<dependency>
+			<groupId>cog-4_1_6_rc2</groupId>
+			<artifactId>commons-digester</artifactId>
+			<type>jar</type>
+			<version>cog-4_1_6</version>
+		</dependency>
+
+		<dependency>
+			<groupId>commons-logging</groupId>
+			<artifactId>commons-logging</artifactId>
+			<version>1.0.4</version>
+		</dependency>
+		<dependency>
+			<groupId>log4j</groupId>
+			<artifactId>log4j</artifactId>
+			<version>1.2.13</version>
+		</dependency>
+
+
+	</dependencies>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.5</source>
+					<target>1.5</target>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-dependency-plugin</artifactId>
+				<executions>
+					<execution>
+						<id>copy-dependencies</id>
+						<phase>package</phase>
+						<goals>
+							<goal>copy-dependencies</goal>
+						</goals>
+						<configuration>
+							<outputDirectory>target/lib</outputDirectory>
+							<overWriteReleases>false</overWriteReleases>
+							<overWriteSnapshots>true</overWriteSnapshots>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<artifactId>maven-antrun-plugin</artifactId>
+				<executions>
+					<execution>
+						<id>deleteCACerts</id>
+						<phase>clean</phase>
+						<goals>
+							<goal>run</goal>
+						</goals>
+						<inherited>false</inherited>
+						<configuration>
+							<tasks>
+								<delete dir="${trustedCertsLocation}" />
+							</tasks>
+						</configuration>
+					</execution>
+					<execution>
+						<id>installCACerts</id>
+						<goals>
+							<goal>run</goal>
+						</goals>
+						<phase>process-resources</phase>
+						<inherited>false</inherited>
+						<configuration>
+							<tasks>
+								<mkdir dir="${trustedCertsLocation}" />
+								<echo message="Downloading file" />
+								<get src="http://software.xsede.org/security/xsede-certs.tar.gz"
+									dest="${trustedCertsLocation}/xsede-certs.tar.gz" ignoreerrors="yes"
+									verbose="on" />
+								<echo message="Unzipping the certs" />
+								<gunzip src="${trustedCertsLocation}/xsede-certs.tar.gz"
+									dest="${trustedCertsLocation}/" />
+
+								<echo message="Downloading file" />
+								<get
+									src="http://www.collab-ogce.org/ogce/images/d/d1/IUCerts.tar.gz"
+									dest="${trustedCertsLocation}/IUCerts.tar.gz" ignoreerrors="yes"
+									verbose="on" />
+								<echo message="Unzipping the certs" />
+								<gunzip src="${trustedCertsLocation}/IUCerts.tar.gz"
+									dest="${trustedCertsLocation}/" />
+								<echo message="Untarring" />
+								<untar dest="${trustedCertsLocation}/../">
+									<fileset dir="${trustedCertsLocation}/">
+										<include name="**/*.tar" />
+									</fileset>
+								</untar>
+
+							</tasks>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+		<pluginManagement>
+			<plugins>
+				<!--This plugin's configuration is used to store Eclipse m2e settings 
+					only. It has no influence on the Maven build itself. -->
+				<plugin>
+					<groupId>org.eclipse.m2e</groupId>
+					<artifactId>lifecycle-mapping</artifactId>
+					<version>1.0.0</version>
+					<configuration>
+						<lifecycleMappingMetadata>
+							<pluginExecutions>
+								<pluginExecution>
+									<pluginExecutionFilter>
+										<groupId>
+											org.apache.maven.plugins
+										</groupId>
+										<artifactId>
+											maven-antrun-plugin
+										</artifactId>
+										<versionRange>
+											[1.3,)
+										</versionRange>
+										<goals>
+											<goal>run</goal>
+										</goals>
+									</pluginExecutionFilter>
+									<action>
+										<ignore></ignore>
+									</action>
+								</pluginExecution>
+							</pluginExecutions>
+						</lifecycleMappingMetadata>
+					</configuration>
+				</plugin>
+			</plugins>
+		</pluginManagement>
+	</build>
+
+</project>
+

Added: airavata/sandbox/grid-tools/gram-client/run.sh
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/run.sh?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/run.sh (added)
+++ airavata/sandbox/grid-tools/gram-client/run.sh Sat Nov 10 02:50:24 2012
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+for i in target/lib/*.jar
+do
+  CLASSPATH=$CLASSPATH:$i
+done
+
+CLASSPATH=$CLASSPATH:target/GRAM5-Lite-1.0.jar:./config
+
+echo $CLASSPATH
+
+$JAVA_HOME/bin/java -classpath $CLASSPATH org.apache.airavata.jobsubmission.JobSubmission $*

Propchange: airavata/sandbox/grid-tools/gram-client/run.sh
------------------------------------------------------------------------------
    svn:executable = *

Added: airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/CancelJob.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/CancelJob.java?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/CancelJob.java (added)
+++ airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/CancelJob.java Sat Nov 10 02:50:24 2012
@@ -0,0 +1,33 @@
+package org.apache.airavata.jobsubmission;
+
+import org.apache.airavata.jobsubmission.context.ApplicationContext;
+import org.apache.airavata.jobsubmission.gram.ExectionContext;
+import org.apache.log4j.Logger;
+import org.globus.gram.GramJob;
+import org.ietf.jgss.GSSCredential;
+
+public class CancelJob {
+	private static final Logger log = Logger.getLogger(CancelJob.class);
+	public void cancelJob(GSSCredential gssCred, ExectionContext appExecContext, String jobUrl) throws Exception{
+		log.setLevel(org.apache.log4j.Level.INFO);
+		String rsl = "";
+		GramJob job = new GramJob(rsl);
+		job.setID(jobUrl);
+		job.setCredentials(gssCred);
+		job.cancel();
+		
+	}
+public static void main(String[] args) {
+	try {
+		ApplicationContext context = new ApplicationContext();
+		context.login();
+		CancelJob job = new CancelJob();
+		String jobURL = "https://lslogin2.lonestar.tacc.utexas.edu:50385/16073824805448638521/14062883951572193460/";
+		ExectionContext contextExectionContext = new ExectionContext();
+		job.cancelJob(context.getGssCredential(), contextExectionContext, jobURL);
+	} catch (Exception e) {
+		// TODO Auto-generated catch block
+		e.printStackTrace();
+	}
+}
+}

Added: airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobListener.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobListener.java?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobListener.java (added)
+++ airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobListener.java Sat Nov 10 02:50:24 2012
@@ -0,0 +1,55 @@
+package org.apache.airavata.jobsubmission;
+
+import org.globus.gram.GramException;
+import org.globus.gram.GramJob;
+import org.globus.gram.GramJobListener;
+import org.ietf.jgss.GSSCredential;
+import org.ietf.jgss.GSSException;
+
+public class JobListener implements GramJobListener {
+
+	private boolean finished;
+	private int error;
+	private int status;
+	private GSSCredential credential;
+	private GramJob job;
+	
+	public JobListener(GramJob job, GSSCredential credential) {
+		this.job = job;
+		this.credential = credential;
+	}
+	public void waitFor() throws InterruptedException, GSSException, GramException {
+		while (!finished) {
+			
+		// job status is changed but method isn't invoked
+		if (status != 0) {
+			if (job.getStatus() != status) {
+				System.out.println("invoke method manually");
+				statusChanged(job);
+				}
+			}
+		 else {
+			statusChanged(job);
+			 System.out.println("Status is zero");
+		}
+		synchronized (this) {
+			wait(1000l);
+		}		
+		}
+	}
+
+	public void statusChanged(GramJob job) {
+		int jobStatus = job.getStatus();
+		String jobId = job.getIDAsString();
+		String statusString = job.getStatusAsString();
+		System.out.println("Status " + statusString);
+		if (jobStatus == GramJob.STATUS_DONE) {
+			finished = true;
+		} else if (jobStatus == GramJob.STATUS_FAILED) {
+			finished = true;
+			error = job.getError();
+			System.out.println("Job Error Code: " + error);
+		}
+	}
+
+}
\ No newline at end of file

Added: airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobStatus.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobStatus.java?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobStatus.java (added)
+++ airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobStatus.java Sat Nov 10 02:50:24 2012
@@ -0,0 +1,33 @@
+package org.apache.airavata.jobsubmission;
+
+import org.apache.airavata.jobsubmission.context.ApplicationContext;
+import org.globus.gram.GramJob;
+
+public class JobStatus {
+
+	
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		try {
+			ApplicationContext context = new ApplicationContext();
+			context.login();
+			
+			String rsl = "";
+			GramJob job = new GramJob(context.getGssCredential(),rsl);
+			job.setID("https://gatekeeper.ranger.tacc.teragrid.org:50388/16073791261988702796/9536223017013632385/");
+			JobListener listener = new JobListener(job, context.getGssCredential());
+			job.addListener(listener);
+			System.out.println("Status 1111111" + job.getStatusAsString());
+		    listener.waitFor();
+			System.out.println("Now Status" + job.getStatusAsString());
+			job.removeListener(listener);
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+
+	}
+
+}

Added: airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobSubmission.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobSubmission.java?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobSubmission.java (added)
+++ airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobSubmission.java Sat Nov 10 02:50:24 2012
@@ -0,0 +1,102 @@
+package org.apache.airavata.jobsubmission;
+
+import org.apache.airavata.jobsubmission.context.ApplicationContext;
+import org.apache.airavata.jobsubmission.gram.ExectionContext;
+import org.apache.airavata.jobsubmission.gram.GramJobSubmission;
+import org.apache.log4j.Logger;
+import org.ietf.jgss.GSSCredential;
+
+public class JobSubmission {
+
+	private static final Logger log = Logger.getLogger(JobSubmission.class);
+	private static ExectionContext contextExectionContext;
+	private static ApplicationContext context;
+	private static String newline = System.getProperty("line.separator");
+
+	public static synchronized ApplicationContext getContext() throws Exception {
+		if (context == null) {
+			context = new ApplicationContext();
+			try {
+				context.login();
+			} catch (Exception e) {
+				context = null;
+				e.printStackTrace();
+				throw e;
+			}
+		}
+		return context;
+	}
+
+	public static ExectionContext getExecutionContext() {
+
+		if (contextExectionContext == null) {
+			try {
+				contextExectionContext = new ExectionContext();
+			} catch (Exception e) {
+				log.error("Error loading configuration file", e);
+				System.err.println("Make sure configuration file is in classpath and has proper values");
+
+				/*
+				 * Set required value to default since property file cannot be
+				 * loaded
+				 */
+				// contextExectionContext.setHost("login5.ranger.tacc.utexas.edu:2120/jobmanager-sge");
+				// contextExectionContext.setHost("gatekeeper.lonestar.tacc.teragrid.org:2120/jobmanager-lsf");
+				// contextExectionContext.setHost("queenbee.loni-lsu.teragrid.org:2120/jobmanager-pbs");
+				contextExectionContext.setHost("gatekeeper.ranger.tacc.teragrid.org:2120/jobmanager-sge");
+				contextExectionContext.setExecutable("/bin/sleep");
+				contextExectionContext.setArguments("30");
+				contextExectionContext.setQueue("checkpt");
+				contextExectionContext.setProjectName("TG-STA060010N");
+				contextExectionContext.setJobType("single");
+				contextExectionContext.setMaxWallTime(1);
+				contextExectionContext.setPcount(1);
+				contextExectionContext.setHostCount(1);
+				e.printStackTrace();
+			}
+		}
+		return contextExectionContext;
+	}
+
+	public static void main(String[] args) {
+		try {
+			ApplicationContext context = new ApplicationContext();
+			context.login();
+
+			StringBuffer jobstatus = new StringBuffer();
+			GramJobSubmission gramJobSubmittion = new GramJobSubmission();
+
+			System.out.println();
+
+			gramJobSubmittion.executeJob(context.getGssCredential(), getExecutionContext(), jobstatus);
+			System.out.println(jobstatus.toString());
+			System.exit(0);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	public String toString() {
+		String result = null;
+		try {
+			StringBuffer x = new StringBuffer();
+			GSSCredential gssCredential = getContext().getGssCredential();
+			x.append(getExecutionContext().getHost() + "#" + getCName(gssCredential.getName().toString()) + newline);
+			log.info("NAME:" + getCName(gssCredential.getName().toString()));
+
+			GramJobSubmission gramJobSubmittion = new GramJobSubmission();
+			gramJobSubmittion.executeJob(gssCredential, getExecutionContext(), x);
+			result = x.toString();
+		} catch (Exception e) {
+			log.error(e.getCause());
+			result = getExecutionContext().getHost() + "#" + "user" + newline + System.currentTimeMillis() + "#" + "id" + "#" + "FAILED" + "#" + e.getMessage();
+
+		}
+		return result;
+	}
+
+	private String getCName(String full) {
+		int index = full.indexOf("/CN=");
+		return full.substring(index + 4);
+	}
+}

Added: airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/context/ApplicationContext.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/context/ApplicationContext.java?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/context/ApplicationContext.java (added)
+++ airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/context/ApplicationContext.java Sat Nov 10 02:50:24 2012
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2009 Pervasive Lab, Indiana University. All rights reserved.
+ *
+ * This software is open source. See the bottom of this file for the license.
+ *
+ * $Id: $
+ */
+
+package org.apache.airavata.jobsubmission.context;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Properties;
+
+import org.apache.airavata.jobsubmission.utils.ServiceConstants;
+import org.apache.log4j.Logger;
+import org.globus.myproxy.MyProxy;
+import org.ietf.jgss.GSSCredential;
+
+/**
+ * @author Raminderjeet Singh
+ */
+public class ApplicationContext {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = -2270092298283648553L;
+	public static final String GRAMCLIENT_PROPERTY = "gramclient.properties";
+	private Properties properties;
+	protected GSSCredential gssCredential;
+
+	private MyProxyCredentials credentials;
+	private static final Logger log = Logger.getLogger(ApplicationContext.class);
+
+	/**
+	 * 
+	 * Constructs a ApplicationGlobalContext.
+	 * 
+	 * @throws GfacGUIException
+	 */
+
+	public ApplicationContext() throws Exception {
+		log.setLevel(org.apache.log4j.Level.INFO);
+		loadConfiguration();
+
+	}
+
+	public static void main(String[] args) {
+		try {
+			ApplicationContext context = new ApplicationContext();
+			context.login();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	/**
+	 * 
+	 * @throws GfacException
+	 */
+	public void login() throws Exception {
+		gssCredential = credentials.getGssCredential();
+	}
+
+	public static String getProperty(String name) {
+		try {
+			ApplicationContext context = new ApplicationContext();
+			return context.getProperties().getProperty(name);
+		} catch (Exception e) {
+			e.printStackTrace();
+			return null;
+		}
+
+	}
+
+	/**
+	 * Load the configration file
+	 * 
+	 * @throws GfacException
+	 */
+	private void loadConfiguration() throws Exception {
+		try {
+			if (properties == null) {
+				ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+				File webinfDir = null;
+				URL propertyFile = classLoader.getResource(GRAMCLIENT_PROPERTY);
+
+				if (propertyFile != null) {
+					File tempFile = new File(propertyFile.getFile());
+					if (tempFile.exists()) {
+						webinfDir = tempFile.getParentFile().getParentFile();
+					}
+				} else {
+					throw new Exception(" Not able to locate " + GRAMCLIENT_PROPERTY);
+				}
+				InputStream propertyStream = classLoader.getResourceAsStream(GRAMCLIENT_PROPERTY);
+				properties = new Properties();
+				if (credentials == null) {
+					this.credentials = new MyProxyCredentials();
+				}
+				if (propertyStream != null) {
+					properties.load(propertyStream);
+					String myproxyServerTmp = properties.getProperty(ServiceConstants.MYPROXY_SERVER);
+					if (myproxyServerTmp != null) {
+						this.credentials.setMyproxyHostname(myproxyServerTmp.trim());
+					}
+					String myproxyPortTemp = properties.getProperty(ServiceConstants.MYPROXY_PORT);
+					if (myproxyPortTemp != null && myproxyPortTemp.trim().length() > 0) {
+						this.credentials.setMyproxyPortNumber(Integer.parseInt(myproxyPortTemp.trim()));
+					} else {
+						this.credentials.setMyproxyPortNumber(MyProxy.DEFAULT_PORT);
+					}
+					String myproxyuser = properties.getProperty(ServiceConstants.MYPROXY_USERNAME);
+					if (myproxyuser != null) {
+						this.credentials.setMyproxyUserName(myproxyuser);
+					}
+					String myproxypass = properties.getProperty(ServiceConstants.MYPROXY_PASSWD);
+					if (myproxypass != null) {
+						this.credentials.setMyproxyPassword(myproxypass);
+					}
+					String myproxytime = properties.getProperty(ServiceConstants.MYPROXY_LIFETIME);
+					if (myproxytime != null) {
+						this.credentials.setMyproxyLifeTime(Integer.parseInt(myproxytime));
+					}
+					this.credentials.setHostcertsKeyFile(properties.getProperty(ServiceConstants.HOSTCERTS_KEY_FILE));
+					this.credentials.setTrustedCertsFile(properties.getProperty(ServiceConstants.TRUSTED_CERTS_FILE));
+				}
+			}
+
+		} catch (Exception e) {
+			e.printStackTrace();
+			log.error(e.getLocalizedMessage());
+			throw new Exception(e);
+		}
+
+	}
+
+	/**
+	 * @return the properties
+	 */
+	public Properties getProperties() {
+		return properties;
+	}
+
+	/**
+	 * @param properties
+	 *            the properties to set
+	 */
+	public void setProperties(Properties properties) {
+		this.properties = properties;
+	}
+
+	/**
+	 * Returns the gssCredential.
+	 * 
+	 * @return The gssCredential
+	 */
+	public GSSCredential getGssCredential() {
+		return this.gssCredential;
+	}
+
+	/**
+	 * Sets gssCredential.
+	 * 
+	 * @param gssCredential
+	 *            The gssCredential to set.
+	 */
+	public void setGssCredential(GSSCredential gssCredential) {
+		this.gssCredential = gssCredential;
+	}
+
+	public MyProxyCredentials getCredentials() {
+		return credentials;
+	}
+
+	public void setCredentials(MyProxyCredentials credentials) {
+		this.credentials = credentials;
+	}
+}

Added: airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/context/CertificateManager.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/context/CertificateManager.java?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/context/CertificateManager.java (added)
+++ airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/context/CertificateManager.java Sat Nov 10 02:50:24 2012
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2009 Pervasive Lab, Indiana University. All rights reserved.
+ *
+ * This software is open source. See the bottom of this file for the license.
+ *
+ * $Id: $
+ */
+package org.apache.airavata.jobsubmission.context;
+
+import java.io.InputStream;
+import java.security.GeneralSecurityException;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.globus.gsi.CertUtil;
+import org.globus.util.ClassLoaderUtils;
+
+
+
+/**
+ * @author Raminderjeet Singh
+ */
+public class CertificateManager {
+
+  
+ 
+    private static X509Certificate[] trustedCertificates;
+
+    /**
+     * Load CA certificates from a file included in the XBaya jar.
+     * 
+     * @return The trusted certificates.
+     */
+    public static X509Certificate[] getTrustedCertificate(String certificate) {
+        if (trustedCertificates != null) {
+            return trustedCertificates;
+        }
+
+        List<X509Certificate> extremeTrustedCertificates = getTrustedCertificates(certificate);
+ 
+        List<X509Certificate> allTrustedCertificates = new ArrayList<X509Certificate>();
+        allTrustedCertificates.addAll(extremeTrustedCertificates);
+ 
+        trustedCertificates = allTrustedCertificates
+                .toArray(new X509Certificate[allTrustedCertificates.size()]);
+        return trustedCertificates;
+    }
+
+
+    private static List<X509Certificate> getTrustedCertificates(String pass) {
+    	//ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); //**
+    	//InputStream stream = classLoader.getResourceAsStream(pass); //**
+    	InputStream stream = ClassLoaderUtils.getResourceAsStream(pass); //**
+        if (stream == null) {
+            throw new RuntimeException("Failed to get InputStream to "
+                    + pass);
+        }
+        return readTrustedCertificates(stream);
+    }
+    
+    /**
+     * @param stream
+     * @return List of X509Certificate
+     */
+    public static List<X509Certificate> readTrustedCertificates(
+            InputStream stream) {
+        ArrayList<X509Certificate> certificates = new ArrayList<X509Certificate>();
+        while (true) {
+            X509Certificate certificate;
+            try {
+            	 certificate = CertUtil.loadCertificate(stream);
+//                certificate = CertificateLoadUtil.loadCertificate(stream); //**
+            }catch (GeneralSecurityException e) {
+                String message = "Certificates are invalid";
+                throw new RuntimeException(message, e);
+            }
+            if (certificate == null) {
+                break;
+            }
+            certificates.add(certificate);
+        }
+        return certificates;
+    }
+
+}
+

Propchange: airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/context/CertificateManager.java
------------------------------------------------------------------------------
    svn:executable = *

Added: airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/context/MyProxyCredentials.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/context/MyProxyCredentials.java?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/context/MyProxyCredentials.java (added)
+++ airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/context/MyProxyCredentials.java Sat Nov 10 02:50:24 2012
@@ -0,0 +1,305 @@
+/*
+ * Copyright (c) 2009 Pervasive Lab, Indiana University. All rights reserved.
+ *
+ * This software is open source. See the bottom of this file for the license.
+ *
+ * $Id: $
+ */
+package org.apache.airavata.jobsubmission.context;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.Serializable;
+import java.security.cert.X509Certificate;
+
+import org.apache.log4j.Logger;
+import org.globus.gsi.GlobusCredential;
+import org.globus.gsi.TrustedCertificates;
+import org.globus.gsi.gssapi.GlobusGSSCredentialImpl;
+import org.globus.myproxy.MyProxy;
+import org.ietf.jgss.GSSCredential;
+
+/**
+ * @author Raminderjeet Singh
+ */
+public class MyProxyCredentials implements Serializable {
+
+	private static final long serialVersionUID = -2471014486509046212L;
+	protected String myproxyHostname;
+	protected String myproxyUserName;
+	protected String myproxyPassword;
+	protected int myproxyPortNumber;
+	protected GSSCredential gssCredential;
+	protected String portalUserName;
+	private String hostcertsKeyFile;
+	private String trustedCertsFile;
+
+	protected int myproxyLifeTime = 14400;
+	final static int SECS_PER_MIN = 60;
+	final static int SECS_PER_HOUR = 3600;
+
+	private boolean initialized = false;
+	private boolean user = true;
+	protected X509Certificate[] trustedCertificates;
+
+	private static final Logger log = Logger.getLogger(MyProxyCredentials.class);
+
+	public MyProxyCredentials() {
+		// default constructor
+	}
+
+	public MyProxyCredentials(String myproxyServer, int myproxyPort, String myproxyUsername, String myproxyPassphrase, int myproxyLifetime) {
+		this.myproxyHostname = myproxyServer;
+		this.myproxyPortNumber = myproxyPort;
+		this.myproxyUserName = myproxyUsername;
+		this.myproxyPassword = myproxyPassphrase;
+		this.myproxyLifeTime = myproxyLifetime;
+
+	}
+
+	public GSSCredential getGssCredential() throws Exception {
+		FileInputStream fis = null;
+		try {
+			if (hostcertsKeyFile != null && !user) {
+				fis = new FileInputStream(hostcertsKeyFile);
+//				X509Credential globusCred = new X509Credential(fis); //**
+				GlobusCredential globusCred = new GlobusCredential(fis);
+				this.gssCredential = new GlobusGSSCredentialImpl(globusCred, GSSCredential.INITIATE_AND_ACCEPT);
+
+			} else {
+				this.gssCredential = getDefaultProxy();
+			}
+			if (gssCredential != null) {
+				return gssCredential;
+			}
+		} catch (Exception e) {
+			log.error("Failed to load proxy credential from ProxyManager");
+			e.printStackTrace();
+			throw e;
+		} finally {
+			if (fis != null) {
+				fis.close();
+			}
+		}
+
+		// then we will try the MyProxy
+		if (getMyproxyUserName() != null && getMyproxyPassword() != null) {
+			gssCredential = renewProxy();
+		}
+		return gssCredential;
+	}
+
+	public GSSCredential getDefaultProxy() throws Exception {
+		init();
+		MyProxy myproxy = new MyProxy(this.myproxyHostname, this.myproxyPortNumber);
+		log.info("USER=" + this.myproxyUserName + ",PASS=" + this.myproxyPassword + ",TIME=" + this.myproxyLifeTime);
+		return myproxy.get(this.myproxyUserName, this.myproxyPassword, this.myproxyLifeTime);
+	}
+
+	private void init() {
+		if (trustedCertsFile != null) {
+			if (new File(trustedCertsFile).isDirectory()) {
+				TrustedCertificates certificates = TrustedCertificates.load(trustedCertsFile);
+				TrustedCertificates.setDefaultTrustedCertificates(certificates);
+			} else {
+				this.trustedCertificates = CertificateManager.getTrustedCertificate(trustedCertsFile);
+
+				TrustedCertificates certificatesArray = new TrustedCertificates(this.trustedCertificates);
+				TrustedCertificates.setDefaultTrustedCertificates(certificatesArray);
+			}
+		}
+	}
+
+	public GSSCredential renewProxy() throws Exception {
+		init();
+
+		FileOutputStream fout = null;
+		try {
+			String proxyloc = null;
+			MyProxy myproxy = new MyProxy(myproxyHostname, myproxyPortNumber);
+			int lifeHours = myproxyLifeTime * SECS_PER_HOUR;
+			GSSCredential proxy = myproxy.get(myproxyUserName, myproxyPassword, lifeHours);
+
+			GlobusCredential globusCred = null; //**
+//			X509Credential globusCred = null; //**
+			if (proxy instanceof GlobusGSSCredentialImpl) {
+				globusCred = ((GlobusGSSCredentialImpl) proxy).getGlobusCredential();//** 
+//				globusCred = ((GlobusGSSCredentialImpl) proxy).getX509Credential();//**
+				log.info("got proxy from myproxy for " + myproxyUserName + " with " + myproxyLifeTime + " lifetime.");
+				String uid = myproxyUserName;
+				if (proxyloc == null) {
+					log.info("uid: " + uid);
+					proxyloc = "/tmp/x509up_u" + uid;
+				}
+				File proxyfile = new File(proxyloc);
+				log.info("proxy location: " + proxyfile.getAbsolutePath());
+				if (proxyfile.exists() == false) {
+					String dirpath = proxyloc.substring(0, proxyloc.lastIndexOf('/'));
+					File dir = new File(dirpath);
+					if (dir.exists() == false) {
+						dir.mkdirs();
+						log.info("new directory " + dirpath + " is created.");
+					}
+					proxyfile.createNewFile();
+					log.info("new proxy file " + proxyloc + " is created.");
+				}
+				fout = new FileOutputStream(proxyfile);
+				globusCred.save(fout);
+				String osName = System.getProperty("os.name");
+				if (!osName.contains("Windows")) {
+					Runtime.getRuntime().exec("/bin/chmod 600 " + proxyloc);
+				}
+				log.info("Proxy file renewed to " + proxyloc + " for the user " + myproxyUserName + " with " + myproxyLifeTime + " lifetime.");
+
+			}
+			return proxy;
+		} catch (Exception e) {
+			throw new Exception(e);
+		} finally {
+			if (fout != null) {
+				fout.close();
+			}
+		}
+	}
+
+	/**
+	 * @return the myproxyHostname
+	 */
+	public String getMyproxyHostname() {
+		return myproxyHostname;
+	}
+
+	/**
+	 * @param myproxyHostname
+	 *            the myproxyHostname to set
+	 */
+	public void setMyproxyHostname(String myproxyHostname) {
+		this.myproxyHostname = myproxyHostname;
+	}
+
+	/**
+	 * @return the myproxyUserName
+	 */
+	public String getMyproxyUserName() {
+		return myproxyUserName;
+	}
+
+	/**
+	 * @param myproxyUserName
+	 *            the myproxyUserName to set
+	 */
+	public void setMyproxyUserName(String myproxyUserName) {
+		this.myproxyUserName = myproxyUserName;
+	}
+
+	/**
+	 * @return the myproxyPassword
+	 */
+	public String getMyproxyPassword() {
+		return myproxyPassword;
+	}
+
+	/**
+	 * @param myproxyPassword
+	 *            the myproxyPassword to set
+	 */
+	public void setMyproxyPassword(String myproxyPassword) {
+		this.myproxyPassword = myproxyPassword;
+	}
+
+	/**
+	 * @return the myproxyLifeTime
+	 */
+	public int getMyproxyLifeTime() {
+		return myproxyLifeTime;
+	}
+
+	/**
+	 * @param myproxyLifeTime
+	 *            the myproxyLifeTime to set
+	 */
+	public void setMyproxyLifeTime(int myproxyLifeTime) {
+		this.myproxyLifeTime = myproxyLifeTime;
+	}
+
+	/**
+	 * @return the myproxyPortNumber
+	 */
+	public int getMyproxyPortNumber() {
+		return myproxyPortNumber;
+	}
+
+	/**
+	 * @param myproxyPortNumber
+	 *            the myproxyPortNumber to set
+	 */
+	public void setMyproxyPortNumber(int myproxyPortNumber) {
+		this.myproxyPortNumber = myproxyPortNumber;
+	}
+
+	/**
+	 * @return the portalUserName
+	 */
+	public String getPortalUserName() {
+		return portalUserName;
+	}
+
+	/**
+	 * @param portalUserName
+	 *            the portalUserName to set
+	 */
+	public void setPortalUserName(String portalUserName) {
+		this.portalUserName = portalUserName;
+	}
+
+	/**
+	 * Returns the initialized.
+	 * 
+	 * @return The initialized
+	 */
+	public boolean isInitialized() {
+		return this.initialized;
+	}
+
+	/**
+	 * Sets initialized.
+	 * 
+	 * @param initialized
+	 *            The initialized to set.
+	 */
+	public void setInitialized(boolean initialized) {
+		this.initialized = initialized;
+	}
+
+	/**
+	 * @param hostcertsKeyFile
+	 *            the hostcertsKeyFile to set
+	 */
+	public void setHostcertsKeyFile(String hostcertsKeyFile) {
+		this.hostcertsKeyFile = hostcertsKeyFile;
+	}
+
+	/**
+	 * @return the hostcertsKeyFile
+	 */
+	public String getHostcertsKeyFile() {
+		return hostcertsKeyFile;
+	}
+
+	/**
+	 * @param trustedCertsFile
+	 *            the trustedCertsFile to set
+	 */
+	public void setTrustedCertsFile(String trustedCertsFile) {
+		this.trustedCertsFile = trustedCertsFile;
+	}
+
+	/**
+	 * @return the trustedCertsFile
+	 */
+	public String getTrustedCertsFile() {
+		return trustedCertsFile;
+	}
+
+}

Added: airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/ExectionContext.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/ExectionContext.java?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/ExectionContext.java (added)
+++ airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/ExectionContext.java Sat Nov 10 02:50:24 2012
@@ -0,0 +1,439 @@
+package org.apache.airavata.jobsubmission.gram;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.apache.airavata.jobsubmission.utils.ServiceConstants;
+
+public class ExectionContext {
+
+	private String workingDir;
+	private String tmpDir;
+	private String stdOut;
+	private String stderr;
+	private String host;
+	private String executable;
+	private ArrayList<String[]> env;
+	private String inputDataDir;
+	private String outputDataDir;
+	private boolean parameterNamesNeeded = false;
+	private String stdIn;
+	private String stdoutStr;
+	private String stderrStr;
+	private String queue;
+	private Integer maxWallTime;
+	private Integer pcount;
+	private String projectName;
+	private Integer minMemory;
+	private Integer hostCount;
+	private String jobType;
+	private String arguments;
+	private String gridFTPServerSource;
+	private String sourcedataLocation;
+	private String gridFTPServerDest;
+	private String destdataLocation;
+	
+	
+
+	public static final String PROPERTY_FILE = "gramclient.properties";
+
+	public ExectionContext() throws IOException {
+		loadConfigration();
+	}
+
+	private void loadConfigration() throws IOException {
+		ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+		InputStream propertyStream = classLoader.getResourceAsStream(PROPERTY_FILE);
+
+		Properties properties = new Properties();
+		if (propertyStream != null) {
+			properties.load(propertyStream);
+			String gateway = properties.getProperty(ServiceConstants.GATEWAY);
+			String exec = properties.getProperty(ServiceConstants.EXECUTION);
+			String args = properties.getProperty(ServiceConstants.ARGUMENTS);
+			String queueName = properties.getProperty(ServiceConstants.QUEUE);
+			String pn = properties.getProperty(ServiceConstants.PROJECT_NUMBER);
+			String jt = properties.getProperty(ServiceConstants.JOB_TYPE);
+			String mwt = properties.getProperty(ServiceConstants.MAX_WALL_TIME);
+			String pc = properties.getProperty(ServiceConstants.PCOUNT);
+			String hc = properties.getProperty(ServiceConstants.HOSTCOUNT);
+			String gridFTPServerSource =  properties.getProperty(ServiceConstants.GRIDFTPSERVERSOURCE);
+			String gridFTPSourcePath =  properties.getProperty(ServiceConstants.GRIDFTPSOURCEPATH);
+			String gridFTPServerDest =  properties.getProperty(ServiceConstants.GRIDFTPSERVERDEST);
+			String gridFTPDestPath =  properties.getProperty(ServiceConstants.GRIDFTPDESTPATH);
+			if (gateway != null) {
+				this.host = gateway;
+			}
+			if (exec != null) {
+				this.executable = exec;
+			}
+			if (args != null) {
+				this.arguments = args;
+			}
+			if (queueName != null) {
+				this.queue = queueName;
+			}
+			if (pn != null) {
+				this.projectName = pn;
+			}
+			if (jt != null) {
+				this.jobType = jt;
+			}
+			if (mwt != null) {
+				try {
+					this.maxWallTime = Integer.parseInt(mwt);
+				} catch (NumberFormatException e) {
+					this.maxWallTime = 1;
+				}
+			}
+			if (pc != null) {
+				try {
+					this.pcount = Integer.parseInt(pc);
+				} catch (NumberFormatException e) {
+					this.pcount = 1;
+				}
+			}
+			if (hc != null) {
+				try {
+					this.hostCount = Integer.parseInt(hc);
+				} catch (NumberFormatException e) {
+					this.hostCount = 1;
+				}
+			}
+			if(gridFTPServerSource != null && !gridFTPServerSource.isEmpty()){
+				this.gridFTPServerSource = gridFTPServerSource;
+			}
+			if(gridFTPSourcePath != null && !gridFTPSourcePath.isEmpty()){
+				this.sourcedataLocation = gridFTPSourcePath;
+			}
+			if(gridFTPServerDest != null && !gridFTPServerDest.isEmpty()){
+				this.gridFTPServerDest = gridFTPServerDest;
+			}
+			if(gridFTPDestPath != null && !gridFTPDestPath.isEmpty()){
+				this.destdataLocation = gridFTPDestPath;
+			}
+			
+		}
+	}
+
+	/**
+	 * @return the workingDir
+	 */
+	public String getWorkingDir() {
+		return workingDir;
+	}
+
+	/**
+	 * @param workingDir
+	 *            the workingDir to set
+	 */
+	public void setWorkingDir(String workingDir) {
+		this.workingDir = workingDir;
+	}
+
+	/**
+	 * @return the tmpDir
+	 */
+	public String getTmpDir() {
+		return tmpDir;
+	}
+
+	/**
+	 * @param tmpDir
+	 *            the tmpDir to set
+	 */
+	public void setTmpDir(String tmpDir) {
+		this.tmpDir = tmpDir;
+	}
+
+	/**
+	 * @return the stdOut
+	 */
+	public String getStdOut() {
+		return stdOut;
+	}
+
+	/**
+	 * @param stdOut
+	 *            the stdOut to set
+	 */
+	public void setStdOut(String stdOut) {
+		this.stdOut = stdOut;
+	}
+
+	/**
+	 * @return the stderr
+	 */
+	public String getStderr() {
+		return stderr;
+	}
+
+	/**
+	 * @param stderr
+	 *            the stderr to set
+	 */
+	public void setStderr(String stderr) {
+		this.stderr = stderr;
+	}
+
+	/**
+	 * @return the host
+	 */
+	public String getHost() {
+		return host;
+	}
+
+	/**
+	 * @param host
+	 *            the host to set
+	 */
+	public void setHost(String host) {
+		this.host = host;
+	}
+
+	/**
+	 * @return the executable
+	 */
+	public String getExecutable() {
+		return executable;
+	}
+
+	/**
+	 * @param executable
+	 *            the executable to set
+	 */
+	public void setExecutable(String executable) {
+		this.executable = executable;
+	}
+
+	/**
+	 * @return the env
+	 */
+	public ArrayList<String[]> getEnv() {
+		return env;
+	}
+
+	/**
+	 * @param env
+	 *            the env to set
+	 */
+	public void setEnv(ArrayList<String[]> env) {
+		this.env = env;
+	}
+
+	/**
+	 * @return the inputDataDir
+	 */
+	public String getInputDataDir() {
+		return inputDataDir;
+	}
+
+	/**
+	 * @param inputDataDir
+	 *            the inputDataDir to set
+	 */
+	public void setInputDataDir(String inputDataDir) {
+		this.inputDataDir = inputDataDir;
+	}
+
+	/**
+	 * @return the outputDataDir
+	 */
+	public String getOutputDataDir() {
+		return outputDataDir;
+	}
+
+	/**
+	 * @param outputDataDir
+	 *            the outputDataDir to set
+	 */
+	public void setOutputDataDir(String outputDataDir) {
+		this.outputDataDir = outputDataDir;
+	}
+
+	/**
+	 * @return the parameterNamesNeeded
+	 */
+	public boolean isParameterNamesNeeded() {
+		return parameterNamesNeeded;
+	}
+
+	/**
+	 * @param parameterNamesNeeded
+	 *            the parameterNamesNeeded to set
+	 */
+	public void setParameterNamesNeeded(boolean parameterNamesNeeded) {
+		this.parameterNamesNeeded = parameterNamesNeeded;
+	}
+
+	/**
+	 * @return the stdIn
+	 */
+	public String getStdIn() {
+		return stdIn;
+	}
+
+	/**
+	 * @param stdIn
+	 *            the stdIn to set
+	 */
+	public void setStdIn(String stdIn) {
+		this.stdIn = stdIn;
+	}
+
+	/**
+	 * @return the stdoutStr
+	 */
+	public String getStdoutStr() {
+		return stdoutStr;
+	}
+
+	/**
+	 * @param stdoutStr
+	 *            the stdoutStr to set
+	 */
+	public void setStdoutStr(String stdoutStr) {
+		this.stdoutStr = stdoutStr;
+	}
+
+	/**
+	 * @return the stderrStr
+	 */
+	public String getStderrStr() {
+		return stderrStr;
+	}
+
+	/**
+	 * @param stderrStr
+	 *            the stderrStr to set
+	 */
+	public void setStderrStr(String stderrStr) {
+		this.stderrStr = stderrStr;
+	}
+
+	public void setQueue(String queue) {
+		this.queue = queue;
+	}
+
+	public String getQueue() {
+		return queue;
+	}
+
+	public void setMaxWallTime(Integer maxWallTime) {
+		this.maxWallTime = maxWallTime;
+	}
+
+	public Integer getMaxWallTime() {
+		return maxWallTime;
+	}
+
+	/**
+	 * @return the pcount
+	 */
+	public Integer getPcount() {
+		return pcount;
+	}
+
+	/**
+	 * @param pcount
+	 *            the pcount to set
+	 */
+	public void setPcount(Integer pcount) {
+		this.pcount = pcount;
+	}
+
+	/**
+	 * @return the projectName
+	 */
+	public String getProjectName() {
+		return projectName;
+	}
+
+	/**
+	 * @param projectName
+	 *            the projectName to set
+	 */
+	public void setProjectName(String projectName) {
+		this.projectName = projectName;
+	}
+
+	/**
+	 * @return the minMemory
+	 */
+	public Integer getMinMemory() {
+		return minMemory;
+	}
+
+	/**
+	 * @param minMemory
+	 *            the minMemory to set
+	 */
+	public void setMinMemory(Integer minMemory) {
+		this.minMemory = minMemory;
+	}
+
+	/**
+	 * @return the hostCount
+	 */
+	public Integer getHostCount() {
+		return hostCount;
+	}
+
+	/**
+	 * @param hostCount
+	 *            the hostCount to set
+	 */
+	public void setHostCount(Integer hostCount) {
+		this.hostCount = hostCount;
+	}
+
+	public void setJobType(String jobType) {
+		this.jobType = jobType;
+	}
+
+	public String getJobType() {
+		return jobType;
+	}
+
+	public void setArguments(String arguments) {
+		this.arguments = arguments;
+	}
+
+	public String getArguments() {
+		return arguments;
+	}
+
+	public String getGridFTPServerSource() {
+		return gridFTPServerSource;
+	}
+
+	public void setGridFTPServerSource(String gridFTPServerSource) {
+		this.gridFTPServerSource = gridFTPServerSource;
+	}
+
+	public String getSourcedataLocation() {
+		return sourcedataLocation;
+	}
+
+	public void setSourcedataLocation(String sourcedataLocation) {
+		this.sourcedataLocation = sourcedataLocation;
+	}
+
+	public String getGridFTPServerDest() {
+		return gridFTPServerDest;
+	}
+
+	public void setGridFTPServerDest(String gridFTPServerDest) {
+		this.gridFTPServerDest = gridFTPServerDest;
+	}
+
+	public String getDestdataLocation() {
+		return destdataLocation;
+	}
+
+	public void setDestdataLocation(String destdataLocation) {
+		this.destdataLocation = destdataLocation;
+	}
+}

Added: airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/FileTransfer.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/FileTransfer.java?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/FileTransfer.java (added)
+++ airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/FileTransfer.java Sat Nov 10 02:50:24 2012
@@ -0,0 +1,62 @@
+package org.apache.airavata.jobsubmission.gram;
+
+import java.net.URI;
+
+import org.apache.airavata.jobsubmission.context.ApplicationContext;
+import org.apache.airavata.jobsubmission.utils.GridFtp;
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.ietf.jgss.GSSCredential;
+
+public class FileTransfer {
+
+	public void makeDir(GSSCredential gssCred, URI destURI) throws Exception {
+		GridFtp ftp = new GridFtp();
+		ftp.makeDir(destURI, gssCred);
+	}
+
+	public void transferData(GSSCredential gssCred, URI srcURI, URI destURI) throws Exception {
+		GridFtp ftp = new GridFtp();
+		ftp.transfer(srcURI, destURI, gssCred, true);
+	}
+
+	public void transferData(GSSCredential gssCred, String sourceERP, String remoteSrcFile, String targetERP,
+			String remoteDestFile) throws Exception {
+		GridFtp ftp = new GridFtp();
+		URI srcURI = GridFtp.createGsiftpURI(sourceERP, remoteSrcFile);
+		URI destURI = GridFtp.createGsiftpURI(targetERP, remoteDestFile);
+		ftp.transfer(srcURI, destURI, gssCred, true);
+	}
+
+	public static void main(String[] args) {
+		try {
+			BasicConfigurator.configure();
+			Logger logger = Logger.getLogger("GridFTPClient");
+			Level lev = Level.toLevel("DEBUG");
+			logger.setLevel(lev);
+			ApplicationContext context = new ApplicationContext();
+			context.login();
+			ExectionContext contextExectionContext = new ExectionContext();
+			FileTransfer fileTransfer = new FileTransfer();
+
+			String sourceERP = contextExectionContext.getGridFTPServerSource();
+			String remoteSrcFile = contextExectionContext.getSourcedataLocation();
+			String targeterp = contextExectionContext.getGridFTPServerDest();
+			String remoteDestFile = contextExectionContext.getDestdataLocation();
+			URI srcURI = GridFtp.createGsiftpURI(sourceERP, remoteSrcFile);
+			URI destURI = GridFtp.createGsiftpURI(targeterp, remoteDestFile);
+			URI dirLocation = GridFtp.createGsiftpURI(targeterp,
+					remoteDestFile.substring(0, remoteDestFile.lastIndexOf("/")));
+			GSSCredential gssCredential = context.getGssCredential();
+			System.out.println(dirLocation);
+			fileTransfer.makeDir(gssCredential, dirLocation);
+			fileTransfer.transferData(gssCredential, srcURI, destURI);
+
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+
+	}
+}
\ No newline at end of file

Added: airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/GramJobSubmission.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/GramJobSubmission.java?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/GramJobSubmission.java (added)
+++ airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/GramJobSubmission.java Sat Nov 10 02:50:24 2012
@@ -0,0 +1,141 @@
+package org.apache.airavata.jobsubmission.gram;
+
+import org.apache.log4j.Logger;
+import org.globus.gram.GramAttributes;
+import org.globus.gram.GramException;
+import org.globus.gram.GramJob;
+import org.ietf.jgss.GSSCredential;
+import org.ietf.jgss.GSSException;
+
+public class GramJobSubmission {
+
+	private static final String MULTIPLE = "multiple";
+
+	private static final String MPI = "mpi";
+
+	private static final String SINGLE = "single";
+
+	private static final String CONDOR = "CONDOR";	
+
+	private static final Logger log = Logger.getLogger(GramJobSubmission.class);
+
+	public void executeJob(GSSCredential gssCred, ExectionContext appExecContext, StringBuffer buffer) throws Exception {
+
+		try{
+			log.setLevel(org.apache.log4j.Level.INFO);
+			String contact = appExecContext.getHost();
+			GramAttributes jobAttr = configureRemoteJob(appExecContext);
+			String rsl = jobAttr.toRSL();
+			GramJob job = new GramJob(rsl);
+			
+			log.info("RSL = " + rsl);
+			JobSubmissionListener listener = new JobSubmissionListener(job, buffer);
+			job.setCredentials(gssCred);
+			job.addListener(listener);
+			log.info("Request to contact:" + contact);			
+			job.request(contact);
+
+			log.info("JobID = " + job.getIDAsString());
+			
+			listener.waitFor();
+			job.removeListener(listener);
+		}catch(GramException ge){
+			ge.printStackTrace();
+			log.error(ge, ge.getCause());
+			buffer.append(System.currentTimeMillis()+ "#id#FAILED#" + ge.getMessage());
+		}catch(GSSException gss){
+			gss.printStackTrace();
+			log.error(gss, gss.getCause());
+			buffer.append(System.currentTimeMillis()+ "#id#FAILED#" + gss.getMessage());
+		}catch(Exception e){
+			e.printStackTrace();
+			log.error(e, e.getCause());
+			buffer.append(System.currentTimeMillis()+ "#id#FAILED#" + e.getMessage());
+		}		
+	}
+
+	protected GramAttributes configureRemoteJob(ExectionContext appExecContext) throws Exception {
+		GramAttributes jobAttr = new GramAttributes();
+		jobAttr.setExecutable(appExecContext.getExecutable());
+		if (appExecContext.getWorkingDir() != null) {
+			jobAttr.setDirectory(appExecContext.getWorkingDir());
+			jobAttr.setStdout(appExecContext.getStdOut());
+			jobAttr.setStderr(appExecContext.getStderr());
+		}
+		// The env here contains the env of the host and the application. i.e
+		// ArrayList<String[]> nv = appExecContext.getEnv();
+		//
+		// for (int i = 0; i < nv.size(); ++i) {
+		// String[] nvPair = (String[]) nv.get(i);
+		// jobAttr.addEnvVariable(nvPair[0], nvPair[1]);
+		// }
+
+		// jobAttr.addEnvVariable(GFacConstants.INPUT_DATA_DIR,
+		// appExecContext.getInputDataDir());
+		// jobAttr.addEnvVariable(GFacConstants.OUTPUT_DATA_DIR,
+		// appExecContext.getOutputDataDir());
+
+		if (appExecContext.getMaxWallTime() != null && appExecContext.getMaxWallTime() > 0) {
+			log.info("Setting max wall clock time to " + appExecContext.getMaxWallTime());
+			jobAttr.setMaxWallTime(appExecContext.getMaxWallTime());
+			jobAttr.set("proxy_timeout", "1");
+		}
+		if (appExecContext.getPcount() != null && appExecContext.getPcount() > 1) {
+			log.info("Setting number of procs to " + appExecContext.getPcount());
+			jobAttr.setNumProcs(appExecContext.getPcount());
+		}
+
+		if (appExecContext.getHostCount() != null && appExecContext.getHostCount() > 1) {
+			jobAttr.set("hostCount", String.valueOf(appExecContext.getHostCount()));
+		}
+
+		if (appExecContext.getProjectName() != null) {
+			log.info("Setting project to " + appExecContext.getProjectName());
+			jobAttr.setProject(appExecContext.getProjectName());
+		}
+
+		if (appExecContext.getQueue() != null) {
+			jobAttr.setQueue(appExecContext.getQueue());
+		}
+		if (appExecContext.getArguments() != null) {
+			jobAttr.set("arguments", appExecContext.getArguments());
+		}
+		String jobType = SINGLE;
+
+		if (appExecContext.getJobType() != null) {
+			jobType = appExecContext.getJobType();
+		}
+		if (jobType.equals(SINGLE)) {
+			log.info("Setting job type to single");
+			jobAttr.setJobType(GramAttributes.JOBTYPE_SINGLE);
+		} else if (jobType.equals(MPI)) {
+			log.info("Setting job type to mpi");
+			jobAttr.setJobType(GramAttributes.JOBTYPE_MPI);
+		} else if (jobType.equals(MULTIPLE)) {
+			log.info("Setting job type to multiple");
+			jobAttr.setJobType(GramAttributes.JOBTYPE_MULTIPLE);
+		} else if (jobType.equals(CONDOR)) {
+			log.info("Setting job type to condor");
+			jobAttr.setJobType(GramAttributes.JOBTYPE_CONDOR);
+		}
+
+		// Support to add the Additional RSL parameters
+		// RSLParmType[] rslParams = app.getRslparmArray();
+		// if (rslParams.length > 0) {
+		// for (RSLParmType rslType : rslParams) {
+		// log.info("Adding rsl param of [" + rslType.getName() + ","
+		// + rslType.getStringValue() + "]");
+		// if(rslType.getName()!= ""){
+		// jobAttr.set(rslType.getName(), rslType.getStringValue());
+		// }
+		// }
+		// }
+
+		// support urgency/SPRUCE case
+		// only add spruce rsl parameter if this host has a spruce jobmanager
+		// configured
+		// jobAttr.set("urgency", appExecContext.getLeadHeader().getUrgency());
+
+		return jobAttr;
+	}
+}

Added: airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/JobSubmissionListener.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/JobSubmissionListener.java?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/JobSubmissionListener.java (added)
+++ airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/JobSubmissionListener.java Sat Nov 10 02:50:24 2012
@@ -0,0 +1,91 @@
+package org.apache.airavata.jobsubmission.gram;
+
+import org.apache.log4j.Logger;
+import org.globus.gram.GramJob;
+import org.globus.gram.GramJobListener;
+
+public class JobSubmissionListener implements GramJobListener {
+
+	private static final String DELIMITER = "#";
+	private boolean finished;
+	private int error;
+	private int status;
+	private StringBuffer buffer;
+
+	private GramJob job;
+
+	private static final Logger log = Logger.getLogger(JobSubmissionListener.class);
+
+	public JobSubmissionListener(GramJob job, StringBuffer buffer) {
+		this.buffer = buffer;
+		this.job = job;
+	}
+
+	// waits for DONE or FAILED status
+	public void waitFor() throws InterruptedException {
+		while (!finished) {
+			
+			// job status is changed but method isn't invoked
+			if (status != 0) {
+				if (job.getStatus() != status) {
+					log.info("invoke method manually");
+					statusChanged(job);
+				} else {
+					log.info("job " + job.getIDAsString() + " have same status: " + GramJob.getStatusAsString(status));
+				}
+			} else {
+				log.info("Status is zero");
+			}
+			
+			synchronized (this) {
+				wait(60 * 1000l);
+			}			
+		}
+	}
+
+	public synchronized void statusChanged(GramJob job) {
+		log.debug("Listener: statusChanged triggered");
+		int jobStatus = job.getStatus();
+		String jobId = job.getIDAsString();
+		String statusString = job.getStatusAsString();
+		log.info("Job Status: " + statusString + "(" + jobStatus + ")");
+		buffer.append(formatJobStatus(jobId, statusString));
+		log.debug(formatJobStatus(jobId, statusString));
+
+		status = jobStatus;
+		if (jobStatus == GramJob.STATUS_DONE) {
+			finished = true;
+		} else if (jobStatus == GramJob.STATUS_FAILED) {
+			finished = true;
+			error = job.getError();
+			log.info("Job Error Code: " + error);
+			buffer.append(DELIMITER + error);
+		}
+		buffer.append("\n");
+
+		// notify wait thread to wake up if done		
+		if (finished) {
+			notify();
+		}
+	}
+
+	public static String formatJobStatus(String jobid, String jobstatus) {
+		return System.currentTimeMillis() + DELIMITER + jobid + DELIMITER + jobstatus;
+	}
+
+	public int getError() {
+		return error;
+	}
+
+	public int getStatus() {
+		return status;
+	}
+
+	public void wakeup() {
+		try {
+			notify();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+}

Added: airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/JobSubmittionListener.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/JobSubmittionListener.java?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/JobSubmittionListener.java (added)
+++ airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/JobSubmittionListener.java Sat Nov 10 02:50:24 2012
@@ -0,0 +1,91 @@
+package org.apache.airavata.jobsubmission.gram;
+
+import org.apache.log4j.Logger;
+import org.globus.gram.GramJob;
+import org.globus.gram.GramJobListener;
+
+public class JobSubmittionListener implements GramJobListener {
+
+	private static final String DELIMITER = "#";
+	private boolean finished;
+	private int error;
+	private int status;
+	private StringBuffer buffer;
+
+	private GramJob job;
+
+	private static final Logger log = Logger.getLogger(JobSubmittionListener.class);
+
+	public JobSubmittionListener(GramJob job, StringBuffer buffer) {
+		this.buffer = buffer;
+		this.job = job;
+	}
+
+	// waits for DONE or FAILED status
+	public void waitFor() throws InterruptedException {
+		while (!finished) {
+			
+			// job status is changed but method isn't invoked
+			if (status != 0) {
+				if (job.getStatus() != status) {
+					log.info("invoke method manually");
+					statusChanged(job);
+				} else {
+					log.info("job " + job.getIDAsString() + " have same status: " + GramJob.getStatusAsString(status));
+				}
+			} else {
+				log.info("Status is zero");
+			}
+			
+			synchronized (this) {
+				wait(60 * 1000l);
+			}			
+		}
+	}
+
+	public synchronized void statusChanged(GramJob job) {
+		log.debug("Listener: statusChanged triggered");
+		int jobStatus = job.getStatus();
+		String jobId = job.getIDAsString();
+		String statusString = job.getStatusAsString();
+		log.info("Job Status: " + statusString + "(" + jobStatus + ")");
+		buffer.append(formatJobStatus(jobId, statusString));
+		log.debug(formatJobStatus(jobId, statusString));
+
+		status = jobStatus;
+		if (jobStatus == GramJob.STATUS_DONE) {
+			finished = true;
+		} else if (jobStatus == GramJob.STATUS_FAILED) {
+			finished = true;
+			error = job.getError();
+			log.info("Job Error Code: " + error);
+			buffer.append(DELIMITER + error);
+		}
+		buffer.append("\n");
+
+		// notify wait thread to wake up if done		
+		if (finished) {
+			notify();
+		}
+	}
+
+	public static String formatJobStatus(String jobid, String jobstatus) {
+		return System.currentTimeMillis() + DELIMITER + jobid + DELIMITER + jobstatus;
+	}
+
+	public int getError() {
+		return error;
+	}
+
+	public int getStatus() {
+		return status;
+	}
+
+	public void wakeup() {
+		try {
+			notify();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+}

Added: airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/utils/GridFTPContactInfo.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/utils/GridFTPContactInfo.java?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/utils/GridFTPContactInfo.java (added)
+++ airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/utils/GridFTPContactInfo.java Sat Nov 10 02:50:24 2012
@@ -0,0 +1,63 @@
+/*
+ *
+ * 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.jobsubmission.utils;
+
+
+
+/**
+ * Class represents GridFTP Endpoint
+ * 
+ */
+public class GridFTPContactInfo {
+	 public static final int DEFAULT_GSI_FTP_PORT = 2811;
+    public String hostName;
+    public int port;
+
+    public GridFTPContactInfo(String hostName, int port) {
+        if (port <= 0 || port == 80) {
+            port = DEFAULT_GSI_FTP_PORT;
+        }
+        this.hostName = hostName;
+        this.port = port;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof GridFTPContactInfo) {
+            return hostName.equals(((GridFTPContactInfo) obj).hostName) && port == ((GridFTPContactInfo) obj).port;
+        } else {
+            return false;
+        }
+    }
+
+    @Override
+    public int hashCode() {
+        return hostName.hashCode();
+    }
+
+    @Override
+    public String toString() {
+        StringBuffer buf = new StringBuffer();
+        buf.append(hostName).append(":").append(port);
+        return buf.toString();
+    }
+}

Added: airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/utils/GridFtp.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/utils/GridFtp.java?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/utils/GridFtp.java (added)
+++ airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/utils/GridFtp.java Sat Nov 10 02:50:24 2012
@@ -0,0 +1,394 @@
+/*
+ *
+ * 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.jobsubmission.utils;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.log4j.Logger;
+import org.globus.ftp.DataChannelAuthentication;
+import org.globus.ftp.DataSourceStream;
+import org.globus.ftp.GridFTPClient;
+import org.globus.ftp.HostPort;
+import org.globus.ftp.Marker;
+import org.globus.ftp.MarkerListener;
+import org.globus.ftp.Session;
+import org.globus.ftp.exception.ClientException;
+import org.globus.ftp.exception.ServerException;
+import org.globus.gsi.gssapi.auth.HostAuthorization;
+import org.ietf.jgss.GSSCredential;
+
+
+/**
+ * GridFTP tools
+ */
+public class GridFtp {
+
+      public static final String GSIFTP_SCHEME = "gsiftp";
+      private static final Logger log = Logger.getLogger(GridFtp.class);
+
+    /**
+     * Make directory at remote location
+     * 
+     * @param destURI
+     * @param gssCred
+     * @throws ServerException
+     * @throws IOException
+     */
+    public void makeDir(URI destURI, GSSCredential gssCred) throws Exception {
+        GridFTPClient destClient = null;
+        GridFTPContactInfo destHost = new GridFTPContactInfo(destURI.getHost(), destURI.getPort());
+        try {
+
+            String destPath = destURI.getPath();
+            log.info(("Creating Directory = " + destHost + "=" + destPath));
+
+            destClient = new GridFTPClient(destHost.hostName, destHost.port);
+
+            int tryCount = 0;
+            while (true) {
+                try {
+                    destClient.setAuthorization(new HostAuthorization("host"));
+                    destClient.authenticate(gssCred);
+                    destClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+
+                    if (!destClient.exists(destPath)) {
+                        destClient.makeDir(destPath);
+                    }
+                    break;
+                } catch (ServerException e) {
+                    tryCount++;
+                    if (tryCount >= 3) {
+                        throw new Exception(e.getMessage(), e);
+                    }
+                    Thread.sleep(10000);
+                } catch (IOException e) {
+                    tryCount++;
+                    if (tryCount >= 3) {
+                        throw new Exception(e.getMessage(), e);
+                    }
+                    Thread.sleep(10000);
+                }
+            }
+        } catch (ServerException e) {
+            throw new Exception("Cannot Create GridFTP Client to:" + destHost.toString(), e);
+        } catch (IOException e) {
+            throw new Exception("Cannot Create GridFTP Client to:" + destHost.toString(), e);
+        } catch (InterruptedException e) {
+            throw new Exception("Internal Error cannot sleep", e);
+        } finally {
+            if (destClient != null) {
+                try {
+                    destClient.close();
+                } catch (Exception e) {
+                    log.info("Cannot close GridFTP client connection");
+                }
+            }
+        }
+    }
+
+    /**
+     * Upload file from stream
+     * 
+     * @param destURI
+     * @param gsCredential
+     * @param localFile
+     * @throws GfacException
+     */
+    public void updateFile(URI destURI, GSSCredential gsCredential, InputStream io) throws Exception {
+        GridFTPClient ftpClient = null;
+        GridFTPContactInfo contactInfo = new GridFTPContactInfo(destURI.getHost(), destURI.getPort());
+
+        try {
+
+            String remoteFile = destURI.getPath();
+            log.info("The remote file is " + remoteFile);
+
+            log.info("Setup GridFTP Client");
+
+            ftpClient = new GridFTPClient(contactInfo.hostName, contactInfo.port);
+            ftpClient.setAuthorization(new HostAuthorization("host"));
+            ftpClient.authenticate(gsCredential);
+            ftpClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+
+            log.info("Uploading file");
+
+            ftpClient.put(remoteFile, new DataSourceStream(io), new MarkerListener() {
+                public void markerArrived(Marker marker) {
+                }
+            });
+
+            log.info("Upload file to:" + remoteFile + " is done");
+
+        } catch (ServerException e) {
+            throw new Exception("Cannot upload file to GridFTP:" + contactInfo.toString(), e);
+        } catch (IOException e) {
+            throw new Exception("Cannot upload file to GridFTP:" + contactInfo.toString(), e);
+        } catch (ClientException e) {
+            throw new Exception("Cannot upload file to GridFTP:" + contactInfo.toString(), e);
+        } finally {
+            if (ftpClient != null) {
+                try {
+                    ftpClient.close();
+                } catch (Exception e) {
+                	log.info("Cannot close GridFTP client connection");
+                }
+            }
+        }
+    }
+
+    /**
+     * Upload file to remote location
+     * 
+     * @param destURI
+     * @param gsCredential
+     * @param localFile
+     * @throws GfacException
+     */
+    public void updateFile(URI destURI, GSSCredential gsCredential, File localFile) throws Exception {
+        GridFTPClient ftpClient = null;
+        GridFTPContactInfo contactInfo = new GridFTPContactInfo(destURI.getHost(), destURI.getPort());
+        try {
+
+            String remoteFile = destURI.getPath();
+
+            log.info("The local temp file is " + localFile);
+            log.info("the remote file is " + remoteFile);
+
+            log.info("Setup GridFTP Client");
+
+            ftpClient = new GridFTPClient(contactInfo.hostName, contactInfo.port);
+            ftpClient.setAuthorization(new HostAuthorization("host"));
+            ftpClient.authenticate(gsCredential);
+            ftpClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+
+            log.info("Uploading file");
+
+            ftpClient.put(localFile, remoteFile, false);
+
+            log.info("Upload file to:" + remoteFile + " is done");
+
+        } catch (ServerException e) {
+            throw new Exception("Cannot upload file to GridFTP:" + contactInfo.toString(), e);
+        } catch (IOException e) {
+            throw new Exception("Cannot upload file to GridFTP:" + contactInfo.toString(), e);
+        } catch (ClientException e) {
+            throw new Exception("Cannot upload file to GridFTP:" + contactInfo.toString(), e);
+        } finally {
+            if (ftpClient != null) {
+                try {
+                    ftpClient.close();
+                } catch (Exception e) {
+                	log.info("Cannot close GridFTP client connection");
+                }
+            }
+        }
+    }
+
+    /**
+     * Download File from remote location
+     * 
+     * @param destURI
+     * @param gsCredential
+     * @param localFile
+     * @throws GfacException
+     */
+    public void downloadFile(URI destURI, GSSCredential gsCredential, File localFile) throws Exception {
+        GridFTPClient ftpClient = null;
+        GridFTPContactInfo contactInfo = new GridFTPContactInfo(destURI.getHost(), destURI.getPort());
+        try {
+            String remoteFile = destURI.getPath();
+
+            log.info("The local temp file is " + localFile);
+            log.info("the remote file is " + remoteFile);
+
+            log.info("Setup GridFTP Client");
+
+            ftpClient = new GridFTPClient(contactInfo.hostName, contactInfo.port);
+            ftpClient.setAuthorization(new HostAuthorization("host"));
+            ftpClient.authenticate(gsCredential);
+            ftpClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+
+            log.info("Downloading file");
+
+            ftpClient.get(remoteFile, localFile);
+
+            log.info("Download file to:" + remoteFile + " is done");
+
+        } catch (ServerException e) {
+            throw new Exception("Cannot download file from GridFTP:" + contactInfo.toString(), e);
+        } catch (IOException e) {
+            throw new Exception("Cannot download file from GridFTP:" + contactInfo.toString(), e);
+        } catch (ClientException e) {
+            throw new Exception("Cannot download file from GridFTP:" + contactInfo.toString(), e);
+        } finally {
+            if (ftpClient != null) {
+                try {
+                    ftpClient.close();
+                } catch (Exception e) {
+                    log.info("Cannot close GridFTP client connection");
+                }
+            }
+        }
+    }
+
+    /**
+     * Stream remote file
+     * 
+     * @param destURI
+     * @param gsCredential
+     * @param localFile
+     * @return
+     * @throws GfacException
+     */
+    public String readRemoteFile(URI destURI, GSSCredential gsCredential, File localFile) throws Exception {
+        BufferedReader instream = null;
+        File localTempfile = null;
+        try {
+
+            if (localFile == null) {
+                localTempfile = File.createTempFile("stderr", "err");
+            } else {
+                localTempfile = localFile;
+            }
+
+            log.info("Loca temporary file:" + localTempfile);
+
+            downloadFile(destURI, gsCredential, localTempfile);
+
+            instream = new BufferedReader(new FileReader(localTempfile));
+            StringBuffer buff = new StringBuffer();
+            String temp = null;
+            while ((temp = instream.readLine()) != null) {
+                buff.append(temp);
+                buff.append(System.getProperty("line.separator"));
+            }
+
+            log.info("finish read file:" + localTempfile);
+
+            return buff.toString();
+        } catch (FileNotFoundException e) {
+            throw new Exception("Cannot read localfile file:" + localTempfile, e);
+        } catch (IOException e) {
+            throw new Exception("Cannot read localfile file:" + localTempfile, e);
+        } finally {
+            if (instream != null) {
+                try {
+                    instream.close();
+                } catch (Exception e) {
+                    log.info("Cannot close GridFTP client connection");
+                }
+            }
+        }
+    }
+
+    /**
+     * Transfer data from one GridFTp Endpoint to another GridFTP Endpoint
+     * 
+     * @param srchost
+     * @param desthost
+     * @param gssCred
+     * @param srcActive
+     * @throws ServerException
+     * @throws ClientException
+     * @throws IOException
+     */
+    public void transfer(URI srchost, URI desthost, GSSCredential gssCred, boolean srcActive) throws Exception {
+        GridFTPClient destClient = null;
+        GridFTPClient srcClient = null;
+
+        try {
+            destClient = new GridFTPClient(desthost.getHost(), desthost.getPort());
+            destClient.setAuthorization(new HostAuthorization("host"));
+            destClient.authenticate(gssCred);
+            destClient.setType(Session.TYPE_IMAGE);
+
+            srcClient = new GridFTPClient(srchost.getHost(), srchost.getPort());
+            srcClient.setAuthorization(new HostAuthorization("host"));
+            srcClient.authenticate(gssCred);
+            srcClient.setType(Session.TYPE_IMAGE);
+
+            if (srcActive) {
+                log.info("Set src active");
+                HostPort hp = destClient.setPassive();
+                srcClient.setActive(hp);
+            } else {
+                log.info("Set dst active");
+                HostPort hp = srcClient.setPassive();
+                destClient.setActive(hp);
+            }
+
+            log.info("Start transfer file from GridFTP:" + srchost.toString() + " to " + desthost.toString());
+
+            /**
+             * Transfer a file. The transfer() function blocks until the transfer is complete.
+             */
+            srcClient.transfer(srchost.getPath(), destClient, desthost.getPath(), false, null);
+            if (srcClient.getSize(srchost.getPath()) == destClient.getSize(desthost.getPath())) {
+                log.info("CHECK SUM OK");
+            } else {
+                log.info("****CHECK SUM FAILED****");
+            }
+
+        } catch (ServerException e) {
+            throw new Exception("Cannot transfer file from GridFTP:" + srchost.toString() + " to "
+                    + desthost.toString(), e);
+        } catch (IOException e) {
+            throw new Exception("Cannot transfer file from GridFTP:" + srchost.toString() + " to "
+                    + desthost.toString(), e);
+        } catch (ClientException e) {
+            throw new Exception("Cannot transfer file from GridFTP:" + srchost.toString() + " to "
+                    + desthost.toString(), e);
+        } finally {
+            if (destClient != null) {
+                try {
+                    destClient.close();
+                } catch (Exception e) {
+                    log.info("Cannot close GridFTP client connection at Desitnation:" + desthost.toString());
+                }
+            }
+            if (srcClient != null) {
+                try {
+                    srcClient.close();
+                } catch (Exception e) {
+                    log.info("Cannot close GridFTP client connection at Source:" + srchost.toString());
+                }
+            }
+        }
+    }
+    public static URI createGsiftpURI(String host, String localPath) throws URISyntaxException {
+        StringBuffer buf = new StringBuffer();
+        if (!host.startsWith("gsiftp://"))
+            buf.append("gsiftp://");
+        buf.append(host);
+        if (!host.endsWith("/"))
+            buf.append("/");
+        buf.append(localPath);
+        return new URI(buf.toString());
+    }
+}

Added: airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/utils/ServiceConstants.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/utils/ServiceConstants.java?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/utils/ServiceConstants.java (added)
+++ airavata/sandbox/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/utils/ServiceConstants.java Sat Nov 10 02:50:24 2012
@@ -0,0 +1,28 @@
+package org.apache.airavata.jobsubmission.utils;
+
+public class ServiceConstants {
+
+	public static final String MYPROXY_SERVER = "myproxyServer";
+	public static final String MYPROXY_PORT = "myproxyPort";
+	public static final String MYPROXY_LIFETIME = "myproxy_lifetime";
+	public static final String MYPROXY_USERNAME = "myproxyUserName";
+	public static final String MYPROXY_PASSWD = "myproxyPasswd";
+	public static final String TRUSTED_CERTS_FILE = "trustedCertsFile";
+	public static final String HOSTCERTS_KEY_FILE = "hostcertsKeyFile";
+
+	public static final String GATEWAY = "gateway";
+	public static final String EXECUTION = "execution";
+	public static final String ARGUMENTS = "arguments";
+	public static final String QUEUE = "queue";
+	public static final String PROJECT_NUMBER = "project_number";
+	public static final String MAX_WALL_TIME = "maxwalltime";
+	public static final String JOB_TYPE = "jobtype";
+	public static final String PCOUNT = "processors";
+	public static final String HOSTCOUNT = "hosts";
+	
+	public static final String GRIDFTPSERVERSOURCE = "gridftpserverSource";
+	public static final String GRIDFTPSOURCEPATH = "gridftpSourcePath";
+	public static final String GRIDFTPSERVERDEST = "gridftpserverDest";
+	public static final String GRIDFTPDESTPATH = "gridftpDestPath";
+
+}

Added: airavata/sandbox/grid-tools/gram-client/testFileTransfer.sh
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gram-client/testFileTransfer.sh?rev=1407721&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gram-client/testFileTransfer.sh (added)
+++ airavata/sandbox/grid-tools/gram-client/testFileTransfer.sh Sat Nov 10 02:50:24 2012
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+for i in target/lib/*.jar
+do
+  CLASSPATH=$CLASSPATH:$i
+done
+
+CLASSPATH=$CLASSPATH:target/GRAM5-Lite-1.0.jar:./config
+
+echo $CLASSPATH
+
+$JAVA_HOME/bin/java -classpath $CLASSPATH org.apache.airavata.jobsubmission.gram.FileTransfer $*