use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity in project opennms by OpenNMS.
the class BusinessServiceEdgeDaoIT method canCreateReadUpdateAndDeleteEdges.
@Test
public void canCreateReadUpdateAndDeleteEdges() {
// Create a business service
BusinessServiceEntity bs = new BusinessServiceEntity();
bs.setName("Web Servers");
bs.setAttribute("dc", "RDU");
bs.setReductionFunction(m_highestSeverity);
m_businessServiceDao.save(bs);
m_businessServiceDao.flush();
// Initially there should be no edges
assertEquals(0, m_businessServiceEdgeDao.countAll());
// Create an edge
IPServiceEdgeEntity edge = new IPServiceEdgeEntity();
edge.setMapFunction(m_identity);
edge.setBusinessService(bs);
// Grab the first monitored service from node 1
OnmsMonitoredService ipService = m_databasePopulator.getNode1().getIpInterfaces().iterator().next().getMonitoredServices().iterator().next();
edge.setIpService(ipService);
m_businessServiceEdgeDao.save(edge);
m_businessServiceEdgeDao.flush();
// Read an edge
assertEquals(edge, m_businessServiceEdgeDao.get(edge.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.BusinessServiceEdgeEntity in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method getBusinessServiceEdgeEntity.
private BusinessServiceEdgeEntity getBusinessServiceEdgeEntity(Long edgeId) {
Objects.requireNonNull(edgeId);
BusinessServiceEdgeEntity edgeEntity = edgeDao.get(edgeId);
if (edgeEntity == null) {
throw new NoSuchElementException("BusinessServiceEdgeEntity with id " + edgeId);
}
return edgeEntity;
}
use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method setMapFunction.
@Override
public void setMapFunction(final Edge edge, final MapFunction mapFunction) {
// This is a workaround for a hibernate bug which does not remove
// orphan elements if the element is replaced using the setter. See:
// https://hibernate.atlassian.net/browse/HHH-6484
final BusinessServiceEdgeEntity edgeEntity = this.getBusinessServiceEdgeEntity(edge);
final AbstractMapFunctionEntity prevMapFunctionEntity = edgeEntity.getMapFunction();
if (prevMapFunctionEntity != null && prevMapFunctionEntity.getId() != null) {
this.mapFunctionDao.delete(prevMapFunctionEntity);
}
final AbstractMapFunctionEntity mapFunctionEntity = new MapFunctionMapper().toPersistenceFunction(mapFunction);
edgeEntity.setMapFunction(mapFunctionEntity);
}
use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method deleteEdge.
@Override
public boolean deleteEdge(BusinessService source, Edge edge) {
BusinessServiceEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(edge);
BusinessServiceEntity businessServiceEntity = getBusinessServiceEntity(source);
// does not exist, no update necessary
if (!businessServiceEntity.getEdges().contains(edgeEntity)) {
return false;
}
// remove and update
businessServiceEntity.removeEdge(edgeEntity);
return true;
}
use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity 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());
}
Aggregations