use of org.apache.hadoop.ozone.recon.api.types.MissingContainerMetadata in project ozone by apache.
the class ContainerEndpoint method getMissingContainers.
/**
* Return
* {@link org.apache.hadoop.ozone.recon.api.types.MissingContainerMetadata}
* for all missing containers.
*
* @return {@link Response}
*/
@GET
@Path("/missing")
public Response getMissingContainers() {
List<MissingContainerMetadata> missingContainers = new ArrayList<>();
containerHealthSchemaManager.getUnhealthyContainers(UnHealthyContainerStates.MISSING, 0, Integer.MAX_VALUE).forEach(container -> {
long containerID = container.getContainerId();
try {
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());
missingContainers.add(new MissingContainerMetadata(containerID, container.getInStateSince(), keyCount, pipelineID, datanodes));
} catch (IOException ioEx) {
throw new WebApplicationException(ioEx, Response.Status.INTERNAL_SERVER_ERROR);
}
});
MissingContainersResponse response = new MissingContainersResponse(missingContainers.size(), missingContainers);
return Response.ok(response).build();
}
use of org.apache.hadoop.ozone.recon.api.types.MissingContainerMetadata in project ozone by apache.
the class TestContainerEndpoint method testGetMissingContainers.
@Test
public void testGetMissingContainers() throws IOException {
Response response = containerEndpoint.getMissingContainers();
MissingContainersResponse responseObject = (MissingContainersResponse) response.getEntity();
assertEquals(0, responseObject.getTotalCount());
assertEquals(Collections.EMPTY_LIST, responseObject.getContainers());
// Add missing containers to the database
long missingSince = System.currentTimeMillis();
UnhealthyContainers missing = new UnhealthyContainers();
missing.setContainerId(1L);
missing.setInStateSince(missingSince);
missing.setActualReplicaCount(0);
missing.setExpectedReplicaCount(3);
missing.setReplicaDelta(3);
missing.setContainerState(ContainerSchemaDefinition.UnHealthyContainerStates.MISSING.toString());
ArrayList<UnhealthyContainers> missingList = new ArrayList<UnhealthyContainers>();
missingList.add(missing);
containerHealthSchemaManager.insertUnhealthyContainerRecords(missingList);
putContainerInfos(1);
// Add container history for id 1
final UUID u1 = newDatanode("host1", "127.0.0.1");
final UUID u2 = newDatanode("host2", "127.0.0.2");
final UUID u3 = newDatanode("host3", "127.0.0.3");
final UUID u4 = newDatanode("host4", "127.0.0.4");
reconContainerManager.upsertContainerHistory(1L, u1, 1L, 1L);
reconContainerManager.upsertContainerHistory(1L, u2, 2L, 1L);
reconContainerManager.upsertContainerHistory(1L, u3, 3L, 1L);
reconContainerManager.upsertContainerHistory(1L, u4, 4L, 1L);
response = containerEndpoint.getMissingContainers();
responseObject = (MissingContainersResponse) response.getEntity();
assertEquals(1, responseObject.getTotalCount());
MissingContainerMetadata container = responseObject.getContainers().stream().findFirst().orElse(null);
Assert.assertNotNull(container);
assertEquals(containerID.getId(), container.getContainerID());
assertEquals(keyCount, container.getKeys());
assertEquals(pipelineID.getId(), container.getPipelineID());
assertEquals(3, container.getReplicas().size());
assertEquals(missingSince, container.getMissingSince());
Set<String> datanodes = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("host2", "host3", "host4")));
List<ContainerHistory> containerReplicas = container.getReplicas();
containerReplicas.forEach(history -> {
Assert.assertTrue(datanodes.contains(history.getDatanodeHost()));
});
}
Aggregations