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));
}
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));
}
Aggregations