Search in sources :

Example 11 with AlarmSummary

use of org.opennms.netmgt.model.alarm.AlarmSummary 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

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