Search in sources :

Example 11 with Criteria

use of org.opennms.features.topology.api.topo.Criteria in project opennms by OpenNMS.

the class EnhancedLinkdTopologyProvider method logCriteriaInContainer.

private void logCriteriaInContainer(GraphContainer container) {
    Criteria[] criteria = container.getCriteria();
    LOG.debug("SearchProvider->addVertexHopCriteria: there are now {} criteria in the GraphContainer.", criteria.length);
    for (Criteria crit : criteria) {
        LOG.debug("SearchProvider->addVertexHopCriteria: criterion: '{}' is in the GraphContainer.", crit);
    }
}
Also used : VertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.VertexHopCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria)

Example 12 with Criteria

use of org.opennms.features.topology.api.topo.Criteria 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);
}
Also used : DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) ImmutableMap(com.google.common.collect.ImmutableMap) Date(java.util.Date) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) Test(org.junit.Test) GraphML(org.opennms.features.graphml.model.GraphML) GraphMLReader(org.opennms.features.graphml.model.GraphMLReader) Collectors(java.util.stream.Collectors) List(java.util.List) Lists(com.google.common.collect.Lists) Map(java.util.Map) InvalidGraphException(org.opennms.features.graphml.model.InvalidGraphException) Criteria(org.opennms.features.topology.api.topo.Criteria) Status(org.opennms.features.topology.api.topo.Status) Assert(org.junit.Assert) VertexRef(org.opennms.features.topology.api.topo.VertexRef) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) Status(org.opennms.features.topology.api.topo.Status) GraphML(org.opennms.features.graphml.model.GraphML) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Test(org.junit.Test)

Example 13 with Criteria

use of org.opennms.features.topology.api.topo.Criteria in project opennms by OpenNMS.

the class EnhancedLinkdTopologyProvider method removeVertexHopCriteria.

@Override
public void removeVertexHopCriteria(SearchResult searchResult, GraphContainer container) {
    LOG.debug("SearchProvider->removeVertexHopCriteria: called with search result: '{}'", searchResult);
    Criteria criterion = findCriterion(searchResult.getId(), container);
    if (criterion != null) {
        LOG.debug("SearchProvider->removeVertexHopCriteria: found criterion: {} for searchResult {}.", criterion, searchResult);
        container.removeCriteria(criterion);
    } else {
        LOG.debug("SearchProvider->removeVertexHopCriteria: did not find criterion for searchResult {}.", searchResult);
    }
    logCriteriaInContainer(container);
}
Also used : VertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.VertexHopCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria)

Example 14 with Criteria

use of org.opennms.features.topology.api.topo.Criteria in project opennms by OpenNMS.

the class AlarmStatusProviderTest method testGetAlarmStatus.

@Test
public void testGetAlarmStatus() {
    Vertex vertex = createVertex(1);
    Vertex vertex2 = createVertex(2);
    Vertex vertex3 = createVertex(3);
    List<VertexRef> vertexList = Lists.newArrayList(vertex, vertex2, vertex3);
    EasyMock.expect(m_alarmDao.getNodeAlarmSummariesIncludeAcknowledgedOnes(EasyMock.anyObject())).andReturn(createNormalAlarmSummaryList());
    EasyMock.replay(m_alarmDao);
    Map<VertexRef, Status> statusMap = m_statusProvider.getStatusForVertices(m_vertexProvider, vertexList, new Criteria[0]);
    assertEquals(3, statusMap.size());
    assertEquals(vertex, statusMap.keySet().stream().sorted((v1, v2) -> v1.getId().compareTo(v2.getId())).collect(Collectors.toList()).get(0));
    // use defined status
    assertEquals("major", statusMap.get(vertex).computeStatus());
    // fallback to normal
    assertEquals("normal", statusMap.get(vertex2).computeStatus());
    // use defined status
    assertEquals("indeterminate", statusMap.get(vertex3).computeStatus());
    EasyMock.verify(m_alarmDao);
}
Also used : Status(org.opennms.features.topology.api.topo.Status) Date(java.util.Date) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) Vertex(org.opennms.features.topology.api.topo.Vertex) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) Lists(com.google.common.collect.Lists) VertexProvider(org.opennms.features.topology.api.topo.VertexProvider) AlarmDao(org.opennms.netmgt.dao.api.AlarmDao) Map(java.util.Map) Criteria(org.opennms.features.topology.api.topo.Criteria) Status(org.opennms.features.topology.api.topo.Status) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Assert.assertEquals(org.junit.Assert.assertEquals) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) Before(org.junit.Before) Vertex(org.opennms.features.topology.api.topo.Vertex) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Test(org.junit.Test)

Example 15 with Criteria

use of org.opennms.features.topology.api.topo.Criteria in project opennms by OpenNMS.

the class BundleContextHistoryManagerTest method initProvidersAndCriteria.

/**
     * In this method all starting {@link SearchCriteria} and {@link SearchProvider} objects are initialized
     */
private void initProvidersAndCriteria() {
    // Preparing SearchProviders
    CategoryProvider vertexProvider = new CategoryProvider() {

        @Override
        public Collection<OnmsCategory> getAllCategories() {
            return Lists.newArrayList(findCategoryByName("somename"));
        }

        @Override
        public OnmsCategory findCategoryByName(String m_categoryName) {
            OnmsCategory cat = new OnmsCategory("test", "test");
            cat.setId(Integer.valueOf(idCategory));
            return cat;
        }

        @Override
        public List<OnmsNode> findNodesForCategory(OnmsCategory category) {
            return new ArrayList<>();
        }
    };
    IpInterfaceProvider ipInterfaceProvider = new IpInterfaceProvider() {

        @Override
        public List<OnmsIpInterface> findMatching(org.opennms.core.criteria.Criteria criteria) {
            OnmsNode node = new OnmsNode();
            node.setId(Integer.valueOf(idIpLike));
            String ipAddr = "127.0.0.1";
            OnmsIpInterface ipInterface = new OnmsIpInterface(ipAddr, node);
            return Lists.newArrayList(ipInterface);
        }
    };
    AlarmProvider alarmProvider = new AlarmProvider() {

        @Override
        public List<OnmsAlarm> findMatchingAlarms(org.opennms.core.criteria.Criteria criteria) {
            Date eventTime = new Date();
            OnmsDistPoller distPoller = new OnmsDistPoller("pollerID");
            OnmsEvent event = new OnmsEvent();
            OnmsAlarm alarm = new OnmsAlarm(Integer.valueOf(idAlarm), "eventUI", distPoller, 2, 3, eventTime, event);
            return Lists.newArrayList(alarm);
        }
    };
    // Creating SearchResults to be used in testing
    SearchResult sResultCategory = new SearchResult(CategoryHopCriteria.NAMESPACE, idCategory, labelCategory, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
    SearchResult sResultAlarm = new SearchResult(AlarmHopCriteria.NAMESPACE, idAlarm, labelAlarm, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
    SearchResult sResultIpLike = new SearchResult(IpLikeHopCriteria.NAMESPACE, idIpLike, labelIpLike, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
    this.startingSearchResults.put(CriteriaTypes.alarm, sResultAlarm);
    this.startingSearchResults.put(CriteriaTypes.ipLike, sResultIpLike);
    this.startingSearchResults.put(CriteriaTypes.category, sResultCategory);
    // Initializing available (initial) SearchProviders
    this.startingProviders.put(CriteriaTypes.category, new CategorySearchProvider(vertexProvider));
    this.startingProviders.put(CriteriaTypes.ipLike, new IpLikeSearchProvider(ipInterfaceProvider));
    this.startingProviders.put(CriteriaTypes.alarm, new AlarmSearchProvider(alarmProvider));
    // Initializing available (initial) Criteria
    this.startingCriteria.put(CriteriaTypes.category, new CategoryHopCriteria(sResultCategory, vertexProvider));
    this.startingCriteria.put(CriteriaTypes.ipLike, new IpLikeHopCriteria(sResultIpLike, ipInterfaceProvider));
    this.startingCriteria.put(CriteriaTypes.alarm, new AlarmHopCriteria(new AlarmSearchProvider(alarmProvider).new AlarmSearchResult(sResultAlarm), alarmProvider));
}
Also used : CategoryProvider(org.opennms.features.topology.app.internal.CategoryProvider) OnmsNode(org.opennms.netmgt.model.OnmsNode) IpInterfaceProvider(org.opennms.features.topology.app.internal.IpInterfaceProvider) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ArrayList(java.util.ArrayList) OnmsDistPoller(org.opennms.netmgt.model.OnmsDistPoller) SearchResult(org.opennms.features.topology.api.topo.SearchResult) CategoryHopCriteria(org.opennms.features.topology.app.internal.support.CategoryHopCriteria) SearchCriteria(org.opennms.features.topology.api.topo.SearchCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria) IpLikeHopCriteria(org.opennms.features.topology.app.internal.support.IpLikeHopCriteria) AlarmHopCriteria(org.opennms.features.topology.app.internal.support.AlarmHopCriteria) Date(java.util.Date) CategorySearchProvider(org.opennms.features.topology.app.internal.CategorySearchProvider) IpLikeHopCriteria(org.opennms.features.topology.app.internal.support.IpLikeHopCriteria) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) AlarmSearchProvider(org.opennms.features.topology.app.internal.AlarmSearchProvider) AlarmProvider(org.opennms.features.topology.app.internal.AlarmProvider) AlarmHopCriteria(org.opennms.features.topology.app.internal.support.AlarmHopCriteria) CategoryHopCriteria(org.opennms.features.topology.app.internal.support.CategoryHopCriteria) IpLikeSearchProvider(org.opennms.features.topology.app.internal.IpLikeSearchProvider)

Aggregations

Criteria (org.opennms.features.topology.api.topo.Criteria)36 VertexHopCriteria (org.opennms.features.topology.api.support.VertexHopGraphProvider.VertexHopCriteria)15 CollapsibleCriteria (org.opennms.features.topology.api.topo.CollapsibleCriteria)13 VertexRef (org.opennms.features.topology.api.topo.VertexRef)12 HashSet (java.util.HashSet)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 List (java.util.List)5 SearchCriteria (org.opennms.features.topology.api.topo.SearchCriteria)5 CategoryHopCriteria (org.opennms.features.topology.app.internal.support.CategoryHopCriteria)5 Lists (com.google.common.collect.Lists)4 Set (java.util.Set)4 Test (org.junit.Test)4 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)4 Status (org.opennms.features.topology.api.topo.Status)4 AlarmHopCriteria (org.opennms.features.topology.app.internal.support.AlarmHopCriteria)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 AlarmSummary (org.opennms.netmgt.model.alarm.AlarmSummary)4 Collection (java.util.Collection)3