Search in sources :

Example 6 with Status

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));
}
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 7 with Status

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;
}
Also used : Status(org.opennms.netmgt.bsm.service.model.Status) TreeMap(java.util.TreeMap)

Example 8 with Status

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();
    }
}
Also used : Status(org.opennms.netmgt.bsm.service.model.Status) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) AlarmWrapper(org.opennms.netmgt.bsm.service.model.AlarmWrapper) Objects(java.util.Objects) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)

Example 9 with Status

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;
}
Also used : Status(org.opennms.netmgt.bsm.service.model.Status) Arrays(java.util.Arrays) Status(org.opennms.netmgt.bsm.service.model.Status) Map(java.util.Map) Criteria(org.opennms.features.topology.api.topo.Criteria) Entry(java.util.Map.Entry) BusinessServiceManager(org.opennms.netmgt.bsm.service.BusinessServiceManager) AlarmWrapper(org.opennms.netmgt.bsm.service.model.AlarmWrapper) Collectors(java.util.stream.Collectors) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) AlarmWrapper(org.opennms.netmgt.bsm.service.model.AlarmWrapper)

Example 10 with Status

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;
}
Also used : FormLayout(com.vaadin.ui.FormLayout) Status(org.opennms.netmgt.bsm.service.model.Status) SetStatusToCriteria(org.opennms.features.topology.plugins.topo.bsm.simulate.SetStatusToCriteria) NativeSelect(com.vaadin.ui.NativeSelect)

Aggregations

Status (org.opennms.netmgt.bsm.service.model.Status)17 BusinessServiceStateMachine (org.opennms.netmgt.bsm.service.BusinessServiceStateMachine)5 Collectors (java.util.stream.Collectors)4 AlarmWrapper (org.opennms.netmgt.bsm.service.model.AlarmWrapper)4 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)4 StatusWithIndex (org.opennms.netmgt.bsm.service.model.StatusWithIndex)4 StatusWithIndices (org.opennms.netmgt.bsm.service.model.StatusWithIndices)4 GraphVertex (org.opennms.netmgt.bsm.service.model.graph.GraphVertex)4 FormLayout (com.vaadin.ui.FormLayout)3 List (java.util.List)3 Edge (org.opennms.netmgt.bsm.service.model.edge.Edge)3 BusinessServiceGraph (org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)3 GraphEdge (org.opennms.netmgt.bsm.service.model.graph.GraphEdge)3 Label (com.vaadin.ui.Label)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2