Search in sources :

Example 1 with FunctionsManager

use of org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager 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());
}
Also used : FunctionsManager(org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager) IpServiceEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.IpServiceEdgeRequestDTO) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) Test(org.junit.Test)

Example 2 with FunctionsManager

use of org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager 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());
}
Also used : FunctionsManager(org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager) ReductionKeyEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.ReductionKeyEdgeRequestDTO) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) Test(org.junit.Test)

Example 3 with FunctionsManager

use of org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager in project opennms by OpenNMS.

the class AbstractBusinessServiceRestServiceIT method canUpdateBusinessService.

@Test
public void canUpdateBusinessService() throws Exception {
    // initialize
    BusinessServiceEntity bs = new BusinessServiceEntityBuilder().name("Dummy Service").addAttribute("some-key", "some-value").addReductionKey("key1", new IdentityEntity()).addReductionKey("key2-deleteMe", new IdentityEntity()).reduceFunction(new HighestSeverityEntity()).toEntity();
    final Long serviceId = m_businessServiceDao.save(bs);
    m_businessServiceDao.flush();
    // update
    BusinessServiceRequestDTO requestDTO = toRequestDto(bs);
    requestDTO.setName("New Name");
    requestDTO.getAttributes().put("key", "value");
    requestDTO.getReductionKeys().clear();
    requestDTO.addReductionKey("key1updated", new FunctionsManager().getMapFunctionDTO(new Ignore()), Edge.DEFAULT_WEIGHT);
    sendData(PUT, getMediaType(), "/business-services/" + serviceId, marshal(requestDTO), 204);
    // Reload from database and verify changes
    bs = m_businessServiceDao.get(serviceId);
    Assert.assertEquals(requestDTO.getName(), bs.getName());
    Assert.assertEquals(requestDTO.getAttributes(), bs.getAttributes());
    Assert.assertEquals(1, bs.getReductionKeyEdges().size());
    Assert.assertEquals(1, bs.getEdges().size());
    Assert.assertEquals(1, m_businessServiceDao.findAll().size());
    Assert.assertEquals(Sets.newHashSet(), bs.getIpServiceEdges());
    BusinessServiceResponseDTO responseDTO = verifyResponse(bs);
    verifyReductionKey("key1updated", responseDTO);
}
Also used : Ignore(org.opennms.netmgt.bsm.service.model.functions.map.Ignore) FunctionsManager(org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager) BusinessServiceResponseDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO) BusinessServiceRequestDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceRequestDTO) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test)

Example 4 with FunctionsManager

use of org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager 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());
}
Also used : ChildEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.ChildEdgeRequestDTO) FunctionsManager(org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) Test(org.junit.Test)

Example 5 with FunctionsManager

use of org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager in project opennms by OpenNMS.

the class BsmTestUtils method transform.

private static MapFunctionDTO transform(AbstractMapFunctionEntity input) {
    Objects.requireNonNull(input);
    MapFunction mapFunction = new MapFunctionMapper().toServiceFunction(input);
    return new FunctionsManager().getMapFunctionDTO(mapFunction);
}
Also used : FunctionsManager(org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager) MapFunction(org.opennms.netmgt.bsm.service.model.functions.map.MapFunction)

Aggregations

FunctionsManager (org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager)6 Test (org.junit.Test)4 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)4 HighestSeverityEntity (org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity)4 BusinessServiceEntityBuilder (org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder)4 Identity (org.opennms.netmgt.bsm.service.model.functions.map.Identity)3 IdentityEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity)1 Ignore (org.opennms.netmgt.bsm.service.model.functions.map.Ignore)1 MapFunction (org.opennms.netmgt.bsm.service.model.functions.map.MapFunction)1 ReductionFunction (org.opennms.netmgt.bsm.service.model.functions.reduce.ReductionFunction)1 BusinessServiceRequestDTO (org.opennms.web.rest.v2.bsm.model.BusinessServiceRequestDTO)1 BusinessServiceResponseDTO (org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO)1 ChildEdgeRequestDTO (org.opennms.web.rest.v2.bsm.model.edge.ChildEdgeRequestDTO)1 IpServiceEdgeRequestDTO (org.opennms.web.rest.v2.bsm.model.edge.IpServiceEdgeRequestDTO)1 ReductionKeyEdgeRequestDTO (org.opennms.web.rest.v2.bsm.model.edge.ReductionKeyEdgeRequestDTO)1