use of org.opennms.netmgt.bsm.test.LoggingStateChangeHandler in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachineIT method canMaintainStateForBambooHierarchy.
@Test
public void canMaintainStateForBambooHierarchy() {
// Setup the the test hierarchy
BambooTestHierarchy testSpecification = new BambooTestHierarchy();
testSpecification.getServices().forEach(entity -> businessServiceDao.save(entity));
// Setup the State Machine
final DefaultBusinessServiceStateMachine stateMachine = new DefaultBusinessServiceStateMachine();
stateMachine.setBusinessServices(testSpecification.getServices().stream().map(s -> wrap(s)).collect(Collectors.toList()));
LoggingStateChangeHandler handler = new LoggingStateChangeHandler();
stateMachine.addHandler(handler, null);
// Verify the initial state
assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(testSpecification.getMasterService())));
assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(testSpecification.getAgentsService())));
assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(testSpecification.getBambooService())));
// Send alarms to the state machine
// Business Service "Master"
stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper("uei.opennms.org/dummy", OnmsSeverity.INDETERMINATE, HTTP_8085_BAMBOO_REDUCTION_KEY));
// no state change
assertEquals(0, handler.getStateChanges().size());
stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper("uei.opennms.org/dummy", OnmsSeverity.WARNING, DISK_USAGE_THRESHOLD_BAMBO_REDUCTION_KEY));
// "Master" and "Bamboo" changed
assertEquals(2, handler.getStateChanges().size());
// Business Service "Agents"
stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper("uei.opennms.org/dummy", OnmsSeverity.MINOR, BAMBOO_AGENT_DUKE_REDUCTION_KEY));
// no state change (threshold not met)
assertEquals(2, handler.getStateChanges().size());
stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper("uei.opennms.org/dummy", OnmsSeverity.NORMAL, BAMBOO_AGENT_NCSTATE_REDUCTION_KEY));
// no state change (threshold not met)
assertEquals(2, handler.getStateChanges().size());
stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper("uei.opennms.org/dummy", OnmsSeverity.MAJOR, BAMBOO_AGENT_CAROLINA_REDUCTION_KEY));
// state change (threshold met) for "Agents" and "Bamboo"
assertEquals(4, handler.getStateChanges().size());
// Verify the updated state
// Business Service "Master"
assertEquals(Status.WARNING, stateMachine.getOperationalStatus(wrap(testSpecification.getMasterService())));
// Business Service "Agents"
assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(wrap(testSpecification.getAgentsService())));
// Business Service "Bamboo" (root)
assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(wrap(testSpecification.getBambooService())));
}
use of org.opennms.netmgt.bsm.test.LoggingStateChangeHandler in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachineTest method canLookupNewAlarmsWhenReloading.
@Test
public void canLookupNewAlarmsWhenReloading() {
// Create a simple hierarchy
MockBusinessServiceHierarchy h = MockBusinessServiceHierarchy.builder().withBusinessService(1).withReductionKey(1, "a1").commit().build();
BusinessService b1 = h.getBusinessServiceById(1);
Edge a1 = h.getEdgeByReductionKey("a1");
// Setup the state machine
DefaultBusinessServiceStateMachine stateMachine = new DefaultBusinessServiceStateMachine();
LoggingStateChangeHandler stateChangeHandler = new LoggingStateChangeHandler();
stateMachine.addHandler(stateChangeHandler, Maps.newHashMap());
stateMachine.setBusinessServices(h.getBusinessServices());
stateMachine.setAlarmProvider(new AlarmProvider() {
@Override
public Map<String, AlarmWrapper> lookup(Set<String> reductionKeys) {
if (reductionKeys.contains("a2")) {
return ImmutableMap.<String, AlarmWrapper>builder().put("a2", new MockAlarmWrapper("a2", Status.CRITICAL)).build();
}
return new HashMap<>();
}
});
// Verify the initial state
assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(b1));
assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(a1));
assertEquals(0, stateChangeHandler.getStateChanges().size());
// Send an alarm and verify the updated state
stateMachine.handleNewOrUpdatedAlarm(new MockAlarmWrapper("a1", Status.MINOR));
assertEquals(Status.MINOR, stateMachine.getOperationalStatus(b1));
assertEquals(Status.MINOR, stateMachine.getOperationalStatus(a1));
assertEquals(1, stateChangeHandler.getStateChanges().size());
// Update the hierarchy and reload the state machine
h = MockBusinessServiceHierarchy.builder().withBusinessService(1).withReductionKey(1, "a1").withReductionKey(2, "a2").commit().build();
stateMachine.setBusinessServices(h.getBusinessServices());
Edge a2 = h.getEdgeByReductionKey("a2");
// The state should be upgraded
assertEquals(Status.CRITICAL, stateMachine.getOperationalStatus(b1));
assertEquals(Status.MINOR, stateMachine.getOperationalStatus(a1));
assertEquals(Status.CRITICAL, stateMachine.getOperationalStatus(a2));
// One additional state change event should have been generated
assertEquals(2, stateChangeHandler.getStateChanges().size());
}
use of org.opennms.netmgt.bsm.test.LoggingStateChangeHandler in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachineTest method canReloadTheStateMachineWhilePreservingState.
@Test
public void canReloadTheStateMachineWhilePreservingState() {
// Create a simple hierarchy
MockBusinessServiceHierarchy h = MockBusinessServiceHierarchy.builder().withBusinessService(1).withReductionKey(1, "a1").commit().build();
BusinessService b1 = h.getBusinessServiceById(1);
// Setup the state machine
BusinessServiceStateMachine stateMachine = new DefaultBusinessServiceStateMachine();
LoggingStateChangeHandler stateChangeHandler = new LoggingStateChangeHandler();
stateMachine.addHandler(stateChangeHandler, Maps.newHashMap());
stateMachine.setBusinessServices(h.getBusinessServices());
// Verify the initial state
assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(b1));
assertEquals(0, stateChangeHandler.getStateChanges().size());
// Send an alarm and verify the updated state
stateMachine.handleNewOrUpdatedAlarm(new MockAlarmWrapper("a1", Status.CRITICAL));
assertEquals(Status.CRITICAL, stateMachine.getOperationalStatus(b1));
assertEquals(1, stateChangeHandler.getStateChanges().size());
// Now reload the state machine without making any changes to the hierarchies
stateMachine.setBusinessServices(h.getBusinessServices());
// The original status should remain
assertEquals(Status.CRITICAL, stateMachine.getOperationalStatus(b1));
// No additional state changes events should have been generated
assertEquals(1, stateChangeHandler.getStateChanges().size());
}
use of org.opennms.netmgt.bsm.test.LoggingStateChangeHandler 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.test.LoggingStateChangeHandler 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