Search in sources :

Example 26 with BusinessServiceEntity

use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.

the class BusinessServiceDaoIT method canCreateReadUpdateAndDeleteBusinessServices.

@Test
@Transactional
public void canCreateReadUpdateAndDeleteBusinessServices() {
    final int ifServiceCount = m_monitoredServiceDao.countAll();
    // Initially there should be no business services
    assertEquals(0, m_businessServiceDao.countAll());
    // Create a business service
    BusinessServiceEntity bs = new BusinessServiceEntityBuilder().name("Web Servers").addAttribute("dc", "RDU").addReductionKey("TestReductionKeyA", new IdentityEntity()).addReductionKey("TestReductionKeyB", new IdentityEntity()).reduceFunction(m_highestSeverity).toEntity();
    m_businessServiceDao.save(bs);
    m_businessServiceDao.flush();
    // Read a business service
    assertEquals(bs, m_businessServiceDao.get(bs.getId()));
    assertEquals(2, m_businessServiceDao.get(bs.getId()).getReductionKeyEdges().size());
    // Update a business service
    bs.setName("Application Servers");
    bs.getAttributes().put("dc", "!RDU");
    bs.getAttributes().put("cd", "/");
    // Grab the first monitored service from node 1
    OnmsMonitoredService ipService = m_databasePopulator.getNode1().getIpInterfaces().iterator().next().getMonitoredServices().iterator().next();
    bs.addIpServiceEdge(ipService, m_ignore);
    m_businessServiceDao.update(bs);
    m_businessServiceDao.flush();
    // Verify the update
    assertEquals(bs, m_businessServiceDao.get(bs.getId()));
    // Delete
    m_businessServiceDao.delete(bs);
    m_businessServiceDao.flush();
    // There should be no business services after the delete
    assertEquals(0, m_businessServiceDao.countAll());
    // No if service should have been deleted
    assertEquals(ifServiceCount, m_monitoredServiceDao.countAll());
}
Also used : BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 27 with BusinessServiceEntity

use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.

the class BusinessServiceDaoIT method verifyBusinessServicesWithRelatedIpServicesAreDeletedOnCascade.

@Test
@Transactional
public void verifyBusinessServicesWithRelatedIpServicesAreDeletedOnCascade() throws InterruptedException {
    // Initially there should be no business services
    assertEquals("Check that there are no initial BusinessServices", 0, m_businessServiceDao.countAll());
    // Create a business service with an associated IP Service
    final BusinessServiceEntity bs = new BusinessServiceEntity();
    bs.setName("Mont Cascades");
    bs.setReductionFunction(m_highestSeverity);
    final OnmsNode node = m_databasePopulator.getNode1();
    final OnmsMonitoredService ipService = getMonitoredServiceFromNode1();
    bs.addIpServiceEdge(ipService, m_ignore);
    m_businessServiceDao.save(bs);
    m_businessServiceDao.flush();
    // We should have a single business service with a single IP service associated
    assertEquals(1, m_businessServiceDao.countAll());
    assertEquals(1, m_businessServiceDao.get(bs.getId()).getIpServiceEdges().size());
    assertNotNull(m_monitoredServiceDao.get(ipService.getId()));
    // Now delete the node
    m_nodeDao.delete(node);
    m_nodeDao.flush();
    // The business service should still be present, but the IP service should have been deleted by the foreign
    // key constraint. We have to clear the session, otherwise hibernate does not know about the node deletion
    m_businessServiceDao.clear();
    assertEquals(1, m_businessServiceDao.countAll());
    assertEquals(0, m_businessServiceDao.get(bs.getId()).getIpServiceEdges().size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with BusinessServiceEntity

use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.

the class BusinessServiceChildEdgeIT method canCreateReadUpdateAndDeleteEdges.

@Test
public void canCreateReadUpdateAndDeleteEdges() {
    // Create the Parent Business Service
    BusinessServiceEntity parent = new BusinessServiceEntityBuilder().name("Parent Service").reduceFunction(new HighestSeverityEntity()).toEntity();
    // Create the Child Business Service
    BusinessServiceEntity child = new BusinessServiceEntityBuilder().name("Child Service").reduceFunction(new HighestSeverityEntity()).toEntity();
    Long parentServiceId = m_businessServiceDao.save(parent);
    Long childServiceId = m_businessServiceDao.save(child);
    m_businessServiceDao.flush();
    // Initially there should be no edges
    assertEquals(0, m_businessServiceEdgeDao.countAll());
    // Create an edge
    BusinessServiceChildEdgeEntity edge = new BusinessServiceChildEdgeEntity();
    edge.setMapFunction(new IdentityEntity());
    edge.setBusinessService(parent);
    edge.setChild(child);
    m_businessServiceEdgeDao.save(edge);
    m_businessServiceEdgeDao.flush();
    // Read an edge
    assertEquals(1, m_businessServiceEdgeDao.countAll());
    assertEquals(edge, m_businessServiceEdgeDao.get(edge.getId()));
    assertEquals(parentServiceId, edge.getBusinessService().getId());
    assertEquals(childServiceId, edge.getChild().getId());
    // Update an edge
    edge.setWeight(2);
    m_businessServiceEdgeDao.save(edge);
    m_businessServiceEdgeDao.flush();
    BusinessServiceEdgeEntity otherEdge = m_businessServiceEdgeDao.get(edge.getId());
    assertEquals(edge, otherEdge);
    assertEquals(1, m_businessServiceEdgeDao.countAll());
    // Delete an edge
    m_businessServiceEdgeDao.delete(edge);
    assertEquals(0, m_businessServiceEdgeDao.countAll());
}
Also used : BusinessServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity) BusinessServiceChildEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test)

Example 29 with BusinessServiceEntity

use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.

the class AbstractBusinessServiceRestServiceIT method canCreateBusinessService.

@Test
public void canCreateBusinessService() throws Exception {
    final BusinessServiceEntity bs = new BusinessServiceEntityBuilder().name("some-service").addAttribute("some-key", "some-value").reduceFunction(new HighestSeverityEntity()).addReductionKey("reductionKey-1", new IdentityEntity()).addReductionKey("reductionKey-2", new IdentityEntity()).addReductionKey("reductionKey-3", new IdentityEntity()).toEntity();
    sendData(POST, getMediaType(), "/business-services", marshal(toRequestDto(bs)), 201);
    Assert.assertEquals(1, m_businessServiceDao.countAll());
    for (BusinessServiceEntity eachEntity : m_businessServiceDao.findAll()) {
        BusinessServiceResponseDTO responseDTO = verifyResponse(eachEntity);
        Assert.assertEquals(3, responseDTO.getReductionKeys().size());
    }
}
Also used : BusinessServiceResponseDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test)

Example 30 with BusinessServiceEntity

use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity 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)

Aggregations

BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)45 Test (org.junit.Test)29 BusinessServiceEntityBuilder (org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder)18 IdentityEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity)14 HighestSeverityEntity (org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity)14 Transactional (org.springframework.transaction.annotation.Transactional)10 IPServiceEdgeEntity (org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity)9 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)9 BusinessServiceEdgeEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity)8 Criteria (org.opennms.core.criteria.Criteria)7 BusinessServiceChildEdgeEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity)7 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)7 NoSuchElementException (java.util.NoSuchElementException)6 Set (java.util.Set)6 IpServiceEdgeImpl (org.opennms.netmgt.bsm.service.internal.edge.IpServiceEdgeImpl)6 OnmsNode (org.opennms.netmgt.model.OnmsNode)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 BusinessServiceDao (org.opennms.netmgt.bsm.persistence.api.BusinessServiceDao)5 SingleReductionKeyEdgeEntity (org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity)5