Added ui-cache-regions CLI command.

Change-Id: I196543792c85e40e582f9456e4e50dd33bedf111
diff --git a/web/gui/BUCK b/web/gui/BUCK
index 4b48069..adf99ef 100644
--- a/web/gui/BUCK
+++ b/web/gui/BUCK
@@ -5,6 +5,8 @@
     '//lib:jetty-websocket',
     '//lib:jetty-util',
     '//lib:jersey-media-multipart',
+    '//lib:org.apache.karaf.shell.console',
+    '//cli:onos-cli',
     '//incubator/api:onos-incubator-api',
     '//incubator/net:onos-incubator-net',
     '//utils/rest:onlab-rest',
diff --git a/web/gui/pom.xml b/web/gui/pom.xml
index c4c4ba0..ce301f6 100644
--- a/web/gui/pom.xml
+++ b/web/gui/pom.xml
@@ -64,6 +64,15 @@
             <groupId>org.glassfish.jersey.media</groupId>
             <artifactId>jersey-media-multipart</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-cli</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.shell</groupId>
+            <artifactId>org.apache.karaf.shell.console</artifactId>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/cli/ListRegions.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/cli/ListRegions.java
new file mode 100644
index 0000000..f7c7972
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/cli/ListRegions.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.ui.impl.topo.cli;
+
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel;
+
+/**
+ * CLI command to list the UiRegions stored in the ModelCache.
+ */
+@Command(scope = "onos", name = "ui-cache-regions",
+        description = "Lists UiRegions in the Model Cache")
+public class ListRegions extends AbstractShellCommand {
+
+    @Override
+    protected void execute() {
+        UiSharedTopologyModel model = get(UiSharedTopologyModel.class);
+        model.getRegions().forEach(r -> print("%s", r));
+    }
+}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/cli/package-info.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/cli/package-info.java
new file mode 100644
index 0000000..bdb21b3
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/cli/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Topology View Model Cache CLI commands.
+ */
+package org.onosproject.ui.impl.topo.cli;
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/model/ModelCache.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/model/ModelCache.java
index 8647c59..e3fedd1 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/topo/model/ModelCache.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/model/ModelCache.java
@@ -240,6 +240,10 @@
         }
     }
 
+    Set<UiRegion> getAllRegions() {
+        return uiTopology.allRegions();
+    }
+
 
     // === DEVICES
 
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/model/UiSharedTopologyModel.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/model/UiSharedTopologyModel.java
index 4fbf707..52eea69 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/topo/model/UiSharedTopologyModel.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/model/UiSharedTopologyModel.java
@@ -68,6 +68,7 @@
 import org.slf4j.LoggerFactory;
 
 import java.util.List;
+import java.util.Set;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -196,7 +197,7 @@
 
 
     // =======================================================================
-    //  methods that the topo session will use to extract information from us
+    //  Methods for topo session (or CLI) to use to get information from us
 
     /**
      * Returns the list of cluster members stored in our model cache.
@@ -208,6 +209,15 @@
     }
 
     /**
+     * Returns the set of regions stored in our model cache.
+     *
+     * @return set of regions
+     */
+    public Set<UiRegion> getRegions() {
+        return cache.getAllRegions();
+    }
+
+    /**
      * Returns the region for the given identifier.
      *
      * @param id region identifier
diff --git a/web/gui/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/web/gui/src/main/resources/OSGI-INF/blueprint/shell-config.xml
new file mode 100644
index 0000000..4d1abe3
--- /dev/null
+++ b/web/gui/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -0,0 +1,27 @@
+<!--
+  ~ Copyright 2016-present Open Networking Laboratory
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+        <command>
+            <action class="org.onosproject.ui.impl.topo.cli.ListRegions"/>
+        </command>
+    </command-bundle>
+
+    <!--<bean id="macIDCompleter" class="org.onosproject.dhcp.cli.MacIdCompleter"/>-->
+
+</blueprint>
\ No newline at end of file