Search in sources :

Example 1 with StatusWithIndices

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

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

use of org.opennms.netmgt.bsm.service.model.StatusWithIndices 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)3 StatusWithIndex (org.opennms.netmgt.bsm.service.model.StatusWithIndex)3 StatusWithIndices (org.opennms.netmgt.bsm.service.model.StatusWithIndices)3 Preconditions (com.google.common.base.Preconditions)1 Iterables (com.google.common.collect.Iterables)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Edge (org.opennms.netmgt.bsm.service.model.edge.Edge)1 Function (org.opennms.netmgt.bsm.service.model.functions.annotations.Function)1 Parameter (org.opennms.netmgt.bsm.service.model.functions.annotations.Parameter)1 ThresholdResultExplanation (org.opennms.netmgt.bsm.service.model.functions.reduce.ThresholdResultExplanation)1 GraphEdge (org.opennms.netmgt.bsm.service.model.graph.GraphEdge)1 GraphVertex (org.opennms.netmgt.bsm.service.model.graph.GraphVertex)1