use of org.opennms.netmgt.bsm.service.model.graph.GraphVertex 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.graph.GraphVertex in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachine method clone.
@Override
public BusinessServiceStateMachine clone(boolean preserveState) {
m_rwLock.readLock().lock();
try {
final BusinessServiceStateMachine sm = new DefaultBusinessServiceStateMachine();
// Rebuild the graph using the business services from the existing state machine
final BusinessServiceGraph graph = getGraph();
sm.setBusinessServices(graph.getVertices().stream().map(GraphVertex::getBusinessService).filter(Objects::nonNull).collect(Collectors.toList()));
// Prime the state
if (preserveState) {
for (String reductionKey : graph.getReductionKeys()) {
GraphVertex reductionKeyVertex = graph.getVertexByReductionKey(reductionKey);
sm.handleNewOrUpdatedAlarm(new AlarmWrapper() {
@Override
public String getReductionKey() {
return reductionKey;
}
@Override
public Status getStatus() {
return reductionKeyVertex.getStatus();
}
});
}
}
return sm;
} finally {
m_rwLock.readLock().unlock();
}
}
use of org.opennms.netmgt.bsm.service.model.graph.GraphVertex in project opennms by OpenNMS.
the class BusinessServiceVertexStatusInfoPanelItemProvider method createComponent.
private Component createComponent(BusinessServiceVertex vertex, GraphContainer container) {
final FormLayout rootLayout = new FormLayout();
rootLayout.setSizeFull();
rootLayout.setSpacing(false);
rootLayout.setMargin(false);
rootLayout.addStyleName("severity");
final BusinessServiceStateMachine stateMachine = SimulationAwareStateMachineFactory.createStateMachine(businessServiceManager, container.getCriteria());
final Status overallStatus = BusinessServicesStatusProvider.getStatus(stateMachine, vertex);
rootLayout.addComponent(createStatusLabel("Overall", overallStatus));
rootLayout.addComponent(new Label());
final BusinessServiceGraph graph = stateMachine.getGraph();
final BusinessService businessService = businessServiceManager.getBusinessServiceById(vertex.getServiceId());
final Set<GraphVertex> impactingVertices = getImpactingVertices(stateMachine, graph, businessService);
for (final Edge edge : businessService.getEdges()) {
// Get the topology vertex for the child to determine the display label
final Vertex childVertex = businessServicesTopologyProvider.getVertex(edge.accept(new EdgeVisitor<VertexRef>() {
@Override
public VertexRef visit(final IpServiceEdge edge) {
return new IpServiceVertex(edge.getIpService(), 0);
}
@Override
public VertexRef visit(final ReductionKeyEdge edge) {
return new ReductionKeyVertex(edge.getReductionKey(), 0);
}
@Override
public VertexRef visit(final ChildEdge edge) {
return new BusinessServiceVertex(edge.getChild(), 0);
}
}));
final Status edgeStatus = stateMachine.getOperationalStatus(edge);
rootLayout.addComponent(createStatusLabel(childVertex.getLabel(), edgeStatus, String.format("%s × %d <i class=\"pull-right glyphicon %s\"></i>", edgeStatus.getLabel(), edge.getWeight(), impactingVertices.contains(graph.getVertexByEdgeId(edge.getId())) ? "glyphicon-flash" : "")));
}
return rootLayout;
}
use of org.opennms.netmgt.bsm.service.model.graph.GraphVertex in project opennms by OpenNMS.
the class AbstractAnalysisOperation method execute.
@Override
public void execute(List<VertexRef> targets, OperationContext operationContext) {
final List<AbstractBusinessServiceVertex> vertices = getVertices(targets);
final BusinessServiceStateMachine stateMachine = SimulationAwareStateMachineFactory.createStateMachine(businessServiceManager, operationContext.getGraphContainer().getCriteria());
final Set<GraphVertex> graphVerticesToFocus = Sets.newHashSet();
final BusinessServiceVertexVisitor<Collection<GraphVertex>> visitor = getVisitorForVerticesToFocus(stateMachine);
for (AbstractBusinessServiceVertex vertex : vertices) {
graphVerticesToFocus.addAll(vertex.accept(visitor));
}
LOG.debug("Found {} business services.", graphVerticesToFocus.size());
if (graphVerticesToFocus.isEmpty()) {
new InfoDialog("No result", getMessageForNoResultDialog()).open();
} else {
focusOnVertices(targets.get(0), graphVerticesToFocus, operationContext.getGraphContainer());
}
}
use of org.opennms.netmgt.bsm.service.model.graph.GraphVertex in project opennms by OpenNMS.
the class BusinessServicesStatusProvider method getStatus.
public static org.opennms.netmgt.bsm.service.model.Status getStatus(BusinessServiceStateMachine stateMachine, BusinessServiceEdge edge) {
final BusinessServiceGraph graph = stateMachine.getGraph();
// We need both the source and target vertices to find the edge in the graph
final GraphVertex source = getGraphVertex(edge.getBusinessServiceSource(), stateMachine.getGraph());
final GraphVertex target = getGraphVertex(edge.getBusinessServiceTarget(), stateMachine.getGraph());
final GraphEdge graphEdge = graph.findEdge(source, target);
return graphEdge != null ? graphEdge.getStatus() : null;
}
Aggregations