committing Shabhaz patches to scratch, from https://issues.apache.org/jira/browse...
authorLahiru Gunathilake <lahiru@apache.org>
Mon, 21 Jan 2013 16:37:52 +0000 (16:37 +0000)
committerLahiru Gunathilake <lahiru@apache.org>
Mon, 21 Jan 2013 16:37:52 +0000 (16:37 +0000)
git-svn-id: https://svn.apache.org/repos/asf/airavata/sandbox@1436470 13f79535-47bb-0310-9956-ffa450edef68

grid-tools/bes-client/src/main/java/org/apache/airavata/sample/bes/AbstractJobCommand.java [new file with mode: 0644]
grid-tools/bes-client/src/main/java/org/apache/airavata/sample/bes/CreateAndTerminateActivityTask.java [new file with mode: 0644]
grid-tools/bes-client/src/main/java/org/apache/airavata/sample/bes/MonitorJobStatusTask.java [new file with mode: 0644]
grid-tools/bes-client/src/main/java/org/apache/airavata/sample/bes/RunAndTerminateJob.java [new file with mode: 0644]
grid-tools/bes-client/src/test/resources/fsp.xml [new file with mode: 0644]
grid-tools/bes-client/src/test/resources/sleep.xml [new file with mode: 0644]

diff --git a/grid-tools/bes-client/src/main/java/org/apache/airavata/sample/bes/AbstractJobCommand.java b/grid-tools/bes-client/src/main/java/org/apache/airavata/sample/bes/AbstractJobCommand.java
new file mode 100644 (file)
index 0000000..fb2a116
--- /dev/null
@@ -0,0 +1,36 @@
+package org.apache.airavata.sample.bes;
+
+import de.fzj.unicore.uas.security.ClientProperties;
+import eu.unicore.security.util.client.IClientProperties;
+
+public abstract class AbstractJobCommand {
+       
+       
+       
+       public static final String factoryUrl = "https://zam1161v01.zam.kfa-juelich.de:8002/INTEROP1/services/BESFactory?res=default_bes_factory";
+       public static final String dateJsdlPath = "src/test/resources/date.xml";
+       
+       protected IClientProperties securityProperties;
+       
+       
+       public AbstractJobCommand() {
+               securityProperties = initSecurityProperties();
+       }
+       
+       protected ClientProperties initSecurityProperties() {
+
+               ClientProperties sp = new ClientProperties();
+
+               sp.setSslEnabled(true);
+               sp.setSignMessage(true);
+
+               sp.setKeystore("src/test/resources/demo-keystore.jks");
+               sp.setKeystorePassword("654321");
+               sp.setKeystoreAlias("demouser-new");
+               sp.setKeystoreType("JKS");
+
+               return sp;
+
+       }
+       
+}
diff --git a/grid-tools/bes-client/src/main/java/org/apache/airavata/sample/bes/CreateAndTerminateActivityTask.java b/grid-tools/bes-client/src/main/java/org/apache/airavata/sample/bes/CreateAndTerminateActivityTask.java
new file mode 100644 (file)
index 0000000..5d69c76
--- /dev/null
@@ -0,0 +1,79 @@
+package org.apache.airavata.sample.bes;
+
+import java.util.Calendar;
+
+import org.ggf.schemas.bes.x2006.x08.besFactory.ActivityStateEnumeration;
+import org.ggf.schemas.bes.x2006.x08.besFactory.CreateActivityDocument;
+import org.ggf.schemas.bes.x2006.x08.besFactory.CreateActivityResponseDocument;
+import org.ggf.schemas.bes.x2006.x08.besFactory.TerminateActivitiesResponseType;
+import org.w3.x2005.x08.addressing.EndpointReferenceType;
+
+import de.fzj.unicore.bes.client.FactoryClient;
+import de.fzj.unicore.wsrflite.xmlbeans.WSUtilities;
+import eu.unicore.security.util.client.IClientProperties;
+
+public class CreateAndTerminateActivityTask {
+
+       private BESJob job;
+
+       private IClientProperties sec;
+       private String jobId;
+       
+       
+       public CreateAndTerminateActivityTask(BESJob job, IClientProperties sec) {
+               this.job = job;
+               this.sec = sec;
+               
+       }
+
+       public void startJob() throws Exception {
+               String factoryUrl = job.getFactoryUrl();
+               EndpointReferenceType eprt = EndpointReferenceType.Factory
+                               .newInstance();
+               eprt.addNewAddress().setStringValue(factoryUrl);
+               System.out.println("========================================");
+               System.out.println(String.format("Job Submitted to %s.\n", factoryUrl));
+               FactoryClient factory = new FactoryClient(eprt, sec);
+               CreateActivityDocument cad = CreateActivityDocument.Factory
+                               .newInstance();
+               cad.addNewCreateActivity().addNewActivityDocument()
+                               .setJobDefinition(job.getJobDoc().getJobDefinition());
+               CreateActivityResponseDocument response = factory.createActivity(cad);
+               EndpointReferenceType activityEpr = response
+                               .getCreateActivityResponse().getActivityIdentifier();
+               jobId = WSUtilities.extractResourceID(activityEpr);
+               if (jobId == null) {
+                       jobId = new Long(Calendar.getInstance().getTimeInMillis())
+                                       .toString();
+               }
+               
+               String status;
+               
+               status = String.format("Job %s is %s.\n", activityEpr.getAddress()
+                               .getStringValue(), factory.getActivityStatus(activityEpr)
+                               .toString()).toString();
+               
+               System.out.println(status);
+               
+               TerminateActivitiesResponseType terminateResType = factory.terminateActivity(activityEpr);
+               
+               Thread.sleep(500);
+               System.out.println(terminateResType);
+
+               if (!(factory.getActivityStatus(activityEpr) == ActivityStateEnumeration.CANCELLED)) {
+                       throw new Exception("Job "+activityEpr.getAddress().getStringValue()+" not CANCELLED");
+               }
+               
+               status = String.format("Job %s is %s.\n", activityEpr.getAddress()
+                               .getStringValue(), factory.getActivityStatus(activityEpr)
+                               .toString()).toString();
+               
+               System.out.println(status);
+               
+
+               
+       }
+
+       
+
+}
diff --git a/grid-tools/bes-client/src/main/java/org/apache/airavata/sample/bes/MonitorJobStatusTask.java b/grid-tools/bes-client/src/main/java/org/apache/airavata/sample/bes/MonitorJobStatusTask.java
new file mode 100644 (file)
index 0000000..168fd55
--- /dev/null
@@ -0,0 +1,26 @@
+package org.apache.airavata.sample.bes;
+
+import org.w3.x2005.x08.addressing.EndpointReferenceType;
+
+import de.fzj.unicore.wsrflite.xmlbeans.WSUtilities;
+
+import eu.unicore.security.util.client.IClientProperties;
+
+public class MonitorJobStatusTask {
+       
+       private String factoryUrl;
+       private EndpointReferenceType jobEPR;
+       private IClientProperties sec;
+       
+       public MonitorJobStatusTask(String factoryUrl, IClientProperties sec, EndpointReferenceType jobEPR) {
+               this.factoryUrl = factoryUrl;
+               this.jobEPR = jobEPR;
+               this.sec = sec; 
+       }
+       
+       
+       
+       
+
+       
+}
diff --git a/grid-tools/bes-client/src/main/java/org/apache/airavata/sample/bes/RunAndTerminateJob.java b/grid-tools/bes-client/src/main/java/org/apache/airavata/sample/bes/RunAndTerminateJob.java
new file mode 100644 (file)
index 0000000..c1be1e0
--- /dev/null
@@ -0,0 +1,36 @@
+package org.apache.airavata.sample.bes;
+
+import java.io.File;
+
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionDocument;
+
+public class RunAndTerminateJob extends AbstractJobCommand {
+
+       public RunAndTerminateJob() {
+               super();
+       }
+
+       public void runAndTerminate(){
+               JobDefinitionDocument jobDoc = null;
+               try {
+                       jobDoc = JobDefinitionDocument.Factory.parse(new File(dateJsdlPath));
+               } catch (Exception e) {
+                       System.err.println("Error parsing JSDL instance. " + e);
+               }
+
+               BESJob job = new BESJob();
+               job.setFactory(factoryUrl);
+               job.setJobDoc(jobDoc);
+
+               CreateAndTerminateActivityTask th = new CreateAndTerminateActivityTask(job, securityProperties);
+               try {
+                       th.startJob();
+               } catch (Exception e) {
+
+                       System.err.println("Couldn't run job: " + e);
+               }
+       }
+       
+
+}
+
diff --git a/grid-tools/bes-client/src/test/resources/fsp.xml b/grid-tools/bes-client/src/test/resources/fsp.xml
new file mode 100644 (file)
index 0000000..55b9bac
--- /dev/null
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<p:JobDefinition xmlns:p="http://schemas.ggf.org/jsdl/2005/11/jsdl"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://schemas.ggf.org/jsdl/2005/11/jsdl jsdl.xsd ">
+       <p:JobDescription>
+               <p:Application>
+                       <POSIXApplication xmlns="http://schemas.ggf.org/jsdl/2005/11/jsdl-posix">
+                               <Executable>/bin/date;/bin/cat</Executable>
+                               <Argument>input.txt</Argument>
+                               <Output>stdout.txt</Output>
+                               <Error>stderr.txt</Error>
+                       </POSIXApplication>
+               </p:Application>
+               <p:DataStaging>
+                       <p:FileName>input.txt</p:FileName>
+                       <p:CreationFlag>overwrite</p:CreationFlag>
+                       <p:Source>
+                               <p:URI>ftp://host.name:8004/hello.txt
+                               </p:URI>
+                       </p:Source>
+                       <ac:Credential xmlns:ac="http://schemas.ogf.org/hpcp/2007/11/ac">
+                               <wsse:UsernameToken
+                                       xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
+                                       <wsse:Username>myuser</wsse:Username>
+                                       <wsse:Password>mypass</wsse:Password>
+                               </wsse:UsernameToken>
+                       </ac:Credential>
+               </p:DataStaging>
+               <p:DataStaging>
+                       <p:FileName>input.txt</p:FileName>
+                       <p:CreationFlag>overwrite</p:CreationFlag>
+                       <p:Target>
+                               <p:URI>ftp://host.name:8004/input.txt</p:URI>
+                       </p:Target>
+                       <ac:Credential xmlns:ac="http://schemas.ogf.org/hpcp/2007/11/ac">
+                               <wsse:UsernameToken
+                                       xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
+                                       <wsse:Username>myuser</wsse:Username>
+                                       <wsse:Password>mypass</wsse:Password>
+                               </wsse:UsernameToken>
+                       </ac:Credential>
+               </p:DataStaging>
+               <p:DataStaging>
+                       <p:FileName>stderr.txt</p:FileName>
+                       <p:CreationFlag>overwrite</p:CreationFlag>
+                       <p:Target>
+                               <!-- replace gridsam with your middleware client - arc clients : ftp://zam1161v01.zam.kfa-juelich.de:8004/ogf27/arc/test__9_200.out 
+                                       - genesis clients : ftp://zam1161v01.zam.kfa-juelich.de:8004/ogf27/genesis/test__9_200.out -->
+                               <p:URI>ftp://host.name:8004/stderr.txt</p:URI>
+                       </p:Target>
+                       <ac:Credential xmlns:ac="http://schemas.ogf.org/hpcp/2007/11/ac">
+                               <wsse:UsernameToken
+                                       xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
+                                       <wsse:Username>myuser</wsse:Username>
+                                       <wsse:Password>mypass</wsse:Password>
+                               </wsse:UsernameToken>
+                       </ac:Credential>
+               </p:DataStaging>
+               <p:DataStaging>
+                       <p:FileName>stdout.txt</p:FileName>
+                       <p:CreationFlag>overwrite</p:CreationFlag>
+                       <!-- replace gridsam with your middleware client - arc clients : ftp://zam1161v01.zam.kfa-juelich.de:8004/ogf27/arc/test__9_200.out 
+                               - genesis clients : ftp://zam1161v01.zam.kfa-juelich.de:8004/ogf27/genesis/test__9_200.out -->
+
+                       <p:Target>
+                               <p:URI>ftp://host.name:8004/stdout.txt</p:URI>
+                       </p:Target>
+                       <ac:Credential xmlns:ac="http://schemas.ogf.org/hpcp/2007/11/ac">
+                               <wsse:UsernameToken
+                                       xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
+                                       <wsse:Username>myuser</wsse:Username>
+                                       <wsse:Password>mypass</wsse:Password>
+                               </wsse:UsernameToken>
+                       </ac:Credential>
+               </p:DataStaging>
+       </p:JobDescription>
+</p:JobDefinition>
\ No newline at end of file
diff --git a/grid-tools/bes-client/src/test/resources/sleep.xml b/grid-tools/bes-client/src/test/resources/sleep.xml
new file mode 100644 (file)
index 0000000..046652f
--- /dev/null
@@ -0,0 +1,10 @@
+<JobDefinition xmlns="http://schemas.ggf.org/jsdl/2005/11/jsdl" xmlns:jsdl="http://schemas.ggf.org/jsdl/2005/11/jsdl-posix" xmlns:ac="http://schemas.ogf.org/hpcp/2007/11/ac" xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
+  <JobDescription>
+    <Application>
+      <jsdl:POSIXApplication>
+        <jsdl:Executable>/bin/sleep</jsdl:Executable>
+        <jsdl:Argument>10000</jsdl:Argument>
+      </jsdl:POSIXApplication>
+    </Application>
+  </JobDescription>
+</JobDefinition>
\ No newline at end of file