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