Search in sources :

Example 1 with ClusterStateResponse

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

the class ClusterStateEndpoint method getClusterState.

/**
 * Return a summary report on current cluster state.
 * @return {@link Response}
 */
@GET
public Response getClusterState() {
    List<DatanodeDetails> datanodeDetails = nodeManager.getAllNodes();
    int containers = this.containerManager.getContainers().size();
    int pipelines = this.pipelineManager.getPipelines().size();
    int healthyDatanodes = nodeManager.getNodeCount(NodeStatus.inServiceHealthy()) + nodeManager.getNodeCount(NodeStatus.inServiceHealthyReadOnly());
    SCMNodeStat stats = nodeManager.getStats();
    DatanodeStorageReport storageReport = new DatanodeStorageReport(stats.getCapacity().get(), stats.getScmUsed().get(), stats.getRemaining().get());
    ClusterStateResponse.Builder builder = ClusterStateResponse.newBuilder();
    GlobalStats volumeRecord = globalStatsDao.findById(TableCountTask.getRowKeyFromTable(VOLUME_TABLE));
    GlobalStats bucketRecord = globalStatsDao.findById(TableCountTask.getRowKeyFromTable(BUCKET_TABLE));
    // Keys from OBJECT_STORE buckets.
    GlobalStats keyRecord = globalStatsDao.findById(TableCountTask.getRowKeyFromTable(KEY_TABLE));
    // Keys from FILE_SYSTEM_OPTIMIZED buckets
    GlobalStats fileRecord = globalStatsDao.findById(TableCountTask.getRowKeyFromTable(FILE_TABLE));
    if (volumeRecord != null) {
        builder.setVolumes(volumeRecord.getValue());
    }
    if (bucketRecord != null) {
        builder.setBuckets(bucketRecord.getValue());
    }
    Long totalKeys = 0L;
    if (keyRecord != null) {
        totalKeys += keyRecord.getValue();
    }
    if (fileRecord != null) {
        totalKeys += fileRecord.getValue();
    }
    builder.setKeys(totalKeys);
    ClusterStateResponse response = builder.setStorageReport(storageReport).setPipelines(pipelines).setContainers(containers).setTotalDatanodes(datanodeDetails.size()).setHealthyDatanodes(healthyDatanodes).build();
    return Response.ok(response).build();
}
Also used : GlobalStats(org.hadoop.ozone.recon.schema.tables.pojos.GlobalStats) DatanodeStorageReport(org.apache.hadoop.ozone.recon.api.types.DatanodeStorageReport) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) ClusterStateResponse(org.apache.hadoop.ozone.recon.api.types.ClusterStateResponse) SCMNodeStat(org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat) GET(javax.ws.rs.GET)

Example 2 with ClusterStateResponse

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

the class TestEndpoints method testGetClusterState.

@Test
public void testGetClusterState() throws Exception {
    Response response = clusterStateEndpoint.getClusterState();
    ClusterStateResponse clusterStateResponse = (ClusterStateResponse) response.getEntity();
    Assert.assertEquals(1, clusterStateResponse.getPipelines());
    Assert.assertEquals(0, clusterStateResponse.getVolumes());
    Assert.assertEquals(0, clusterStateResponse.getBuckets());
    Assert.assertEquals(0, clusterStateResponse.getKeys());
    Assert.assertEquals(2, clusterStateResponse.getTotalDatanodes());
    Assert.assertEquals(2, clusterStateResponse.getHealthyDatanodes());
    waitAndCheckConditionAfterHeartbeat(() -> {
        Response response1 = clusterStateEndpoint.getClusterState();
        ClusterStateResponse clusterStateResponse1 = (ClusterStateResponse) response1.getEntity();
        return (clusterStateResponse1.getContainers() == 1);
    });
    // check volume, bucket and key count after running table count task
    Pair<String, Boolean> result = tableCountTask.reprocess(reconOMMetadataManager);
    assertTrue(result.getRight());
    response = clusterStateEndpoint.getClusterState();
    clusterStateResponse = (ClusterStateResponse) response.getEntity();
    Assert.assertEquals(2, clusterStateResponse.getVolumes());
    Assert.assertEquals(2, clusterStateResponse.getBuckets());
    Assert.assertEquals(3, clusterStateResponse.getKeys());
}
Also used : ClusterStateResponse(org.apache.hadoop.ozone.recon.api.types.ClusterStateResponse) DatanodesResponse(org.apache.hadoop.ozone.recon.api.types.DatanodesResponse) Response(javax.ws.rs.core.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) PipelinesResponse(org.apache.hadoop.ozone.recon.api.types.PipelinesResponse) ClusterStateResponse(org.apache.hadoop.ozone.recon.api.types.ClusterStateResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Test(org.junit.Test) AbstractReconSqlDBTest(org.apache.hadoop.ozone.recon.persistence.AbstractReconSqlDBTest)

Aggregations

ClusterStateResponse (org.apache.hadoop.ozone.recon.api.types.ClusterStateResponse)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 GET (javax.ws.rs.GET)1 Response (javax.ws.rs.core.Response)1 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)1 SCMNodeStat (org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat)1 DatanodeStorageReport (org.apache.hadoop.ozone.recon.api.types.DatanodeStorageReport)1 DatanodesResponse (org.apache.hadoop.ozone.recon.api.types.DatanodesResponse)1 PipelinesResponse (org.apache.hadoop.ozone.recon.api.types.PipelinesResponse)1 AbstractReconSqlDBTest (org.apache.hadoop.ozone.recon.persistence.AbstractReconSqlDBTest)1 GlobalStats (org.hadoop.ozone.recon.schema.tables.pojos.GlobalStats)1 Test (org.junit.Test)1 ArgumentMatchers.anyBoolean (org.mockito.ArgumentMatchers.anyBoolean)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1