Search in sources :

Example 1 with BusinessServiceEdgeEntity

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

the class BusinessServiceEdgeDaoIT method canCreateReadUpdateAndDeleteEdges.

@Test
public void canCreateReadUpdateAndDeleteEdges() {
    // Create a business service
    BusinessServiceEntity bs = new BusinessServiceEntity();
    bs.setName("Web Servers");
    bs.setAttribute("dc", "RDU");
    bs.setReductionFunction(m_highestSeverity);
    m_businessServiceDao.save(bs);
    m_businessServiceDao.flush();
    // Initially there should be no edges
    assertEquals(0, m_businessServiceEdgeDao.countAll());
    // Create an edge
    IPServiceEdgeEntity edge = new IPServiceEdgeEntity();
    edge.setMapFunction(m_identity);
    edge.setBusinessService(bs);
    // Grab the first monitored service from node 1
    OnmsMonitoredService ipService = m_databasePopulator.getNode1().getIpInterfaces().iterator().next().getMonitoredServices().iterator().next();
    edge.setIpService(ipService);
    m_businessServiceEdgeDao.save(edge);
    m_businessServiceEdgeDao.flush();
    // Read an edge
    assertEquals(edge, m_businessServiceEdgeDao.get(edge.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 : IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) BusinessServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test)

Example 2 with BusinessServiceEdgeEntity

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

the class BusinessServiceManagerImpl method getBusinessServiceEdgeEntity.

private BusinessServiceEdgeEntity getBusinessServiceEdgeEntity(Long edgeId) {
    Objects.requireNonNull(edgeId);
    BusinessServiceEdgeEntity edgeEntity = edgeDao.get(edgeId);
    if (edgeEntity == null) {
        throw new NoSuchElementException("BusinessServiceEdgeEntity with id " + edgeId);
    }
    return edgeEntity;
}
Also used : BusinessServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with BusinessServiceEdgeEntity

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

the class BusinessServiceManagerImpl method setMapFunction.

@Override
public void setMapFunction(final Edge edge, final MapFunction mapFunction) {
    // 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 BusinessServiceEdgeEntity edgeEntity = this.getBusinessServiceEdgeEntity(edge);
    final AbstractMapFunctionEntity prevMapFunctionEntity = edgeEntity.getMapFunction();
    if (prevMapFunctionEntity != null && prevMapFunctionEntity.getId() != null) {
        this.mapFunctionDao.delete(prevMapFunctionEntity);
    }
    final AbstractMapFunctionEntity mapFunctionEntity = new MapFunctionMapper().toPersistenceFunction(mapFunction);
    edgeEntity.setMapFunction(mapFunctionEntity);
}
Also used : BusinessServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity) AbstractMapFunctionEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.AbstractMapFunctionEntity)

Example 4 with BusinessServiceEdgeEntity

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

the class BusinessServiceManagerImpl method deleteEdge.

@Override
public boolean deleteEdge(BusinessService source, Edge edge) {
    BusinessServiceEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(edge);
    BusinessServiceEntity businessServiceEntity = getBusinessServiceEntity(source);
    // does not exist, no update necessary
    if (!businessServiceEntity.getEdges().contains(edgeEntity)) {
        return false;
    }
    // remove and update
    businessServiceEntity.removeEdge(edgeEntity);
    return true;
}
Also used : BusinessServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)

Example 5 with BusinessServiceEdgeEntity

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

Aggregations

BusinessServiceEdgeEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity)6 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)4 Test (org.junit.Test)2 NoSuchElementException (java.util.NoSuchElementException)1 BusinessServiceChildEdgeEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity)1 IPServiceEdgeEntity (org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity)1 AbstractMapFunctionEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.AbstractMapFunctionEntity)1 IdentityEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity)1 HighestSeverityEntity (org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity)1 BusinessServiceEntityBuilder (org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder)1 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)1