use of org.opennms.netmgt.bsm.service.model.functions.map.Identity in project opennms by OpenNMS.
the class AbstractBusinessServiceRestServiceIT method canAddIpServiceEdge.
@Test
public void canAddIpServiceEdge() throws Exception {
// Create a business service without any edges
BusinessServiceEntity service = new BusinessServiceEntityBuilder().name("Dummy Service").reduceFunction(new HighestSeverityEntity()).toEntity();
final Long serviceId = m_businessServiceDao.save(service);
m_businessServiceDao.flush();
// The Request to send to create an edge
IpServiceEdgeRequestDTO edgeRequestDTO = new IpServiceEdgeRequestDTO();
edgeRequestDTO.setMapFunction(new FunctionsManager().getMapFunctionDTO(new Identity()));
// verify adding of not existing ip service is not possible
edgeRequestDTO.setIpServiceId(-1);
sendData(POST, getMediaType(), buildIpServiceEdgeUrl(serviceId), marshal(edgeRequestDTO), 404);
// verify adding of existing ip service is possible
edgeRequestDTO.setIpServiceId(10);
sendData(POST, getMediaType(), buildIpServiceEdgeUrl(serviceId), marshal(edgeRequestDTO), 200);
Assert.assertEquals(1, m_businessServiceDao.get(serviceId).getIpServiceEdges().size());
// verify adding twice possible, but not modified
sendData(POST, getMediaType(), buildIpServiceEdgeUrl(serviceId), marshal(edgeRequestDTO), 304);
Assert.assertEquals(1, m_businessServiceDao.get(serviceId).getIpServiceEdges().size());
// verify adding of existing ip service is possible
edgeRequestDTO.setIpServiceId(17);
sendData(POST, getMediaType(), buildIpServiceEdgeUrl(serviceId), marshal(edgeRequestDTO), 200);
Assert.assertEquals(2, m_businessServiceDao.get(serviceId).getIpServiceEdges().size());
}
use of org.opennms.netmgt.bsm.service.model.functions.map.Identity in project opennms by OpenNMS.
the class AbstractBusinessServiceRestServiceIT method canAddReductionKeyEdge.
@Test
public void canAddReductionKeyEdge() throws Exception {
// Create a business service without any edges
BusinessServiceEntity service = new BusinessServiceEntityBuilder().name("Dummy Service").reduceFunction(new HighestSeverityEntity()).toEntity();
final Long serviceId = m_businessServiceDao.save(service);
m_businessServiceDao.flush();
// The Request to send to create an edge
ReductionKeyEdgeRequestDTO edgeRequestDTO = new ReductionKeyEdgeRequestDTO();
edgeRequestDTO.setMapFunction(new FunctionsManager().getMapFunctionDTO(new Identity()));
// verify adding of existing ip service is possible
edgeRequestDTO.setReductionKey("1st reduction key");
sendData(POST, getMediaType(), buildReductionKeyEdgeUrl(serviceId), marshal(edgeRequestDTO), 200);
Assert.assertEquals(1, m_businessServiceDao.get(serviceId).getReductionKeyEdges().size());
// verify adding twice possible, but not modified
sendData(POST, getMediaType(), buildReductionKeyEdgeUrl(serviceId), marshal(edgeRequestDTO), 304);
Assert.assertEquals(1, m_businessServiceDao.get(serviceId).getReductionKeyEdges().size());
// verify adding of existing ip service is possible
edgeRequestDTO.setReductionKey("2nd reduction key");
sendData(POST, getMediaType(), buildReductionKeyEdgeUrl(serviceId), marshal(edgeRequestDTO), 200);
Assert.assertEquals(2, m_businessServiceDao.get(serviceId).getReductionKeyEdges().size());
}
use of org.opennms.netmgt.bsm.service.model.functions.map.Identity 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.service.model.functions.map.Identity in project opennms by OpenNMS.
the class BusinessServiceManagerImplIT method testChildDeletionMultipleLevels.
// 1 parent -> 1 Child -> 1 child
@Test
public void testChildDeletionMultipleLevels() {
BusinessService service_p = createBusinessService("Business Service #p");
BusinessService service_c_1 = createBusinessService("Business Service #c1");
BusinessService service_c_2 = createBusinessService("Business Service #c2");
businessServiceManager.addChildEdge(service_p, service_c_1, new Identity(), Edge.DEFAULT_WEIGHT);
businessServiceManager.addChildEdge(service_c_1, service_c_2, new Identity(), Edge.DEFAULT_WEIGHT);
service_p.save();
service_c_1.save();
service_c_2.save();
// ensure the edges are there before deleting
Assert.assertEquals(2, edgeDao.countAll());
service_c_1.delete();
Assert.assertEquals(ImmutableSet.of(), service_p.getChildServices());
// verify that the edge is also gon
Assert.assertEquals(0, edgeDao.countAll());
}
use of org.opennms.netmgt.bsm.service.model.functions.map.Identity in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachineIT method canMaintainStateForSimpleHierarchy.
@Test
public void canMaintainStateForSimpleHierarchy() {
// Setup the the test hierarchy
SimpleTestHierarchy testHierarchy = new SimpleTestHierarchy(populator);
testHierarchy.getServices().forEach(entity -> businessServiceDao.save(entity));
BusinessServiceImpl bsChild1 = wrap(testHierarchy.getChild1());
BusinessServiceImpl bsChild2 = wrap(testHierarchy.getChild2());
BusinessServiceImpl bsParent = wrap(testHierarchy.getRoot());
IpServiceEdge svc1 = wrap(testHierarchy.getServiceChild1());
IpServiceEdge svc2 = wrap(testHierarchy.getServiceChild2());
// Manually add a reduction key to a business service to verify that this also works
bsChild1.addReductionKeyEdge("explicitReductionKey", new Identity(), Edge.DEFAULT_WEIGHT, null);
businessServiceDao.flush();
// Setup the state machine
List<BusinessService> bss = Lists.newArrayList(bsChild1, bsChild2, bsParent);
LoggingStateChangeHandler handler = new LoggingStateChangeHandler();
DefaultBusinessServiceStateMachine stateMachine = new DefaultBusinessServiceStateMachine();
stateMachine.setBusinessServices(bss);
stateMachine.addHandler(handler, null);
// Verify the initial state
assertEquals(0, handler.getStateChanges().size());
for (BusinessService eachBs : bss) {
assertEquals(DefaultBusinessServiceStateMachine.MIN_SEVERITY, stateMachine.getOperationalStatus(eachBs));
}
// Pass alarm to the state machine
stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(testHierarchy.getServiceChild1().getIpService(), OnmsSeverity.MINOR));
// Verify the updated state
assertEquals(2, handler.getStateChanges().size());
assertEquals(Status.MINOR, stateMachine.getOperationalStatus(svc1));
assertEquals(Status.MINOR, stateMachine.getOperationalStatus(bsChild1));
assertEquals(DefaultBusinessServiceStateMachine.MIN_SEVERITY, stateMachine.getOperationalStatus(svc2));
assertEquals(DefaultBusinessServiceStateMachine.MIN_SEVERITY, stateMachine.getOperationalStatus(bsChild2));
assertEquals(Status.MINOR, stateMachine.getOperationalStatus(bsParent));
// Verify that hierarchy works
stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(testHierarchy.getServiceChild2().getIpService(), OnmsSeverity.MAJOR));
assertEquals(4, handler.getStateChanges().size());
assertEquals(Status.MINOR, stateMachine.getOperationalStatus(svc1));
assertEquals(Status.MINOR, stateMachine.getOperationalStatus(bsChild1));
assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(svc2));
assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(bsChild2));
assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(bsParent));
// Verify that explicit reductionKeys work as well
AlarmWrapper alarmWrapper = createAlarmWrapper(EventConstants.NODE_LOST_SERVICE_EVENT_UEI, OnmsSeverity.CRITICAL, "explicitReductionKey");
stateMachine.handleNewOrUpdatedAlarm(alarmWrapper);
assertEquals(6, handler.getStateChanges().size());
assertEquals(Status.MINOR, stateMachine.getOperationalStatus(svc1));
assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(svc2));
assertEquals(Status.CRITICAL, stateMachine.getOperationalStatus(bsChild1));
assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(bsChild2));
assertEquals(Status.CRITICAL, stateMachine.getOperationalStatus(bsParent));
}
Aggregations