Search in sources :

Example 1 with GraphVertex

use of org.opennms.netmgt.bsm.service.model.graph.GraphVertex in project opennms by OpenNMS.

the class BusinessServicesTopologyProvider method load.

private void load() {
    resetContainer();
    BusinessServiceGraph graph = businessServiceManager.getGraph();
    for (GraphVertex topLevelBusinessService : graph.getVerticesByLevel(0)) {
        addVertex(graph, topLevelBusinessService, null);
    }
}
Also used : GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)

Example 2 with GraphVertex

use of org.opennms.netmgt.bsm.service.model.graph.GraphVertex in project opennms by OpenNMS.

the class DefaultBusinessServiceStateMachine method setBusinessServices.

@Override
public void setBusinessServices(List<BusinessService> businessServices) {
    m_rwLock.writeLock().lock();
    try {
        // Create a new graph
        BusinessServiceGraph g = new BusinessServiceGraphImpl(businessServices);
        // Prime the graph with the state from the previous graph and
        // keep track of the new reductions keys
        Set<String> reductionsKeysToLookup = Sets.newHashSet();
        for (String reductionKey : g.getReductionKeys()) {
            GraphVertex reductionKeyVertex = m_g.getVertexByReductionKey(reductionKey);
            if (reductionKeyVertex != null) {
                updateAndPropagateVertex(g, g.getVertexByReductionKey(reductionKey), reductionKeyVertex.getStatus());
            } else {
                reductionsKeysToLookup.add(reductionKey);
            }
        }
        if (m_alarmProvider == null && reductionsKeysToLookup.size() > 0) {
            LOG.warn("There are one or more reduction keys to lookup, but no alarm provider is set.");
        } else {
            // graph without having to wait for calls to handleNewOrUpdatedAlarm()
            if (reductionsKeysToLookup.size() > 0) {
                final Map<String, AlarmWrapper> lookup = m_alarmProvider.lookup(reductionsKeysToLookup);
                for (Entry<String, AlarmWrapper> eachEntry : lookup.entrySet()) {
                    updateAndPropagateVertex(g, g.getVertexByReductionKey(eachEntry.getKey()), eachEntry.getValue().getStatus());
                }
            }
        }
        m_g = g;
    } finally {
        m_rwLock.writeLock().unlock();
    }
}
Also used : GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) BusinessServiceGraphImpl(org.opennms.netmgt.bsm.service.model.graph.internal.BusinessServiceGraphImpl) AlarmWrapper(org.opennms.netmgt.bsm.service.model.AlarmWrapper) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)

Example 3 with GraphVertex

use of org.opennms.netmgt.bsm.service.model.graph.GraphVertex in project opennms by OpenNMS.

the class BusinessServiceGraphImpl method addBusinessServiceVertex.

private GraphVertex addBusinessServiceVertex(BusinessService businessService) {
    // Use an existing vertex if we already created one
    GraphVertex businessServiceVertex = m_verticesByBusinessServiceId.get(businessService.getId());
    if (businessServiceVertex != null) {
        return businessServiceVertex;
    }
    // Create
    businessServiceVertex = new GraphVertexImpl(businessService.getReduceFunction(), businessService);
    // Add
    addVertex(businessServiceVertex);
    // Index
    m_verticesByBusinessServiceId.put(businessService.getId(), businessServiceVertex);
    for (Edge edge : businessService.getEdges()) {
        // Create the edge
        GraphEdge graphEdge = new GraphEdgeImpl(edge);
        // Use an existing vertex if we already created one
        final GraphVertex[] vertexForEdge = { getExistingVertex(edge) };
        // If we couldn't find an existing vertex, create one
        if (vertexForEdge[0] == null) {
            edge.accept(new EdgeVisitor<Void>() {

                @Override
                public Void visit(ChildEdge edge) {
                    vertexForEdge[0] = addBusinessServiceVertex(edge.getChild());
                    return null;
                }

                @Override
                public Void visit(IpServiceEdge edge) {
                    // There are multiple reductions keys for this edge
                    // Create an intermediary vertex using the Most Critical reduction function
                    vertexForEdge[0] = new GraphVertexImpl(REDUCE_HIGHEST_SEVERITY, edge.getIpService());
                    addVertex(vertexForEdge[0]);
                    m_verticesByIpServiceId.put(vertexForEdge[0].getIpService().getId(), vertexForEdge[0]);
                    // SPECIAL CASE: Map the reductions keys to the intermediary vertex using the Identity map
                    for (String reductionKey : edge.getReductionKeys()) {
                        GraphVertex reductionKeyVertex = m_verticesByReductionKey.get(reductionKey);
                        if (reductionKeyVertex == null) {
                            // not already added
                            reductionKeyVertex = new GraphVertexImpl(REDUCE_HIGHEST_SEVERITY, reductionKey);
                            addVertex(reductionKeyVertex);
                            m_verticesByReductionKey.put(reductionKey, reductionKeyVertex);
                        }
                        // Always add an edge
                        GraphEdgeImpl intermediaryEdge = new GraphEdgeImpl(MAP_IDENTITY);
                        addEdge(intermediaryEdge, vertexForEdge[0], reductionKeyVertex);
                    }
                    return null;
                }

                @Override
                public Void visit(ReductionKeyEdge edge) {
                    String reductionKey = edge.getReductionKey();
                    vertexForEdge[0] = new GraphVertexImpl(REDUCE_HIGHEST_SEVERITY, edge.getReductionKey());
                    addVertex(vertexForEdge[0]);
                    m_verticesByReductionKey.put(reductionKey, vertexForEdge[0]);
                    return null;
                }
            });
        }
        // Link and index
        addEdge(graphEdge, businessServiceVertex, vertexForEdge[0]);
        m_verticesByEdgeId.put(edge.getId(), vertexForEdge[0]);
        m_edgesByEdgeId.put(edge.getId(), graphEdge);
    }
    return businessServiceVertex;
}
Also used : ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) Edge(org.opennms.netmgt.bsm.service.model.edge.Edge) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge)

Example 4 with GraphVertex

use of org.opennms.netmgt.bsm.service.model.graph.GraphVertex in project opennms by OpenNMS.

the class DefaultBusinessServiceStateMachine method renderGraphToPng.

@Override
public void renderGraphToPng(File tempFile) {
    m_rwLock.readLock().lock();
    try {
        Layout<GraphVertex, GraphEdge> layout = new KKLayout<GraphVertex, GraphEdge>(m_g);
        // Size of the layout
        layout.setSize(new Dimension(1024, 1024));
        VisualizationImageServer<GraphVertex, GraphEdge> vv = new VisualizationImageServer<GraphVertex, GraphEdge>(layout, layout.getSize());
        // Viewing area size
        vv.setPreferredSize(new Dimension(1200, 1200));
        vv.getRenderContext().setVertexLabelTransformer(new Transformer<GraphVertex, String>() {

            @Override
            public String transform(GraphVertex vertex) {
                if (vertex.getBusinessService() != null) {
                    return String.format("BS[%s]", vertex.getBusinessService().getName());
                }
                if (vertex.getIpService() != null) {
                    IpService ipService = vertex.getIpService();
                    return String.format("IP_SERVICE[%s,%s]", ipService.getId(), ipService.getServiceName());
                }
                if (vertex.getReductionKey() != null) {
                    return String.format("RK[%s]", vertex.getReductionKey());
                }
                return "UNKNOWN";
            }
        });
        vv.getRenderContext().setEdgeLabelTransformer(new Transformer<GraphEdge, String>() {

            @Override
            public String transform(GraphEdge edge) {
                return String.format("%s", edge.getMapFunction().getClass().getSimpleName());
            }
        });
        // Create the buffered image
        BufferedImage image = (BufferedImage) vv.getImage(new Point2D.Double(vv.getGraphLayout().getSize().getWidth() / 2, vv.getGraphLayout().getSize().getHeight() / 2), new Dimension(vv.getGraphLayout().getSize()));
        // Render
        try {
            ImageIO.write(image, "png", tempFile);
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
    } finally {
        m_rwLock.readLock().unlock();
    }
}
Also used : KKLayout(edu.uci.ics.jung.algorithms.layout.KKLayout) Dimension(java.awt.Dimension) IOException(java.io.IOException) IpService(org.opennms.netmgt.bsm.service.model.IpService) BufferedImage(java.awt.image.BufferedImage) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) VisualizationImageServer(edu.uci.ics.jung.visualization.VisualizationImageServer) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge)

Example 5 with GraphVertex

use of org.opennms.netmgt.bsm.service.model.graph.GraphVertex in project opennms by OpenNMS.

the class DefaultBusinessServiceStateMachine method getOperationalStatus.

@Override
public Status getOperationalStatus(BusinessService businessService) {
    Objects.requireNonNull(businessService);
    m_rwLock.readLock().lock();
    try {
        GraphVertex vertex = m_g.getVertexByBusinessServiceId(businessService.getId());
        if (vertex != null) {
            return vertex.getStatus();
        }
        return null;
    } finally {
        m_rwLock.readLock().unlock();
    }
}
Also used : GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex)

Aggregations

GraphVertex (org.opennms.netmgt.bsm.service.model.graph.GraphVertex)17 BusinessServiceGraph (org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)7 GraphEdge (org.opennms.netmgt.bsm.service.model.graph.GraphEdge)7 Status (org.opennms.netmgt.bsm.service.model.Status)4 BusinessServiceStateMachine (org.opennms.netmgt.bsm.service.BusinessServiceStateMachine)3 Edge (org.opennms.netmgt.bsm.service.model.edge.Edge)3 Collections (java.util.Collections)2 Test (org.junit.Test)2 MockAlarmWrapper (org.opennms.netmgt.bsm.mock.MockAlarmWrapper)2 MockBusinessServiceHierarchy (org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy)2 AlarmWrapper (org.opennms.netmgt.bsm.service.model.AlarmWrapper)2 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)2 StatusWithIndex (org.opennms.netmgt.bsm.service.model.StatusWithIndex)2 StatusWithIndices (org.opennms.netmgt.bsm.service.model.StatusWithIndices)2 ChildEdge (org.opennms.netmgt.bsm.service.model.edge.ChildEdge)2 IpServiceEdge (org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge)2 ReductionKeyEdge (org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge)2 HighestSeverity (org.opennms.netmgt.bsm.service.model.functions.reduce.HighestSeverity)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1