use of org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph 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.BusinessServiceGraph 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;
}
use of org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph in project opennms by OpenNMS.
the class BusinessServiceGraphImplTest method canCalculateVertexLevel.
@Test
public void canCalculateVertexLevel() {
/**
* Creates a graph that looks like:
* B1 B5 B6 B7
* | / /
* B2 / /
* | / /
* B3 /
* | /
* B4
*/
MockBusinessServiceHierarchy h = MockBusinessServiceHierarchy.builder().withBusinessService(1).withBusinessService(2).withBusinessService(3).withBusinessService(4).commit().commit().commit().commit().withBusinessService(5).withBusinessService(3).commit().commit().withBusinessService(6).withBusinessService(4).commit().commit().withBusinessService(7).commit().build();
List<BusinessService> businessServices = h.getBusinessServices();
// Quick sanity check of the generated hierarchy
assertEquals(7, businessServices.size());
assertEquals(1, h.getBusinessServiceById(3).getEdges().size());
// Create the graph
BusinessServiceGraph graph = new BusinessServiceGraphImpl(h.getBusinessServices());
// Verify the services at every level
Map<Integer, Set<BusinessService>> servicesByLevel = Maps.newTreeMap();
servicesByLevel.put(0, Sets.newHashSet(h.getBusinessServiceById(1), h.getBusinessServiceById(5), h.getBusinessServiceById(6), h.getBusinessServiceById(7)));
servicesByLevel.put(1, Sets.newHashSet(h.getBusinessServiceById(2)));
servicesByLevel.put(2, Sets.newHashSet(h.getBusinessServiceById(3)));
servicesByLevel.put(3, Sets.newHashSet(h.getBusinessServiceById(4)));
servicesByLevel.put(4, Sets.newHashSet());
for (Entry<Integer, Set<BusinessService>> entry : servicesByLevel.entrySet()) {
int level = entry.getKey();
Set<BusinessService> servicesAtLevel = graph.getVerticesByLevel(level).stream().filter(// Used to verify the level on the actual vertex
v -> v.getLevel() == level).map(v -> v.getBusinessService()).collect(Collectors.toSet());
assertEquals(String.format("Mismatch at level %d", level), entry.getValue(), servicesAtLevel);
}
}
use of org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph in project opennms by OpenNMS.
the class BusinessServiceContainer method createRowForVertex.
private void createRowForVertex(BusinessServiceGraph graph, GraphVertex graphVertex, BusinessServiceRow parentRow) {
final BusinessService businessService = graphVertex.getBusinessService();
if (businessService == null) {
return;
}
final long rowId = rowIdCounter.incrementAndGet();
final Long parentBusinessServiceId = parentRow != null ? parentRow.getBusinessService().getId() : null;
final BusinessServiceRow row = new BusinessServiceRow(rowId, businessService, parentBusinessServiceId);
if (parentRow != null) {
rowIdToParentRowIdMapping.put(rowId, parentRow.getRowId());
}
addBean(row);
// Recurse with all of the children
graph.getOutEdges(graphVertex).stream().map(e -> graph.getOpposite(graphVertex, e)).filter(v -> v.getBusinessService() != null).sorted((v1, v2) -> v1.getBusinessService().getName().compareTo(v2.getBusinessService().getName())).forEach(v -> createRowForVertex(graph, v, row));
}
use of org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph in project opennms by OpenNMS.
the class GraphAlgorithms method calculateImpact.
public static List<GraphVertex> calculateImpact(BusinessServiceGraph graph, GraphVertex vertex) {
if (vertex == null) {
return Collections.emptyList();
}
// Gather the list of parent vertices that are impacted by the current vertex
final List<GraphVertex> impactedParentVertices = graph.getInEdges(vertex).stream().filter(e -> calculateImpacting(graph, graph.getOpposite(vertex, e)).contains(e)).map(e -> graph.getOpposite(vertex, e)).sorted().collect(Collectors.toList());
// Recurse
final List<GraphVertex> impacts = Lists.newArrayList(impactedParentVertices);
for (GraphVertex impactedParentVertex : impactedParentVertices) {
impacts.addAll(calculateImpact(graph, impactedParentVertex));
}
return impacts;
}
Aggregations