Search in sources :

Example 6 with GraphEdge

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

the class DefaultBusinessServiceStateMachine method weighStatuses.

/**
 * Apply the edges weights to the associated statuses set in the map,
 * ignoring the actual status stored in the edge. Can be used for simulations
 * without needing to change the actual edge's status.
 *
 * @param edgesWithStatus
 * @return
 */
public static List<StatusWithIndex> weighStatuses(Map<GraphEdge, Status> edgesWithStatus) {
    // Find the greatest common divisor of all the weights
    int gcd = edgesWithStatus.keySet().stream().map(GraphEdge::getWeight).reduce((a, b) -> BigInteger.valueOf(a).gcd(BigInteger.valueOf(b)).intValue()).orElse(1);
    // Multiply the statuses based on their relative weight
    List<StatusWithIndex> statuses = Lists.newArrayList();
    int k = 0;
    for (Entry<GraphEdge, Status> entry : edgesWithStatus.entrySet()) {
        int relativeWeight = Math.floorDiv(entry.getKey().getWeight(), gcd);
        for (int i = 0; i < relativeWeight; i++) {
            statuses.add(new StatusWithIndex(entry.getValue(), k));
        }
        k++;
    }
    return statuses;
}
Also used : IpService(org.opennms.netmgt.bsm.service.model.IpService) Point2D(java.awt.geom.Point2D) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) AlarmWrapper(org.opennms.netmgt.bsm.service.model.AlarmWrapper) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Transformer(org.apache.commons.collections15.Transformer) StatusWithIndices(org.opennms.netmgt.bsm.service.model.StatusWithIndices) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) BigInteger(java.math.BigInteger) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ThresholdResultExplanation(org.opennms.netmgt.bsm.service.model.functions.reduce.ThresholdResultExplanation) BufferedImage(java.awt.image.BufferedImage) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) Dimension(java.awt.Dimension) List(java.util.List) Edge(org.opennms.netmgt.bsm.service.model.edge.Edge) BusinessServiceStateChangeHandler(org.opennms.netmgt.bsm.service.BusinessServiceStateChangeHandler) Entry(java.util.Map.Entry) Optional(java.util.Optional) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge) VisualizationImageServer(edu.uci.ics.jung.visualization.VisualizationImageServer) Threshold(org.opennms.netmgt.bsm.service.model.functions.reduce.Threshold) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Function(java.util.function.Function) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Lists(com.google.common.collect.Lists) KKLayout(edu.uci.ics.jung.algorithms.layout.KKLayout) Status(org.opennms.netmgt.bsm.service.model.Status) AlarmProvider(org.opennms.netmgt.bsm.service.AlarmProvider) Layout(edu.uci.ics.jung.algorithms.layout.Layout) Logger(org.slf4j.Logger) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) BusinessServiceGraphImpl(org.opennms.netmgt.bsm.service.model.graph.internal.BusinessServiceGraphImpl) File(java.io.File) StatusWithIndex(org.opennms.netmgt.bsm.service.model.StatusWithIndex) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) GraphAlgorithms(org.opennms.netmgt.bsm.service.model.graph.internal.GraphAlgorithms) Collections(java.util.Collections) StatusWithIndex(org.opennms.netmgt.bsm.service.model.StatusWithIndex) Status(org.opennms.netmgt.bsm.service.model.Status) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge)

Example 7 with GraphEdge

use of org.opennms.netmgt.bsm.service.model.graph.GraphEdge 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(StatusWithIndex::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;
}
Also used : StatusWithIndex(org.opennms.netmgt.bsm.service.model.StatusWithIndex) Status(org.opennms.netmgt.bsm.service.model.Status) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ThresholdResultExplanation(org.opennms.netmgt.bsm.service.model.functions.reduce.ThresholdResultExplanation) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge) Edge(org.opennms.netmgt.bsm.service.model.edge.Edge) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge) StatusWithIndices(org.opennms.netmgt.bsm.service.model.StatusWithIndices)

Example 8 with GraphEdge

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

the class BusinessServiceGraphImpl method calculateAndIndexLevels.

private void calculateAndIndexLevels() {
    // Start by finding the root vertices
    // These are the vertices with no incoming edges
    final Set<GraphVertex> rootVertices = Sets.newHashSet();
    for (GraphVertex vertex : getVertices()) {
        if (getInEdges(vertex).size() == 0) {
            rootVertices.add(vertex);
        }
    }
    // Now calculate the distance of every node to each of the root nodes
    final GraphLevelIndexer<GraphVertex, GraphEdge> levelIndexer = new GraphLevelIndexer<>();
    levelIndexer.indexLevel(this, rootVertices);
    for (Entry<GraphVertex, Integer> entry : levelIndexer.getLevelMap().entrySet()) {
        final int level = entry.getValue().intValue();
        final GraphVertexImpl vertex = (GraphVertexImpl) entry.getKey();
        // Store the maximum level within the vertex
        vertex.setLevel(Math.max(level, vertex.getLevel()));
    }
    // Index the vertices by level
    for (GraphVertex vertex : getVertices()) {
        Set<GraphVertex> verticesAtLevel = m_verticesByLevel.get(vertex.getLevel());
        if (verticesAtLevel == null) {
            verticesAtLevel = Sets.newHashSet();
            m_verticesByLevel.put(vertex.getLevel(), verticesAtLevel);
        }
        verticesAtLevel.add(vertex);
    }
}
Also used : GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge)

Aggregations

GraphEdge (org.opennms.netmgt.bsm.service.model.graph.GraphEdge)8 GraphVertex (org.opennms.netmgt.bsm.service.model.graph.GraphVertex)7 Status (org.opennms.netmgt.bsm.service.model.Status)3 Edge (org.opennms.netmgt.bsm.service.model.edge.Edge)3 KKLayout (edu.uci.ics.jung.algorithms.layout.KKLayout)2 VisualizationImageServer (edu.uci.ics.jung.visualization.VisualizationImageServer)2 Dimension (java.awt.Dimension)2 BufferedImage (java.awt.image.BufferedImage)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 StatusWithIndex (org.opennms.netmgt.bsm.service.model.StatusWithIndex)2 StatusWithIndices (org.opennms.netmgt.bsm.service.model.StatusWithIndices)2 ThresholdResultExplanation (org.opennms.netmgt.bsm.service.model.functions.reduce.ThresholdResultExplanation)2 BusinessServiceGraph (org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)2 Throwables (com.google.common.base.Throwables)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 Layout (edu.uci.ics.jung.algorithms.layout.Layout)1 Point2D (java.awt.geom.Point2D)1