Search in sources :

Example 1 with SeverityFilter

use of org.opennms.features.status.api.SeverityFilter in project opennms by OpenNMS.

the class StatusRestService method getApplications.

@GET
@Path("/applications")
public Response getApplications(@Context final UriInfo uriInfo) {
    final QueryParameters queryParameters = QueryParametersBuilder.buildFrom(uriInfo);
    final SeverityFilter severityFilter = getSeverityFilter(uriInfo);
    final Query query = new Query(queryParameters, severityFilter);
    final List<StatusEntity<OnmsApplication>> applications = applicationStatusService.getStatus(query);
    final int totalCount = applicationStatusService.count(query);
    final int offset = queryParameters.getOffset();
    final List<ApplicationDTO> statusEntities = applications.stream().map(a -> {
        ApplicationDTO dto = new ApplicationDTO();
        dto.setId(a.getEntity().getId());
        dto.setName(a.getEntity().getName());
        dto.setSeverity(a.getStatus());
        return dto;
    }).collect(Collectors.toList());
    final ApplicationDTOList list = new ApplicationDTOList(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) ApplicationDTO(org.opennms.web.rest.v2.status.model.ApplicationDTO) NodeQuery(org.opennms.features.status.api.node.NodeQuery) Query(org.opennms.features.status.api.Query) ApplicationDTOList(org.opennms.web.rest.v2.status.model.ApplicationDTOList) QueryParameters(org.opennms.web.utils.QueryParameters) StatusEntity(org.opennms.features.status.api.StatusEntity) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with SeverityFilter

use of org.opennms.features.status.api.SeverityFilter in project opennms by OpenNMS.

the class StatusRestService method getSeverityFilter.

private static SeverityFilter getSeverityFilter(UriInfo uriInfo) {
    final SeverityFilter severityFilter = new SeverityFilter();
    final List<String> severityFilterList = uriInfo.getQueryParameters().get("severityFilter");
    if (severityFilterList != null) {
        for (String eachSeverity : severityFilterList) {
            OnmsSeverity severity = getSeverity(eachSeverity);
            severityFilter.add(severity);
        }
    }
    return severityFilter;
}
Also used : SeverityFilter(org.opennms.features.status.api.SeverityFilter) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity)

Example 3 with SeverityFilter

use of org.opennms.features.status.api.SeverityFilter 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)

Example 4 with SeverityFilter

use of org.opennms.features.status.api.SeverityFilter in project opennms by OpenNMS.

the class StatusRestService method getBusinessServices.

@GET
@Path("/business-services")
public Response getBusinessServices(@Context final UriInfo uriInfo) {
    final QueryParameters queryParameters = QueryParametersBuilder.buildFrom(uriInfo);
    final SeverityFilter severityFilter = getSeverityFilter(uriInfo);
    final Query query = new Query(queryParameters, severityFilter);
    final List<StatusEntity<BusinessService>> services = businessServiceStatusService.getStatus(query);
    final int totalCount = businessServiceStatusService.count(query);
    final int offset = queryParameters.getOffset();
    final List<BusinessServiceDTO> statusEntities = services.stream().map(bs -> {
        BusinessServiceDTO statusDTO = new BusinessServiceDTO();
        statusDTO.setId(bs.getEntity().getId().intValue());
        statusDTO.setName(bs.getEntity().getName());
        statusDTO.setSeverity(bs.getStatus());
        return statusDTO;
    }).collect(Collectors.toList());
    final BusinessServiceDTOList list = new BusinessServiceDTOList(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) Query(org.opennms.features.status.api.Query) BusinessServiceDTOList(org.opennms.web.rest.v2.status.model.BusinessServiceDTOList) BusinessServiceDTO(org.opennms.web.rest.v2.status.model.BusinessServiceDTO) QueryParameters(org.opennms.web.utils.QueryParameters) StatusEntity(org.opennms.features.status.api.StatusEntity) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

SeverityFilter (org.opennms.features.status.api.SeverityFilter)4 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)4 Strings (com.google.common.base.Strings)3 Arrays (java.util.Arrays)3 Comparator (java.util.Comparator)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 PathParam (javax.ws.rs.PathParam)3 Produces (javax.ws.rs.Produces)3 Context (javax.ws.rs.core.Context)3 MediaType (javax.ws.rs.core.MediaType)3 Response (javax.ws.rs.core.Response)3 UriInfo (javax.ws.rs.core.UriInfo)3 JaxbListWrapper (org.opennms.core.config.api.JaxbListWrapper)3 Query (org.opennms.features.status.api.Query)3 StatusEntity (org.opennms.features.status.api.StatusEntity)3 StatusSummary (org.opennms.features.status.api.StatusSummary)3