use of org.opennms.features.topology.api.topo.Criteria 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.features.topology.api.topo.Criteria in project opennms by OpenNMS.
the class NCSHopCriteriaHistoryOperation method applyHistory.
@Override
public void applyHistory(GraphContainer container, Map<String, String> settings) {
// Remove any existing {@link NCSHopCriteria}
Set<NCSHopCriteria> oldCriteria = Criteria.getCriteriaForGraphContainer(container, NCSHopCriteria.class);
for (NCSHopCriteria criterium : oldCriteria) {
container.removeCriteria(criterium);
}
String setting = settings.get(getClass().getName());
if (setting != null && setting.length() > 0) {
for (String idString : setting.split(DELIMITER)) {
Long id = Long.parseLong(idString);
Criteria criteria = NCSEdgeProvider.createCriteria(Collections.singletonList(id));
container.addCriteria(new NCSHopCriteria(idString, NCSSearchProvider.getVertexRefsForEdges(m_ncsEdgeProvider, criteria), m_ncsComponentRepository.get(id).getName()));
}
}
}
use of org.opennms.features.topology.api.topo.Criteria in project opennms by OpenNMS.
the class NCSSearchProvider method addVertexHopCriteria.
@Override
public void addVertexHopCriteria(SearchResult searchResult, GraphContainer container) {
Criteria criteria = NCSEdgeProvider.createCriteria(Collections.singletonList(Long.parseLong(searchResult.getId())));
container.addCriteria(new NCSHopCriteria(searchResult.getId(), new HashSet<VertexRef>(getVertexRefsForEdges(m_ncsEdgeProvider, criteria)), searchResult.getLabel()));
}
use of org.opennms.features.topology.api.topo.Criteria in project opennms by OpenNMS.
the class VertexHopGraphProvider method getVertices.
@Override
public List<Vertex> getVertices(Criteria... criteria) {
// If we have a IgnoreHopCriteria, just return all existing vertices
for (Criteria criterium : criteria) {
try {
IgnoreHopCriteria ignoreHopCriteria = (IgnoreHopCriteria) criterium;
return m_delegate.getVertices();
} catch (ClassCastException e) {
}
}
// Otherwise consider vertices szl and focus nodes
Set<VertexRef> focusNodes = getFocusNodes(criteria);
int maxSemanticZoomLevel = getMaxSemanticZoomLevel(criteria);
// Clear the existing semantic zoom level values
m_semanticZoomLevels.clear();
int semanticZoomLevel = 0;
// If we didn't find any matching nodes among the focus nodes...
if (focusNodes.size() < 1) {
// ...then return an empty list of vertices
return Collections.emptyList();
// return allVertices;
}
Map<VertexRef, Set<VertexRef>> neighborMap = new HashMap<VertexRef, Set<VertexRef>>();
List<Edge> edges = m_delegate.getEdges(criteria);
for (Edge edge : edges) {
VertexRef src = edge.getSource().getVertex();
VertexRef tgt = edge.getTarget().getVertex();
Set<VertexRef> srcNeighbors = neighborMap.get(src);
if (srcNeighbors == null) {
srcNeighbors = new HashSet<VertexRef>();
neighborMap.put(src, srcNeighbors);
}
srcNeighbors.add(tgt);
Set<VertexRef> tgtNeighbors = neighborMap.get(tgt);
if (tgtNeighbors == null) {
tgtNeighbors = new HashSet<VertexRef>();
neighborMap.put(tgt, tgtNeighbors);
}
tgtNeighbors.add(src);
}
Set<Vertex> processed = new HashSet<Vertex>();
Set<VertexRef> neighbors = new HashSet<VertexRef>();
Set<VertexRef> workingSet = new HashSet<VertexRef>(focusNodes);
// Put a limit on the SZL in case we infinite loop for some reason
while (semanticZoomLevel <= maxSemanticZoomLevel && workingSet.size() > 0) {
neighbors.clear();
for (VertexRef vertexRef : workingSet) {
// Only consider Vertex if it is actually not filtered by the criteria (which it might)
Vertex vertex = getVertex(vertexRef, criteria);
if (vertex != null) {
if (m_semanticZoomLevels.containsKey(vertexRef)) {
throw new IllegalStateException("Calculating semantic zoom level for vertex that has already been calculated: " + vertexRef.toString());
}
m_semanticZoomLevels.put(vertexRef, semanticZoomLevel);
Set<VertexRef> refs = neighborMap.get(vertexRef);
if (refs != null) {
neighbors.addAll(refs);
}
processed.add(vertex);
}
}
neighbors.removeAll(processed);
workingSet.clear();
workingSet.addAll(neighbors);
// Increment the semantic zoom level
semanticZoomLevel++;
}
processed = collapseVertices(processed, getCollapsedCriteria(criteria));
return new ArrayList<Vertex>(processed);
}
use of org.opennms.features.topology.api.topo.Criteria in project opennms by OpenNMS.
the class AlarmSearchProvider method removeVertexHopCriteria.
@Override
public void removeVertexHopCriteria(SearchResult searchResult, GraphContainer container) {
LOG.debug("SearchProvider.removeVertexHopCriteria: called with search result: '{}'", searchResult);
Criteria criterion = findCriterion(searchResult, container);
if (criterion != null) {
container.removeCriteria(criterion);
}
}
Aggregations