use of org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity 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.functions.map.IdentityEntity in project opennms by OpenNMS.
the class AbstractBusinessServiceRestServiceIT method canUpdateBusinessService.
@Test
public void canUpdateBusinessService() throws Exception {
// initialize
BusinessServiceEntity bs = new BusinessServiceEntityBuilder().name("Dummy Service").addAttribute("some-key", "some-value").addReductionKey("key1", new IdentityEntity()).addReductionKey("key2-deleteMe", new IdentityEntity()).reduceFunction(new HighestSeverityEntity()).toEntity();
final Long serviceId = m_businessServiceDao.save(bs);
m_businessServiceDao.flush();
// update
BusinessServiceRequestDTO requestDTO = toRequestDto(bs);
requestDTO.setName("New Name");
requestDTO.getAttributes().put("key", "value");
requestDTO.getReductionKeys().clear();
requestDTO.addReductionKey("key1updated", new FunctionsManager().getMapFunctionDTO(new Ignore()), Edge.DEFAULT_WEIGHT);
sendData(PUT, getMediaType(), "/business-services/" + serviceId, marshal(requestDTO), 204);
// Reload from database and verify changes
bs = m_businessServiceDao.get(serviceId);
Assert.assertEquals(requestDTO.getName(), bs.getName());
Assert.assertEquals(requestDTO.getAttributes(), bs.getAttributes());
Assert.assertEquals(1, bs.getReductionKeyEdges().size());
Assert.assertEquals(1, bs.getEdges().size());
Assert.assertEquals(1, m_businessServiceDao.findAll().size());
Assert.assertEquals(Sets.newHashSet(), bs.getIpServiceEdges());
BusinessServiceResponseDTO responseDTO = verifyResponse(bs);
verifyReductionKey("key1updated", responseDTO);
}
use of org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity in project opennms by OpenNMS.
the class BusinessServiceDaoIT method verifyDeleteOnCascade.
/**
* If we do not explicitly delete the map or reduce function it should be deleted if not referenced anymore.
*/
@Test
@Transactional
public void verifyDeleteOnCascade() {
BusinessServiceEntity child2 = new BusinessServiceEntityBuilder().name("Child 2").reduceFunction(new HighestSeverityEntity()).addReductionKey("some-key", new IdentityEntity()).toEntity();
BusinessServiceEntity child1 = new BusinessServiceEntityBuilder().name("Child 1").reduceFunction(new HighestSeverityEntity()).addChildren(child2, new IdentityEntity()).toEntity();
BusinessServiceEntity parent = new BusinessServiceEntityBuilder().name("Parent Web Servers").addAttribute("dc", "RDU").addReductionKey("TestReductionKeyA", new IdentityEntity()).addReductionKey("TestReductionKeyB", new IdentityEntity()).addIpService(getMonitoredServiceFromNode1(), new IdentityEntity()).reduceFunction(m_highestSeverity).addChildren(child1, new IdentityEntity()).toEntity();
m_businessServiceDao.save(child2);
m_businessServiceDao.save(child1);
m_businessServiceDao.save(parent);
m_businessServiceDao.flush();
assertEquals(3, m_businessServiceDao.countAll());
assertEquals(3, m_reductionFunctionDao.countAll());
assertEquals(6, m_edgeDao.countAll());
// Deletion of child does not delete the edges referencing to that child
// remove all parent -> child associations manually
BusinessServiceChildEdgeEntity parentToChild1Edge = parent.getChildEdges().iterator().next();
parent.removeEdge(parentToChild1Edge);
m_edgeDao.delete(parentToChild1Edge);
// edges do not need to be deleted manually, deletes will be cascaded
m_businessServiceDao.delete(child1);
m_businessServiceDao.flush();
assertEquals(2, m_businessServiceDao.countAll());
assertEquals(2, m_reductionFunctionDao.countAll());
assertEquals(4, m_edgeDao.countAll());
// Deletion of parent should delete all references
m_businessServiceDao.delete(parent);
assertEquals(1, m_businessServiceDao.countAll());
assertEquals(1, m_reductionFunctionDao.countAll());
assertEquals(1, m_edgeDao.countAll());
// Deletion of Child 2 should also work
m_businessServiceDao.delete(child2);
assertEquals(0, m_businessServiceDao.countAll());
assertEquals(0, m_reductionFunctionDao.countAll());
assertEquals(0, m_edgeDao.countAll());
}
use of org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachineIT method ensureReductionKeyLookupIsFastEnough.
/**
* Builds 200 business services.
* Each business Services has one parent and two children.
* Each children has 12 reduction key edges.
* In sum there are:
* - 600 business services
* - 4800 reduction key edges
* - 400 child edges
* - 5200 edges
*
* See NMS-8978 for more details.
*/
@Test
public void ensureReductionKeyLookupIsFastEnough() {
for (int i = 0; i < 200; i++) {
BusinessServiceEntity parentEntity = new BusinessServiceEntityBuilder().name("Parent " + i).reduceFunction(new HighestSeverityEntity()).toEntity();
for (int c = 0; c < 2; c++) {
BusinessServiceEntityBuilder childBuilder = new BusinessServiceEntityBuilder().name("Child " + i + " " + c).reduceFunction(new HighestSeverityEntity());
for (int a = 0; a < 12; a++) {
childBuilder.addReductionKey("custom." + i + "." + c + "." + a, new IdentityEntity());
}
BusinessServiceEntity childEntity = childBuilder.toEntity();
parentEntity.addChildServiceEdge(childEntity, new IdentityEntity());
businessServiceDao.save(childEntity);
}
businessServiceDao.save(parentEntity);
}
final Set<String> uniqueReductionKeys = businessServiceDao.findMatching(new CriteriaBuilder(BusinessServiceEntity.class).like("name", "Child%").toCriteria()).stream().flatMap(service -> service.getReductionKeyEdges().stream()).flatMap(edge -> edge.getReductionKeys().stream()).collect(Collectors.toSet());
for (String eachKey : uniqueReductionKeys) {
final OnmsAlarm alarm = new OnmsAlarm();
alarm.setUei("custom");
alarm.setAlarmType(OnmsAlarm.PROBLEM_TYPE);
alarm.setDescription("dummy");
alarm.setLogMsg("dummy");
alarm.setSeverity(OnmsSeverity.WARNING);
alarm.setReductionKey(eachKey);
alarm.setDistPoller(distPollerDao.whoami());
alarm.setCounter(1);
populator.getAlarmDao().save(alarm);
}
populator.getAlarmDao().flush();
businessServiceDao.flush();
// Simulate lookup of reduction keys
final long start = System.currentTimeMillis();
final DefaultBusinessServiceStateMachine stateMachine = new DefaultBusinessServiceStateMachine();
stateMachine.setAlarmProvider(alarmProvider);
stateMachine.setBusinessServices(businessServiceDao.findAll().stream().map(e -> new BusinessServiceImpl(businessServiceManager, e)).collect(Collectors.toList()));
long diff = System.currentTimeMillis() - start;
LoggerFactory.getLogger(getClass()).info("Took {} ms to initialize state machine", diff);
Assert.assertTrue("Reduction Key lookup took much longer than expected. Expected was 1000 ms, but took " + diff + " ms", 1000 >= diff);
}
Aggregations