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
Showing
4 changed files
with
34 additions
and
19 deletions
| ... | @@ -190,4 +190,18 @@ public abstract class UiMessageHandler { | ... | @@ -190,4 +190,18 @@ public abstract class UiMessageHandler { |
| 190 | protected ArrayNode arrayNode() { | 190 | protected ArrayNode arrayNode() { |
| 191 | return mapper.createArrayNode(); | 191 | return mapper.createArrayNode(); |
| 192 | } | 192 | } |
| 193 | + | ||
| 194 | + /** | ||
| 195 | + * Sends the specified data to the client. | ||
| 196 | + * It is expected that the data is in the prescribed JSON format for | ||
| 197 | + * events to the client. | ||
| 198 | + * | ||
| 199 | + * @param data data to be sent | ||
| 200 | + */ | ||
| 201 | + protected synchronized void sendMessage(ObjectNode data) { | ||
| 202 | + UiConnection connection = connection(); | ||
| 203 | + if (connection != null) { | ||
| 204 | + connection.sendMessage(data); | ||
| 205 | + } | ||
| 206 | + } | ||
| 193 | } | 207 | } | ... | ... |
| ... | @@ -15,23 +15,21 @@ | ... | @@ -15,23 +15,21 @@ |
| 15 | * | 15 | * |
| 16 | */ | 16 | */ |
| 17 | 17 | ||
| 18 | -package org.onosproject.ui.impl.topo; | 18 | +package org.onosproject.ui.topo; |
| 19 | 19 | ||
| 20 | import com.fasterxml.jackson.databind.ObjectMapper; | 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 21 | import com.fasterxml.jackson.databind.node.ArrayNode; | 21 | import com.fasterxml.jackson.databind.node.ArrayNode; |
| 22 | import com.fasterxml.jackson.databind.node.ObjectNode; | 22 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 23 | -import org.onosproject.ui.topo.ButtonId; | 23 | + |
| 24 | -import org.onosproject.ui.topo.DeviceHighlight; | 24 | +import static org.onosproject.ui.JsonUtils.envelope; |
| 25 | -import org.onosproject.ui.topo.Highlights; | ||
| 26 | -import org.onosproject.ui.topo.HostHighlight; | ||
| 27 | -import org.onosproject.ui.topo.LinkHighlight; | ||
| 28 | -import org.onosproject.ui.topo.PropertyPanel; | ||
| 29 | 25 | ||
| 30 | /** | 26 | /** |
| 31 | * JSON utilities for the Topology View. | 27 | * JSON utilities for the Topology View. |
| 32 | */ | 28 | */ |
| 33 | public final class TopoJson { | 29 | public final class TopoJson { |
| 34 | // package-private for unit test access | 30 | // package-private for unit test access |
| 31 | + static final String SHOW_HIGHLIGHTS = "showHighlights"; | ||
| 32 | + | ||
| 35 | static final String DEVICES = "devices"; | 33 | static final String DEVICES = "devices"; |
| 36 | static final String HOSTS = "hosts"; | 34 | static final String HOSTS = "hosts"; |
| 37 | static final String LINKS = "links"; | 35 | static final String LINKS = "links"; |
| ... | @@ -62,6 +60,17 @@ public final class TopoJson { | ... | @@ -62,6 +60,17 @@ public final class TopoJson { |
| 62 | private TopoJson() { } | 60 | private TopoJson() { } |
| 63 | 61 | ||
| 64 | /** | 62 | /** |
| 63 | + * Returns a formatted message ready to send to the topology view | ||
| 64 | + * to render highlights. | ||
| 65 | + * | ||
| 66 | + * @param highlights highlights model to transform | ||
| 67 | + * @return fully formatted "show highlights" message | ||
| 68 | + */ | ||
| 69 | + public static ObjectNode highlightsMessage(Highlights highlights) { | ||
| 70 | + return envelope(SHOW_HIGHLIGHTS, json(highlights)); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + /** | ||
| 65 | * Transforms the given highlights model into a JSON message payload. | 74 | * Transforms the given highlights model into a JSON message payload. |
| 66 | * | 75 | * |
| 67 | * @param highlights the model to transform | 76 | * @param highlights the model to transform | ... | ... |
| ... | @@ -15,13 +15,12 @@ | ... | @@ -15,13 +15,12 @@ |
| 15 | * | 15 | * |
| 16 | */ | 16 | */ |
| 17 | 17 | ||
| 18 | -package org.onosproject.ui.impl.topo; | 18 | +package org.onosproject.ui.topo; |
| 19 | 19 | ||
| 20 | import com.fasterxml.jackson.databind.node.ArrayNode; | 20 | import com.fasterxml.jackson.databind.node.ArrayNode; |
| 21 | import com.fasterxml.jackson.databind.node.ObjectNode; | 21 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 22 | import org.junit.Test; | 22 | import org.junit.Test; |
| 23 | import org.onosproject.ui.JsonUtils; | 23 | import org.onosproject.ui.JsonUtils; |
| 24 | -import org.onosproject.ui.topo.Highlights; | ||
| 25 | import org.onosproject.ui.topo.Highlights.Amount; | 24 | import org.onosproject.ui.topo.Highlights.Amount; |
| 26 | 25 | ||
| 27 | import static org.junit.Assert.assertEquals; | 26 | import static org.junit.Assert.assertEquals; | ... | ... |
| ... | @@ -80,7 +80,8 @@ import static org.onosproject.net.device.DeviceEvent.Type.*; | ... | @@ -80,7 +80,8 @@ import static org.onosproject.net.device.DeviceEvent.Type.*; |
| 80 | import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED; | 80 | import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED; |
| 81 | import static org.onosproject.net.link.LinkEvent.Type.LINK_ADDED; | 81 | import static org.onosproject.net.link.LinkEvent.Type.LINK_ADDED; |
| 82 | import static org.onosproject.ui.JsonUtils.envelope; | 82 | import static org.onosproject.ui.JsonUtils.envelope; |
| 83 | -import static org.onosproject.ui.impl.topo.TopoJson.json; | 83 | +import static org.onosproject.ui.topo.TopoJson.highlightsMessage; |
| 84 | +import static org.onosproject.ui.topo.TopoJson.json; | ||
| 84 | 85 | ||
| 85 | /** | 86 | /** |
| 86 | * Web socket capable of interacting with the GUI topology view. | 87 | * Web socket capable of interacting with the GUI topology view. |
| ... | @@ -538,15 +539,7 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -538,15 +539,7 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
| 538 | 539 | ||
| 539 | // Converts highlights to JSON format and sends the message to the client | 540 | // Converts highlights to JSON format and sends the message to the client |
| 540 | protected void sendHighlights(Highlights highlights) { | 541 | protected void sendHighlights(Highlights highlights) { |
| 541 | - sendMessage(envelope(SHOW_HIGHLIGHTS, json(highlights))); | 542 | + sendMessage(highlightsMessage(highlights)); |
| 542 | - } | ||
| 543 | - | ||
| 544 | - // Sends the specified data to the client. | ||
| 545 | - protected synchronized void sendMessage(ObjectNode data) { | ||
| 546 | - UiConnection connection = connection(); | ||
| 547 | - if (connection != null) { | ||
| 548 | - connection.sendMessage(data); | ||
| 549 | - } | ||
| 550 | } | 543 | } |
| 551 | 544 | ||
| 552 | // Subscribes for summary messages. | 545 | // Subscribes for summary messages. | ... | ... |
-
Please register or login to post a comment