use of org.opennms.netmgt.bsm.service.internal.edge.ChildEdgeImpl 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.service.internal.edge.ChildEdgeImpl 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.service.internal.edge.ChildEdgeImpl 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