Search in sources :

Example 1 with IpServiceEdgeRequestDTO

use of org.opennms.web.rest.v2.bsm.model.edge.IpServiceEdgeRequestDTO in project opennms by OpenNMS.

the class BusinessServiceRequestDTO method addIpService.

public void addIpService(int ipServiceId, MapFunctionDTO mapFunction, int weight, String friendlyName) {
    IpServiceEdgeRequestDTO edge = new IpServiceEdgeRequestDTO();
    edge.setIpServiceId(ipServiceId);
    edge.setMapFunction(mapFunction);
    edge.setWeight(weight);
    edge.setFriendlyName(friendlyName);
    getIpServices().add(edge);
}
Also used : IpServiceEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.IpServiceEdgeRequestDTO)

Example 2 with IpServiceEdgeRequestDTO

use of org.opennms.web.rest.v2.bsm.model.edge.IpServiceEdgeRequestDTO in project opennms by OpenNMS.

the class BusinessServiceRestService method update.

@PUT
@Path("{id}")
public Response update(@PathParam("id") final Long id, final BusinessServiceRequestDTO request) {
    final BusinessService service = getManager().getBusinessServiceById(id);
    service.setName(request.getName());
    service.setAttributes(request.getAttributes());
    service.setReduceFunction(transform(request.getReduceFunction()));
    service.setReductionKeyEdges(Sets.newHashSet());
    service.setIpServiceEdges(Sets.newHashSet());
    service.setChildEdges(Sets.newHashSet());
    request.getEdges().forEach(eachEdge -> eachEdge.accept(new EdgeRequestDTOVisitor() {

        @Override
        public void visit(IpServiceEdgeRequestDTO ipEdge) {
            getManager().addIpServiceEdge(service, getManager().getIpServiceById(ipEdge.getIpServiceId()), transform(ipEdge.getMapFunction()), ipEdge.getWeight(), ipEdge.getFriendlyName());
        }

        @Override
        public void visit(ChildEdgeRequestDTO childEdge) {
            getManager().addChildEdge(service, getManager().getBusinessServiceById(childEdge.getChildId()), transform(childEdge.getMapFunction()), childEdge.getWeight());
        }

        @Override
        public void visit(ReductionKeyEdgeRequestDTO rkEdge) {
            getManager().addReductionKeyEdge(service, rkEdge.getReductionKey(), transform(rkEdge.getMapFunction()), rkEdge.getWeight(), rkEdge.getFriendlyName());
        }
    }));
    getManager().saveBusinessService(service);
    return Response.noContent().build();
}
Also used : ChildEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.ChildEdgeRequestDTO) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) IpServiceEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.IpServiceEdgeRequestDTO) EdgeRequestDTOVisitor(org.opennms.web.rest.v2.bsm.model.edge.EdgeRequestDTOVisitor) ReductionKeyEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.ReductionKeyEdgeRequestDTO) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 3 with IpServiceEdgeRequestDTO

use of org.opennms.web.rest.v2.bsm.model.edge.IpServiceEdgeRequestDTO in project opennms by OpenNMS.

the class BusinessServiceRestService method create.

@POST
public Response create(@Context final UriInfo uriInfo, final BusinessServiceRequestDTO request) {
    final BusinessService service = getManager().createBusinessService();
    service.setName(request.getName());
    service.setAttributes(request.getAttributes());
    service.setReduceFunction(transform(request.getReduceFunction()));
    request.getEdges().forEach(eachEdge -> eachEdge.accept(new EdgeRequestDTOVisitor() {

        @Override
        public void visit(IpServiceEdgeRequestDTO ipEdge) {
            service.addIpServiceEdge(getManager().getIpServiceById(ipEdge.getIpServiceId()), transform(ipEdge.getMapFunction()), ipEdge.getWeight(), ipEdge.getFriendlyName());
        }

        @Override
        public void visit(ChildEdgeRequestDTO childEdge) {
            service.addChildEdge(getManager().getBusinessServiceById(childEdge.getChildId()), transform(childEdge.getMapFunction()), childEdge.getWeight());
        }

        @Override
        public void visit(ReductionKeyEdgeRequestDTO rkEdge) {
            service.addReductionKeyEdge(rkEdge.getReductionKey(), transform(rkEdge.getMapFunction()), rkEdge.getWeight(), rkEdge.getFriendlyName());
        }
    }));
    getManager().saveBusinessService(service);
    return Response.created(RedirectHelper.getRedirectUri(uriInfo, service.getId())).build();
}
Also used : ChildEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.ChildEdgeRequestDTO) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) IpServiceEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.IpServiceEdgeRequestDTO) EdgeRequestDTOVisitor(org.opennms.web.rest.v2.bsm.model.edge.EdgeRequestDTOVisitor) ReductionKeyEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.ReductionKeyEdgeRequestDTO) POST(javax.ws.rs.POST)

Example 4 with IpServiceEdgeRequestDTO

use of org.opennms.web.rest.v2.bsm.model.edge.IpServiceEdgeRequestDTO 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)

Aggregations

IpServiceEdgeRequestDTO (org.opennms.web.rest.v2.bsm.model.edge.IpServiceEdgeRequestDTO)4 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)2 ChildEdgeRequestDTO (org.opennms.web.rest.v2.bsm.model.edge.ChildEdgeRequestDTO)2 EdgeRequestDTOVisitor (org.opennms.web.rest.v2.bsm.model.edge.EdgeRequestDTOVisitor)2 ReductionKeyEdgeRequestDTO (org.opennms.web.rest.v2.bsm.model.edge.ReductionKeyEdgeRequestDTO)2 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Test (org.junit.Test)1 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)1 HighestSeverityEntity (org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity)1 Identity (org.opennms.netmgt.bsm.service.model.functions.map.Identity)1 BusinessServiceEntityBuilder (org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder)1 FunctionsManager (org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager)1