Search in sources :

Example 1 with StatusEntity

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

the class NodeStatusService method getStatus.

public List<StatusEntity<OnmsNode>> getStatus(NodeQuery query) {
    // Build query
    final NodeStatusCalculatorConfig config = buildFrom(query);
    // Calculate Status
    final Status status = statusCalculator.calculateStatus(config);
    // Find nodes for node id
    final List<OnmsNode> nodes = getNodes(status.getIds());
    final Map<Integer, OnmsNode> nodeIdMap = nodes.stream().collect(Collectors.toMap(n -> n.getId(), n -> n));
    // convert to wrapper
    return status.getIds().stream().map(nodeId -> {
        OnmsSeverity nodeStatus = status.getSeverity(nodeId);
        OnmsNode node = nodeIdMap.get(nodeId);
        if (nodeStatus == null) {
            throw new IllegalStateException("nodeStatus should not be null");
        }
        if (node == null) {
            throw new IllegalStateException("node should not be null");
        }
        return new StatusEntityWrapper<>(node, nodeStatus);
    }).collect(Collectors.toList());
}
Also used : Status(org.opennms.features.status.api.node.strategy.Status) NodeDao(org.opennms.netmgt.dao.api.NodeDao) NodeStatusCalculationStrategy(org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy) Status(org.opennms.features.status.api.node.strategy.Status) Autowired(org.springframework.beans.factory.annotation.Autowired) NodeStatusCalculatorConfig(org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig) StatusEntityWrapper(org.opennms.features.status.api.StatusEntityWrapper) Collectors(java.util.stream.Collectors) StatusEntity(org.opennms.features.status.api.StatusEntity) ArrayList(java.util.ArrayList) List(java.util.List) StatusSummary(org.opennms.features.status.api.StatusSummary) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) NodeStatusCalculatorConfig(org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig)

Example 2 with StatusEntity

use of org.opennms.features.status.api.StatusEntity 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 3 with StatusEntity

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

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

the class BusinessServiceStatusService method getStatus.

public List<StatusEntity<BusinessService>> getStatus(Query query) {
    final BusinessServiceSearchCriteriaBuilder criteria = buildFrom(query);
    final List<BusinessService> services = criteria.apply(businessServiceManager, businessServiceManager.getAllBusinessServices());
    final List<StatusEntity<BusinessService>> mappedServices = services.stream().map(eachService -> new StatusEntityWrapper<>(eachService, OnmsSeverity.get(eachService.getOperationalStatus().getLabel()))).collect(Collectors.toList());
    return mappedServices;
}
Also used : QueryParameters(org.opennms.web.utils.QueryParameters) BusinessServiceManager(org.opennms.netmgt.bsm.service.BusinessServiceManager) Autowired(org.springframework.beans.factory.annotation.Autowired) Query(org.opennms.features.status.api.Query) StatusEntityWrapper(org.opennms.features.status.api.StatusEntityWrapper) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Collectors(java.util.stream.Collectors) StatusEntity(org.opennms.features.status.api.StatusEntity) BusinessServiceSearchCriteriaBuilder(org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteriaBuilder) List(java.util.List) StatusSummary(org.opennms.features.status.api.StatusSummary) Status(org.opennms.netmgt.bsm.service.model.Status) Service(org.springframework.stereotype.Service) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) StatusEntityWrapper(org.opennms.features.status.api.StatusEntityWrapper) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) BusinessServiceSearchCriteriaBuilder(org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteriaBuilder) StatusEntity(org.opennms.features.status.api.StatusEntity)

Example 5 with StatusEntity

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

List (java.util.List)5 Collectors (java.util.stream.Collectors)5 StatusEntity (org.opennms.features.status.api.StatusEntity)5 StatusSummary (org.opennms.features.status.api.StatusSummary)5 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Map (java.util.Map)4 Query (org.opennms.features.status.api.Query)4 NodeStatusCalculationStrategy (org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy)4 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 QueryParameters (org.opennms.web.utils.QueryParameters)4 Strings (com.google.common.base.Strings)3 Arrays (java.util.Arrays)3 Comparator (java.util.Comparator)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