use of org.opennms.netmgt.bsm.service.model.functions.reduce.Threshold 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.service.model.functions.reduce.Threshold in project opennms by OpenNMS.
the class BusinessServiceVertexInfoPanelItemProvider method createComponent.
private Component createComponent(AbstractBusinessServiceVertex ref, GraphContainer graphContainer) {
final FormLayout formLayout = new FormLayout();
formLayout.setSpacing(false);
formLayout.setMargin(false);
ref.accept(new BusinessServiceVertexVisitor<Void>() {
@Override
public Void visit(BusinessServiceVertex vertex) {
final BusinessService businessService = businessServiceManager.getBusinessServiceById(vertex.getServiceId());
formLayout.addComponent(createLabel("Reduce function", getReduceFunctionDescription(businessService.getReduceFunction())));
// Apply Reduce Function specific details
businessService.getReduceFunction().accept(new ReduceFunctionVisitor<Void>() {
@Override
public Void visit(HighestSeverity highestSeverity) {
return null;
}
@Override
public Void visit(HighestSeverityAbove highestSeverityAbove) {
return null;
}
@Override
public // Threshold is not very transparent, we add an Explain Button in these cases
Void visit(Threshold threshold) {
final Button explainButton = createButton("Explain", "Explain the Threshold function", FontAwesome.TABLE, (Button.ClickListener) event -> {
ThresholdExplanationWindow explainWindow = new ThresholdExplanationWindow(SimulationAwareStateMachineFactory.createSimulatedStateMachine(businessServiceManager, graphContainer.getCriteria()).explain(businessService, (Threshold) businessService.getReduceFunction()));
UI.getCurrent().addWindow(explainWindow);
});
explainButton.setStyleName(BaseTheme.BUTTON_LINK);
formLayout.addComponent(explainButton);
return null;
}
@Override
public Void visit(ExponentialPropagation exponentialPropagation) {
return null;
}
});
return null;
}
@Override
public Void visit(IpServiceVertex vertex) {
IpService ipService = businessServiceManager.getIpServiceById(vertex.getIpServiceId());
formLayout.addComponent(createLabel("Interface", ipService.getIpAddress()));
formLayout.addComponent(createLabel("Service", ipService.getServiceName()));
if (!ipService.getServiceName().equals(vertex.getLabel())) {
formLayout.addComponent(createLabel("Friendly Name", vertex.getLabel()));
}
return null;
}
@Override
public Void visit(ReductionKeyVertex vertex) {
formLayout.addComponent(createLabel("Reduction Key", vertex.getReductionKey()));
if (!vertex.getReductionKey().equals(vertex.getLabel())) {
formLayout.addComponent(createLabel("Friendly Name", vertex.getLabel()));
}
return null;
}
});
return formLayout;
}
use of org.opennms.netmgt.bsm.service.model.functions.reduce.Threshold in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachine method explain.
@Override
public ThresholdResultExplanation explain(BusinessService businessService, Threshold threshold) {
final GraphVertex vertex = getGraph().getVertexByBusinessServiceId(businessService.getId());
// Calculate the weighed statuses from the child edges
List<StatusWithIndex> statusesWithIndices = weighEdges(getGraph().getOutEdges(vertex));
List<Status> statuses = statusesWithIndices.stream().map(si -> si.getStatus()).collect(Collectors.toList());
// Reduce
Status reducedStatus = threshold.reduce(statusesWithIndices).orElse(new StatusWithIndices(MIN_SEVERITY, Collections.emptyList())).getStatus();
ThresholdResultExplanation explanation = new ThresholdResultExplanation();
explanation.setStatus(reducedStatus);
explanation.setHitsByStatus(threshold.getHitsByStatus(statuses));
explanation.setGraphEdges(getGraph().getOutEdges(vertex));
explanation.setWeightStatuses(statuses);
explanation.setFunction(threshold);
Map<GraphEdge, GraphVertex> graphEdgeToGraphVertex = new HashMap<>();
for (Edge eachEdge : businessService.getEdges()) {
GraphVertex vertexForEdge = getGraph().getVertexByEdgeId(eachEdge.getId());
GraphEdge graphEdge = getGraph().getGraphEdgeByEdgeId(eachEdge.getId());
if (vertexForEdge != null && graphEdge != null) {
graphEdgeToGraphVertex.put(graphEdge, vertexForEdge);
}
}
explanation.setGraphEdgeToGraphVertexMapping(graphEdgeToGraphVertex);
return explanation;
}
Aggregations