Search in sources :

Example 1 with MissingContainerMetadata

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();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) MissingContainerMetadata(org.apache.hadoop.ozone.recon.api.types.MissingContainerMetadata) ContainerHistory(org.apache.hadoop.ozone.recon.persistence.ContainerHistory) ArrayList(java.util.ArrayList) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) IOException(java.io.IOException) MissingContainersResponse(org.apache.hadoop.ozone.recon.api.types.MissingContainersResponse) UUID(java.util.UUID) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with MissingContainerMetadata

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()));
    });
}
Also used : ArrayList(java.util.ArrayList) MissingContainersResponse(org.apache.hadoop.ozone.recon.api.types.MissingContainersResponse) KeysResponse(org.apache.hadoop.ozone.recon.api.types.KeysResponse) ContainersResponse(org.apache.hadoop.ozone.recon.api.types.ContainersResponse) Response(javax.ws.rs.core.Response) UnhealthyContainersResponse(org.apache.hadoop.ozone.recon.api.types.UnhealthyContainersResponse) MissingContainerMetadata(org.apache.hadoop.ozone.recon.api.types.MissingContainerMetadata) ContainerHistory(org.apache.hadoop.ozone.recon.persistence.ContainerHistory) UnhealthyContainers(org.hadoop.ozone.recon.schema.tables.pojos.UnhealthyContainers) MissingContainersResponse(org.apache.hadoop.ozone.recon.api.types.MissingContainersResponse) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 MissingContainerMetadata (org.apache.hadoop.ozone.recon.api.types.MissingContainerMetadata)2 MissingContainersResponse (org.apache.hadoop.ozone.recon.api.types.MissingContainersResponse)2 ContainerHistory (org.apache.hadoop.ozone.recon.persistence.ContainerHistory)2 IOException (java.io.IOException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Response (javax.ws.rs.core.Response)1 ContainerInfo (org.apache.hadoop.hdds.scm.container.ContainerInfo)1 ContainersResponse (org.apache.hadoop.ozone.recon.api.types.ContainersResponse)1 KeysResponse (org.apache.hadoop.ozone.recon.api.types.KeysResponse)1 UnhealthyContainersResponse (org.apache.hadoop.ozone.recon.api.types.UnhealthyContainersResponse)1 UnhealthyContainers (org.hadoop.ozone.recon.schema.tables.pojos.UnhealthyContainers)1 Test (org.junit.Test)1