Search in sources :

Example 6 with MockBusinessServiceHierarchy

use of org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy in project opennms by OpenNMS.

the class BusinessServiceGraphImplTest method canCalculateVertexLevel.

@Test
public void canCalculateVertexLevel() {
    /**
     * Creates a graph that looks like:
     *   B1    B5   B6   B7
     *    |   /     /
     *    B2  /    /
     *    | /   /
     *    B3   /
     *    | /
     *    B4
     */
    MockBusinessServiceHierarchy h = MockBusinessServiceHierarchy.builder().withBusinessService(1).withBusinessService(2).withBusinessService(3).withBusinessService(4).commit().commit().commit().commit().withBusinessService(5).withBusinessService(3).commit().commit().withBusinessService(6).withBusinessService(4).commit().commit().withBusinessService(7).commit().build();
    List<BusinessService> businessServices = h.getBusinessServices();
    // Quick sanity check of the generated hierarchy
    assertEquals(7, businessServices.size());
    assertEquals(1, h.getBusinessServiceById(3).getEdges().size());
    // Create the graph
    BusinessServiceGraph graph = new BusinessServiceGraphImpl(h.getBusinessServices());
    // Verify the services at every level
    Map<Integer, Set<BusinessService>> servicesByLevel = Maps.newTreeMap();
    servicesByLevel.put(0, Sets.newHashSet(h.getBusinessServiceById(1), h.getBusinessServiceById(5), h.getBusinessServiceById(6), h.getBusinessServiceById(7)));
    servicesByLevel.put(1, Sets.newHashSet(h.getBusinessServiceById(2)));
    servicesByLevel.put(2, Sets.newHashSet(h.getBusinessServiceById(3)));
    servicesByLevel.put(3, Sets.newHashSet(h.getBusinessServiceById(4)));
    servicesByLevel.put(4, Sets.newHashSet());
    for (Entry<Integer, Set<BusinessService>> entry : servicesByLevel.entrySet()) {
        int level = entry.getKey();
        Set<BusinessService> servicesAtLevel = graph.getVerticesByLevel(level).stream().filter(// Used to verify the level on the actual vertex
        v -> v.getLevel() == level).map(v -> v.getBusinessService()).collect(Collectors.toSet());
        assertEquals(String.format("Mismatch at level %d", level), entry.getValue(), servicesAtLevel);
    }
}
Also used : Set(java.util.Set) Test(org.junit.Test) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) Builder(org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy.Builder) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) List(java.util.List) Map(java.util.Map) Entry(java.util.Map.Entry) Assert.assertEquals(org.junit.Assert.assertEquals) MockBusinessServiceHierarchy(org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Set(java.util.Set) MockBusinessServiceHierarchy(org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) Test(org.junit.Test)

Example 7 with MockBusinessServiceHierarchy

use of org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy 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

Test (org.junit.Test)7 MockBusinessServiceHierarchy (org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy)7 MockAlarmWrapper (org.opennms.netmgt.bsm.mock.MockAlarmWrapper)4 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)3 Map (java.util.Map)2 Builder (org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy.Builder)2 BusinessServiceStateMachine (org.opennms.netmgt.bsm.service.BusinessServiceStateMachine)2 HighestSeverity (org.opennms.netmgt.bsm.service.model.functions.reduce.HighestSeverity)2 BusinessServiceGraph (org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)2 GraphVertex (org.opennms.netmgt.bsm.service.model.graph.GraphVertex)2 LoggingStateChangeHandler (org.opennms.netmgt.bsm.test.LoggingStateChangeHandler)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 File (java.io.File)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1