Search in sources :

Example 1 with BusinessServiceEntity

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

the class BsmdIT method createBusinessService.

private BusinessServiceEntity createBusinessService(String name) {
    BusinessServiceEntity bs = new BusinessServiceEntity();
    bs.setName(name);
    bs.setReductionFunction(new HighestSeverityEntity());
    bs.setAttribute("my-attr-key", "my-attr-value");
    // Grab the first monitored service from node 1
    OnmsMonitoredService ipService = m_databasePopulator.getNode1().getIpInterfaces().iterator().next().getMonitoredServices().iterator().next();
    bs.addIpServiceEdge(ipService, new IdentityEntity());
    // Persist
    m_businessServiceDao.save(bs);
    m_businessServiceDao.flush();
    return bs;
}
Also used : BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity)

Example 2 with BusinessServiceEntity

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

the class BsmdIT method verifyReloadBsmd.

/**
     * Verifies that a reload of the Bsmd works as expected.
     */
@Test
@Transactional
public void verifyReloadBsmd() throws Exception {
    BusinessServiceEntity businessService1 = createBusinessService("service1");
    m_bsmd.start();
    Assert.assertEquals(Status.NORMAL, m_bsmd.getBusinessServiceStateMachine().getOperationalStatus(wrap(businessService1)));
    // verify reload of business services works when event is send
    BusinessServiceEntity businessService2 = createBusinessService("service2");
    Assert.assertNull(m_bsmd.getBusinessServiceStateMachine().getOperationalStatus(wrap(businessService2)));
    EventBuilder ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_UEI, "test");
    ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "bsmd");
    m_eventMgr.sendNow(ebldr.getEvent());
    Assert.assertEquals(Status.NORMAL, m_bsmd.getBusinessServiceStateMachine().getOperationalStatus(wrap(businessService2)));
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with BusinessServiceEntity

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

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

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

the class BsmdIT method verifyAlarmPollingIsEnabled.

/**
     * Verifies that the daemon polls the alarm table on a regular basis. This is done to ensure that all alarms are
     * considered, because the appropriate alarm created/changed/deleted/updated event may not have been sent.
     *
     */
@Test
public void verifyAlarmPollingIsEnabled() throws Exception {
    System.setProperty(Bsmd.POLL_INTERVAL_KEY, "10");
    BusinessServiceEntity simpleBs = createSimpleBusinessService();
    m_bsmd.start();
    // Create an alarm, but do NOT send any lifecyle events
    final AtomicReference<OnmsAlarm> alarmRef = new AtomicReference<>();
    template.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
            Assert.assertEquals(Status.NORMAL, m_bsmd.getBusinessServiceStateMachine().getOperationalStatus(wrap(simpleBs)));
            OnmsAlarm alarm = createAlarm();
            m_alarmDao.save(alarm);
            alarmRef.set(alarm);
            m_alarmDao.flush();
            Assert.assertEquals(Status.NORMAL, m_bsmd.getBusinessServiceStateMachine().getOperationalStatus(wrap(simpleBs)));
        }
    });
    // Wait for the business service status to be updated
    await().atMost(20, SECONDS).until(() -> m_bsmd.getBusinessServiceStateMachine().getOperationalStatus(wrap(simpleBs)), equalTo(Status.CRITICAL));
    // Now delete alarm, and again, do NOT send any lifecyle events
    template.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
            m_alarmDao.delete(alarmRef.get());
            m_alarmDao.flush();
        }
    });
    // Wait for the business service status to be updated
    await().atMost(20, SECONDS).until(() -> m_bsmd.getBusinessServiceStateMachine().getOperationalStatus(wrap(simpleBs)), equalTo(Status.NORMAL));
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) TransactionStatus(org.springframework.transaction.TransactionStatus) AtomicReference(java.util.concurrent.atomic.AtomicReference) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.Test)

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