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));
}
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());
}
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;
}
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);
}
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)));
}
Aggregations