Search in sources :

Example 1 with BusinessServiceRequestDTO

use of org.opennms.web.rest.v2.bsm.model.BusinessServiceRequestDTO 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 2 with BusinessServiceRequestDTO

use of org.opennms.web.rest.v2.bsm.model.BusinessServiceRequestDTO 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 3 with BusinessServiceRequestDTO

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

the class BusinessServiceRequestDTOMarshalTest method data.

@Parameterized.Parameters
public static Collection<Object[]> data() throws IOException {
    final SetTo setTo = new SetTo();
    setTo.setStatus(Status.CRITICAL);
    final MapFunctionDTO increaseDto = createMapFunctionDTO(new Increase());
    final MapFunctionDTO setToDto = createMapFunctionDTO(setTo);
    final BusinessServiceRequestDTO requestDTO = new BusinessServiceRequestDTO();
    requestDTO.setReduceFunction(createReduceFunctionDTO(new HighestSeverity()));
    requestDTO.setName("Web Servers");
    requestDTO.addAttribute("dc", "RDU");
    requestDTO.addAttribute("some-key", "some-value");
    requestDTO.addChildService(2L, increaseDto, 5);
    requestDTO.addChildService(3L, setToDto, 5);
    requestDTO.addReductionKey("myReductionKeyA", increaseDto, 7, "reduction-key-a-friendly-name");
    requestDTO.addReductionKey("myReductionKeyB", increaseDto, 7, "reduction-key-b-friendly-name");
    requestDTO.addIpService(1, increaseDto, 9, "ip-service-friendly-name");
    return Arrays.asList(new Object[][] { { BusinessServiceRequestDTO.class, requestDTO, "{" + "  \"name\" : \"Web Servers\"," + "  \"attributes\" : {" + "    \"attribute\" : [ {" + "      \"key\" : \"dc\"," + "      \"value\" : \"RDU\"" + "    }, {" + "      \"key\" : \"some-key\"," + "      \"value\" : \"some-value\"" + "    } ]" + "  }," + "  \"reduce-function\" : {" + "       \"type\" : \"HighestSeverity\"," + "       \"properties\" : { }" + "  }," + "  \"child-edges\" : [" + "       {" + "           \"map-function\" : {" + "               \"type\" : \"Increase\"," + "               \"properties\" : { }" + "           }," + "           \"weight\" : 5," + "           \"child-id\" : 2" + "       }," + "       {" + "           \"map-function\" : {" + "               \"type\" : \"SetTo\"," + "               \"properties\" : {" + "                   \"status\" : \"Critical\"" + "               }" + "           }," + "           \"weight\" : 5," + "           \"child-id\" : 3" + "       }," + "   ]," + "  \"ip-service-edges\" : [" + "       {" + "           \"map-function\" : {" + "               \"type\" : \"Increase\"," + "               \"properties\" : { }" + "           }," + "           \"weight\" : 9," + "           \"ip-service-id\" : 1," + "           \"friendly-name\" : \"ip-service-friendly-name\"" + "       }," + "   ]," + "  \"reduction-key-edges\" : [" + "       {" + "           \"map-function\" : {" + "               \"type\" : \"Increase\"," + "               \"properties\" : { }" + "           }," + "           \"weight\" : 7," + "           \"reduction-key\" : \"myReductionKeyA\"," + "           \"friendly-name\" : \"reduction-key-a-friendly-name\"" + "       }," + "       {" + "            \"map-function\" : {" + "               \"type\" : \"Increase\"," + "               \"properties\" : { }" + "           }," + "           \"weight\" : 7," + "           \"reduction-key\" : \"myReductionKeyB\"," + "           \"friendly-name\" : \"reduction-key-b-friendly-name\"" + "       }," + "   ]," + "}", "<business-service>\n" + "   <name>Web Servers</name>\n" + "   <attributes>\n" + "      <attribute>\n" + "         <key>dc</key>\n" + "         <value>RDU</value>\n" + "      </attribute>\n" + "      <attribute>\n" + "         <key>some-key</key>\n" + "         <value>some-value</value>\n" + "      </attribute>\n" + "   </attributes>\n" + "    <ip-service-edges>\n" + "      <ip-service-edge>\n" + "         <map-function>\n" + "            <type>Increase</type>\n" + "         </map-function>\n" + "         <weight>9</weight>\n" + "         <friendly-name>ip-service-friendly-name</friendly-name>\n" + "         <ip-service-id>1</ip-service-id>\n" + "      </ip-service-edge>\n" + "   </ip-service-edges>\n" + "   <child-edges>\n" + "      <child-edge>\n" + "         <map-function>\n" + "            <type>Increase</type>\n" + "         </map-function>\n" + "         <weight>5</weight>\n" + "         <child-id>2</child-id>\n" + "      </child-edge>\n" + "      <child-edge>\n" + "         <map-function>\n" + "            <type>SetTo</type>\n" + "            <properties>\n" + "               <entry>\n" + "                  <key>status</key>\n" + "                  <value>Critical</value>\n" + "               </entry>\n" + "            </properties>\n" + "         </map-function>\n" + "         <weight>5</weight>\n" + "         <child-id>3</child-id>\n" + "      </child-edge>\n" + "   </child-edges>\n" + "   <reduction-key-edges>\n" + "      <reduction-key-edge>\n" + "         <map-function>\n" + "            <type>Increase</type>\n" + "         </map-function>\n" + "         <weight>7</weight>\n" + "         <friendly-name>reduction-key-a-friendly-name</friendly-name>\n" + "         <reduction-key>myReductionKeyA</reduction-key>\n" + "      </reduction-key-edge>\n" + "      <reduction-key-edge>\n" + "         <map-function>\n" + "            <type>Increase</type>\n" + "         </map-function>\n" + "         <weight>7</weight>\n" + "         <friendly-name>reduction-key-b-friendly-name</friendly-name>\n" + "         <reduction-key>myReductionKeyB</reduction-key>\n" + "      </reduction-key-edge>\n" + "   </reduction-key-edges>\n" + "   <reduce-function>\n" + "      <type>HighestSeverity</type>\n" + "   </reduce-function>\n" + "</business-service>" } });
}
Also used : TestHelper.createMapFunctionDTO(org.opennms.web.rest.v2.bsm.model.TestHelper.createMapFunctionDTO) HighestSeverity(org.opennms.netmgt.bsm.service.model.functions.reduce.HighestSeverity) Increase(org.opennms.netmgt.bsm.service.model.functions.map.Increase) SetTo(org.opennms.netmgt.bsm.service.model.functions.map.SetTo)

Example 4 with BusinessServiceRequestDTO

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

the class BsmTestUtils method toRequestDto.

public static BusinessServiceRequestDTO toRequestDto(BusinessServiceEntity input) {
    Objects.requireNonNull(input);
    BusinessServiceRequestDTO request = new BusinessServiceRequestDTO();
    request.setName(input.getName());
    request.setAttributes(new HashMap<>(input.getAttributes()));
    request.setReduceFunction(transform(input.getReductionFunction()));
    input.getEdges().forEach(eachEdge -> eachEdge.accept(new EdgeEntityVisitor<Void>() {

        @Override
        public Void visit(BusinessServiceChildEdgeEntity edgeEntity) {
            request.addChildService(edgeEntity.getChild().getId(), transform(edgeEntity.getMapFunction()), edgeEntity.getWeight());
            return null;
        }

        @Override
        public Void visit(SingleReductionKeyEdgeEntity edgeEntity) {
            request.addReductionKey(edgeEntity.getReductionKey(), transform(edgeEntity.getMapFunction()), edgeEntity.getWeight(), edgeEntity.getFriendlyName());
            return null;
        }

        @Override
        public Void visit(IPServiceEdgeEntity edgeEntity) {
            request.addIpService(edgeEntity.getIpService().getId(), transform(edgeEntity.getMapFunction()), edgeEntity.getWeight(), edgeEntity.getFriendlyName());
            return null;
        }
    }));
    return request;
}
Also used : SingleReductionKeyEdgeEntity(org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity) IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) EdgeEntityVisitor(org.opennms.netmgt.bsm.persistence.api.EdgeEntityVisitor) BusinessServiceRequestDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceRequestDTO) BusinessServiceChildEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity)

Example 5 with BusinessServiceRequestDTO

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

Aggregations

BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)2 BusinessServiceRequestDTO (org.opennms.web.rest.v2.bsm.model.BusinessServiceRequestDTO)2 ChildEdgeRequestDTO (org.opennms.web.rest.v2.bsm.model.edge.ChildEdgeRequestDTO)2 EdgeRequestDTOVisitor (org.opennms.web.rest.v2.bsm.model.edge.EdgeRequestDTOVisitor)2 IpServiceEdgeRequestDTO (org.opennms.web.rest.v2.bsm.model.edge.IpServiceEdgeRequestDTO)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 BusinessServiceChildEdgeEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity)1 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)1 EdgeEntityVisitor (org.opennms.netmgt.bsm.persistence.api.EdgeEntityVisitor)1 IPServiceEdgeEntity (org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity)1 SingleReductionKeyEdgeEntity (org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity)1 IdentityEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity)1 HighestSeverityEntity (org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity)1 Ignore (org.opennms.netmgt.bsm.service.model.functions.map.Ignore)1 Increase (org.opennms.netmgt.bsm.service.model.functions.map.Increase)1 SetTo (org.opennms.netmgt.bsm.service.model.functions.map.SetTo)1