use of org.hadoop.ozone.recon.schema.tables.pojos.GlobalStats in project ozone by apache.
the class TestStatsSchemaDefinition method testGlobalStatsCRUDOperations.
@Test
public void testGlobalStatsCRUDOperations() throws Exception {
Connection connection = getConnection();
DatabaseMetaData metaData = connection.getMetaData();
ResultSet resultSet = metaData.getTables(null, null, GLOBAL_STATS_TABLE_NAME, null);
while (resultSet.next()) {
Assert.assertEquals(GLOBAL_STATS_TABLE_NAME, resultSet.getString("TABLE_NAME"));
}
GlobalStatsDao dao = getDao(GlobalStatsDao.class);
long now = System.currentTimeMillis();
GlobalStats newRecord = new GlobalStats();
newRecord.setLastUpdatedTimestamp(new Timestamp(now));
newRecord.setKey("key1");
newRecord.setValue(500L);
// Create
dao.insert(newRecord);
GlobalStats newRecord2 = new GlobalStats();
newRecord2.setLastUpdatedTimestamp(new Timestamp(now + 1000L));
newRecord2.setKey("key2");
newRecord2.setValue(10L);
dao.insert(newRecord2);
// Read
GlobalStats dbRecord = dao.findById("key1");
Assert.assertEquals("key1", dbRecord.getKey());
Assert.assertEquals(Long.valueOf(500), dbRecord.getValue());
Assert.assertEquals(new Timestamp(now), dbRecord.getLastUpdatedTimestamp());
dbRecord = dao.findById("key2");
Assert.assertEquals("key2", dbRecord.getKey());
Assert.assertEquals(Long.valueOf(10), dbRecord.getValue());
Assert.assertEquals(new Timestamp(now + 1000L), dbRecord.getLastUpdatedTimestamp());
// Update
dbRecord.setValue(100L);
dbRecord.setLastUpdatedTimestamp(new Timestamp(now + 2000L));
dao.update(dbRecord);
// Read updated
dbRecord = dao.findById("key2");
Assert.assertEquals(new Timestamp(now + 2000L), dbRecord.getLastUpdatedTimestamp());
Assert.assertEquals(Long.valueOf(100L), dbRecord.getValue());
// Delete
dao.deleteById("key1");
// Verify
dbRecord = dao.findById("key1");
Assert.assertNull(dbRecord);
}
use of org.hadoop.ozone.recon.schema.tables.pojos.GlobalStats in project ozone by apache.
the class ReconUtils method upsertGlobalStatsTable.
/**
* Upsert row in GlobalStats table.
*
* @param sqlConfiguration
* @param globalStatsDao
* @param key
* @param count
*/
public static void upsertGlobalStatsTable(Configuration sqlConfiguration, GlobalStatsDao globalStatsDao, String key, Long count) {
// Get the current timestamp
Timestamp now = using(sqlConfiguration).fetchValue(select(currentTimestamp()));
GlobalStats record = globalStatsDao.fetchOneByKey(key);
GlobalStats newRecord = new GlobalStats(key, count, now);
// Insert a new record for key if it does not exist
if (record == null) {
globalStatsDao.insert(newRecord);
} else {
globalStatsDao.update(newRecord);
}
}
use of org.hadoop.ozone.recon.schema.tables.pojos.GlobalStats 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();
}
Aggregations