@Test public void testLoad() { m_databasePopulator.check(m_topologyProvider); }
@Override public void load(String filename) throws MalformedURLException, JAXBException { if (filename != null) { LoggerFactory.getLogger(LinkdTopologyProvider.class).warn("Filename that was specified for linkd topology will be ignored: " + filename + ", using " + m_configurationFile + " instead"); } log("loadtopology: Clear " + VertexProvider.class.getSimpleName()); clearVertices(); log("loadtopology: Clear " + EdgeProvider.class.getSimpleName()); clearEdges(); for (DataLinkInterface link: m_dataLinkInterfaceDao.findAll()) { log("loadtopology: parsing link: " + link.getDataLinkInterfaceId()); OnmsNode node = m_nodeDao.get(link.getNode().getId()); log("loadtopology: found source node: " + node.getLabel()); String sourceId = node.getNodeId(); Vertex source = getVertex(getVertexNamespace(), sourceId); if (source == null) { log("loadtopology: adding source node as vertex: " + node.getLabel()); source = getVertex(node); addVertices(source); } OnmsNode parentNode = m_nodeDao.get(link.getNodeParentId()); log("loadtopology: found target node: " + parentNode.getLabel()); String targetId = parentNode.getNodeId(); Vertex target = getVertex(getVertexNamespace(), targetId); if (target == null) { log("loadtopology: adding target as vertex: " + parentNode.getLabel()); target = getVertex(parentNode); addVertices(target); } AbstractEdge edge = connectVertices(link.getDataLinkInterfaceId(), source, target); edge.setTooltipText(getEdgeTooltipText(link, source, target)); } log("loadtopology: adding nodes without links: " + isAddNodeWithoutLink()); if (isAddNodeWithoutLink()) { for (OnmsNode onmsnode: m_nodeDao.findAll()) { String nodeId = onmsnode.getNodeId(); if (getVertex(getVertexNamespace(), nodeId) == null) { log("loadtopology: adding link-less node: " + onmsnode.getLabel()); addVertices(getVertex(onmsnode)); } } } log("Found " + getVertices().size() + " vertices"); log("Found " + getEdges().size() + " edges"); File configFile = new File(m_configurationFile); if (configFile.exists() && configFile.canRead()) { log("loadtopology: loading topology from configuration file: " + m_configurationFile); m_groupCounter = 0; WrappedGraph graph = getGraphFromFile(configFile); int numberOfGroups = 0; for (WrappedVertex vertex: graph.m_vertices) { if (vertex.group) { log("loadtopology: adding group to topology: " + vertex.id); if (vertex.namespace == null) { vertex.namespace = getVertexNamespace(); LoggerFactory.getLogger(this.getClass()).warn("Setting namespace on vertex to default: {}", vertex); } if (vertex.id == null) { LoggerFactory.getLogger(this.getClass()).warn("Invalid vertex unmarshalled from {}: {}", m_configurationFile, vertex); } else if (vertex.id.startsWith(LINKD_GROUP_ID_PREFIX)) { try { int groupNumber = Integer.parseInt(vertex.id.substring(LINKD_GROUP_ID_PREFIX.length())); if (m_groupCounter <= groupNumber) { m_groupCounter = groupNumber + 1; } } catch (NumberFormatException e) { } } AbstractVertex newVertex = addGroup(vertex.id, vertex.iconKey, vertex.label); newVertex.setIpAddress(vertex.ipAddr); newVertex.setLocked(vertex.locked); if (vertex.nodeID != null) newVertex.setNodeID(vertex.nodeID); if (! newVertex.equals(vertex.parent)) newVertex.setParent(vertex.parent); newVertex.setSelected(vertex.selected); newVertex.setStyleName(vertex.styleName); newVertex.setTooltipText(vertex.tooltipText); if (vertex.x != null) newVertex.setX(vertex.x); if (vertex.y != null) newVertex.setY(vertex.y); numberOfGroups++; } } for (Vertex vertex: getVertices()) { if (vertex.getParent() != null && !vertex.equals(vertex.getParent())) { log("loadtopology: setting parent of " + vertex + " to " + vertex.getParent()); setParent(vertex, vertex.getParent()); } } log("Found " + numberOfGroups + " groups"); } else { log("loadtopology: could not load topology configFile:" + m_configurationFile); } }
LinkdTopologyProvider extends AbstractTopologyProvider implements GraphProvider { @Override public void load(String filename) throws MalformedURLException, JAXBException { if (filename != null) { LoggerFactory.getLogger(LinkdTopologyProvider.class).warn("Filename that was specified for linkd topology will be ignored: " + filename + ", using " + m_configurationFile + " instead"); } log("loadtopology: Clear " + VertexProvider.class.getSimpleName()); clearVertices(); log("loadtopology: Clear " + EdgeProvider.class.getSimpleName()); clearEdges(); for (DataLinkInterface link: m_dataLinkInterfaceDao.findAll()) { log("loadtopology: parsing link: " + link.getDataLinkInterfaceId()); OnmsNode node = m_nodeDao.get(link.getNode().getId()); log("loadtopology: found source node: " + node.getLabel()); String sourceId = node.getNodeId(); Vertex source = getVertex(getVertexNamespace(), sourceId); if (source == null) { log("loadtopology: adding source node as vertex: " + node.getLabel()); source = getVertex(node); addVertices(source); } OnmsNode parentNode = m_nodeDao.get(link.getNodeParentId()); log("loadtopology: found target node: " + parentNode.getLabel()); String targetId = parentNode.getNodeId(); Vertex target = getVertex(getVertexNamespace(), targetId); if (target == null) { log("loadtopology: adding target as vertex: " + parentNode.getLabel()); target = getVertex(parentNode); addVertices(target); } AbstractEdge edge = connectVertices(link.getDataLinkInterfaceId(), source, target); edge.setTooltipText(getEdgeTooltipText(link, source, target)); } log("loadtopology: adding nodes without links: " + isAddNodeWithoutLink()); if (isAddNodeWithoutLink()) { for (OnmsNode onmsnode: m_nodeDao.findAll()) { String nodeId = onmsnode.getNodeId(); if (getVertex(getVertexNamespace(), nodeId) == null) { log("loadtopology: adding link-less node: " + onmsnode.getLabel()); addVertices(getVertex(onmsnode)); } } } log("Found " + getVertices().size() + " vertices"); log("Found " + getEdges().size() + " edges"); File configFile = new File(m_configurationFile); if (configFile.exists() && configFile.canRead()) { log("loadtopology: loading topology from configuration file: " + m_configurationFile); m_groupCounter = 0; WrappedGraph graph = getGraphFromFile(configFile); int numberOfGroups = 0; for (WrappedVertex vertex: graph.m_vertices) { if (vertex.group) { log("loadtopology: adding group to topology: " + vertex.id); if (vertex.namespace == null) { vertex.namespace = getVertexNamespace(); LoggerFactory.getLogger(this.getClass()).warn("Setting namespace on vertex to default: {}", vertex); } if (vertex.id == null) { LoggerFactory.getLogger(this.getClass()).warn("Invalid vertex unmarshalled from {}: {}", m_configurationFile, vertex); } else if (vertex.id.startsWith(LINKD_GROUP_ID_PREFIX)) { try { int groupNumber = Integer.parseInt(vertex.id.substring(LINKD_GROUP_ID_PREFIX.length())); if (m_groupCounter <= groupNumber) { m_groupCounter = groupNumber + 1; } } catch (NumberFormatException e) { } } AbstractVertex newVertex = addGroup(vertex.id, vertex.iconKey, vertex.label); newVertex.setIpAddress(vertex.ipAddr); newVertex.setLocked(vertex.locked); if (vertex.nodeID != null) newVertex.setNodeID(vertex.nodeID); if (! newVertex.equals(vertex.parent)) newVertex.setParent(vertex.parent); newVertex.setSelected(vertex.selected); newVertex.setStyleName(vertex.styleName); newVertex.setTooltipText(vertex.tooltipText); if (vertex.x != null) newVertex.setX(vertex.x); if (vertex.y != null) newVertex.setY(vertex.y); numberOfGroups++; } } for (Vertex vertex: getVertices()) { if (vertex.getParent() != null && !vertex.equals(vertex.getParent())) { log("loadtopology: setting parent of " + vertex + " to " + vertex.getParent()); setParent(vertex, vertex.getParent()); } } log("Found " + numberOfGroups + " groups"); } else { log("loadtopology: could not load topology configFile:" + m_configurationFile); } } }
LinkdTopologyProvider extends AbstractTopologyProvider implements GraphProvider { @Override public void load(String filename) throws MalformedURLException, JAXBException { if (filename != null) { LoggerFactory.getLogger(LinkdTopologyProvider.class).warn("Filename that was specified for linkd topology will be ignored: " + filename + ", using " + m_configurationFile + " instead"); } log("loadtopology: Clear " + VertexProvider.class.getSimpleName()); clearVertices(); log("loadtopology: Clear " + EdgeProvider.class.getSimpleName()); clearEdges(); for (DataLinkInterface link: m_dataLinkInterfaceDao.findAll()) { log("loadtopology: parsing link: " + link.getDataLinkInterfaceId()); OnmsNode node = m_nodeDao.get(link.getNode().getId()); log("loadtopology: found source node: " + node.getLabel()); String sourceId = node.getNodeId(); Vertex source = getVertex(getVertexNamespace(), sourceId); if (source == null) { log("loadtopology: adding source node as vertex: " + node.getLabel()); source = getVertex(node); addVertices(source); } OnmsNode parentNode = m_nodeDao.get(link.getNodeParentId()); log("loadtopology: found target node: " + parentNode.getLabel()); String targetId = parentNode.getNodeId(); Vertex target = getVertex(getVertexNamespace(), targetId); if (target == null) { log("loadtopology: adding target as vertex: " + parentNode.getLabel()); target = getVertex(parentNode); addVertices(target); } AbstractEdge edge = connectVertices(link.getDataLinkInterfaceId(), source, target); edge.setTooltipText(getEdgeTooltipText(link, source, target)); } log("loadtopology: adding nodes without links: " + isAddNodeWithoutLink()); if (isAddNodeWithoutLink()) { for (OnmsNode onmsnode: m_nodeDao.findAll()) { String nodeId = onmsnode.getNodeId(); if (getVertex(getVertexNamespace(), nodeId) == null) { log("loadtopology: adding link-less node: " + onmsnode.getLabel()); addVertices(getVertex(onmsnode)); } } } log("Found " + getVertices().size() + " vertices"); log("Found " + getEdges().size() + " edges"); File configFile = new File(m_configurationFile); if (configFile.exists() && configFile.canRead()) { log("loadtopology: loading topology from configuration file: " + m_configurationFile); m_groupCounter = 0; WrappedGraph graph = getGraphFromFile(configFile); int numberOfGroups = 0; for (WrappedVertex vertex: graph.m_vertices) { if (vertex.group) { log("loadtopology: adding group to topology: " + vertex.id); if (vertex.namespace == null) { vertex.namespace = getVertexNamespace(); LoggerFactory.getLogger(this.getClass()).warn("Setting namespace on vertex to default: {}", vertex); } if (vertex.id == null) { LoggerFactory.getLogger(this.getClass()).warn("Invalid vertex unmarshalled from {}: {}", m_configurationFile, vertex); } else if (vertex.id.startsWith(LINKD_GROUP_ID_PREFIX)) { try { int groupNumber = Integer.parseInt(vertex.id.substring(LINKD_GROUP_ID_PREFIX.length())); if (m_groupCounter <= groupNumber) { m_groupCounter = groupNumber + 1; } } catch (NumberFormatException e) { } } AbstractVertex newVertex = addGroup(vertex.id, vertex.iconKey, vertex.label); newVertex.setIpAddress(vertex.ipAddr); newVertex.setLocked(vertex.locked); if (vertex.nodeID != null) newVertex.setNodeID(vertex.nodeID); if (! newVertex.equals(vertex.parent)) newVertex.setParent(vertex.parent); newVertex.setSelected(vertex.selected); newVertex.setStyleName(vertex.styleName); newVertex.setTooltipText(vertex.tooltipText); if (vertex.x != null) newVertex.setX(vertex.x); if (vertex.y != null) newVertex.setY(vertex.y); numberOfGroups++; } } for (Vertex vertex: getVertices()) { if (vertex.getParent() != null && !vertex.equals(vertex.getParent())) { log("loadtopology: setting parent of " + vertex + " to " + vertex.getParent()); setParent(vertex, vertex.getParent()); } } log("Found " + numberOfGroups + " groups"); } else { log("loadtopology: could not load topology configFile:" + m_configurationFile); } } LinkdTopologyProvider(); }
LinkdTopologyProvider extends AbstractTopologyProvider implements GraphProvider { @Override public void load(String filename) throws MalformedURLException, JAXBException { if (filename != null) { LoggerFactory.getLogger(LinkdTopologyProvider.class).warn("Filename that was specified for linkd topology will be ignored: " + filename + ", using " + m_configurationFile + " instead"); } log("loadtopology: Clear " + VertexProvider.class.getSimpleName()); clearVertices(); log("loadtopology: Clear " + EdgeProvider.class.getSimpleName()); clearEdges(); for (DataLinkInterface link: m_dataLinkInterfaceDao.findAll()) { log("loadtopology: parsing link: " + link.getDataLinkInterfaceId()); OnmsNode node = m_nodeDao.get(link.getNode().getId()); log("loadtopology: found source node: " + node.getLabel()); String sourceId = node.getNodeId(); Vertex source = getVertex(getVertexNamespace(), sourceId); if (source == null) { log("loadtopology: adding source node as vertex: " + node.getLabel()); source = getVertex(node); addVertices(source); } OnmsNode parentNode = m_nodeDao.get(link.getNodeParentId()); log("loadtopology: found target node: " + parentNode.getLabel()); String targetId = parentNode.getNodeId(); Vertex target = getVertex(getVertexNamespace(), targetId); if (target == null) { log("loadtopology: adding target as vertex: " + parentNode.getLabel()); target = getVertex(parentNode); addVertices(target); } AbstractEdge edge = connectVertices(link.getDataLinkInterfaceId(), source, target); edge.setTooltipText(getEdgeTooltipText(link, source, target)); } log("loadtopology: adding nodes without links: " + isAddNodeWithoutLink()); if (isAddNodeWithoutLink()) { for (OnmsNode onmsnode: m_nodeDao.findAll()) { String nodeId = onmsnode.getNodeId(); if (getVertex(getVertexNamespace(), nodeId) == null) { log("loadtopology: adding link-less node: " + onmsnode.getLabel()); addVertices(getVertex(onmsnode)); } } } log("Found " + getVertices().size() + " vertices"); log("Found " + getEdges().size() + " edges"); File configFile = new File(m_configurationFile); if (configFile.exists() && configFile.canRead()) { log("loadtopology: loading topology from configuration file: " + m_configurationFile); m_groupCounter = 0; WrappedGraph graph = getGraphFromFile(configFile); int numberOfGroups = 0; for (WrappedVertex vertex: graph.m_vertices) { if (vertex.group) { log("loadtopology: adding group to topology: " + vertex.id); if (vertex.namespace == null) { vertex.namespace = getVertexNamespace(); LoggerFactory.getLogger(this.getClass()).warn("Setting namespace on vertex to default: {}", vertex); } if (vertex.id == null) { LoggerFactory.getLogger(this.getClass()).warn("Invalid vertex unmarshalled from {}: {}", m_configurationFile, vertex); } else if (vertex.id.startsWith(LINKD_GROUP_ID_PREFIX)) { try { int groupNumber = Integer.parseInt(vertex.id.substring(LINKD_GROUP_ID_PREFIX.length())); if (m_groupCounter <= groupNumber) { m_groupCounter = groupNumber + 1; } } catch (NumberFormatException e) { } } AbstractVertex newVertex = addGroup(vertex.id, vertex.iconKey, vertex.label); newVertex.setIpAddress(vertex.ipAddr); newVertex.setLocked(vertex.locked); if (vertex.nodeID != null) newVertex.setNodeID(vertex.nodeID); if (! newVertex.equals(vertex.parent)) newVertex.setParent(vertex.parent); newVertex.setSelected(vertex.selected); newVertex.setStyleName(vertex.styleName); newVertex.setTooltipText(vertex.tooltipText); if (vertex.x != null) newVertex.setX(vertex.x); if (vertex.y != null) newVertex.setY(vertex.y); numberOfGroups++; } } for (Vertex vertex: getVertices()) { if (vertex.getParent() != null && !vertex.equals(vertex.getParent())) { log("loadtopology: setting parent of " + vertex + " to " + vertex.getParent()); setParent(vertex, vertex.getParent()); } } log("Found " + numberOfGroups + " groups"); } else { log("loadtopology: could not load topology configFile:" + m_configurationFile); } } LinkdTopologyProvider(); String getConfigurationFile(); void setConfigurationFile(String configurationFile); SnmpInterfaceDao getSnmpInterfaceDao(); void setSnmpInterfaceDao(SnmpInterfaceDao snmpInterfaceDao); NodeDao getNodeDao(); void setNodeDao(NodeDao nodeDao); boolean isAddNodeWithoutLink(); void setAddNodeWithoutLink(boolean addNodeWithoutLink); DataLinkInterfaceDao getDataLinkInterfaceDao(); void setDataLinkInterfaceDao(DataLinkInterfaceDao dataLinkInterfaceDao); void onInit(); @Override void refresh(); @Override void load(String filename); static String getIconName(OnmsNode node); @Override void save(); IpInterfaceDao getIpInterfaceDao(); void setIpInterfaceDao(IpInterfaceDao ipInterfaceDao); }
LinkdTopologyProvider extends AbstractTopologyProvider implements GraphProvider { @Override public void load(String filename) throws MalformedURLException, JAXBException { if (filename != null) { LoggerFactory.getLogger(LinkdTopologyProvider.class).warn("Filename that was specified for linkd topology will be ignored: " + filename + ", using " + m_configurationFile + " instead"); } log("loadtopology: Clear " + VertexProvider.class.getSimpleName()); clearVertices(); log("loadtopology: Clear " + EdgeProvider.class.getSimpleName()); clearEdges(); for (DataLinkInterface link: m_dataLinkInterfaceDao.findAll()) { log("loadtopology: parsing link: " + link.getDataLinkInterfaceId()); OnmsNode node = m_nodeDao.get(link.getNode().getId()); log("loadtopology: found source node: " + node.getLabel()); String sourceId = node.getNodeId(); Vertex source = getVertex(getVertexNamespace(), sourceId); if (source == null) { log("loadtopology: adding source node as vertex: " + node.getLabel()); source = getVertex(node); addVertices(source); } OnmsNode parentNode = m_nodeDao.get(link.getNodeParentId()); log("loadtopology: found target node: " + parentNode.getLabel()); String targetId = parentNode.getNodeId(); Vertex target = getVertex(getVertexNamespace(), targetId); if (target == null) { log("loadtopology: adding target as vertex: " + parentNode.getLabel()); target = getVertex(parentNode); addVertices(target); } AbstractEdge edge = connectVertices(link.getDataLinkInterfaceId(), source, target); edge.setTooltipText(getEdgeTooltipText(link, source, target)); } log("loadtopology: adding nodes without links: " + isAddNodeWithoutLink()); if (isAddNodeWithoutLink()) { for (OnmsNode onmsnode: m_nodeDao.findAll()) { String nodeId = onmsnode.getNodeId(); if (getVertex(getVertexNamespace(), nodeId) == null) { log("loadtopology: adding link-less node: " + onmsnode.getLabel()); addVertices(getVertex(onmsnode)); } } } log("Found " + getVertices().size() + " vertices"); log("Found " + getEdges().size() + " edges"); File configFile = new File(m_configurationFile); if (configFile.exists() && configFile.canRead()) { log("loadtopology: loading topology from configuration file: " + m_configurationFile); m_groupCounter = 0; WrappedGraph graph = getGraphFromFile(configFile); int numberOfGroups = 0; for (WrappedVertex vertex: graph.m_vertices) { if (vertex.group) { log("loadtopology: adding group to topology: " + vertex.id); if (vertex.namespace == null) { vertex.namespace = getVertexNamespace(); LoggerFactory.getLogger(this.getClass()).warn("Setting namespace on vertex to default: {}", vertex); } if (vertex.id == null) { LoggerFactory.getLogger(this.getClass()).warn("Invalid vertex unmarshalled from {}: {}", m_configurationFile, vertex); } else if (vertex.id.startsWith(LINKD_GROUP_ID_PREFIX)) { try { int groupNumber = Integer.parseInt(vertex.id.substring(LINKD_GROUP_ID_PREFIX.length())); if (m_groupCounter <= groupNumber) { m_groupCounter = groupNumber + 1; } } catch (NumberFormatException e) { } } AbstractVertex newVertex = addGroup(vertex.id, vertex.iconKey, vertex.label); newVertex.setIpAddress(vertex.ipAddr); newVertex.setLocked(vertex.locked); if (vertex.nodeID != null) newVertex.setNodeID(vertex.nodeID); if (! newVertex.equals(vertex.parent)) newVertex.setParent(vertex.parent); newVertex.setSelected(vertex.selected); newVertex.setStyleName(vertex.styleName); newVertex.setTooltipText(vertex.tooltipText); if (vertex.x != null) newVertex.setX(vertex.x); if (vertex.y != null) newVertex.setY(vertex.y); numberOfGroups++; } } for (Vertex vertex: getVertices()) { if (vertex.getParent() != null && !vertex.equals(vertex.getParent())) { log("loadtopology: setting parent of " + vertex + " to " + vertex.getParent()); setParent(vertex, vertex.getParent()); } } log("Found " + numberOfGroups + " groups"); } else { log("loadtopology: could not load topology configFile:" + m_configurationFile); } } LinkdTopologyProvider(); String getConfigurationFile(); void setConfigurationFile(String configurationFile); SnmpInterfaceDao getSnmpInterfaceDao(); void setSnmpInterfaceDao(SnmpInterfaceDao snmpInterfaceDao); NodeDao getNodeDao(); void setNodeDao(NodeDao nodeDao); boolean isAddNodeWithoutLink(); void setAddNodeWithoutLink(boolean addNodeWithoutLink); DataLinkInterfaceDao getDataLinkInterfaceDao(); void setDataLinkInterfaceDao(DataLinkInterfaceDao dataLinkInterfaceDao); void onInit(); @Override void refresh(); @Override void load(String filename); static String getIconName(OnmsNode node); @Override void save(); IpInterfaceDao getIpInterfaceDao(); void setIpInterfaceDao(IpInterfaceDao ipInterfaceDao); static final String TOPOLOGY_NAMESPACE_LINKD; static final String GROUP_ICON_KEY; static final String SERVER_ICON_KEY; }