use of org.opennms.netmgt.bsm.mock.MockAlarmWrapper in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachineTest method canPerformRootCauseAndImpactAnalysis.
@Test
public void canPerformRootCauseAndImpactAnalysis() {
// Create a hierarchy using all of the available reduction functions
HighestSeverity highestSeverity = new HighestSeverity();
Threshold threshold = new Threshold();
threshold.setThreshold(0.5f);
HighestSeverityAbove highestSeverityAbove = new HighestSeverityAbove();
highestSeverityAbove.setThreshold(Status.MINOR);
MockBusinessServiceHierarchy h = MockBusinessServiceHierarchy.builder().withBusinessService(1).withName("b1").withReductionFunction(highestSeverityAbove).withBusinessService(2).withName("b2").withReductionFunction(highestSeverity).withReductionKey(21, "a1").withReductionKey(22, "a2").withReductionKey(23, "a3").commit().withBusinessService(3).withName("b3").withReductionFunction(threshold).withReductionKey(34, "a4").withReductionKey(35, "a5").withReductionKey(36, "a6").withReductionKey(37, "a7").commit().commit().build();
// Setup the state machine
DefaultBusinessServiceStateMachine stateMachine = new DefaultBusinessServiceStateMachine();
stateMachine.setBusinessServices(h.getBusinessServices());
// Bump b2 to MINOR, caused by a1
stateMachine.handleNewOrUpdatedAlarm(new MockAlarmWrapper("a1", Status.MINOR));
// Bump b3 to MAJOR, caused by a4, a6 and a7
stateMachine.handleNewOrUpdatedAlarm(new MockAlarmWrapper("a4", Status.MAJOR));
stateMachine.handleNewOrUpdatedAlarm(new MockAlarmWrapper("a6", Status.CRITICAL));
stateMachine.handleNewOrUpdatedAlarm(new MockAlarmWrapper("a7", Status.MAJOR));
// Bumped b1 to MAJOR, caused by b3
// Verify the state
assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(h.getBusinessServiceById(1)));
assertEquals(Status.MINOR, stateMachine.getOperationalStatus(h.getBusinessServiceById(2)));
assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(h.getBusinessServiceById(3)));
// Calculate and verify the root causes, b2 caused by a1
List<GraphVertex> causedby = stateMachine.calculateRootCause(h.getBusinessServiceById(2));
assertEquals(1, causedby.size());
assertEquals("a1", causedby.get(0).getReductionKey());
// b3 caused by a4, a6 and a7
causedby = stateMachine.calculateRootCause(h.getBusinessServiceById(3));
assertEquals(3, causedby.size());
assertEquals("a4", causedby.get(0).getReductionKey());
assertEquals("a6", causedby.get(1).getReductionKey());
assertEquals("a7", causedby.get(2).getReductionKey());
// b1 caused by b3, which was in turn caused by a4, a6 and a7
causedby = stateMachine.calculateRootCause(h.getBusinessServiceById(1));
assertEquals(4, causedby.size());
assertEquals(Long.valueOf(3), causedby.get(0).getBusinessService().getId());
assertEquals("a4", causedby.get(1).getReductionKey());
assertEquals("a6", causedby.get(2).getReductionKey());
assertEquals("a7", causedby.get(3).getReductionKey());
// Now calculate the impact, a1 impacts b2
List<GraphVertex> impacts = stateMachine.calculateImpact("a1");
assertEquals(1, impacts.size());
assertEquals("b2", impacts.get(0).getBusinessService().getName());
// a4 impacts b3 which impacts b1
impacts = stateMachine.calculateImpact("a4");
assertEquals(2, impacts.size());
assertEquals("b3", impacts.get(0).getBusinessService().getName());
assertEquals("b1", impacts.get(1).getBusinessService().getName());
// b3 impacts b1
impacts = stateMachine.calculateImpact(h.getBusinessServiceById(3));
assertEquals(1, impacts.size());
assertEquals("b1", impacts.get(0).getBusinessService().getName());
}
use of org.opennms.netmgt.bsm.mock.MockAlarmWrapper 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.mock.MockAlarmWrapper 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.mock.MockAlarmWrapper 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());
}
Aggregations