Search in sources :

Example 16 with GraphVertex

use of org.opennms.netmgt.bsm.service.model.graph.GraphVertex in project opennms by OpenNMS.

the class BusinessServiceGraphImpl method calculateAndIndexLevels.

private void calculateAndIndexLevels() {
    // Start by finding the root vertices
    // These are the vertices with no incoming edges
    final Set<GraphVertex> rootVertices = Sets.newHashSet();
    for (GraphVertex vertex : getVertices()) {
        if (getInEdges(vertex).size() == 0) {
            rootVertices.add(vertex);
        }
    }
    // Now calculate the distance of every node to each of the root nodes
    final GraphLevelIndexer<GraphVertex, GraphEdge> levelIndexer = new GraphLevelIndexer<>();
    levelIndexer.indexLevel(this, rootVertices);
    for (Entry<GraphVertex, Integer> entry : levelIndexer.getLevelMap().entrySet()) {
        final int level = entry.getValue().intValue();
        final GraphVertexImpl vertex = (GraphVertexImpl) entry.getKey();
        // Store the maximum level within the vertex
        vertex.setLevel(Math.max(level, vertex.getLevel()));
    }
    // Index the vertices by level
    for (GraphVertex vertex : getVertices()) {
        Set<GraphVertex> verticesAtLevel = m_verticesByLevel.get(vertex.getLevel());
        if (verticesAtLevel == null) {
            verticesAtLevel = Sets.newHashSet();
            m_verticesByLevel.put(vertex.getLevel(), verticesAtLevel);
        }
        verticesAtLevel.add(vertex);
    }
}
Also used : GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge)

Example 17 with GraphVertex

use of org.opennms.netmgt.bsm.service.model.graph.GraphVertex in project opennms by OpenNMS.

the class RootCauseAnalysisTest method canEfficientlyPerformRootCauseAnalysis.

/**
 * Verifies that the RCA and IA algorithms can be performed
 * against business services that reference 100+ reduction keys.
 *
 * See NMS-8527 for details.
 */
@Test(timeout = 10000)
public void canEfficientlyPerformRootCauseAnalysis() {
    final int NUMBER_OF_REDUCTION_KEYS_PER_BS = 2500;
    HighestSeverity highestSeverity = new HighestSeverity();
    BusinessServiceBuilder builder = MockBusinessServiceHierarchy.builder().withBusinessService(1).withName("b1").withReductionFunction(highestSeverity);
    for (int i = 0; i < NUMBER_OF_REDUCTION_KEYS_PER_BS; i++) {
        builder.withReductionKey(i, "a" + i);
    }
    MockBusinessServiceHierarchy h = builder.commit().build();
    // Setup the state machine
    DefaultBusinessServiceStateMachine stateMachine = new DefaultBusinessServiceStateMachine();
    stateMachine.setBusinessServices(h.getBusinessServices());
    // Bump b1 to MINOR, cause by a1
    stateMachine.handleNewOrUpdatedAlarm(new MockAlarmWrapper("a1", Status.MINOR));
    // Verify the state
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(h.getBusinessServiceById(1)));
    // Calculate and verify the root cause, b1 caused by a1
    List<GraphVertex> causedby = stateMachine.calculateRootCause(h.getBusinessServiceById(1));
    assertEquals(1, causedby.size());
    assertEquals("a1", causedby.get(0).getReductionKey());
    // Now calculate the impact, a1 impacts b1
    List<GraphVertex> impacts = stateMachine.calculateImpact("a1");
    assertEquals(1, impacts.size());
    assertEquals("b1", impacts.get(0).getBusinessService().getName());
}
Also used : HighestSeverity(org.opennms.netmgt.bsm.service.model.functions.reduce.HighestSeverity) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) MockBusinessServiceHierarchy(org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy) BusinessServiceBuilder(org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy.HierarchyBuilder.BusinessServiceBuilder) MockAlarmWrapper(org.opennms.netmgt.bsm.mock.MockAlarmWrapper) Test(org.junit.Test)

Aggregations

GraphVertex (org.opennms.netmgt.bsm.service.model.graph.GraphVertex)17 BusinessServiceGraph (org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)7 GraphEdge (org.opennms.netmgt.bsm.service.model.graph.GraphEdge)7 Status (org.opennms.netmgt.bsm.service.model.Status)4 BusinessServiceStateMachine (org.opennms.netmgt.bsm.service.BusinessServiceStateMachine)3 Edge (org.opennms.netmgt.bsm.service.model.edge.Edge)3 Collections (java.util.Collections)2 Test (org.junit.Test)2 MockAlarmWrapper (org.opennms.netmgt.bsm.mock.MockAlarmWrapper)2 MockBusinessServiceHierarchy (org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy)2 AlarmWrapper (org.opennms.netmgt.bsm.service.model.AlarmWrapper)2 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)2 StatusWithIndex (org.opennms.netmgt.bsm.service.model.StatusWithIndex)2 StatusWithIndices (org.opennms.netmgt.bsm.service.model.StatusWithIndices)2 ChildEdge (org.opennms.netmgt.bsm.service.model.edge.ChildEdge)2 IpServiceEdge (org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge)2 ReductionKeyEdge (org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge)2 HighestSeverity (org.opennms.netmgt.bsm.service.model.functions.reduce.HighestSeverity)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1