Repository: oodt
Updated Branches:
  refs/heads/master 6c58b743a -> 6409d7103


fix for OODT-918: Created a prerequisite workflow condition for DRAT 
contributed by Karanjeet Singh this closes #35


Project: http://git-wip-us.apache.org/repos/asf/oodt/repo
Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/6409d710
Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/6409d710
Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/6409d710

Branch: refs/heads/master
Commit: 6409d7103115f49355be1e54fbeb184c092748bd
Parents: 6c58b74
Author: Chris Mattmann <[email protected]>
Authored: Fri Nov 13 22:05:17 2015 -0800
Committer: Chris Mattmann <[email protected]>
Committed: Fri Nov 13 22:05:17 2015 -0800

----------------------------------------------------------------------
 CHANGES.txt                                     |   3 +
 .../examples/PrerequisiteCondition.java         |  97 ++++++++++++++++++
 .../workflow/examples/ResmgrJobCondition.java   | 100 +++++++++++++++++++
 3 files changed, 200 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oodt/blob/6409d710/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 4178835..d003f88 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,9 @@ Apache OODT Change Log
 ======================
 Release 0.11 - Current Development
 
+* OODT-918 - Created a prerequisite workflow condition for DRAT (Karanjeet
+  Singh via mattmann)
+
 * OODT-913 Multiple metadata values not written out into product-types.xml 
(luca)
 
 * ODT-862 Include the Workflow ID as part of the standard metadata (luca)

http://git-wip-us.apache.org/repos/asf/oodt/blob/6409d710/workflow/src/main/java/org/apache/oodt/cas/workflow/examples/PrerequisiteCondition.java
----------------------------------------------------------------------
diff --git 
a/workflow/src/main/java/org/apache/oodt/cas/workflow/examples/PrerequisiteCondition.java
 
b/workflow/src/main/java/org/apache/oodt/cas/workflow/examples/PrerequisiteCondition.java
new file mode 100644
index 0000000..254896e
--- /dev/null
+++ 
b/workflow/src/main/java/org/apache/oodt/cas/workflow/examples/PrerequisiteCondition.java
@@ -0,0 +1,97 @@
+/*
+ * 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.oodt.cas.workflow.examples;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Iterator;
+
+//OODT imports
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.resource.structs.Job;
+import org.apache.oodt.cas.resource.structs.exceptions.JobQueueException;
+import org.apache.oodt.cas.resource.system.XmlRpcResourceManagerClient;
+import org.apache.oodt.cas.workflow.structs.WorkflowConditionConfiguration;
+import org.apache.oodt.cas.workflow.structs.WorkflowConditionInstance;
+
+/**
+ * @author singhk
+ * @version $Revision$
+ *
+ * <p>A Simple condition that evaluates to false as many times as the 
prerequisite job in Resource Manager
+ * isn't completed. After that, the condition returns
+ * true.</p>
+ *
+ */
+public class PrerequisiteCondition implements WorkflowConditionInstance {
+
+       public PrerequisiteCondition() {
+               super();
+       }
+       
+       /**
+        * Check if there is any job queued in Resource Manager with name 
equivalent to <code>jobName</code>
+        * @param client
+        * @param jobName
+        * @return true if job is present, otherwise false
+        */
+       @SuppressWarnings("unchecked")
+       private boolean isJobPresentInQueue(XmlRpcResourceManagerClient client, 
String jobName){
+               Iterator<Job> iter;
+               try {
+                       iter = (Iterator<Job>)client.getQueuedJobs().iterator();
+                       while(iter.hasNext()){
+                               Job job = iter.next();
+                               if(job.getName().equals(jobName))
+                                       return true;
+                       }
+               } catch (JobQueueException e) {
+                       e.printStackTrace();
+               }
+               return false;
+       }
+
+       /* (non-Javadoc)
+        * @see 
org.apache.oodt.cas.workflow.structs.WorkflowConditionInstance#evaluate(org.apache.oodt.cas.metadata.Metadata)
+        */
+    public boolean evaluate(Metadata metadata, WorkflowConditionConfiguration 
config) {
+               
+               String[] jobs = (config.getProperty("JOBS")).split(",");
+               String resourceManagerUrl = config.getProperty("RESMGR_URL");
+               boolean flag = true;
+
+               System.out.println(new Date() + " PrerequisiteCondition: Jobs: 
"+ Arrays.toString(jobs));
+               System.out.println(new Date() + " PrerequisiteCondition: 
Resource Manager: "+ resourceManagerUrl);
+               
+               XmlRpcResourceManagerClient client = null;
+               try {
+                       client = new XmlRpcResourceManagerClient(new 
URL(resourceManagerUrl));
+                       flag = true;
+                       for (String job : jobs)
+                               flag = flag && !isJobPresentInQueue(client, 
job);
+                       if(flag)
+                               return true;
+               } catch (MalformedURLException e) {
+                       e.printStackTrace();
+               }
+               return false;
+       }
+}

http://git-wip-us.apache.org/repos/asf/oodt/blob/6409d710/workflow/src/main/java/org/apache/oodt/cas/workflow/examples/ResmgrJobCondition.java
----------------------------------------------------------------------
diff --git 
a/workflow/src/main/java/org/apache/oodt/cas/workflow/examples/ResmgrJobCondition.java
 
b/workflow/src/main/java/org/apache/oodt/cas/workflow/examples/ResmgrJobCondition.java
new file mode 100644
index 0000000..78ec8e0
--- /dev/null
+++ 
b/workflow/src/main/java/org/apache/oodt/cas/workflow/examples/ResmgrJobCondition.java
@@ -0,0 +1,100 @@
+/*
+ * 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.oodt.cas.workflow.examples;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.logging.Logger;
+
+//OODT imports
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.resource.structs.Job;
+import org.apache.oodt.cas.resource.structs.exceptions.JobQueueException;
+import org.apache.oodt.cas.resource.system.XmlRpcResourceManagerClient;
+import org.apache.oodt.cas.workflow.structs.WorkflowConditionConfiguration;
+import org.apache.oodt.cas.workflow.structs.WorkflowConditionInstance;
+
+/**
+ * @author singhk
+ * @version $Revision$
+ *
+ * <p>A Simple condition that evaluates to false as many times as the 
prerequisite job in Resource Manager
+ * isn't completed. After that, the condition returns
+ * true.</p>
+ *
+ */
+public class ResmgrJobCondition implements WorkflowConditionInstance {
+
+       private static final Logger LOG = 
Logger.getLogger(ResmgrJobCondition.class.getName());
+       
+       public ResmgrJobCondition() {
+               super();
+       }
+       
+       /**
+        * Check if there is any job queued in Resource Manager with name 
equivalent to <code>jobName</code>
+        * @param client
+        * @param jobName
+        * @return true if job is present, otherwise false
+        */
+       @SuppressWarnings("unchecked")
+       private boolean isJobPresentInQueue(XmlRpcResourceManagerClient client, 
String jobName){
+               Iterator<Job> iter;
+               try {
+                       iter = (Iterator<Job>)client.getQueuedJobs().iterator();
+                       while(iter.hasNext()){
+                               Job job = iter.next();
+                               if(job.getName().equals(jobName))
+                                       return true;
+                       }
+               } catch (JobQueueException e) {
+                       e.printStackTrace();
+               }
+               return false;
+       }
+
+       /* (non-Javadoc)
+        * @see 
org.apache.oodt.cas.workflow.structs.WorkflowConditionInstance#evaluate(org.apache.oodt.cas.metadata.Metadata)
+        */
+    public boolean evaluate(Metadata metadata, WorkflowConditionConfiguration 
config) {
+               
+               String[] jobs = (config.getProperty("JOBS")).split(",");
+               String resourceManagerUrl = config.getProperty("RESMGR_URL");
+               boolean flag = true;
+
+               LOG.info(new Date() + " PrerequisiteCondition: Jobs: "+ 
Arrays.toString(jobs));
+               LOG.info(new Date() + " PrerequisiteCondition: Resource 
Manager: "+ resourceManagerUrl);
+               
+               XmlRpcResourceManagerClient client = null;
+               try {
+                       client = new XmlRpcResourceManagerClient(new 
URL(resourceManagerUrl));
+                       flag = true;
+                       for (String job : jobs)
+                               flag = flag && !isJobPresentInQueue(client, 
job);
+                       if(flag)
+                               return true;
+               } catch (MalformedURLException e) {
+                       e.printStackTrace();
+               }
+               return false;
+       }
+}

Reply via email to