Search in sources :

Example 41 with VertexRef

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

the class CategoryHopCriteria method getVertices.

@Override
public Set<VertexRef> getVertices() {
    OnmsCategory category = categoryProvider.findCategoryByName(m_categoryName);
    if (category == null) {
        return Collections.emptySet();
    } else {
        List<OnmsNode> nodes = categoryProvider.findNodesForCategory(category);
        List<Integer> nodeIds = nodes.stream().map(n -> n.getId()).collect(Collectors.toList());
        GraphProvider graphProvider = graphContainer.getTopologyServiceClient().getGraphProviderBy(graphContainer.getTopologyServiceClient().getNamespace());
        return graphProvider.getVertices(new IgnoreHopCriteria()).stream().filter(v -> v.getNodeID() != null).filter(v -> nodeIds.contains(v.getNodeID())).collect(Collectors.toSet());
    }
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) Constants(org.opennms.features.topology.api.Constants) SearchResult(org.opennms.features.topology.api.topo.SearchResult) Vertex(org.opennms.features.topology.api.topo.Vertex) Set(java.util.Set) CategoryProvider(org.opennms.features.topology.app.internal.CategoryProvider) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) Objects(java.util.Objects) GroupRef(org.opennms.features.topology.api.topo.GroupRef) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) List(java.util.List) IgnoreHopCriteria(org.opennms.features.topology.api.support.IgnoreHopCriteria) SearchCriteria(org.opennms.features.topology.api.topo.SearchCriteria) VertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.VertexHopCriteria) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Collections(java.util.Collections) OnmsNode(org.opennms.netmgt.model.OnmsNode) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) IgnoreHopCriteria(org.opennms.features.topology.api.support.IgnoreHopCriteria) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider)

Example 42 with VertexRef

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

the class IpLikeHopCriteria method getVertices.

@Override
public Set<VertexRef> getVertices() {
    CriteriaBuilder bldr = new CriteriaBuilder(OnmsIpInterface.class);
    bldr.iplike("ipAddr", m_ipQuery);
    List<OnmsIpInterface> ips = ipInterfaceProvider.findMatching(bldr.toCriteria());
    Set<VertexRef> vertices = new TreeSet<VertexRef>(new RefComparator());
    for (OnmsIpInterface ip : ips) {
        OnmsNode node = ip.getNode();
        vertices.add(new DefaultVertexRef("nodes", String.valueOf(node.getId()), node.getLabel()));
    }
    return vertices;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) TreeSet(java.util.TreeSet) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) RefComparator(org.opennms.features.topology.api.topo.RefComparator)

Example 43 with VertexRef

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

the class LayoutManager method isPersistedLayoutEqualToCurrentLayout.

public boolean isPersistedLayoutEqualToCurrentLayout(Graph graph) {
    LayoutEntity layoutEntity = loadLayout(graph);
    if (layoutEntity != null) {
        // If we have a layout persisted, we verify if it is equal.
        final Map<VertexRef, Point> persistedLocations = layoutEntity.getVertexPositions().stream().collect(Collectors.toMap((Function<VertexPositionEntity, VertexRef>) vertexPositionEntity -> {
            VertexRefEntity vertexRefEntity = vertexPositionEntity.getVertexRef();
            return new DefaultVertexRef(vertexRefEntity.getNamespace(), vertexRefEntity.getId());
        }, vertexPositionEntity -> {
            PointEntity position = vertexPositionEntity.getPosition();
            return new Point(position.getX(), position.getY());
        }));
        // The locations may contain elements currently not visible, we filter them
        final Map<VertexRef, Point> manualLocations = new HashMap<>();
        graph.getLayout().getLocations().forEach((key, value) -> {
            if (persistedLocations.containsKey(key)) {
                // layoutEntity stores int coordinates, but manualLocations are stored as double.
                // Convert to int to make it comparable.
                manualLocations.put(key, new Point((int) value.getX(), (int) value.getY()));
            }
        });
        final boolean layoutIsEqual = manualLocations.equals(persistedLocations);
        return layoutIsEqual;
    }
    // We don't have anything persisted, so they are not equal
    return false;
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) Date(java.util.Date) Vertex(org.opennms.features.topology.api.topo.Vertex) HashMap(java.util.HashMap) Hashing(com.google.common.hash.Hashing) Function(java.util.function.Function) VertexPositionEntity(org.opennms.netmgt.topology.persistence.api.VertexPositionEntity) Point(org.opennms.features.topology.api.Point) Layout(org.opennms.features.topology.api.Layout) Map(java.util.Map) LayoutDao(org.opennms.netmgt.topology.persistence.api.LayoutDao) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) Collection(java.util.Collection) Graph(org.opennms.features.topology.api.Graph) Collectors(java.util.stream.Collectors) PointEntity(org.opennms.netmgt.topology.persistence.api.PointEntity) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) TransactionAwareBeanProxyFactory(org.opennms.netmgt.vaadin.core.TransactionAwareBeanProxyFactory) List(java.util.List) VertexRefEntity(org.opennms.netmgt.topology.persistence.api.VertexRefEntity) TransactionOperations(org.springframework.transaction.support.TransactionOperations) LayoutEntity(org.opennms.netmgt.topology.persistence.api.LayoutEntity) Comparator(java.util.Comparator) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Function(java.util.function.Function) VertexRefEntity(org.opennms.netmgt.topology.persistence.api.VertexRefEntity) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) HashMap(java.util.HashMap) LayoutEntity(org.opennms.netmgt.topology.persistence.api.LayoutEntity) Point(org.opennms.features.topology.api.Point) PointEntity(org.opennms.netmgt.topology.persistence.api.PointEntity) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 44 with VertexRef

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

the class BreadcrumbComponent method createButton.

private static Button createButton(GraphContainer container, Breadcrumb breadcrumb) {
    final Button button = new Button();
    final String layerName = getLayerName(container, breadcrumb.getTargetNamespace());
    if (breadcrumb.getSourceVertices().isEmpty()) {
        button.setCaption(layerName);
    } else {
        String sourceLayerName = getLayerName(container, breadcrumb.getSourceVertices().get(0).getNamespace());
        if (breadcrumb.getSourceVertices().size() > 2) {
            button.setCaption("Multiple " + layerName);
            button.setDescription(String.format("Multiple vertices from %s", sourceLayerName));
        } else {
            button.setCaption(breadcrumb.getSourceVertices().stream().map(VertexRef::getLabel).collect(Collectors.joining(", ")));
            button.setDescription(String.format("%s from %s", button.getCaption(), sourceLayerName));
        }
    }
    button.addStyleName(BaseTheme.BUTTON_LINK);
    button.addClickListener((event) -> breadcrumb.clicked(container));
    return button;
}
Also used : Button(com.vaadin.ui.Button) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 45 with VertexRef

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

the class OSGiVerticesUpdateManagerTest method createVertexRefsWithIds.

private List<VertexRef> createVertexRefsWithIds(int... vertIds) {
    List<VertexRef> vertices = new ArrayList<>();
    for (int i = 0; i < vertIds.length; i++) {
        VertexRef vRef = new DefaultVertexRef("nodes", "" + vertIds[i], "");
        vertices.add(vRef);
    }
    return vertices;
}
Also used : DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) ArrayList(java.util.ArrayList) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

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