use of org.opennms.features.graphml.model.InvalidGraphException in project opennms by OpenNMS.
the class GraphMLSearchProviderTest method canSearchAllSearchProviders.
@Test
public void canSearchAllSearchProviders() throws IOException, InvalidGraphException {
final GraphMLMetaTopologyProvider metaTopologyProvider = new GraphMLMetaTopologyProvider(new GraphMLServiceAccessor());
metaTopologyProvider.setTopologyLocation("target/test-classes/test-graph.xml");
metaTopologyProvider.reload();
Assert.assertNotNull(metaTopologyProvider.getDefaultGraphProvider());
List<SearchProvider> searchProviders = metaTopologyProvider.getGraphProviders().stream().map(eachProvider -> new GraphMLSearchProvider(metaTopologyProvider.getRawTopologyProvider(eachProvider.getNamespace()))).collect(Collectors.toList());
Assert.assertEquals(2, searchProviders.size());
DefaultTopologyService defaultTopologyService = new DefaultTopologyService();
defaultTopologyService.setServiceLocator(new SimpleServiceLocator(metaTopologyProvider));
VEProviderGraphContainer graphContainer = new VEProviderGraphContainer();
graphContainer.setTopologyService(defaultTopologyService);
graphContainer.setMetaTopologyId(metaTopologyProvider.getId());
graphContainer.setSelectedNamespace(metaTopologyProvider.getDefaultGraphProvider().getNamespace());
OperationContext operationContext = EasyMock.niceMock(OperationContext.class);
EasyMock.expect(operationContext.getGraphContainer()).andReturn(graphContainer).anyTimes();
OnmsServiceManager onmsServiceManager = EasyMock.niceMock(OnmsServiceManager.class);
EasyMock.expect(onmsServiceManager.getServices(SearchProvider.class, null, new Hashtable<>())).andReturn(searchProviders).anyTimes();
EasyMock.replay(onmsServiceManager, operationContext);
SearchBox searchBox = new SearchBox(onmsServiceManager, operationContext);
List<SearchSuggestion> results = searchBox.getQueryResults("North");
Assert.assertEquals(5, results.size());
}
use of org.opennms.features.graphml.model.InvalidGraphException in project opennms by OpenNMS.
the class GraphMLVertexStatusProviderTest method testStatusProvider.
@Test
public void testStatusProvider() throws InvalidGraphException {
GraphML graphML = GraphMLReader.read(getClass().getResourceAsStream("/test-graph.xml"));
GraphMLTopologyProvider topologyProvider = new GraphMLTopologyProvider(graphML.getGraphs().get(0), new GraphMLServiceAccessor());
GraphMLVertexStatusProvider statusProvider = new GraphMLVertexStatusProvider(topologyProvider.getNamespace(), nodeIds -> Lists.newArrayList(createSummary(1, "North", OnmsSeverity.WARNING, 1), createSummary(2, "West", OnmsSeverity.MINOR, 2), createSummary(3, "South", OnmsSeverity.MAJOR, 3)));
List<VertexRef> vertices = topologyProvider.getVertices().stream().map(eachVertex -> (VertexRef) eachVertex).collect(Collectors.toList());
Assert.assertEquals(4, vertices.size());
Assert.assertEquals(topologyProvider.getNamespace(), statusProvider.getNamespace());
Assert.assertEquals(Boolean.TRUE, statusProvider.contributesTo(topologyProvider.getNamespace()));
Map<VertexRef, Status> statusForVertices = statusProvider.getStatusForVertices(topologyProvider, vertices, new Criteria[0]);
Assert.assertEquals(4, statusForVertices.size());
Assert.assertEquals(ImmutableMap.of(createVertexRef(topologyProvider.getNamespace(), "north"), createStatus(OnmsSeverity.WARNING, 1), createVertexRef(topologyProvider.getNamespace(), "west"), createStatus(OnmsSeverity.MINOR, 2), createVertexRef(topologyProvider.getNamespace(), "south"), createStatus(OnmsSeverity.MAJOR, 3), createVertexRef(topologyProvider.getNamespace(), "east"), createStatus(OnmsSeverity.NORMAL, 0)), statusForVertices);
}
use of org.opennms.features.graphml.model.InvalidGraphException in project opennms by OpenNMS.
the class GraphMLMetaTopologyProvider method validate.
private void validate(GraphML graphML) throws InvalidGraphException {
final Set<String> graphIds = new HashSet<>();
final Map<String, Set<String>> nodeIdsByNamespace = new HashMap<>();
final Map<String, Set<String>> edgeIdsByNamespace = new HashMap<>();
for (GraphMLGraph eachGraph : graphML.getGraphs()) {
final String ns = eachGraph.getProperty(GraphMLProperties.NAMESPACE);
if (Strings.isNullOrEmpty(ns)) {
throw new InvalidGraphException("No namespace defined on graph with id " + eachGraph.getId());
}
if (graphIds.contains(eachGraph.getId())) {
throw new InvalidGraphException("There already exists a graph with id " + eachGraph.getId());
}
graphIds.add(eachGraph.getId());
for (GraphMLNode eachNode : eachGraph.getNodes()) {
Set<String> nodeIdsInNs = nodeIdsByNamespace.get(ns);
if (nodeIdsInNs == null) {
nodeIdsInNs = new HashSet<>();
nodeIdsByNamespace.put(ns, nodeIdsInNs);
}
if (nodeIdsInNs.contains(eachNode.getId())) {
throw new InvalidGraphException("There already exists a node with id " + eachNode.getId() + " in namespace " + ns);
}
nodeIdsInNs.add(eachNode.getId());
}
for (GraphMLEdge eachEdge : eachGraph.getEdges()) {
Set<String> edgeIdsInNs = edgeIdsByNamespace.get(ns);
if (edgeIdsInNs == null) {
edgeIdsInNs = new HashSet<>();
edgeIdsByNamespace.put(ns, edgeIdsInNs);
}
if (edgeIdsInNs.contains(eachEdge.getId())) {
throw new InvalidGraphException("There already exists an edge with id " + eachEdge.getId() + " in namespace " + ns);
}
edgeIdsInNs.add(eachEdge.getId());
}
}
}
use of org.opennms.features.graphml.model.InvalidGraphException in project opennms by OpenNMS.
the class GraphMLVertexStatusProviderIT method testScriptStatusProvider.
@Test
public void testScriptStatusProvider() throws InvalidGraphException {
GraphML graphML = GraphMLReader.read(getClass().getResourceAsStream("/test-graph.xml"));
GraphMLTopologyProvider topologyProvider = new GraphMLTopologyProvider(null, graphML.getGraphs().get(0), new GraphMLServiceAccessor());
GraphMLScriptVertexStatusProvider statusProvider = new GraphMLScriptVertexStatusProvider(topologyProvider.getNamespace(), this.alarmSummaryWrapper, new ScriptEngineManager(), this.serviceAccessor, Paths.get("src", "test", "opennms-home", "etc", "graphml-vertex-status"));
List<VertexRef> vertices = topologyProvider.getVertices().stream().map(eachVertex -> (VertexRef) eachVertex).collect(Collectors.toList());
Assert.assertEquals(4, vertices.size());
Assert.assertEquals(topologyProvider.getNamespace(), statusProvider.getNamespace());
Assert.assertTrue(statusProvider.contributesTo(topologyProvider.getNamespace()));
Map<? extends VertexRef, ? extends Status> statusForVertices = statusProvider.getStatusForVertices(topologyProvider, vertices, new Criteria[0]);
Assert.assertEquals(4, statusForVertices.size());
Assert.assertEquals(ImmutableMap.of(createVertexRef(topologyProvider.getNamespace(), "north"), createStatus(OnmsSeverity.NORMAL, 0), createVertexRef(topologyProvider.getNamespace(), "west"), createStatus(OnmsSeverity.NORMAL, 0), createVertexRef(topologyProvider.getNamespace(), "south"), createStatus(OnmsSeverity.WARNING, 42), createVertexRef(topologyProvider.getNamespace(), "east"), createStatus(OnmsSeverity.CRITICAL, 23)), statusForVertices);
}
use of org.opennms.features.graphml.model.InvalidGraphException in project opennms by OpenNMS.
the class GraphMLVertexStatusProviderIT method testDefaultStatusProvider.
@Test
public void testDefaultStatusProvider() throws InvalidGraphException {
GraphML graphML = GraphMLReader.read(getClass().getResourceAsStream("/test-graph.xml"));
GraphMLTopologyProvider topologyProvider = new GraphMLTopologyProvider(null, graphML.getGraphs().get(0), new GraphMLServiceAccessor());
GraphMLDefaultVertexStatusProvider statusProvider = new GraphMLDefaultVertexStatusProvider(topologyProvider.getNamespace(), this.alarmSummaryWrapper);
List<VertexRef> vertices = topologyProvider.getVertices().stream().map(eachVertex -> (VertexRef) eachVertex).collect(Collectors.toList());
Assert.assertEquals(4, vertices.size());
Assert.assertEquals(topologyProvider.getNamespace(), statusProvider.getNamespace());
Assert.assertTrue(statusProvider.contributesTo(topologyProvider.getNamespace()));
Map<? extends VertexRef, ? extends Status> statusForVertices = statusProvider.getStatusForVertices(topologyProvider, vertices, new Criteria[0]);
Assert.assertEquals(4, statusForVertices.size());
Assert.assertEquals(ImmutableMap.of(createVertexRef(topologyProvider.getNamespace(), "north"), createStatus(OnmsSeverity.WARNING, 1), createVertexRef(topologyProvider.getNamespace(), "west"), createStatus(OnmsSeverity.MINOR, 2), createVertexRef(topologyProvider.getNamespace(), "south"), createStatus(OnmsSeverity.MAJOR, 3), createVertexRef(topologyProvider.getNamespace(), "east"), createStatus(OnmsSeverity.NORMAL, 0)), statusForVertices);
}
Aggregations