Search in sources :

Example 1 with BusinessServiceChildEdgeEntity

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;
}
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 2 with BusinessServiceChildEdgeEntity

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());
}
Also used : BusinessServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity) BusinessServiceChildEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test)

Example 3 with BusinessServiceChildEdgeEntity

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);
}
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)

Example 4 with BusinessServiceChildEdgeEntity

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

Example 5 with BusinessServiceChildEdgeEntity

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;
}
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)

Aggregations

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