Search in sources :

Example 16 with BusinessServiceEntity

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)));
}
Also used : BsmTestUtils.createDummyBusinessService(org.opennms.netmgt.bsm.test.BsmTestUtils.createDummyBusinessService) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) Test(org.junit.Test)

Example 17 with BusinessServiceEntity

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());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Event(org.opennms.netmgt.xml.event.Event) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 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)

Example 19 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)));
    reloadBsmd();
    Assert.assertEquals(Status.NORMAL, m_bsmd.getBusinessServiceStateMachine().getOperationalStatus(wrap(businessService2)));
}
Also used : BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with BusinessServiceEntity

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);
}
Also used : SimpleTestHierarchy(org.opennms.netmgt.bsm.test.hierarchies.SimpleTestHierarchy) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) 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