Search in sources :

Example 1 with UnHealthyContainerStates

use of org.hadoop.ozone.recon.schema.ContainerSchemaDefinition.UnHealthyContainerStates 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)

Example 2 with UnHealthyContainerStates

use of org.hadoop.ozone.recon.schema.ContainerSchemaDefinition.UnHealthyContainerStates in project ozone by apache.

the class TestContainerHealthTaskRecordGenerator method testRecordNotGeneratedIfAlreadyExists.

@Test
public void testRecordNotGeneratedIfAlreadyExists() {
    Set<String> existingRec = new HashSet<>();
    for (UnHealthyContainerStates s : UnHealthyContainerStates.values()) {
        existingRec.add(s.toString());
    }
    // Over-replicated
    Set<ContainerReplica> replicas = generateReplicas(container, CLOSED, CLOSED, CLOSED, CLOSED, CLOSED);
    ContainerHealthStatus status = new ContainerHealthStatus(container, replicas, placementPolicy);
    List<UnhealthyContainers> records = ContainerHealthTask.ContainerHealthRecords.generateUnhealthyRecords(status, existingRec, (long) 1234567);
    assertEquals(0, records.size());
    // Missing
    replicas.clear();
    status = new ContainerHealthStatus(container, replicas, placementPolicy);
    records = ContainerHealthTask.ContainerHealthRecords.generateUnhealthyRecords(status, existingRec, (long) 1234567);
    assertEquals(0, records.size());
    // Under and Mis-Replicated
    replicas = generateReplicas(container, CLOSED, CLOSED);
    when(placementPolicy.validateContainerPlacement(Mockito.anyList(), Mockito.anyInt())).thenReturn(new ContainerPlacementStatusDefault(1, 2, 5));
    status = new ContainerHealthStatus(container, replicas, placementPolicy);
    records = ContainerHealthTask.ContainerHealthRecords.generateUnhealthyRecords(status, existingRec, (long) 1234567);
    assertEquals(0, records.size());
}
Also used : UnHealthyContainerStates(org.hadoop.ozone.recon.schema.ContainerSchemaDefinition.UnHealthyContainerStates) ContainerReplica(org.apache.hadoop.hdds.scm.container.ContainerReplica) UnhealthyContainers(org.hadoop.ozone.recon.schema.tables.pojos.UnhealthyContainers) ContainerPlacementStatusDefault(org.apache.hadoop.hdds.scm.container.placement.algorithms.ContainerPlacementStatusDefault) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

UnHealthyContainerStates (org.hadoop.ozone.recon.schema.ContainerSchemaDefinition.UnHealthyContainerStates)2 UnhealthyContainers (org.hadoop.ozone.recon.schema.tables.pojos.UnhealthyContainers)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)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 ContainerReplica (org.apache.hadoop.hdds.scm.container.ContainerReplica)1 ContainerPlacementStatusDefault (org.apache.hadoop.hdds.scm.container.placement.algorithms.ContainerPlacementStatusDefault)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 Test (org.junit.Test)1