Search in sources :

Example 1 with StatusWithIndex

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

the class DefaultBusinessServiceStateMachine method reduceUpdateAndPropagateVertex.

private void reduceUpdateAndPropagateVertex(BusinessServiceGraph graph, GraphVertex vertex) {
    if (vertex == null) {
        // Nothing to do here
        return;
    }
    // Calculate the weighed statuses from the child edges
    List<StatusWithIndex> statuses = weighEdges(graph.getOutEdges(vertex));
    // Reduce
    Optional<StatusWithIndices> reducedStatus = vertex.getReductionFunction().reduce(statuses);
    Status newStatus;
    if (reducedStatus.isPresent()) {
        newStatus = reducedStatus.get().getStatus();
    } else {
        newStatus = MIN_SEVERITY;
    }
    // Update and propagate
    updateAndPropagateVertex(graph, vertex, newStatus);
}
Also used : StatusWithIndex(org.opennms.netmgt.bsm.service.model.StatusWithIndex) Status(org.opennms.netmgt.bsm.service.model.Status) StatusWithIndices(org.opennms.netmgt.bsm.service.model.StatusWithIndices)

Example 2 with StatusWithIndex

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

the class ExponentialPropagation method reduce.

@Override
public Optional<StatusWithIndices> reduce(List<StatusWithIndex> statuses) {
    // Exit early for no incoming statuses
    if (statuses.isEmpty()) {
        return Optional.empty();
    }
    // indeterminate. So, we have to handle this case explicitly here...
    if (Iterables.all(statuses, si -> si.getStatus() == Status.INDETERMINATE)) {
        return Optional.empty();
    }
    // Get the exponential sum of all child states
    final double sum = statuses.stream().filter(// Ignore normal and indeterminate
    si -> si.getStatus().ordinal() >= Status.WARNING.ordinal()).mapToDouble(// Offset to warning = n^0
    si -> Math.pow(this.base, (double) (si.getStatus().ordinal() - Status.WARNING.ordinal()))).sum();
    // Grab the indices from all the statuses that contributed to the sum
    // since these contribute to the cause
    final List<Integer> contributingIndices = statuses.stream().filter(si -> si.getStatus().ordinal() >= Status.WARNING.ordinal()).map(StatusWithIndex::getIndex).distinct().sorted().collect(Collectors.toList());
    // Get the log n of the sum
    // Revert offset from above
    final int res = (int) Math.floor(Math.log(sum) / Math.log(this.base)) + Status.WARNING.ordinal();
    // Find the resulting status and treat values lower than NORMAL.ordinal() as NORMAL.ordinal() and
    // all values higher than CRITICAL.ordinal() as CRITICAL.ordinal()
    final Status effectiveStatus = Status.get(Math.max(Math.min(res, Status.CRITICAL.ordinal()), Status.NORMAL.ordinal()));
    return Optional.of(new StatusWithIndices(effectiveStatus, contributingIndices));
}
Also used : List(java.util.List) Parameter(org.opennms.netmgt.bsm.service.model.functions.annotations.Parameter) Iterables(com.google.common.collect.Iterables) StatusWithIndex(org.opennms.netmgt.bsm.service.model.StatusWithIndex) Status(org.opennms.netmgt.bsm.service.model.Status) StatusWithIndices(org.opennms.netmgt.bsm.service.model.StatusWithIndices) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Collectors(java.util.stream.Collectors) Function(org.opennms.netmgt.bsm.service.model.functions.annotations.Function) Status(org.opennms.netmgt.bsm.service.model.Status) StatusWithIndices(org.opennms.netmgt.bsm.service.model.StatusWithIndices)

Example 3 with StatusWithIndex

use of org.opennms.netmgt.bsm.service.model.StatusWithIndex 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 4 with StatusWithIndex

use of org.opennms.netmgt.bsm.service.model.StatusWithIndex 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)

Aggregations

Status (org.opennms.netmgt.bsm.service.model.Status)4 StatusWithIndex (org.opennms.netmgt.bsm.service.model.StatusWithIndex)4 StatusWithIndices (org.opennms.netmgt.bsm.service.model.StatusWithIndices)4 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Edge (org.opennms.netmgt.bsm.service.model.edge.Edge)2 ThresholdResultExplanation (org.opennms.netmgt.bsm.service.model.functions.reduce.ThresholdResultExplanation)2 GraphEdge (org.opennms.netmgt.bsm.service.model.graph.GraphEdge)2 GraphVertex (org.opennms.netmgt.bsm.service.model.graph.GraphVertex)2 Preconditions (com.google.common.base.Preconditions)1 Throwables (com.google.common.base.Throwables)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 KKLayout (edu.uci.ics.jung.algorithms.layout.KKLayout)1 Layout (edu.uci.ics.jung.algorithms.layout.Layout)1 VisualizationImageServer (edu.uci.ics.jung.visualization.VisualizationImageServer)1