GUI Topo -- Badges - Enhanced uitopo archetype to also use badges.
Change-Id: I80cd4783a4154a2ccce6054175022b97ef7bc6c1
diff --git a/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/AppUiTopovMessageHandler.java b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/AppUiTopovMessageHandler.java
index 7c35cc5..65e3489 100644
--- a/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/AppUiTopovMessageHandler.java
+++ b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/AppUiTopovMessageHandler.java
@@ -33,7 +33,10 @@
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiConnection;
import org.onosproject.ui.UiMessageHandler;
+import org.onosproject.ui.topo.DeviceHighlight;
import org.onosproject.ui.topo.Highlights;
+import org.onosproject.ui.topo.NodeBadge;
+import org.onosproject.ui.topo.NodeBadge.Status;
import org.onosproject.ui.topo.TopoJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -224,11 +227,26 @@
if (elementOfNote != null && elementOfNote instanceof Device) {
DeviceId devId = (DeviceId) elementOfNote.id();
Set<Link> links = linkService.getDeviceEgressLinks(devId);
- sendHighlights(fromLinks(links, devId));
+ Highlights highlights = fromLinks(links, devId);
+ addDeviceBadge(highlights, devId, links.size());
+ sendHighlights(highlights);
}
// Note: could also process Host, if available
}
+ private void addDeviceBadge(Highlights h, DeviceId devId, int n) {
+ DeviceHighlight dh = new DeviceHighlight(devId.toString());
+ dh.setBadge(createBadge(n));
+ h.add(dh);
+ }
+
+ private NodeBadge createBadge(int n) {
+ Status status = n > 3 ? Status.ERROR : Status.WARN;
+ String noun = n > 3 ? "(critical)" : "(problematic)";
+ String msg = "Egress links: " + n + " " + noun;
+ return NodeBadge.number(status, n, msg);
+ }
+
private Highlights fromLinks(Set<Link> links, DeviceId devId) {
DemoLinkMap linkMap = new DemoLinkMap();
if (links != null) {