Search in sources :

Example 31 with BusinessServiceEntity

use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.

the class BusinessServiceManagerImpl method setReduceFunction.

@Override
public void setReduceFunction(final BusinessService businessService, final ReductionFunction reductionFunction) {
    // This is a workaround for a hibernate bug which does not remove
    // orphan elements if the element is replaced using the setter. See:
    // https://hibernate.atlassian.net/browse/HHH-6484
    final BusinessServiceEntity entity = this.getBusinessServiceEntity(businessService);
    final AbstractReductionFunctionEntity prevReduceFunctionEntity = entity.getReductionFunction();
    if (prevReduceFunctionEntity != null && prevReduceFunctionEntity.getId() != null) {
        this.reductionFunctionDao.delete(prevReduceFunctionEntity);
    }
    final AbstractReductionFunctionEntity reduceFunctionEntity = new ReduceFunctionMapper().toPersistenceFunction(reductionFunction);
    entity.setReductionFunction(reduceFunctionEntity);
}
Also used : AbstractReductionFunctionEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.AbstractReductionFunctionEntity) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)

Example 32 with BusinessServiceEntity

use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity 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 33 with BusinessServiceEntity

use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.

the class BusinessServiceManagerImpl method getBusinessServiceEntity.

private BusinessServiceEntity getBusinessServiceEntity(Long serviceId) throws NoSuchElementException {
    Objects.requireNonNull(serviceId);
    final BusinessServiceEntity entity = getDao().get(serviceId);
    if (entity == null) {
        throw new NoSuchElementException("BusinessServiceEntity with id " + serviceId);
    }
    return entity;
}
Also used : BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) NoSuchElementException(java.util.NoSuchElementException)

Example 34 with BusinessServiceEntity

use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.

the class BusinessServiceManagerImpl method removeEdge.

@Override
public void removeEdge(final BusinessService businessService, final Edge edge) {
    final BusinessServiceEntity businessServiceEntity = getBusinessServiceEntity(businessService);
    final BusinessServiceEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(edge);
    businessServiceEntity.removeEdge(edgeEntity);
}
Also used : BusinessServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)

Example 35 with BusinessServiceEntity

use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity 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)

Aggregations

BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)45 Test (org.junit.Test)29 BusinessServiceEntityBuilder (org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder)18 IdentityEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity)14 HighestSeverityEntity (org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity)14 Transactional (org.springframework.transaction.annotation.Transactional)10 IPServiceEdgeEntity (org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity)9 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)9 BusinessServiceEdgeEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity)8 Criteria (org.opennms.core.criteria.Criteria)7 BusinessServiceChildEdgeEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity)7 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)7 NoSuchElementException (java.util.NoSuchElementException)6 Set (java.util.Set)6 IpServiceEdgeImpl (org.opennms.netmgt.bsm.service.internal.edge.IpServiceEdgeImpl)6 OnmsNode (org.opennms.netmgt.model.OnmsNode)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 BusinessServiceDao (org.opennms.netmgt.bsm.persistence.api.BusinessServiceDao)5 SingleReductionKeyEdgeEntity (org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity)5