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