Search in sources :

Example 1 with MapFunction

use of org.opennms.netmgt.bsm.service.model.functions.map.MapFunction 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 MapFunction

use of org.opennms.netmgt.bsm.service.model.functions.map.MapFunction in project opennms by OpenNMS.

the class BusinessServiceEdgeEditWindow method getMapFunction.

@SuppressWarnings("unchecked")
private MapFunction getMapFunction() {
    try {
        final MapFunction mapFunction = ((Class<? extends MapFunction>) m_mapFunctionSelect.getValue()).newInstance();
        mapFunction.accept(new MapFunctionVisitor<Void>() {

            @Override
            public Void visit(Decrease decrease) {
                return null;
            }

            @Override
            public Void visit(Identity identity) {
                return null;
            }

            @Override
            public Void visit(Ignore ignore) {
                return null;
            }

            @Override
            public Void visit(Increase increase) {
                return null;
            }

            @Override
            public Void visit(SetTo setTo) {
                setTo.setStatus((Status) m_mapFunctionSeveritySelect.getValue());
                return null;
            }
        });
        return mapFunction;
    } catch (final InstantiationException | IllegalAccessException e) {
        throw Throwables.propagate(e);
    }
}
Also used : Status(org.opennms.netmgt.bsm.service.model.Status) Ignore(org.opennms.netmgt.bsm.service.model.functions.map.Ignore) Increase(org.opennms.netmgt.bsm.service.model.functions.map.Increase) MapFunction(org.opennms.netmgt.bsm.service.model.functions.map.MapFunction) Decrease(org.opennms.netmgt.bsm.service.model.functions.map.Decrease) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) SetTo(org.opennms.netmgt.bsm.service.model.functions.map.SetTo)

Example 3 with MapFunction

use of org.opennms.netmgt.bsm.service.model.functions.map.MapFunction in project opennms by OpenNMS.

the class BusinessServiceManagerImpl method addIpServiceEdge.

@Override
public boolean addIpServiceEdge(BusinessService businessService, IpService ipService, MapFunction mapFunction, int weight, String friendlyName) {
    final BusinessServiceEntity parentEntity = getBusinessServiceEntity(businessService);
    // Create the edge
    final IpServiceEdge edge = createEdge(IpServiceEdge.class, businessService, mapFunction, weight);
    edge.setIpService(ipService);
    edge.setFriendlyName(friendlyName);
    // if already exists, no update
    final IPServiceEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(edge);
    long count = parentEntity.getIpServiceEdges().stream().filter(e -> e.equalsDefinition(edgeEntity)).count();
    if (count > 0) {
        return false;
    }
    parentEntity.addEdge(((IpServiceEdgeImpl) 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) IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge)

Example 4 with MapFunction

use of org.opennms.netmgt.bsm.service.model.functions.map.MapFunction 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;
}
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) ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) BusinessServiceChildEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)

Example 5 with MapFunction

use of org.opennms.netmgt.bsm.service.model.functions.map.MapFunction in project opennms by OpenNMS.

the class BsmTestUtils method transform.

private static MapFunctionDTO transform(AbstractMapFunctionEntity input) {
    Objects.requireNonNull(input);
    MapFunction mapFunction = new MapFunctionMapper().toServiceFunction(input);
    return new FunctionsManager().getMapFunctionDTO(mapFunction);
}
Also used : FunctionsManager(org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager) MapFunction(org.opennms.netmgt.bsm.service.model.functions.map.MapFunction)

Aggregations

MapFunction (org.opennms.netmgt.bsm.service.model.functions.map.MapFunction)5 Status (org.opennms.netmgt.bsm.service.model.Status)4 List (java.util.List)3 NoSuchElementException (java.util.NoSuchElementException)3 Objects (java.util.Objects)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Criteria (org.opennms.core.criteria.Criteria)3 BusinessServiceChildEdgeEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity)3 BusinessServiceDao (org.opennms.netmgt.bsm.persistence.api.BusinessServiceDao)3 BusinessServiceEdgeDao (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeDao)3 BusinessServiceEdgeEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity)3 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)3 EdgeEntityVisitor (org.opennms.netmgt.bsm.persistence.api.EdgeEntityVisitor)3 IPServiceEdgeEntity (org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity)3 SingleReductionKeyEdgeEntity (org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity)3 AbstractMapFunctionEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.AbstractMapFunctionEntity)3 MapFunctionDao (org.opennms.netmgt.bsm.persistence.api.functions.map.MapFunctionDao)3 AbstractReductionFunctionEntity (org.opennms.netmgt.bsm.persistence.api.functions.reduce.AbstractReductionFunctionEntity)3 ReductionFunctionDao (org.opennms.netmgt.bsm.persistence.api.functions.reduce.ReductionFunctionDao)3