Search in sources :

Example 6 with AlarmWrapper

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

the class DefaultBusinessServiceStateMachineIT method canMaintainStateForSimpleHierarchy.

@Test
public void canMaintainStateForSimpleHierarchy() {
    // Setup the the test hierarchy
    SimpleTestHierarchy testHierarchy = new SimpleTestHierarchy(populator);
    testHierarchy.getServices().forEach(entity -> businessServiceDao.save(entity));
    BusinessServiceImpl bsChild1 = wrap(testHierarchy.getChild1());
    BusinessServiceImpl bsChild2 = wrap(testHierarchy.getChild2());
    BusinessServiceImpl bsParent = wrap(testHierarchy.getRoot());
    IpServiceEdge svc1 = wrap(testHierarchy.getServiceChild1());
    IpServiceEdge svc2 = wrap(testHierarchy.getServiceChild2());
    // Manually add a reduction key to a business service to verify that this also works
    bsChild1.addReductionKeyEdge("explicitReductionKey", new Identity(), Edge.DEFAULT_WEIGHT, null);
    businessServiceDao.flush();
    // Setup the state machine
    List<BusinessService> bss = Lists.newArrayList(bsChild1, bsChild2, bsParent);
    LoggingStateChangeHandler handler = new LoggingStateChangeHandler();
    DefaultBusinessServiceStateMachine stateMachine = new DefaultBusinessServiceStateMachine();
    stateMachine.setBusinessServices(bss);
    stateMachine.addHandler(handler, null);
    // Verify the initial state
    assertEquals(0, handler.getStateChanges().size());
    for (BusinessService eachBs : bss) {
        assertEquals(DefaultBusinessServiceStateMachine.MIN_SEVERITY, stateMachine.getOperationalStatus(eachBs));
    }
    // Pass alarm to the state machine
    stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(testHierarchy.getServiceChild1().getIpService(), OnmsSeverity.MINOR));
    // Verify the updated state
    assertEquals(2, handler.getStateChanges().size());
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(svc1));
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(bsChild1));
    assertEquals(DefaultBusinessServiceStateMachine.MIN_SEVERITY, stateMachine.getOperationalStatus(svc2));
    assertEquals(DefaultBusinessServiceStateMachine.MIN_SEVERITY, stateMachine.getOperationalStatus(bsChild2));
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(bsParent));
    // Verify that hierarchy works
    stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(testHierarchy.getServiceChild2().getIpService(), OnmsSeverity.MAJOR));
    assertEquals(4, handler.getStateChanges().size());
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(svc1));
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(bsChild1));
    assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(svc2));
    assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(bsChild2));
    assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(bsParent));
    // Verify that explicit reductionKeys work as well
    AlarmWrapper alarmWrapper = createAlarmWrapper(EventConstants.NODE_LOST_SERVICE_EVENT_UEI, OnmsSeverity.CRITICAL, "explicitReductionKey");
    stateMachine.handleNewOrUpdatedAlarm(alarmWrapper);
    assertEquals(6, handler.getStateChanges().size());
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(svc1));
    assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(svc2));
    assertEquals(Status.CRITICAL, stateMachine.getOperationalStatus(bsChild1));
    assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(bsChild2));
    assertEquals(Status.CRITICAL, stateMachine.getOperationalStatus(bsParent));
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) SimpleTestHierarchy(org.opennms.netmgt.bsm.test.hierarchies.SimpleTestHierarchy) AlarmWrapper(org.opennms.netmgt.bsm.service.model.AlarmWrapper) BsmTestUtils.createAlarmWrapper(org.opennms.netmgt.bsm.test.BsmTestUtils.createAlarmWrapper) LoggingStateChangeHandler(org.opennms.netmgt.bsm.test.LoggingStateChangeHandler) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) Test(org.junit.Test)

Aggregations

AlarmWrapper (org.opennms.netmgt.bsm.service.model.AlarmWrapper)6 Status (org.opennms.netmgt.bsm.service.model.Status)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Collectors (java.util.stream.Collectors)2 BusinessServiceStateMachine (org.opennms.netmgt.bsm.service.BusinessServiceStateMachine)2 BusinessServiceGraph (org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)2 GraphVertex (org.opennms.netmgt.bsm.service.model.graph.GraphVertex)2 BusinessServiceGraphImpl (org.opennms.netmgt.bsm.service.model.graph.internal.BusinessServiceGraphImpl)2 Throwables (com.google.common.base.Throwables)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 KKLayout (edu.uci.ics.jung.algorithms.layout.KKLayout)1 Layout (edu.uci.ics.jung.algorithms.layout.Layout)1 VisualizationImageServer (edu.uci.ics.jung.visualization.VisualizationImageServer)1 Dimension (java.awt.Dimension)1 Point2D (java.awt.geom.Point2D)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1