Search in sources :

Example 1 with IpServiceEdge

use of org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge in project opennms by OpenNMS.

the class BusinessServiceGraphImpl method addBusinessServiceVertex.

private GraphVertex addBusinessServiceVertex(BusinessService businessService) {
    // Use an existing vertex if we already created one
    GraphVertex businessServiceVertex = m_verticesByBusinessServiceId.get(businessService.getId());
    if (businessServiceVertex != null) {
        return businessServiceVertex;
    }
    // Create
    businessServiceVertex = new GraphVertexImpl(businessService.getReduceFunction(), businessService);
    // Add
    addVertex(businessServiceVertex);
    // Index
    m_verticesByBusinessServiceId.put(businessService.getId(), businessServiceVertex);
    for (Edge edge : businessService.getEdges()) {
        // Create the edge
        GraphEdge graphEdge = new GraphEdgeImpl(edge);
        // Use an existing vertex if we already created one
        final GraphVertex[] vertexForEdge = { getExistingVertex(edge) };
        // If we couldn't find an existing vertex, create one
        if (vertexForEdge[0] == null) {
            edge.accept(new EdgeVisitor<Void>() {

                @Override
                public Void visit(ChildEdge edge) {
                    vertexForEdge[0] = addBusinessServiceVertex(edge.getChild());
                    return null;
                }

                @Override
                public Void visit(IpServiceEdge edge) {
                    // There are multiple reductions keys for this edge
                    // Create an intermediary vertex using the Most Critical reduction function
                    vertexForEdge[0] = new GraphVertexImpl(REDUCE_HIGHEST_SEVERITY, edge.getIpService());
                    addVertex(vertexForEdge[0]);
                    m_verticesByIpServiceId.put(vertexForEdge[0].getIpService().getId(), vertexForEdge[0]);
                    // SPECIAL CASE: Map the reductions keys to the intermediary vertex using the Identity map
                    for (String reductionKey : edge.getReductionKeys()) {
                        GraphVertex reductionKeyVertex = m_verticesByReductionKey.get(reductionKey);
                        if (reductionKeyVertex == null) {
                            // not already added
                            reductionKeyVertex = new GraphVertexImpl(REDUCE_HIGHEST_SEVERITY, reductionKey);
                            addVertex(reductionKeyVertex);
                            m_verticesByReductionKey.put(reductionKey, reductionKeyVertex);
                        }
                        // Always add an edge
                        GraphEdgeImpl intermediaryEdge = new GraphEdgeImpl(MAP_IDENTITY);
                        addEdge(intermediaryEdge, vertexForEdge[0], reductionKeyVertex);
                    }
                    return null;
                }

                @Override
                public Void visit(ReductionKeyEdge edge) {
                    String reductionKey = edge.getReductionKey();
                    vertexForEdge[0] = new GraphVertexImpl(REDUCE_HIGHEST_SEVERITY, edge.getReductionKey());
                    addVertex(vertexForEdge[0]);
                    m_verticesByReductionKey.put(reductionKey, vertexForEdge[0]);
                    return null;
                }
            });
        }
        // Link and index
        addEdge(graphEdge, businessServiceVertex, vertexForEdge[0]);
        m_verticesByEdgeId.put(edge.getId(), vertexForEdge[0]);
        m_edgesByEdgeId.put(edge.getId(), graphEdge);
    }
    return businessServiceVertex;
}
Also used : ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) Edge(org.opennms.netmgt.bsm.service.model.edge.Edge) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge)

Example 2 with IpServiceEdge

use of org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge in project opennms by OpenNMS.

the class BusinessServiceManagerImplIT method testGetOperationalStatusForBusinessService.

@Test
public void testGetOperationalStatusForBusinessService() {
    BusinessService bsService1 = createBusinessService("Dummy Business Service");
    BusinessService bsService2 = createBusinessService("Another Dummy Business Service");
    businessServiceStateMachine.setBusinessServices(Lists.newArrayList(bsService1, bsService2));
    final IpService ipServiceWithId5 = getIpService(5);
    final IpService ipServiceWithId6 = getIpService(6);
    // no ip services attached
    Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService1));
    Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService2));
    // ip services attached
    businessServiceManager.addIpServiceEdge(bsService1, ipServiceWithId5, new Identity(), Edge.DEFAULT_WEIGHT);
    businessServiceManager.addIpServiceEdge(bsService2, ipServiceWithId6, new Identity(), Edge.DEFAULT_WEIGHT);
    bsService1.save();
    bsService2.save();
    businessServiceDao.flush();
    Assert.assertFalse("Services are equal but should not", Objects.equals(bsService1, bsService2));
    businessServiceStateMachine.setBusinessServices(Lists.newArrayList(bsService1, bsService2));
    // should not have any effect
    Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService1));
    Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService2));
    // attach NORMAL alarm to service 1
    final IpServiceEdge ipServiceEdgeOnBsService1 = bsService1.getIpServiceEdges().iterator().next();
    businessServiceStateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(monitoredServiceDao.get(5), OnmsSeverity.NORMAL));
    Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(ipServiceEdgeOnBsService1));
    Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService1));
    Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService2));
    // attach INDETERMINATE alarm to service 1
    businessServiceStateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(monitoredServiceDao.get(5), OnmsSeverity.INDETERMINATE));
    Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(ipServiceEdgeOnBsService1));
    Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService1));
    Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService2));
    // attach WARNING alarm to service 1
    businessServiceStateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(monitoredServiceDao.get(5), OnmsSeverity.WARNING));
    Assert.assertEquals(Status.WARNING, businessServiceManager.getOperationalStatus(ipServiceEdgeOnBsService1));
    Assert.assertEquals(Status.WARNING, businessServiceManager.getOperationalStatus(bsService1));
    Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService2));
    // attach CRITICAL alarm to service 1
    businessServiceStateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(monitoredServiceDao.get(5), OnmsSeverity.CRITICAL));
    Assert.assertEquals(Status.CRITICAL, businessServiceManager.getOperationalStatus(ipServiceEdgeOnBsService1));
    Assert.assertEquals(Status.CRITICAL, businessServiceManager.getOperationalStatus(bsService1));
    Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService2));
}
Also used : BsmTestUtils.createDummyBusinessService(org.opennms.netmgt.bsm.test.BsmTestUtils.createDummyBusinessService) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) IpService(org.opennms.netmgt.bsm.service.model.IpService) Test(org.junit.Test)

Example 3 with IpServiceEdge

use of org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge in project opennms by OpenNMS.

the class BusinessServiceRestService method getById.

@GET
@Path("{id}")
public Response getById(@PathParam("id") Long id) {
    BusinessService service = getManager().getBusinessServiceById(id);
    final BusinessServiceResponseDTO response = new BusinessServiceResponseDTO();
    response.setId(service.getId());
    response.setName(service.getName());
    response.setAttributes(service.getAttributes());
    response.setLocation(ResourceLocationFactory.createBusinessServiceLocation(service.getId().toString()));
    response.setParentServices(service.getParentServices().stream().map(BusinessService::getId).collect(Collectors.toSet()));
    response.setOperationalStatus(service.getOperationalStatus());
    response.setReduceFunction(transform(service.getReduceFunction()));
    service.getEdges().forEach(eachEdge -> eachEdge.accept(new EdgeVisitor<Void>() {

        @Override
        public Void visit(IpServiceEdge edge) {
            response.getIpServices().add(transform(edge));
            return null;
        }

        @Override
        public Void visit(ReductionKeyEdge edge) {
            response.getReductionKeys().add(transform(edge));
            return null;
        }

        @Override
        public Void visit(ChildEdge edge) {
            response.getChildren().add(transform(edge));
            return null;
        }
    }));
    return Response.ok(response).build();
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) BusinessServiceResponseDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO) ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) EdgeVisitor(org.opennms.netmgt.bsm.service.model.edge.EdgeVisitor) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 4 with IpServiceEdge

use of org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge in project opennms by OpenNMS.

the class BusinessServiceManagerImpl method addIpServiceEdge.

@Override
public boolean addIpServiceEdge(BusinessService businessService, IpService ipService, MapFunction mapFunction, int weight, String friendlyName) {
    final BusinessServiceEntity parentEntity = getBusinessServiceEntity(businessService);
    // Create the edge
    final IpServiceEdge edge = createEdge(IpServiceEdge.class, businessService, mapFunction, weight);
    edge.setIpService(ipService);
    edge.setFriendlyName(friendlyName);
    // if already exists, no update
    final IPServiceEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(edge);
    long count = parentEntity.getIpServiceEdges().stream().filter(e -> e.equalsDefinition(edgeEntity)).count();
    if (count > 0) {
        return false;
    }
    parentEntity.addEdge(((IpServiceEdgeImpl) edge).getEntity());
    return true;
}
Also used : ReductionKeyEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.ReductionKeyEdgeImpl) IpService(org.opennms.netmgt.bsm.service.model.IpService) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) ReductionFunctionDao(org.opennms.netmgt.bsm.persistence.api.functions.reduce.ReductionFunctionDao) ChildEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.ChildEdgeImpl) BusinessServiceDao(org.opennms.netmgt.bsm.persistence.api.BusinessServiceDao) BusinessServiceManager(org.opennms.netmgt.bsm.service.BusinessServiceManager) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractReductionFunctionEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.AbstractReductionFunctionEntity) EventConstants(org.opennms.netmgt.events.api.EventConstants) MapFunction(org.opennms.netmgt.bsm.service.model.functions.map.MapFunction) BusinessServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) MonitoredServiceDao(org.opennms.netmgt.dao.api.MonitoredServiceDao) IpServiceEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.IpServiceEdgeImpl) BusinessServiceSearchCriteria(org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteria) AbstractEdge(org.opennms.netmgt.bsm.service.internal.edge.AbstractEdge) ReductionFunction(org.opennms.netmgt.bsm.service.model.functions.reduce.ReductionFunction) Status(org.opennms.netmgt.bsm.service.model.Status) BusinessServiceChildEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity) EdgeEntityVisitor(org.opennms.netmgt.bsm.persistence.api.EdgeEntityVisitor) NoSuchElementException(java.util.NoSuchElementException) ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) OnmsNode(org.opennms.netmgt.model.OnmsNode) NodeDao(org.opennms.netmgt.dao.api.NodeDao) AbstractMapFunctionEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.AbstractMapFunctionEntity) BusinessServiceEdgeDao(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeDao) Set(java.util.Set) BusinessServiceGraphImpl(org.opennms.netmgt.bsm.service.model.graph.internal.BusinessServiceGraphImpl) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) SingleReductionKeyEdgeEntity(org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity) Collectors(java.util.stream.Collectors) Criteria(org.opennms.core.criteria.Criteria) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) Objects(java.util.Objects) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) List(java.util.List) Node(org.opennms.netmgt.bsm.service.model.Node) Edge(org.opennms.netmgt.bsm.service.model.edge.Edge) MapFunctionDao(org.opennms.netmgt.bsm.persistence.api.functions.map.MapFunctionDao) EventForwarder(org.opennms.netmgt.events.api.EventForwarder) IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge)

Example 5 with IpServiceEdge

use of org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge in project opennms by OpenNMS.

the class BusinessServiceVertexStatusInfoPanelItemProvider method createComponent.

private Component createComponent(BusinessServiceVertex vertex, GraphContainer container) {
    final FormLayout rootLayout = new FormLayout();
    rootLayout.setSizeFull();
    rootLayout.setSpacing(false);
    rootLayout.setMargin(false);
    rootLayout.addStyleName("severity");
    final BusinessServiceStateMachine stateMachine = SimulationAwareStateMachineFactory.createStateMachine(businessServiceManager, container.getCriteria());
    final Status overallStatus = BusinessServicesStatusProvider.getStatus(stateMachine, vertex);
    rootLayout.addComponent(createStatusLabel("Overall", overallStatus));
    rootLayout.addComponent(new Label());
    final BusinessServiceGraph graph = stateMachine.getGraph();
    final BusinessService businessService = businessServiceManager.getBusinessServiceById(vertex.getServiceId());
    final Set<GraphVertex> impactingVertices = getImpactingVertices(stateMachine, graph, businessService);
    for (final Edge edge : businessService.getEdges()) {
        // Get the topology vertex for the child to determine the display label
        final Vertex childVertex = businessServicesTopologyProvider.getVertex(edge.accept(new EdgeVisitor<VertexRef>() {

            @Override
            public VertexRef visit(final IpServiceEdge edge) {
                return new IpServiceVertex(edge.getIpService(), 0);
            }

            @Override
            public VertexRef visit(final ReductionKeyEdge edge) {
                return new ReductionKeyVertex(edge.getReductionKey(), 0);
            }

            @Override
            public VertexRef visit(final ChildEdge edge) {
                return new BusinessServiceVertex(edge.getChild(), 0);
            }
        }));
        final Status edgeStatus = stateMachine.getOperationalStatus(edge);
        rootLayout.addComponent(createStatusLabel(childVertex.getLabel(), edgeStatus, String.format("%s &times; %d <i class=\"pull-right glyphicon %s\"></i>", edgeStatus.getLabel(), edge.getWeight(), impactingVertices.contains(graph.getVertexByEdgeId(edge.getId())) ? "glyphicon-flash" : "")));
    }
    return rootLayout;
}
Also used : FormLayout(com.vaadin.ui.FormLayout) Status(org.opennms.netmgt.bsm.service.model.Status) Vertex(org.opennms.features.topology.api.topo.Vertex) IpServiceVertex(org.opennms.features.topology.plugins.topo.bsm.IpServiceVertex) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) BusinessServiceVertex(org.opennms.features.topology.plugins.topo.bsm.BusinessServiceVertex) ReductionKeyVertex(org.opennms.features.topology.plugins.topo.bsm.ReductionKeyVertex) ReductionKeyVertex(org.opennms.features.topology.plugins.topo.bsm.ReductionKeyVertex) ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) Label(com.vaadin.ui.Label) UIHelper.createLabel(org.opennms.netmgt.vaadin.core.UIHelper.createLabel) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) EdgeVisitor(org.opennms.netmgt.bsm.service.model.edge.EdgeVisitor) IpServiceVertex(org.opennms.features.topology.plugins.topo.bsm.IpServiceVertex) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) Edge(org.opennms.netmgt.bsm.service.model.edge.Edge) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) BusinessServiceVertex(org.opennms.features.topology.plugins.topo.bsm.BusinessServiceVertex)

Aggregations

IpServiceEdge (org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge)7 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)6 ChildEdge (org.opennms.netmgt.bsm.service.model.edge.ChildEdge)4 ReductionKeyEdge (org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge)4 Test (org.junit.Test)3 Edge (org.opennms.netmgt.bsm.service.model.edge.Edge)3 BusinessServiceStateMachine (org.opennms.netmgt.bsm.service.BusinessServiceStateMachine)2 Status (org.opennms.netmgt.bsm.service.model.Status)2 EdgeVisitor (org.opennms.netmgt.bsm.service.model.edge.EdgeVisitor)2 BusinessServiceGraph (org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)2 LoggingStateChangeHandler (org.opennms.netmgt.bsm.test.LoggingStateChangeHandler)2 FormLayout (com.vaadin.ui.FormLayout)1 Label (com.vaadin.ui.Label)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1