Search in sources :

Example 1 with IpService

use of org.opennms.netmgt.bsm.service.model.IpService 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 2 with IpService

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

the class DefaultBusinessServiceStateMachine method renderGraphToPng.

@Override
public void renderGraphToPng(File tempFile) {
    m_rwLock.readLock().lock();
    try {
        Layout<GraphVertex, GraphEdge> layout = new KKLayout<GraphVertex, GraphEdge>(m_g);
        // Size of the layout
        layout.setSize(new Dimension(1024, 1024));
        VisualizationImageServer<GraphVertex, GraphEdge> vv = new VisualizationImageServer<GraphVertex, GraphEdge>(layout, layout.getSize());
        // Viewing area size
        vv.setPreferredSize(new Dimension(1200, 1200));
        vv.getRenderContext().setVertexLabelTransformer(new Transformer<GraphVertex, String>() {

            @Override
            public String transform(GraphVertex vertex) {
                if (vertex.getBusinessService() != null) {
                    return String.format("BS[%s]", vertex.getBusinessService().getName());
                }
                if (vertex.getIpService() != null) {
                    IpService ipService = vertex.getIpService();
                    return String.format("IP_SERVICE[%s,%s]", ipService.getId(), ipService.getServiceName());
                }
                if (vertex.getReductionKey() != null) {
                    return String.format("RK[%s]", vertex.getReductionKey());
                }
                return "UNKNOWN";
            }
        });
        vv.getRenderContext().setEdgeLabelTransformer(new Transformer<GraphEdge, String>() {

            @Override
            public String transform(GraphEdge edge) {
                return String.format("%s", edge.getMapFunction().getClass().getSimpleName());
            }
        });
        // Create the buffered image
        BufferedImage image = (BufferedImage) vv.getImage(new Point2D.Double(vv.getGraphLayout().getSize().getWidth() / 2, vv.getGraphLayout().getSize().getHeight() / 2), new Dimension(vv.getGraphLayout().getSize()));
        // Render
        try {
            ImageIO.write(image, "png", tempFile);
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
    } finally {
        m_rwLock.readLock().unlock();
    }
}
Also used : KKLayout(edu.uci.ics.jung.algorithms.layout.KKLayout) Dimension(java.awt.Dimension) IOException(java.io.IOException) IpService(org.opennms.netmgt.bsm.service.model.IpService) BufferedImage(java.awt.image.BufferedImage) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) VisualizationImageServer(edu.uci.ics.jung.visualization.VisualizationImageServer) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge)

Example 3 with IpService

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

the class BusinessServiceVertexInfoPanelItemProvider method createComponent.

private Component createComponent(AbstractBusinessServiceVertex ref, GraphContainer graphContainer) {
    final FormLayout formLayout = new FormLayout();
    formLayout.setSpacing(false);
    formLayout.setMargin(false);
    ref.accept(new BusinessServiceVertexVisitor<Void>() {

        @Override
        public Void visit(BusinessServiceVertex vertex) {
            final BusinessService businessService = businessServiceManager.getBusinessServiceById(vertex.getServiceId());
            formLayout.addComponent(createLabel("Reduce function", getReduceFunctionDescription(businessService.getReduceFunction())));
            // Apply Reduce Function specific details
            businessService.getReduceFunction().accept(new ReduceFunctionVisitor<Void>() {

                @Override
                public Void visit(HighestSeverity highestSeverity) {
                    return null;
                }

                @Override
                public Void visit(HighestSeverityAbove highestSeverityAbove) {
                    return null;
                }

                @Override
                public // Threshold is not very transparent, we add an Explain Button in these cases
                Void visit(Threshold threshold) {
                    final Button explainButton = createButton("Explain", "Explain the Threshold function", FontAwesome.TABLE, (Button.ClickListener) event -> {
                        ThresholdExplanationWindow explainWindow = new ThresholdExplanationWindow(SimulationAwareStateMachineFactory.createSimulatedStateMachine(businessServiceManager, graphContainer.getCriteria()).explain(businessService, (Threshold) businessService.getReduceFunction()));
                        UI.getCurrent().addWindow(explainWindow);
                    });
                    explainButton.setStyleName(BaseTheme.BUTTON_LINK);
                    formLayout.addComponent(explainButton);
                    return null;
                }

                @Override
                public Void visit(ExponentialPropagation exponentialPropagation) {
                    return null;
                }
            });
            return null;
        }

        @Override
        public Void visit(IpServiceVertex vertex) {
            IpService ipService = businessServiceManager.getIpServiceById(vertex.getIpServiceId());
            formLayout.addComponent(createLabel("Interface", ipService.getIpAddress()));
            formLayout.addComponent(createLabel("Service", ipService.getServiceName()));
            if (!ipService.getServiceName().equals(vertex.getLabel())) {
                formLayout.addComponent(createLabel("Friendly Name", vertex.getLabel()));
            }
            return null;
        }

        @Override
        public Void visit(ReductionKeyVertex vertex) {
            formLayout.addComponent(createLabel("Reduction Key", vertex.getReductionKey()));
            if (!vertex.getReductionKey().equals(vertex.getLabel())) {
                formLayout.addComponent(createLabel("Friendly Name", vertex.getLabel()));
            }
            return null;
        }
    });
    return formLayout;
}
Also used : FormLayout(com.vaadin.ui.FormLayout) GraphContainer(org.opennms.features.topology.api.GraphContainer) AbstractBusinessServiceVertex(org.opennms.features.topology.plugins.topo.bsm.AbstractBusinessServiceVertex) IpService(org.opennms.netmgt.bsm.service.model.IpService) BaseTheme(com.vaadin.ui.themes.BaseTheme) VerticalLayout(com.vaadin.ui.VerticalLayout) Threshold(org.opennms.netmgt.bsm.service.model.functions.reduce.Threshold) UI(com.vaadin.ui.UI) BusinessServiceManager(org.opennms.netmgt.bsm.service.BusinessServiceManager) HighestSeverityAbove(org.opennms.netmgt.bsm.service.model.functions.reduce.HighestSeverityAbove) Window(com.vaadin.ui.Window) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) BusinessServiceVertexVisitor(org.opennms.features.topology.plugins.topo.bsm.BusinessServiceVertexVisitor) Strings(com.google.common.base.Strings) FontAwesome(com.vaadin.server.FontAwesome) GraphVertexToTopologyVertexConverter(org.opennms.features.topology.plugins.topo.bsm.GraphVertexToTopologyVertexConverter) VertexInfoPanelItemProvider(org.opennms.features.topology.api.info.VertexInfoPanelItemProvider) DefaultInfoPanelItem(org.opennms.features.topology.api.info.item.DefaultInfoPanelItem) ReductionFunction(org.opennms.netmgt.bsm.service.model.functions.reduce.ReductionFunction) Status(org.opennms.netmgt.bsm.service.model.Status) Label(com.vaadin.ui.Label) ShortcutAction(com.vaadin.event.ShortcutAction) Comparator.comparing(java.util.Comparator.comparing) UIHelper.createLabel(org.opennms.netmgt.vaadin.core.UIHelper.createLabel) BusinessServicesTopologyProvider(org.opennms.features.topology.plugins.topo.bsm.BusinessServicesTopologyProvider) ThresholdResultExplanation(org.opennms.netmgt.bsm.service.model.functions.reduce.ThresholdResultExplanation) InfoPanelItem(org.opennms.features.topology.api.info.item.InfoPanelItem) ExponentialPropagation(org.opennms.netmgt.bsm.service.model.functions.reduce.ExponentialPropagation) IpServiceVertex(org.opennms.features.topology.plugins.topo.bsm.IpServiceVertex) Collectors(java.util.stream.Collectors) Sizeable(com.vaadin.server.Sizeable) SimulationAwareStateMachineFactory(org.opennms.features.topology.plugins.topo.bsm.simulate.SimulationAwareStateMachineFactory) TransactionAwareBeanProxyFactory(org.opennms.netmgt.vaadin.core.TransactionAwareBeanProxyFactory) BusinessServiceVertexStatusInfoPanelItemProvider.createStatusLabel(org.opennms.features.topology.plugins.topo.bsm.info.BusinessServiceVertexStatusInfoPanelItemProvider.createStatusLabel) List(java.util.List) Button(com.vaadin.ui.Button) Table(com.vaadin.ui.Table) Edge(org.opennms.netmgt.bsm.service.model.edge.Edge) FormLayout(com.vaadin.ui.FormLayout) BusinessServiceVertex(org.opennms.features.topology.plugins.topo.bsm.BusinessServiceVertex) ReductionKeyVertex(org.opennms.features.topology.plugins.topo.bsm.ReductionKeyVertex) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge) ReduceFunctionVisitor(org.opennms.netmgt.bsm.service.model.functions.reduce.ReduceFunctionVisitor) VertexRef(org.opennms.features.topology.api.topo.VertexRef) HighestSeverity(org.opennms.netmgt.bsm.service.model.functions.reduce.HighestSeverity) UIHelper.createButton(org.opennms.netmgt.vaadin.core.UIHelper.createButton) Component(com.vaadin.ui.Component) HighestSeverity(org.opennms.netmgt.bsm.service.model.functions.reduce.HighestSeverity) ReductionKeyVertex(org.opennms.features.topology.plugins.topo.bsm.ReductionKeyVertex) HighestSeverityAbove(org.opennms.netmgt.bsm.service.model.functions.reduce.HighestSeverityAbove) IpService(org.opennms.netmgt.bsm.service.model.IpService) IpServiceVertex(org.opennms.features.topology.plugins.topo.bsm.IpServiceVertex) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) ReduceFunctionVisitor(org.opennms.netmgt.bsm.service.model.functions.reduce.ReduceFunctionVisitor) Button(com.vaadin.ui.Button) UIHelper.createButton(org.opennms.netmgt.vaadin.core.UIHelper.createButton) ExponentialPropagation(org.opennms.netmgt.bsm.service.model.functions.reduce.ExponentialPropagation) AbstractBusinessServiceVertex(org.opennms.features.topology.plugins.topo.bsm.AbstractBusinessServiceVertex) BusinessServiceVertex(org.opennms.features.topology.plugins.topo.bsm.BusinessServiceVertex) Threshold(org.opennms.netmgt.bsm.service.model.functions.reduce.Threshold)

Example 4 with IpService

use of org.opennms.netmgt.bsm.service.model.IpService 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 IpService

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

the class BusinessServiceRestService method addIpServiceEdge.

@POST
@Path("{id}/ip-service-edge")
public // Add IpService
Response addIpServiceEdge(@PathParam("id") final Long serviceId, final IpServiceEdgeRequestDTO edgeRequest) {
    final BusinessService businessService = getManager().getBusinessServiceById(serviceId);
    final IpService ipService = getManager().getIpServiceById(edgeRequest.getIpServiceId());
    boolean changed = getManager().addIpServiceEdge(businessService, ipService, transform(edgeRequest.getMapFunction()), edgeRequest.getWeight(), edgeRequest.getFriendlyName());
    if (!changed) {
        return Response.notModified().build();
    }
    businessService.save();
    return Response.ok().build();
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) IpService(org.opennms.netmgt.bsm.service.model.IpService) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

IpService (org.opennms.netmgt.bsm.service.model.IpService)6 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)5 BusinessServiceManager (org.opennms.netmgt.bsm.service.BusinessServiceManager)3 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.Test)2 Node (org.opennms.netmgt.bsm.service.model.Node)2 GraphEdge (org.opennms.netmgt.bsm.service.model.graph.GraphEdge)2 Strings (com.google.common.base.Strings)1 ShortcutAction (com.vaadin.event.ShortcutAction)1 FontAwesome (com.vaadin.server.FontAwesome)1 Sizeable (com.vaadin.server.Sizeable)1 Button (com.vaadin.ui.Button)1 Component (com.vaadin.ui.Component)1 FormLayout (com.vaadin.ui.FormLayout)1 Label (com.vaadin.ui.Label)1 Table (com.vaadin.ui.Table)1 UI (com.vaadin.ui.UI)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 Window (com.vaadin.ui.Window)1