Search in sources :

Example 1 with TopologyServiceClient

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

the class BreadcrumbPathCalculatorTest method setUp.

@Before
public void setUp() {
    final GraphProvider layer1 = new SimpleGraphBuilder("layer1").vertex("A1").vertex("A2").get();
    final GraphProvider layer2 = new SimpleGraphBuilder("layer2").vertex("B1").vertex("B2").vertex("B3").vertex("B4").get();
    final GraphProvider layer3 = new SimpleGraphBuilder("layer3").vertex("C1").vertex("C2").vertex("C3").vertex("C4").vertex("C5").vertex("C6").edge("e1", "C1", "C4").edge("e2", "C1", "C5").edge("e3", "C4", "C5").get();
    final Map<VertexRef, List<VertexRef>> oppositesMap = Maps.newHashMap();
    oppositesMap.put(new DefaultVertexRef("layer1", "A1"), Lists.newArrayList(new DefaultVertexRef("layer2", "B3"), new DefaultVertexRef("layer2", "B4")));
    oppositesMap.put(new DefaultVertexRef("layer1", "A2"), Lists.newArrayList(new DefaultVertexRef("layer2", "B1"), new DefaultVertexRef("layer2", "B2")));
    oppositesMap.put(new DefaultVertexRef("layer2", "B1"), Lists.newArrayList(new DefaultVertexRef("layer3", "C2")));
    oppositesMap.put(new DefaultVertexRef("layer2", "B2"), Lists.newArrayList(new DefaultVertexRef("layer3", "C1")));
    oppositesMap.put(new DefaultVertexRef("layer2", "B3"), Lists.newArrayList(new DefaultVertexRef("layer3", "C3")));
    MetaTopologyProvider metaTopologyProvider = new MetaTopologyProvider() {

        @Override
        public GraphProvider getDefaultGraphProvider() {
            return layer1;
        }

        @Override
        public Collection<GraphProvider> getGraphProviders() {
            return Lists.newArrayList(layer1, layer2, layer3);
        }

        @Override
        public Collection<VertexRef> getOppositeVertices(VertexRef vertexRef) {
            return Optional.ofNullable(oppositesMap.get(vertexRef)).orElse(Lists.newArrayList());
        }

        @Override
        public GraphProvider getGraphProviderBy(String namespace) {
            return getGraphProviders().stream().filter(p -> p.getNamespace().equals(namespace)).findFirst().orElse(null);
        }

        @Override
        public BreadcrumbStrategy getBreadcrumbStrategy() {
            return BreadcrumbStrategy.NONE;
        }

        @Override
        public String getId() {
            return getGraphProviders().stream().map(g -> g.getNamespace()).collect(Collectors.joining(":"));
        }
    };
    DefaultTopologyService topologyService = new DefaultTopologyService();
    topologyService.setServiceLocator(new SimpleServiceLocator(metaTopologyProvider));
    DefaultTopologyServiceClient client = new DefaultTopologyServiceClient(topologyService);
    client.setMetaTopologyId(metaTopologyProvider.getId());
    client.setNamespace(metaTopologyProvider.getDefaultGraphProvider().getNamespace());
    topologyServiceClient = client;
}
Also used : DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) DefaultTopologyServiceClient(org.opennms.features.topology.app.internal.DefaultTopologyServiceClient) Collection(java.util.Collection) IOException(java.io.IOException) Test(org.junit.Test) DefaultTopologyService(org.opennms.features.topology.app.internal.service.DefaultTopologyService) Collectors(java.util.stream.Collectors) TopologyServiceClient(org.opennms.features.topology.api.TopologyServiceClient) Maps(com.google.common.collect.Maps) MetaTopologyProvider(org.opennms.features.topology.api.topo.MetaTopologyProvider) List(java.util.List) BreadcrumbStrategy(org.opennms.features.topology.api.support.breadcrumbs.BreadcrumbStrategy) Lists(com.google.common.collect.Lists) Map(java.util.Map) Optional(java.util.Optional) SimpleGraphBuilder(org.opennms.features.topology.api.support.SimpleGraphBuilder) Assert(org.junit.Assert) VertexRef(org.opennms.features.topology.api.topo.VertexRef) SimpleServiceLocator(org.opennms.features.topology.app.internal.service.SimpleServiceLocator) Before(org.junit.Before) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) MetaTopologyProvider(org.opennms.features.topology.api.topo.MetaTopologyProvider) SimpleGraphBuilder(org.opennms.features.topology.api.support.SimpleGraphBuilder) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) DefaultTopologyServiceClient(org.opennms.features.topology.app.internal.DefaultTopologyServiceClient) DefaultTopologyService(org.opennms.features.topology.app.internal.service.DefaultTopologyService) SimpleServiceLocator(org.opennms.features.topology.app.internal.service.SimpleServiceLocator) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) List(java.util.List) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Before(org.junit.Before)

Example 2 with TopologyServiceClient

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

Aggregations

Test (org.junit.Test)2 TopologyServiceClient (org.opennms.features.topology.api.TopologyServiceClient)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1 GraphContainer (org.opennms.features.topology.api.GraphContainer)1 SimpleGraphBuilder (org.opennms.features.topology.api.support.SimpleGraphBuilder)1 BreadcrumbStrategy (org.opennms.features.topology.api.support.breadcrumbs.BreadcrumbStrategy)1 AbstractSearchQuery (org.opennms.features.topology.api.topo.AbstractSearchQuery)1 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)1 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)1 GraphProvider (org.opennms.features.topology.api.topo.GraphProvider)1 MetaTopologyProvider (org.opennms.features.topology.api.topo.MetaTopologyProvider)1