Search in sources :

Example 16 with BusinessService

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

the class BusinessServiceSearchProvider method queryVertices.

@Override
public List<? extends VertexRef> queryVertices(SearchQuery searchQuery, GraphContainer container) {
    List<BusinessServiceVertex> results = Lists.newArrayList();
    String queryString = searchQuery.getQueryString();
    CriteriaBuilder bldr = new CriteriaBuilder(BusinessService.class);
    if (queryString != null && queryString.length() > 0) {
        bldr.ilike("name", String.format("%%%s%%", queryString));
    }
    bldr.orderBy("name", true);
    bldr.limit(10);
    Criteria dbQueryCriteria = bldr.toCriteria();
    for (BusinessService bs : businessServiceManager.findMatching(dbQueryCriteria)) {
        final BusinessServiceVertex businessServiceVertex = new BusinessServiceVertex(bs, 0);
        // Only consider results which are available in the Topology Provider, see BSM-191
        if (container.getTopologyServiceClient().getVertex(businessServiceVertex) != null) {
            results.add(businessServiceVertex);
        }
    }
    return results;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Criteria(org.opennms.core.criteria.Criteria)

Example 17 with BusinessService

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

the class BusinessServicesTopologyProvider method getDefaults.

@Override
public Defaults getDefaults() {
    return new Defaults().withPreferredLayout("Hierarchy Layout").withCriteria(() -> {
        // Grab the business service with the smallest id
        List<BusinessService> businessServices = businessServiceManager.findMatching(new CriteriaBuilder(BusinessService.class).orderBy("id", true).limit(1).toCriteria());
        // If one was found, use it for the default focus
        if (!businessServices.isEmpty()) {
            BusinessService businessService = businessServices.iterator().next();
            BusinessServiceVertex businessServiceVertex = new BusinessServiceVertex(businessService, 0);
            return Lists.newArrayList(new VertexHopGraphProvider.DefaultVertexHopCriteria(businessServiceVertex));
        }
        return null;
    });
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Defaults(org.opennms.features.topology.api.topo.Defaults) VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider)

Example 18 with BusinessService

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

the class BusinessServicesBoxController method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    int numberOfRows = Integer.getInteger("opennms.businessServicesWithProblems.count", DEFAULT_ROW_COUNT);
    BusinessServiceSearchCriteriaBuilder criteriaBuilder = new BusinessServiceSearchCriteriaBuilder().order(BusinessServiceSearchCriteriaBuilder.Order.Severity).greaterSeverity(Status.NORMAL).desc();
    List<BusinessService> bsList = criteriaBuilder.apply(businessServiceManager, businessServiceManager.getAllBusinessServices());
    boolean more = bsList.size() - numberOfRows > 0;
    if (bsList.size() > numberOfRows) {
        bsList = bsList.subList(0, numberOfRows);
    }
    ModelAndView modelAndView = new ModelAndView(m_successView);
    modelAndView.addObject("more", more);
    modelAndView.addObject("services", bsList);
    return modelAndView;
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) BusinessServiceSearchCriteriaBuilder(org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteriaBuilder) ModelAndView(org.springframework.web.servlet.ModelAndView)

Example 19 with BusinessService

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

the class BusinessServiceRestService method addReductionKeyEdge.

@POST
@Path("{id}/reduction-key-edge")
public // Add Reduction Key
Response addReductionKeyEdge(@PathParam("id") final Long serviceId, final ReductionKeyEdgeRequestDTO edgeRequest) {
    final BusinessService businessService = getManager().getBusinessServiceById(serviceId);
    boolean changed = getManager().addReductionKeyEdge(businessService, edgeRequest.getReductionKey(), transform(edgeRequest.getMapFunction()), edgeRequest.getWeight(), edgeRequest.getFriendlyName());
    if (!changed) {
        return Response.notModified().build();
    }
    businessService.save();
    return Response.ok().build();
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 20 with BusinessService

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

the class BusinessServiceRestService method getById.

@GET
@Path("{id}")
public Response getById(@PathParam("id") Long id) {
    BusinessService service = getManager().getBusinessServiceById(id);
    final BusinessServiceResponseDTO response = new BusinessServiceResponseDTO();
    response.setId(service.getId());
    response.setName(service.getName());
    response.setAttributes(service.getAttributes());
    response.setLocation(ResourceLocationFactory.createBusinessServiceLocation(service.getId().toString()));
    response.setParentServices(service.getParentServices().stream().map(BusinessService::getId).collect(Collectors.toSet()));
    response.setOperationalStatus(service.getOperationalStatus());
    response.setReduceFunction(transform(service.getReduceFunction()));
    service.getEdges().forEach(eachEdge -> eachEdge.accept(new EdgeVisitor<Void>() {

        @Override
        public Void visit(IpServiceEdge edge) {
            response.getIpServices().add(transform(edge));
            return null;
        }

        @Override
        public Void visit(ReductionKeyEdge edge) {
            response.getReductionKeys().add(transform(edge));
            return null;
        }

        @Override
        public Void visit(ChildEdge edge) {
            response.getChildren().add(transform(edge));
            return null;
        }
    }));
    return Response.ok(response).build();
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) BusinessServiceResponseDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO) ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) EdgeVisitor(org.opennms.netmgt.bsm.service.model.edge.EdgeVisitor) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

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