Fix cluster menu 18/1118/2
authorAndrew Kim <andrekim@cisco.com>
Fri, 6 Sep 2013 22:21:27 +0000 (17:21 -0500)
committerAndrew Kim <andrekim@cisco.com>
Sun, 8 Sep 2013 18:15:57 +0000 (13:15 -0500)
Change-Id: I78b11efc4928b1be0d3d3f0b865483b59b8fb839
Signed-off-by: Andrew Kim <andrekim@cisco.com>
opendaylight/web/root/src/main/java/org/opendaylight/controller/web/DaylightWebAdmin.java
opendaylight/web/root/src/main/resources/js/open.js

index d9aa03ea6209a66fa4548ef091694b1e63dd633c..3b0b85c065cc8cf2de88205525aaaf6f89e84868 100644 (file)
@@ -56,7 +56,7 @@ public class DaylightWebAdmin {
             return null;
         }
 
-        List<ClusterNodeBean> clusters = new ArrayList<ClusterNodeBean>();
+        List<ClusterNodeBean> clusterNodes = new ArrayList<ClusterNodeBean>();
 
         List<InetAddress> controllers = clusterServices.getClusteredControllers();
         for (InetAddress controller : controllers) {
@@ -64,25 +64,24 @@ public class DaylightWebAdmin {
             if (controller.equals(clusterServices.getMyAddress())) {
                 clusterBeanBuilder.highlightMe();
             }
-            if (clusterServices.amICoordinator()) {
+            if (clusterServices.getCoordinatorAddress().equals(controller)) {
                 clusterBeanBuilder.iAmCoordinator();
             }
-
-            clusters.add(clusterBeanBuilder.build());
+            clusterNodes.add(clusterBeanBuilder.build());
         }
 
-        return gson.toJson(clusters);
+        return gson.toJson(clusterNodes);
     }
 
     /**
      * Return nodes connected to controller {controller}
-     * @param cluster
+     * @param controller
      *            - byte[] of the address of the controller
      * @return List<NodeBean>
      */
     @RequestMapping("/cluster/controller/{controller}")
     @ResponseBody
-    public String getNodesConnectedToController(@PathVariable("controller") String cluster) {
+    public String getNodesConnectedToController(@PathVariable("controller") String controller) {
         IClusterGlobalServices clusterServices = (IClusterGlobalServices) ServiceHelper.getGlobalInstance(
                 IClusterGlobalServices.class, this);
         if (clusterServices == null) {
@@ -99,18 +98,20 @@ public class DaylightWebAdmin {
             return null;
         }
 
-        byte[] address = gson.fromJson(cluster, byte[].class);
-        InetAddress clusterAddress = null;
+        byte[] address = gson.fromJson(controller, byte[].class);
+        InetAddress controllerAddress = null;
         try {
-            clusterAddress = InetAddress.getByAddress(address);
+            controllerAddress = InetAddress.getByAddress(address);
         } catch (UnknownHostException e) {
             return null;
         }
-        InetAddress thisCluster = clusterServices.getMyAddress();
 
         List<NodeBean> result = new ArrayList<NodeBean>();
 
-        Set<Node> nodes = connectionManager.getNodes(thisCluster);
+        Set<Node> nodes = connectionManager.getNodes(controllerAddress);
+        if (nodes == null) {
+            return gson.toJson(result);
+        }
         for (Node node : nodes) {
             Description description = (Description) switchManager.getNodeProp(node, Description.propertyName);
             NodeBean nodeBean;
index 599922d391b12284b87544615e6022a9396d69ed..85e4d472ef0d5f89e3e274543e4040a3b2e22ae2 100644 (file)
@@ -515,9 +515,6 @@ one.main.cluster = {
                close : 'one-main-cluster-id-close',
                datagrid : 'one-main-cluster-id-datagrid'
        },
-       registry : { // one.main.cluster.registry
-               cluster : undefined
-       },
        initialize : function() {
                var h3 = 'Cluster Management';
                var footer = one.main.cluster.footer();
@@ -544,7 +541,7 @@ one.main.cluster = {
                                        if ($tr.find('td:nth-child(1)').attr('colspan') === '1') {
                                                return false;
                                        }
-                                       var address = one.main.cluster.registry.cluster[$tr.index()];
+                                       var address = $tr.find('.ux-id').text();
                                        one.main.cluster.nodes.initialize(address);
                                });
                        });
@@ -558,7 +555,14 @@ one.main.cluster = {
                var registry = [];
                $(data).each(function(idx, val) {
                        var name = val.name;
+                       var address = val.address;
+                       var $registry = $(document.createElement('span'));
+                       $registry
+                               .append(JSON.stringify(address))
+                               .css('display', 'none')
+                               .addClass('ux-id');
                        name = one.lib.dashlet.label(name, null)[0].outerHTML;
+                       name += $registry[0].outerHTML;
                        if (val.me === true) {
                                var me = one.lib.dashlet.label('*', 'label-inverse')[0].outerHTML;
                                name += '&nbsp;'+me;
@@ -570,9 +574,7 @@ one.main.cluster = {
                        tdata.push({
                                'controller' : name
                        });
-                       registry.push(val.address);
                });
-               one.main.cluster.registry.cluster = registry;
                var source = new StaticDataSource({
                        columns : [
                                {
@@ -613,7 +615,7 @@ one.main.cluster.nodes = {
                });
                
                // body
-               $.getJSON('/admin/cluster/controller/'+JSON.stringify(address), function(data) {
+               $.getJSON('/admin/cluster/controller/'+address, function(data) {
                        var $gridHTML = one.lib.dashlet.datagrid.init(one.main.cluster.nodes.id.datagrid, {
                                searchable: true,
                                filterable: false,