use of org.opennms.netmgt.bsm.service.model.Status 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.Status in project opennms by OpenNMS.
the class Threshold method getHitsByStatus.
// We increment the number of "hits" for a particular Status key
// when one of the inputs is greater or equals to that given key
// For example, reduce(Status.WARNING, Status.NORMAL) would build a map that looks like:
// { 'WARNING': 1, 'NORMAL': 2, 'INDETERMINATE': 2 }
public Map<Status, Integer> getHitsByStatus(List<Status> statuses) {
final Map<Status, Integer> hitsByStatus = new TreeMap<>(HIGHEST_SEVERITY_FIRST);
for (Status s : statuses) {
for (Status ss : Status.values()) {
if (ss.isGreaterThan(s)) {
continue;
}
Integer count = hitsByStatus.get(ss);
if (count == null) {
count = 1;
} else {
count = count + 1;
}
hitsByStatus.put(ss, count);
}
}
return hitsByStatus;
}
use of org.opennms.netmgt.bsm.service.model.Status in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachine method clone.
@Override
public BusinessServiceStateMachine clone(boolean preserveState) {
m_rwLock.readLock().lock();
try {
final BusinessServiceStateMachine sm = new DefaultBusinessServiceStateMachine();
// Rebuild the graph using the business services from the existing state machine
final BusinessServiceGraph graph = getGraph();
sm.setBusinessServices(graph.getVertices().stream().map(GraphVertex::getBusinessService).filter(Objects::nonNull).collect(Collectors.toList()));
// Prime the state
if (preserveState) {
for (String reductionKey : graph.getReductionKeys()) {
GraphVertex reductionKeyVertex = graph.getVertexByReductionKey(reductionKey);
sm.handleNewOrUpdatedAlarm(new AlarmWrapper() {
@Override
public String getReductionKey() {
return reductionKey;
}
@Override
public Status getStatus() {
return reductionKeyVertex.getStatus();
}
});
}
}
return sm;
} finally {
m_rwLock.readLock().unlock();
}
}
use of org.opennms.netmgt.bsm.service.model.Status in project opennms by OpenNMS.
the class SimulationAwareStateMachineFactory method createSimulatedStateMachine.
public static BusinessServiceStateMachine createSimulatedStateMachine(BusinessServiceManager manager, Criteria[] criteria) {
// Gather the statuses and group them by reduction key
final Map<String, Status> statusByReductionKey = Arrays.stream(criteria).filter(c -> c instanceof SetStatusToCriteria).map(c -> (SetStatusToCriteria) c).filter(c -> c.getStatus() != null).collect(Collectors.toMap(SetStatusToCriteria::getReductionKey, SetStatusToCriteria::getStatus));
// Determine whether or not we should inherit the existing state
final boolean shouldInheritState = Arrays.stream(criteria).anyMatch(c -> c instanceof InheritStateCriteria);
// Grab a copy of the state machine, and update push alarms
// that reflect the simulated state of the reduction keys
final BusinessServiceStateMachine stateMachine = manager.getStateMachine().clone(shouldInheritState);
for (Entry<String, Status> entry : statusByReductionKey.entrySet()) {
stateMachine.handleNewOrUpdatedAlarm(new AlarmWrapper() {
@Override
public String getReductionKey() {
return entry.getKey();
}
@Override
public Status getStatus() {
return entry.getValue();
}
});
}
return stateMachine;
}
use of org.opennms.netmgt.bsm.service.model.Status in project opennms by OpenNMS.
the class SimulationModeReductionKeyInfoPanelItemProvider method createComponent.
private Component createComponent(ReductionKeyVertex vertex, GraphContainer container) {
final FormLayout formLayout = new FormLayout();
formLayout.setSpacing(false);
formLayout.setMargin(false);
NativeSelect dropdown = new NativeSelect("Severity");
dropdown.setMultiSelect(false);
dropdown.setNewItemsAllowed(false);
dropdown.setNullSelectionAllowed(true);
dropdown.setImmediate(true);
dropdown.setRequired(true);
dropdown.addItems(Arrays.asList(Status.values()));
SetStatusToCriteria setStatusTo = findCriteria(container, vertex);
if (setStatusTo != null) {
dropdown.setValue(setStatusTo.getStatus());
} else {
dropdown.setValue(null);
}
dropdown.addValueChangeListener(event -> {
// The set of criteria may have changed since we last queried it above
// do we issue try finding it again, instead of using the same existing object
SetStatusToCriteria currentSetStatusTo = findCriteria(container, vertex);
Status selectedStatus = (Status) dropdown.getValue();
if (currentSetStatusTo != null) {
currentSetStatusTo.setStatus(selectedStatus);
} else {
currentSetStatusTo = new SetStatusToCriteria(vertex.getReductionKey(), selectedStatus);
container.addCriteria(currentSetStatusTo);
}
// Remove the current selection before redrawing the layout in order
// to avoid centering on the current vertex
container.getSelectionManager().setSelectedVertexRefs(Collections.emptyList());
container.getSelectionManager().setSelectedEdgeRefs(Collections.emptyList());
container.redoLayout();
});
formLayout.addComponent(dropdown);
return formLayout;
}
Aggregations