ONOS-1721 - GUI -- Websocket Service unit tests written, topo nav glyph added, other minor improvements.
Change-Id: I8199024e884d8538cd7c7d891d4fb4c81541150d
diff --git a/web/gui/src/main/webapp/app/fw/remote/websocket.js b/web/gui/src/main/webapp/app/fw/remote/websocket.js
index cb68098..0ca10e9 100644
--- a/web/gui/src/main/webapp/app/fw/remote/websocket.js
+++ b/web/gui/src/main/webapp/app/fw/remote/websocket.js
@@ -80,7 +80,7 @@
ev = JSON.parse(msgEvent.data);
} catch (e) {
$log.error('Message.data is not valid JSON', msgEvent.data, e);
- return;
+ return null;
}
$log.debug(' << *Rx* ', ev.event, ev.payload);
@@ -89,6 +89,7 @@
h(ev.payload);
} catch (e) {
$log.error('Problem handling event:', ev, e);
+ return null;
}
} else {
$log.warn('Unhandled event:', ev);
@@ -120,8 +121,7 @@
function findGuiSuccessor() {
var ncn = clusterNodes.length,
- ip = undefined,
- node;
+ ip, node;
while (connectRetries < ncn && !ip) {
connectRetries++;
@@ -134,7 +134,7 @@
}
function informListeners(host, url) {
- angular.forEach(openListeners, function(lsnr) {
+ angular.forEach(openListeners, function (lsnr) {
lsnr.cb(host, url);
});
}
@@ -144,6 +144,14 @@
ws.send(JSON.stringify(ev));
}
+ function noHandlersWarn(handlers, caller) {
+ if (!handlers || fs.isEmptyObject(handlers)) {
+ $log.warn('WSS.' + caller + '(): no event handlers');
+ return true;
+ }
+ return false;
+ }
+
// ===================
// === API Functions
@@ -151,6 +159,21 @@
function resetSid() {
sid = 0;
}
+ function resetState() {
+ webSockOpts = undefined;
+ ws = null;
+ wsUp = false;
+ host = undefined;
+ url = undefined;
+ pendingEvents = [];
+ handlers = {};
+ sid = 0;
+ clusterNodes = [];
+ clusterIndex = -1;
+ connectRetries = 0;
+ openListeners = {};
+ nextListenerId = 1;
+ }
// Currently supported opts:
// wsport: web socket port (other than default 8181)
@@ -181,9 +204,14 @@
// * an API object which has an event handler for the key
//
function bindHandlers(handlerMap) {
- var m = d3.map(handlerMap),
+ var m,
dups = [];
+ if (noHandlersWarn(handlerMap, 'bindHandlers')) {
+ return null;
+ }
+ m = d3.map(handlerMap);
+
m.forEach(function (eventId, api) {
var fn = fs.isF(api) || fs.isF(api[eventId]);
if (!fn) {
@@ -205,7 +233,12 @@
// Unbinds the specified message handlers.
// Expected that the same map will be used, but we only care about keys
function unbindHandlers(handlerMap) {
- var m = d3.map(handlerMap);
+ var m;
+
+ if (noHandlersWarn(handlerMap, 'unbindHandlers')) {
+ return null;
+ }
+ m = d3.map(handlerMap);
m.forEach(function (eventId) {
delete handlers[eventId];
@@ -227,8 +260,14 @@
}
function removeOpenListener(lsnr) {
- var id = lsnr && lsnr.id,
- o = openListeners[id];
+ var id = fs.isO(lsnr) && lsnr.id,
+ o;
+ if (!id) {
+ $log.warn('WSS.removeOpenListener(): invalid listener', lsnr);
+ return null;
+ }
+ o = openListeners[id];
+
if (o) {
delete openListeners[id];
}
@@ -270,6 +309,7 @@
return {
resetSid: resetSid,
+ resetState: resetState,
createWebSocket: createWebSocket,
bindHandlers: bindHandlers,
unbindHandlers: unbindHandlers,
diff --git a/web/gui/src/main/webapp/app/fw/svg/glyph.js b/web/gui/src/main/webapp/app/fw/svg/glyph.js
index 3cbef4b..3f65017 100644
--- a/web/gui/src/main/webapp/app/fw/svg/glyph.js
+++ b/web/gui/src/main/webapp/app/fw/svg/glyph.js
@@ -114,6 +114,18 @@
"-2,4.1-2.9,7-2.9c2.9,0,5.1,0.9,6.9,2.9c5,5.4,5.6,17.1,5.4,22.6" +
"h-25C42.3,43.1,43.1,31.5,48.1,26.1z",
+ topo: 'M97.2,76.3H86.6l-7.7-21.9H82c1,0,1.9-0.8,1.9-1.9V35.7c' +
+ '0-1-0.8-1.9-1.9-1.9H65.2c-1,0-1.9,0.8-1.9,1.9v2.6L33.4,26.1v-11' +
+ 'c0-1-0.8-1.9-1.9-1.9H14.7c-1,0-1.9,0.8-1.9,1.9v16.8c0,1,0.8,' +
+ '1.9,1.9,1.9h16.8c1,0,1.9-0.8,1.9-1.9v-2.6l29.9,12.2v9L30.5,76.9' +
+ 'c-0.3-0.3-0.8-0.5-1.3-0.5H12.4c-1,0-1.9,0.8-1.9,1.9V95c0,1,0.8,' +
+ '1.9,1.9,1.9h16.8c1,0,1.9-0.8,1.9-1.9v-6.9h47.4V95c0,1,0.8,1.9,' +
+ '1.9,1.9h16.8c1,0,1.9-0.8,1.9-1.9V78.2C99.1,77.2,98.2,76.3,97.2,' +
+ '76.3z M31.1,85.1v-4.9l32.8-26.4c0.3,0.3,0.8,0.5,1.3,0.5h10.5l' +
+ '7.7,21.9h-3c-1,0-1.9,0.8-1.9,1.9v6.9H31.1z',
+
+ // --- Navigation glyphs ------------------------------------
+
flowTable: 'M15.9,19.1h-8v-13h8V19.1z M90.5,6.1H75.6v13h14.9V6.1z' +
' M71.9,6.1H56.9v13h14.9V6.1z M53.2,6.1H38.3v13h14.9V6.1z M34.5,' +
'6.1H19.6v13h14.9V6.1z M102.2,6.1h-8v13h8V6.1z M102.2,23.6H7.9v' +
diff --git a/web/gui/src/main/webapp/app/fw/svg/icon.js b/web/gui/src/main/webapp/app/fw/svg/icon.js
index e53fe2a..737a8a8 100644
--- a/web/gui/src/main/webapp/app/fw/svg/icon.js
+++ b/web/gui/src/main/webapp/app/fw/svg/icon.js
@@ -51,7 +51,7 @@
nav_apps: 'bird',
nav_cluster: 'node',
- nav_topo: 'unknown', // TODO: need a topology glyph
+ nav_topo: 'topo',
nav_devs: 'switch',
nav_links: 'ports',
nav_hosts: 'endstation',
diff --git a/web/gui/src/main/webapp/app/view/topo/topoSelect.js b/web/gui/src/main/webapp/app/view/topo/topoSelect.js
index 521c917..097b2b0 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoSelect.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoSelect.js
@@ -252,7 +252,7 @@
cb: function () {
ns.navTo(flowPath, { devId: data.props['URI'] });
},
- tt: 'Show flows for this device'
+ tt: 'Show flows table for this device'
});
}