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());
}
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);
}
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);
}
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;
}
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);
}
Aggregations