Search in sources :

Example 51 with VertexRef

use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.

the class NodeMapQueryLink method execute.

@Override
public void execute(final List<VertexRef> targets, final OperationContext operationContext) {
    final Collection<VertexRef> availableNodes = m_geoAssetProvider.getNodesWithCoordinates();
    final StringBuilder sb = new StringBuilder();
    sb.append(VaadinServlet.getCurrent().getServletContext().getContextPath());
    sb.append("/node-maps#search/nodeId%20in%20");
    final List<String> nodeIds = new ArrayList<>();
    for (final VertexRef ref : targets) {
        if (availableNodes.contains(ref)) {
            nodeIds.add(ref.getId());
        }
    }
    final Iterator<String> i = nodeIds.iterator();
    while (i.hasNext()) {
        sb.append(i.next());
        if (i.hasNext()) {
            sb.append(",");
        }
    }
    final String redirectUrl = sb.toString();
    LOG.info("redirecting to: " + redirectUrl);
    final UI ui = operationContext.getMainWindow();
    ui.getPage().getJavaScript().execute("window.location = '" + redirectUrl + "';");
}
Also used : UI(com.vaadin.ui.UI) ArrayList(java.util.ArrayList) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 52 with VertexRef

use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.

the class NodeMapsApplication method init.

@Override
protected void init(final VaadinRequest vaadinRequest) {
    m_request = vaadinRequest;
    LOG.debug("initializing");
    final VaadinApplicationContextImpl context = new VaadinApplicationContextImpl();
    final UI currentUI = UI.getCurrent();
    context.setSessionId(currentUI.getSession().getSession().getId());
    context.setUiId(currentUI.getUIId());
    context.setUsername(vaadinRequest.getRemoteUser());
    Assert.notNull(m_alarmTable);
    Assert.notNull(m_nodeTable);
    final String searchString = vaadinRequest.getParameter("search");
    final Integer maxClusterRadius = Integer.getInteger("gwt.maxClusterRadius", 350);
    LOG.info("Starting search string: {}, max cluster radius: {}", searchString, maxClusterRadius);
    m_alarmTable.setVaadinApplicationContext(context);
    final EventProxy eventProxy = new EventProxy() {

        @Override
        public <T> void fireEvent(final T eventObject) {
            LOG.debug("got event: {}", eventObject);
            if (eventObject instanceof VerticesUpdateEvent) {
                final VerticesUpdateEvent event = (VerticesUpdateEvent) eventObject;
                final List<Integer> nodeIds = new ArrayList<>();
                for (final VertexRef ref : event.getVertexRefs()) {
                    if ("nodes".equals(ref.getNamespace()) && ref.getId() != null) {
                        nodeIds.add(Integer.valueOf(ref.getId()));
                    }
                }
                m_nodeMapComponent.setSelectedNodes(nodeIds);
                return;
            }
            LOG.warn("Unsure how to deal with event: {}", eventObject);
        }

        @Override
        public <T> void addPossibleEventConsumer(final T possibleEventConsumer) {
            LOG.debug("(ignoring) add consumer: {}", possibleEventConsumer);
        /* throw new UnsupportedOperationException("Not yet implemented!"); */
        }
    };
    m_alarmTable.setEventProxy(eventProxy);
    m_nodeTable.setEventProxy(eventProxy);
    createMapPanel(searchString, maxClusterRadius);
    createRootLayout();
    addRefresher();
    // Notify the user if no tileserver url or options are set
    if (!configuration.isValid()) {
        new InvalidConfigurationWindow(configuration).open();
    }
}
Also used : VerticesUpdateEvent(org.opennms.features.topology.api.VerticesUpdateManager.VerticesUpdateEvent) VaadinApplicationContextImpl(org.opennms.osgi.VaadinApplicationContextImpl) UI(com.vaadin.ui.UI) ArrayList(java.util.ArrayList) VertexRef(org.opennms.features.topology.api.topo.VertexRef) EventProxy(org.opennms.osgi.EventProxy)

Example 53 with VertexRef

use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.

the class GraphMLMetaTopologyProvider method reload.

public void reload() throws IOException, InvalidGraphException {
    graphsByNamespace.clear();
    oppositeVertices.clear();
    rawGraphsByNamespace.clear();
    if (graphMLFile == null) {
        LOG.warn("No graph defined");
        return;
    }
    if (!graphMLFile.exists()) {
        LOG.warn("No graph found at location " + graphMLFile.toString());
        return;
    }
    try (InputStream input = new FileInputStream(graphMLFile)) {
        final GraphML graphML = GraphMLReader.read(input);
        validate(graphML);
        for (GraphMLGraph eachGraph : graphML.getGraphs()) {
            final GraphMLTopologyProvider topoProvider = new GraphMLTopologyProvider(this, eachGraph, m_serviceAccessor);
            final VertexHopGraphProvider vertexHopGraphProvider = new VertexHopGraphProvider(topoProvider);
            graphsByNamespace.put(topoProvider.getNamespace(), vertexHopGraphProvider);
            rawGraphsByNamespace.put(topoProvider.getNamespace(), topoProvider);
        }
        for (GraphMLGraph eachGraph : graphML.getGraphs()) {
            for (org.opennms.features.graphml.model.GraphMLEdge eachEdge : eachGraph.getEdges()) {
                final VertexRef sourceVertex = getVertex(eachEdge.getSource());
                final VertexRef targetVertex = getVertex(eachEdge.getTarget());
                if (!sourceVertex.getNamespace().equals(targetVertex.getNamespace())) {
                    List<VertexRef> opposites = oppositeVertices.get(sourceVertex);
                    if (opposites == null) {
                        opposites = Lists.newArrayList();
                        oppositeVertices.put(sourceVertex, opposites);
                    }
                    opposites.add(targetVertex);
                }
            }
        }
        this.breadcrumbStrategy = getBreadcrumbStrategy(graphML);
    }
}
Also used : GraphML(org.opennms.features.graphml.model.GraphML) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) GraphMLGraph(org.opennms.features.graphml.model.GraphMLGraph) VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider) VertexRef(org.opennms.features.topology.api.topo.VertexRef) GraphMLEdge(org.opennms.features.graphml.model.GraphMLEdge) FileInputStream(java.io.FileInputStream)

Example 54 with VertexRef

use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.

the class GraphMLPropagateVertexStatusProvider method getStatusForVertices.

@Override
public Map<? extends VertexRef, ? extends Status> getStatusForVertices(final VertexProvider vertexProvider, final Collection<VertexRef> vertices, final Criteria[] criteria) {
    final List<Criteria> criteriaList = Lists.newArrayList(criteria);
    final LoopDetectionCriteria loopDetectionCriteria = Iterables.tryFind(criteriaList, c -> c instanceof LoopDetectionCriteria).transform(c -> (LoopDetectionCriteria) c).or(LoopDetectionCriteria::new);
    // Build map from namespace to opposite vertices
    final Multimap<String, VertexRef> oppositeVertices = HashMultimap.create();
    for (final VertexRef sourceVertex : vertices) {
        // Filter out loops
        if (loopDetectionCriteria.contains(sourceVertex)) {
            LOG.error("Loop detected with: {}:{}", sourceVertex.getNamespace(), sourceVertex.getId());
            continue;
        }
        for (VertexRef targetVertex : this.provider.getOppositeVertices(sourceVertex)) {
            oppositeVertices.put(targetVertex.getNamespace(), targetVertex);
        }
    }
    // Replace loop detection criteria with extended one
    criteriaList.remove(loopDetectionCriteria);
    criteriaList.add(loopDetectionCriteria.with(vertices));
    // Find and call status provider for each namespace and get result per opposite vertex
    final Map<VertexRef, Status> targetStatuses = Maps.newHashMap();
    try {
        final Collection<ServiceReference<StatusProvider>> statusProviderReferences = this.bundleContext.getServiceReferences(StatusProvider.class, null);
        for (final ServiceReference<StatusProvider> statusProviderReference : statusProviderReferences) {
            try {
                final StatusProvider statusProvider = bundleContext.getService(statusProviderReference);
                for (final Map.Entry<String, Collection<VertexRef>> e : oppositeVertices.asMap().entrySet()) {
                    if (statusProvider.contributesTo(e.getKey())) {
                        targetStatuses.putAll(statusProvider.getStatusForVertices(this.provider.getGraphProviderBy(e.getKey()), e.getValue(), criteriaList.toArray(new Criteria[0])));
                    }
                }
            } finally {
                bundleContext.ungetService(statusProviderReference);
            }
        }
    } catch (final InvalidSyntaxException e) {
    }
    // Merge statuses from targets to sources
    final Map<VertexRef, GraphMLVertexStatus> statuses = Maps.newHashMap();
    for (final VertexRef sourceVertex : vertices) {
        GraphMLVertexStatus mergedStatus = new GraphMLVertexStatus();
        for (VertexRef targetVertex : this.provider.getOppositeVertices(sourceVertex)) {
            if (targetStatuses.containsKey(targetVertex)) {
                mergedStatus = GraphMLVertexStatus.merge(mergedStatus, (GraphMLVertexStatus) targetStatuses.get(targetVertex));
            }
        }
        statuses.put(sourceVertex, mergedStatus);
    }
    return statuses;
}
Also used : Iterables(com.google.common.collect.Iterables) Logger(org.slf4j.Logger) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Multimap(com.google.common.collect.Multimap) Maps(com.google.common.collect.Maps) BundleContext(org.osgi.framework.BundleContext) HashSet(java.util.HashSet) Objects(java.util.Objects) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) List(java.util.List) HashMultimap(com.google.common.collect.HashMultimap) Lists(com.google.common.collect.Lists) VertexProvider(org.opennms.features.topology.api.topo.VertexProvider) Criteria(org.opennms.features.topology.api.topo.Criteria) Map(java.util.Map) GraphMLMetaTopologyProvider(org.opennms.features.topology.plugins.topo.graphml.GraphMLMetaTopologyProvider) Status(org.opennms.features.topology.api.topo.Status) VertexRef(org.opennms.features.topology.api.topo.VertexRef) ServiceReference(org.osgi.framework.ServiceReference) Status(org.opennms.features.topology.api.topo.Status) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) Criteria(org.opennms.features.topology.api.topo.Criteria) ServiceReference(org.osgi.framework.ServiceReference) Collection(java.util.Collection) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Map(java.util.Map)

Example 55 with VertexRef

use of org.opennms.features.topology.api.topo.VertexRef 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

VertexRef (org.opennms.features.topology.api.topo.VertexRef)105 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)33 Vertex (org.opennms.features.topology.api.topo.Vertex)31 Point (org.opennms.features.topology.api.Point)23 Criteria (org.opennms.features.topology.api.topo.Criteria)22 Edge (org.opennms.features.topology.api.topo.Edge)22 Test (org.junit.Test)21 List (java.util.List)20 ArrayList (java.util.ArrayList)19 Collectors (java.util.stream.Collectors)18 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)18 Map (java.util.Map)17 Status (org.opennms.features.topology.api.topo.Status)15 Collection (java.util.Collection)13 HashSet (java.util.HashSet)13 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)12 HashMap (java.util.HashMap)12 Layout (org.opennms.features.topology.api.Layout)12 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)12 Lists (com.google.common.collect.Lists)11