Topology REST updates and cleanup:
 * Added new REST call: /wm/onos/topology/all
   It returns the whole topology: switches (and ports), links, devices:

{
    "switches": [
        ...
    ],
    "devices": [
        ...
    ],
    "links": [
        ...
    ]
}

 * Modified the path for existing topology REST calls to remove the
   trailing "/json":

/wm/onos/topology/devices/json -> /wm/onos/topology/devices
/wm/onos/topology/links/json -> /wm/onos/topology/links
/wm/onos/topology/switches/json -> /wm/onos/topology/switches

 * Added new ONOS CLI command "show topology all" to show the whole
   topology

 * Updated the ONOS CLI with the above REST calls path renaming

 * Minor cleanup and bug fixes in the ONOS CLI

Change-Id: I96b85ca7a491671f049f30136618d00086384063
diff --git a/onoscli b/onoscli
index 127ec95..31d47f8 100755
--- a/onoscli
+++ b/onoscli
@@ -207,6 +207,10 @@
 	    Command("show switch", "Show switches"),
 	    #
 	    Command("show switch all", "Show all switches", self.show_switch_all)
+	    #
+	    Command("show topology", "Show network topology"),
+	    #
+	    Command("show topology all", "Show whole network topology", self.show_topology_all)
 	]
 
 	# Sort the commands by the level in the CLI command hierarchy
@@ -298,7 +302,7 @@
     def show_device_all(self, args):
 	"CLI command callback: show device all"
 
-	url = "http://%s:%s/wm/onos/topology/devices/json" % (self.onos_ip, self.onos_port)
+	url = "http://%s:%s/wm/onos/topology/devices" % (self.onos_ip, self.onos_port)
 	result = get_json(url)
 	self.print_json_result(result)
 
@@ -331,7 +335,7 @@
     def show_link_all(self, args):
 	"CLI command callback: show link all"
 
-	url = "http://%s:%s/wm/onos/topology/links/json" % (self.onos_ip, self.onos_port)
+	url = "http://%s:%s/wm/onos/topology/links" % (self.onos_ip, self.onos_port)
 	result = get_json(url)
 	#
 	if (self.output_format == "json"):
@@ -364,7 +368,15 @@
     def show_switch_all(self, args):
 	"CLI command callback: show switch all"
 
-	url = "http://%s:%s/wm/onos/topology/switches/json" % (self.onos_ip, self.onos_port)
+	url = "http://%s:%s/wm/onos/topology/switches" % (self.onos_ip, self.onos_port)
+	result = get_json(url)
+	#
+	self.print_json_result(result)
+
+    def show_topology_all(self, args):
+	"CLI command callback: show topology all"
+
+	url = "http://%s:%s/wm/onos/topology/all" % (self.onos_ip, self.onos_port)
 	result = get_json(url)
 	#
 	self.print_json_result(result)
@@ -577,12 +589,13 @@
     """Make a REST GET call and return the JSON result
        url: the URL to call"""
 
-    parsed_result = ""
+    parsed_result = []
     try:
 	response = urllib2.urlopen(url)
 	result = response.read()
 	response.close()
-	parsed_result = json.loads(result)
+	if len(result) != 0:
+	    parsed_result = json.loads(result)
     except HTTPError as exc:
 	print "ERROR:"
 	print "  REST GET URL: %s" % url
@@ -604,7 +617,7 @@
        url: the URL to call
        data: the data to POST"""
 
-    parsed_result = ""
+    parsed_result = []
     data_json = json.dumps(data)
     try:
 	request = urllib2.Request(url, data_json)
@@ -634,7 +647,7 @@
     """Make a REST DELETE call and return the JSON result
        url: the URL to call"""
 
-    parsed_result = ""
+    parsed_result = []
     try:
 	request = urllib2.Request(url)
 	request.get_method = lambda: 'DELETE'
diff --git a/src/main/java/net/onrc/onos/core/topology/web/TopologyAllResource.java b/src/main/java/net/onrc/onos/core/topology/web/TopologyAllResource.java
new file mode 100644
index 0000000..700ca60
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/topology/web/TopologyAllResource.java
@@ -0,0 +1,33 @@
+package net.onrc.onos.core.topology.web;
+
+import net.onrc.onos.core.topology.ITopologyService;
+import net.onrc.onos.core.topology.Topology;
+
+import org.restlet.representation.Representation;
+import org.restlet.resource.Get;
+import org.restlet.resource.ServerResource;
+
+/**
+ * A class to access the network topology information.
+ */
+public class TopologyAllResource extends ServerResource {
+    /**
+     * Gets the network topology information.
+     *
+     * @return a Representation of the network topology.
+     */
+    @Get("json")
+    public Representation retrieve() {
+        ITopologyService topologyService =
+            (ITopologyService) getContext().getAttributes()
+                .get(ITopologyService.class.getCanonicalName());
+
+        Topology topology = topologyService.getTopology();
+        topology.acquireReadLock();
+        try {
+            return toRepresentation(topology, null);
+        } finally {
+            topology.releaseReadLock();
+        }
+    }
+}
diff --git a/src/main/java/net/onrc/onos/core/topology/web/TopologyWebRoutable.java b/src/main/java/net/onrc/onos/core/topology/web/TopologyWebRoutable.java
index cef3ac3..9e5dabe 100644
--- a/src/main/java/net/onrc/onos/core/topology/web/TopologyWebRoutable.java
+++ b/src/main/java/net/onrc/onos/core/topology/web/TopologyWebRoutable.java
@@ -17,9 +17,10 @@
         router.attach("/ds/ports/json", DatastorePortsResource.class);
 
         // Topology API
-        router.attach("/switches/json", TopologySwitchesResource.class);
-        router.attach("/links/json", TopologyLinksResource.class);
-        router.attach("/devices/json", TopologyDevicesResource.class);
+        router.attach("/all", TopologyAllResource.class);
+        router.attach("/devices", TopologyDevicesResource.class);
+        router.attach("/links", TopologyLinksResource.class);
+        router.attach("/switches", TopologySwitchesResource.class);
         // TODO: Move the Shortest Path REST API to the Intent framework
         router.attach("/shortest-path/{src-dpid}/{dst-dpid}/json", TopologyShortestPathResource.class);