Author: mattmann
Date: Sun Sep 14 15:44:19 2014
New Revision: 1624863

URL: http://svn.apache.org/r1624863
Log:
- fix for OODT-669 Make Resource Manager work without Ganglia

Added:
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/utils/
      - copied from r1623586, 
oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/monitor/utils/
Removed:
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ResourceMonitor.java
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ResourceMonitorFactory.java
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/exceptions/
    oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/monitor/utils/
    oodt/trunk/resource/src/testdata/resourcemon/nodes.xml
Modified:
    oodt/trunk/CHANGES.txt
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/AssignmentMonitor.java
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/AssignmentMonitorFactory.java
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaAdapter.java
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaMetKeys.java
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaResourceMonitor.java
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaResourceMonitorFactory.java
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/loadcalc/LoadCalculator.java
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/loadcalc/WeightedAverageLoadCalc.java
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/utils/MockGmetad.java
    
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/util/GenericResourceManagerObjectFactory.java
    
oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/monitor/TestAssignmentMonitor.java
    
oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/monitor/TestGangliaResourceMonitor.java
    
oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/monitor/TestGangliaXMLParser.java
    oodt/trunk/resource/src/testdata/policy/nodes.xml
    oodt/trunk/resource/src/testdata/test.resource.properties

Modified: oodt/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/oodt/trunk/CHANGES.txt?rev=1624863&r1=1624862&r2=1624863&view=diff
==============================================================================
--- oodt/trunk/CHANGES.txt (original)
+++ oodt/trunk/CHANGES.txt Sun Sep 14 15:44:19 2014
@@ -4,6 +4,8 @@ Apache OODT Change Log
 Release 0.7 - Current Development
 -------------------------------------------- 
 
+* OODT-669 Make Resource Manager work without Ganglia (mattmann, rajith)
+
 * OODT-644 Fix to FTP protocol tests, abstracting some of the logic to make 
the code better suited to mocking(magicaltrout)
 
 * OODT-644 Fix to stub FTP client protocol so it doesn't fail when the port is 
in use

Modified: 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/AssignmentMonitor.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/AssignmentMonitor.java?rev=1624863&r1=1624862&r2=1624863&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/AssignmentMonitor.java
 (original)
+++ 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/AssignmentMonitor.java
 Sun Sep 14 15:44:19 2014
@@ -15,7 +15,6 @@
  * limitations under the License.
  */
 
-
 package org.apache.oodt.cas.resource.monitor;
 
 //JDK imports
@@ -23,19 +22,18 @@ import java.net.URL;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Vector;
-import java.util.logging.Logger;
 
 //OODT imports
 import org.apache.oodt.cas.resource.structs.ResourceNode;
 import org.apache.oodt.cas.resource.structs.exceptions.MonitorException;
 
 /**
- *
+ * 
  * @author woollard
  * @author bfoster
- * @author rajith
+ * @author mattmann
  * @version $Revision$
- *
+ * 
  * <p>
  * An implementation of the {@link Monitor} interface that loads its 
information
  * about the underlying nodes from an XML file called <code>nodes.xml</code>.
@@ -44,23 +42,20 @@ import org.apache.oodt.cas.resource.stru
  * </p>
  */
 public class AssignmentMonitor implements Monitor {
-
-    /* our log stream */
-    private static Logger LOG = Logger.getLogger(AssignmentMonitor.class
-            .getName());
-
+       
     /* our nodes map */
     private static HashMap<String, ResourceNode> nodesMap;
 
-    /* resource monitor */
-    private ResourceMonitor resourceMonitor;
+    /* our load map */
+    private static HashMap<String, Integer> loadMap;
 
-    public AssignmentMonitor(List<ResourceNode> nodes, ResourceMonitor 
resourceMonitor) {
+    public AssignmentMonitor(List<ResourceNode> nodes) {
         nodesMap = new HashMap<String, ResourceNode>();
-        this.resourceMonitor = resourceMonitor;
-
+        loadMap = new HashMap<String, Integer>();
+        
         for (ResourceNode node : nodes) {
             nodesMap.put(node.getNodeId(), node);
+            loadMap.put(node.getNodeId(), new Integer(0));
         }
     }
 
@@ -70,27 +65,30 @@ public class AssignmentMonitor implement
      * @see gov.nasa.jpl.oodt.cas.resource.monitor.Monitor#assignLoad(
      *      gov.nasa.jpl.oodt.cas.resource.structs.ResourceNode, int)
      */
+    @Override
     public boolean assignLoad(ResourceNode node, int loadValue)
             throws MonitorException {
-        float loadVal = (float) loadValue;
-        float loadCap = (float) node.getCapacity();
-        float curLoad = resourceMonitor.getLoad(node);
+        int loadCap = node.getCapacity();
+        int curLoad = loadMap.get(node.getNodeId());
 
-        if (loadVal <= (loadCap - curLoad)) {
-            resourceMonitor.updateLoad(node.getNodeId(), curLoad + loadVal);
+        if (loadValue <= (loadCap - curLoad)) {
+            loadMap.remove(node.getNodeId());
+            loadMap.put(node.getNodeId(), new Integer(curLoad + loadValue));
             return true;
         } else {
             return false;
         }
     }
 
+    @Override
     public boolean reduceLoad(ResourceNode node, int loadValue)
             throws MonitorException {
-        float load = resourceMonitor.getLoad(node);
-        float newVal = load - (float)loadValue;
+        int load = loadMap.get(node.getNodeId());
+        int newVal = load - loadValue;
         if (newVal < 0)
             newVal = 0; // should not happen but just in case
-        resourceMonitor.updateLoad(node.getNodeId(), newVal);
+        loadMap.remove(node.getNodeId());
+        loadMap.put(node.getNodeId(), new Integer(newVal));
         return true;
     }
 
@@ -101,9 +99,8 @@ public class AssignmentMonitor implement
      */
     public int getLoad(ResourceNode node) throws MonitorException {
         ResourceNode resource = (ResourceNode) nodesMap.get(node.getNodeId());
-//        Integer i = (Integer) loadMap.get(node.getNodeId());
-        float load = resourceMonitor.getLoad(node);
-        return (int) ((float) resource.getCapacity() - load);
+        int i = loadMap.get(node.getNodeId());
+        return (resource.getCapacity() - i);
     }
 
     /*
@@ -143,12 +140,12 @@ public class AssignmentMonitor implement
 
     public void addNode(ResourceNode node) throws MonitorException {
         nodesMap.put(node.getNodeId(), node);
-        resourceMonitor.addNode(node.getNodeId(), node.getCapacity());
+        if (!loadMap.containsKey(node.getNodeId()))
+            loadMap.put(node.getNodeId(), new Integer(0));
     }
 
     public void removeNodeById(String nodeId) throws MonitorException {
-        nodesMap.remove(nodeId);
-        resourceMonitor.removeNodeById(nodeId);
+        nodesMap.remove(nodeId);    
+        loadMap.remove(nodeId);
     }
-
 }

Modified: 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/AssignmentMonitorFactory.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/AssignmentMonitorFactory.java?rev=1624863&r1=1624862&r2=1624863&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/AssignmentMonitorFactory.java
 (original)
+++ 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/AssignmentMonitorFactory.java
 Sun Sep 14 15:44:19 2014
@@ -19,24 +19,22 @@
 package org.apache.oodt.cas.resource.monitor;
 
 //OODT imports
-import org.apache.oodt.cas.resource.structs.ResourceNode;
+import org.apache.oodt.cas.resource.noderepo.XmlNodeRepositoryFactory;
 import org.apache.oodt.cas.resource.util.GenericResourceManagerObjectFactory;
 
 //JDK imports
-import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 /**
  * @author woollard
  * @author bfoster
- * @author rajith
  * @version $Revision$
- *
+ * 
  * <p>
  * Creates implementations of {@link AssignmentMonitor}s.
  * </p>
- *
+ * 
  */
 public class AssignmentMonitorFactory implements MonitorFactory {
 
@@ -52,16 +50,11 @@ public class AssignmentMonitorFactory im
     public AssignmentMonitor createMonitor() {
         try {
             String nodeRepoFactoryStr = System.getProperty(
-                    "org.apache.oodt.cas.resource.nodes.repo.factory");
-            String resourceMonitorStr = System
-                    
.getProperty("org.apache.oodt.cas.resource.monitor.factory");
-
-            List<ResourceNode> resourceNodes = 
GenericResourceManagerObjectFactory
-                    
.getNodeRepositoryFromFactory(nodeRepoFactoryStr).loadNodes();
-            ResourceMonitor resourceMonitor = 
GenericResourceManagerObjectFactory
-                    .getResourceMonitorFromServiceFactory(resourceMonitorStr);
-
-            return new AssignmentMonitor(resourceNodes, resourceMonitor);
+                    "gov.nasa.jpl.oodt.cas.resource.nodes.repo.factory",
+                    XmlNodeRepositoryFactory.class.getCanonicalName());
+            return new AssignmentMonitor(GenericResourceManagerObjectFactory
+                    .getNodeRepositoryFromFactory(nodeRepoFactoryStr)
+                    .loadNodes());
         } catch (Exception e) {
             LOG.log(Level.SEVERE, "Failed to create Assignment Monitor : "
                     + e.getMessage(), e);

Modified: 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaAdapter.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaAdapter.java?rev=1624863&r1=1624862&r2=1624863&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaAdapter.java
 (original)
+++ 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaAdapter.java
 Sun Sep 14 15:44:19 2014
@@ -17,13 +17,15 @@
 
 package org.apache.oodt.cas.resource.monitor.ganglia;
 
-import org.apache.oodt.cas.resource.monitor.exceptions.GangliaMonitorException;
+//OODT imports
 import org.apache.oodt.cas.resource.monitor.ganglia.configuration.Cluster;
 import org.apache.oodt.cas.resource.monitor.ganglia.configuration.Host;
 import org.apache.oodt.cas.resource.monitor.ganglia.configuration.Metric;
+import org.apache.oodt.cas.resource.structs.exceptions.MonitorException;
+
+//JDK imports
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
-
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParserFactory;
 import java.io.BufferedReader;
@@ -34,65 +36,81 @@ import java.net.Socket;
 import java.net.UnknownHostException;
 import java.util.HashMap;
 import java.util.List;
-import java.util.Set;
+import java.util.Map;
 
 /**
  * @author rajith
+ * @author mattmann
  * @version $Revision$
  */
 public class GangliaAdapter {
 
-    private static String ENCODING = "ISO-8859-1";
+    private static final String ENCODING = "ISO-8859-1";
 
+    private String host;
+    
+    private int port;
+    
+    
+    public GangliaAdapter(String host, int port){
+               this.host = host;
+               this.port = port;
+    }
+
+    protected GangliaAdapter(){
+       this(null, -9999);
+    }
+    
     /**
      * Get resource nodes' status.
-     * @return List that contains status of resource nodes
-     * @throws 
org.apache.oodt.cas.resource.monitor.exceptions.GangliaMonitorException {@link 
org.apache.oodt.cas.resource.monitor.exceptions.GangliaMonitorException} if an 
error occurred.
+     * @return Map that contains status of resource nodes
+     * @throws 
org.apache.oodt.cas.resource.monitor.exceptions.MonitorException if an error 
occurred.
      */
-    public static HashMap<String, HashMap> getResourceNodeStatus(Set 
requiredNodes)
-            throws GangliaMonitorException {
-        String host = System
-                
.getProperty("org.apache.oodt.cas.resource.monitor.ganglia.gemtad.host.address");
-        int port = Integer.valueOf(System
-                
.getProperty("org.apache.oodt.cas.resource.monitor.ganglia.gemtad.host.port"));
-
-        List<Cluster> gridStatus = parseConfiguration(readXMLDump(host, port));
-        return filterRequiredNodes(requiredNodes, gridStatus);
+    public Map<String, Map<String,String>> getResourceNodeStatus()
+            throws MonitorException {
+        List<Cluster> gridStatus = parseConfiguration(readXMLDump(this.host, 
this.port));
+        return filterNodes(gridStatus);
+    }
+    
+    /**
+     * 
+     * @return A string representation of the {@link #host}:{@link #port}
+     */
+    public String getUrlString(){
+       return this.host+":"+this.port;
     }
 
     /**
-     * Filter out the required nodes from the grid state ganglia configuration
-     * @param requiredNodes the required nodes
+     * Filter out the nodes from the grid state ganglia configuration
      * @param gridStatus Ganglia meta daemon parsed grid status
-     * @return filtered resource node HashMap
+     * @return resource node Map
      */
-    private static HashMap<String, HashMap> filterRequiredNodes (Set 
requiredNodes,
-                                                                 List<Cluster> 
gridStatus){
+    private Map<String, Map<String,String>> filterNodes (List<Cluster> 
gridStatus){
 
-        HashMap<String, HashMap> filteredNodes = new HashMap<String, 
HashMap>();
+        Map<String, Map<String,String>> nodes = new HashMap<String, 
Map<String,String>>();
         for (Cluster cluster : gridStatus) {
             for (Host host : cluster.getHosts()) {
-                if(requiredNodes.contains(host.getName())){
-                    HashMap<String, String> metrics = new HashMap<String, 
String>();
+                    Map<String, String> metrics = new HashMap<String, 
String>();
                     for (Metric metric : host.getMetrics()) {
                         metrics.put(metric.getName(), metric.getValue());
                     }
                     metrics.put(GangliaMetKeys.TN,host.getTn());
                     metrics.put(GangliaMetKeys.TMAX, host.getTmax());
-                    filteredNodes.put(host.getName(), metrics);
-                }
+                    metrics.put(GangliaMetKeys.IP, host.getIp());
+                    metrics.put(GangliaMetKeys.NAME, host.getName());
+                    nodes.put(host.getName(), metrics);
             }
         }
-        return filteredNodes;
+        return nodes;
     }
 
     /**
      * Get a XML dump from a ganglia meta daemon.
      * @return A String that contains all the dump
-     * @throws 
org.apache.oodt.cas.resource.monitor.exceptions.GangliaMonitorException {@link 
org.apache.oodt.cas.resource.monitor.exceptions.GangliaMonitorException}
+     * @throws 
org.apache.oodt.cas.resource.monitor.exceptions.MonitorException {@link 
org.apache.oodt.cas.resource.monitor.exceptions.MonitorException}
      * if an error occurred during the read.
      */
-    private static String readXMLDump(String host, int port) throws 
GangliaMonitorException {
+    private String readXMLDump(String host, int port) throws MonitorException {
         StringBuilder buffer = new StringBuilder();
 
         try {
@@ -106,10 +124,10 @@ public class GangliaAdapter {
             }
             reader.close();
         } catch (UnknownHostException e) {
-            throw new GangliaMonitorException
+            throw new MonitorException
                     ("Unknown host: " + host + ":" + port + "-" + 
e.getMessage());
         } catch (IOException e) {
-            throw new GangliaMonitorException
+            throw new MonitorException
                     ("Unable to get the monitoring report from the GMeta 
daemon: "
                             + e.getMessage());
         }
@@ -120,10 +138,10 @@ public class GangliaAdapter {
      * Parse a configuration from a XML output of a Ganglia meta daemon.
      * @param buffer the XML buffer
      * @return a Configuration
-     * @throws 
org.apache.oodt.cas.resource.monitor.exceptions.GangliaMonitorException {@link 
org.apache.oodt.cas.resource.monitor.exceptions.GangliaMonitorException} if an 
error occurred
+     * @throws 
org.apache.oodt.cas.resource.monitor.exceptions.MonitorException {@link 
org.apache.oodt.cas.resource.monitor.exceptions.MonitorException} if an error 
occurred
      */
-    private static List<Cluster> parseConfiguration(String buffer)
-            throws GangliaMonitorException {
+    private List<Cluster> parseConfiguration(String buffer)
+            throws MonitorException {
         SAXParserFactory factory = SAXParserFactory.newInstance();
         javax.xml.parsers.SAXParser parser;
         GangliaXMLParser gangliaXMLParser;
@@ -133,11 +151,11 @@ public class GangliaAdapter {
             parser.parse(new InputSource(new StringReader(buffer)), 
gangliaXMLParser);
 
         } catch (ParserConfigurationException e) {
-            throw new GangliaMonitorException("Error while parsing: " + 
e.getMessage());
+            throw new MonitorException("Error while parsing: " + 
e.getMessage());
         } catch (SAXException e) {
-            throw new GangliaMonitorException("Error while parsing the XML: " 
+ e.getMessage());
+            throw new MonitorException("Error while parsing the XML: " + 
e.getMessage());
         } catch (IOException e) {
-            throw new GangliaMonitorException("I/O error: " + e.getMessage());
+            throw new MonitorException("I/O error: " + e.getMessage());
         }
         return gangliaXMLParser.getGridConfiguration();
     }

Modified: 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaMetKeys.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaMetKeys.java?rev=1624863&r1=1624862&r2=1624863&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaMetKeys.java
 (original)
+++ 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaMetKeys.java
 Sun Sep 14 15:44:19 2014
@@ -23,6 +23,7 @@ package org.apache.oodt.cas.resource.mon
  */
 public interface GangliaMetKeys {
 
+       /* XML specific keys */
     public static final String CLUSTER = "CLUSTER";
     public static final String HOST = "HOST";
     public static final String METRIC = "METRIC";
@@ -54,6 +55,16 @@ public interface GangliaMetKeys {
     public static final String OWNER = "OWNER";
     public static final String LATLONG = "LATLONG";
     public static final String URL = "URL";
+    
+    /*Ganglia metric keys*/
+    public static String LOAD_ONE = "load_one";
+    public static String LOAD_FIVE = "load_five";
+    public static String LOAD_FIFTEEN = "load_fifteen";
+    public static String CPU_NUM = "cpu_num";
+
+    /* Various needed keys */
+    public static int MAXIMUM_FRACTION_DIGITS = 3;
+
 
 
 }

Modified: 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaResourceMonitor.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaResourceMonitor.java?rev=1624863&r1=1624862&r2=1624863&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaResourceMonitor.java
 (original)
+++ 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaResourceMonitor.java
 Sun Sep 14 15:44:19 2014
@@ -17,113 +17,258 @@
 
 package org.apache.oodt.cas.resource.monitor.ganglia;
 
-import org.apache.oodt.cas.resource.monitor.ResourceMonitor;
-import org.apache.oodt.cas.resource.monitor.exceptions.GangliaMonitorException;
+//OODT imports
+import org.apache.oodt.cas.resource.monitor.Monitor;
 import org.apache.oodt.cas.resource.monitor.ganglia.loadcalc.LoadCalculator;
 import org.apache.oodt.cas.resource.structs.ResourceNode;
+import org.apache.oodt.cas.resource.structs.exceptions.MonitorException;
+import static org.apache.oodt.cas.resource.monitor.ganglia.GangliaMetKeys.NAME;
 
+//JDK imports
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Vector;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 /**
  * @author rajith
+ * @author mattmann
  * @version $Revision$
  */
-public class GangliaResourceMonitor implements ResourceMonitor {
+public class GangliaResourceMonitor implements Monitor {
 
-    private static final Logger LOG = 
Logger.getLogger(GangliaResourceMonitor.class.getName());
-
-    /*loadMap will be updated after a UPDATE_INTERVAL milliseconds interval*/
-    private static long UPDATE_INTERVAL = 60000;
-
-    private static HashMap<String, Float> nodeCapacityMap = new 
HashMap<String, Float>();
-    private static HashMap<String, Float> loadMap = new HashMap<String, 
Float>();
-
-    private LoadCalculator loadCalculator;
-    private long lastUpdatedTime;
-
-    /**
-     * Make a new GangliaResourceMonitor that reads information
-     * from a ganglia meta daemon.
-     * @param loadCalculator LoadCalculator {@link 
org.apache.oodt.cas.resource.monitor.ganglia.loadcalc.LoadCalculator} to 
calculate load
-     * @param nodes resource nodes {@link 
org.apache.oodt.cas.resource.structs.ResourceNode} to be monitored.
-     */
-    public GangliaResourceMonitor(LoadCalculator loadCalculator, 
List<ResourceNode> nodes){
-        this.loadCalculator = loadCalculator;
-
-        for (ResourceNode node : nodes) {
-            nodeCapacityMap.put(node.getNodeId(), (float) node.getCapacity());
-        }
-        // Initially set the value UPDATE_INTERVAL earlier.
-        lastUpdatedTime = System.currentTimeMillis() - UPDATE_INTERVAL;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public float getLoad(ResourceNode node) {
-        try {
-            if(lastUpdatedTime + UPDATE_INTERVAL <= 
(System.currentTimeMillis())){
-                updateLoadMap();
-            }
-            return loadMap.get(node.getNodeId());
-        } catch (GangliaMonitorException e) {
-            LOG.log(Level.SEVERE, "Failed get status from the Ganglia meta 
daemon : "
-                    + e.getMessage(), e);
-            return nodeCapacityMap.get(node.getNodeId()); //return the 
capacity as the load of the node
-        } catch (NullPointerException e){
-            LOG.log(Level.SEVERE, "The required nodeId is not available: "
-                    + node.getNodeId() + " :" + e.getMessage(), e);
-            return (float) node.getCapacity(); //return node's if the nodeId 
is not available.
-        } catch (Exception e){
-            LOG.log(Level.SEVERE, "Failed get status from the Ganglia meta 
daemon for the nodeId: "
-                    + node.getNodeId() + " :" + e.getMessage(), e);
-            return nodeCapacityMap.get(node.getNodeId()); //return the 
capacity as the load of the node
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void updateLoad(String nodeId, float loadValue) {
-        loadMap.put(nodeId, loadValue);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void addNode(String nodeId, float capacity) {
-        nodeCapacityMap.put(nodeId, capacity);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void removeNodeById(String nodeId) {
-        nodeCapacityMap.remove(nodeId);
-        loadMap.remove(nodeId);
-    }
-
-    /**
-     * Update the loadMap by calculating the load by the LoadCalculator
-     * @throws 
org.apache.oodt.cas.resource.monitor.exceptions.GangliaMonitorException {@link 
org.apache.oodt.cas.resource.monitor.exceptions.GangliaMonitorException} if an 
error occurred
-     */
-    private void updateLoadMap() throws GangliaMonitorException {
-        lastUpdatedTime = System.currentTimeMillis();
-        HashMap<String, HashMap> resourceNodesMetrics = GangliaAdapter
-                .getResourceNodeStatus(nodeCapacityMap.keySet());
-
-        for (Map.Entry<String, HashMap> entry: 
resourceNodesMetrics.entrySet()){
-            loadMap.put(entry.getKey(), loadCalculator.calculateLoad(
-                    nodeCapacityMap.get(entry.getKey()), 
resourceNodesMetrics.get(entry.getKey())));
-        }
-    }
+       private static final Logger LOG = Logger
+                       .getLogger(GangliaResourceMonitor.class.getName());
+       private LoadCalculator loadCalculator;
+       private Map<String, Integer> loadMap;
+       private Map<String, Map<String, String>> gmetaNodes;
+       private Map<String, GangliaAdapter> gmetaAdapters;
+       private static final int DEFAULT_PORT = 8649;
+
+       /**
+        * Make a new GangliaResourceMonitor that reads information from a 
ganglia
+        * meta daemon.
+        * 
+        * @param loadCalculator
+        *            LoadCalculator
+        *            {@link 
org.apache.oodt.cas.resource.monitor.ganglia.loadcalc.LoadCalculator}
+        *            to calculate load
+        * @param nodes
+        *            resource nodes
+        *            {@link org.apache.oodt.cas.resource.structs.ResourceNode} 
to
+        *            be monitored.
+        */
+       public GangliaResourceMonitor(LoadCalculator loadCalculator,
+                       String gmetadHost, int gmetadPort) {
+               this.loadCalculator = loadCalculator;
+               this.loadMap = new HashMap<String, Integer>();
+               this.gmetaNodes = new HashMap<String, Map<String, String>>();
+               this.gmetaAdapters = new HashMap<String, GangliaAdapter>();
+               try {
+                       this.initGmetaNodes(gmetadHost, gmetadPort);
+               } catch (Exception e) {
+                       e.printStackTrace();
+                       LOG.log(Level.WARNING,
+                                       "URL exception initializing gmetad 
nodes: [" + gmetadHost
+                                                       + ":" + gmetadPort + 
"]: Message: "
+                                                       + e.getMessage());
+               }
+
+       }
+
+       @Override
+       public int getLoad(ResourceNode node) throws MonitorException {
+               Map<String, String> nodeProperties = null;
+               String nodeId = node.getNodeId();
+               nodeProperties = this.locateNode(nodeId);
+               if (nodeProperties == null) {
+                       throw new MonitorException(
+                                       "GangliaMonitor: not tracking requested 
node: [" + nodeId
+                                                       + "]");
+               }
+
+               // calculate load
+               double calcLoad = 
this.loadCalculator.calculateLoad(nodeProperties);
+               System.out.println(calcLoad);
+               int load = new Long(Math.round(calcLoad)).intValue();
+               System.out.println("LOAD is: "+load);
+               return load;
+       }
+
+       @Override
+       public boolean assignLoad(ResourceNode node, int loadValue)
+                       throws MonitorException {
+               // technically this method should simply do nothing, since
+               // putting a job onto a node should cause Ganglia to detect
+               // for now we'll simply track what the current perceived load
+               // on a node is - we may want to factor this into the weighting
+               // in load calculator later
+               String nodeId = node.getNodeId();
+               if (loadMap.containsKey(nodeId)) {
+                       int currLoad = loadMap.get(nodeId);
+                       currLoad += loadValue;
+                       loadMap.put(nodeId, currLoad);
+               } else {
+                       loadMap.put(nodeId, loadValue);
+               }
+               return true;
+       }
+
+       @Override
+       public void addNode(ResourceNode node) {
+               this.addGmetadNode(node.getIpAddr().getHost(), node.getIpAddr()
+                               .getPort());
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public void removeNodeById(String nodeId) {
+               this.removeGmetadNode(nodeId);
+       }
+
+       @Override
+       public List getNodes() throws MonitorException {
+               List<ResourceNode> nodes = new Vector<ResourceNode>();
+               if (this.gmetaAdapters != null) {
+                       for (GangliaAdapter adapter : 
this.gmetaAdapters.values()) {
+                               Map<String, Map<String, String>> aNodes = 
adapter
+                                               .getResourceNodeStatus();
+                               for (Map<String, String> map : aNodes.values()) 
{
+                                       try {
+                                               
nodes.add(this.nodeFromMap(map));
+                                       } catch (MalformedURLException e) {
+                                               e.printStackTrace();
+                                               throw new 
MonitorException(e.getMessage());
+                                       }
+                               }
+                       }
+               }
+
+               return nodes;
+       }
+
+       @Override
+       public ResourceNode getNodeById(String nodeId) throws MonitorException {
+               try {
+                       return this.nodeFromMap(this.locateNode(nodeId));
+               } catch (MalformedURLException e) {
+                       e.printStackTrace();
+                       throw new MonitorException(e.getMessage());
+               }
+       }
+
+       @Override
+       public ResourceNode getNodeByURL(URL ipAddr) throws MonitorException {
+               if (this.gmetaAdapters != null) {
+                       for (GangliaAdapter adapter : 
this.gmetaAdapters.values()) {
+                               Map<String, Map<String, String>> aNodes = 
adapter
+                                               .getResourceNodeStatus();
+                               for (String aNodeId : aNodes.keySet()) {
+                                       String host = ipAddr.getHost();
+                                       int port = ipAddr.getPort();
+                                       Map<String, String> nodeProps = 
aNodes.get(aNodeId);
+                                       if (aNodeId.equals(host)
+                                                       && 
nodeProps.get(DEFAULT_PORT).equals(
+                                                                       
String.valueOf(port))) {
+                                               try {
+                                                       return 
this.nodeFromMap(aNodes.get(aNodeId));
+                                               } catch (MalformedURLException 
e) {
+                                                       e.printStackTrace();
+                                                       throw new 
MonitorException(e.getMessage());
+                                               }
+                                       }
+                               }
+                       }
+               }
+
+               return null;
+       }
+
+       @Override
+       public boolean reduceLoad(ResourceNode node, int loadValue)
+                       throws MonitorException {
+               String nodeId = node.getNodeId();
+               if (this.loadMap.containsKey(nodeId)) {
+                       int currLoad = loadMap.get(nodeId);
+                       currLoad = Math.min(0, currLoad - loadValue);
+                       this.loadMap.put(nodeId, currLoad);
+               } else {
+                       this.loadMap.put(nodeId, 0);
+               }
+               
+               return true;
+       }
+
+       private Map<String, String> locateNode(String nodeId) {
+               if (this.gmetaAdapters != null && this.gmetaAdapters.size() > 
0) {
+                       for (String nId : this.gmetaAdapters.keySet()) {
+                               GangliaAdapter adapter = 
this.gmetaAdapters.get(nId);
+                               try {
+                                       System.out.println("Querying gmetad: 
["+adapter.getUrlString()+"]");
+                                       Map<String, Map<String, String>> 
nodeStatus = adapter
+                                                       
.getResourceNodeStatus();
+                                       System.out.println("Looking for nodeid: 
["+nodeId+"]");
+                                       if (nodeStatus.containsKey(nodeId)) {
+                                               System.out.println("NODE met: 
"+nodeStatus.get(nodeId));
+                                               return nodeStatus.get(nodeId);
+                                       }
+                               } catch (MonitorException e) {
+                                       LOG.log(Level.WARNING,
+                                                       "MonitorException 
contacting Ganglia: ["
+                                                                       + 
adapter.getUrlString() + "]");
+                                       e.printStackTrace();
+                               }
+                       }
+
+               }
+
+               return null;
+       }
+
+       private ResourceNode nodeFromMap(Map<String, String> map)
+                       throws MalformedURLException {
+               if (map == null) return null;
+               ResourceNode node = new ResourceNode();
+               System.out.println("MAP IS "+map);
+               System.out.println("Setting hostname to "+map.get(NAME));
+               node.setId(map.get(NAME));
+               node.setIpAddr(new URL("http://"; + map.get(NAME) + ":" + 
DEFAULT_PORT));
+               return node;
+       }
+
+       private void initGmetaNodes(String host, int port)
+                       throws MalformedURLException {
+               this.addGmetadNode(host, port);
+       }
+
+       private GangliaAdapter createAdapter(Map<String, String> node) {
+               return new GangliaAdapter(node.get("host"), Integer.valueOf(node
+                               .get("port")));
+       }
+
+       private void addGmetadNode(String host, int port) {
+               Map<String, String> rootNode = new HashMap<String, String>();
+               rootNode.put("host", host);
+               rootNode.put("port", String.valueOf(port));
+               this.gmetaNodes.put(host, rootNode);
+               this.gmetaAdapters.put(host, this.createAdapter(rootNode));
+       }
+
+       private void removeGmetadNode(String host) {
+               if (this.gmetaNodes.containsKey(host)
+                               && this.gmetaAdapters.containsKey(host)) {
+                       LOG.log(Level.FINE,
+                                       "Removing gmetad node: ["
+                                                       + 
gmetaAdapters.get(host).getUrlString() + "]");
+                       this.gmetaAdapters.remove(host);
+                       this.gmetaNodes.remove(host);
+               }
+       }
 
 }

Modified: 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaResourceMonitorFactory.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaResourceMonitorFactory.java?rev=1624863&r1=1624862&r2=1624863&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaResourceMonitorFactory.java
 (original)
+++ 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/GangliaResourceMonitorFactory.java
 Sun Sep 14 15:44:19 2014
@@ -17,44 +17,52 @@
 
 package org.apache.oodt.cas.resource.monitor.ganglia;
 
-import org.apache.oodt.cas.resource.monitor.ResourceMonitor;
-import org.apache.oodt.cas.resource.monitor.ResourceMonitorFactory;
-import org.apache.oodt.cas.resource.monitor.ganglia.loadcalc.LoadCalculator;
-import org.apache.oodt.cas.resource.structs.ResourceNode;
-import org.apache.oodt.cas.resource.util.GenericResourceManagerObjectFactory;
-
+//JDK imports
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+
+
+//OODT imports
+import org.apache.oodt.cas.resource.monitor.Monitor;
+import org.apache.oodt.cas.resource.monitor.MonitorFactory;
+import org.apache.oodt.cas.resource.monitor.ganglia.loadcalc.LoadCalculator;
+import org.apache.oodt.cas.resource.structs.ResourceNode;
+import org.apache.oodt.cas.resource.util.GenericResourceManagerObjectFactory;
+
 /**
  * @author rajith
  * @version $Revision$
  */
-public class GangliaResourceMonitorFactory implements ResourceMonitorFactory {
+public class GangliaResourceMonitorFactory implements MonitorFactory {
+
+       private static final Logger LOG = Logger
+                       
.getLogger(GangliaResourceMonitorFactory.class.getName());
 
-    private static final Logger LOG = 
Logger.getLogger(GangliaResourceMonitorFactory.class.getName());
+       @Override
+       public Monitor createMonitor() {
+               try {
+                       String loadCalculatorFactoryStr = System
+                                       
.getProperty("org.apache.oodt.cas.resource.monitor.loadcalc.factory");
+                       String nodeRepoFactoryStr = System
+                                       
.getProperty("org.apache.oodt.cas.resource.nodes.repo.factory");
+                       
+                       String gmetadHost = System
+                     
.getProperty("org.apache.oodt.cas.resource.monitor.ganglia.gemtad.host.address");
+                       
+                       int gmetadPort = Integer.valueOf(System
+                               
.getProperty("org.apache.oodt.cas.resource.monitor.ganglia.gemtad.host.port"));
+
+                       LoadCalculator loadCalculator = 
GenericResourceManagerObjectFactory
+                                       
.getLoadCalculatorFromServiceFactory(loadCalculatorFactoryStr);
+
+                       return new GangliaResourceMonitor(loadCalculator, 
gmetadHost, gmetadPort);
+               } catch (Exception e) {
+                       LOG.log(Level.SEVERE,
+                                       "Failed to create Resource Monitor : " 
+ e.getMessage(), e);
+                       return null;
+               }
+       }
 
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public ResourceMonitor createResourceMonitor() {
-        try {
-            String loadCalculatorFactoryStr =  System
-                    
.getProperty("org.apache.oodt.cas.resource.monitor.loadcalc.factory");
-            String nodeRepoFactoryStr = System
-                    
.getProperty("org.apache.oodt.cas.resource.nodes.repo.factory");
-
-            List<ResourceNode> resourceNodes = 
GenericResourceManagerObjectFactory
-                    
.getNodeRepositoryFromFactory(nodeRepoFactoryStr).loadNodes();
-            LoadCalculator loadCalculator = GenericResourceManagerObjectFactory
-                    
.getLoadCalculatorFromServiceFactory(loadCalculatorFactoryStr);
-
-            return new GangliaResourceMonitor(loadCalculator, resourceNodes);
-        } catch (Exception e){
-            LOG.log(Level.SEVERE, "Failed to create Resource Monitor : " + 
e.getMessage(), e);
-            return null;
-        }
-    }
 }

Modified: 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/loadcalc/LoadCalculator.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/loadcalc/LoadCalculator.java?rev=1624863&r1=1624862&r2=1624863&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/loadcalc/LoadCalculator.java
 (original)
+++ 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/loadcalc/LoadCalculator.java
 Sun Sep 14 15:44:19 2014
@@ -17,29 +17,21 @@
 
 package org.apache.oodt.cas.resource.monitor.ganglia.loadcalc;
 
-import java.util.HashMap;
+//JDK imports
+import java.util.Map;
 
 /**
  * @author rajith
+ * @author mattmann
  * @version $Revision$
  */
 public interface LoadCalculator {
 
-    public static int MAXIMUM_FRACTION_DIGITS = 3;
-
-    /*Ganglia metric keys*/
-    public static String LOAD_ONE = "load_one";
-    public static String LOAD_FIVE = "load_five";
-    public static String LOAD_FIFTEEN = "load_fifteen";
-    public static String CPU_NUM = "cpu_num";
-
     /**
      * Calculate the load and normalize it within the given node's capacity
-     * @param nodeCapacity node's {@link 
org.apache.oodt.cas.resource.structs.ResourceNode}
-     *                     capacity
      * @param metrics status metrics of the resource node
      * @return An integer representation of the load within 0 and node's 
capacity
      */
-    public float calculateLoad(float nodeCapacity, HashMap<String, String> 
metrics);
+    public double calculateLoad(Map<String, String> metrics);
 
 }

Modified: 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/loadcalc/WeightedAverageLoadCalc.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/loadcalc/WeightedAverageLoadCalc.java?rev=1624863&r1=1624862&r2=1624863&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/loadcalc/WeightedAverageLoadCalc.java
 (original)
+++ 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/ganglia/loadcalc/WeightedAverageLoadCalc.java
 Sun Sep 14 15:44:19 2014
@@ -17,20 +17,29 @@
 
 package org.apache.oodt.cas.resource.monitor.ganglia.loadcalc;
 
-import org.apache.oodt.cas.resource.monitor.ganglia.GangliaMetKeys;
-
+//JDK imports
 import java.text.NumberFormat;
-import java.util.HashMap;
+import java.util.Map;
+
+//OODT imports
+import static 
org.apache.oodt.cas.resource.monitor.ganglia.GangliaMetKeys.MAXIMUM_FRACTION_DIGITS;
+import static org.apache.oodt.cas.resource.monitor.ganglia.GangliaMetKeys.TN;
+import static org.apache.oodt.cas.resource.monitor.ganglia.GangliaMetKeys.TMAX;
+import static 
org.apache.oodt.cas.resource.monitor.ganglia.GangliaMetKeys.CPU_NUM;
+import static 
org.apache.oodt.cas.resource.monitor.ganglia.GangliaMetKeys.LOAD_ONE;
+import static 
org.apache.oodt.cas.resource.monitor.ganglia.GangliaMetKeys.LOAD_FIVE;
+import static 
org.apache.oodt.cas.resource.monitor.ganglia.GangliaMetKeys.LOAD_FIFTEEN;
 
 /**
  * @author rajith
+ * @author mattmann
  * @version $Revision$
  */
 public class WeightedAverageLoadCalc implements LoadCalculator {
 
-    private int loadOneWeight;
-    private int loadFiveWeight;
-    private int loadFifteenWeight;
+    private double loadOneWeight;
+    private double loadFiveWeight;
+    private double loadFifteenWeight;
 
     /* to format the load value*/
     private NumberFormat numberFormat;
@@ -41,7 +50,7 @@ public class WeightedAverageLoadCalc imp
      * @param loadFiveWeight weight for the load_five
      * @param loadFifteenWeight weight for the load_fifteen
      */
-    public WeightedAverageLoadCalc (int loadOneWeight, int loadFiveWeight, int 
loadFifteenWeight){
+    public WeightedAverageLoadCalc (double loadOneWeight, double 
loadFiveWeight, double loadFifteenWeight){
         this.loadOneWeight = loadOneWeight;
         this.loadFiveWeight = loadFiveWeight;
         this.loadFifteenWeight = loadFifteenWeight;
@@ -53,34 +62,36 @@ public class WeightedAverageLoadCalc imp
      * {@inheritDoc}
      *
      * load is calculated as follows
-     * weightedLoadOne = loadOneWeight * minimum of (nodeCapacity, 
((loadOne/numOfCPUs) * nodeCapacity))
+     * weightedLoadOne = loadOneWeight * minimum of (numOfCPUs, 
((loadOne/numOfCPUs) * numOfCPUs))
      *
      * load = (weightedLoadOne + weightedLoadFive + weightedLoadFifteen) /
      *           (loadOneWeight + loadFiveWeight + loadFifteenWeight)
      */
     @Override
-    public float calculateLoad(float nodeCapacity, HashMap<String, String> 
nodeMetrics) {
-        int tn = Integer.valueOf(nodeMetrics.get(GangliaMetKeys.TN));
-        int tmax = Integer.valueOf(nodeMetrics.get(GangliaMetKeys.TMAX));
+    public double calculateLoad(Map<String, String> nodeMetrics) {
+        double tn = Double.valueOf(nodeMetrics.get(TN));
+        double tmax = Double.valueOf(nodeMetrics.get(TMAX));
+        double numCpus = Double.valueOf(nodeMetrics.get(CPU_NUM));
 
         if(tn > (4 * tmax)){
-           return nodeCapacity; //if the node is offline assign the node's 
capacity as the load
+           return numCpus; //if the node is offline assign the node's capacity 
as the load
         }
         else {
-            float weightedLoadOne = loadOneWeight * Math.min(nodeCapacity,
-                    ((Float.valueOf(nodeMetrics.get(LOAD_ONE)) /
-                            Float.valueOf(nodeMetrics.get(CPU_NUM))) * 
nodeCapacity));
-            float weightedLoadFive = loadFiveWeight * Math.min(nodeCapacity,
-                    ((Float.valueOf(nodeMetrics.get(LOAD_FIVE)) /
-                            Float.valueOf(nodeMetrics.get(CPU_NUM)))* 
nodeCapacity));
-            float weightedLoadFifteen = loadFifteenWeight * 
Math.min(nodeCapacity,
-                    ((Float.valueOf(nodeMetrics.get(LOAD_FIFTEEN)) /
-                            Float.valueOf(nodeMetrics.get(CPU_NUM)))* 
nodeCapacity));
+            double weightedLoadOne = loadOneWeight * Math.min(numCpus,
+                    ((Double.valueOf(nodeMetrics.get(LOAD_ONE)) /
+                            Double.valueOf(nodeMetrics.get(CPU_NUM))) * 
numCpus));
+            double weightedLoadFive = loadFiveWeight * Math.min(numCpus,
+                    ((Double.valueOf(nodeMetrics.get(LOAD_FIVE)) /
+                            Double.valueOf(nodeMetrics.get(CPU_NUM)))* 
numCpus));
+            double weightedLoadFifteen = loadFifteenWeight * Math.min(numCpus,
+                    ((Double.valueOf(nodeMetrics.get(LOAD_FIFTEEN)) /
+                            Double.valueOf(nodeMetrics.get(CPU_NUM)))* 
numCpus));
 
-            float weightedLoadAverage = (weightedLoadOne + weightedLoadFive + 
weightedLoadFifteen) /
+            double weightedLoadAverage = (weightedLoadOne + weightedLoadFive + 
weightedLoadFifteen) /
                     (loadOneWeight + loadFiveWeight + loadFifteenWeight);
-
-            return Float.valueOf(numberFormat.format(weightedLoadAverage));
+            
+            System.out.println("Weighted load one: ["+weightedLoadOne+"]: 
weighted load five: ["+weightedLoadFive+"] weighted load fifteen: 
["+weightedLoadFifteen+"]");
+            return Double.valueOf(numberFormat.format(weightedLoadAverage));
         }
     }
 }

Modified: 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/utils/MockGmetad.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/utils/MockGmetad.java?rev=1624863&r1=1623586&r2=1624863&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/utils/MockGmetad.java
 (original)
+++ 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/monitor/utils/MockGmetad.java
 Sun Sep 14 15:44:19 2014
@@ -17,12 +17,18 @@
 
 package org.apache.oodt.cas.resource.monitor.utils;
 
-import java.io.*;
+//JDK imports
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.OutputStream;
 import java.net.ServerSocket;
 import java.net.Socket;
 
 /**
  * @author rajith
+ * @author mattmann
  * @version $Revision$
  *
  * Ganglia meta daemon mock server
@@ -78,4 +84,24 @@ public class MockGmetad implements Runna
         }
 
     }
+    
+    public static void main(String [] args) throws Exception{
+       String xmlPath = null;
+       int serverPort = -1;
+       final String usage = "java MockGmetad <xml path> <port>\n";
+       
+       if (args.length != 2){
+               System.err.println(usage);
+               System.exit(1);
+       }
+       
+       xmlPath = args[0];
+       serverPort = Integer.valueOf(args[1]);
+       
+       MockGmetad gmetad = new MockGmetad(serverPort, xmlPath);
+       ThreadLocal<MockGmetad> mockGmetad = new ThreadLocal<MockGmetad>();
+       mockGmetad.set(gmetad);
+       Thread mockGmetadServer = new Thread(mockGmetad.get());
+        mockGmetadServer.start();
+    }
 }

Modified: 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/util/GenericResourceManagerObjectFactory.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/util/GenericResourceManagerObjectFactory.java?rev=1624863&r1=1624862&r2=1624863&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/util/GenericResourceManagerObjectFactory.java
 (original)
+++ 
oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/util/GenericResourceManagerObjectFactory.java
 Sun Sep 14 15:44:19 2014
@@ -31,8 +31,6 @@ import org.apache.oodt.cas.resource.jobr
 import org.apache.oodt.cas.resource.jobrepo.JobRepositoryFactory;
 import org.apache.oodt.cas.resource.monitor.Monitor;
 import org.apache.oodt.cas.resource.monitor.MonitorFactory;
-import org.apache.oodt.cas.resource.monitor.ResourceMonitor;
-import org.apache.oodt.cas.resource.monitor.ResourceMonitorFactory;
 import org.apache.oodt.cas.resource.monitor.ganglia.loadcalc.LoadCalculator;
 import 
org.apache.oodt.cas.resource.monitor.ganglia.loadcalc.LoadCalculatorFactory;
 import org.apache.oodt.cas.resource.noderepo.NodeRepository;
@@ -386,44 +384,6 @@ public final class GenericResourceManage
     return null;
   }
 
-
-    /**
-     * Creates a new {@link 
org.apache.oodt.cas.resource.monitor.ResourceMonitor} implementation from the 
given String name of
-     * the {@link org.apache.oodt.cas.resource.monitor.ResourceMonitorFactory}.
-     *
-     * @param serviceFactory
-     *          The name of the {@link 
org.apache.oodt.cas.resource.monitor.ResourceMonitorFactory} class to use to 
create
-     *          {@link org.apache.oodt.cas.resource.monitor.ResourceMonitor}s.
-     * @return A new {@link 
org.apache.oodt.cas.resource.monitor.ResourceMonitor} implementation.
-     */
-    public static ResourceMonitor getResourceMonitorFromServiceFactory(String 
serviceFactory){
-        Class clazz;
-        ResourceMonitorFactory factory;
-
-        try {
-            clazz = Class.forName(serviceFactory);
-            factory = (ResourceMonitorFactory) clazz.newInstance();
-            return factory.createResourceMonitor();
-        } catch (ClassNotFoundException e) {
-            e.printStackTrace();
-            LOG.log(Level.WARNING,
-                    "ClassNotFoundException when loading resource monitor 
factory class "
-                            + serviceFactory + " Message: " + e.getMessage());
-        } catch (InstantiationException e) {
-            e.printStackTrace();
-            LOG.log(Level.WARNING,
-                    "InstantiationException when loading resource monitor 
factory class "
-                            + serviceFactory + " Message: " + e.getMessage());
-        } catch (IllegalAccessException e) {
-            e.printStackTrace();
-            LOG.log(Level.WARNING,
-                    "IllegalAccessException when loading resource monitor 
factory class "
-                            + serviceFactory + " Message: " + e.getMessage());
-        }
-
-        return null;
-    }
-
     /**
      * Creates a new {@link 
org.apache.oodt.cas.resource.monitor.ganglia.loadcalc.LoadCalculator} 
implementation from the given String name of
      * the {@link ResourceMonitorFactory}.

Modified: 
oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/monitor/TestAssignmentMonitor.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/monitor/TestAssignmentMonitor.java?rev=1624863&r1=1624862&r2=1624863&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/monitor/TestAssignmentMonitor.java
 (original)
+++ 
oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/monitor/TestAssignmentMonitor.java
 Sun Sep 14 15:44:19 2014
@@ -134,14 +134,6 @@ public class TestAssignmentMonitor exten
                 && this.assgnMon.getNodes().containsAll(nodes));
     }
 
-    public void testGetLoad() throws MonitorException {
-        ResourceNode resourceNode = assgnMon.getNodeById("localhost");
-
-        /*since the Gmetad is offline load value from the ResourceMonitor
-        * should be node's capacity, therefore AssignmentMonitors
-        * load value is 0*/
-        assertEquals(0, assgnMon.getLoad(resourceNode));
-    }
 
     private void generateTestConfig() throws IOException {
         String propertiesFile = "." + File.separator + "src" + File.separator +

Modified: 
oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/monitor/TestGangliaResourceMonitor.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/monitor/TestGangliaResourceMonitor.java?rev=1624863&r1=1624862&r2=1624863&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/monitor/TestGangliaResourceMonitor.java
 (original)
+++ 
oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/monitor/TestGangliaResourceMonitor.java
 Sun Sep 14 15:44:19 2014
@@ -17,20 +17,26 @@
 
 package org.apache.oodt.cas.resource.monitor;
 
+//Junit imports
 import junit.framework.TestCase;
+
+
+//OODT imports
 import org.apache.oodt.cas.resource.monitor.ganglia.GangliaResourceMonitor;
 import 
org.apache.oodt.cas.resource.monitor.ganglia.GangliaResourceMonitorFactory;
 import org.apache.oodt.cas.resource.monitor.utils.MockGmetad;
 import org.apache.oodt.cas.resource.structs.ResourceNode;
 
+
+//JDK imports
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
+import java.util.List;
 
 /**
  * @author rajith
+ * @author mattmann
  * @version $Revision$
  *
  * Test Suite for the {@link 
org.apache.oodt.cas.resource.monitor.ganglia.GangliaResourceMonitor}
@@ -46,7 +52,7 @@ public class TestGangliaResourceMonitor 
         runMockGmetad();
 
         gangliaResourceMonitor = (GangliaResourceMonitor)
-                new GangliaResourceMonitorFactory().createResourceMonitor();
+                new GangliaResourceMonitorFactory().createMonitor();
     }
 
     @Override
@@ -56,39 +62,71 @@ public class TestGangliaResourceMonitor 
 
     public void testGetLoad() {
         try {
-            ResourceNode resourceNode =
-                    new ResourceNode("localhost",new 
URL("http://localhost:9999";), 8);
-            assertEquals((float)1.556, 
gangliaResourceMonitor.getLoad(resourceNode));
-        } catch (MalformedURLException ignored) {
-            //Exception ignored
-        }
-    }
-
-    public void testUpdateLoad(){
-        try {
-            ResourceNode resourceNode =
-                    new ResourceNode("remotenode",new 
URL("http://localhost:9999";), 9);
-            assertEquals((float) 1.751, 
gangliaResourceMonitor.getLoad(resourceNode));
-
-            gangliaResourceMonitor.updateLoad("remotenode", 6);
-            assertEquals((float) 6, 
gangliaResourceMonitor.getLoad(resourceNode));
-        }  catch (MalformedURLException ignored) {
-            //Exception ignored
+            ResourceNode resourceNode = new ResourceNode();
+            resourceNode.setId("localhost");
+            assertEquals(1, gangliaResourceMonitor.getLoad(resourceNode));
+        } catch (Exception e) {
+               e.printStackTrace();
+            fail(e.getMessage());
         }
     }
 
     public void testRemoveNodeById(){
         try {
-            ResourceNode resourceNode =
-                    new ResourceNode("remotenode",new 
URL("http://localhost:9999";), 9);
-
-            gangliaResourceMonitor.removeNodeById("remotenode");
-            /*since node is not available node's capacity is returned as the 
load*/
-            assertEquals((float) 9, 
gangliaResourceMonitor.getLoad(resourceNode));
-        } catch (MalformedURLException ignored) {
-            //Exception ignored
+            gangliaResourceMonitor.removeNodeById("localhost");
+            assertNull(gangliaResourceMonitor.getNodeById("remotenode"));
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail(e.getMessage());
         }
     }
+    
+    public void testGetNodes(){
+       try{
+               List<ResourceNode> nodes = gangliaResourceMonitor.getNodes();
+               assertNotNull(nodes);
+               assertEquals(3, nodes.size());
+               boolean hasLocal = false;
+               boolean hasLocal2 = false;
+               boolean hasRemote = false;
+               
+               for(ResourceNode node: nodes){
+                       if(node.getNodeId().equals("localhost")){
+                               hasLocal = true;
+                       }
+                       else if(node.getNodeId().equals("localhost2")){
+                               hasLocal2 = true;
+                       }
+                       else if(node.getNodeId().equals("remotenode")){
+                               hasRemote = true;
+                       }
+                       
+               }
+               assertTrue(hasLocal&&hasLocal2&&hasRemote);
+       }
+       catch (Exception e){
+               e.printStackTrace();
+               fail(e.getMessage());
+       }
+    }
+    
+    public void testGetNodeById(){
+       try{
+               ResourceNode node = 
gangliaResourceMonitor.getNodeById("localhost");
+               assertNotNull(node);
+               assertEquals("localhost", node.getNodeId());
+               node = gangliaResourceMonitor.getNodeById("localhost2");
+               assertNotNull(node);
+               assertEquals("localhost2", node.getNodeId());
+               node = gangliaResourceMonitor.getNodeById("remotenode");
+               assertNotNull(node);
+               assertEquals("remotenode", node.getNodeId());
+       }
+       catch(Exception e){
+               e.printStackTrace();
+               fail(e.getMessage());
+       }
+    }
 
     private void runMockGmetad() {
         int port = Integer.valueOf(System
@@ -96,7 +134,6 @@ public class TestGangliaResourceMonitor 
         String sampleXMLfilePath = "." + File.separator + "src" + 
File.separator +
                 "testdata" + File.separator + "resourcemon" + File.separator + 
"gangliaXMLdump.xml";
         mockGmetad.set(new MockGmetad(port, sampleXMLfilePath));
-
         Thread mockGmetadServer = new Thread(mockGmetad.get());
         mockGmetadServer.start();
     }
@@ -105,9 +142,6 @@ public class TestGangliaResourceMonitor 
         String propertiesFile = "." + File.separator + "src" + File.separator +
                 "testdata" + File.separator + "test.resource.properties";
         System.getProperties().load(new FileInputStream(new 
File(propertiesFile)));
-        System.setProperty("org.apache.oodt.cas.resource.nodes.dirs",
-                "file:" + new File("." + File.separator + "src" + 
File.separator +
-                        "testdata" + File.separator + 
"resourcemon").getAbsolutePath());
     }
 
 }

Modified: 
oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/monitor/TestGangliaXMLParser.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/monitor/TestGangliaXMLParser.java?rev=1624863&r1=1624862&r2=1624863&view=diff
==============================================================================
--- 
oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/monitor/TestGangliaXMLParser.java
 (original)
+++ 
oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/monitor/TestGangliaXMLParser.java
 Sun Sep 14 15:44:19 2014
@@ -17,16 +17,20 @@
 
 package org.apache.oodt.cas.resource.monitor;
 
+//Junit imports
 import junit.framework.TestCase;
-import org.apache.oodt.cas.resource.monitor.exceptions.GangliaMonitorException;
+
+//OODT imports
+import org.apache.oodt.cas.resource.structs.exceptions.MonitorException;
 import org.apache.oodt.cas.resource.monitor.ganglia.GangliaMetKeys;
 import org.apache.oodt.cas.resource.monitor.ganglia.GangliaXMLParser;
 import org.apache.oodt.cas.resource.monitor.ganglia.configuration.Cluster;
 import org.apache.oodt.cas.resource.monitor.ganglia.configuration.Host;
 import org.apache.oodt.cas.resource.monitor.ganglia.configuration.Metric;
+
+//JDK imports
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
-
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParserFactory;
 import java.io.*;
@@ -35,6 +39,7 @@ import java.util.List;
 
 /**
  * @author rajith
+ * @author mattmann
  * @version $Revision$
  *
  * Test Suite for the {@link GangliaXMLParser}
@@ -47,7 +52,7 @@ public class TestGangliaXMLParser extend
      * {@inheritDoc}
      * Read gangliaXMLdump.xml and build the grid configuration
      */
-    protected void setUp() throws GangliaMonitorException, IOException {
+    protected void setUp() throws MonitorException, IOException {
         StringBuilder stringBuffer = new StringBuilder();
 
         try {
@@ -75,11 +80,11 @@ public class TestGangliaXMLParser extend
             parser.parse(new InputSource(new StringReader(buffer)), 
gangliaXMLParser);
             gridConfiguration = gangliaXMLParser.getGridConfiguration();
         } catch (ParserConfigurationException e) {
-            throw new GangliaMonitorException("Error while parsing: " + 
e.getMessage());
+            throw new MonitorException("Error while parsing: " + 
e.getMessage());
         } catch (SAXException e) {
-            throw new GangliaMonitorException("Error while parsing the XML: " 
+ e.getMessage());
+            throw new MonitorException("Error while parsing the XML: " + 
e.getMessage());
         } catch (IOException e) {
-            throw new GangliaMonitorException("I/O error: " + e.getMessage());
+            throw new MonitorException("I/O error: " + e.getMessage());
         }
     }
 

Modified: oodt/trunk/resource/src/testdata/policy/nodes.xml
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/testdata/policy/nodes.xml?rev=1624863&r1=1624862&r2=1624863&view=diff
==============================================================================
--- oodt/trunk/resource/src/testdata/policy/nodes.xml (original)
+++ oodt/trunk/resource/src/testdata/policy/nodes.xml Sun Sep 14 15:44:19 2014
@@ -16,7 +16,7 @@ License for the specific language govern
 the License.
 -->
 <cas:resourcenodes xmlns:cas="http://oodt.jpl.nasa.gov/1.0/cas";>
-       <node nodeId="localhost" ip="http://localhost:2001"; capacity="8"/>
+       <node nodeId="localhost" ip="http://localhost:2001"; capacity="8.0"/>
        <!-- EnvReplace Example 
        <node nodeId="somehost" ip="http://somehost:[BATCH_STUB_PORT]"; 
capacity="8" envReplace="true"/>
        -->

Modified: oodt/trunk/resource/src/testdata/test.resource.properties
URL: 
http://svn.apache.org/viewvc/oodt/trunk/resource/src/testdata/test.resource.properties?rev=1624863&r1=1624862&r2=1624863&view=diff
==============================================================================
--- oodt/trunk/resource/src/testdata/test.resource.properties (original)
+++ oodt/trunk/resource/src/testdata/test.resource.properties Sun Sep 14 
15:44:19 2014
@@ -72,6 +72,5 @@ org.apache.oodt.cas.resource.monitor.loa
 
 #ganglia meta daemon (gmetad) host details
 org.apache.oodt.cas.resource.monitor.ganglia.gemtad.host.address=localhost
-#invalid port
 org.apache.oodt.cas.resource.monitor.ganglia.gemtad.host.port=8659
 


Reply via email to