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