Search in sources :

Example 1 with StorageCapacity

use of org.smartdata.model.StorageCapacity in project SSM by Intel-bigdata.

the class TestStorageHistoryDao method testInsertGetStorageTable.

@Test
public void testInsertGetStorageTable() throws Exception {
    StorageCapacity[] storageCapacities = new StorageCapacity[3];
    storageCapacities[0] = new StorageCapacity("type1", 1000L, 10L, 1L);
    storageCapacities[1] = new StorageCapacity("type1", 2000L, 10L, 2L);
    storageCapacities[2] = new StorageCapacity("type1", 3000L, 10L, 3L);
    storageHistDao.insertStorageHistTable(storageCapacities, 1000);
    List<StorageCapacity> capacities = storageHistDao.getStorageHistoryData("type1", 1000, 1000, 3000);
    Assert.assertTrue(capacities.size() == storageCapacities.length);
    Assert.assertEquals(storageCapacities.length, storageHistDao.getNumberOfStorageHistoryData("type1", 1000));
    storageHistDao.deleteOldRecords("type1", 1000, 1000L);
    Assert.assertEquals(storageCapacities.length - 1, storageHistDao.getNumberOfStorageHistoryData("type1", 1000));
}
Also used : StorageCapacity(org.smartdata.model.StorageCapacity) Test(org.junit.Test)

Example 2 with StorageCapacity

use of org.smartdata.model.StorageCapacity in project SSM by Intel-bigdata.

the class TestStorageDao method testInsertGetStorageTable.

@Test
public void testInsertGetStorageTable() throws Exception {
    StorageCapacity[] storageCapacities = new StorageCapacity[2];
    storageCapacities[0] = new StorageCapacity("type1", 1L, 1L);
    storageCapacities[1] = new StorageCapacity("type2", 2L, 2L);
    storageDao.insertUpdateStoragesTable(storageCapacities);
    Assert.assertTrue(storageDao.getStorageCapacity("type1").equals(storageCapacities[0]));
    Map<String, StorageCapacity> map = storageDao.getStorageTablesItem();
    Assert.assertTrue(map.get("type2").equals(storageCapacities[1]));
}
Also used : StorageCapacity(org.smartdata.model.StorageCapacity) Test(org.junit.Test)

Example 3 with StorageCapacity

use of org.smartdata.model.StorageCapacity in project SSM by Intel-bigdata.

the class StatesManager method getStorageUtilization.

public Utilization getStorageUtilization(String resourceName) throws IOException {
    try {
        long now = System.currentTimeMillis();
        if (!resourceName.equals("cache")) {
            long capacity = serverContext.getMetaStore().getStoreCapacityOfDifferentStorageType(resourceName);
            long free = serverContext.getMetaStore().getStoreFreeOfDifferentStorageType(resourceName);
            return new Utilization(now, capacity, capacity - free);
        } else {
            StorageCapacity storageCapacity = serverContext.getMetaStore().getStorageCapacity("cache");
            return new Utilization(now, storageCapacity.getCapacity(), storageCapacity.getCapacity() - storageCapacity.getFree());
        }
    } catch (MetaStoreException e) {
        throw new IOException(e);
    }
}
Also used : MetaStoreException(org.smartdata.metastore.MetaStoreException) Utilization(org.smartdata.model.Utilization) StorageCapacity(org.smartdata.model.StorageCapacity) IOException(java.io.IOException)

Example 4 with StorageCapacity

use of org.smartdata.model.StorageCapacity in project SSM by Intel-bigdata.

the class StorageHistoryDao method getStorageHistoryData.

public List<StorageCapacity> getStorageHistoryData(String type, long interval, long startTime, long endTime) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    String sql = "SELECT * FROM storage_hist WHERE type = ? AND " + "time_stamp BETWEEN ? AND ?";
    List<StorageCapacity> data = jdbcTemplate.query(sql, new Object[] { type + "-" + interval, startTime, endTime }, new StorageHistoryRowMapper());
    for (StorageCapacity sc : data) {
        sc.setType(type);
    }
    return data;
}
Also used : StorageCapacity(org.smartdata.model.StorageCapacity) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Example 5 with StorageCapacity

use of org.smartdata.model.StorageCapacity in project SSM by Intel-bigdata.

the class SmartEngine method getHistUtilization.

public List<Utilization> getHistUtilization(String resourceName, long granularity, long begin, long end) throws IOException {
    long now = System.currentTimeMillis();
    if (begin == end && Math.abs(begin - now) <= 5) {
        return Arrays.asList(getUtilization(resourceName));
    }
    List<StorageCapacity> cs = serverContext.getMetaStore().getStorageHistoryData(resourceName, granularity, begin, end);
    List<Utilization> us = new ArrayList<>(cs.size());
    for (StorageCapacity c : cs) {
        us.add(new Utilization(c.getTimeStamp(), c.getCapacity(), c.getUsed()));
    }
    return us;
}
Also used : Utilization(org.smartdata.model.Utilization) StorageCapacity(org.smartdata.model.StorageCapacity) ArrayList(java.util.ArrayList)

Aggregations

StorageCapacity (org.smartdata.model.StorageCapacity)9 Test (org.junit.Test)4 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)3 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Utilization (org.smartdata.model.Utilization)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 MetaStoreException (org.smartdata.metastore.MetaStoreException)1