use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity in project opennms by OpenNMS.
the class BsmTestUtils method toRequestDto.
public static BusinessServiceRequestDTO toRequestDto(BusinessServiceEntity input) {
Objects.requireNonNull(input);
BusinessServiceRequestDTO request = new BusinessServiceRequestDTO();
request.setName(input.getName());
request.setAttributes(new HashMap<>(input.getAttributes()));
request.setReduceFunction(transform(input.getReductionFunction()));
input.getEdges().forEach(eachEdge -> eachEdge.accept(new EdgeEntityVisitor<Void>() {
@Override
public Void visit(BusinessServiceChildEdgeEntity edgeEntity) {
request.addChildService(edgeEntity.getChild().getId(), transform(edgeEntity.getMapFunction()), edgeEntity.getWeight());
return null;
}
@Override
public Void visit(SingleReductionKeyEdgeEntity edgeEntity) {
request.addReductionKey(edgeEntity.getReductionKey(), transform(edgeEntity.getMapFunction()), edgeEntity.getWeight(), edgeEntity.getFriendlyName());
return null;
}
@Override
public Void visit(IPServiceEdgeEntity edgeEntity) {
request.addIpService(edgeEntity.getIpService().getId(), transform(edgeEntity.getMapFunction()), edgeEntity.getWeight(), edgeEntity.getFriendlyName());
return null;
}
}));
return request;
}
use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity 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.BusinessServiceChildEdgeEntity in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method createEdge.
@SuppressWarnings("unchecked")
private <T extends Edge> T createEdge(Class<T> type, BusinessService source, MapFunction mapFunction, int weight) {
T edge = null;
if (type == IpServiceEdge.class) {
edge = (T) new IpServiceEdgeImpl(this, new IPServiceEdgeEntity());
}
if (type == ChildEdge.class) {
edge = (T) new ChildEdgeImpl(this, new BusinessServiceChildEdgeEntity());
}
if (type == ReductionKeyEdge.class) {
edge = (T) new ReductionKeyEdgeImpl(this, new SingleReductionKeyEdgeEntity());
}
if (edge != null) {
edge.setSource(source);
edge.setMapFunction(mapFunction);
edge.setWeight(weight);
return edge;
}
throw new IllegalArgumentException("Could not create edge for type " + type);
}
use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity 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.BusinessServiceChildEdgeEntity 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;
}
Aggregations