use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method saveBusinessService.
@Override
public void saveBusinessService(BusinessService service) {
BusinessServiceEntity entity = getBusinessServiceEntity(service);
getDao().saveOrUpdate(entity);
}
use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method setChildEdges.
@Override
public void setChildEdges(BusinessService parentService, Set<ChildEdge> childEdges) {
final BusinessServiceEntity parentEntity = getBusinessServiceEntity(parentService);
for (final BusinessServiceChildEdgeEntity e : parentEntity.getChildEdges()) {
parentEntity.removeEdge(e);
}
childEdges.forEach(e -> parentEntity.addEdge(((ChildEdgeImpl) e).getEntity()));
}
use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method addChildEdge.
@Override
public boolean addChildEdge(BusinessService parentService, BusinessService childService, MapFunction mapFunction, int weight) {
// verify that exists
final BusinessServiceEntity parentEntity = getBusinessServiceEntity(parentService);
final BusinessServiceEntity childEntity = getBusinessServiceEntity(childService);
// Create the edge
ChildEdge childEdge = createEdge(ChildEdge.class, parentService, mapFunction, weight);
childEdge.setChild(childService);
// Verify no loop
if (this.checkDescendantForLoop(parentEntity, childEntity)) {
throw new IllegalArgumentException("Service will form a loop");
}
// if already exists, no update
final BusinessServiceChildEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(childEdge);
long count = parentEntity.getChildEdges().stream().filter(e -> e.equalsDefinition(edgeEntity)).count();
if (count > 0) {
return false;
}
parentEntity.addEdge(((ChildEdgeImpl) childEdge).getEntity());
return true;
}
use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity 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());
}
use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity 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);
}
Aggregations