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