Search in sources :

Example 1 with UnhealthyContainersSummary

use of org.apache.hadoop.ozone.recon.api.types.UnhealthyContainersSummary in project ozone by apache.

the class ContainerEndpoint method getUnhealthyContainers.

/**
 * Return
 * {@link org.apache.hadoop.ozone.recon.api.types.UnhealthyContainerMetadata}
 * for all unhealthy containers.
 *
 * @param state Return only containers matching the given unhealthy state,
 *              eg UNDER_REPLICATED, MIS_REPLICATED, OVER_REPLICATED or
 *              MISSING. Passing null returns all containers.
 * @param limit The limit of unhealthy containers to return.
 * @param batchNum The batch number (like "page number") of results to return.
 *                 Passing 1, will return records 1 to limit. 2 will return
 *                 limit + 1 to 2 * limit, etc.
 * @return {@link Response}
 */
@GET
@Path("/unhealthy/{state}")
public Response getUnhealthyContainers(@PathParam("state") String state, @DefaultValue(DEFAULT_FETCH_COUNT) @QueryParam(RECON_QUERY_LIMIT) int limit, @DefaultValue(DEFAULT_BATCH_NUMBER) @QueryParam(RECON_QUERY_BATCH_PARAM) int batchNum) {
    int offset = Math.max(((batchNum - 1) * limit), 0);
    List<UnhealthyContainerMetadata> unhealthyMeta = new ArrayList<>();
    List<UnhealthyContainersSummary> summary;
    try {
        UnHealthyContainerStates internalState = null;
        if (state != null) {
            // If an invalid state is passed in, this will throw
            // illegalArgumentException and fail the request
            internalState = UnHealthyContainerStates.valueOf(state);
        }
        summary = containerHealthSchemaManager.getUnhealthyContainersSummary();
        List<UnhealthyContainers> containers = containerHealthSchemaManager.getUnhealthyContainers(internalState, offset, limit);
        for (UnhealthyContainers c : containers) {
            long containerID = c.getContainerId();
            ContainerInfo containerInfo = containerManager.getContainer(ContainerID.valueOf(containerID));
            long keyCount = containerInfo.getNumberOfKeys();
            UUID pipelineID = containerInfo.getPipelineID().getId();
            List<ContainerHistory> datanodes = containerManager.getLatestContainerHistory(containerID, containerInfo.getReplicationConfig().getRequiredNodes());
            unhealthyMeta.add(new UnhealthyContainerMetadata(c, datanodes, pipelineID, keyCount));
        }
    } catch (IOException ex) {
        throw new WebApplicationException(ex, Response.Status.INTERNAL_SERVER_ERROR);
    } catch (IllegalArgumentException e) {
        throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
    }
    UnhealthyContainersResponse response = new UnhealthyContainersResponse(unhealthyMeta);
    for (UnhealthyContainersSummary s : summary) {
        response.setSummaryCount(s.getContainerState(), s.getCount());
    }
    return Response.ok(response).build();
}
Also used : UnhealthyContainerMetadata(org.apache.hadoop.ozone.recon.api.types.UnhealthyContainerMetadata) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) UnhealthyContainersResponse(org.apache.hadoop.ozone.recon.api.types.UnhealthyContainersResponse) IOException(java.io.IOException) UnHealthyContainerStates(org.hadoop.ozone.recon.schema.ContainerSchemaDefinition.UnHealthyContainerStates) ContainerHistory(org.apache.hadoop.ozone.recon.persistence.ContainerHistory) UnhealthyContainers(org.hadoop.ozone.recon.schema.tables.pojos.UnhealthyContainers) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) UUID(java.util.UUID) UnhealthyContainersSummary(org.apache.hadoop.ozone.recon.api.types.UnhealthyContainersSummary) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ContainerInfo (org.apache.hadoop.hdds.scm.container.ContainerInfo)1 UnhealthyContainerMetadata (org.apache.hadoop.ozone.recon.api.types.UnhealthyContainerMetadata)1 UnhealthyContainersResponse (org.apache.hadoop.ozone.recon.api.types.UnhealthyContainersResponse)1 UnhealthyContainersSummary (org.apache.hadoop.ozone.recon.api.types.UnhealthyContainersSummary)1 ContainerHistory (org.apache.hadoop.ozone.recon.persistence.ContainerHistory)1 UnHealthyContainerStates (org.hadoop.ozone.recon.schema.ContainerSchemaDefinition.UnHealthyContainerStates)1 UnhealthyContainers (org.hadoop.ozone.recon.schema.tables.pojos.UnhealthyContainers)1