Search in sources :

Example 6 with BusinessService

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

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

the class BusinessServiceManagerImplIT method testChildMapping.

@Test
public void testChildMapping() {
    BusinessService service_p_1 = createBusinessService("Business Service #p1");
    BusinessService service_p_2 = createBusinessService("Business Service #p2");
    BusinessService service_c_1 = createBusinessService("Business Service #c1");
    BusinessService service_c_2 = createBusinessService("Business Service #c2");
    businessServiceManager.addChildEdge(service_p_1, service_c_1, new Identity(), Edge.DEFAULT_WEIGHT);
    businessServiceManager.addChildEdge(service_p_1, service_c_2, new Identity(), Edge.DEFAULT_WEIGHT);
    businessServiceManager.addChildEdge(service_p_2, service_c_1, new Identity(), Edge.DEFAULT_WEIGHT);
    businessServiceManager.addChildEdge(service_p_2, service_c_2, new Identity(), Edge.DEFAULT_WEIGHT);
    Assert.assertEquals(ImmutableSet.of(service_p_1, service_p_2), service_c_1.getParentServices());
    Assert.assertEquals(ImmutableSet.of(service_p_1, service_p_2), service_c_2.getParentServices());
}
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) Test(org.junit.Test)

Example 8 with BusinessService

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

the class BusinessServiceManagerImpl method addReductionKeyEdge.

@Override
public boolean addReductionKeyEdge(BusinessService businessService, String reductionKey, MapFunction mapFunction, int weight, String friendlyName) {
    final BusinessServiceEntity parentEntity = getBusinessServiceEntity(businessService);
    // Create the edge
    final ReductionKeyEdgeImpl edge = (ReductionKeyEdgeImpl) createEdge(ReductionKeyEdge.class, businessService, mapFunction, weight);
    edge.setReductionKey(reductionKey);
    edge.setFriendlyName(friendlyName);
    // if already exists, no update
    final SingleReductionKeyEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(edge);
    long count = parentEntity.getReductionKeyEdges().stream().filter(e -> e.equalsDefinition(edgeEntity)).count();
    if (count > 0) {
        return false;
    }
    parentEntity.addEdge(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) SingleReductionKeyEdgeEntity(org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) ReductionKeyEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.ReductionKeyEdgeImpl) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge)

Example 9 with BusinessService

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

the class BusinessServiceTreeTable method refresh.

/**
     * Refreshes table entries.
     */
public void refresh() {
    final com.google.common.collect.Table<Long, Optional<Long>, Boolean> expandState = getCurrentExpandState();
    final BusinessServiceContainer newContainer = new BusinessServiceContainer();
    if (!Strings.isNullOrEmpty(businessServiceNameFilter)) {
        newContainer.addContainerFilter(new BusinessServiceFilter(newContainer, businessServiceNameFilter));
    }
    // Build a graph using all of the business services stored in the database
    // We don't use the existing graph, since it only contains the services know by the state machine
    List<BusinessService> allBusinessServices = businessServiceManager.getAllBusinessServices();
    final BusinessServiceGraph graph = businessServiceManager.getGraph(allBusinessServices);
    // Recursively generate the table rows, starting with the roots
    graph.getVerticesByLevel(0).stream().filter(v -> v.getBusinessService() != null).sorted((v1, v2) -> v1.getBusinessService().getName().compareTo(v2.getBusinessService().getName())).forEach(v -> newContainer.addRow(graph, v));
    // Make it hierarchical
    Hierarchical hierarchicalContainer = createHierarchicalContainer(newContainer);
    // Update datasource
    setContainerDataSource(hierarchicalContainer);
    // reset visible columns
    setVisibleColumns("name", "links", "edit / delete");
    // Restore the previous collapsed state
    List<BusinessServiceRow> rows = getItemIds().stream().map(itemId -> getItem(itemId).getBean()).collect(Collectors.toList());
    applyExpandState(expandState, rows);
}
Also used : TopologyLinkBuilder(org.opennms.features.topology.link.TopologyLinkBuilder) TransactionAwareUI(org.opennms.netmgt.vaadin.core.TransactionAwareUI) BeanItem(com.vaadin.data.util.BeanItem) TreeTable(com.vaadin.ui.TreeTable) Alignment(com.vaadin.ui.Alignment) BusinessServiceManager(org.opennms.netmgt.bsm.service.BusinessServiceManager) UIHelper(org.opennms.netmgt.vaadin.core.UIHelper) HashBasedTable(com.google.common.collect.HashBasedTable) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Strings(com.google.common.base.Strings) FontAwesome(com.vaadin.server.FontAwesome) Status(org.opennms.netmgt.bsm.service.model.Status) Map(java.util.Map) Label(com.vaadin.ui.Label) ContainerHierarchicalWrapper(com.vaadin.data.util.ContainerHierarchicalWrapper) TopologyProvider(org.opennms.features.topology.link.TopologyProvider) Item(com.vaadin.data.Item) Property(com.vaadin.data.Property) Collection(java.util.Collection) Layout(org.opennms.features.topology.link.Layout) Link(com.vaadin.ui.Link) Collectors(java.util.stream.Collectors) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) Objects(java.util.Objects) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) List(java.util.List) ExternalResource(com.vaadin.server.ExternalResource) Button(com.vaadin.ui.Button) Table(com.vaadin.ui.Table) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Optional(java.util.Optional) Optional(java.util.Optional) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService)

Example 10 with BusinessService

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

the class BusinessServiceManagerImplIT method testLoopDetection.

@Test
public void testLoopDetection() {
    BusinessServiceEntity service1 = createDummyBusinessService("Business Service #1");
    BusinessServiceEntity service2 = createDummyBusinessService("Business Service #2");
    BusinessServiceEntity service3 = createDummyBusinessService("Business Service #3");
    Long serviceId1 = businessServiceDao.save(service1);
    Long serviceId2 = businessServiceDao.save(service2);
    Long serviceId3 = businessServiceDao.save(service3);
    BusinessService bs1 = getBusinessService(serviceId1);
    BusinessService bs2 = getBusinessService(serviceId2);
    BusinessService bs3 = getBusinessService(serviceId3);
    Assert.assertEquals(ImmutableSet.of(businessServiceManager.getBusinessServiceById(serviceId2), businessServiceManager.getBusinessServiceById(serviceId3)), businessServiceManager.getFeasibleChildServices(businessServiceManager.getBusinessServiceById(serviceId1)));
    Assert.assertEquals(ImmutableSet.of(businessServiceManager.getBusinessServiceById(serviceId1), businessServiceManager.getBusinessServiceById(serviceId3)), businessServiceManager.getFeasibleChildServices(businessServiceManager.getBusinessServiceById(serviceId2)));
    Assert.assertEquals(ImmutableSet.of(businessServiceManager.getBusinessServiceById(serviceId1), businessServiceManager.getBusinessServiceById(serviceId2)), businessServiceManager.getFeasibleChildServices(businessServiceManager.getBusinessServiceById(serviceId3)));
    businessServiceManager.addChildEdge(bs1, bs2, new Identity(), Edge.DEFAULT_WEIGHT);
    bs1.save();
    bs2.save();
    Assert.assertEquals(ImmutableSet.of(businessServiceManager.getBusinessServiceById(serviceId2), businessServiceManager.getBusinessServiceById(serviceId3)), businessServiceManager.getFeasibleChildServices(businessServiceManager.getBusinessServiceById(serviceId1)));
    Assert.assertEquals(ImmutableSet.of(businessServiceManager.getBusinessServiceById(serviceId3)), businessServiceManager.getFeasibleChildServices(businessServiceManager.getBusinessServiceById(serviceId2)));
    Assert.assertEquals(ImmutableSet.of(businessServiceManager.getBusinessServiceById(serviceId1), businessServiceManager.getBusinessServiceById(serviceId2)), businessServiceManager.getFeasibleChildServices(businessServiceManager.getBusinessServiceById(serviceId3)));
    businessServiceManager.addChildEdge(bs2, bs3, new Identity(), Edge.DEFAULT_WEIGHT);
    bs2.save();
    bs3.save();
    Assert.assertEquals(ImmutableSet.of(businessServiceManager.getBusinessServiceById(serviceId2), businessServiceManager.getBusinessServiceById(serviceId3)), businessServiceManager.getFeasibleChildServices(businessServiceManager.getBusinessServiceById(serviceId1)));
    Assert.assertEquals(ImmutableSet.of(businessServiceManager.getBusinessServiceById(serviceId3)), businessServiceManager.getFeasibleChildServices(businessServiceManager.getBusinessServiceById(serviceId2)));
    Assert.assertEquals(ImmutableSet.of(), businessServiceManager.getFeasibleChildServices(businessServiceManager.getBusinessServiceById(serviceId3)));
}
Also used : BsmTestUtils.createDummyBusinessService(org.opennms.netmgt.bsm.test.BsmTestUtils.createDummyBusinessService) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) 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