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();
}
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();
}
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>" } });
}
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;
}
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);
}
Aggregations