Search in sources :

Example 1 with AlarmWrapper

use of org.opennms.netmgt.bsm.service.model.AlarmWrapper 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().filter(v -> v.getBusinessService() != null).map(v -> v.getBusinessService()).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 : IpService(org.opennms.netmgt.bsm.service.model.IpService) Point2D(java.awt.geom.Point2D) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) AlarmWrapper(org.opennms.netmgt.bsm.service.model.AlarmWrapper) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Transformer(org.apache.commons.collections15.Transformer) StatusWithIndices(org.opennms.netmgt.bsm.service.model.StatusWithIndices) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) BigInteger(java.math.BigInteger) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ThresholdResultExplanation(org.opennms.netmgt.bsm.service.model.functions.reduce.ThresholdResultExplanation) BufferedImage(java.awt.image.BufferedImage) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) Dimension(java.awt.Dimension) List(java.util.List) Edge(org.opennms.netmgt.bsm.service.model.edge.Edge) BusinessServiceStateChangeHandler(org.opennms.netmgt.bsm.service.BusinessServiceStateChangeHandler) Entry(java.util.Map.Entry) Optional(java.util.Optional) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge) VisualizationImageServer(edu.uci.ics.jung.visualization.VisualizationImageServer) Threshold(org.opennms.netmgt.bsm.service.model.functions.reduce.Threshold) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Function(java.util.function.Function) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Lists(com.google.common.collect.Lists) KKLayout(edu.uci.ics.jung.algorithms.layout.KKLayout) Status(org.opennms.netmgt.bsm.service.model.Status) AlarmProvider(org.opennms.netmgt.bsm.service.AlarmProvider) Layout(edu.uci.ics.jung.algorithms.layout.Layout) Logger(org.slf4j.Logger) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) BusinessServiceGraphImpl(org.opennms.netmgt.bsm.service.model.graph.internal.BusinessServiceGraphImpl) File(java.io.File) StatusWithIndex(org.opennms.netmgt.bsm.service.model.StatusWithIndex) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) GraphAlgorithms(org.opennms.netmgt.bsm.service.model.graph.internal.GraphAlgorithms) Collections(java.util.Collections) 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) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)

Example 2 with AlarmWrapper

use of org.opennms.netmgt.bsm.service.model.AlarmWrapper in project opennms by OpenNMS.

the class DefaultBusinessServiceStateMachine method setBusinessServices.

@Override
public void setBusinessServices(List<BusinessService> businessServices) {
    m_rwLock.writeLock().lock();
    try {
        // Create a new graph
        BusinessServiceGraph g = new BusinessServiceGraphImpl(businessServices);
        // Prime the graph with the state from the previous graph and
        // keep track of the new reductions keys
        Set<String> reductionsKeysToLookup = Sets.newHashSet();
        for (String reductionKey : g.getReductionKeys()) {
            GraphVertex reductionKeyVertex = m_g.getVertexByReductionKey(reductionKey);
            if (reductionKeyVertex != null) {
                updateAndPropagateVertex(g, g.getVertexByReductionKey(reductionKey), reductionKeyVertex.getStatus());
            } else {
                reductionsKeysToLookup.add(reductionKey);
            }
        }
        if (m_alarmProvider == null && reductionsKeysToLookup.size() > 0) {
            LOG.warn("There are one or more reduction keys to lookup, but no alarm provider is set.");
        } else {
            // graph without having to wait for calls to handleNewOrUpdatedAlarm()
            if (reductionsKeysToLookup.size() > 0) {
                final Map<String, AlarmWrapper> lookup = m_alarmProvider.lookup(reductionsKeysToLookup);
                for (Entry<String, AlarmWrapper> eachEntry : lookup.entrySet()) {
                    updateAndPropagateVertex(g, g.getVertexByReductionKey(eachEntry.getKey()), eachEntry.getValue().getStatus());
                }
            }
        }
        m_g = g;
    } finally {
        m_rwLock.writeLock().unlock();
    }
}
Also used : GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) BusinessServiceGraphImpl(org.opennms.netmgt.bsm.service.model.graph.internal.BusinessServiceGraphImpl) AlarmWrapper(org.opennms.netmgt.bsm.service.model.AlarmWrapper) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)

Example 3 with AlarmWrapper

use of org.opennms.netmgt.bsm.service.model.AlarmWrapper in project opennms by OpenNMS.

the class DefaultBusinessServiceStateMachine method handleAllAlarms.

@Override
public void handleAllAlarms(List<AlarmWrapper> alarms) {
    final Set<String> reductionKeysFromGivenAlarms = new HashSet<>(alarms.size());
    m_rwLock.writeLock().lock();
    try {
        for (AlarmWrapper alarm : alarms) {
            // Recursively propagate the status for all of the given alarms
            updateAndPropagateVertex(m_g, m_g.getVertexByReductionKey(alarm.getReductionKey()), alarm.getStatus());
            // Keep track of the reduction keys that have been processed
            reductionKeysFromGivenAlarms.add(alarm.getReductionKey());
        }
        for (String missingReductionKey : Sets.difference(m_g.getReductionKeys(), reductionKeysFromGivenAlarms)) {
            // There is a vertex on the graph that corresponds to this reduction key
            // but no alarm with this reduction key exists
            updateAndPropagateVertex(m_g, m_g.getVertexByReductionKey(missingReductionKey), Status.INDETERMINATE);
        }
    } finally {
        m_rwLock.writeLock().unlock();
    }
}
Also used : AlarmWrapper(org.opennms.netmgt.bsm.service.model.AlarmWrapper) HashSet(java.util.HashSet)

Example 4 with AlarmWrapper

use of org.opennms.netmgt.bsm.service.model.AlarmWrapper 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 : 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) Status(org.opennms.netmgt.bsm.service.model.Status) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) AlarmWrapper(org.opennms.netmgt.bsm.service.model.AlarmWrapper)

Example 5 with AlarmWrapper

use of org.opennms.netmgt.bsm.service.model.AlarmWrapper 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;
        }
    });
}
Also used : Status(org.opennms.netmgt.bsm.service.model.Status) TransactionStatus(org.springframework.transaction.TransactionStatus) AlarmWrapper(org.opennms.netmgt.bsm.service.model.AlarmWrapper) Parm(org.opennms.netmgt.xml.event.Parm)

Aggregations

AlarmWrapper (org.opennms.netmgt.bsm.service.model.AlarmWrapper)6 Status (org.opennms.netmgt.bsm.service.model.Status)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Collectors (java.util.stream.Collectors)2 BusinessServiceStateMachine (org.opennms.netmgt.bsm.service.BusinessServiceStateMachine)2 BusinessServiceGraph (org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)2 GraphVertex (org.opennms.netmgt.bsm.service.model.graph.GraphVertex)2 BusinessServiceGraphImpl (org.opennms.netmgt.bsm.service.model.graph.internal.BusinessServiceGraphImpl)2 Throwables (com.google.common.base.Throwables)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 KKLayout (edu.uci.ics.jung.algorithms.layout.KKLayout)1 Layout (edu.uci.ics.jung.algorithms.layout.Layout)1 VisualizationImageServer (edu.uci.ics.jung.visualization.VisualizationImageServer)1 Dimension (java.awt.Dimension)1 Point2D (java.awt.geom.Point2D)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1