More plumbing of grid coordinates vs. geo coordinates.
- Added background reference parameter to layout command
- send correct location data to client for devices, hosts
Change-Id: Ic00bda76f4e4bc8d3e23e07a08f3bc5367ec85a9
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyResource.java b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyResource.java
index fa2613b..2f813d0 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyResource.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyResource.java
@@ -40,10 +40,23 @@
@Path("topology")
public class TopologyResource extends BaseResource {
+ private static final String ID = "id";
+ private static final String URI = "uri";
+
+ // length of a MAC defined as a string ... "xx:xx:xx:xx:xx:xx"
+ private static final int MAC_LEN = 17;
+ private static final char SLASH_CHAR = '/';
+
private static final Logger log = getLogger(TopologyResource.class);
private final ObjectMapper mapper = new ObjectMapper();
+ /**
+ * Returns the location data associated with devices and hosts, that is
+ * currently cached in the Meta-UI store.
+ *
+ * @return cached location data for devices and hosts
+ */
@Path("geoloc")
@GET
@Produces("application/json")
@@ -55,10 +68,10 @@
Map<String, ObjectNode> metaUi = TopologyViewMessageHandler.getMetaUi();
for (String id : metaUi.keySet()) {
ObjectNode memento = metaUi.get(id);
- if (id.length() > 17 && id.charAt(17) == '/') {
- addGeoData(hosts, "id", id, memento);
+ if (isHostId(id)) {
+ addGeoData(hosts, ID, id, memento);
} else {
- addGeoData(devices, "uri", id, memento);
+ addGeoData(devices, URI, id, memento);
}
}
@@ -67,11 +80,18 @@
return Response.ok(rootNode.toString()).build();
}
+ private boolean isHostId(String id) {
+ return id.length() > MAC_LEN && id.charAt(MAC_LEN) == SLASH_CHAR;
+ }
+
private void addGeoData(ArrayNode array, String idField, String id,
ObjectNode memento) {
ObjectNode node = mapper.createObjectNode().put(idField, id);
ObjectNode annot = mapper.createObjectNode();
node.set("annotations", annot);
+
+ // TODO: add handling of gridY/gridX if locType is "grid" (not "geo")
+
try {
annot.put("latitude", memento.get("lat").asDouble())
.put("longitude", memento.get("lng").asDouble());
@@ -81,14 +101,22 @@
}
}
+ /**
+ * Stores sprite data for retrieval by the UI Topology View.
+ *
+ * @param stream input data stream (typically from an uploaded file).
+ * @return REST response
+ * @throws IOException if there is an issue reading from the stream
+ * @deprecated since Junco (1.9), in favor of client-side defined sprite layers
+ */
@Path("sprites")
@POST
@Consumes("application/json")
+ @Deprecated
public Response setSprites(InputStream stream) throws IOException {
JsonNode root = mapper.readTree(stream);
String name = root.path("defn_name").asText("sprites");
get(SpriteService.class).put(name, root);
return Response.ok().build();
}
-
}