use of org.opennms.features.topology.api.topo.DefaultStatus in project opennms by OpenNMS.
the class GraphMLVertexStatusProvider method getStatusForVertices.
@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
// All vertices for the current vertexProvider
final List<GraphMLVertex> graphMLVertices = vertices.stream().filter(eachVertex -> contributesTo(eachVertex.getNamespace()) && eachVertex instanceof GraphMLVertex).map(eachVertex -> (GraphMLVertex) eachVertex).collect(Collectors.toList());
// All vertices associated with a node id
final Map<Integer, VertexRef> nodeIdMap = graphMLVertices.stream().filter(eachVertex -> eachVertex.getNodeID() != null).collect(Collectors.toMap(AbstractVertex::getNodeID, Function.identity()));
// Alarm summary for each node id
final Map<Integer, AlarmSummary> nodeIdToAlarmSummaryMap = getAlarmSummaries(nodeIdMap.keySet());
// Set the result
Map<VertexRef, Status> resultMap = Maps.newHashMap();
for (GraphMLVertex eachVertex : graphMLVertices) {
AlarmSummary alarmSummary = nodeIdToAlarmSummaryMap.get(eachVertex.getNodeID());
DefaultStatus status = alarmSummary == null ? new VertexStatus(OnmsSeverity.NORMAL) : new VertexStatus(alarmSummary.getMaxSeverity(), alarmSummary.getAlarmCount());
resultMap.put(eachVertex, status);
}
return resultMap;
}
use of org.opennms.features.topology.api.topo.DefaultStatus in project opennms by OpenNMS.
the class VmwareStatusProvider method getStatusForVertices.
@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
final List<AbstractVertex> vmwareVertices = vertices.stream().filter(v -> v.getNamespace().equals(getNamespace())).map(v -> (AbstractVertex) v).collect(Collectors.toList());
// All vertices associated with a node id
final Map<Integer, VertexRef> nodeIdMap = vmwareVertices.stream().filter(v -> v.getNodeID() != null).collect(Collectors.toMap(AbstractVertex::getNodeID, Function.identity()));
// Alarm summary for each node id
final Map<Integer, AlarmSummary> nodeIdToAlarmSummaryMap = getAlarmSummaries(nodeIdMap.keySet());
// Set the result
Map<VertexRef, Status> resultMap = Maps.newHashMap();
for (AbstractVertex eachVertex : vmwareVertices) {
AlarmSummary alarmSummary = nodeIdToAlarmSummaryMap.get(eachVertex.getNodeID());
if (alarmSummary != null) {
resultMap.put(eachVertex, new DefaultStatus(alarmSummary.getMaxSeverity().getLabel(), 0));
}
}
return resultMap;
}
use of org.opennms.features.topology.api.topo.DefaultStatus in project opennms by OpenNMS.
the class ApplicationStatusProvider method getStatusForVertices.
@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
Map<VertexRef, Status> returnMap = new HashMap<>();
Map<ApplicationStatusEntity.Key, Status> statusMap = new HashMap<>();
List<ApplicationStatusEntity> result = applicationDao.getAlarmStatus();
for (ApplicationStatusEntity eachRow : result) {
DefaultStatus status = createStatus(eachRow.getSeverity(), eachRow.getCount());
statusMap.put(eachRow.getKey(), status);
}
// status for all known node ids
Collection<VertexRef> vertexRefsForNamespace = getVertexRefsForNamespace(vertices);
Collection<VertexRef> vertexRefsRoot = getRootElements(vertexRefsForNamespace);
Collection<VertexRef> vertexRefs = new ArrayList<>(vertexRefsForNamespace);
vertexRefs.removeAll(vertexRefsRoot);
// calculate status for children
for (VertexRef eachVertex : vertexRefs) {
ApplicationVertex applicationVertex = (ApplicationVertex) eachVertex;
Status alarmStatus = statusMap.get(createKey(applicationVertex));
if (alarmStatus == null) {
alarmStatus = createStatus(OnmsSeverity.NORMAL, 0);
}
returnMap.put(eachVertex, alarmStatus);
}
// calculate status for root
for (VertexRef eachRoot : vertexRefsRoot) {
ApplicationVertex eachRootApplication = (ApplicationVertex) eachRoot;
OnmsSeverity maxSeverity = OnmsSeverity.NORMAL;
int count = 0;
for (VertexRef eachChild : eachRootApplication.getChildren()) {
ApplicationVertex eachChildApplication = (ApplicationVertex) eachChild;
ApplicationStatusEntity.Key childKey = createKey(eachChildApplication);
Status childStatus = statusMap.get(childKey);
if (childStatus != null && maxSeverity.isLessThan(createSeverity(childStatus.computeStatus()))) {
maxSeverity = createSeverity(childStatus.computeStatus());
count = Integer.parseInt(childStatus.getStatusProperties().get("statusCount"));
}
}
returnMap.put(eachRoot, createStatus(maxSeverity, count));
}
return returnMap;
}
use of org.opennms.features.topology.api.topo.DefaultStatus in project opennms by OpenNMS.
the class PathOutageStatusProvider method getStatusForVertices.
@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
final List<Integer> nodeIds = vertices.stream().filter(v -> v.getNamespace().equals(getNamespace())).map(v -> (PathOutageVertex) v).map(v -> v.getNodeID()).collect(Collectors.toList());
if (nodeIds.isEmpty()) {
return new HashMap<>();
}
// Preparing database request
final StringBuilder hql = new StringBuilder();
hql.append("SELECT node.id, max(event.eventSeverity) ");
hql.append("FROM OnmsOutage as outage ");
hql.append("LEFT JOIN outage.monitoredService as ifservice ");
hql.append("LEFT JOIN ifservice.ipInterface as ipinterface ");
hql.append("LEFT JOIN ipinterface.node as node ");
hql.append("LEFT JOIN outage.serviceLostEvent as event ");
hql.append("WHERE node.id in (:nodeIds) ");
hql.append("AND outage.serviceRegainedEvent is null ");
hql.append("GROUP BY node.id");
final List<String> paramNames = Lists.newArrayList("nodeIds");
final List<Object> paramValues = new ArrayList();
paramValues.add(Lists.newArrayList(nodeIds));
final List<Object[]> retvals = this.persistenceAccessor.findUsingNamedParameters(hql.toString(), paramNames.toArray(new String[paramNames.size()]), paramValues.toArray());
// Generating alarms map
final Map<Integer, OnmsSeverity> mappedAlarms = new HashedMap();
for (int i = 0; i < retvals.size(); i++) {
final Integer nodeId = (Integer) retvals.get(i)[0];
final Integer severity = Optional.ofNullable((Integer) retvals.get(i)[1]).orElse(OnmsSeverity.NORMAL.ordinal());
mappedAlarms.put(nodeId, OnmsSeverity.get(severity));
}
final Map<VertexRef, Status> status = vertices.stream().map(v -> (PathOutageVertex) v).collect(Collectors.toMap(v -> v, v -> {
if (!mappedAlarms.containsKey(v.getNodeID())) {
return new DefaultStatus(OnmsSeverity.NORMAL.getLabel(), 0);
} else {
return new DefaultStatus(mappedAlarms.get(v.getNodeID()).getLabel(), 0);
}
}));
return status;
}
Aggregations