Server-side GUI: handle ClusterEvent JSON encoding and posting.

Change-Id: I7c9c155b86740ea1d8fd7d418666d47013c3c27c
diff --git a/core/api/src/main/java/org/onosproject/ui/model/topo/UiClusterMember.java b/core/api/src/main/java/org/onosproject/ui/model/topo/UiClusterMember.java
index f30d9dc..ca8687d 100644
--- a/core/api/src/main/java/org/onosproject/ui/model/topo/UiClusterMember.java
+++ b/core/api/src/main/java/org/onosproject/ui/model/topo/UiClusterMember.java
@@ -21,7 +21,6 @@
 import org.onosproject.cluster.NodeId;
 
 import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onosproject.cluster.ControllerNode.State.INACTIVE;
 
 /**
  * Represents an individual member of the cluster (ONOS instance).
@@ -33,8 +32,6 @@
     private final UiTopology topology;
     private final NodeId nodeId;
 
-    private ControllerNode.State state = INACTIVE;
-
     /**
      * Constructs a UI cluster member, with a reference to the parent
      * topology instance and the specified controller node instance.
@@ -51,8 +48,6 @@
     @Override
     public String toString() {
         return "UiClusterMember{" + nodeId +
-                ", online=" + isOnline() +
-                ", ready=" + isReady() +
                 "}";
     }
 
@@ -71,15 +66,6 @@
     }
 
     /**
-     * Sets the state of this cluster member.
-     *
-     * @param state the state
-     */
-    public void setState(ControllerNode.State state) {
-        this.state = state;
-    }
-
-    /**
      * Returns the identity of the cluster member.
      *
      * @return member identifier
@@ -97,21 +83,4 @@
         return backingNode().ip();
     }
 
-    /**
-     * Returns true if this cluster member is online (active).
-     *
-     * @return true if online, false otherwise
-     */
-    public boolean isOnline() {
-        return state.isActive();
-    }
-
-    /**
-     * Returns true if this cluster member is considered ready.
-     *
-     * @return true if ready, false otherwise
-     */
-    public boolean isReady() {
-        return state.isReady();
-    }
 }
diff --git a/core/api/src/test/java/org/onosproject/ui/model/topo/UiClusterMemberTest.java b/core/api/src/test/java/org/onosproject/ui/model/topo/UiClusterMemberTest.java
index 2e26989..167fc89 100644
--- a/core/api/src/test/java/org/onosproject/ui/model/topo/UiClusterMemberTest.java
+++ b/core/api/src/test/java/org/onosproject/ui/model/topo/UiClusterMemberTest.java
@@ -43,7 +43,5 @@
 
         assertEquals("wrong id", NODE_ID, member.id());
         assertEquals("wrong IP", NODE_IP, member.ip());
-        assertEquals("unex. online", false, member.isOnline());
-        assertEquals("unex. ready", false, member.isReady());
     }
 }
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2Jsonifier.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2Jsonifier.java
index 214553e..606d175 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2Jsonifier.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2Jsonifier.java
@@ -24,6 +24,7 @@
 import org.onlab.osgi.ServiceDirectory;
 import org.onlab.packet.IpAddress;
 import org.onosproject.cluster.ClusterService;
+import org.onosproject.cluster.ControllerNode;
 import org.onosproject.cluster.NodeId;
 import org.onosproject.incubator.net.PortStatisticsService;
 import org.onosproject.incubator.net.tunnel.TunnelService;
@@ -41,6 +42,7 @@
 import org.onosproject.net.region.Region;
 import org.onosproject.net.statistic.StatisticService;
 import org.onosproject.net.topology.TopologyService;
+import org.onosproject.ui.GlyphConstants;
 import org.onosproject.ui.JsonUtils;
 import org.onosproject.ui.UiExtensionService;
 import org.onosproject.ui.UiPreferencesService;
@@ -202,11 +204,12 @@
 
     private ObjectNode json(UiClusterMember member, boolean isUiAttached) {
         int switchCount = mastershipService.getDevicesOf(member.id()).size();
+        ControllerNode.State state = clusterService.getState(member.id());
         return objectNode()
                 .put("id", member.id().toString())
                 .put("ip", member.ip().toString())
-                .put("online", member.isOnline())
-                .put("ready", member.isReady())
+                .put("online", state.isActive())
+                .put("ready", state.isReady())
                 .put("uiAttached", isUiAttached)
                 .put("switches", switchCount);
     }
@@ -397,8 +400,9 @@
         if (element instanceof UiLink) {
             return json((UiLink) element);
         }
-
-        // TODO: UiClusterMember
+        if (element instanceof UiClusterMember) {
+            return json((UiClusterMember) element);
+        }
 
         // Unrecognized UiElement class
         return objectNode()
@@ -634,6 +638,16 @@
         return data;
     }
 
+    private ObjectNode json(UiClusterMember member) {
+        ControllerNode.State state = clusterService.getState(member.id());
+        return objectNode()
+                .put("id", member.idAsString())
+                .put("ip", member.ip().toString())
+                .put("online", state.isActive())
+                .put("ready", state.isReady())
+                .put(GlyphConstants.UI_ATTACHED,
+                     member.backingNode().equals(clusterService.getLocalNode()));
+    }
 
     private ObjectNode jsonClosedRegion(String ridStr, UiRegion region) {
         ObjectNode node = objectNode()
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/model/ModelCache.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/model/ModelCache.java
index fa426e1..a078b7d 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/topo/model/ModelCache.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/model/ModelCache.java
@@ -138,8 +138,7 @@
     }
 
     private void updateClusterMember(UiClusterMember member) {
-        ControllerNode.State state = services.cluster().getState(member.id());
-        member.setState(state);
+        // maybe something to update in the future?
     }
 
     private void loadClusterMembers() {
diff --git a/web/gui/src/test/java/org/onosproject/ui/impl/topo/model/ModelCacheTest.java b/web/gui/src/test/java/org/onosproject/ui/impl/topo/model/ModelCacheTest.java
index 8d7ada6..8a9328d 100644
--- a/web/gui/src/test/java/org/onosproject/ui/impl/topo/model/ModelCacheTest.java
+++ b/web/gui/src/test/java/org/onosproject/ui/impl/topo/model/ModelCacheTest.java
@@ -152,8 +152,11 @@
         // see AbstractUiImplTest Mock Environment for expected values...
         assertEquals("wrong id str", C1, member.idAsString());
         assertEquals("wrong id", nodeId(C1), member.id());
-        assertEquals("not online", true, member.isOnline());
-        assertEquals("not ready", true, member.isReady());
+
+        // TODO make assertions through the cluster service; state no longer
+        //   cached in the UiModel...
+//        assertEquals("not online", true, member.isOnline());
+//        assertEquals("not ready", true, member.isReady());
     }