Search in sources :

Example 26 with BusinessService

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

Example 27 with BusinessService

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

the class BusinessServiceVertexProviderTest method testVertexRefId.

@Test
public void testVertexRefId() {
    // Mock the manager to return a node label
    BusinessServiceManager managerMock = EasyMock.createNiceMock(BusinessServiceManager.class);
    EasyMock.expect(managerMock.getNodeById(EasyMock.anyInt())).andReturn(new Node() {

        @Override
        public String getLabel() {
            return "localhost";
        }

        @Override
        public Integer getId() {
            return 1;
        }
    }).anyTimes();
    EasyMock.replay(managerMock);
    // create 3 business service vertices, where the first 2 should be equal
    BusinessServiceEntityBuilder builder = new BusinessServiceEntityBuilder().id(10L).name("Name");
    BusinessService bs1 = new BusinessServiceImpl(managerMock, builder.toEntity());
    BusinessService bs2 = new BusinessServiceImpl(managerMock, builder.toEntity());
    // is different
    BusinessService bs3 = new BusinessServiceImpl(managerMock, builder.id(11L).toEntity());
    BusinessServiceVertex bsVertex1 = new BusinessServiceVertex(bs1, 0);
    BusinessServiceVertex bsVertex2 = new BusinessServiceVertex(bs2, 0);
    BusinessServiceVertex bsVertex3 = new BusinessServiceVertex(bs3, 0);
    // create 2 ip Service vertices where all of them should be equal
    IpService ipService1 = new IpServiceImpl(managerMock, BsmTestUtils.createMonitoredService(1, 1, "127.0.0.1", "SSH"));
    IpService ipService2 = new IpServiceImpl(managerMock, BsmTestUtils.createMonitoredService(1, 1, "127.0.0.1", "SSH"));
    IpServiceVertex ipServiceVertex1 = new IpServiceVertex(ipService1, 0);
    IpServiceVertex ipServiceVertex2 = new IpServiceVertex(ipService2, 0);
    // create 3 reduction key vertices where 2 of them should be equal
    ReductionKeyVertex rkVertex1 = new ReductionKeyVertex("key1", 0);
    ReductionKeyVertex rkVertex2 = new ReductionKeyVertex("key1", 0);
    ReductionKeyVertex rkVertex3 = new ReductionKeyVertex("key2", 0);
    // Add all the above vertices. Some of them even twice to ensure that the getRefId() methods work correctly
    BusinessServiceVertexProvider vertexProvider = new BusinessServiceVertexProvider(BusinessServicesTopologyProvider.TOPOLOGY_NAMESPACE);
    // adding twice on purpose
    vertexProvider.add(bsVertex1, bsVertex1, bsVertex2, bsVertex2, bsVertex3, bsVertex3);
    // adding twice on purpose
    vertexProvider.add(ipServiceVertex1, ipServiceVertex1, ipServiceVertex2, ipServiceVertex2);
    // adding twice on purpose
    vertexProvider.add(rkVertex1, rkVertex1);
    // adding twice on purpose
    vertexProvider.add(rkVertex2, rkVertex2);
    // adding twice on purpose
    vertexProvider.add(rkVertex3, rkVertex3);
    // In total there should be 5 vertices
    Assert.assertEquals(5, vertexProvider.getVertices().size());
    Assert.assertSame(ipServiceVertex2, vertexProvider.getVertex(ipServiceVertex1));
    Assert.assertSame(ipServiceVertex2, vertexProvider.getVertex(ipServiceVertex2));
    Assert.assertSame(bsVertex2, vertexProvider.getVertex(bsVertex1));
    Assert.assertSame(bsVertex2, vertexProvider.getVertex(bsVertex2));
    Assert.assertSame(bsVertex3, vertexProvider.getVertex(bsVertex3));
    Assert.assertNotSame(bsVertex1, vertexProvider.getVertex(bsVertex3));
    Assert.assertNotSame(bsVertex2, vertexProvider.getVertex(bsVertex3));
    Assert.assertSame(rkVertex2, vertexProvider.getVertex(rkVertex1));
    Assert.assertSame(rkVertex2, vertexProvider.getVertex(rkVertex2));
    Assert.assertNotSame(rkVertex1, vertexProvider.getVertex(rkVertex3));
    Assert.assertSame(rkVertex3, vertexProvider.getVertex(rkVertex3));
    EasyMock.verify(managerMock);
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) BusinessServiceImpl(org.opennms.netmgt.bsm.service.internal.BusinessServiceImpl) Node(org.opennms.netmgt.bsm.service.model.Node) IpServiceImpl(org.opennms.netmgt.bsm.service.internal.IpServiceImpl) BusinessServiceManager(org.opennms.netmgt.bsm.service.BusinessServiceManager) IpService(org.opennms.netmgt.bsm.service.model.IpService) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) Test(org.junit.Test)

Example 28 with BusinessService

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

the class DefaultBusinessServiceStateMachine method explain.

@Override
public ThresholdResultExplanation explain(BusinessService businessService, Threshold threshold) {
    final GraphVertex vertex = getGraph().getVertexByBusinessServiceId(businessService.getId());
    // Calculate the weighed statuses from the child edges
    List<StatusWithIndex> statusesWithIndices = weighEdges(getGraph().getOutEdges(vertex));
    List<Status> statuses = statusesWithIndices.stream().map(si -> si.getStatus()).collect(Collectors.toList());
    // Reduce
    Status reducedStatus = threshold.reduce(statusesWithIndices).orElse(new StatusWithIndices(MIN_SEVERITY, Collections.emptyList())).getStatus();
    ThresholdResultExplanation explanation = new ThresholdResultExplanation();
    explanation.setStatus(reducedStatus);
    explanation.setHitsByStatus(threshold.getHitsByStatus(statuses));
    explanation.setGraphEdges(getGraph().getOutEdges(vertex));
    explanation.setWeightStatuses(statuses);
    explanation.setFunction(threshold);
    Map<GraphEdge, GraphVertex> graphEdgeToGraphVertex = new HashMap<>();
    for (Edge eachEdge : businessService.getEdges()) {
        GraphVertex vertexForEdge = getGraph().getVertexByEdgeId(eachEdge.getId());
        GraphEdge graphEdge = getGraph().getGraphEdgeByEdgeId(eachEdge.getId());
        if (vertexForEdge != null && graphEdge != null) {
            graphEdgeToGraphVertex.put(graphEdge, vertexForEdge);
        }
    }
    explanation.setGraphEdgeToGraphVertexMapping(graphEdgeToGraphVertex);
    return explanation;
}
Also used : StatusWithIndex(org.opennms.netmgt.bsm.service.model.StatusWithIndex) IpService(org.opennms.netmgt.bsm.service.model.IpService) Point2D(java.awt.geom.Point2D) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) AlarmWrapper(org.opennms.netmgt.bsm.service.model.AlarmWrapper) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Transformer(org.apache.commons.collections15.Transformer) StatusWithIndices(org.opennms.netmgt.bsm.service.model.StatusWithIndices) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) BigInteger(java.math.BigInteger) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ThresholdResultExplanation(org.opennms.netmgt.bsm.service.model.functions.reduce.ThresholdResultExplanation) BufferedImage(java.awt.image.BufferedImage) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) Dimension(java.awt.Dimension) List(java.util.List) Edge(org.opennms.netmgt.bsm.service.model.edge.Edge) BusinessServiceStateChangeHandler(org.opennms.netmgt.bsm.service.BusinessServiceStateChangeHandler) Entry(java.util.Map.Entry) Optional(java.util.Optional) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge) VisualizationImageServer(edu.uci.ics.jung.visualization.VisualizationImageServer) Threshold(org.opennms.netmgt.bsm.service.model.functions.reduce.Threshold) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Function(java.util.function.Function) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Lists(com.google.common.collect.Lists) KKLayout(edu.uci.ics.jung.algorithms.layout.KKLayout) Status(org.opennms.netmgt.bsm.service.model.Status) AlarmProvider(org.opennms.netmgt.bsm.service.AlarmProvider) Layout(edu.uci.ics.jung.algorithms.layout.Layout) Logger(org.slf4j.Logger) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) BusinessServiceGraphImpl(org.opennms.netmgt.bsm.service.model.graph.internal.BusinessServiceGraphImpl) File(java.io.File) StatusWithIndex(org.opennms.netmgt.bsm.service.model.StatusWithIndex) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) GraphAlgorithms(org.opennms.netmgt.bsm.service.model.graph.internal.GraphAlgorithms) Collections(java.util.Collections) Status(org.opennms.netmgt.bsm.service.model.Status) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ThresholdResultExplanation(org.opennms.netmgt.bsm.service.model.functions.reduce.ThresholdResultExplanation) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge) Edge(org.opennms.netmgt.bsm.service.model.edge.Edge) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge) StatusWithIndices(org.opennms.netmgt.bsm.service.model.StatusWithIndices)

Example 29 with BusinessService

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

the class DefaultBusinessServiceStateMachineTest method canLookupNewAlarmsWhenReloading.

@Test
public void canLookupNewAlarmsWhenReloading() {
    // Create a simple hierarchy
    MockBusinessServiceHierarchy h = MockBusinessServiceHierarchy.builder().withBusinessService(1).withReductionKey(1, "a1").commit().build();
    BusinessService b1 = h.getBusinessServiceById(1);
    Edge a1 = h.getEdgeByReductionKey("a1");
    // Setup the state machine
    DefaultBusinessServiceStateMachine stateMachine = new DefaultBusinessServiceStateMachine();
    LoggingStateChangeHandler stateChangeHandler = new LoggingStateChangeHandler();
    stateMachine.addHandler(stateChangeHandler, Maps.newHashMap());
    stateMachine.setBusinessServices(h.getBusinessServices());
    stateMachine.setAlarmProvider(new AlarmProvider() {

        @Override
        public Map<String, AlarmWrapper> lookup(Set<String> reductionKeys) {
            if (reductionKeys.contains("a2")) {
                return ImmutableMap.<String, AlarmWrapper>builder().put("a2", new MockAlarmWrapper("a2", Status.CRITICAL)).build();
            }
            return new HashMap<>();
        }
    });
    // Verify the initial state
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(b1));
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(a1));
    assertEquals(0, stateChangeHandler.getStateChanges().size());
    // Send an alarm and verify the updated state
    stateMachine.handleNewOrUpdatedAlarm(new MockAlarmWrapper("a1", Status.MINOR));
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(b1));
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(a1));
    assertEquals(1, stateChangeHandler.getStateChanges().size());
    // Update the hierarchy and reload the state machine
    h = MockBusinessServiceHierarchy.builder().withBusinessService(1).withReductionKey(1, "a1").withReductionKey(2, "a2").commit().build();
    stateMachine.setBusinessServices(h.getBusinessServices());
    Edge a2 = h.getEdgeByReductionKey("a2");
    // The state should be upgraded
    assertEquals(Status.CRITICAL, stateMachine.getOperationalStatus(b1));
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(a1));
    assertEquals(Status.CRITICAL, stateMachine.getOperationalStatus(a2));
    // One additional state change event should have been generated
    assertEquals(2, stateChangeHandler.getStateChanges().size());
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) AlarmProvider(org.opennms.netmgt.bsm.service.AlarmProvider) MockBusinessServiceHierarchy(org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy) LoggingStateChangeHandler(org.opennms.netmgt.bsm.test.LoggingStateChangeHandler) Edge(org.opennms.netmgt.bsm.service.model.edge.Edge) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) MockAlarmWrapper(org.opennms.netmgt.bsm.mock.MockAlarmWrapper) Test(org.junit.Test)

Example 30 with BusinessService

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

the class DefaultBusinessServiceStateMachineTest method canReloadTheStateMachineWhilePreservingState.

@Test
public void canReloadTheStateMachineWhilePreservingState() {
    // Create a simple hierarchy
    MockBusinessServiceHierarchy h = MockBusinessServiceHierarchy.builder().withBusinessService(1).withReductionKey(1, "a1").commit().build();
    BusinessService b1 = h.getBusinessServiceById(1);
    // Setup the state machine
    BusinessServiceStateMachine stateMachine = new DefaultBusinessServiceStateMachine();
    LoggingStateChangeHandler stateChangeHandler = new LoggingStateChangeHandler();
    stateMachine.addHandler(stateChangeHandler, Maps.newHashMap());
    stateMachine.setBusinessServices(h.getBusinessServices());
    // Verify the initial state
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(b1));
    assertEquals(0, stateChangeHandler.getStateChanges().size());
    // Send an alarm and verify the updated state
    stateMachine.handleNewOrUpdatedAlarm(new MockAlarmWrapper("a1", Status.CRITICAL));
    assertEquals(Status.CRITICAL, stateMachine.getOperationalStatus(b1));
    assertEquals(1, stateChangeHandler.getStateChanges().size());
    // Now reload the state machine without making any changes to the hierarchies
    stateMachine.setBusinessServices(h.getBusinessServices());
    // The original status should remain
    assertEquals(Status.CRITICAL, stateMachine.getOperationalStatus(b1));
    // No additional state changes events should have been generated
    assertEquals(1, stateChangeHandler.getStateChanges().size());
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) MockBusinessServiceHierarchy(org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy) LoggingStateChangeHandler(org.opennms.netmgt.bsm.test.LoggingStateChangeHandler) MockAlarmWrapper(org.opennms.netmgt.bsm.mock.MockAlarmWrapper) Test(org.junit.Test)

Aggregations

BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)39 Test (org.junit.Test)13 IpServiceEdge (org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge)10 Collectors (java.util.stream.Collectors)9 IpService (org.opennms.netmgt.bsm.service.model.IpService)9 Status (org.opennms.netmgt.bsm.service.model.Status)9 Edge (org.opennms.netmgt.bsm.service.model.edge.Edge)9 BusinessServiceGraph (org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)9 List (java.util.List)8 BusinessServiceManager (org.opennms.netmgt.bsm.service.BusinessServiceManager)8 BusinessServiceStateMachine (org.opennms.netmgt.bsm.service.BusinessServiceStateMachine)8 Map (java.util.Map)7 Objects (java.util.Objects)7 Path (javax.ws.rs.Path)7 ChildEdge (org.opennms.netmgt.bsm.service.model.edge.ChildEdge)7 ReductionKeyEdge (org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge)7 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)6 NoSuchElementException (java.util.NoSuchElementException)5 Set (java.util.Set)5 Criteria (org.opennms.core.criteria.Criteria)5