ONOS-6259: Topo2 - Implement server-side highlighting model (WIP)
- added locType parameter to region-add command
- created RegionABC sample topology
- fixed possible NPE in Topo2Jsonifier.jsonClosedRegion()
- added "plain" sprite layout
- check for undefined sprite layout and log a warning
- updated logger.sh script
- fixed Topo2Model to have a reference to colleciton before initialization

Change-Id: Ie6af28516338f5d64576bf465373cb5df3dff52c
diff --git a/web/gui/logger.sh b/web/gui/logger.sh
index 53c3ddad..93a9048 100755
--- a/web/gui/logger.sh
+++ b/web/gui/logger.sh
@@ -3,16 +3,22 @@
 host=${1:-localhost}
 
 ### Set up debug log messages for classes we care about
+#
+# -- NOTE: leave commented out for checked-in source
+#          developer can uncomment locally
+
 onos ${host} <<-EOF
 
-log:set DEBUG org.onosproject.ui.impl.topo.Topo2ViewMessageHandler
-log:set DEBUG org.onosproject.ui.impl.topo.Topo2Jsonifier
-log:set DEBUG org.onosproject.ui.impl.topo.Topo2TrafficMessageHandler
-log:set DEBUG org.onosproject.ui.impl.topo.Traffic2Monitor
+#log:set DEBUG org.onosproject.ui.impl.topo.Topo2ViewMessageHandler
+#log:set DEBUG org.onosproject.ui.impl.topo.Topo2Jsonifier
+#log:set DEBUG org.onosproject.ui.impl.topo.Topo2TrafficMessageHandler
+#log:set DEBUG org.onosproject.ui.impl.topo.Traffic2Monitor
 
-log:set DEBUG org.onosproject.ui.impl.UiWebSocket
+#log:set DEBUG org.onosproject.ui.impl.UiWebSocket
 #log:set DEBUG org.onosproject.ui.impl.UiTopoSession
 
+#log:set DEBUG org.onosproject.ui.impl.topo.model.ModelCache
+
 log:list
 
 EOF
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2Jsonifier.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2Jsonifier.java
index c7a223f..da1f8e4 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2Jsonifier.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2Jsonifier.java
@@ -611,9 +611,11 @@
         //       all descendant subregions.
 
         Region r = region.backingRegion();
-        // this is location data, as injected via network configuration script
-        addGeoGridLocation(node, r);
-        addProps(node, r);
+        if (r != null) {
+            // add data injected via network configuration script
+            addGeoGridLocation(node, r);
+            addProps(node, r);
+        }
 
         // this may contain location data, as dragged by user
         // (which should take precedence, over configured data)
diff --git a/web/gui/src/main/webapp/app/fw/svg/sprite.js b/web/gui/src/main/webapp/app/fw/svg/sprite.js
index 6eafe66..b64f58d 100644
--- a/web/gui/src/main/webapp/app/fw/svg/sprite.js
+++ b/web/gui/src/main/webapp/app/fw/svg/sprite.js
@@ -215,9 +215,9 @@
 
     // Returns a layout "builder", which can be used to programmatically
     // define a layout.
-    function createLayout(id, w, h, grid) {
-        $log.debug('createLayout:', id, w, 'x', h, '(grid=' + grid + ')');
-        return layoutBuilder(id, w, h, grid);
+    function createLayout(id, w, h, opts) {
+        $log.debug('createLayout:', id, w, 'x', h, '(opts:', opts, ')');
+        return layoutBuilder(id, w, h, opts);
     }
 
     // Registers a sprite defined by the given object (JSON structure).
diff --git a/web/gui/src/main/webapp/app/fw/svg/spriteData.js b/web/gui/src/main/webapp/app/fw/svg/spriteData.js
index 1625a46..d970af9 100644
--- a/web/gui/src/main/webapp/app/fw/svg/spriteData.js
+++ b/web/gui/src/main/webapp/app/fw/svg/spriteData.js
@@ -77,6 +77,9 @@
             .addLabel('Segment Routing 2', 120, 10, {anchor: 'right'})
             .register();
 
+        ssApi.createLayout('plain', 80, 60)
+            .register();
+
         ssApi.dump();
         // ----------------------------------------------------------$$$
     }
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2Model.js b/web/gui/src/main/webapp/app/view/topo2/topo2Model.js
index efcd201..6da29c4 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2Model.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Model.js
@@ -25,6 +25,7 @@
     function Model(attributes, collection) {
         this.attributes = {};
         this.set(angular.extend({}, attributes || {}), { silent: true });
+        this.collection = collection;
         this.initialize.apply(this, arguments);
     }
 
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2Overlay.js b/web/gui/src/main/webapp/app/view/topo2/topo2Overlay.js
index 1227c30..222e837 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2Overlay.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Overlay.js
@@ -141,7 +141,8 @@
             // TODO: Inconsistent host id's (currentRegion and LinkLabel)
             var id = link.id.replace('/None/0', '/None').replace('-', '~'),
                 lab = t2rs.getLink(id);
-                // TODO: There's a bug in backend where link id is in reverse
+                // DONE: There's a bug in backend where link id is in reverse
+                //       This is fixed -- SDH
                 if (lab) {
                     t2lc.addLabel(LinkLabel, link, linkLabelsDOM, {
                         link: lab
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2SpriteLayer.js b/web/gui/src/main/webapp/app/view/topo2/topo2SpriteLayer.js
index 98e890b..f53ccc6 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2SpriteLayer.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2SpriteLayer.js
@@ -31,9 +31,10 @@
 
     angular.module('ovTopo2')
         .factory('Topo2SpriteLayerService', [
-            'FnService', 'Topo2ViewController', 'SpriteService', 'ThemeService',
+            '$log', 'FnService',
+            'Topo2ViewController', 'SpriteService', 'ThemeService',
 
-            function (fs, ViewController, ss, ts) {
+            function ($log, fs, ViewController, ss, ts) {
 
                 var SpriteLayer = ViewController.extend({
 
@@ -50,13 +51,17 @@
                         this.container.selectAll("*").remove();
                         this.layout = ss.layout(id);
 
-                        this.width = this.layout.data.w;
-                        this.height = this.layout.data.h;
+                        if (this.layout) {
+                            this.width = this.layout.data.w;
+                            this.height = this.layout.data.h;
 
-                        this.renderLayout();
+                            this.renderLayout();
 
-                        if (fs.debugOn('sprite_grid')) {
-                            this.renderGrid();
+                            if (fs.debugOn('sprite_grid')) {
+                                this.renderGrid();
+                            }
+                        } else {
+                            $log.warn('no sprite layout registered:', id);
                         }
 
                         // Returns a promise for consistency with Topo2MapService