Author: mattmann
Date: Mon Aug 31 06:19:37 2015
New Revision: 1700204

URL: http://svn.apache.org/r1700204
Log:
OODT-246 Give user the ability to print a detailed report on what jobs in the 
Resource Manager are running on what nodes contributed by Gabe Resneck, mattmann

Added:
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/cli/action/GetExecReportCliAction.java
Modified:
    oodt/trunk/CHANGES.txt
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/batchmgr/Batchmgr.java
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/batchmgr/XmlRpcBatchMgr.java
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/mux/QueueMuxBatchManager.java
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManager.java
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManagerClient.java
    oodt/trunk/resource/src/main/resources/cmd-line-actions.xml
    oodt/trunk/resource/src/main/resources/cmd-line-options.xml
    
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/mocks/MockBatchManager.java

Modified: oodt/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/oodt/trunk/CHANGES.txt?rev=1700204&r1=1700203&r2=1700204&view=diff
==============================================================================
--- oodt/trunk/CHANGES.txt (original)
+++ oodt/trunk/CHANGES.txt Mon Aug 31 06:19:37 2015
@@ -2,6 +2,9 @@ Apache OODT Change Log
 ======================
 Release 0.10 - Current Development
 
+* OODT-246 Give user the ability to print a detailed report on what jobs in 
+  the Resource Manager are running on what nodes (Gabe Resneck, mattmann)
+
 * OODT-245 List results from the Resource Manager client should be sorted 
   alphabetically (Gabe Resneck via mattmann)
 

Modified: 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/batchmgr/Batchmgr.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/batchmgr/Batchmgr.java?rev=1700204&r1=1700203&r2=1700204&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/batchmgr/Batchmgr.java
 (original)
+++ 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/batchmgr/Batchmgr.java
 Mon Aug 31 06:19:37 2015
@@ -27,6 +27,7 @@ import org.apache.oodt.cas.resource.stru
 
 //java imports
 import java.net.URL;
+import java.util.List;
 
 /**
  * @author woollard
@@ -87,5 +88,11 @@ public interface Batchmgr {
      * @return
      */
     public String getExecutionNode(String jobId);
+    
+    /**
+     * Get a list of the ids of all jobs that are executing on the given node. 
+     * @return A list of ids of jobs on the given node
+     */
+    public List getJobsOnNode(String nodeId);
 
 }

Modified: 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/batchmgr/XmlRpcBatchMgr.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/batchmgr/XmlRpcBatchMgr.java?rev=1700204&r1=1700203&r2=1700204&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/batchmgr/XmlRpcBatchMgr.java
 (original)
+++ 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/batchmgr/XmlRpcBatchMgr.java
 Mon Aug 31 06:19:37 2015
@@ -30,8 +30,12 @@ import org.apache.oodt.cas.resource.stru
 import org.apache.oodt.cas.resource.structs.exceptions.MonitorException;
 
 //JDK imports
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
+import java.util.Vector;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -139,6 +143,23 @@ public class XmlRpcBatchMgr implements B
         XmlRpcBatchMgrProxy proxy = new XmlRpcBatchMgrProxy(spec, node, this);
         return proxy.killJob();
     }
+    
+    public List getJobsOnNode(String nodeId){
+       Vector<String> jobIds = new Vector();
+       
+       if(this.nodeToJobMap.size() > 0){
+               for(Iterator i = this.nodeToJobMap.keySet().iterator(); 
i.hasNext(); ){
+                       String jobId = (String)i.next();
+                       if(nodeId.equals(this.nodeToJobMap.get(jobId))){
+                               jobIds.add(jobId);
+                       }
+               }
+       }
+       
+       Collections.sort(jobIds); // sort the list to return as a courtesy to 
the user
+       
+       return jobIds;
+    }
 
     protected void notifyMonitor(ResourceNode node, JobSpec jobSpec) {
         Job job = jobSpec.getJob();

Added: 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/cli/action/GetExecReportCliAction.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/cli/action/GetExecReportCliAction.java?rev=1700204&view=auto
==============================================================================
--- 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/cli/action/GetExecReportCliAction.java
 (added)
+++ 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/cli/action/GetExecReportCliAction.java
 Mon Aug 31 06:19:37 2015
@@ -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.oodt.cas.resource.cli.action;
+
+//JDK imports
+import java.util.List;
+
+//OODT imports
+import org.apache.oodt.cas.cli.exception.CmdLineActionException;
+
+/**
+ * A {@link CmdLineAction} which list all jobs executing and shows 
+ * what nodes are executing those jobs in addition to queue name and
+ * load value.
+ * 
+ */
+public class GetExecReportCliAction extends ResourceCliAction {
+
+   @Override
+   public void execute(ActionMessagePrinter printer)
+         throws CmdLineActionException {
+      try {
+         String report = getClient().getExecReport();
+         printer.println("Exec Report: ");
+         printer.println(report);
+         printer.println();
+      } catch (Exception e) {
+         throw new CmdLineActionException("Failed to get exec report: "
+               + e.getMessage(), e);
+      }
+   }
+}

Modified: 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/mux/QueueMuxBatchManager.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/mux/QueueMuxBatchManager.java?rev=1700204&r1=1700203&r2=1700204&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/mux/QueueMuxBatchManager.java
 (original)
+++ 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/mux/QueueMuxBatchManager.java
 Mon Aug 31 06:19:37 2015
@@ -17,6 +17,7 @@
 
 package org.apache.oodt.cas.resource.mux;
 
+import java.util.List;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.logging.Level;
@@ -26,6 +27,7 @@ import org.apache.oodt.cas.resource.batc
 import org.apache.oodt.cas.resource.jobrepo.JobRepository;
 import org.apache.oodt.cas.resource.monitor.Monitor;
 import org.apache.oodt.cas.resource.structs.JobSpec;
+import org.apache.oodt.cas.resource.structs.Job;
 import org.apache.oodt.cas.resource.structs.ResourceNode;
 import org.apache.oodt.cas.resource.structs.exceptions.JobExecutionException;
 import org.apache.oodt.cas.resource.structs.exceptions.QueueManagerException;
@@ -84,6 +86,11 @@ public class QueueMuxBatchManager implem
         throw new UnsupportedOperationException("Cannot set the monitor when 
using the queue-mux batch manager.");
     }
 
+    @Override
+    public List<Job> getJobsOnNode(String nodeId) {
+        throw new UnsupportedOperationException("Method not supported: get 
Jobs on Node.");
+    }
+
     /* (non-Javadoc)
      * @see 
org.apache.oodt.cas.resource.batchmgr.Batchmgr#setJobRepository(org.apache.oodt.cas.resource.jobrepo.JobRepository)
      */

Modified: 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManager.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManager.java?rev=1700204&r1=1700203&r2=1700204&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManager.java
 (original)
+++ 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManager.java
 Mon Aug 31 06:19:37 2015
@@ -387,6 +387,47 @@ public class XmlRpcResourceManager {
        return report;
     }
     
+    public String getExecutionReport() throws JobRepositoryException{
+       String report = new String();
+       
+       try{
+       
+               // get a sorted list of all nodes, since the report should be
+               // alphabetically sorted by node
+               List resNodes = scheduler.getMonitor().getNodes();
+               if(resNodes.size() == 0){
+                       throw new MonitorException(
+                                       "No jobs can be executing, as there are 
no nodes in the Monitor");
+               }
+               Vector<String> nodeIds = new Vector<String>();
+               for(Iterator i = resNodes.iterator(); i.hasNext(); ){
+                       nodeIds.add(((ResourceNode)i.next()).getNodeId());
+               }
+               Collections.sort(nodeIds);
+               
+               // generate the report string
+               for(String nodeId: nodeIds){
+                       List execJobIds = 
this.scheduler.getBatchmgr().getJobsOnNode(nodeId);
+                       if(execJobIds != null && execJobIds.size() > 0){
+                               for(Iterator i = execJobIds.iterator(); 
i.hasNext(); ){
+                                       String jobId = (String)i.next();
+                                       Job job = 
scheduler.getJobQueue().getJobRepository()
+                                                       
.getJobById(jobId).getJob();
+                                       report += "job id=" + jobId;
+                                       report += ", load=" + 
job.getLoadValue();
+                                       report += ", node=" + nodeId;
+                                       report += ", queue=" + 
job.getQueueName() + "\n";
+                               }
+                       }
+               }
+       
+       }catch(Exception e){
+               throw new JobRepositoryException(e.getMessage(), e);
+       }
+       
+       return report;
+    }
+    
     public static void main(String[] args) throws Exception {
         int portNum = -1;
         String usage = "XmlRpcResourceManager --portNum <port number for xml 
rpc service>\n";

Modified: 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManagerClient.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManagerClient.java?rev=1700204&r1=1700203&r2=1700204&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManagerClient.java
 (original)
+++ 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManagerClient.java
 Mon Aug 31 06:19:37 2015
@@ -513,6 +513,18 @@ public class XmlRpcResourceManagerClient
    }
 
 
+    public String getExecReport() throws JobRepositoryException{
+       String report = null;
+       
+       try{
+           report = (String)client.execute("resourcemgr.getExecutionReport", 
new Vector<Object>());
+       }catch(Exception e){
+           throw new JobRepositoryException(e.getMessage(), e);
+       }
+       
+       return report;
+  }   
+
   public static String getReadableJobStatus(String status) {
     if (status.equals(JobStatus.SUCCESS)) {
       return "SUCCESS";

Modified: oodt/trunk/resource/src/main/resources/cmd-line-actions.xml
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/resources/cmd-line-actions.xml?rev=1700204&r1=1700203&r2=1700204&view=diff
==============================================================================
--- oodt/trunk/resource/src/main/resources/cmd-line-actions.xml (original)
+++ oodt/trunk/resource/src/main/resources/cmd-line-actions.xml Mon Aug 31 
06:19:37 2015
@@ -66,6 +66,10 @@
                 
class="org.apache.oodt.cas.resource.cli.action.GetQueuedJobsCliAction">
                 <property name="description" value="Gets list of jobs 
currently in the queue" />
         </bean>
+        <bean id="getExecReport"
+                
class="org.apache.oodt.cas.resource.cli.action.GetExecReportCliAction">
+                <property name="description" value="Gets list of jobs 
currently in the queue" />
+        </bean>
         <bean id="getNodeReport"
                 
class="org.apache.oodt.cas.resource.cli.action.GetNodeReportCliAction">
                 <property name="description" value="Gets name (all nodes will 
be displayed in alphabetical order), load and capacity of all nodes, and their 
queues." />

Modified: oodt/trunk/resource/src/main/resources/cmd-line-options.xml
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/resources/cmd-line-options.xml?rev=1700204&r1=1700203&r2=1700204&view=diff
==============================================================================
--- oodt/trunk/resource/src/main/resources/cmd-line-options.xml (original)
+++ oodt/trunk/resource/src/main/resources/cmd-line-options.xml Mon Aug 31 
06:19:37 2015
@@ -59,6 +59,8 @@
                                         p:option-ref="getQueuedJobs" 
p:required="false" />
                                <bean 
class="org.apache.oodt.cas.cli.option.GroupSubOption"
                                        p:option-ref="getNodeReport" 
p:required="false"/>
+                                <bean 
class="org.apache.oodt.cas.cli.option.GroupSubOption"
+                                        p:option-ref="getExecReport" 
p:required="false"/>
                                <bean 
class="org.apache.oodt.cas.cli.option.GroupSubOption"
                                        p:option-ref="addNode" 
p:required="false" />
                                <bean 
class="org.apache.oodt.cas.cli.option.GroupSubOption"
@@ -640,5 +642,22 @@
                         </list>
                 </property>
         </bean>
-
+        <bean id="getExecReport" 
class="org.apache.oodt.cas.cli.option.ActionCmdLineOption"
+                p:isSubOption="true">
+                <property name="shortOption" value="ereport" />
+                <property name="longOption" value="getExecReport" />
+                <property name="description" value="Triggers getExecReport 
Action" />
+                <property name="hasArgs" value="false" />
+                <property name="staticArgs">
+                        <list>
+                                <value>getExecReport</value>
+                        </list>
+                </property>
+                <property name="requirementRules">
+                        <list>
+                                <bean 
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+                                      p:actionName="getExecReport" 
p:relation="REQUIRED" />
+                        </list>
+                </property>
+        </bean>
 </beans>

Modified: 
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/mocks/MockBatchManager.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/mocks/MockBatchManager.java?rev=1700204&r1=1700203&r2=1700204&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/mocks/MockBatchManager.java
 (original)
+++ 
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/mocks/MockBatchManager.java
 Mon Aug 31 06:19:37 2015
@@ -16,10 +16,12 @@
  */
 package org.apache.oodt.cas.resource.mux.mocks;
 
+import java.util.List;
 import org.apache.oodt.cas.resource.batchmgr.Batchmgr;
 import org.apache.oodt.cas.resource.jobrepo.JobRepository;
 import org.apache.oodt.cas.resource.monitor.Monitor;
 import org.apache.oodt.cas.resource.structs.JobSpec;
+import org.apache.oodt.cas.resource.structs.Job;
 import org.apache.oodt.cas.resource.structs.ResourceNode;
 import org.apache.oodt.cas.resource.structs.exceptions.JobExecutionException;
 /**
@@ -48,6 +50,11 @@ public class MockBatchManager implements
     public void setJobRepository(JobRepository repository) {}
 
     @Override
+    public List<Job> getJobsOnNode(String nodeId){
+       throw new UnsupportedOperationException("method not implemented. 
getJobsOnNode");
+    }
+
+    @Override
     public boolean killJob(String jobId, ResourceNode node) {
         if (this.execJobSpec.getJob().getId().equals(jobId))
         {
@@ -62,6 +69,7 @@ public class MockBatchManager implements
     public String getExecutionNode(String jobId) {
         return execResNode.getNodeId();
     }
+
     /*****
      * The following are test methods to report what jobs are here.
      *****/


Reply via email to