Simon Hunt

ONOS-2186 - GUI Topo Overlay - (WIP)

- Moved TopoJson to core ui API, so it is accessible to external apps
- Added highlightsMessage() to TopoJson
- Pulled sendMessage() up to UiMessageHandler

Change-Id: Iacab5b69e3b2a6db98be8391274695247ba5526d
......@@ -190,4 +190,18 @@ public abstract class UiMessageHandler {
protected ArrayNode arrayNode() {
return mapper.createArrayNode();
}
/**
* Sends the specified data to the client.
* It is expected that the data is in the prescribed JSON format for
* events to the client.
*
* @param data data to be sent
*/
protected synchronized void sendMessage(ObjectNode data) {
UiConnection connection = connection();
if (connection != null) {
connection.sendMessage(data);
}
}
}
......
......@@ -15,23 +15,21 @@
*
*/
package org.onosproject.ui.impl.topo;
package org.onosproject.ui.topo;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onosproject.ui.topo.ButtonId;
import org.onosproject.ui.topo.DeviceHighlight;
import org.onosproject.ui.topo.Highlights;
import org.onosproject.ui.topo.HostHighlight;
import org.onosproject.ui.topo.LinkHighlight;
import org.onosproject.ui.topo.PropertyPanel;
import static org.onosproject.ui.JsonUtils.envelope;
/**
* JSON utilities for the Topology View.
*/
public final class TopoJson {
// package-private for unit test access
static final String SHOW_HIGHLIGHTS = "showHighlights";
static final String DEVICES = "devices";
static final String HOSTS = "hosts";
static final String LINKS = "links";
......@@ -62,6 +60,17 @@ public final class TopoJson {
private TopoJson() { }
/**
* Returns a formatted message ready to send to the topology view
* to render highlights.
*
* @param highlights highlights model to transform
* @return fully formatted "show highlights" message
*/
public static ObjectNode highlightsMessage(Highlights highlights) {
return envelope(SHOW_HIGHLIGHTS, json(highlights));
}
/**
* Transforms the given highlights model into a JSON message payload.
*
* @param highlights the model to transform
......
......@@ -15,13 +15,12 @@
*
*/
package org.onosproject.ui.impl.topo;
package org.onosproject.ui.topo;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.Test;
import org.onosproject.ui.JsonUtils;
import org.onosproject.ui.topo.Highlights;
import org.onosproject.ui.topo.Highlights.Amount;
import static org.junit.Assert.assertEquals;
......
......@@ -80,7 +80,8 @@ import static org.onosproject.net.device.DeviceEvent.Type.*;
import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED;
import static org.onosproject.net.link.LinkEvent.Type.LINK_ADDED;
import static org.onosproject.ui.JsonUtils.envelope;
import static org.onosproject.ui.impl.topo.TopoJson.json;
import static org.onosproject.ui.topo.TopoJson.highlightsMessage;
import static org.onosproject.ui.topo.TopoJson.json;
/**
* Web socket capable of interacting with the GUI topology view.
......@@ -538,15 +539,7 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase {
// Converts highlights to JSON format and sends the message to the client
protected void sendHighlights(Highlights highlights) {
sendMessage(envelope(SHOW_HIGHLIGHTS, json(highlights)));
}
// Sends the specified data to the client.
protected synchronized void sendMessage(ObjectNode data) {
UiConnection connection = connection();
if (connection != null) {
connection.sendMessage(data);
}
sendMessage(highlightsMessage(highlights));
}
// Subscribes for summary messages.
......