Search in sources :

Example 41 with BusinessServiceEntity

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

the class AbstractBusinessServiceRestServiceIT method canAddChildServiceEdge.

@Test
public void canAddChildServiceEdge() throws Exception {
    // Create a child and parent Business Service without any edges
    BusinessServiceEntity childEntity = new BusinessServiceEntityBuilder().name("Child Service").reduceFunction(new HighestSeverityEntity()).toEntity();
    BusinessServiceEntity parentEntity = new BusinessServiceEntityBuilder().name("Parent Service").reduceFunction(new HighestSeverityEntity()).toEntity();
    final Long parentServiceId = m_businessServiceDao.save(parentEntity);
    final Long childServiceId = m_businessServiceDao.save(childEntity);
    m_businessServiceDao.flush();
    // The Request to send to create the edge
    ChildEdgeRequestDTO edgeRequestDTO = new ChildEdgeRequestDTO();
    edgeRequestDTO.setMapFunction(new FunctionsManager().getMapFunctionDTO(new Identity()));
    // verify adding of not existing ip parentEntity is not possible
    edgeRequestDTO.setChildId(-1L);
    sendData(POST, getMediaType(), buildChildServiceEdgeUrl(parentServiceId), marshal(edgeRequestDTO), 404);
    // verify adding of existing ip parentEntity is possible
    edgeRequestDTO.setChildId(childServiceId);
    sendData(POST, getMediaType(), buildChildServiceEdgeUrl(parentServiceId), marshal(edgeRequestDTO), 200);
    Assert.assertEquals(1, m_businessServiceDao.get(parentServiceId).getChildEdges().size());
    // verify adding twice possible, but not modified
    sendData(POST, getMediaType(), buildChildServiceEdgeUrl(parentServiceId), marshal(edgeRequestDTO), 304);
    Assert.assertEquals(1, m_businessServiceDao.get(parentServiceId).getChildEdges().size());
}
Also used : ChildEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.ChildEdgeRequestDTO) FunctionsManager(org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) Test(org.junit.Test)

Example 42 with BusinessServiceEntity

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

the class AbstractBusinessServiceRestServiceIT method findEntityByName.

private BusinessServiceEntity findEntityByName(String name) {
    Criteria criteria = new CriteriaBuilder(BusinessServiceEntity.class).eq("name", name).toCriteria();
    List<BusinessServiceEntity> matching = m_businessServiceDao.findMatching(criteria);
    if (matching.isEmpty()) {
        throw new NoSuchElementException("Did not find business service with name '" + name + "'.");
    }
    return matching.get(0);
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Criteria(org.opennms.core.criteria.Criteria) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) NoSuchElementException(java.util.NoSuchElementException)

Example 43 with BusinessServiceEntity

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

the class DefaultBusinessServiceStateMachineIT method canGetOperationalStatusForIpServices.

@Test
public void canGetOperationalStatusForIpServices() {
    // Setup the the test hierarchy
    SimpleTestHierarchy simpleTestHierarchy = new SimpleTestHierarchy(populator);
    simpleTestHierarchy.getServices().forEach(entity -> businessServiceDao.save(entity));
    final BusinessServiceEntity root = simpleTestHierarchy.getRoot();
    final IPServiceEdgeEntity serviceChild1 = simpleTestHierarchy.getServiceChild1();
    final IPServiceEdgeEntity serviceChild2 = simpleTestHierarchy.getServiceChild2();
    // Setup the State Machine
    DefaultBusinessServiceStateMachine stateMachine = new DefaultBusinessServiceStateMachine();
    stateMachine.setBusinessServices(simpleTestHierarchy.getServices().stream().map(s -> wrap(s)).collect(Collectors.toList()));
    // Verify the initial state
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(root)));
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(simpleTestHierarchy.getChild1())));
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(simpleTestHierarchy.getChild2())));
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(serviceChild1)));
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(serviceChild2)));
    // Node lost service alarm
    String nodeLostServiceReductionKey = ReductionKeyHelper.getNodeLostServiceReductionKey(serviceChild1.getIpService());
    stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(EventConstants.NODE_LOST_SERVICE_EVENT_UEI, OnmsSeverity.WARNING, nodeLostServiceReductionKey));
    // Verify state
    assertEquals(Status.WARNING, stateMachine.getOperationalStatus(wrap(serviceChild1)));
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(serviceChild2)));
    // Interface down alarm
    String interfaceDownReductionKey = ReductionKeyHelper.getInterfaceDownReductionKey(serviceChild1.getIpService());
    stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(EventConstants.INTERFACE_DOWN_EVENT_UEI, OnmsSeverity.MINOR, interfaceDownReductionKey));
    // Verify state
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(wrap(serviceChild1)));
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(serviceChild2)));
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(wrap(root)));
    // Node down alarm
    String nodeDownReductionKey = ReductionKeyHelper.getNodeDownReductionKey(serviceChild1.getIpService());
    stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(EventConstants.NODE_DOWN_EVENT_UEI, OnmsSeverity.MAJOR, nodeDownReductionKey));
    // Verify state
    Assert.assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(wrap(serviceChild1)));
    Assert.assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(serviceChild2)));
    Assert.assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(wrap(root)));
}
Also used : IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) SimpleTestHierarchy(org.opennms.netmgt.bsm.test.hierarchies.SimpleTestHierarchy) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) Test(org.junit.Test)

Example 44 with BusinessServiceEntity

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

the class BusinessServiceCriteriaTest method createDummyBusinessService.

private BusinessService createDummyBusinessService(final long id, final String name, String attributeKey, String attributeValue, final Status status) {
    BusinessServiceEntity businessServiceEntity = new BusinessServiceEntity();
    businessServiceEntity.setId(id);
    businessServiceEntity.setAttribute(attributeKey, attributeValue);
    businessServiceEntity.setName(name);
    BusinessService businessService = new BusinessServiceImpl(businessServiceManager, businessServiceEntity) {

        @Override
        public Status getOperationalStatus() {
            return status;
        }
    };
    return businessService;
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)

Example 45 with BusinessServiceEntity

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

the class BusinessServiceManagerImplIT method testLoopCreation.

@Test
public void testLoopCreation() {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("Service will form a loop");
    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);
    businessServiceManager.addChildEdge(getBusinessService(serviceId1), getBusinessService(serviceId2), new Identity(), Edge.DEFAULT_WEIGHT);
    businessServiceManager.addChildEdge(getBusinessService(serviceId2), getBusinessService(serviceId3), new Identity(), Edge.DEFAULT_WEIGHT);
    businessServiceManager.addChildEdge(getBusinessService(serviceId3), getBusinessService(serviceId1), new Identity(), Edge.DEFAULT_WEIGHT);
}
Also used : BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) 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