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);
}
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));
}
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;
}
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;
}
Aggregations