ONOS-1479 -- GUI - augmenting topology view for extensibility:
- Added id field to property panel, as well as overloaded constructors.
- Added modify*Details() methods to UiTopoOverlay.
- Cleaned up use of string constants.
- Reworked RequestDetails in Topo view msg handler (and base).
- Fixed bug in topo UI where selected host title click caused exception on server.
Change-Id: Ib2a3cf60fae8ad8cda77a3b6933ee758262e6f3c
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java
index ddc61f8..9a360bf 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java
@@ -85,6 +85,7 @@
*/
public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase {
+ // incoming event types
private static final String REQ_DETAILS = "requestDetails";
private static final String UPDATE_META = "updateMeta";
private static final String ADD_HOST_INTENT = "addHostIntent";
@@ -107,6 +108,33 @@
private static final String TOPO_SELECT_OVERLAY = "topoSelectOverlay";
private static final String TOPO_STOP = "topoStop";
+ // outgoing event types
+ private static final String SHOW_SUMMARY = "showSummary";
+ private static final String SHOW_DETAILS = "showDetails";
+ private static final String SPRITE_LIST_RESPONSE = "spriteListResponse";
+ private static final String SPRITE_DATA_RESPONSE = "spriteDataResponse";
+ private static final String UPDATE_INSTANCE = "updateInstance";
+
+ // fields
+ private static final String ID = "id";
+ private static final String IDS = "ids";
+ private static final String HOVER = "hover";
+ private static final String DEVICE = "device";
+ private static final String HOST = "host";
+ private static final String CLASS = "class";
+ private static final String UNKNOWN = "unknown";
+ private static final String ONE = "one";
+ private static final String TWO = "two";
+ private static final String SRC = "src";
+ private static final String DST = "dst";
+ private static final String DATA = "data";
+ private static final String NAME = "name";
+ private static final String NAMES = "names";
+ private static final String ACTIVATE = "activate";
+ private static final String DEACTIVATE = "deactivate";
+ private static final String PRIMARY = "primary";
+ private static final String SECONDARY = "secondary";
+
private static final String APP_ID = "org.onosproject.gui";
@@ -244,8 +272,8 @@
@Override
public void process(long sid, ObjectNode payload) {
- String deact = string(payload, "deactivate");
- String act = string(payload, "activate");
+ String deact = string(payload, DEACTIVATE);
+ String act = string(payload, ACTIVATE);
overlayCache.switchOverlay(deact, act);
}
}
@@ -295,8 +323,8 @@
ObjectNode root = objectNode();
ArrayNode names = arrayNode();
get(SpriteService.class).getNames().forEach(names::add);
- root.set("names", names);
- sendMessage("spriteListResponse", sid, root);
+ root.set(NAMES, names);
+ sendMessage(SPRITE_LIST_RESPONSE, sid, root);
}
}
@@ -307,10 +335,10 @@
@Override
public void process(long sid, ObjectNode payload) {
- String name = string(payload, "name");
+ String name = string(payload, NAME);
ObjectNode root = objectNode();
- root.set("data", get(SpriteService.class).get(name));
- sendMessage("spriteDataResponse", sid, root);
+ root.set(DATA, get(SpriteService.class).get(name));
+ sendMessage(SPRITE_DATA_RESPONSE, sid, root);
}
}
@@ -321,14 +349,20 @@
@Override
public void process(long sid, ObjectNode payload) {
- String type = string(payload, "class", "unknown");
- String id = string(payload, "id");
+ String type = string(payload, CLASS, UNKNOWN);
+ String id = string(payload, ID);
+ PropertyPanel pp = null;
- if (type.equals("device")) {
- sendMessage(deviceDetails(deviceId(id), sid));
- } else if (type.equals("host")) {
- sendMessage(hostDetails(hostId(id), sid));
+ if (type.equals(DEVICE)) {
+ pp = deviceDetails(deviceId(id), sid);
+ overlayCache.currentOverlay().modifyDeviceDetails(pp);
+ } else if (type.equals(HOST)) {
+ pp = hostDetails(hostId(id), sid);
+ overlayCache.currentOverlay().modifyHostDetails(pp);
}
+
+ ObjectNode json = JsonUtils.envelope(SHOW_DETAILS, sid, json(pp));
+ sendMessage(json);
}
}
@@ -364,8 +398,8 @@
@Override
public void process(long sid, ObjectNode payload) {
// TODO: add protection against device ids and non-existent hosts.
- HostId one = hostId(string(payload, "one"));
- HostId two = hostId(string(payload, "two"));
+ HostId one = hostId(string(payload, ONE));
+ HostId two = hostId(string(payload, TWO));
HostToHostIntent intent = HostToHostIntent.builder()
.appId(appId)
@@ -386,8 +420,8 @@
@Override
public void process(long sid, ObjectNode payload) {
// TODO: add protection against device ids and non-existent hosts.
- Set<HostId> src = getHostIds((ArrayNode) payload.path("src"));
- HostId dst = hostId(string(payload, "dst"));
+ Set<HostId> src = getHostIds((ArrayNode) payload.path(SRC));
+ HostId dst = hostId(string(payload, DST));
Host dstHost = hostService.getHost(dst);
Set<ConnectPoint> ingressPoints = getHostLocations(src);
@@ -421,12 +455,12 @@
// Cancel any other traffic monitoring mode.
stopTrafficMonitoring();
- if (!payload.has("ids")) {
+ if (!payload.has(IDS)) {
return;
}
// Get the set of selected hosts and their intents.
- ArrayNode ids = (ArrayNode) payload.path("ids");
+ ArrayNode ids = (ArrayNode) payload.path(IDS);
selectedHosts = getHosts(ids);
selectedDevices = getDevices(ids);
selectedIntents = intentFilter.findPathIntents(
@@ -435,7 +469,7 @@
if (haveSelectedIntents()) {
// Send a message to highlight all links of all monitored intents.
- sendMessage(trafficMessage(new TrafficClass("primary", selectedIntents)));
+ sendMessage(trafficMessage(new TrafficClass(PRIMARY, selectedIntents)));
}
// TODO: Re-introduce once the client click vs hover gesture stuff is sorted out.
@@ -548,7 +582,7 @@
private synchronized void requestSummary(long sid) {
PropertyPanel pp = summmaryMessage(sid);
overlayCache.currentOverlay().modifySummary(pp);
- ObjectNode json = JsonUtils.envelope("showSummary", sid, json(pp));
+ ObjectNode json = JsonUtils.envelope(SHOW_SUMMARY, sid, json(pp));
sendMessage(json);
}
@@ -668,12 +702,12 @@
startTrafficMonitoring();
// Get the set of selected hosts and their intents.
- ArrayNode ids = (ArrayNode) payload.path("ids");
+ ArrayNode ids = (ArrayNode) payload.path(IDS);
Set<Host> hosts = new HashSet<>();
Set<Device> devices = getDevices(ids);
// If there is a hover node, include it in the hosts and find intents.
- String hover = JsonUtils.string(payload, "hover");
+ String hover = JsonUtils.string(payload, HOVER);
if (!isNullOrEmpty(hover)) {
addHover(hosts, devices, hover);
}
@@ -699,8 +733,8 @@
secondary.removeAll(primary);
// Send a message to highlight all links of all monitored intents.
- sendMessage(trafficMessage(new TrafficClass("primary", primary),
- new TrafficClass("secondary", secondary)));
+ sendMessage(trafficMessage(new TrafficClass(PRIMARY, primary),
+ new TrafficClass(SECONDARY, secondary)));
}
// Requests next or previous related intent.
@@ -720,7 +754,7 @@
// selected intent highlighted.
private void sendSelectedIntent() {
Intent selectedIntent = selectedIntents.get(currentIntentIndex);
- log.info("Requested next intent {}", selectedIntent.id());
+ log.debug("Requested next intent {}", selectedIntent.id());
Set<Intent> primary = new HashSet<>();
primary.add(selectedIntent);
@@ -729,8 +763,8 @@
secondary.remove(selectedIntent);
// Send a message to highlight all links of the selected intent.
- sendMessage(trafficMessage(new TrafficClass("primary", primary),
- new TrafficClass("secondary", secondary)));
+ sendMessage(trafficMessage(new TrafficClass(PRIMARY, primary),
+ new TrafficClass(SECONDARY, secondary)));
}
// Requests monitoring of traffic for the selected intent.
@@ -740,13 +774,13 @@
currentIntentIndex = 0;
}
Intent selectedIntent = selectedIntents.get(currentIntentIndex);
- log.info("Requested traffic for selected {}", selectedIntent.id());
+ log.debug("Requested traffic for selected {}", selectedIntent.id());
Set<Intent> primary = new HashSet<>();
primary.add(selectedIntent);
// Send a message to highlight all links of the selected intent.
- sendMessage(trafficMessage(new TrafficClass("primary", primary, true)));
+ sendMessage(trafficMessage(new TrafficClass(PRIMARY, primary, true)));
}
}
@@ -805,7 +839,7 @@
@Override
public void event(MastershipEvent event) {
msgSender.execute(() -> {
- sendAllInstances("updateInstance");
+ sendAllInstances(UPDATE_INSTANCE);
Device device = deviceService.getDevice(event.subject());
if (device != null) {
sendMessage(deviceMessage(new DeviceEvent(DEVICE_UPDATED, device)));