use of org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy 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.MockBusinessServiceHierarchy in project opennms by OpenNMS.
the class BusinessServiceGraphImplTest method canCalculateVertexLevelForDeepHierarchy.
@Test
public void canCalculateVertexLevelForDeepHierarchy() {
final String[][] BUSINESS_SERVICE_NAMES = new String[][] { { "b1" }, { "b2" }, { "b3", "c21", "c22" }, { "b4", "c31", "c32", "c33" }, { "b5", "c41" }, { "b6", "c51", "c52" }, { "b7", "c61" }, { "b8", "c71", "c72", "c73", "c74" }, { "b9", "c81", "c82" }, { "b10", "c91", "c92", "c93", "c94", "c95", "c96", "c97", "c98", "c99" }, { "b11", "c101" }, { "b12", "c111", "c112" }, { "b13", "c121" }, { "b14" } };
// Build the hierarchy, linking every level to the left most business service
// in the line above
Map<Long, Integer> businessServiceIdToLevel = Maps.newHashMap();
Builder builder = MockBusinessServiceHierarchy.builder();
long k = 0;
for (int level = 0; level < BUSINESS_SERVICE_NAMES.length; level++) {
String[] servicesAtLevel = BUSINESS_SERVICE_NAMES[level];
for (int i = servicesAtLevel.length - 1; i >= 0; i--) {
builder = builder.withBusinessService(k).withName(servicesAtLevel[i]);
businessServiceIdToLevel.put(k, level);
k++;
if (i != 0) {
builder = builder.commit();
}
}
}
for (int level = 0; level < BUSINESS_SERVICE_NAMES.length; level++) {
builder = builder.commit();
}
// Create the graph
MockBusinessServiceHierarchy h = builder.build();
BusinessServiceGraph graph = new BusinessServiceGraphImpl(h.getBusinessServices());
// Verify
for (Entry<Long, Integer> entry : businessServiceIdToLevel.entrySet()) {
long id = entry.getKey();
int expectedLevel = entry.getValue();
assertEquals(expectedLevel, graph.getVertexByBusinessServiceId(id).getLevel());
}
}
use of org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy 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.MockBusinessServiceHierarchy in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachineTest method canRenderGraphToPng.
@Test
public void canRenderGraphToPng() {
// Create a simple hierarchy
MockBusinessServiceHierarchy h = MockBusinessServiceHierarchy.builder().withBusinessService(1).withReductionKey(1, "a1").commit().build();
// Setup the state machine
BusinessServiceStateMachine stateMachine = new DefaultBusinessServiceStateMachine();
stateMachine.setBusinessServices(h.getBusinessServices());
// Render the state machine graph
File pngFile = new File(tempFolder.getRoot(), "test.png");
assertFalse(pngFile.getAbsolutePath() + " should not exist.", pngFile.exists());
stateMachine.renderGraphToPng(pngFile);
assertTrue(pngFile.getAbsolutePath() + " should exist.", pngFile.exists());
}
use of org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy 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());
}
Aggregations