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/cli/src/main/java/org/onosproject/cli/net/RegionAddCommand.java b/cli/src/main/java/org/onosproject/cli/net/RegionAddCommand.java
index eff8fb5..db91db6 100644
--- a/cli/src/main/java/org/onosproject/cli/net/RegionAddCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/RegionAddCommand.java
@@ -39,10 +39,13 @@
         description = "Adds a new region.")
 public class RegionAddCommand extends AbstractShellCommand {
 
+    private static final String E_BAD_LOC_TYPE = "locType must be {geo|grid}";
+
+    private static final String GEO = "geo";
+    private static final String GRID = "grid";
     private static final String SLASH = "/";
 
-    private static final BiMap<String, Region.Type> REGION_TYPE_MAP
-            = HashBiMap.create();
+    private static final BiMap<String, Region.Type> REGION_TYPE_MAP = HashBiMap.create();
 
     static {
         for (Region.Type t : Region.Type.values()) {
@@ -63,15 +66,21 @@
             required = true, multiValued = false)
     String type = null;
 
-    @Argument(index = 3, name = "latitude", description = "Geo latitude",
+    @Argument(index = 3, name = "latOrY",
+            description = "Geo latitude / Grid y-coord",
             required = true, multiValued = false)
-    Double latitude = null;
+    Double latOrY = null;
 
-    @Argument(index = 4, name = "longitude", description = "Geo longitude",
+    @Argument(index = 4, name = "longOrX",
+            description = "Geo longitude / Grid x-coord",
             required = true, multiValued = false)
-    Double longitude = null;
+    Double longOrX = null;
 
-    @Argument(index = 5, name = "masters", description = "Region Master, a set " +
+    @Argument(index = 5, name = "locType", description = "Location type {geo|grid}",
+            required = false, multiValued = false)
+    String locType = GEO;
+
+    @Argument(index = 6, name = "masters", description = "Region Master, a set " +
             "of nodeIds should be split with '/' delimiter (e.g., 1 2 3 / 4 5 6)",
             required = true, multiValued = true)
     List<String> masterArgs = null;
@@ -81,6 +90,33 @@
         RegionAdminService service = get(RegionAdminService.class);
         RegionId regionId = RegionId.regionId(id);
 
+        NetworkConfigService cfgService = get(NetworkConfigService.class);
+        BasicRegionConfig cfg = cfgService.addConfig(regionId, BasicRegionConfig.class);
+        setConfigurationData(cfg);
+
+        List<Set<NodeId>> masters = parseMasterArgs();
+        service.createRegion(regionId, name, REGION_TYPE_MAP.get(type), masters);
+        print("Region successfully added.");
+    }
+
+    private void setConfigurationData(BasicRegionConfig cfg) {
+        cfg.name(name).locType(locType);
+
+        if (GEO.equals(locType)) {
+            cfg.latitude(latOrY).longitude(longOrX);
+
+        } else if (GRID.equals(locType)) {
+            cfg.gridY(latOrY).gridX(longOrX);
+
+        } else {
+            throw new IllegalArgumentException(E_BAD_LOC_TYPE);
+
+        }
+
+        cfg.apply();
+    }
+
+    private List<Set<NodeId>> parseMasterArgs() {
         List<Set<NodeId>> masters = Lists.newArrayList();
         Set<NodeId> nodeIds = Sets.newHashSet();
         for (String masterArg : masterArgs) {
@@ -92,15 +128,6 @@
             }
         }
         masters.add(nodeIds);
-
-        NetworkConfigService cfgService = get(NetworkConfigService.class);
-        BasicRegionConfig cfg = cfgService.addConfig(regionId, BasicRegionConfig.class);
-        cfg.name(name)
-                .latitude(latitude)
-                .longitude(longitude)
-                .apply();
-
-        service.createRegion(regionId, name, REGION_TYPE_MAP.get(type), masters);
-        print("Region successfully added.");
+        return masters;
     }
 }
\ No newline at end of file