Search in sources :

Example 1 with AlarmHopCriteria

use of org.opennms.features.topology.app.internal.support.AlarmHopCriteria in project opennms by OpenNMS.

the class AlarmSearchProvider method addVertexHopCriteria.

/**
     * Creates a criteria that provides <VertexRefs> matching the Alarm query from the users query
     * stored in the <SearchResult> that was created by this class during the query method.  The SearchResult 
     * and the Criterion use the AlarmID as the ID for dereferencing in the container.
     */
@Override
public void addVertexHopCriteria(SearchResult searchResult, GraphContainer container) {
    LOG.debug("SearchProvider.addVertexHopCriteria: called with search result: '{}'", searchResult);
    AlarmSearchResult aResult = new AlarmSearchResult(searchResult);
    String id = searchResult.getId();
    String query = searchResult.getQuery();
    if (!OnmsSeverity.get(query).equals(OnmsSeverity.INDETERMINATE)) {
        aResult.setSeverityQuery(true);
    } else {
        aResult.setAlarmId(Integer.valueOf(id));
        aResult.setSeverityQuery(false);
    }
    container.addCriteria(new AlarmHopCriteria(aResult, alarmProvider));
    LOG.debug("SearchProvider.addVertexHop: adding hop criteria {}.", new AlarmHopCriteria(aResult, alarmProvider));
}
Also used : AlarmHopCriteria(org.opennms.features.topology.app.internal.support.AlarmHopCriteria)

Example 2 with AlarmHopCriteria

use of org.opennms.features.topology.app.internal.support.AlarmHopCriteria 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)

Example 3 with AlarmHopCriteria

use of org.opennms.features.topology.app.internal.support.AlarmHopCriteria in project opennms by OpenNMS.

the class BundleContextHistoryManagerTest method verifySearchCriteriaPersistence.

/**
     * <p>This method tests the correctness of {@link org.opennms.features.topology.api.support.HistoryAwareSearchProvider#buildCriteriaFromQuery(SearchResult)} method.
     * The {@link SearchCriteria} objects, generated by this method, are compared to those created directly, with the use of a corresponding constructor</p>
     * <p>
     * Additionally, it checks whether the {@link SavedHistory} objects are saved / loaded correctly and whether there is any data loss / distortion
     * </p>
     */
@Test
public void verifySearchCriteriaPersistence() {
    // Test 1 - checking whether method buildCriteriaFromQuery is working correctly
    // Testing for CategoryHopCriteria & CategorySearchProvider
    Criteria criterionNew = ((HistoryAwareSearchProvider) this.startingProviders.get(CriteriaTypes.category)).buildCriteriaFromQuery(this.startingSearchResults.get(CriteriaTypes.category));
    Assert.assertEquals(this.startingCriteria.get(CriteriaTypes.category), criterionNew);
    // Testing for IpLikeHopCriteria & IpLikeSearchProvider
    criterionNew = ((HistoryAwareSearchProvider) this.startingProviders.get(CriteriaTypes.ipLike)).buildCriteriaFromQuery(this.startingSearchResults.get(CriteriaTypes.ipLike));
    Assert.assertEquals(this.startingCriteria.get(CriteriaTypes.ipLike), criterionNew);
    // Testing for AlarmHopCriteria & AlarmSearchProvider
    criterionNew = ((HistoryAwareSearchProvider) this.startingProviders.get(CriteriaTypes.alarm)).buildCriteriaFromQuery(this.startingSearchResults.get(CriteriaTypes.alarm));
    Assert.assertEquals(this.startingCriteria.get(CriteriaTypes.alarm), criterionNew);
    // Step 1 - providing GraphContainer with a starting Criteria set
    for (Criteria criteria : this.startingCriteria.values()) {
        graphContainerMock.addCriteria(criteria);
    }
    // Saving and then loading history
    String fragment = historyManager.saveOrUpdateHistory("admin", graphContainerMock);
    historyManager.applyHistory(fragment, graphContainerMock);
    Assert.assertNotNull(capturedCriteria);
    Assert.assertThat(startingCriteria.values(), containsInAnyOrder(capturedCriteria.toArray()));
}
Also used : 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) HistoryAwareSearchProvider(org.opennms.features.topology.api.support.HistoryAwareSearchProvider) Test(org.junit.Test)

Example 4 with AlarmHopCriteria

use of org.opennms.features.topology.app.internal.support.AlarmHopCriteria in project opennms by OpenNMS.

the class AlarmSearchProvider method getVertexRefsBy.

//FIXME so that the focus button works.???
@Override
public Set<VertexRef> getVertexRefsBy(SearchResult searchResult, GraphContainer container) {
    LOG.debug("SearchProvider.getVertexRefsBy: called with search result: '{}'", searchResult);
    Criteria criterion = findCriterion(searchResult, container);
    Set<VertexRef> vertices = ((AlarmHopCriteria) criterion).getVertices();
    LOG.debug("SearchProvider.getVertexRefsBy: found '{}' vertices.", vertices.size());
    return vertices;
}
Also used : AlarmHopCriteria(org.opennms.features.topology.app.internal.support.AlarmHopCriteria) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) AlarmHopCriteria(org.opennms.features.topology.app.internal.support.AlarmHopCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Aggregations

AlarmHopCriteria (org.opennms.features.topology.app.internal.support.AlarmHopCriteria)4 Criteria (org.opennms.features.topology.api.topo.Criteria)3 SearchCriteria (org.opennms.features.topology.api.topo.SearchCriteria)2 CategoryHopCriteria (org.opennms.features.topology.app.internal.support.CategoryHopCriteria)2 IpLikeHopCriteria (org.opennms.features.topology.app.internal.support.IpLikeHopCriteria)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Test (org.junit.Test)1 HistoryAwareSearchProvider (org.opennms.features.topology.api.support.HistoryAwareSearchProvider)1 CollapsibleCriteria (org.opennms.features.topology.api.topo.CollapsibleCriteria)1 SearchResult (org.opennms.features.topology.api.topo.SearchResult)1 VertexRef (org.opennms.features.topology.api.topo.VertexRef)1 AlarmProvider (org.opennms.features.topology.app.internal.AlarmProvider)1 AlarmSearchProvider (org.opennms.features.topology.app.internal.AlarmSearchProvider)1 CategoryProvider (org.opennms.features.topology.app.internal.CategoryProvider)1 CategorySearchProvider (org.opennms.features.topology.app.internal.CategorySearchProvider)1 IpInterfaceProvider (org.opennms.features.topology.app.internal.IpInterfaceProvider)1 IpLikeSearchProvider (org.opennms.features.topology.app.internal.IpLikeSearchProvider)1 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)1 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)1