Search in sources :

Example 6 with Identity

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

the class AbstractBusinessServiceRestServiceIT method canAddIpServiceEdge.

@Test
public void canAddIpServiceEdge() throws Exception {
    // Create a business service without any edges
    BusinessServiceEntity service = new BusinessServiceEntityBuilder().name("Dummy Service").reduceFunction(new HighestSeverityEntity()).toEntity();
    final Long serviceId = m_businessServiceDao.save(service);
    m_businessServiceDao.flush();
    // The Request to send to create an edge
    IpServiceEdgeRequestDTO edgeRequestDTO = new IpServiceEdgeRequestDTO();
    edgeRequestDTO.setMapFunction(new FunctionsManager().getMapFunctionDTO(new Identity()));
    // verify adding of not existing ip service is not possible
    edgeRequestDTO.setIpServiceId(-1);
    sendData(POST, getMediaType(), buildIpServiceEdgeUrl(serviceId), marshal(edgeRequestDTO), 404);
    // verify adding of existing ip service is possible
    edgeRequestDTO.setIpServiceId(10);
    sendData(POST, getMediaType(), buildIpServiceEdgeUrl(serviceId), marshal(edgeRequestDTO), 200);
    Assert.assertEquals(1, m_businessServiceDao.get(serviceId).getIpServiceEdges().size());
    // verify adding twice possible, but not modified
    sendData(POST, getMediaType(), buildIpServiceEdgeUrl(serviceId), marshal(edgeRequestDTO), 304);
    Assert.assertEquals(1, m_businessServiceDao.get(serviceId).getIpServiceEdges().size());
    // verify adding of existing ip service is possible
    edgeRequestDTO.setIpServiceId(17);
    sendData(POST, getMediaType(), buildIpServiceEdgeUrl(serviceId), marshal(edgeRequestDTO), 200);
    Assert.assertEquals(2, m_businessServiceDao.get(serviceId).getIpServiceEdges().size());
}
Also used : FunctionsManager(org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager) IpServiceEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.IpServiceEdgeRequestDTO) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) Test(org.junit.Test)

Example 7 with Identity

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

the class AbstractBusinessServiceRestServiceIT method canAddReductionKeyEdge.

@Test
public void canAddReductionKeyEdge() throws Exception {
    // Create a business service without any edges
    BusinessServiceEntity service = new BusinessServiceEntityBuilder().name("Dummy Service").reduceFunction(new HighestSeverityEntity()).toEntity();
    final Long serviceId = m_businessServiceDao.save(service);
    m_businessServiceDao.flush();
    // The Request to send to create an edge
    ReductionKeyEdgeRequestDTO edgeRequestDTO = new ReductionKeyEdgeRequestDTO();
    edgeRequestDTO.setMapFunction(new FunctionsManager().getMapFunctionDTO(new Identity()));
    // verify adding of existing ip service is possible
    edgeRequestDTO.setReductionKey("1st reduction key");
    sendData(POST, getMediaType(), buildReductionKeyEdgeUrl(serviceId), marshal(edgeRequestDTO), 200);
    Assert.assertEquals(1, m_businessServiceDao.get(serviceId).getReductionKeyEdges().size());
    // verify adding twice possible, but not modified
    sendData(POST, getMediaType(), buildReductionKeyEdgeUrl(serviceId), marshal(edgeRequestDTO), 304);
    Assert.assertEquals(1, m_businessServiceDao.get(serviceId).getReductionKeyEdges().size());
    // verify adding of existing ip service is possible
    edgeRequestDTO.setReductionKey("2nd reduction key");
    sendData(POST, getMediaType(), buildReductionKeyEdgeUrl(serviceId), marshal(edgeRequestDTO), 200);
    Assert.assertEquals(2, m_businessServiceDao.get(serviceId).getReductionKeyEdges().size());
}
Also used : FunctionsManager(org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager) ReductionKeyEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.ReductionKeyEdgeRequestDTO) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) Test(org.junit.Test)

Example 8 with Identity

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

the class AbstractBusinessServiceRestServiceIT method canAddChildServiceEdge.

@Test
public void canAddChildServiceEdge() throws Exception {
    // Create a child and parent Business Service without any edges
    BusinessServiceEntity childEntity = new BusinessServiceEntityBuilder().name("Child Service").reduceFunction(new HighestSeverityEntity()).toEntity();
    BusinessServiceEntity parentEntity = new BusinessServiceEntityBuilder().name("Parent Service").reduceFunction(new HighestSeverityEntity()).toEntity();
    final Long parentServiceId = m_businessServiceDao.save(parentEntity);
    final Long childServiceId = m_businessServiceDao.save(childEntity);
    m_businessServiceDao.flush();
    // The Request to send to create the edge
    ChildEdgeRequestDTO edgeRequestDTO = new ChildEdgeRequestDTO();
    edgeRequestDTO.setMapFunction(new FunctionsManager().getMapFunctionDTO(new Identity()));
    // verify adding of not existing ip parentEntity is not possible
    edgeRequestDTO.setChildId(-1L);
    sendData(POST, getMediaType(), buildChildServiceEdgeUrl(parentServiceId), marshal(edgeRequestDTO), 404);
    // verify adding of existing ip parentEntity is possible
    edgeRequestDTO.setChildId(childServiceId);
    sendData(POST, getMediaType(), buildChildServiceEdgeUrl(parentServiceId), marshal(edgeRequestDTO), 200);
    Assert.assertEquals(1, m_businessServiceDao.get(parentServiceId).getChildEdges().size());
    // verify adding twice possible, but not modified
    sendData(POST, getMediaType(), buildChildServiceEdgeUrl(parentServiceId), marshal(edgeRequestDTO), 304);
    Assert.assertEquals(1, m_businessServiceDao.get(parentServiceId).getChildEdges().size());
}
Also used : ChildEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.ChildEdgeRequestDTO) FunctionsManager(org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) Test(org.junit.Test)

Example 9 with Identity

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

the class BusinessServiceManagerImplIT method testChildDeletionMultipleLevels.

// 1 parent -> 1 Child -> 1 child
@Test
public void testChildDeletionMultipleLevels() {
    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_c_1, 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_p.getChildServices());
    // verify that the edge is also gon
    Assert.assertEquals(0, 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)

Example 10 with Identity

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

the class DefaultBusinessServiceStateMachineIT method canMaintainStateForSimpleHierarchy.

@Test
public void canMaintainStateForSimpleHierarchy() {
    // Setup the the test hierarchy
    SimpleTestHierarchy testHierarchy = new SimpleTestHierarchy(populator);
    testHierarchy.getServices().forEach(entity -> businessServiceDao.save(entity));
    BusinessServiceImpl bsChild1 = wrap(testHierarchy.getChild1());
    BusinessServiceImpl bsChild2 = wrap(testHierarchy.getChild2());
    BusinessServiceImpl bsParent = wrap(testHierarchy.getRoot());
    IpServiceEdge svc1 = wrap(testHierarchy.getServiceChild1());
    IpServiceEdge svc2 = wrap(testHierarchy.getServiceChild2());
    // Manually add a reduction key to a business service to verify that this also works
    bsChild1.addReductionKeyEdge("explicitReductionKey", new Identity(), Edge.DEFAULT_WEIGHT, null);
    businessServiceDao.flush();
    // Setup the state machine
    List<BusinessService> bss = Lists.newArrayList(bsChild1, bsChild2, bsParent);
    LoggingStateChangeHandler handler = new LoggingStateChangeHandler();
    DefaultBusinessServiceStateMachine stateMachine = new DefaultBusinessServiceStateMachine();
    stateMachine.setBusinessServices(bss);
    stateMachine.addHandler(handler, null);
    // Verify the initial state
    assertEquals(0, handler.getStateChanges().size());
    for (BusinessService eachBs : bss) {
        assertEquals(DefaultBusinessServiceStateMachine.MIN_SEVERITY, stateMachine.getOperationalStatus(eachBs));
    }
    // Pass alarm to the state machine
    stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(testHierarchy.getServiceChild1().getIpService(), OnmsSeverity.MINOR));
    // Verify the updated state
    assertEquals(2, handler.getStateChanges().size());
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(svc1));
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(bsChild1));
    assertEquals(DefaultBusinessServiceStateMachine.MIN_SEVERITY, stateMachine.getOperationalStatus(svc2));
    assertEquals(DefaultBusinessServiceStateMachine.MIN_SEVERITY, stateMachine.getOperationalStatus(bsChild2));
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(bsParent));
    // Verify that hierarchy works
    stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(testHierarchy.getServiceChild2().getIpService(), OnmsSeverity.MAJOR));
    assertEquals(4, handler.getStateChanges().size());
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(svc1));
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(bsChild1));
    assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(svc2));
    assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(bsChild2));
    assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(bsParent));
    // Verify that explicit reductionKeys work as well
    AlarmWrapper alarmWrapper = createAlarmWrapper(EventConstants.NODE_LOST_SERVICE_EVENT_UEI, OnmsSeverity.CRITICAL, "explicitReductionKey");
    stateMachine.handleNewOrUpdatedAlarm(alarmWrapper);
    assertEquals(6, handler.getStateChanges().size());
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(svc1));
    assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(svc2));
    assertEquals(Status.CRITICAL, stateMachine.getOperationalStatus(bsChild1));
    assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(bsChild2));
    assertEquals(Status.CRITICAL, stateMachine.getOperationalStatus(bsParent));
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) SimpleTestHierarchy(org.opennms.netmgt.bsm.test.hierarchies.SimpleTestHierarchy) AlarmWrapper(org.opennms.netmgt.bsm.service.model.AlarmWrapper) BsmTestUtils.createAlarmWrapper(org.opennms.netmgt.bsm.test.BsmTestUtils.createAlarmWrapper) LoggingStateChangeHandler(org.opennms.netmgt.bsm.test.LoggingStateChangeHandler) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) 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