Search in sources :

Example 6 with IpServiceEdge

use of org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge 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)

Example 7 with IpServiceEdge

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

the class DefaultBusinessServiceStateMachineIT method canShareIpService.

/**
 * Verifies that two Business Services can share the same Ip Service and both Business Services will change their
 * status when the IP Service changes its status.
 */
@Test
public void canShareIpService() {
    BusinessServicesShareIpServiceHierarchy testHierarchy = new BusinessServicesShareIpServiceHierarchy(populator);
    testHierarchy.getServices().forEach(entity -> businessServiceDao.save(entity));
    businessServiceDao.flush();
    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());
    // 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(3, handler.getStateChanges().size());
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(svc1));
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(bsChild1));
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(svc2));
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(bsChild2));
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(bsParent));
}
Also used : BusinessServicesShareIpServiceHierarchy(org.opennms.netmgt.bsm.test.hierarchies.BusinessServicesShareIpServiceHierarchy) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) LoggingStateChangeHandler(org.opennms.netmgt.bsm.test.LoggingStateChangeHandler) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) Test(org.junit.Test)

Aggregations

IpServiceEdge (org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge)7 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)6 ChildEdge (org.opennms.netmgt.bsm.service.model.edge.ChildEdge)4 ReductionKeyEdge (org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge)4 Test (org.junit.Test)3 Edge (org.opennms.netmgt.bsm.service.model.edge.Edge)3 BusinessServiceStateMachine (org.opennms.netmgt.bsm.service.BusinessServiceStateMachine)2 Status (org.opennms.netmgt.bsm.service.model.Status)2 EdgeVisitor (org.opennms.netmgt.bsm.service.model.edge.EdgeVisitor)2 BusinessServiceGraph (org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)2 LoggingStateChangeHandler (org.opennms.netmgt.bsm.test.LoggingStateChangeHandler)2 FormLayout (com.vaadin.ui.FormLayout)1 Label (com.vaadin.ui.Label)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1