List<SwitchConfig> switchConfigurations = new ArrayList<SwitchConfig>();
for(Switch sw : nodes) {
Node n = sw.getNode();
- SwitchConfig config = switchManager.getSwitchConfig(n.getNodeIDString());
+ SwitchConfig config = switchManager.getSwitchConfig(n.toString());
switchConfigurations.add(config);
}
for (Map.Entry<Node, Set<Edge>> e : nodeEdges.entrySet()) {
Node n = e.getKey();
- SwitchConfig config = switchManager.getSwitchConfig(n.getNodeIDString());
- NodeBean node = createNodeBean(config, n);
+ String description = switchManager.getNodeDescription(n);
+ NodeBean node = createNodeBean(description, n);
List<Map<String, Object>> adjacencies = new LinkedList<Map<String, Object>>();
Set<Edge> links = e.getValue();
if (cache.containsKey(node.id())) {
// retrieve node from cache
Map<String, Object> nodeEntry = cache.get(node.id());
- // update node name when appropriate
- if (config != null) {
- Map<String, String> data = (Map<String, String>) nodeEntry.get("data");
- data.put("$desc", config.getNodeDescription());
- nodeEntry.put("data", data);
- }
+
+ Map<String, String> data = (Map<String, String>) nodeEntry.get("data");
+ data.put("$desc", description);
+ nodeEntry.put("data", data);
+
// always update adjacencies
nodeEntry.put("adjacencies", adjacencies);
// stage this cached node (with position)
}
}
- protected NodeBean createNodeBean(SwitchConfig config, Node node) {
- NodeBean bean = null;
- if (config != null) {
- bean = new NodeBean(node.toString(), config.getNodeDescription(), NodeType.NODE);
- } else {
- bean = new NodeBean(node.toString(), node.toString(), NodeType.NODE);
- }
-
- return bean;
+ protected NodeBean createNodeBean(String description, Node node) {
+ String name = (description == null ||
+ description.trim().isEmpty() ||
+ description.equalsIgnoreCase("none"))?
+ node.toString() : description;
+ return new NodeBean(node.toString(), name, NodeType.NODE);
}
- private void addSingleNodes(List<Switch> nodes, ISwitchManager switchManager) {
+ @SuppressWarnings("unchecked")
+ private void addSingleNodes(List<Switch> nodes, ISwitchManager switchManager) {
if (nodes == null) return;
for (Switch sw : nodes) {
Node n = sw.getNode();
- SwitchConfig config = switchManager.getSwitchConfig(n.getNodeIDString());
+
+ String description = switchManager.getNodeDescription(n);
if ((stagedNodes.containsKey(n.toString()) && cache.containsKey(n.toString())) || newNodes.containsKey(n.toString())) {
continue;
}
- NodeBean node = createNodeBean(config, n);
+ NodeBean node = createNodeBean(description, n);
// FIXME still doesn't display standalone node when last remaining link is removed
if (cache.containsKey(node.id()) && !stagedNodes.containsKey(node.id())) {
Map<String, Object> nodeEntry = cache.get(node.id());
- if (config != null) {
- Map<String, String> data = (Map<String, String>) nodeEntry.get("data");
- data.put("$desc", config.getNodeDescription());
- nodeEntry.put("data", data);
- }
+ Map<String, String> data = (Map<String, String>) nodeEntry.get("data");
+ data.put("$desc", description);
+ nodeEntry.put("data", data);
stagedNodes.put(node.id(), nodeEntry);
} else {
newNodes.put(node.id(), node.out());
public void testCreateNodeBean() {
Topology topology = new Topology();
Node node = NodeCreator.createOFNode(new Long(3));
- SwitchConfig mockSwitchConfig = new SwitchConfig(node.getNodeIDString(), "foo", null, null);
+ String description = "foo";
- NodeBean bean = topology.createNodeBean(mockSwitchConfig, node);
+ NodeBean bean = topology.createNodeBean(description, node);
assertNotNull(bean);
assertEquals(bean.id, node.toString());
assertNotNull(bean);
assertEquals(bean.id, node.toString());
assertEquals(bean.name, bean.id);
+
+ bean = topology.createNodeBean(" ", node);
+
+ assertNotNull(bean);
+ assertEquals(bean.id, node.toString());
+ assertEquals(bean.name, bean.id);
}
}