use of org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity in project opennms by OpenNMS.
the class BsmdIT method createBusinessService.
private BusinessServiceEntity createBusinessService(String name) {
BusinessServiceEntity bs = new BusinessServiceEntity();
bs.setName(name);
bs.setReductionFunction(new HighestSeverityEntity());
bs.setAttribute("my-attr-key", "my-attr-value");
// Grab the first monitored service from node 1
OnmsMonitoredService ipService = m_databasePopulator.getNode1().getIpInterfaces().iterator().next().getMonitoredServices().iterator().next();
bs.addIpServiceEdge(ipService, new IdentityEntity());
// Persist
m_businessServiceDao.save(bs);
m_businessServiceDao.flush();
return bs;
}
use of org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity in project opennms by OpenNMS.
the class AbstractBusinessServiceRestServiceIT method canRemoveEdges.
@Test
public void canRemoveEdges() throws Exception {
BusinessServiceEntity child = new BusinessServiceEntityBuilder().name("Child Service").reduceFunction(new HighestSeverityEntity()).toEntity();
m_businessServiceDao.save(child);
BusinessServiceEntity parent = new BusinessServiceEntityBuilder().name("Parent Service").reduceFunction(new HighestSeverityEntity()).addIpService(monitoredServiceDao.get(17), new SetToEntity(OnmsSeverity.CRITICAL.getId())).addIpService(monitoredServiceDao.get(18), new IgnoreEntity()).addIpService(monitoredServiceDao.get(20), new IdentityEntity()).addReductionKey("abc", new IgnoreEntity()).addReductionKey("abcd", new IgnoreEntity()).addChildren(child, new IncreaseEntity()).toEntity();
final Long parentServiceId = m_businessServiceDao.save(parent);
m_businessServiceDao.flush();
// verify that test data is set up correctly
Assert.assertEquals(3, parent.getIpServiceEdges().size());
Assert.assertEquals(2, parent.getReductionKeyEdges().size());
Assert.assertEquals(1, parent.getChildEdges().size());
Assert.assertEquals(6, parent.getEdges().size());
// determine edge ids
List<Long> edgeIdList = parent.getEdges().stream().map(e -> e.getId()).sorted().collect(Collectors.toList());
// verify removing not existing ip service not possible
sendData(DELETE, getMediaType(), buildEdgeUrl(parentServiceId, -1), "", 404);
// verify removing of existing ip service is possible
for (int i = 0; i < edgeIdList.size(); i++) {
long edgeId = edgeIdList.get(i);
int edgesLeftCount = edgeIdList.size() - i - 1;
// verify removing of existing ip service is possible
sendData(DELETE, getMediaType(), buildEdgeUrl(parentServiceId, edgeId), "", 200);
Assert.assertEquals(edgesLeftCount, m_businessServiceDao.get(parentServiceId).getEdges().size());
// verify removing twice possible, but not modified
sendData(DELETE, getMediaType(), buildEdgeUrl(parentServiceId, edgeId), "", 304);
Assert.assertEquals(edgesLeftCount, m_businessServiceDao.get(parentServiceId).getEdges().size());
}
}
use of org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity in project opennms by OpenNMS.
the class AbstractBusinessServiceRestServiceIT method canRetrieveBusinessServices.
@Test
public void canRetrieveBusinessServices() throws Exception {
// Add business services to the DB
BusinessServiceEntity bs = new BusinessServiceEntityBuilder().name("Application Servers").addReductionKey("MyReductionKey", new IdentityEntity()).reduceFunction(new HighestSeverityEntity()).toEntity();
Long id = m_businessServiceDao.save(bs);
m_businessServiceDao.flush();
// Retrieve the list of business services
List<ResourceLocation> businessServices = listBusinessServices();
// Verify
Assert.assertEquals(1, businessServices.size());
BusinessServiceResponseDTO expectedResponseDTO = toResponseDto(bs);
BusinessServiceResponseDTO actualResponseDTO = getAndUnmarshal(buildServiceUrl(id), 200, BusinessServiceResponseDTO.class);
Assert.assertEquals(expectedResponseDTO, actualResponseDTO);
verifyReductionKey("MyReductionKey", actualResponseDTO);
}
use of org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity in project opennms by OpenNMS.
the class AbstractBusinessServiceRestServiceIT method verifyFriendlyName.
@Test
public void verifyFriendlyName() throws Exception {
BusinessServiceEntity entity = new BusinessServiceEntityBuilder().name("Some Custom Name").addReductionKey("My Reduction Key", new IdentityEntity(), "so friendly").reduceFunction(new HighestSeverityEntity()).toEntity();
sendData(POST, getMediaType(), "/business-services", marshal(toRequestDto(entity)), 201);
BusinessServiceResponseDTO responseDTO = verifyResponse(findEntityByName("Some Custom Name"));
Assert.assertEquals(1, responseDTO.getReductionKeys().size());
Assert.assertEquals("so friendly", responseDTO.getReductionKeys().get(0).getFriendlyName());
}
use of org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity in project opennms by OpenNMS.
the class BusinessServiceSearchProviderIT method verifyQuery.
@Test
public void verifyQuery() {
BusinessServiceEntity bs1 = new BusinessServiceEntityBuilder().name("Test Service").reduceFunction(new HighestSeverityEntity()).addReductionKey("bs1.key1", new IdentityEntity(), 1).addReductionKey("bs1.key2", new IdentityEntity(), 1).toEntity();
BusinessServiceEntity bs2 = new BusinessServiceEntityBuilder().name("Real Service 2").reduceFunction(new HighestSeverityEntity()).addReductionKey("bs2.key1", new IdentityEntity(), 1).addReductionKey("bs2.key2", new IdentityEntity(), 1).toEntity();
businessServiceDao.save(bs1);
businessServiceDao.save(bs2);
businessServiceDao.flush();
// prepare mocks
TopologyServiceClient topologyServiceClientMock = EasyMock.createNiceMock(TopologyServiceClient.class);
EasyMock.expect(topologyServiceClientMock.getVertex(EasyMock.anyObject(BusinessServiceVertex.class))).andReturn(// always return a vertex, it just needs to be not null
new AbstractVertex("bsm", "0", "Dummy Vertex"));
GraphContainer graphContainerMock = EasyMock.createNiceMock(GraphContainer.class);
EasyMock.expect(graphContainerMock.getTopologyServiceClient()).andReturn(topologyServiceClientMock).anyTimes();
EasyMock.replay(graphContainerMock, topologyServiceClientMock);
// try searching
final BusinessServiceSearchProvider provider = new BusinessServiceSearchProvider();
provider.setBusinessServiceManager(businessServiceManager);
final SearchQuery query = new AbstractSearchQuery("Test") {
@Override
public boolean matches(String label) {
// always match, it does not matter
return true;
}
};
final List<SearchResult> result = provider.query(query, graphContainerMock);
Assert.assertEquals(1, result.size());
EasyMock.verify(graphContainerMock, topologyServiceClientMock);
}
Aggregations