Search in sources :

Example 1 with GlobalStats

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);
}
Also used : GlobalStats(org.hadoop.ozone.recon.schema.tables.pojos.GlobalStats) GlobalStatsDao(org.hadoop.ozone.recon.schema.tables.daos.GlobalStatsDao) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 2 with GlobalStats

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);
    }
}
Also used : GlobalStats(org.hadoop.ozone.recon.schema.tables.pojos.GlobalStats) DSL.currentTimestamp(org.jooq.impl.DSL.currentTimestamp) Timestamp(java.sql.Timestamp)

Example 3 with GlobalStats

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

Aggregations

GlobalStats (org.hadoop.ozone.recon.schema.tables.pojos.GlobalStats)3 Timestamp (java.sql.Timestamp)2 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSet (java.sql.ResultSet)1 GET (javax.ws.rs.GET)1 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)1 SCMNodeStat (org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat)1 ClusterStateResponse (org.apache.hadoop.ozone.recon.api.types.ClusterStateResponse)1 DatanodeStorageReport (org.apache.hadoop.ozone.recon.api.types.DatanodeStorageReport)1 GlobalStatsDao (org.hadoop.ozone.recon.schema.tables.daos.GlobalStatsDao)1 DSL.currentTimestamp (org.jooq.impl.DSL.currentTimestamp)1 Test (org.junit.Test)1