Search in sources :

Example 1 with BambooTestHierarchy

use of org.opennms.netmgt.bsm.test.hierarchies.BambooTestHierarchy in project opennms by OpenNMS.

the class AbstractBusinessServiceRestServiceIT method canCreateBambooHierarchy.

@Test
public void canCreateBambooHierarchy() throws Exception {
    final BambooTestHierarchy testData = new BambooTestHierarchy();
    // save hierarchy for later use
    final Map<BusinessServiceEntity, Set<BusinessServiceEdgeEntity>> edgeMap = Maps.newHashMap();
    testData.getServices().forEach(eachEntity -> edgeMap.put(eachEntity, Sets.newHashSet(eachEntity.getEdges())));
    // clear hierarchy
    testData.getServices().forEach(eachEntity -> eachEntity.setEdges(Sets.newHashSet()));
    // save business services to database
    for (BusinessServiceEntity eachEntity : testData.getServices()) {
        sendData(POST, getMediaType(), "/business-services", marshal(toRequestDto(eachEntity)), 201);
    }
    // apply ids (we created objects via rest)
    edgeMap.keySet().forEach(s -> s.setId(findEntityByName(s.getName()).getId()));
    // set hierarchy
    for (Map.Entry<BusinessServiceEntity, Set<BusinessServiceEdgeEntity>> eachEntry : edgeMap.entrySet()) {
        eachEntry.getKey().setEdges(eachEntry.getValue());
        sendData(PUT, getMediaType(), buildServiceUrl(eachEntry.getKey().getId()), marshal(toRequestDto(eachEntry.getKey())), 204);
    }
    // verify
    Assert.assertEquals(3, m_businessServiceDao.countAll());
    BusinessServiceEntity parentEntity = findEntityByName("Bamboo");
    BusinessServiceEntity mastersBusinessServiceEntity = findEntityByName("Master");
    BusinessServiceEntity agentsBusinessServiceEntity = findEntityByName("Agents");
    Assert.assertEquals(0, m_businessServiceDao.findParents(parentEntity).size());
    Assert.assertEquals(2, parentEntity.getChildEdges().size());
    Assert.assertEquals(1, m_businessServiceDao.findParents(mastersBusinessServiceEntity).size());
    Assert.assertEquals(2, mastersBusinessServiceEntity.getReductionKeyEdges().size());
    Assert.assertEquals(1, m_businessServiceDao.findParents(agentsBusinessServiceEntity).size());
    Assert.assertEquals(3, agentsBusinessServiceEntity.getReductionKeyEdges().size());
    // Verify Weight
    Assert.assertEquals(2, getReductionKeyEdge(agentsBusinessServiceEntity, BAMBOO_AGENT_DUKE_REDUCTION_KEY).getWeight());
    Assert.assertEquals(2, getReductionKeyEdge(agentsBusinessServiceEntity, BAMBOO_AGENT_CAROLINA_REDUCTION_KEY).getWeight());
    Assert.assertEquals(1, getReductionKeyEdge(agentsBusinessServiceEntity, BAMBOO_AGENT_NCSTATE_REDUCTION_KEY).getWeight());
    // verify rest
    verifyResponse(parentEntity);
    verifyResponse(mastersBusinessServiceEntity);
    verifyResponse(agentsBusinessServiceEntity);
}
Also used : Set(java.util.Set) BambooTestHierarchy(org.opennms.netmgt.bsm.test.hierarchies.BambooTestHierarchy) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) Map(java.util.Map) Test(org.junit.Test)

Example 2 with BambooTestHierarchy

use of org.opennms.netmgt.bsm.test.hierarchies.BambooTestHierarchy in project opennms by OpenNMS.

the class DefaultBusinessServiceStateMachineIT method canMaintainStateForBambooHierarchy.

@Test
public void canMaintainStateForBambooHierarchy() {
    // Setup the the test hierarchy
    BambooTestHierarchy testSpecification = new BambooTestHierarchy();
    testSpecification.getServices().forEach(entity -> businessServiceDao.save(entity));
    // Setup the State Machine
    final DefaultBusinessServiceStateMachine stateMachine = new DefaultBusinessServiceStateMachine();
    stateMachine.setBusinessServices(testSpecification.getServices().stream().map(s -> wrap(s)).collect(Collectors.toList()));
    LoggingStateChangeHandler handler = new LoggingStateChangeHandler();
    stateMachine.addHandler(handler, null);
    // Verify the initial state
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(testSpecification.getMasterService())));
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(testSpecification.getAgentsService())));
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(testSpecification.getBambooService())));
    // Send alarms to the state machine
    // Business Service "Master"
    stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper("uei.opennms.org/dummy", OnmsSeverity.INDETERMINATE, HTTP_8085_BAMBOO_REDUCTION_KEY));
    // no state change
    assertEquals(0, handler.getStateChanges().size());
    stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper("uei.opennms.org/dummy", OnmsSeverity.WARNING, DISK_USAGE_THRESHOLD_BAMBO_REDUCTION_KEY));
    // "Master" and "Bamboo" changed
    assertEquals(2, handler.getStateChanges().size());
    // Business Service "Agents"
    stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper("uei.opennms.org/dummy", OnmsSeverity.MINOR, BAMBOO_AGENT_DUKE_REDUCTION_KEY));
    // no state change (threshold not met)
    assertEquals(2, handler.getStateChanges().size());
    stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper("uei.opennms.org/dummy", OnmsSeverity.NORMAL, BAMBOO_AGENT_NCSTATE_REDUCTION_KEY));
    // no state change (threshold not met)
    assertEquals(2, handler.getStateChanges().size());
    stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper("uei.opennms.org/dummy", OnmsSeverity.MAJOR, BAMBOO_AGENT_CAROLINA_REDUCTION_KEY));
    // state change (threshold met) for "Agents" and "Bamboo"
    assertEquals(4, handler.getStateChanges().size());
    // Verify the updated state
    // Business Service "Master"
    assertEquals(Status.WARNING, stateMachine.getOperationalStatus(wrap(testSpecification.getMasterService())));
    // Business Service "Agents"
    assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(wrap(testSpecification.getAgentsService())));
    // Business Service "Bamboo" (root)
    assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(wrap(testSpecification.getBambooService())));
}
Also used : BambooTestHierarchy(org.opennms.netmgt.bsm.test.hierarchies.BambooTestHierarchy) LoggingStateChangeHandler(org.opennms.netmgt.bsm.test.LoggingStateChangeHandler) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 BambooTestHierarchy (org.opennms.netmgt.bsm.test.hierarchies.BambooTestHierarchy)2 Map (java.util.Map)1 Set (java.util.Set)1 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)1 LoggingStateChangeHandler (org.opennms.netmgt.bsm.test.LoggingStateChangeHandler)1