Adding gram functionality changes for jglobus 2
authoramilaj <amilaj@unknown>
Thu, 20 Jun 2013 03:14:27 +0000 (03:14 +0000)
committeramilaj <amilaj@unknown>
Thu, 20 Jun 2013 03:14:27 +0000 (03:14 +0000)
git-svn-id: https://svn.apache.org/repos/asf/airavata/sandbox@1494843 13f79535-47bb-0310-9956-ffa450edef68

28 files changed:
grid-tools/gram-client/pom.xml
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/CancelJob.java [deleted file]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobListener.java [deleted file]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobStatus.java [deleted file]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobSubmission.java [deleted file]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/ExecutionContext.java [moved from grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/ExectionContext.java with 84% similarity]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/GFacException.java [new file with mode: 0644]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/GramJobSubmissionManager.java [new file with mode: 0644]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/JobSubmissionListener.java
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/ListenerQueue.java [new file with mode: 0644]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/RSLGenerator.java [moved from grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/GramJobSubmission.java with 61% similarity]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/errors.properties [new file with mode: 0644]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/notifier/GramJobLogger.java [new file with mode: 0644]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/notifier/GramJobNotifier.java [new file with mode: 0644]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/persistence/DBJobPersistenceManager.java [new file with mode: 0644]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/persistence/JobData.java [new file with mode: 0644]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/persistence/JobPersistenceManager.java [new file with mode: 0644]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/persistence/PersistenceGramJobNotifier.java [new file with mode: 0644]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/security/CertificateManager.java [deleted file]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/security/MyProxyCredentials.java [deleted file]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/security/SecurityContext.java [deleted file]
grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/utils/ServiceConstants.java
grid-tools/gram-client/src/main/resources/airavata-gram-client.properties
grid-tools/gram-client/src/test/java/org/apache/airavata/jobsubmission/gram/GramJobSubmissionManagerTest.java [new file with mode: 0644]
grid-tools/gram-client/src/test/java/org/apache/airavata/jobsubmission/gram/LoneStarGramTest.java [new file with mode: 0644]
grid-tools/gram-client/src/test/java/org/apache/airavata/jobsubmission/gram/StampedeGramTest.java [new file with mode: 0644]
grid-tools/gram-client/src/test/java/org/apache/airavata/jobsubmission/gram/TrestlesGramTest.java [new file with mode: 0644]
grid-tools/gram-client/src/test/resources/airavata-myproxy-client.properties [new file with mode: 0644]

index da5626f..f08a262 100644 (file)
        language governing permissions and limitations under the License. -->
 
 <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>
-               </plugins>
-       </build>
+         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>org.apache.airavata</groupId>
+            <artifactId>airavata-myproxy-client</artifactId>
+            <version>0.1-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.jglobus</groupId>
+            <artifactId>gss</artifactId>
+            <version>2.0.6-rc2</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.jglobus</groupId>
+            <artifactId>gram</artifactId>
+            <version>2.0.6-rc2</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>
+
+        <dependency>
+            <groupId>org.apache.derby</groupId>
+            <artifactId>derby</artifactId>
+            <version>${derby.version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-log4j12</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>log4j</groupId>
+                    <artifactId>log4j</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.derby</groupId>
+            <artifactId>derbyclient</artifactId>
+            <version>${derby.version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-log4j12</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>log4j</groupId>
+                    <artifactId>log4j</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.derby</groupId>
+            <artifactId>derbynet</artifactId>
+            <version>${derby.version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-log4j12</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>log4j</groupId>
+                    <artifactId>log4j</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.derby</groupId>
+            <artifactId>derbytools</artifactId>
+            <version>${derby.version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-log4j12</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>log4j</groupId>
+                    <artifactId>log4j</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.airavata</groupId>
+            <artifactId>airavata-common-utils</artifactId>
+            <version>0.8-SNAPSHOT</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-log4j12</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>log4j</groupId>
+                    <artifactId>log4j</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>commons-dbcp</groupId>
+            <artifactId>commons-dbcp</artifactId>
+            <version>1.4</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-log4j12</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>log4j</groupId>
+                    <artifactId>log4j</artifactId>
+                </exclusion>
+            </exclusions>
+        </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-surefire-plugin</artifactId>
+                <version>${surefire.version}</version>
+                <configuration>
+                    <failIfNoTests>false</failIfNoTests>
+                    <skipTests>${skipTests}</skipTests>
+                    <workingDirectory>${project.build.testOutputDirectory}</workingDirectory>
+                    <systemPropertyVariables>
+                        <projectDirectory>${basedir}</projectDirectory>
+                    </systemPropertyVariables>
+
+                </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>
+        </plugins>
+    </build>
+
+    <properties>
+        <surefire.version>2.12</surefire.version>
+        <junit.version>4.7</junit.version>
+        <derby.version>10.9.1.0</derby.version>
+        <skipTests>false</skipTests>
+    </properties>
 
 </project>
 
diff --git a/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/CancelJob.java b/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/CancelJob.java
deleted file mode 100644 (file)
index bdfea5a..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- *
- * 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;
-
-import org.apache.airavata.jobsubmission.gram.ExectionContext;
-import org.apache.airavata.jobsubmission.security.SecurityContext;
-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 {
-               SecurityContext context = new SecurityContext();
-               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();
-       }
-}
-}
diff --git a/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobListener.java b/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobListener.java
deleted file mode 100644 (file)
index 938feed..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- *
- * 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;
-
-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
diff --git a/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobStatus.java b/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobStatus.java
deleted file mode 100644 (file)
index 40a2d96..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- *
- * 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;
-
-import org.apache.airavata.jobsubmission.security.SecurityContext;
-import org.globus.gram.GramJob;
-
-public class JobStatus {
-
-    /**
-     * @param args
-     */
-    public static void main(String[] args) {
-        try {
-            SecurityContext context = new SecurityContext();
-            context.login();
-
-            String rsl = "";
-            GramJob job = new GramJob(context.getGssCredential(), rsl);
-            job.setID("https://trestles-login2.sdsc.edu:50385/16289849894573229156/9412551328091080577/");
-            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();
-        }
-
-    }
-
-}
diff --git a/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobSubmission.java b/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/JobSubmission.java
deleted file mode 100644 (file)
index d6f8e22..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- *
- * 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;
-
-import org.apache.airavata.jobsubmission.gram.ExectionContext;
-import org.apache.airavata.jobsubmission.gram.GramJobSubmission;
-import org.apache.airavata.jobsubmission.security.SecurityContext;
-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 SecurityContext context;
-    private static String newline = System.getProperty("line.separator");
-
-    public static synchronized SecurityContext getContext() throws Exception {
-        if (context == null) {
-            context = new SecurityContext();
-            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 {
-            SecurityContext context = new SecurityContext();
-            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);
-    }
-}
@@ -24,16 +24,19 @@ package org.apache.airavata.jobsubmission.gram;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 import java.util.Properties;
 
+import org.apache.airavata.jobsubmission.gram.notifier.GramJobNotifier;
 import org.apache.airavata.jobsubmission.utils.ServiceConstants;
 
-public class ExectionContext {
+public class ExecutionContext {
 
     private String testingHost;
     
     private String lonestarGRAM;
-    private String rangerGRAM;
+    private String stampedeGRAM;
     private String trestlesGRAM;
     
     private String workingDir;
@@ -58,9 +61,16 @@ public class ExectionContext {
     private String jobType;
     private String arguments;
 
+    private boolean interactive;
+
+    private String userName;
+    private String password;
+
+    private List<GramJobNotifier> gramJobNotifierList = new ArrayList<GramJobNotifier>();
+
     public static final String PROPERTY_FILE = "airavata-gram-client.properties";
 
-    public ExectionContext() throws IOException {
+    public ExecutionContext() throws IOException {
         loadConfigration();
     }
 
@@ -75,7 +85,7 @@ public class ExectionContext {
             String testinghost = properties.getProperty(ServiceConstants.TESTINGHOST);
             
             String lonestargram = properties.getProperty(ServiceConstants.LONESTARGRAMEPR);
-            String rangergram = properties.getProperty(ServiceConstants.RANGERGRAMEPR);
+            String stampedeGram = properties.getProperty(ServiceConstants.STAMPEDE_GRAM_EPR);
             String trestlesgram = properties.getProperty(ServiceConstants.TRESTLESGRAMEPR);
 
             String exec = properties.getProperty(ServiceConstants.EXECUTABLE);
@@ -94,8 +104,8 @@ public class ExectionContext {
             if (lonestargram != null) {
                 this.lonestarGRAM = lonestargram;
             }
-            if (rangergram != null) {
-                this.rangerGRAM = rangergram;
+            if (stampedeGram != null) {
+                this.stampedeGRAM = stampedeGram;
             }
             if (trestlesgram != null) {
                 this.trestlesGRAM = trestlesgram;
@@ -157,18 +167,32 @@ public class ExectionContext {
         this.lonestarGRAM = lonestarGRAM;
     }
 
-    public String getRangerGRAM() {
-        return rangerGRAM;
+    public String getStampedeGRAM() {
+        return stampedeGRAM;
     }
 
-    public void setRangerGRAM(String rangerGRAM) {
-        this.rangerGRAM = rangerGRAM;
+    public void setStampedeGRAM(String stampedeGRAM) {
+        this.stampedeGRAM = stampedeGRAM;
     }
 
     public String getTrestlesGRAM() {
         return trestlesGRAM;
     }
 
+    public String getGRAMEndPoint() {
+
+        if (this.getHost().equals("trestles")) {
+            return this.getTrestlesGRAM();
+        } else if (this.getHost().equals("stampede")) {
+            return this.getStampedeGRAM();
+        } else if (this.getHost().equals("lonestar")) {
+            return this.getLonestarGRAM();
+        } else {
+            throw new RuntimeException("Invalid host " + this.getHost() );
+        }
+
+    }
+
     public void setTrestlesGRAM(String trestlesGRAM) {
         this.trestlesGRAM = trestlesGRAM;
     }
@@ -459,4 +483,36 @@ public class ExectionContext {
     public String getArguments() {
         return arguments;
     }
+
+    public boolean isInteractive() {
+        return interactive;
+    }
+
+    public void setInteractive(boolean interactive) {
+        this.interactive = interactive;
+    }
+
+    public void addGramJobNotifier(GramJobNotifier gramJobNotifier) {
+        this.gramJobNotifierList.add(gramJobNotifier);
+    }
+
+    public List<GramJobNotifier> getGramJobNotifierList() {
+        return Collections.unmodifiableList(gramJobNotifierList);
+    }
+
+    public String getUserName() {
+        return userName;
+    }
+
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
 }
diff --git a/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/GFacException.java b/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/GFacException.java
new file mode 100644 (file)
index 0000000..57c33db
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ *
+ * 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.gram;
+
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 6/18/13
+ * Time: 4:21 PM
+ */
+
+public class GFacException extends Exception {
+
+    public GFacException(String message) {
+        super(message);
+    }
+
+    public GFacException(Exception exception) {
+        super(exception);
+    }
+}
diff --git a/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/GramJobSubmissionManager.java b/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/GramJobSubmissionManager.java
new file mode 100644 (file)
index 0000000..2f75d3d
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ *
+ * 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.gram;
+
+import org.apache.airavata.jobsubmission.gram.persistence.JobData;
+import org.apache.airavata.jobsubmission.gram.persistence.JobPersistenceManager;
+import org.apache.airavata.jobsubmission.gram.persistence.PersistenceGramJobNotifier;
+import org.apache.log4j.Logger;
+import org.globus.gram.GramAttributes;
+import org.globus.gram.GramException;
+import org.globus.gram.GramJob;
+import org.globus.gram.WaitingForCommitException;
+import org.globus.gram.internal.GRAMConstants;
+import org.ietf.jgss.GSSCredential;
+import org.ietf.jgss.GSSException;
+
+import java.net.MalformedURLException;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class GramJobSubmissionManager {
+
+    private static final Logger log = Logger.getLogger(GramJobSubmissionManager.class);
+
+    private static final Map<String, GramJob> currentlyExecutingJobs = new ConcurrentHashMap<String, GramJob>();
+
+    private RSLGenerator rslGenerator;
+
+    private JobPersistenceManager jobPersistenceManager;
+
+    public GramJobSubmissionManager(JobPersistenceManager jobPersistenceManager) {
+        this.jobPersistenceManager = jobPersistenceManager;
+        this.rslGenerator = new RSLGenerator();
+    }
+
+    public String executeJob(GSSCredential gssCred, String contactString,
+                             ExecutionContext appExecContext) throws Exception {
+
+        try {
+            //TODO remove when porting
+            log.setLevel(org.apache.log4j.Level.ALL);
+
+            appExecContext.addGramJobNotifier(new PersistenceGramJobNotifier(this.jobPersistenceManager));
+
+            GramAttributes jobAttr = rslGenerator.configureRemoteJob(appExecContext);
+            String rsl = jobAttr.toRSL();
+            GramJob job = new GramJob(rsl + "(twoPhase=yes)");
+
+            log.info("RSL = " + rsl);
+            JobSubmissionListener listener = new JobSubmissionListener(appExecContext.getGramJobNotifierList());
+            job.setCredentials(gssCred);
+            job.addListener(listener);
+            log.info("Request to contact:" + contactString);
+
+            try {
+
+                job.request(true, contactString, appExecContext.isInteractive());
+
+            } catch(WaitingForCommitException e) {
+
+                log.info("JobID = " + job.getIDAsString());
+
+                jobPersistenceManager.updateJobStatus(new JobData(job.getIDAsString(),
+                        GRAMConstants.STATUS_UNSUBMITTED));
+
+                ListenerQueue listenerQueue = ListenerQueue.getInstance();
+                listenerQueue.addJob(job);
+
+                currentlyExecutingJobs.put(job.getIDAsString(), job);
+
+                log.debug("Two phase commit: sending COMMIT_REQUEST signal");
+                job.signal(GramJob.SIGNAL_COMMIT_REQUEST);
+            }
+
+            return job.getIDAsString();
+
+        } catch (GramException ge) {
+            ge.printStackTrace();
+            log.error(ge, ge.getCause());
+        } catch (GSSException gss) {
+            gss.printStackTrace();
+            log.error(gss, gss.getCause());
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e, e.getCause());
+        }
+
+        return null;
+    }
+
+
+
+    public void cancelJob(String jobId) throws GramException, GSSException {
+
+        if (currentlyExecutingJobs.containsKey(jobId)) {
+            GramJob gramJob = currentlyExecutingJobs.get(jobId);
+            if (gramJob != null) {
+                gramJob.cancel();
+                gramJob.signal(GramJob.SIGNAL_COMMIT_END);
+            }
+        }
+
+    }
+
+    public void startMonitoringRunningJobs(GSSCredential gssCred, ExecutionContext appExecContext) throws GFacException, MalformedURLException {
+
+        ListenerQueue listenerQueue = ListenerQueue.getInstance();
+
+        List<JobData> jobDataList = this.jobPersistenceManager.getRunningJobs();
+
+        appExecContext.addGramJobNotifier(new PersistenceGramJobNotifier(this.jobPersistenceManager));
+        JobSubmissionListener listener = new JobSubmissionListener(appExecContext.getGramJobNotifierList());
+
+        for (JobData jobData : jobDataList) {
+
+            GramJob gramJob = new GramJob(null);
+            gramJob.setID(jobData.getJobId());
+            gramJob.setCredentials(gssCred);
+            gramJob.addListener(listener);
+
+
+            log.info("Adding job " + jobData.getJobId() + " in state " + jobData.getState()
+                    + " to monitoring queue");
+
+            listenerQueue.addJob(gramJob);
+        }
+
+    }
+}
index 02f2138..215d2fa 100644 (file)
 
 package org.apache.airavata.jobsubmission.gram;
 
+import org.apache.airavata.jobsubmission.gram.notifier.GramJobNotifier;
 import org.apache.log4j.Logger;
+import org.globus.gram.GramException;
 import org.globus.gram.GramJob;
 import org.globus.gram.GramJobListener;
+import org.globus.gram.internal.GRAMProtocolErrorConstants;
+import org.ietf.jgss.GSSException;
+
+import java.util.List;
 
 public class JobSubmissionListener implements GramJobListener {
 
-    private static final String DELIMITER = "#";
-    private boolean finished;
-    private int error;
-    private int status;
-    private StringBuffer buffer;
+    private int currentStatus = -43;
 
-    private GramJob job;
+    private boolean isSubmitted = false;
 
     private static final Logger log = Logger.getLogger(JobSubmissionListener.class);
 
-    public JobSubmissionListener(GramJob job, StringBuffer buffer) {
-        this.buffer = buffer;
-        this.job = job;
-    }
+    private List<GramJobNotifier> gramJobNotifierList;
 
-    // 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(20 * 1000l);
-            }
-        }
+    public JobSubmissionListener(List<GramJobNotifier> notifiers) {
+        this.gramJobNotifierList = notifiers;
     }
 
+
     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();
+        if (currentStatus != jobStatus) {
+            currentStatus = jobStatus;
+
+            if (currentStatus == GramJob.STATUS_FAILED) {
+                int error = job.getError();
+
+                log.debug("Job Error Code: " + error);
+
+                try {
+                    job.unbind();
+
+                    if (error == GRAMProtocolErrorConstants.USER_CANCELLED) {
+                        for(GramJobNotifier notifier : gramJobNotifierList) {
+                            notifier.OnCancel(job);
+                        }
+                    } else if (error == GRAMProtocolErrorConstants.ERROR_AUTHORIZATION) {
+                        for(GramJobNotifier notifier : gramJobNotifierList) {
+                            notifier.OnAuthorisationDenied(job);
+                        }
+                    } else {
+                        for(GramJobNotifier notifier : gramJobNotifierList) {
+                            notifier.OnError(job);
+                        }
+                    }
+
+                } catch (Exception e) {
+                    for(GramJobNotifier notifier : gramJobNotifierList) {
+                        notifier.OnListenerError(job, e);
+                    }
+                }
+            } else if (currentStatus == GramJob.STATUS_DONE) {
+                try {
+                    job.unbind();
+
+                    for(GramJobNotifier notifier : gramJobNotifierList) {
+                        notifier.OnCompletion(job);
+                    }
+
+                } catch (Exception e) {
+                    for(GramJobNotifier notifier : gramJobNotifierList) {
+                        notifier.OnListenerError(job, e);
+                    }
+                }
+            } else if (currentStatus == GramJob.STATUS_ACTIVE) {
+
+                for(GramJobNotifier notifier : gramJobNotifierList) {
+                    notifier.OnActive(job);
+                }
+            } else if (currentStatus == GramJob.STATUS_PENDING) {
+
+                for(GramJobNotifier notifier : gramJobNotifierList) {
+                    notifier.OnPending(job);
+                }
+            } else if (currentStatus == GramJob.STATUS_UNSUBMITTED) {
+
+                for(GramJobNotifier notifier : gramJobNotifierList) {
+                    notifier.OnUnSubmit(job);
+                }
+            } else if (currentStatus == GramJob.STATUS_STAGE_IN) {
+
+                for(GramJobNotifier notifier : gramJobNotifierList) {
+                    notifier.OnFilesStagedIn(job);
+                }
+            } else if (currentStatus == GramJob.STATUS_STAGE_OUT) {
+
+                for(GramJobNotifier notifier : gramJobNotifierList) {
+                    notifier.OnFilesStagedOut(job);
+                }
+            } else if (currentStatus == GramJob.STATUS_SUSPENDED) {
+
+                for(GramJobNotifier notifier : gramJobNotifierList) {
+                    notifier.OnSuspend(job);
+                }
+            }
         }
     }
 
     public static String formatJobStatus(String jobid, String jobstatus) {
-        return System.currentTimeMillis() + DELIMITER + jobid + DELIMITER + jobstatus;
+        return System.currentTimeMillis() + " " + jobid + " " + jobstatus;
     }
 
-    public int getError() {
+    /*public int getError() {
         return error;
     }
 
     public int getStatus() {
         return status;
-    }
+    }*/
 
     public void wakeup() {
         try {
diff --git a/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/ListenerQueue.java b/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/ListenerQueue.java
new file mode 100644 (file)
index 0000000..3801c1b
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ *
+ * 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.gram;
+
+import org.globus.gram.GramException;
+import org.globus.gram.GramJob;
+import org.ietf.jgss.GSSException;
+
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 6/17/13
+ * Time: 2:15 PM
+ */
+
+public class ListenerQueue extends Thread {
+
+    private final Queue<JobListenerThread> qe;
+
+    private static ListenerQueue listenerQueue;
+
+    private boolean shutDown = false;
+
+    private ListenerQueue() {
+        qe = new ConcurrentLinkedQueue<JobListenerThread>();
+    }
+
+    public static ListenerQueue getInstance() {
+
+        if (null == listenerQueue) {
+            listenerQueue = new ListenerQueue();
+            return listenerQueue;
+        } else {
+            return listenerQueue;
+        }
+    }
+
+    public void run() {
+
+        while (!shutDown) {
+
+            startListener();
+
+            try {
+                synchronized (qe) {
+                    qe.wait();
+                }
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+
+        }
+    }
+
+    public void     stopListenerQueue() {
+        shutDown = true;
+
+        synchronized (qe) {
+            qe.notify();
+        }
+
+        listenerQueue = null;
+
+        try {
+            this.join();
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+
+
+    }
+
+    public void startListenerQueue() {
+        shutDown = false;
+        this.start();
+    }
+
+    public void startListener() {
+
+        while(!qe.isEmpty()) {
+            JobListenerThread jobListenerThread = qe.poll();
+            jobListenerThread.start();
+        }
+    }
+
+    public synchronized void addJob(GramJob job) {
+
+        qe.offer(new JobListenerThread(job));
+
+        synchronized (qe) {
+            qe.notifyAll();
+        }
+    }
+
+    class JobListenerThread extends Thread {
+
+        private GramJob listeningJob;
+
+        public JobListenerThread(GramJob job) {
+            listeningJob = job;
+        }
+
+        public void run() {
+            try {
+                listeningJob.bind();
+            } catch (GramException e) {
+                e.printStackTrace();
+            } catch (GSSException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+
+}
 
 package org.apache.airavata.jobsubmission.gram;
 
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 6/18/13
+ * Time: 10:24 AM
+ */
+
 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 {
+/**
+ * Responsible for generating the RSL from descriptors. Based on execution contexts.
+ */
+public class RSLGenerator {
 
     private static final String MULTIPLE = "multiple";
 
@@ -38,51 +43,9 @@ public class GramJobSubmission {
 
     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.ALL);
-            String contact = "";
-            if (appExecContext.getTestingHost().equals("trestles")) {
-                contact = appExecContext.getTrestlesGRAM();
-            } else if (appExecContext.getTestingHost().equals("ranger")) {
-                contact = appExecContext.getRangerGRAM();
-            } else if (appExecContext.getTestingHost().equals("lonestar")) {
-                contact = appExecContext.getLonestarGRAM();
-            }
-            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());
-        }
-    }
+    private static final Logger log = Logger.getLogger(RSLGenerator.class);
 
-    protected GramAttributes configureRemoteJob(ExectionContext appExecContext) throws Exception {
+    protected GramAttributes configureRemoteJob(ExecutionContext appExecContext) throws Exception {
         GramAttributes jobAttr = new GramAttributes();
         jobAttr.setExecutable(appExecContext.getExecutable());
         if (appExecContext.getWorkingDir() != null) {
@@ -135,6 +98,8 @@ public class GramJobSubmission {
             jobAttr.setJobType(GramAttributes.JOBTYPE_CONDOR);
         }
 
+
         return jobAttr;
     }
+
 }
diff --git a/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/errors.properties b/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/errors.properties
new file mode 100644 (file)
index 0000000..3e4382b
--- /dev/null
@@ -0,0 +1,176 @@
+1 = Parameter not supported
+2 = The RSL length is greater than the maximum allowed
+3 = No resources available
+4 = Bad directory specified
+5 = The executable does not exist
+6 = Insufficient funds
+7 = Authentication with the remote server failed
+8 = Job cancelled by user
+9 = Job cancelled by system
+
+10 = Data transfer to the server failed
+11 = The stdin file does not exist
+12 = The connection to the server failed (check host and port)
+13 = The provided RSL 'maxtime' value is invalid (not an integer or must be greater than 0)
+14 = The provided RSL 'count' value is invalid (not an integer or must be greater than 0)
+15 = The job manager received an invalid RSL
+16 = Could not connect to job manager
+17 = The job failed when the job manager attempted to run it
+18 = Paradyn error
+19 = The provided RSL 'jobtype' value is invalid
+
+20 = The provided RSL 'myjob' value is invalid
+21 = The job manager failed to locate an internal script argument file
+22 = The job manager failed to create an internal script argument file
+23 = The job manager detected an invalid job state
+24 = The job manager detected an invalid script response
+25 = The job manager detected an invalid job state
+26 = The provided RSL 'jobtype' value is not supported by this job manager
+27 = Unimplemented
+28 = The job manager failed to create an internal script submission file
+29 = The job manager cannot find the user proxy
+
+30 = The job manager failed to open the user proxy
+31 = The job manager failed to cancel the job as requested
+32 = System memory allocation failed
+33 = The interprocess job communication initialization failed
+34 = The interprocess job communication setup failed
+35 = The provided RSL 'host count' value is invalid
+36 = One of the provided RSL parameters is unsupported
+37 = The provided RSL 'queue' parameter is invalid
+38 = The provided RSL 'project' parameter is invalid
+39 = The provided RSL string includes variables that could not be identified
+
+40 = The provided RSL 'environment' parameter is invalid
+41 = The provided RSL 'dryrun' parameter is invalid
+42 = The provided RSL is invalid (an empty string)
+43 = The job manager failed to stage the executable
+44 = The job manager failed to stage the stdin file
+45 = The requested job manager type is invalid
+46 = The provided RSL 'arguments' parameter is invalid
+47 = The gatekeeper failed to run the job manager
+48 = The provided RSL could not be properly parsed
+49 = There is a version mismatch between GRAM components
+
+50 = The provided RSL 'arguments' parameter is invalid
+51 = The provided RSL 'count' parameter is invalid
+52 = The provided RSL 'directory' parameter is invalid
+53 = The provided RSL 'dryrun' parameter is invalid
+54 = The provided RSL 'environment' parameter is invalid
+55 = The provided RSL 'executable' parameter is invalid
+56 = The provided RSL 'host_count' parameter is invalid
+57 = The provided RSL 'jobtype' parameter is invalid
+58 = The provided RSL 'maxtime' parameter is invalid
+59 = The provided RSL 'myjob' parameter is invalid
+
+60 = The provided RSL 'paradyn' parameter is invalid
+61 = The provided RSL 'project' parameter is invalid
+62 = The provided RSL 'queue' parameter is invalid
+63 = The provided RSL 'stderr' parameter is invalid
+64 = The provided RSL 'stdin' parameter is invalid
+65 = The provided RSL 'stdout' parameter is invalid
+66 = The job manager failed to locate an internal script
+67 = The job manager failed on the system call pipe()
+68 = The job manager failed on the system call fcntl()
+69 = The job manager failed to create the temporary stdout filename
+
+70 = The job manager failed to create the temporary stderr filename
+71 = The job manager failed on the system call fork()
+72 = The executable file permissions do not allow execution
+73 = The job manager failed to open stdout
+74 = The job manager failed to open stderr
+75 = The cache file could not be opened in order to relocate the user proxy
+76 = Cannot access cache files in ~/.globus/.gass_cache, check permissions, quota, and disk space
+77 = The job manager failed to insert the contact in the client contact list
+78 = The contact was not found in the job manager's client contact list
+79 = Connecting to the job manager failed.  Possible reasons: job terminated, invalid job contact, network problems, ...
+
+80 = The syntax of the job contact is invalid
+81 = The executable parameter in the RSL is undefined
+82 = The job manager service is misconfigured.  condor arch undefined
+83 = The job manager service is misconfigured.  condor os undefined
+84 = The provided RSL 'min_memory' parameter is invalid
+85 = The provided RSL 'max_memory' parameter is invalid
+86 = The RSL 'min_memory' value is not zero or greater
+87 = The RSL 'max_memory' value is not zero or greater
+88 = The creation of a HTTP message failed
+89 = Parsing incoming HTTP message failed
+
+90 = The packing of information into a HTTP message failed
+91 = An incoming HTTP message did not contain the expected information
+92 = The job manager does not support the service that the client requested
+93 = The gatekeeper failed to find the requested service
+94 = The jobmanager does not accept any new requests (shutting down)
+95 = The client failed to close the listener associated with the callback URL
+96 = The gatekeeper contact cannot be parsed
+97 = The job manager could not find the 'poe' command
+98 = The job manager could not find the 'mpirun' command
+99 = The provided RSL 'start_time' parameter is invalid"
+100 = The provided RSL 'reservation_handle' parameter is invalid
+
+101 = The provided RSL 'max_wall_time' parameter is invalid
+102 = The RSL 'max_wall_time' value is not zero or greater
+103 = The provided RSL 'max_cpu_time' parameter is invalid
+104 = The RSL 'max_cpu_time' value is not zero or greater
+105 = The job manager is misconfigured, a scheduler script is missing
+106 = The job manager is misconfigured, a scheduler script has invalid permissions
+107 = The job manager failed to signal the job
+108 = The job manager did not recognize/support the signal type
+109 = The job manager failed to get the job id from the local scheduler
+
+110 = The job manager is waiting for a commit signal
+111 = The job manager timed out while waiting for a commit signal
+112 = The provided RSL 'save_state' parameter is invalid
+113 = The provided RSL 'restart' parameter is invalid
+114 = The provided RSL 'two_phase' parameter is invalid
+115 = The RSL 'two_phase' value is not zero or greater
+116 = The provided RSL 'stdout_position' parameter is invalid
+117 = The RSL 'stdout_position' value is not zero or greater
+118 = The provided RSL 'stderr_position' parameter is invalid
+119 = The RSL 'stderr_position' value is not zero or greater
+
+120 = The job manager restart attempt failed
+121 = The job state file doesn't exist
+122 = Could not read the job state file
+123 = Could not write the job state file
+124 = The old job manager is still alive
+125 = The job manager state file TTL expired
+126 = It is unknown if the job was submitted
+127 = The provided RSL 'remote_io_url' parameter is invalid
+128 = Could not write the remote io url file
+129 = The standard output/error size is different
+
+130 = The job manager was sent a stop signal (job is still running)
+131 = The user proxy expired (job is still running)
+132 = The job was not submitted by original jobmanager
+133 = The job manager is not waiting for that commit signal
+134 = The provided RSL scheduler specific parameter is invalid
+135 = The job manager could not stage in a file
+136 = The scratch directory could not be created
+137 = The provided 'gass_cache' parameter is invalid
+138 = The RSL contains attributes which are not valid for job submission
+139 = The RSL contains attributes which are not valid for stdio update
+
+140 = The RSL contains attributes which are not valid for job restart
+141 = The provided RSL 'file_stage_in' parameter is invalid
+142 = The provided RSL 'file_stage_in_shared' parameter is invalid
+143 = The provided RSL 'file_stage_out' parameter is invalid
+144 = The provided RSL 'gass_cache' parameter is invalid
+145 = The provided RSL 'file_cleanup' parameter is invalid
+146 = The provided RSL 'scratch_dir' parameter is invalid
+147 = The provided scheduler-specific RSL parameter is invalid
+148 = A required RSL attribute was not defined in the RSL spec
+149 = The gass_cache attribute points to an invalid cache directory
+
+150 = The provided RSL 'save_state' parameter has an invalid value
+151 = The job manager could not open the RSL attribute validation file
+152 = The  job manager could not read the RSL attribute validation file
+153 = The provided RSL 'proxy_timeout' is invalid
+154 = The RSL 'proxy_timeout' value is not greater than zero
+155 = The job manager could not stage out a file
+156 = The job contact string does not match any which the job manager is handling
+157 = Proxy delegation failed
+158 = The job manager could not lock the state lock file
+
+1000 = Failed to start up callback handler
+1003 = Job contact not set
diff --git a/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/notifier/GramJobLogger.java b/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/notifier/GramJobLogger.java
new file mode 100644 (file)
index 0000000..76f831a
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ *
+ * 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.gram.notifier;
+
+import org.apache.log4j.Logger;
+import org.globus.gram.GramJob;
+import org.ietf.jgss.GSSException;
+
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 6/18/13
+ * Time: 10:59 AM
+ */
+
+public class GramJobLogger implements GramJobNotifier {
+
+    private static final Logger log = Logger.getLogger(GramJobLogger.class);
+
+    private static ResourceBundle resources;
+
+    private String format = "Job Id [ %s ] is in [ %s ] state.";
+
+    static {
+        try {
+            resources = ResourceBundle.getBundle("org.apache.airavata.jobsubmission.gram.errors",
+                    Locale.getDefault());
+        } catch (MissingResourceException mre) {
+            System.err.println("org.globus.gram.internal.gram.errors.properties not found");
+        }
+    }
+
+
+    public void OnPending(GramJob job) {
+        log.info(String.format(format, job.getIDAsString(), "PENDING"));
+    }
+
+    public void OnActive(GramJob job) {
+        log.info(String.format(format, job.getIDAsString(), "ACTIVE"));
+    }
+
+    public void OnError(GramJob job) {
+        log.info(String.format("Job Id [ %s ] is in %s state. Error code - %d and description - %s",
+                job.getIDAsString(), "[ ERROR ]", job.getError(),"TODO fix bundle loading"));
+    }
+
+    public void OnCompletion(GramJob job) {
+        log.info(String.format(format, job.getIDAsString(), "COMPLETE"));
+    }
+
+    public void OnCancel(GramJob job) {
+        log.info(String.format(format, job.getIDAsString(), "USER-CANCELED"));
+    }
+
+    public void OnSuspend(GramJob job) {
+        log.info(String.format(format, job.getIDAsString(), "SUSPEND"));
+    }
+
+    public void OnUnSubmit(GramJob job) {
+        log.info(String.format(format, job.getIDAsString(), "UN-SUBMITTED"));
+    }
+
+    public void OnFilesStagedIn(GramJob job) {
+        log.info(String.format(format, job.getIDAsString(), "FILES-STAGED-IN"));
+    }
+
+    public void OnFilesStagedOut(GramJob job) {
+        log.info(String.format(format, job.getIDAsString(), "FILES-STAGED-OUT"));
+    }
+
+    public void OnListenerError(GramJob job, Exception e) {
+        log.error("An error occurred while monitoring job id - " + job.getIDAsString(), e);
+    }
+
+    public void OnAuthorisationDenied(GramJob job) {
+        try {
+            log.error("Authorisation denied for job execution. User name - "
+                    + job.getCredentials().getName().toString());
+        } catch (GSSException e) {
+            log.error("An error occurred while logging authorisation information - ", e);
+        }
+    }
+}
diff --git a/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/notifier/GramJobNotifier.java b/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/notifier/GramJobNotifier.java
new file mode 100644 (file)
index 0000000..a28b1cb
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ *
+ * 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.gram.notifier;
+
+import org.globus.gram.GramJob;
+
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 6/18/13
+ * Time: 10:45 AM
+ */
+
+public interface GramJobNotifier {
+
+    void OnPending(GramJob job);
+
+    void OnActive(GramJob job);
+
+    void OnError (GramJob job);
+
+    void OnCompletion(GramJob job);
+
+    void OnCancel (GramJob job);
+
+    void OnSuspend (GramJob job);
+
+    void OnUnSubmit (GramJob job);
+
+    void OnFilesStagedIn (GramJob job);
+
+    void OnFilesStagedOut (GramJob job);
+
+    void OnListenerError(GramJob job, Exception e);
+
+    void OnAuthorisationDenied(GramJob job);
+
+}
diff --git a/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/persistence/DBJobPersistenceManager.java b/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/persistence/DBJobPersistenceManager.java
new file mode 100644 (file)
index 0000000..c08f547
--- /dev/null
@@ -0,0 +1,219 @@
+/*
+ *
+ * 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.gram.persistence;
+
+import org.apache.airavata.common.utils.DBUtil;
+import org.apache.airavata.jobsubmission.gram.GFacException;
+import org.apache.log4j.Logger;
+import org.globus.gram.internal.GRAMConstants;
+
+import java.sql.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 6/18/13
+ * Time: 4:16 PM
+ */
+
+public class DBJobPersistenceManager implements JobPersistenceManager {
+
+    private DBUtil dbUtil;
+
+    private static final Logger log = Logger.getLogger(DBJobPersistenceManager.class);
+
+
+    public DBJobPersistenceManager(DBUtil db) {
+        this.dbUtil = db;
+    }
+
+    public synchronized void updateJobStatus(JobData jobData) throws GFacException{
+
+        if (jobData.getState() == GRAMConstants.STATUS_UNSUBMITTED) {
+            insertJob(jobData);
+        } else {
+
+            String sql = "update gram_job set status = ? where job_id = ?";
+
+            Connection connection = null;
+            PreparedStatement stmt = null;
+
+            try {
+                connection = getConnection();
+                stmt = connection.prepareStatement(sql);
+                stmt.setInt(1, jobData.getState());
+                stmt.setString(2, jobData.getJobId());
+
+                stmt.executeUpdate();
+                connection.commit();
+
+            } catch (SQLException e) {
+                throw new GFacException(e);
+            } finally {
+                try {
+                    if (stmt != null) {
+                        stmt.close();
+                    }
+
+                    if (connection != null) {
+                        connection.close();
+                    }
+
+                } catch (SQLException e) {
+                    log.error("Error closing streams", e);
+                }
+            }
+        }
+    }
+
+    private void insertJob(JobData jobData) throws GFacException {
+
+        String sql = "insert into gram_job values (?, ?)";
+
+        PreparedStatement stmt = null;
+        Connection connection = null;
+
+        try {
+            connection = getConnection();
+            stmt = connection.prepareStatement(sql);
+            stmt.setString(1, jobData.getJobId());
+            stmt.setInt(2, jobData.getState());
+
+            stmt.executeUpdate();
+        } catch (SQLException e) {
+            throw new GFacException(e);
+        } finally {
+            try {
+                if (stmt != null) {
+                    stmt.close();
+                }
+
+                if (connection != null) {
+                    connection.close();
+                }
+
+            } catch (SQLException e) {
+                log.error("Error closing streams", e);
+            }
+        }
+
+    }
+
+    public List<JobData> getRunningJobs() throws GFacException {
+
+        String sql = "select * from gram_job where status not in (?, ?, ?)";
+
+        int[] statuses = new int[3];
+        statuses[0] = GRAMConstants.STATUS_UNSUBMITTED;
+        statuses[1] = GRAMConstants.STATUS_DONE;
+        statuses[2] = GRAMConstants.STATUS_FAILED;
+
+        return getJobs(sql, statuses);
+    }
+
+    public List<JobData> getFailedJobs() throws GFacException {
+
+        String sql = "select * from gram_job where status in (?)";
+
+        int[] statuses = new int[1];
+        statuses[0] = GRAMConstants.STATUS_FAILED;
+
+        return getJobs(sql, statuses);
+    }
+
+    public List<JobData> getUnSubmittedJobs() throws GFacException {
+
+        String sql = "select * from gram_job where status in (?)";
+
+        int[] statuses = new int[1];
+        statuses[0] = GRAMConstants.STATUS_UNSUBMITTED;
+
+        return getJobs(sql, statuses);
+    }
+
+    public List<JobData> getSuccessfullyCompletedJobs() throws GFacException {
+
+        String sql = "select * from gram_job where status in (?)";
+
+        int[] statuses = new int[1];
+        statuses[0] = GRAMConstants.STATUS_DONE;
+
+        return getJobs(sql, statuses);
+
+    }
+
+
+    protected List<JobData> getJobs(String sql, int[] statuses) throws GFacException {
+
+        List<JobData> jobs = new ArrayList<JobData>();
+
+        PreparedStatement preparedStatement = null;
+        Connection connection = null;
+
+        try {
+            connection = getConnection();
+            preparedStatement = connection.prepareStatement(sql);
+
+            int index = 1;
+            for (int status : statuses) {
+                preparedStatement.setInt(index, status);
+                ++index;
+            }
+
+            ResultSet resultSet = preparedStatement.executeQuery();
+
+            while (resultSet.next()) {
+
+                String jobId = resultSet.getString("job_id");
+                int state = resultSet.getInt("status");
+
+                jobs.add(new JobData(jobId, state));
+            }
+
+        } catch (SQLException e) {
+            throw new GFacException(e);
+        } finally {
+            try {
+                if (preparedStatement != null) {
+                    preparedStatement.close();
+                }
+
+                if (connection != null) {
+                    connection.close();
+                }
+
+            } catch (SQLException e) {
+                log.error("Error closing connection", e);
+            }
+        }
+
+        return jobs;
+    }
+
+    private synchronized Connection getConnection() throws SQLException {
+        Connection connection = dbUtil.getConnection();
+        connection.setAutoCommit(true);
+
+        return connection;
+    }
+}
diff --git a/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/persistence/JobData.java b/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/persistence/JobData.java
new file mode 100644 (file)
index 0000000..dda765b
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.jobsubmission.gram.persistence;
+
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 6/18/13
+ * Time: 2:34 PM
+ */
+
+public class JobData {
+
+    private String jobId;
+    private int state;
+
+    public JobData(String id, int state) {
+        this.jobId = id;
+        this.state = state;
+    }
+
+    public String getJobId() {
+        return jobId;
+    }
+
+    public void setJobId(String jobId) {
+        this.jobId = jobId;
+    }
+
+    public int getState() {
+        return state;
+    }
+
+    public void setState(int state) {
+        this.state = state;
+    }
+}
diff --git a/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/persistence/JobPersistenceManager.java b/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/persistence/JobPersistenceManager.java
new file mode 100644 (file)
index 0000000..460164d
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ *
+ * 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.gram.persistence;
+
+import org.apache.airavata.jobsubmission.gram.GFacException;
+
+import java.util.List;
+
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 6/18/13
+ * Time: 2:23 PM
+ */
+
+public interface JobPersistenceManager {
+
+    void updateJobStatus (JobData jobData) throws GFacException;
+
+    List<JobData> getRunningJobs() throws GFacException;
+
+    List<JobData> getFailedJobs() throws GFacException;
+
+    List<JobData> getUnSubmittedJobs() throws GFacException;
+
+    List<JobData> getSuccessfullyCompletedJobs() throws GFacException;
+
+}
diff --git a/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/persistence/PersistenceGramJobNotifier.java b/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/gram/persistence/PersistenceGramJobNotifier.java
new file mode 100644 (file)
index 0000000..4b6d312
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ *
+ * 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.gram.persistence;
+
+import org.apache.airavata.jobsubmission.gram.GFacException;
+import org.apache.airavata.jobsubmission.gram.notifier.GramJobNotifier;
+import org.globus.gram.GramJob;
+
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 6/18/13
+ * Time: 3:49 PM
+ */
+
+public class PersistenceGramJobNotifier implements GramJobNotifier {
+
+    private JobPersistenceManager jobPersistenceManager;
+
+    public PersistenceGramJobNotifier(JobPersistenceManager persistenceManager) {
+        this.jobPersistenceManager = persistenceManager;
+    }
+
+    public void OnPending(GramJob job) {
+        try {
+            this.jobPersistenceManager.updateJobStatus(new JobData(job.getIDAsString(), job.getStatus()));
+        } catch (GFacException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void OnActive(GramJob job) {}
+
+    public void OnError(GramJob job) {
+        try {
+            this.jobPersistenceManager.updateJobStatus(new JobData(job.getIDAsString(), job.getStatus()));
+        } catch (GFacException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void OnCompletion(GramJob job) {
+        try {
+            this.jobPersistenceManager.updateJobStatus(new JobData(job.getIDAsString(), job.getStatus()));
+        } catch (GFacException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void OnCancel(GramJob job) {
+        try {
+            this.jobPersistenceManager.updateJobStatus(new JobData(job.getIDAsString(), job.getStatus()));
+        } catch (GFacException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void OnSuspend(GramJob job) {}
+
+    public void OnUnSubmit(GramJob job) {}
+
+    public void OnFilesStagedIn(GramJob job) {}
+
+    public void OnFilesStagedOut(GramJob job) {}
+
+    public void OnListenerError(GramJob job, Exception e) {}
+
+    public void OnAuthorisationDenied(GramJob job) {
+        try {
+            this.jobPersistenceManager.updateJobStatus(new JobData(job.getIDAsString(), job.getStatus()));
+        } catch (GFacException e) {
+            e.printStackTrace();
+        }
+    }
+}
diff --git a/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/security/CertificateManager.java b/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/security/CertificateManager.java
deleted file mode 100755 (executable)
index 28fe22e..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- *
- * 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.security;
-
-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;
-
-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;
-    }
-
-}
diff --git a/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/security/MyProxyCredentials.java b/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/security/MyProxyCredentials.java
deleted file mode 100644 (file)
index 38c8362..0000000
+++ /dev/null
@@ -1,318 +0,0 @@
-/*
- *
- * 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.security;
-
-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;
-
-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;
-    }
-
-}
diff --git a/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/security/SecurityContext.java b/grid-tools/gram-client/src/main/java/org/apache/airavata/jobsubmission/security/SecurityContext.java
deleted file mode 100644 (file)
index b2dacb2..0000000
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- *
- * 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.security;
-
-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;
-
-public class SecurityContext {
-
-    /**
-        * 
-        */
-    private static final long serialVersionUID = -2270092298283648553L;
-    public static final String GRAMCLIENT_PROPERTY = "airavata-gram-client.properties";
-    private Properties properties;
-    protected GSSCredential gssCredential;
-
-    private MyProxyCredentials credentials;
-    private static final Logger log = Logger.getLogger(SecurityContext.class);
-
-    /**
-     * 
-     * Constructs a ApplicationGlobalContext.
-     * 
-     * @throws GfacGUIException
-     */
-
-    public SecurityContext() throws Exception {
-        log.setLevel(org.apache.log4j.Level.INFO);
-        loadConfiguration();
-
-    }
-
-    public static void main(String[] args) {
-        try {
-            SecurityContext context = new SecurityContext();
-            context.login();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-    /**
-     * 
-     * @throws GfacException
-     */
-    public void login() throws Exception {
-        gssCredential = credentials.getGssCredential();
-    }
-
-    public static String getProperty(String name) {
-        try {
-            SecurityContext context = new SecurityContext();
-            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;
-    }
-}
index f9e6db1..b15911f 100644 (file)
@@ -34,7 +34,7 @@ public class ServiceConstants {
        public static final String TESTINGHOST = "testing.host";
        
     public static final String LONESTARGRAMEPR = "lonestar.gram.endpoint";
-    public static final String RANGERGRAMEPR = "ranger.gram.endpoint";
+    public static final String STAMPEDE_GRAM_EPR = "stampede.gram.endpoint";
     public static final String TRESTLESGRAMEPR = "trestles.gram.endpoint";
        
        public static final String EXECUTABLE = "executable";
index 78d9155..347c273 100644 (file)
@@ -14,15 +14,15 @@ testing.host=trestles
 lonestar.gram.endpoint=gridftp1.ls4.tacc.utexas.edu:2119/jobmanager-sge\r
 \r
 ## TACC Stampede        \r
-stampede.gram.endpoint=login5.stampede.tacc.utexas.edu:2119/jobmanager-slurm\r
+stampede.gram.endpoint=login5.stampede.tacc.utexas.edu:2119/jobmanager-slurm3\r
 \r
 ## SDSC Trestles        \r
 trestles.gram.endpoint=trestles-login2.sdsc.edu:2119/jobmanager-pbstest2\r
 \r
-executable=/bin/hostname\r
+executable=/bin/sleep\r
 arguments=30\r
 queue=normal\r
-project_number=TG-STA110014S\r
+project_number=TG-MCB070039N\r
 jobtype=single\r
 maxwalltime=1\r
 processors=1\r
diff --git a/grid-tools/gram-client/src/test/java/org/apache/airavata/jobsubmission/gram/GramJobSubmissionManagerTest.java b/grid-tools/gram-client/src/test/java/org/apache/airavata/jobsubmission/gram/GramJobSubmissionManagerTest.java
new file mode 100644 (file)
index 0000000..1122e77
--- /dev/null
@@ -0,0 +1,232 @@
+/*
+ *
+ * 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.gram;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import org.apache.airavata.common.utils.DBUtil;
+import org.apache.airavata.common.utils.DerbyUtil;
+import org.apache.airavata.jobsubmission.gram.notifier.GramJobLogger;
+import org.apache.airavata.jobsubmission.gram.persistence.DBJobPersistenceManager;
+import org.apache.airavata.jobsubmission.gram.persistence.JobData;
+import org.apache.airavata.jobsubmission.gram.persistence.JobPersistenceManager;
+import org.apache.airavata.security.myproxy.SecurityContext;
+import org.apache.log4j.Logger;
+import org.globus.gsi.provider.GlobusProvider;
+
+import java.security.Security;
+import java.util.List;
+
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 6/12/13
+ * Time: 10:24 AM
+ */
+
+public class GramJobSubmissionManagerTest extends TestCase {
+
+    static {
+        Security.addProvider(new GlobusProvider());
+    }
+
+    private static final Logger logger = Logger.getLogger(GramJobSubmissionManagerTest.class);
+
+    protected static String hostAddress = "localhost";
+    protected static int port = 20000;
+    protected static String userName = "admin";
+    protected static String password = "admin";
+    protected static String driver = "org.apache.derby.jdbc.ClientDriver";
+
+    public void setUp() throws Exception{
+
+        DerbyUtil.startDerbyInServerMode(getHostAddress(), getPort(), getUserName(), getPassword());
+
+        String createTable = "CREATE TABLE gram_job\n" +
+                "(\n" +
+                "        job_id VARCHAR(256) NOT NULL,\n" +
+                "        status int NOT NULL,\n" +
+                "        PRIMARY KEY (job_id)\n" +
+                ")";
+
+
+        String dropTable = "drop table gram_job";
+
+        try {
+            executeSQL(dropTable);
+        } catch (Exception e) {}
+
+        executeSQL(createTable);
+
+    }
+
+    public static void executeSQL(String sql) throws Exception {
+        DBUtil dbUtil = new DBUtil(getJDBCUrl(), getUserName(), getPassword(), getDriver());
+        dbUtil.executeSQL(sql);
+    }
+
+    public static String getJDBCUrl() {
+        return "jdbc:derby://" + getHostAddress() + ":" + getPort() + "/persistent_data;create=true;user=" + getUserName() + ";password=" + getPassword();
+    }
+
+    public static String getHostAddress() {
+        return hostAddress;
+    }
+
+    public static int getPort() {
+        return port;
+    }
+
+    public static String getUserName() {
+        return userName;
+    }
+
+    public static String getPassword() {
+        return password;
+    }
+
+    public static String getDriver() {
+        return driver;
+    }
+
+    public DBUtil getDbUtil () throws Exception {
+        return new DBUtil(getJDBCUrl(), getUserName(), getPassword(), getDriver());
+
+    }
+
+    // Dummy test case just avoid failures
+    public void testDummy() {}
+
+    public void executeJob(ExecutionContext executionContext) throws Exception {
+
+        ListenerQueue listenerQueue = ListenerQueue.getInstance();
+        listenerQueue.start();
+
+        SecurityContext context = new SecurityContext();
+        context.login();
+
+        JobPersistenceManager jobPersistenceManager
+                = new DBJobPersistenceManager(getDbUtil());
+        GramJobSubmissionManager gramJobSubmissionManager
+                = new GramJobSubmissionManager(jobPersistenceManager);
+
+
+
+        String jobId = gramJobSubmissionManager.executeJob(context.getRawCredential(),
+                executionContext.getGRAMEndPoint(),
+                executionContext);
+
+        Assert.assertNotNull(jobId);
+
+        listenerQueue.join(2 * 60 * 1000);
+
+        logger.info("Checking whether job is in successful state in the persistence store");
+
+        List<JobData> list = jobPersistenceManager.getSuccessfullyCompletedJobs();
+        Assert.assertEquals(1, list.size());
+
+        Assert.assertEquals(jobId, list.get(0).getJobId());
+
+        listenerQueue.stopListenerQueue();
+
+    }
+
+    public void monitoringRunningJobs(ExecutionContext executionContext) throws Exception {
+
+        ListenerQueue listenerQueue = ListenerQueue.getInstance();
+        listenerQueue.startListenerQueue();
+
+        SecurityContext context = new SecurityContext();
+        context.login();
+
+        JobPersistenceManager jobPersistenceManager
+                = new DBJobPersistenceManager(getDbUtil());
+        GramJobSubmissionManager gramJobSubmissionManager
+                = new GramJobSubmissionManager(jobPersistenceManager);
+
+        executionContext.addGramJobNotifier(new GramJobLogger());
+
+        String jobId = gramJobSubmissionManager.executeJob(context.getRawCredential(),
+                executionContext.getTrestlesGRAM(),
+                executionContext);
+
+        listenerQueue.join(1000);
+
+        listenerQueue.stopListenerQueue();
+
+        logger.info("=================== Process Finished - Monitoring Stopped ==========================");
+
+        Assert.assertNotNull(jobId);
+
+        listenerQueue = ListenerQueue.getInstance();
+        listenerQueue.startListenerQueue();
+
+        logger.info("=================== Monitoring Stored Jobs ==========================");
+
+        gramJobSubmissionManager.startMonitoringRunningJobs(context.getRawCredential(), executionContext);
+
+        listenerQueue.join(1 * 60 * 1000);
+
+        listenerQueue.stopListenerQueue();
+
+    }
+
+    public void cancelJob(ExecutionContext executionContext) throws Exception {
+
+        ListenerQueue listenerQueue = ListenerQueue.getInstance();
+        listenerQueue.startListenerQueue();
+
+        SecurityContext context = new SecurityContext(executionContext.getUserName(), executionContext.getPassword());
+        context.login();
+
+        JobPersistenceManager jobPersistenceManager
+                = new DBJobPersistenceManager(getDbUtil());
+        GramJobSubmissionManager gramJobSubmissionManager
+                = new GramJobSubmissionManager(jobPersistenceManager);
+
+        executionContext.addGramJobNotifier(new GramJobLogger());
+
+        executionContext.setHost("trestles");
+
+        String jobId = gramJobSubmissionManager.executeJob(context.getRawCredential(),
+                executionContext.getTrestlesGRAM(),
+                executionContext);
+
+        Thread.sleep(30 * 1000);
+
+        Assert.assertNotNull(jobId);
+
+        gramJobSubmissionManager.cancelJob(jobId);
+
+
+        logger.info("========== End of test case ==============");
+
+        listenerQueue.join(1 * 30 * 1000);
+
+        listenerQueue.stopListenerQueue();
+    }
+
+
+    public static ExecutionContext getDefaultExecutionContext() throws Exception {
+
+        return new ExecutionContext();
+    }
+}
diff --git a/grid-tools/gram-client/src/test/java/org/apache/airavata/jobsubmission/gram/LoneStarGramTest.java b/grid-tools/gram-client/src/test/java/org/apache/airavata/jobsubmission/gram/LoneStarGramTest.java
new file mode 100644 (file)
index 0000000..52b8b1d
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ *
+ * 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.gram;
+
+import org.apache.airavata.jobsubmission.gram.notifier.GramJobLogger;
+
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 6/19/13
+ * Time: 3:56 PM
+ */
+
+public class LoneStarGramTest extends GramJobSubmissionManagerTest {
+
+
+    // Dummy test case just avoid failures
+    public void testDummy() {}
+
+    public void xtestExecuteJobLoneStarInteractive() throws Exception {
+
+        ExecutionContext executionContext = getDefaultExecutionContext();
+
+        executionContext.setHost("lonestar");
+
+        executionContext.setInteractive(true);
+        executionContext.addGramJobNotifier(new GramJobLogger());
+
+        executeJob(executionContext);
+    }
+
+    public void xtestMonitoringRunningJobsLoneStar() throws Exception {
+
+        ExecutionContext executionContext = getDefaultExecutionContext();
+
+        executionContext.setHost("lonestar");
+
+        executionContext.setInteractive(true);
+        executionContext.addGramJobNotifier(new GramJobLogger());
+
+        monitoringRunningJobs(executionContext);
+    }
+
+    public void xtestCancelJobsLoneStar() throws Exception {
+
+        ExecutionContext executionContext = getDefaultExecutionContext();
+
+        executionContext.setHost("lonestar");
+
+        executionContext.setInteractive(true);
+        executionContext.addGramJobNotifier(new GramJobLogger());
+
+        cancelJob(executionContext);
+    }
+
+
+}
diff --git a/grid-tools/gram-client/src/test/java/org/apache/airavata/jobsubmission/gram/StampedeGramTest.java b/grid-tools/gram-client/src/test/java/org/apache/airavata/jobsubmission/gram/StampedeGramTest.java
new file mode 100644 (file)
index 0000000..b8c0bdb
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ *
+ * 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.gram;
+
+import org.apache.airavata.jobsubmission.gram.notifier.GramJobLogger;
+
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 6/19/13
+ * Time: 3:56 PM
+ */
+
+public class StampedeGramTest extends GramJobSubmissionManagerTest {
+
+    // ====================== Stampede ==============================//
+
+    public void testExecuteJobStampedeInteractive() throws Exception {
+
+        ExecutionContext executionContext = getDefaultExecutionContext();
+
+        executionContext.setHost("stampede");
+
+        executionContext.setInteractive(true);
+        executionContext.addGramJobNotifier(new GramJobLogger());
+
+        executeJob(executionContext);
+    }
+
+    public void testMonitoringRunningJobsStampede() throws Exception {
+
+        ExecutionContext executionContext = getDefaultExecutionContext();
+
+        executionContext.setHost("stampede");
+
+        executionContext.setInteractive(true);
+        executionContext.addGramJobNotifier(new GramJobLogger());
+
+        monitoringRunningJobs(executionContext);
+    }
+
+    public void testCancelJobsStampede() throws Exception {
+
+        ExecutionContext executionContext = getDefaultExecutionContext();
+
+        executionContext.setHost("stampede");
+
+        executionContext.setInteractive(true);
+        executionContext.addGramJobNotifier(new GramJobLogger());
+
+        cancelJob(executionContext);
+    }
+
+}
diff --git a/grid-tools/gram-client/src/test/java/org/apache/airavata/jobsubmission/gram/TrestlesGramTest.java b/grid-tools/gram-client/src/test/java/org/apache/airavata/jobsubmission/gram/TrestlesGramTest.java
new file mode 100644 (file)
index 0000000..3fc1eb0
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ *
+ * 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.gram;
+
+import org.apache.airavata.jobsubmission.gram.notifier.GramJobLogger;
+
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 6/19/13
+ * Time: 3:54 PM
+ */
+
+public class TrestlesGramTest extends GramJobSubmissionManagerTest {
+
+    // ====================== Trestles ==============================//
+
+    public void testExecuteJobTrestlesInteractive() throws Exception {
+
+        ExecutionContext executionContext = getDefaultExecutionContext();
+
+        executionContext.setHost("trestles");
+
+        executionContext.setInteractive(true);
+        executionContext.addGramJobNotifier(new GramJobLogger());
+
+        executeJob(executionContext);
+    }
+
+    public void testMonitoringRunningJobsTrestles() throws Exception {
+
+        ExecutionContext executionContext = getDefaultExecutionContext();
+
+        executionContext.setHost("trestles");
+
+        executionContext.setInteractive(true);
+        executionContext.addGramJobNotifier(new GramJobLogger());
+
+        monitoringRunningJobs(executionContext);
+    }
+
+    public void testCancelJobsTrestles() throws Exception {
+
+        ExecutionContext executionContext = getDefaultExecutionContext();
+
+        executionContext.setHost("trestles");
+
+        executionContext.setInteractive(true);
+        executionContext.addGramJobNotifier(new GramJobLogger());
+
+        cancelJob(executionContext);
+    }
+}
diff --git a/grid-tools/gram-client/src/test/resources/airavata-myproxy-client.properties b/grid-tools/gram-client/src/test/resources/airavata-myproxy-client.properties
new file mode 100644 (file)
index 0000000..600dad9
--- /dev/null
@@ -0,0 +1,7 @@
+#Download trusted certificates from - https://software.xsede.org/security/xsede-certs.tar.gz
+trustedCertsFile=/Users/thejaka/development/apache/airavata/sandbox/grid-tools/gridftp-client/certificates
+myproxyServer=myproxy.teragrid.org
+myproxy_lifetime=17280000
+myproxyUserName=
+myproxyPasswd=
+myproxyPort=7512