ONOS-1479 - GUI Topology Overlay Work - (WIP)
- Implemented initial ability to have overlay modify the summary panel data. Change-Id: I0d6bd6d62f0e0d5ba9d901a47271044e0c8d0c89
Showing
7 changed files
with
180 additions
and
21 deletions
| ... | @@ -17,6 +17,7 @@ | ... | @@ -17,6 +17,7 @@ |
| 17 | 17 | ||
| 18 | package org.onosproject.ui; | 18 | package org.onosproject.ui; |
| 19 | 19 | ||
| 20 | +import org.onosproject.ui.topo.PropertyPanel; | ||
| 20 | import org.slf4j.Logger; | 21 | import org.slf4j.Logger; |
| 21 | import org.slf4j.LoggerFactory; | 22 | import org.slf4j.LoggerFactory; |
| 22 | 23 | ||
| ... | @@ -75,4 +76,13 @@ public class UiTopoOverlay { | ... | @@ -75,4 +76,13 @@ public class UiTopoOverlay { |
| 75 | */ | 76 | */ |
| 76 | public void destroy() { | 77 | public void destroy() { |
| 77 | } | 78 | } |
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * Callback to modify the contents of the summary panel. | ||
| 82 | + * This default implementation does nothing. | ||
| 83 | + * | ||
| 84 | + * @param pp property panel model of summary data | ||
| 85 | + */ | ||
| 86 | + public void modifySummary(PropertyPanel pp) { | ||
| 87 | + } | ||
| 78 | } | 88 | } | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + * | ||
| 16 | + */ | ||
| 17 | + | ||
| 18 | +package org.onosproject.ui.topo; | ||
| 19 | + | ||
| 20 | +import java.util.ArrayList; | ||
| 21 | +import java.util.List; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * Models a panel displayed on the Topology View. | ||
| 25 | + */ | ||
| 26 | +public class PropertyPanel { | ||
| 27 | + | ||
| 28 | + private String title; | ||
| 29 | + private String typeId; | ||
| 30 | + private List<Prop> properties = new ArrayList<>(); | ||
| 31 | + | ||
| 32 | + | ||
| 33 | + public PropertyPanel(String title, String typeId) { | ||
| 34 | + this.title = title; | ||
| 35 | + this.typeId = typeId; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public PropertyPanel add(Prop p) { | ||
| 39 | + properties.add(p); | ||
| 40 | + return this; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public String title() { | ||
| 44 | + return title; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public String typeId() { | ||
| 48 | + return typeId; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + // TODO: consider protecting this? | ||
| 52 | + public List<Prop> properties() { | ||
| 53 | + return properties; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public PropertyPanel title(String title) { | ||
| 57 | + this.title = title; | ||
| 58 | + return this; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + // TODO: add other builder-like setters here | ||
| 62 | + | ||
| 63 | + | ||
| 64 | + // ==================== | ||
| 65 | + | ||
| 66 | + public static class Prop { | ||
| 67 | + public final String key; | ||
| 68 | + public final String value; | ||
| 69 | + | ||
| 70 | + public Prop(String key, String value) { | ||
| 71 | + this.key = key; | ||
| 72 | + this.value = value; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public String key() { | ||
| 76 | + return key; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public String value() { | ||
| 80 | + return value; | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + // Auxiliary properties separator | ||
| 85 | + public static class Separator extends Prop { | ||
| 86 | + public Separator() { | ||
| 87 | + super("-", ""); | ||
| 88 | + } | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | +} |
| ... | @@ -22,13 +22,22 @@ import org.onosproject.ui.UiTopoOverlay; | ... | @@ -22,13 +22,22 @@ import org.onosproject.ui.UiTopoOverlay; |
| 22 | import java.util.HashMap; | 22 | import java.util.HashMap; |
| 23 | import java.util.Map; | 23 | import java.util.Map; |
| 24 | 24 | ||
| 25 | +import static com.google.common.base.Strings.isNullOrEmpty; | ||
| 26 | + | ||
| 25 | /** | 27 | /** |
| 26 | * A cache of {@link org.onosproject.ui.UiTopoOverlay}'s that were registered | 28 | * A cache of {@link org.onosproject.ui.UiTopoOverlay}'s that were registered |
| 27 | * at the time the UI connection was established. | 29 | * at the time the UI connection was established. |
| 28 | */ | 30 | */ |
| 29 | public class TopoOverlayCache { | 31 | public class TopoOverlayCache { |
| 30 | 32 | ||
| 33 | + private static final UiTopoOverlay NONE = new NullOverlay(); | ||
| 34 | + | ||
| 31 | private final Map<String, UiTopoOverlay> overlays = new HashMap<>(); | 35 | private final Map<String, UiTopoOverlay> overlays = new HashMap<>(); |
| 36 | + private UiTopoOverlay current = NONE; | ||
| 37 | + | ||
| 38 | + public TopoOverlayCache() { | ||
| 39 | + overlays.put(null, NONE); | ||
| 40 | + } | ||
| 32 | 41 | ||
| 33 | /** | 42 | /** |
| 34 | * Adds a topology overlay to the cache. | 43 | * Adds a topology overlay to the cache. |
| ... | @@ -55,16 +64,18 @@ public class TopoOverlayCache { | ... | @@ -55,16 +64,18 @@ public class TopoOverlayCache { |
| 55 | public void switchOverlay(String deact, String act) { | 64 | public void switchOverlay(String deact, String act) { |
| 56 | UiTopoOverlay toDeactivate = getOverlay(deact); | 65 | UiTopoOverlay toDeactivate = getOverlay(deact); |
| 57 | UiTopoOverlay toActivate = getOverlay(act); | 66 | UiTopoOverlay toActivate = getOverlay(act); |
| 58 | - if (toDeactivate != null) { | 67 | + |
| 59 | - toDeactivate.deactivate(); | 68 | + toDeactivate.deactivate(); |
| 60 | - } | 69 | + current = toActivate; |
| 61 | - if (toActivate != null) { | 70 | + current.activate(); |
| 62 | - toActivate.activate(); | ||
| 63 | - } | ||
| 64 | } | 71 | } |
| 65 | 72 | ||
| 66 | private UiTopoOverlay getOverlay(String id) { | 73 | private UiTopoOverlay getOverlay(String id) { |
| 67 | - return id == null ? null : overlays.get(id); | 74 | + return isNullOrEmpty(id) ? NONE : overlays.get(id); |
| 75 | + } | ||
| 76 | + | ||
| 77 | + public UiTopoOverlay currentOverlay() { | ||
| 78 | + return current; | ||
| 68 | } | 79 | } |
| 69 | 80 | ||
| 70 | /** | 81 | /** |
| ... | @@ -75,4 +86,28 @@ public class TopoOverlayCache { | ... | @@ -75,4 +86,28 @@ public class TopoOverlayCache { |
| 75 | public int size() { | 86 | public int size() { |
| 76 | return overlays.size(); | 87 | return overlays.size(); |
| 77 | } | 88 | } |
| 89 | + | ||
| 90 | + | ||
| 91 | + | ||
| 92 | + private static class NullOverlay extends UiTopoOverlay { | ||
| 93 | + public NullOverlay() { | ||
| 94 | + super(null); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + @Override | ||
| 98 | + public void init() { | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + @Override | ||
| 102 | + public void activate() { | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + @Override | ||
| 106 | + public void deactivate() { | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + @Override | ||
| 110 | + public void destroy() { | ||
| 111 | + } | ||
| 112 | + } | ||
| 78 | } | 113 | } | ... | ... |
| ... | @@ -57,6 +57,7 @@ import org.onosproject.net.link.LinkListener; | ... | @@ -57,6 +57,7 @@ import org.onosproject.net.link.LinkListener; |
| 57 | import org.onosproject.ui.JsonUtils; | 57 | import org.onosproject.ui.JsonUtils; |
| 58 | import org.onosproject.ui.RequestHandler; | 58 | import org.onosproject.ui.RequestHandler; |
| 59 | import org.onosproject.ui.UiConnection; | 59 | import org.onosproject.ui.UiConnection; |
| 60 | +import org.onosproject.ui.topo.PropertyPanel; | ||
| 60 | 61 | ||
| 61 | import java.util.ArrayList; | 62 | import java.util.ArrayList; |
| 62 | import java.util.Collection; | 63 | import java.util.Collection; |
| ... | @@ -561,7 +562,10 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -561,7 +562,10 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
| 561 | 562 | ||
| 562 | // Subscribes for summary messages. | 563 | // Subscribes for summary messages. |
| 563 | private synchronized void requestSummary(long sid) { | 564 | private synchronized void requestSummary(long sid) { |
| 564 | - sendMessage(summmaryMessage(sid)); | 565 | + PropertyPanel pp = summmaryMessage(sid); |
| 566 | + overlayCache.currentOverlay().modifySummary(pp); | ||
| 567 | + ObjectNode json = JsonUtils.envelope("showSummary", sid, json(pp)); | ||
| 568 | + sendMessage(json); | ||
| 565 | } | 569 | } |
| 566 | 570 | ||
| 567 | 571 | ... | ... |
| ... | @@ -72,6 +72,7 @@ import org.onosproject.net.topology.TopologyService; | ... | @@ -72,6 +72,7 @@ import org.onosproject.net.topology.TopologyService; |
| 72 | import org.onosproject.ui.JsonUtils; | 72 | import org.onosproject.ui.JsonUtils; |
| 73 | import org.onosproject.ui.UiConnection; | 73 | import org.onosproject.ui.UiConnection; |
| 74 | import org.onosproject.ui.UiMessageHandler; | 74 | import org.onosproject.ui.UiMessageHandler; |
| 75 | +import org.onosproject.ui.topo.PropertyPanel; | ||
| 75 | import org.slf4j.Logger; | 76 | import org.slf4j.Logger; |
| 76 | import org.slf4j.LoggerFactory; | 77 | import org.slf4j.LoggerFactory; |
| 77 | 78 | ||
| ... | @@ -443,19 +444,20 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -443,19 +444,20 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
| 443 | } | 444 | } |
| 444 | 445 | ||
| 445 | // Returns summary response. | 446 | // Returns summary response. |
| 446 | - protected ObjectNode summmaryMessage(long sid) { | 447 | + protected PropertyPanel summmaryMessage(long sid) { |
| 447 | Topology topology = topologyService.currentTopology(); | 448 | Topology topology = topologyService.currentTopology(); |
| 448 | - return JsonUtils.envelope("showSummary", sid, | 449 | + PropertyPanel pp = new PropertyPanel("ONOS Summary", "node") |
| 449 | - json("ONOS Summary", "node", | 450 | + .add(new PropertyPanel.Prop("Devices", format(topology.deviceCount()))) |
| 450 | - new Prop("Devices", format(topology.deviceCount())), | 451 | + .add(new PropertyPanel.Prop("Links", format(topology.linkCount()))) |
| 451 | - new Prop("Links", format(topology.linkCount())), | 452 | + .add(new PropertyPanel.Prop("Hosts", format(hostService.getHostCount()))) |
| 452 | - new Prop("Hosts", format(hostService.getHostCount())), | 453 | + .add(new PropertyPanel.Prop("Topology SCCs", format(topology.clusterCount()))) |
| 453 | - new Prop("Topology SCCs", format(topology.clusterCount())), | 454 | + .add(new PropertyPanel.Separator()) |
| 454 | - new Separator(), | 455 | + .add(new PropertyPanel.Prop("Intents", format(intentService.getIntentCount()))) |
| 455 | - new Prop("Intents", format(intentService.getIntentCount())), | 456 | + .add(new PropertyPanel.Prop("Tunnels", format(tunnelService.tunnelCount()))) |
| 456 | - new Prop("Tunnels", format(tunnelService.tunnelCount())), | 457 | + .add(new PropertyPanel.Prop("Flows", format(flowService.getFlowRuleCount()))) |
| 457 | - new Prop("Flows", format(flowService.getFlowRuleCount())), | 458 | + .add(new PropertyPanel.Prop("Version", version)); |
| 458 | - new Prop("Version", version))); | 459 | + |
| 460 | + return pp; | ||
| 459 | } | 461 | } |
| 460 | 462 | ||
| 461 | // Returns device details response. | 463 | // Returns device details response. |
| ... | @@ -840,6 +842,20 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -840,6 +842,20 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
| 840 | link.dst().elementId(), link.dst().port()); | 842 | link.dst().elementId(), link.dst().port()); |
| 841 | } | 843 | } |
| 842 | 844 | ||
| 845 | + protected ObjectNode json(PropertyPanel pp) { | ||
| 846 | + ObjectNode result = objectNode() | ||
| 847 | + .put("title", pp.title()).put("type", pp.typeId()); | ||
| 848 | + ObjectNode pnode = objectNode(); | ||
| 849 | + ArrayNode porder = arrayNode(); | ||
| 850 | + for (PropertyPanel.Prop p : pp.properties()) { | ||
| 851 | + porder.add(p.key()); | ||
| 852 | + pnode.put(p.key(), p.value()); | ||
| 853 | + } | ||
| 854 | + result.set("propOrder", porder); | ||
| 855 | + result.set("props", pnode); | ||
| 856 | + return result; | ||
| 857 | + } | ||
| 858 | + | ||
| 843 | // Produces JSON property details. | 859 | // Produces JSON property details. |
| 844 | private ObjectNode json(String id, String type, Prop... props) { | 860 | private ObjectNode json(String id, String type, Prop... props) { |
| 845 | ObjectNode result = objectNode() | 861 | ObjectNode result = objectNode() | ... | ... |
| ... | @@ -126,6 +126,9 @@ | ... | @@ -126,6 +126,9 @@ |
| 126 | current = overlay(id); | 126 | current = overlay(id); |
| 127 | current && doop('activate'); | 127 | current && doop('activate'); |
| 128 | wss.sendEvent('topoSelectOverlay', payload); | 128 | wss.sendEvent('topoSelectOverlay', payload); |
| 129 | + | ||
| 130 | + // TODO: refactor to emit "flush on overlay change" messages | ||
| 131 | + wss.sendEvent('requestSummary'); | ||
| 129 | } | 132 | } |
| 130 | } | 133 | } |
| 131 | 134 | ... | ... |
| ... | @@ -208,7 +208,7 @@ | ... | @@ -208,7 +208,7 @@ |
| 208 | gs.addGlyph(svg, 'node', 40); | 208 | gs.addGlyph(svg, 'node', 40); |
| 209 | gs.addGlyph(svg, 'bird', 24, true, [8,12]); | 209 | gs.addGlyph(svg, 'bird', 24, true, [8,12]); |
| 210 | 210 | ||
| 211 | - title.text(data.id); | 211 | + title.text(data.title); |
| 212 | listProps(tbody, data); | 212 | listProps(tbody, data); |
| 213 | } | 213 | } |
| 214 | 214 | ... | ... |
-
Please register or login to post a comment