Search in sources :

Example 1 with GraphMLVertex

use of org.opennms.features.topology.plugins.topo.graphml.GraphMLVertex in project opennms by OpenNMS.

the class GraphMLDefaultVertexStatusProvider method getStatusForVertices.

@Override
public Map<? extends VertexRef, ? extends 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());
        GraphMLVertexStatus status = alarmSummary == null ? new GraphMLVertexStatus() : new GraphMLVertexStatus(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) 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) GraphMLVertex(org.opennms.features.topology.plugins.topo.graphml.GraphMLVertex) Status(org.opennms.features.topology.api.topo.Status) GraphMLVertex(org.opennms.features.topology.plugins.topo.graphml.GraphMLVertex) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 2 with GraphMLVertex

use of org.opennms.features.topology.plugins.topo.graphml.GraphMLVertex in project opennms by OpenNMS.

the class GraphMLScriptVertexStatusProvider method getStatusForVertices.

@Override
public Map<? extends VertexRef, ? extends Status> getStatusForVertices(final VertexProvider vertexProvider, final Collection<VertexRef> vertices, final 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());
    // Alarm summary for each node id
    final Map<Integer, AlarmSummary> nodeIdToAlarmSummaryMap = alarmSummaryWrapper.getAlarmSummaries(Lists.transform(graphMLVertices, AbstractVertex::getNodeID)).stream().collect(Collectors.toMap(AlarmSummary::getNodeId, Function.identity()));
    // Calculate status via scripts
    return serviceAccessor.getTransactionOperations().execute(t -> this.scripting.compute(graphMLVertices.stream(), (vertex) -> {
        final SimpleBindings bindings = new SimpleBindings();
        bindings.put("vertex", vertex);
        if (vertex.getNodeID() != null) {
            bindings.put("node", serviceAccessor.getNodeDao().get(vertex.getNodeID()));
            bindings.put("alarmSummary", nodeIdToAlarmSummaryMap.get(vertex.getNodeID()));
        }
        bindings.put("measurements", new MeasurementsWrapper(serviceAccessor.getMeasurementsService()));
        bindings.put("nodeDao", serviceAccessor.getNodeDao());
        bindings.put("snmpInterfaceDao", serviceAccessor.getSnmpInterfaceDao());
        return bindings;
    }));
}
Also used : MeasurementsWrapper(org.opennms.features.topology.api.info.MeasurementsWrapper) Scripting(org.opennms.features.topology.plugins.topo.graphml.internal.Scripting) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) Collection(java.util.Collection) ScriptEngineManager(javax.script.ScriptEngineManager) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) SimpleBindings(javax.script.SimpleBindings) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) List(java.util.List) Lists(com.google.common.collect.Lists) VertexProvider(org.opennms.features.topology.api.topo.VertexProvider) Paths(java.nio.file.Paths) AlarmSummaryWrapper(org.opennms.features.topology.plugins.topo.graphml.internal.AlarmSummaryWrapper) Criteria(org.opennms.features.topology.api.topo.Criteria) Map(java.util.Map) Status(org.opennms.features.topology.api.topo.Status) VertexRef(org.opennms.features.topology.api.topo.VertexRef) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) Path(java.nio.file.Path) GraphMLVertex(org.opennms.features.topology.plugins.topo.graphml.GraphMLVertex) GraphMLVertex(org.opennms.features.topology.plugins.topo.graphml.GraphMLVertex) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) SimpleBindings(javax.script.SimpleBindings) MeasurementsWrapper(org.opennms.features.topology.api.info.MeasurementsWrapper)

Aggregations

Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)2 Criteria (org.opennms.features.topology.api.topo.Criteria)2 Status (org.opennms.features.topology.api.topo.Status)2 StatusProvider (org.opennms.features.topology.api.topo.StatusProvider)2 VertexProvider (org.opennms.features.topology.api.topo.VertexProvider)2 VertexRef (org.opennms.features.topology.api.topo.VertexRef)2 GraphMLVertex (org.opennms.features.topology.plugins.topo.graphml.GraphMLVertex)2 AlarmSummaryWrapper (org.opennms.features.topology.plugins.topo.graphml.internal.AlarmSummaryWrapper)2 AlarmSummary (org.opennms.netmgt.model.alarm.AlarmSummary)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1