use of org.opennms.netmgt.bsm.test.hierarchies.SimpleTestHierarchy 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);
}
use of org.opennms.netmgt.bsm.test.hierarchies.SimpleTestHierarchy 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.test.hierarchies.SimpleTestHierarchy 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