use of org.opennms.netmgt.bsm.service.model.Status in project opennms by OpenNMS.
the class BusinessServiceStatusService method buildFrom.
private BusinessServiceSearchCriteriaBuilder buildFrom(Query query) {
final BusinessServiceSearchCriteriaBuilder criteriaBuilder = new BusinessServiceSearchCriteriaBuilder();
if (query.getSeverityFilter() != null && !query.getSeverityFilter().getSeverities().isEmpty()) {
final List<Status> statusList = query.getSeverityFilter().getSeverities().stream().map(eachSeverity -> Status.of(eachSeverity.name())).collect(Collectors.toList());
criteriaBuilder.inSeverity(statusList);
} else {
criteriaBuilder.greaterOrEqualSeverity(Status.NORMAL);
}
if (query.getParameters().getOrder() != null) {
final QueryParameters.Order order = query.getParameters().getOrder();
criteriaBuilder.order(order.getColumn(), !order.isDesc());
}
if (query.getParameters().getLimit() != null) {
criteriaBuilder.limit(query.getParameters().getLimit());
}
if (query.getParameters().getOffset() != null) {
criteriaBuilder.offset(query.getParameters().getOffset());
}
return criteriaBuilder;
}
use of org.opennms.netmgt.bsm.service.model.Status 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.Status 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;
}
use of org.opennms.netmgt.bsm.service.model.Status in project opennms by OpenNMS.
the class Bsmd method handleAlarmDeleted.
private void handleAlarmDeleted(Event e, int alarmId) {
final Parm alarmReductionKeyParm = e.getParm(EventConstants.PARM_ALARM_REDUCTION_KEY);
if (alarmReductionKeyParm == null || alarmReductionKeyParm.getValue() == null) {
LOG.warn("The alarmReductionKey parameter has no value on event with uei: {}. Ignoring.", e.getUei());
return;
}
final String reductionKey = alarmReductionKeyParm.getValue().toString();
LOG.debug("Handling delete for alarm with id: {} and reduction key: {}", alarmId, reductionKey);
m_stateMachine.handleNewOrUpdatedAlarm(new AlarmWrapper() {
@Override
public String getReductionKey() {
return reductionKey;
}
@Override
public Status getStatus() {
return Status.INDETERMINATE;
}
});
}
use of org.opennms.netmgt.bsm.service.model.Status in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachine method updateAndPropagateVertex.
private void updateAndPropagateVertex(BusinessServiceGraph graph, GraphVertex vertex, Status newStatus) {
if (vertex == null) {
// Nothing to do here
return;
}
// Apply lower bound
newStatus = newStatus.isLessThan(MIN_SEVERITY) ? MIN_SEVERITY : newStatus;
// Update the status if necessary
Status previousStatus = vertex.getStatus();
if (previousStatus.equals(newStatus)) {
// The status hasn't changed, there's nothing to propagate
return;
}
vertex.setStatus(newStatus);
// Notify the listeners
onStatusUpdated(graph, vertex, previousStatus);
// Update the edges with the mapped status
List<GraphEdge> updatedEges = Lists.newArrayList();
for (GraphEdge edge : graph.getInEdges(vertex)) {
Status mappedStatus = newStatus;
if (newStatus.isGreaterThan(MIN_SEVERITY)) {
// Only apply the map function when the status is > the minimum
mappedStatus = edge.getMapFunction().map(newStatus).orElse(MIN_SEVERITY);
} else {
mappedStatus = newStatus;
}
if (mappedStatus.equals(edge.getStatus())) {
// The status hasn't changed
continue;
}
// Update the status and add it to the list of edges to propagate
edge.setStatus(mappedStatus);
updatedEges.add(edge);
}
// Propagate once all of the edges have been updated
for (GraphEdge edge : updatedEges) {
reduceUpdateAndPropagateVertex(graph, graph.getOpposite(vertex, edge));
}
}
Aggregations