Search in sources :

Example 1 with BusinessService

use of org.opennms.netmgt.bsm.service.model.BusinessService 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 BusinessService

use of org.opennms.netmgt.bsm.service.model.BusinessService in project opennms by OpenNMS.

the class BusinessServiceRestService method list.

@GET
public Response list() {
    List<BusinessService> services = getManager().getAllBusinessServices();
    if (services == null || services.isEmpty()) {
        return Response.noContent().build();
    }
    BusinessServiceListDTO serviceList = new BusinessServiceListDTO(services);
    return Response.ok(serviceList).build();
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) BusinessServiceListDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceListDTO) GET(javax.ws.rs.GET)

Example 3 with BusinessService

use of org.opennms.netmgt.bsm.service.model.BusinessService 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 BusinessService

use of org.opennms.netmgt.bsm.service.model.BusinessService in project opennms by OpenNMS.

the class BusinessServiceRestService method removeEdge.

@DELETE
@Path("{id}/edges/{edgeId}")
public Response removeEdge(@PathParam("id") final Long serviceId, @PathParam("edgeId") final Long edgeId) {
    final BusinessService service = getManager().getBusinessServiceById(serviceId);
    final Edge edge = getManager().getEdgeById(edgeId);
    boolean changed = getManager().deleteEdge(service, edge);
    if (!changed) {
        return Response.notModified().build();
    }
    service.save();
    return Response.ok().build();
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) Edge(org.opennms.netmgt.bsm.service.model.edge.Edge) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 5 with BusinessService

use of org.opennms.netmgt.bsm.service.model.BusinessService in project opennms by OpenNMS.

the class BusinessServiceRestService method delete.

@DELETE
@Path("{id}")
public Response delete(@PathParam("id") Long id) {
    final BusinessService service = getManager().getBusinessServiceById(id);
    getManager().deleteBusinessService(service);
    return Response.ok().build();
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Aggregations

BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)39 Test (org.junit.Test)13 IpServiceEdge (org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge)10 Collectors (java.util.stream.Collectors)9 IpService (org.opennms.netmgt.bsm.service.model.IpService)9 Status (org.opennms.netmgt.bsm.service.model.Status)9 Edge (org.opennms.netmgt.bsm.service.model.edge.Edge)9 BusinessServiceGraph (org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)9 List (java.util.List)8 BusinessServiceManager (org.opennms.netmgt.bsm.service.BusinessServiceManager)8 BusinessServiceStateMachine (org.opennms.netmgt.bsm.service.BusinessServiceStateMachine)8 Map (java.util.Map)7 Objects (java.util.Objects)7 Path (javax.ws.rs.Path)7 ChildEdge (org.opennms.netmgt.bsm.service.model.edge.ChildEdge)7 ReductionKeyEdge (org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge)7 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)6 NoSuchElementException (java.util.NoSuchElementException)5 Set (java.util.Set)5 Criteria (org.opennms.core.criteria.Criteria)5