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