Search in sources :

Example 1 with DefaultStatus

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;
}
Also used : AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) Collection(java.util.Collection) Set(java.util.Set) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) ArrayList(java.util.ArrayList) Objects(java.util.Objects) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) List(java.util.List) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) VertexProvider(org.opennms.features.topology.api.topo.VertexProvider) AlarmSummaryWrapper(org.opennms.features.topology.plugins.topo.graphml.internal.AlarmSummaryWrapper) Map(java.util.Map) Criteria(org.opennms.features.topology.api.topo.Criteria) Status(org.opennms.features.topology.api.topo.Status) VertexRef(org.opennms.features.topology.api.topo.VertexRef) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) Status(org.opennms.features.topology.api.topo.Status) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 2 with DefaultStatus

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;
}
Also used : AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) Collection(java.util.Collection) Set(java.util.Set) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) ArrayList(java.util.ArrayList) Objects(java.util.Objects) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) List(java.util.List) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) VertexProvider(org.opennms.features.topology.api.topo.VertexProvider) AlarmDao(org.opennms.netmgt.dao.api.AlarmDao) Map(java.util.Map) Criteria(org.opennms.features.topology.api.topo.Criteria) Status(org.opennms.features.topology.api.topo.Status) VertexRef(org.opennms.features.topology.api.topo.VertexRef) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) Status(org.opennms.features.topology.api.topo.Status) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 3 with DefaultStatus

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;
}
Also used : DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) Status(org.opennms.features.topology.api.topo.Status) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApplicationStatusEntity(org.opennms.netmgt.dao.api.ApplicationStatusEntity) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 4 with DefaultStatus

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;
}
Also used : Collection(java.util.Collection) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) HashedMap(org.apache.commons.collections.map.HashedMap) ArrayList(java.util.ArrayList) Objects(java.util.Objects) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) List(java.util.List) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) Lists(com.google.common.collect.Lists) VertexProvider(org.opennms.features.topology.api.topo.VertexProvider) GenericPersistenceAccessor(org.opennms.netmgt.dao.api.GenericPersistenceAccessor) Map(java.util.Map) Criteria(org.opennms.features.topology.api.topo.Criteria) Optional(java.util.Optional) Status(org.opennms.features.topology.api.topo.Status) VertexRef(org.opennms.features.topology.api.topo.VertexRef) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) Status(org.opennms.features.topology.api.topo.Status) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) HashedMap(org.apache.commons.collections.map.HashedMap) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Aggregations

ArrayList (java.util.ArrayList)4 DefaultStatus (org.opennms.features.topology.api.topo.DefaultStatus)4 Status (org.opennms.features.topology.api.topo.Status)4 VertexRef (org.opennms.features.topology.api.topo.VertexRef)4 Collection (java.util.Collection)3 List (java.util.List)3 Map (java.util.Map)3 Objects (java.util.Objects)3 Collectors (java.util.stream.Collectors)3 Criteria (org.opennms.features.topology.api.topo.Criteria)3 StatusProvider (org.opennms.features.topology.api.topo.StatusProvider)3 VertexProvider (org.opennms.features.topology.api.topo.VertexProvider)3 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)3 Maps (com.google.common.collect.Maps)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 Function (java.util.function.Function)2 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)2 AlarmSummary (org.opennms.netmgt.model.alarm.AlarmSummary)2 Lists (com.google.common.collect.Lists)1