Search in sources :

Example 1 with NodeStatusCalculationStrategy

use of org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy in project opennms by OpenNMS.

the class StatusRestService method getNodeStatus.

@GET
@Path("/summary/nodes/{type}")
public Response getNodeStatus(@PathParam("type") String type) {
    final NodeStatusCalculationStrategy strategy = NodeStatusCalculationStrategy.createFrom(type);
    if (strategy == null) {
        return Response.status(Response.Status.BAD_REQUEST).entity("Strategy '" + type + "' not supported. Supported values are:" + Arrays.toString(NodeStatusCalculationStrategy.values())).build();
    }
    final StatusSummary summary = nodeStatusService.getSummary(strategy);
    return Response.ok().entity(convert(summary)).build();
}
Also used : StatusSummary(org.opennms.features.status.api.StatusSummary) NodeStatusCalculationStrategy(org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with NodeStatusCalculationStrategy

use of org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy in project opennms by OpenNMS.

the class StatusRestService method getNodes.

@GET
@Path("/nodes/{type}")
public Response getNodes(@Context final UriInfo uriInfo, @PathParam("type") String type) {
    final NodeStatusCalculationStrategy strategy = NodeStatusCalculationStrategy.createFrom(type);
    if (strategy == null) {
        return Response.status(Response.Status.BAD_REQUEST).entity("Strategy '" + type + "' not supported. Supported values are:" + Arrays.toString(NodeStatusCalculationStrategy.values())).build();
    }
    final QueryParameters queryParameters = QueryParametersBuilder.buildFrom(uriInfo);
    final SeverityFilter severityFilter = getSeverityFilter(uriInfo);
    final NodeQuery query = new NodeQuery(queryParameters, severityFilter);
    query.setStatusCalculationStrategy(strategy);
    // Adjust order parameters
    if (query.getParameters().getOrder() != null && query.getParameters().getOrder().getColumn().equals("label")) {
        query.getParameters().setOrder(new QueryParameters.Order("node.nodelabel", query.getParameters().getOrder().isDesc()));
    }
    final List<StatusEntity<OnmsNode>> nodes = nodeStatusService.getStatus(query);
    final int totalCount = nodeStatusService.count(query);
    final int offset = queryParameters.getOffset();
    final List<NodeDTO> statusEntities = nodes.stream().map(node -> {
        NodeDTO nodeDTO = new NodeDTO();
        nodeDTO.setId(node.getEntity().getId());
        nodeDTO.setName(node.getEntity().getLabel());
        nodeDTO.setSeverity(node.getStatus());
        return nodeDTO;
    }).collect(Collectors.toList());
    final NodeDTOList list = new NodeDTOList(statusEntities);
    list.setOffset(queryParameters.getOffset());
    list.setTotalCount(totalCount);
    return createResponse(list, offset, totalCount);
}
Also used : Arrays(java.util.Arrays) PathParam(javax.ws.rs.PathParam) QueryParameters(org.opennms.web.utils.QueryParameters) NodeStatusCalculationStrategy(org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy) Produces(javax.ws.rs.Produces) BusinessServiceDTO(org.opennms.web.rest.v2.status.model.BusinessServiceDTO) GET(javax.ws.rs.GET) NodeDTO(org.opennms.web.rest.v2.status.model.NodeDTO) Path(javax.ws.rs.Path) Autowired(org.springframework.beans.factory.annotation.Autowired) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) JaxbListWrapper(org.opennms.core.config.api.JaxbListWrapper) ApplicationStatusService(org.opennms.features.status.api.application.ApplicationStatusService) Strings(com.google.common.base.Strings) MediaType(javax.ws.rs.core.MediaType) StatusSummary(org.opennms.features.status.api.StatusSummary) BusinessServiceStatusService(org.opennms.features.status.api.bsm.BusinessServiceStatusService) Map(java.util.Map) NodeQuery(org.opennms.features.status.api.node.NodeQuery) QueryParametersBuilder(org.opennms.web.utils.QueryParametersBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) ApplicationDTO(org.opennms.web.rest.v2.status.model.ApplicationDTO) SeverityFilter(org.opennms.features.status.api.SeverityFilter) Context(javax.ws.rs.core.Context) NodeDTOList(org.opennms.web.rest.v2.status.model.NodeDTOList) Query(org.opennms.features.status.api.Query) NodeStatusService(org.opennms.features.status.api.node.NodeStatusService) Collectors(java.util.stream.Collectors) StatusEntity(org.opennms.features.status.api.StatusEntity) List(java.util.List) Component(org.springframework.stereotype.Component) Response(javax.ws.rs.core.Response) BusinessServiceDTOList(org.opennms.web.rest.v2.status.model.BusinessServiceDTOList) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) ApplicationDTOList(org.opennms.web.rest.v2.status.model.ApplicationDTOList) UriInfo(javax.ws.rs.core.UriInfo) Comparator(java.util.Comparator) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) SeverityFilter(org.opennms.features.status.api.SeverityFilter) NodeQuery(org.opennms.features.status.api.node.NodeQuery) NodeStatusCalculationStrategy(org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy) QueryParameters(org.opennms.web.utils.QueryParameters) StatusEntity(org.opennms.features.status.api.StatusEntity) NodeDTO(org.opennms.web.rest.v2.status.model.NodeDTO) NodeDTOList(org.opennms.web.rest.v2.status.model.NodeDTOList) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 StatusSummary (org.opennms.features.status.api.StatusSummary)2 NodeStatusCalculationStrategy (org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy)2 Strings (com.google.common.base.Strings)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 PathParam (javax.ws.rs.PathParam)1 Produces (javax.ws.rs.Produces)1 Context (javax.ws.rs.core.Context)1 MediaType (javax.ws.rs.core.MediaType)1 Response (javax.ws.rs.core.Response)1 UriInfo (javax.ws.rs.core.UriInfo)1 JaxbListWrapper (org.opennms.core.config.api.JaxbListWrapper)1 Query (org.opennms.features.status.api.Query)1 SeverityFilter (org.opennms.features.status.api.SeverityFilter)1 StatusEntity (org.opennms.features.status.api.StatusEntity)1