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