Search in sources :

Example 1 with SingleReductionKeyEdgeEntity

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;
}
Also used : ReductionKeyEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.ReductionKeyEdgeImpl) IpService(org.opennms.netmgt.bsm.service.model.IpService) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) ReductionFunctionDao(org.opennms.netmgt.bsm.persistence.api.functions.reduce.ReductionFunctionDao) ChildEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.ChildEdgeImpl) BusinessServiceDao(org.opennms.netmgt.bsm.persistence.api.BusinessServiceDao) BusinessServiceManager(org.opennms.netmgt.bsm.service.BusinessServiceManager) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractReductionFunctionEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.AbstractReductionFunctionEntity) EventConstants(org.opennms.netmgt.events.api.EventConstants) MapFunction(org.opennms.netmgt.bsm.service.model.functions.map.MapFunction) BusinessServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) MonitoredServiceDao(org.opennms.netmgt.dao.api.MonitoredServiceDao) IpServiceEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.IpServiceEdgeImpl) BusinessServiceSearchCriteria(org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteria) AbstractEdge(org.opennms.netmgt.bsm.service.internal.edge.AbstractEdge) ReductionFunction(org.opennms.netmgt.bsm.service.model.functions.reduce.ReductionFunction) Status(org.opennms.netmgt.bsm.service.model.Status) BusinessServiceChildEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity) EdgeEntityVisitor(org.opennms.netmgt.bsm.persistence.api.EdgeEntityVisitor) NoSuchElementException(java.util.NoSuchElementException) ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) OnmsNode(org.opennms.netmgt.model.OnmsNode) NodeDao(org.opennms.netmgt.dao.api.NodeDao) AbstractMapFunctionEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.AbstractMapFunctionEntity) BusinessServiceEdgeDao(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeDao) Set(java.util.Set) BusinessServiceGraphImpl(org.opennms.netmgt.bsm.service.model.graph.internal.BusinessServiceGraphImpl) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) SingleReductionKeyEdgeEntity(org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity) Collectors(java.util.stream.Collectors) Criteria(org.opennms.core.criteria.Criteria) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) Objects(java.util.Objects) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) List(java.util.List) Node(org.opennms.netmgt.bsm.service.model.Node) Edge(org.opennms.netmgt.bsm.service.model.edge.Edge) MapFunctionDao(org.opennms.netmgt.bsm.persistence.api.functions.map.MapFunctionDao) EventForwarder(org.opennms.netmgt.events.api.EventForwarder) IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) SingleReductionKeyEdgeEntity(org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) ReductionKeyEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.ReductionKeyEdgeImpl) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge)

Example 2 with SingleReductionKeyEdgeEntity

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;
}
Also used : SingleReductionKeyEdgeEntity(org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity) IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) EdgeEntityVisitor(org.opennms.netmgt.bsm.persistence.api.EdgeEntityVisitor) BusinessServiceRequestDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceRequestDTO) BusinessServiceChildEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity)

Example 3 with SingleReductionKeyEdgeEntity

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()));
}
Also used : SingleReductionKeyEdgeEntity(org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) ReductionKeyEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.ReductionKeyEdgeImpl)

Example 4 with SingleReductionKeyEdgeEntity

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);
}
Also used : IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) SingleReductionKeyEdgeEntity(org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity) IpServiceEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.IpServiceEdgeImpl) ChildEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.ChildEdgeImpl) BusinessServiceChildEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity) ReductionKeyEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.ReductionKeyEdgeImpl)

Aggregations

SingleReductionKeyEdgeEntity (org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity)4 BusinessServiceChildEdgeEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity)3 IPServiceEdgeEntity (org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity)3 ReductionKeyEdgeImpl (org.opennms.netmgt.bsm.service.internal.edge.ReductionKeyEdgeImpl)3 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)2 EdgeEntityVisitor (org.opennms.netmgt.bsm.persistence.api.EdgeEntityVisitor)2 ChildEdgeImpl (org.opennms.netmgt.bsm.service.internal.edge.ChildEdgeImpl)2 IpServiceEdgeImpl (org.opennms.netmgt.bsm.service.internal.edge.IpServiceEdgeImpl)2 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Criteria (org.opennms.core.criteria.Criteria)1 BusinessServiceDao (org.opennms.netmgt.bsm.persistence.api.BusinessServiceDao)1 BusinessServiceEdgeDao (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeDao)1 BusinessServiceEdgeEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity)1 AbstractMapFunctionEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.AbstractMapFunctionEntity)1 MapFunctionDao (org.opennms.netmgt.bsm.persistence.api.functions.map.MapFunctionDao)1 AbstractReductionFunctionEntity (org.opennms.netmgt.bsm.persistence.api.functions.reduce.AbstractReductionFunctionEntity)1