use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.
the class BusinessServiceManagerImplIT method testLoopDetection.
@Test
public void testLoopDetection() {
BusinessServiceEntity service1 = createDummyBusinessService("Business Service #1");
BusinessServiceEntity service2 = createDummyBusinessService("Business Service #2");
BusinessServiceEntity service3 = createDummyBusinessService("Business Service #3");
Long serviceId1 = businessServiceDao.save(service1);
Long serviceId2 = businessServiceDao.save(service2);
Long serviceId3 = businessServiceDao.save(service3);
BusinessService bs1 = getBusinessService(serviceId1);
BusinessService bs2 = getBusinessService(serviceId2);
BusinessService bs3 = getBusinessService(serviceId3);
Assert.assertEquals(ImmutableSet.of(businessServiceManager.getBusinessServiceById(serviceId2), businessServiceManager.getBusinessServiceById(serviceId3)), businessServiceManager.getFeasibleChildServices(businessServiceManager.getBusinessServiceById(serviceId1)));
Assert.assertEquals(ImmutableSet.of(businessServiceManager.getBusinessServiceById(serviceId1), businessServiceManager.getBusinessServiceById(serviceId3)), businessServiceManager.getFeasibleChildServices(businessServiceManager.getBusinessServiceById(serviceId2)));
Assert.assertEquals(ImmutableSet.of(businessServiceManager.getBusinessServiceById(serviceId1), businessServiceManager.getBusinessServiceById(serviceId2)), businessServiceManager.getFeasibleChildServices(businessServiceManager.getBusinessServiceById(serviceId3)));
businessServiceManager.addChildEdge(bs1, bs2, new Identity(), Edge.DEFAULT_WEIGHT);
bs1.save();
bs2.save();
Assert.assertEquals(ImmutableSet.of(businessServiceManager.getBusinessServiceById(serviceId2), businessServiceManager.getBusinessServiceById(serviceId3)), businessServiceManager.getFeasibleChildServices(businessServiceManager.getBusinessServiceById(serviceId1)));
Assert.assertEquals(ImmutableSet.of(businessServiceManager.getBusinessServiceById(serviceId3)), businessServiceManager.getFeasibleChildServices(businessServiceManager.getBusinessServiceById(serviceId2)));
Assert.assertEquals(ImmutableSet.of(businessServiceManager.getBusinessServiceById(serviceId1), businessServiceManager.getBusinessServiceById(serviceId2)), businessServiceManager.getFeasibleChildServices(businessServiceManager.getBusinessServiceById(serviceId3)));
businessServiceManager.addChildEdge(bs2, bs3, new Identity(), Edge.DEFAULT_WEIGHT);
bs2.save();
bs3.save();
Assert.assertEquals(ImmutableSet.of(businessServiceManager.getBusinessServiceById(serviceId2), businessServiceManager.getBusinessServiceById(serviceId3)), businessServiceManager.getFeasibleChildServices(businessServiceManager.getBusinessServiceById(serviceId1)));
Assert.assertEquals(ImmutableSet.of(businessServiceManager.getBusinessServiceById(serviceId3)), businessServiceManager.getFeasibleChildServices(businessServiceManager.getBusinessServiceById(serviceId2)));
Assert.assertEquals(ImmutableSet.of(), businessServiceManager.getFeasibleChildServices(businessServiceManager.getBusinessServiceById(serviceId3)));
}
use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.
the class BsmdIT method canSendEventsOnOperationalStatusChanged.
/**
* Verifies that the daemon generates events when the operational status
* of a Business Service is changed.
*
* Also verifies that the generate events include parameters which map
* to the business services attributes.
*
* @throws Exception
*/
@Test
@Transactional
public void canSendEventsOnOperationalStatusChanged() throws Exception {
// Create a business service
BusinessServiceEntity simpleBs = createSimpleBusinessService();
// Start the daemon
m_bsmd.start();
// Expect a statusChanged event
EventBuilder ebldr = new EventBuilder(EventConstants.BUSINESS_SERVICE_OPERATIONAL_STATUS_CHANGED_UEI, "test");
m_eventMgr.getEventAnticipator().anticipateEvent(ebldr.getEvent());
// Expect a serviceProblem event
ebldr = new EventBuilder(EventConstants.BUSINESS_SERVICE_PROBLEM_UEI, "test");
m_eventMgr.getEventAnticipator().anticipateEvent(ebldr.getEvent());
// Create the alarm
OnmsAlarm alarm = createAlarm();
m_alarmDao.save(alarm);
// Send alarm created event
ebldr = new EventBuilder(EventConstants.ALARM_CREATED_UEI, "test");
ebldr.addParam(EventConstants.PARM_ALARM_ID, alarm.getId());
m_bsmd.handleAlarmLifecycleEvents(ebldr.getEvent());
// Verify expectations
Collection<Event> stillWaitingFor = m_eventMgr.getEventAnticipator().waitForAnticipated(5000);
assertTrue("Expected events not forthcoming " + stillWaitingFor, stillWaitingFor.isEmpty());
verifyParametersOnAnticipatedEventsReceived(m_eventMgr.getEventAnticipator(), simpleBs.getId());
// Expect a statusChanged event
ebldr = new EventBuilder(EventConstants.BUSINESS_SERVICE_OPERATIONAL_STATUS_CHANGED_UEI, "test");
m_eventMgr.getEventAnticipator().anticipateEvent(ebldr.getEvent());
// Expect a serviceProblemResolved event
ebldr = new EventBuilder(EventConstants.BUSINESS_SERVICE_PROBLEM_RESOLVED_UEI, "test");
m_eventMgr.getEventAnticipator().anticipateEvent(ebldr.getEvent());
// Clear the alarm
alarm.setSeverity(OnmsSeverity.CLEARED);
// Send an alarm cleared event
ebldr = new EventBuilder(EventConstants.ALARM_CLEARED_UEI, "test");
ebldr.addParam(EventConstants.PARM_ALARM_ID, alarm.getId());
m_bsmd.handleAlarmLifecycleEvents(ebldr.getEvent());
// Verify expectations
stillWaitingFor = m_eventMgr.getEventAnticipator().waitForAnticipated(5000);
assertTrue("Expected events not forthcoming " + stillWaitingFor, stillWaitingFor.isEmpty());
verifyParametersOnAnticipatedEventsReceived(m_eventMgr.getEventAnticipator(), simpleBs.getId());
}
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));
}
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)));
reloadBsmd();
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 AbstractBusinessServiceRestServiceIT method canCreateSimpleHierarchy.
/**
* Verify that the Rest API can deal with setting of a hierarchy
*/
@Test
public void canCreateSimpleHierarchy() throws Exception {
final SimpleTestHierarchy testData = new SimpleTestHierarchy(databasePopulator);
// clear hierarchy
for (BusinessServiceEntity eachEntity : testData.getServices()) {
eachEntity.getEdges().clear();
}
// save business services
for (BusinessServiceEntity eachEntity : testData.getServices()) {
sendData(POST, getMediaType(), "/business-services", marshal(toRequestDto(eachEntity)), 201);
}
// set hierarchy
BusinessServiceEntity parentEntity = findEntityByName("Parent").addChildServiceEdge(findEntityByName("Child 1"), new IdentityEntity(), 1).addChildServiceEdge(findEntityByName("Child 2"), new IdentityEntity(), 1);
sendData(PUT, getMediaType(), buildServiceUrl(parentEntity.getId()), marshal(toRequestDto(parentEntity)), 204);
// Verify
Assert.assertEquals(3, m_businessServiceDao.countAll());
parentEntity = findEntityByName("Parent");
BusinessServiceEntity child1Entity = findEntityByName("Child 1");
BusinessServiceEntity child2Entity = findEntityByName("Child 2");
Assert.assertEquals(0, m_businessServiceDao.findParents(parentEntity).size());
Assert.assertEquals(2, parentEntity.getChildEdges().size());
Assert.assertEquals(1, m_businessServiceDao.findParents(child1Entity).size());
Assert.assertEquals(0, child1Entity.getChildEdges().size());
Assert.assertEquals(1, m_businessServiceDao.findParents(child2Entity).size());
Assert.assertEquals(0, child2Entity.getChildEdges().size());
verifyResponse(parentEntity);
verifyResponse(child1Entity);
verifyResponse(child2Entity);
}
Aggregations