use of org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method addReductionKeyEdge.
@Override
public boolean addReductionKeyEdge(BusinessService businessService, String reductionKey, MapFunction mapFunction, int weight, String friendlyName) {
final BusinessServiceEntity parentEntity = getBusinessServiceEntity(businessService);
// Create the edge
final ReductionKeyEdgeImpl edge = (ReductionKeyEdgeImpl) createEdge(ReductionKeyEdge.class, businessService, mapFunction, weight);
edge.setReductionKey(reductionKey);
edge.setFriendlyName(friendlyName);
// if already exists, no update
final SingleReductionKeyEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(edge);
long count = parentEntity.getReductionKeyEdges().stream().filter(e -> e.equalsDefinition(edgeEntity)).count();
if (count > 0) {
return false;
}
parentEntity.addEdge(edge.getEntity());
return true;
}
use of org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity 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.SingleReductionKeyEdgeEntity in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method setReductionKeyEdges.
@Override
public void setReductionKeyEdges(BusinessService businessService, Set<ReductionKeyEdge> reductionKeyEdges) {
final BusinessServiceEntity parentEntity = getBusinessServiceEntity(businessService);
for (final SingleReductionKeyEdgeEntity e : parentEntity.getReductionKeyEdges()) {
parentEntity.removeEdge(e);
}
reductionKeyEdges.forEach(e -> parentEntity.addEdge(((ReductionKeyEdgeImpl) e).getEntity()));
}
use of org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity 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);
}
Aggregations