Search in sources :

Example 6 with AbstractVertex

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

the class BusinessServiceSearchProviderIT method verifyQuery.

@Test
public void verifyQuery() {
    BusinessServiceEntity bs1 = new BusinessServiceEntityBuilder().name("Test Service").reduceFunction(new HighestSeverityEntity()).addReductionKey("bs1.key1", new IdentityEntity(), 1).addReductionKey("bs1.key2", new IdentityEntity(), 1).toEntity();
    BusinessServiceEntity bs2 = new BusinessServiceEntityBuilder().name("Real Service 2").reduceFunction(new HighestSeverityEntity()).addReductionKey("bs2.key1", new IdentityEntity(), 1).addReductionKey("bs2.key2", new IdentityEntity(), 1).toEntity();
    businessServiceDao.save(bs1);
    businessServiceDao.save(bs2);
    businessServiceDao.flush();
    // prepare mocks
    TopologyServiceClient topologyServiceClientMock = EasyMock.createNiceMock(TopologyServiceClient.class);
    EasyMock.expect(topologyServiceClientMock.getVertex(EasyMock.anyObject(BusinessServiceVertex.class))).andReturn(// always return a vertex, it just needs to be not null
    new AbstractVertex("bsm", "0", "Dummy Vertex"));
    GraphContainer graphContainerMock = EasyMock.createNiceMock(GraphContainer.class);
    EasyMock.expect(graphContainerMock.getTopologyServiceClient()).andReturn(topologyServiceClientMock).anyTimes();
    EasyMock.replay(graphContainerMock, topologyServiceClientMock);
    // try searching
    final BusinessServiceSearchProvider provider = new BusinessServiceSearchProvider();
    provider.setBusinessServiceManager(businessServiceManager);
    final SearchQuery query = new AbstractSearchQuery("Test") {

        @Override
        public boolean matches(String label) {
            // always match, it does not matter
            return true;
        }
    };
    final List<SearchResult> result = provider.query(query, graphContainerMock);
    Assert.assertEquals(1, result.size());
    EasyMock.verify(graphContainerMock, topologyServiceClientMock);
}
Also used : SearchQuery(org.opennms.features.topology.api.topo.SearchQuery) AbstractSearchQuery(org.opennms.features.topology.api.topo.AbstractSearchQuery) SearchResult(org.opennms.features.topology.api.topo.SearchResult) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) GraphContainer(org.opennms.features.topology.api.GraphContainer) TopologyServiceClient(org.opennms.features.topology.api.TopologyServiceClient) AbstractSearchQuery(org.opennms.features.topology.api.topo.AbstractSearchQuery) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test)

Example 7 with AbstractVertex

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

the class AbstractLinkdTopologyProvider method getVertex.

protected AbstractVertex getVertex(Integer nodeId, String ip, String sysobjectId, String nodeLabel, String tooltipText) {
    AbstractVertex vertex = new SimpleLeafVertex(TOPOLOGY_NAMESPACE_LINKD, nodeId.toString(), 0, 0);
    vertex.setIconKey(getIconName(sysobjectId));
    vertex.setLabel(nodeLabel);
    vertex.setIpAddress(ip);
    vertex.setNodeID(nodeId);
    vertex.setTooltipText(tooltipText);
    return vertex;
}
Also used : AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) SimpleLeafVertex(org.opennms.features.topology.api.topo.SimpleLeafVertex)

Example 8 with AbstractVertex

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

the class AlarmStatusProviderTest method createVertex.

private static Vertex createVertex(int nodeId) {
    AbstractVertex v = new AbstractVertex("nodes", Integer.toString(nodeId), Integer.toString(nodeId));
    v.setNodeID(nodeId);
    return v;
}
Also used : AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex)

Example 9 with AbstractVertex

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

the class IconSelectionOperation method execute.

@Override
public void execute(List<VertexRef> targets, OperationContext operationContext) {
    final AbstractVertex vertex = (AbstractVertex) targets.get(0);
    final String preSelectedIconId = operationContext.getGraphContainer().getIconManager().getSVGIconId(vertex);
    new IconSelectionDialog(preSelectedIconId).withOkAction(iconWindow -> {
        final IconManager iconManager = operationContext.getGraphContainer().getIconManager();
        final String newIconId = iconWindow.getSelectedIcon();
        String newIconKey = iconManager.setIconMapping(vertex, newIconId);
        if (newIconKey != null) {
            vertex.setIconKey(newIconKey);
            operationContext.getGraphContainer().setDirty(true);
            operationContext.getGraphContainer().redoLayout();
        }
    }).open();
}
Also used : AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) List(java.util.List) IconSelectionDialog(org.opennms.features.topology.app.internal.ui.icons.IconSelectionDialog) Operation(org.opennms.features.topology.api.Operation) OperationContext(org.opennms.features.topology.api.OperationContext) IconManager(org.opennms.features.topology.api.IconManager) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) VertexRef(org.opennms.features.topology.api.topo.VertexRef) IconSelectionDialog(org.opennms.features.topology.app.internal.ui.icons.IconSelectionDialog) IconManager(org.opennms.features.topology.api.IconManager)

Example 10 with AbstractVertex

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

the class EnhancedLinkdTopologyProvider method getBridgeLinks.

private void getBridgeLinks(Map<Integer, OnmsNode> nodemap, Map<Integer, List<OnmsSnmpInterface>> nodesnmpmap, Map<String, List<OnmsIpInterface>> macToIpMap, Map<Integer, List<OnmsIpInterface>> ipmap, Map<Integer, OnmsIpInterface> ipprimarymap) {
    for (BroadcastDomain domain : m_bridgeTopologyDao.getAllPersisted(m_bridgeBridgeLinkDao, m_bridgeMacLinkDao)) {
        LOG.info("loadtopology: parsing broadcast Domain: '{}', {}", domain);
        for (SharedSegment segment : domain.getTopology()) {
            if (segment.noMacsOnSegment() && segment.getBridgeBridgeLinks().size() == 1) {
                for (BridgeBridgeLink link : segment.getBridgeBridgeLinks()) {
                    Vertex source = getOrCreateVertex(nodemap.get(link.getNode().getId()), ipprimarymap.get(link.getNode().getId()));
                    Vertex target = getOrCreateVertex(nodemap.get(link.getDesignatedNode().getId()), ipprimarymap.get(link.getDesignatedNode().getId()));
                    BridgeLinkDetail detail = new BridgeLinkDetail(EnhancedLinkdTopologyProvider.TOPOLOGY_NAMESPACE_LINKD, source, link.getBridgePortIfIndex(), target, link.getDesignatedPortIfIndex(), link.getBridgePort(), link.getDesignatedPort(), link.getId(), link.getId());
                    LinkdEdge edge = connectVertices(detail, BRIDGE_EDGE_NAMESPACE);
                    edge.setTooltipText(getEdgeTooltipText(detail, nodesnmpmap));
                }
                continue;
            }
            if (segment.getBridgeMacLinks().size() == 1 && segment.getBridgeBridgeLinks().size() == 0) {
                for (BridgeMacLink sourcelink : segment.getBridgeMacLinks()) {
                    if (macToIpMap.containsKey(sourcelink.getMacAddress()) && macToIpMap.get(sourcelink.getMacAddress()).size() > 0) {
                        List<OnmsIpInterface> targetInterfaces = macToIpMap.get(sourcelink.getMacAddress());
                        OnmsIpInterface targetIp = targetInterfaces.get(0);
                        if (segment.getBridgeIdsOnSegment().contains(targetIp.getNode().getId()))
                            continue;
                        Vertex source = getOrCreateVertex(nodemap.get(sourcelink.getNode().getId()), ipprimarymap.get(sourcelink.getNode().getId()));
                        Vertex target = getOrCreateVertex(nodemap.get(targetIp.getNode().getId()), ipprimarymap.get(targetIp.getNode().getId()));
                        LinkdEdge edge = connectVertices(sourcelink, source, target, BRIDGE_EDGE_NAMESPACE);
                        edge.setTooltipText(getEdgeTooltipText(sourcelink, source, target, targetInterfaces, nodesnmpmap));
                    }
                }
                continue;
            }
            String cloudId = segment.getDesignatedBridge() + ":" + segment.getDesignatedPort();
            AbstractVertex cloudVertex = addVertex(cloudId, 0, 0);
            cloudVertex.setLabel("");
            cloudVertex.setIconKey("cloud");
            cloudVertex.setTooltipText("Shared Segment: " + nodemap.get(segment.getDesignatedBridge()).getLabel() + " port: " + segment.getDesignatedPort());
            addVertices(cloudVertex);
            LOG.info("loadtopology: adding cloud: id: '{}', {}", cloudId, cloudVertex.getTooltipText());
            for (BridgePort targetport : segment.getBridgePortsOnSegment()) {
                Vertex target = getOrCreateVertex(nodemap.get(targetport.getNode().getId()), ipprimarymap.get(targetport.getNode().getId()));
                LinkdEdge edge = connectVertices(targetport, cloudVertex, target, BRIDGE_EDGE_NAMESPACE);
                edge.setTooltipText(getEdgeTooltipText(targetport, target, nodesnmpmap));
            }
            for (String targetmac : segment.getMacsOnSegment()) {
                if (macToIpMap.containsKey(targetmac) && macToIpMap.get(targetmac).size() > 0) {
                    List<OnmsIpInterface> targetInterfaces = macToIpMap.get(targetmac);
                    OnmsIpInterface targetIp = targetInterfaces.get(0);
                    if (segment.getBridgeIdsOnSegment().contains(targetIp.getNode().getId()))
                        continue;
                    Vertex target = getOrCreateVertex(nodemap.get(targetIp.getNode().getId()), ipprimarymap.get(targetIp.getNode().getId()));
                    LinkdEdge edge = connectCloudMacVertices(targetmac, cloudVertex, target, BRIDGE_EDGE_NAMESPACE);
                    edge.setTooltipText(getEdgeTooltipText(targetmac, target, targetInterfaces));
                }
            }
        }
    }
}
Also used : AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) Vertex(org.opennms.features.topology.api.topo.Vertex) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) BridgePort(org.opennms.netmgt.model.topology.BridgePort) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) BroadcastDomain(org.opennms.netmgt.model.topology.BroadcastDomain) BridgeBridgeLink(org.opennms.netmgt.model.BridgeBridgeLink) SharedSegment(org.opennms.netmgt.model.topology.SharedSegment) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink)

Aggregations

AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)18 VertexRef (org.opennms.features.topology.api.topo.VertexRef)7 List (java.util.List)5 Map (java.util.Map)4 Objects (java.util.Objects)4 Function (java.util.function.Function)4 Collectors (java.util.stream.Collectors)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 Test (org.junit.Test)3 Vertex (org.opennms.features.topology.api.topo.Vertex)3 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Sets (com.google.common.collect.Sets)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 URLDecoder (java.net.URLDecoder)2 StandardCharsets (java.nio.charset.StandardCharsets)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Set (java.util.Set)2