Search in sources :

Example 6 with BusinessServiceGraph

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 &times; %d <i class=\"pull-right glyphicon %s\"></i>", edgeStatus.getLabel(), edge.getWeight(), impactingVertices.contains(graph.getVertexByEdgeId(edge.getId())) ? "glyphicon-flash" : "")));
    }
    return rootLayout;
}
Also used : FormLayout(com.vaadin.ui.FormLayout) Status(org.opennms.netmgt.bsm.service.model.Status) Vertex(org.opennms.features.topology.api.topo.Vertex) IpServiceVertex(org.opennms.features.topology.plugins.topo.bsm.IpServiceVertex) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) BusinessServiceVertex(org.opennms.features.topology.plugins.topo.bsm.BusinessServiceVertex) ReductionKeyVertex(org.opennms.features.topology.plugins.topo.bsm.ReductionKeyVertex) ReductionKeyVertex(org.opennms.features.topology.plugins.topo.bsm.ReductionKeyVertex) ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) Label(com.vaadin.ui.Label) UIHelper.createLabel(org.opennms.netmgt.vaadin.core.UIHelper.createLabel) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) EdgeVisitor(org.opennms.netmgt.bsm.service.model.edge.EdgeVisitor) IpServiceVertex(org.opennms.features.topology.plugins.topo.bsm.IpServiceVertex) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) Edge(org.opennms.netmgt.bsm.service.model.edge.Edge) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) BusinessServiceVertex(org.opennms.features.topology.plugins.topo.bsm.BusinessServiceVertex)

Example 7 with BusinessServiceGraph

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;
}
Also used : GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)

Example 8 with BusinessServiceGraph

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);
    }
}
Also used : Set(java.util.Set) Test(org.junit.Test) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) Builder(org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy.Builder) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) List(java.util.List) Map(java.util.Map) Entry(java.util.Map.Entry) Assert.assertEquals(org.junit.Assert.assertEquals) MockBusinessServiceHierarchy(org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Set(java.util.Set) MockBusinessServiceHierarchy(org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) Test(org.junit.Test)

Example 9 with BusinessServiceGraph

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));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) BeanContainer(com.vaadin.data.util.BeanContainer) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) Map(java.util.Map) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Collections(java.util.Collections) Maps(com.google.common.collect.Maps) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 10 with BusinessServiceGraph

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;
}
Also used : Set(java.util.Set) DefaultBusinessServiceStateMachine(org.opennms.netmgt.bsm.service.internal.DefaultBusinessServiceStateMachine) Collectors(java.util.stream.Collectors) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) List(java.util.List) Lists(com.google.common.collect.Lists) StatusWithIndex(org.opennms.netmgt.bsm.service.model.StatusWithIndex) Status(org.opennms.netmgt.bsm.service.model.Status) StatusWithIndices(org.opennms.netmgt.bsm.service.model.StatusWithIndices) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) Optional(java.util.Optional) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge) Collections(java.util.Collections) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex)

Aggregations

BusinessServiceGraph (org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)10 GraphVertex (org.opennms.netmgt.bsm.service.model.graph.GraphVertex)7 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)5 List (java.util.List)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 Status (org.opennms.netmgt.bsm.service.model.Status)4 Optional (java.util.Optional)3 BusinessServiceStateMachine (org.opennms.netmgt.bsm.service.BusinessServiceStateMachine)3 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Sets (com.google.common.collect.Sets)2 Label (com.vaadin.ui.Label)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Objects (java.util.Objects)2 Set (java.util.Set)2 AlarmWrapper (org.opennms.netmgt.bsm.service.model.AlarmWrapper)2 GraphEdge (org.opennms.netmgt.bsm.service.model.graph.GraphEdge)2 BusinessServiceGraphImpl (org.opennms.netmgt.bsm.service.model.graph.internal.BusinessServiceGraphImpl)2