Search in sources :

Example 1 with Identity

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

use of org.opennms.netmgt.bsm.service.model.functions.map.Identity 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 3 with Identity

use of org.opennms.netmgt.bsm.service.model.functions.map.Identity in project opennms by OpenNMS.

the class BusinessServiceEdgeEditWindow method getMapFunction.

@SuppressWarnings("unchecked")
private MapFunction getMapFunction() {
    try {
        final MapFunction mapFunction = ((Class<? extends MapFunction>) m_mapFunctionSelect.getValue()).newInstance();
        mapFunction.accept(new MapFunctionVisitor<Void>() {

            @Override
            public Void visit(Decrease decrease) {
                return null;
            }

            @Override
            public Void visit(Identity identity) {
                return null;
            }

            @Override
            public Void visit(Ignore ignore) {
                return null;
            }

            @Override
            public Void visit(Increase increase) {
                return null;
            }

            @Override
            public Void visit(SetTo setTo) {
                setTo.setStatus((Status) m_mapFunctionSeveritySelect.getValue());
                return null;
            }
        });
        return mapFunction;
    } catch (final InstantiationException | IllegalAccessException e) {
        throw Throwables.propagate(e);
    }
}
Also used : Status(org.opennms.netmgt.bsm.service.model.Status) Ignore(org.opennms.netmgt.bsm.service.model.functions.map.Ignore) Increase(org.opennms.netmgt.bsm.service.model.functions.map.Increase) MapFunction(org.opennms.netmgt.bsm.service.model.functions.map.MapFunction) Decrease(org.opennms.netmgt.bsm.service.model.functions.map.Decrease) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) SetTo(org.opennms.netmgt.bsm.service.model.functions.map.SetTo)

Example 4 with Identity

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

Example 5 with Identity

use of org.opennms.netmgt.bsm.service.model.functions.map.Identity in project opennms by OpenNMS.

the class BusinessServiceManagerImplIT method testChildDeletionSingleLevel.

// 1 parent -> 2 children
@Test
public void testChildDeletionSingleLevel() {
    BusinessService service_p = createBusinessService("Business Service #p");
    BusinessService service_c_1 = createBusinessService("Business Service #c1");
    BusinessService service_c_2 = createBusinessService("Business Service #c2");
    businessServiceManager.addChildEdge(service_p, service_c_1, new Identity(), Edge.DEFAULT_WEIGHT);
    businessServiceManager.addChildEdge(service_p, service_c_2, new Identity(), Edge.DEFAULT_WEIGHT);
    service_p.save();
    service_c_1.save();
    service_c_2.save();
    // ensure the edges are there before deleting
    Assert.assertEquals(2, edgeDao.countAll());
    service_c_1.delete();
    Assert.assertEquals(ImmutableSet.of(service_c_2), service_p.getChildServices());
    // verify that the edge is also gone
    Assert.assertEquals(1, edgeDao.countAll());
}
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)

Aggregations

Identity (org.opennms.netmgt.bsm.service.model.functions.map.Identity)12 Test (org.junit.Test)10 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)7 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)5 BsmTestUtils.createDummyBusinessService (org.opennms.netmgt.bsm.test.BsmTestUtils.createDummyBusinessService)5 HighestSeverityEntity (org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity)3 BusinessServiceEntityBuilder (org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder)3 FunctionsManager (org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager)3 IpServiceEdge (org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge)2 Map (java.util.Map)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Argument (org.apache.felix.gogo.commands.Argument)1 Command (org.apache.felix.gogo.commands.Command)1 OsgiCommandSupport (org.apache.karaf.shell.console.OsgiCommandSupport)1 BusinessServiceManager (org.opennms.netmgt.bsm.service.BusinessServiceManager)1 AlarmWrapper (org.opennms.netmgt.bsm.service.model.AlarmWrapper)1 IpService (org.opennms.netmgt.bsm.service.model.IpService)1 Status (org.opennms.netmgt.bsm.service.model.Status)1 Decrease (org.opennms.netmgt.bsm.service.model.functions.map.Decrease)1