Primitive support to save the topology coordinates and cleanup of some unused tiering... 13/313/1
authorMadhu Venugopal <vmadhu@cisco.com>
Tue, 7 May 2013 10:04:14 +0000 (03:04 -0700)
committerMadhu Venugopal <vmadhu@cisco.com>
Tue, 7 May 2013 10:18:27 +0000 (03:18 -0700)
Change-Id: Ibe9ae8ab560533cc7215f3d35b1875265fbe54a6
Signed-off-by: Madhu Venugopal <vmadhu@cisco.com>
opendaylight/hosttracker/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/HostTracker.java
opendaylight/web/topology/pom.xml
opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java

index 7c312e1577b927850e3c11839c3b817cb9282238..f416f29a25c639341f0b512d9c3b2555c49f6890 100644 (file)
@@ -576,25 +576,6 @@ public class HostTracker implements IfIptoHost, IfHostListener,
                 Tier tier = new Tier(1);
                 switchManager.setNodeProp(node, tier);
                 topologyManager.updateHostLink(p, h, UpdateType.ADDED, null);
-                /*
-                 * This is a temporary fix for Cisco Live's Hadoop
-                 * Demonstration. The concept of Tiering must be revisited based
-                 * on other application requirements and the design might
-                 * warrant a separate module (as it involves tracking the
-                 * topology/ host changes & updating the Tiering numbers in an
-                 * effective manner).
-                 */
-                updateSwitchTiers(node, 1);
-
-                /*
-                 * The following 2 lines are added for testing purposes. We can
-                 * remove it once the North-Bound APIs are available for
-                 * testing.
-                 * 
-                 * ArrayList<ArrayList<String>> hierarchies =
-                 * getHostNetworkHierarchy(host.getNetworkAddress());
-                 * logHierarchies(hierarchies);
-                 */
             } else {
                 // No need to reset the tiering if no other hosts are currently
                 // connected
@@ -899,16 +880,6 @@ public class HostTracker implements IfIptoHost, IfHostListener,
         logger.debug(
                 "HostTracker Topology linkUpdate handling src:{}[port {}] dst:{}[port {}] added: {}",
                 new Object[] { srcNid, srcPort, dstNid, dstPort, added });
-        clearTiers();
-        for (Entry<InetAddress, HostNodeConnector> entry : hostsDB.entrySet()) {
-            HostNodeConnector host = entry.getValue();
-            Node node = host.getnodeconnectorNode();
-            if (node != null) {
-                Tier t = new Tier(1);
-                switchManager.setNodeProp(node, t);
-                updateSwitchTiers(node, 1);
-            }
-        }
     }
 
     @Override
index 0dd10512ebe3254b5fb44f5f7c12a71e0fecfd16..b260e2d1f8b0bbd7130674b4bc51daf0746736cc 100644 (file)
@@ -25,6 +25,7 @@
                                                </Export-Package>
                                                <Import-Package>
                                                        org.opendaylight.controller.containermanager,
+                                                       org.opendaylight.controller.configuration,
                                                        org.opendaylight.controller.sal.authorization,
                                                        org.opendaylight.controller.sal.packet.address,
                                                        org.opendaylight.controller.sal.action,
                        <artifactId>containermanager</artifactId>
                        <version>0.4.0-SNAPSHOT</version>
                </dependency>
+               <dependency>
+                       <groupId>org.opendaylight.controller</groupId>
+                       <artifactId>configuration</artifactId>
+                       <version>0.4.0-SNAPSHOT</version>
+               </dependency>           
                <dependency>
                        <groupId>org.opendaylight.controller</groupId>
                        <artifactId>switchmanager</artifactId>
index 3e25110e58358a77be386bc2ddf1fa5148cea08c..0f4569fc19ded417398157a33cc529810e94ed14 100644 (file)
@@ -10,6 +10,9 @@
 package org.opendaylight.controller.topology.web;
 
 import java.awt.Dimension;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.ObjectInputStream;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -21,6 +24,7 @@ import java.util.Set;
 
 import javax.servlet.http.HttpServletRequest;
 
+import org.opendaylight.controller.configuration.IConfigurationAware;
 import org.opendaylight.controller.containermanager.IContainerAuthorization;
 import org.opendaylight.controller.sal.authorization.Resource;
 import org.opendaylight.controller.sal.authorization.UserLevel;
@@ -33,13 +37,19 @@ import org.opendaylight.controller.sal.core.NodeConnector;
 import org.opendaylight.controller.sal.core.Property;
 import org.opendaylight.controller.sal.packet.address.EthernetAddress;
 import org.opendaylight.controller.sal.utils.GlobalConstants;
+import org.opendaylight.controller.sal.utils.IObjectReader;
+import org.opendaylight.controller.sal.utils.ObjectReader;
+import org.opendaylight.controller.sal.utils.ObjectWriter;
 import org.opendaylight.controller.sal.utils.ServiceHelper;
+import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.sal.utils.StatusCode;
 import org.opendaylight.controller.switchmanager.ISwitchManager;
 import org.opendaylight.controller.switchmanager.Switch;
 import org.opendaylight.controller.switchmanager.SwitchConfig;
 import org.opendaylight.controller.topologymanager.ITopologyManager;
 import org.opendaylight.controller.usermanager.IUserManager;
 import org.opendaylight.controller.web.DaylightWebUtil;
+import org.opendaylight.controller.web.IDaylightWeb;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -53,7 +63,9 @@ import edu.uci.ics.jung.graph.SparseMultigraph;
 
 @Controller
 @RequestMapping("/")
-public class Topology {
+public class Topology implements IObjectReader, IConfigurationAware {
+    private static String ROOT = GlobalConstants.STARTUPHOME.toString();
+    private String topologyWebFileName = null;
 
     protected Map<String, Map<String, Map<String, Object>>> metaCache = new HashMap<String, Map<String, Map<String, Object>>>();
     protected Map<String, Map<String, Object>> stagedNodes;
@@ -64,6 +76,12 @@ public class Topology {
     protected Map<String, Integer> metaNodeSingleHash = new HashMap<String, Integer>();
     protected Map<String, Integer> metaNodeConfigurationHash = new HashMap<String, Integer>();
     
+    public Topology() {
+       ServiceHelper.registerGlobalService(IConfigurationAware.class, this, null);
+       topologyWebFileName = ROOT + "topologyCache.sav";
+       loadConfiguration();
+    }
+    
     /**
      * Topology of nodes and hosts in the network in JSON format.
      * 
@@ -558,4 +576,25 @@ public class Topology {
        
        return false;
     }
+
+    @SuppressWarnings("unchecked")
+       private void loadConfiguration() {
+        ObjectReader objReader = new ObjectReader();
+        metaCache = (Map<String, Map<String, Map<String, Object>>>) objReader.read(this, topologyWebFileName);
+        if (metaCache == null) metaCache = new HashMap<String, Map<String, Map<String, Object>>>();
+    }
+
+    @Override
+    public Status saveConfiguration() {
+        ObjectWriter objWriter = new ObjectWriter();
+        objWriter.write(metaCache, topologyWebFileName);
+        return new Status(StatusCode.SUCCESS, null);
+    }
+
+    @Override
+    public Object readObject(ObjectInputStream ois)
+            throws FileNotFoundException, IOException, ClassNotFoundException {
+        // Perform the class deserialization locally, from inside the package where the class is defined
+        return ois.readObject();
+    }
 }
\ No newline at end of file