Search in sources :

Example 1 with IPServiceEdgeEntity

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

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

the class FriendlyNameValidationTest method friendlyNameTooLong.

@Test
public void friendlyNameTooLong() {
    IdentityEntity identityEntity = new IdentityEntity();
    IPServiceEdgeEntity edge = new IPServiceEdgeEntity();
    edge.setFriendlyName(FRIENDLYNAME_TOO_LONG);
    edge.setMapFunction(identityEntity);
    validator.validate(edge);
    Set<ConstraintViolation<IPServiceEdgeEntity>> constraintViolations = validator.validate(edge);
    Assert.assertEquals(1, constraintViolations.size());
}
Also used : IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) ConstraintViolation(javax.validation.ConstraintViolation) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test)

Example 3 with IPServiceEdgeEntity

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

the class FriendlyNameValidationTest method friendlyNameMaximum.

@Test
public void friendlyNameMaximum() {
    IdentityEntity identityEntity = new IdentityEntity();
    IPServiceEdgeEntity edge = new IPServiceEdgeEntity();
    edge.setFriendlyName(FRIENDLYNAME_THIRTY_CHARS);
    edge.setMapFunction(identityEntity);
    validator.validate(edge);
    Set<ConstraintViolation<IPServiceEdgeEntity>> constraintViolations = validator.validate(edge);
    Assert.assertEquals(0, constraintViolations.size());
}
Also used : IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) ConstraintViolation(javax.validation.ConstraintViolation) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test)

Example 4 with IPServiceEdgeEntity

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

the class IPServiceEdgeDaoIT method ipServiceEdgesWithRelatedIpServicesAreDeletedOnCascade.

@Test
public void ipServiceEdgesWithRelatedIpServicesAreDeletedOnCascade() throws InterruptedException {
    // Create a business service
    BusinessServiceEntity bs = new BusinessServiceEntity();
    bs.setName("Mont Cascades");
    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
    OnmsNode node = m_databasePopulator.getNode1();
    OnmsMonitoredService ipService = node.getIpInterfaces().iterator().next().getMonitoredServices().iterator().next();
    edge.setIpService(ipService);
    m_businessServiceEdgeDao.save(edge);
    m_businessServiceEdgeDao.flush();
    bs.addEdge(edge);
    m_businessServiceDao.update(bs);
    m_businessServiceDao.flush();
    // We should have a single business service with a single IP service associated
    assertEquals(1, m_businessServiceDao.countAll());
    assertEquals(1, m_businessServiceDao.get(bs.getId()).getIpServiceEdges().size());
    // Now delete the node
    m_nodeDao.delete(node);
    m_nodeDao.flush();
    // The business service should still be present, but the IP service should have been deleted
    // by the foreign key constraint
    assertEquals(1, m_businessServiceDao.countAll());
    assertEquals(0, m_businessServiceDao.get(bs.getId()).getIpServiceEdges().size());
}
Also used : IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) OnmsNode(org.opennms.netmgt.model.OnmsNode) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test)

Example 5 with IPServiceEdgeEntity

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

the class BusinessServiceManagerImpl method setIpServiceEdges.

@Override
public void setIpServiceEdges(BusinessService businessService, Set<IpServiceEdge> ipServiceEdges) {
    final BusinessServiceEntity entity = getBusinessServiceEntity(businessService);
    for (final IPServiceEdgeEntity e : entity.getIpServiceEdges()) {
        entity.removeEdge(e);
    }
    ipServiceEdges.forEach(e -> entity.addEdge(((IpServiceEdgeImpl) e).getEntity()));
}
Also used : IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) IpServiceEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.IpServiceEdgeImpl) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)

Aggregations

IPServiceEdgeEntity (org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity)10 Test (org.junit.Test)6 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)5 ConstraintViolation (javax.validation.ConstraintViolation)3 BusinessServiceChildEdgeEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity)3 SingleReductionKeyEdgeEntity (org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity)3 IdentityEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity)3 IpServiceEdgeImpl (org.opennms.netmgt.bsm.service.internal.edge.IpServiceEdgeImpl)3 BusinessServiceEdgeEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity)2 EdgeEntityVisitor (org.opennms.netmgt.bsm.persistence.api.EdgeEntityVisitor)2 ChildEdgeImpl (org.opennms.netmgt.bsm.service.internal.edge.ChildEdgeImpl)2 ReductionKeyEdgeImpl (org.opennms.netmgt.bsm.service.internal.edge.ReductionKeyEdgeImpl)2 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)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