Search in sources :

Example 6 with StorageCapacity

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

the class TestMetaStore method testInsertStoragesTable.

@Test
public void testInsertStoragesTable() throws Exception {
    StorageCapacity storage1 = new StorageCapacity("Flash", 12343333L, 2223333L);
    StorageCapacity storage2 = new StorageCapacity("RAM", 12342233L, 2223663L);
    StorageCapacity[] storages = { storage1, storage2 };
    metaStore.insertUpdateStoragesTable(storages);
    StorageCapacity storageCapacity1 = metaStore.getStorageCapacity("Flash");
    StorageCapacity storageCapacity2 = metaStore.getStorageCapacity("RAM");
    Assert.assertTrue(storageCapacity1.equals(storage1));
    Assert.assertTrue(storageCapacity2.equals(storage2));
    Assert.assertTrue(metaStore.updateStoragesTable("Flash", 123456L, 4562233L));
    Assert.assertTrue(metaStore.getStorageCapacity("Flash").getCapacity() == 123456L);
}
Also used : StorageCapacity(org.smartdata.model.StorageCapacity) Test(org.junit.Test)

Example 7 with StorageCapacity

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

the class TestMetaStore method testGetStorageCapacity.

@Test
public void testGetStorageCapacity() throws Exception {
    StorageCapacity storage1 = new StorageCapacity("HDD", 12343333L, 2223333L);
    StorageCapacity storage2 = new StorageCapacity("RAM", 12342233L, 2223663L);
    StorageCapacity[] storages = { storage1, storage2 };
    metaStore.insertUpdateStoragesTable(storages);
    Assert.assertTrue(metaStore.getStorageCapacity("HDD").equals(storage1));
    Assert.assertTrue(metaStore.getStorageCapacity("RAM").equals(storage2));
    StorageCapacity storage3 = new StorageCapacity("HDD", 100L, 10L);
    metaStore.insertUpdateStoragesTable(storage3);
    Assert.assertTrue(metaStore.getStorageCapacity("HDD").equals(storage3));
}
Also used : StorageCapacity(org.smartdata.model.StorageCapacity) Test(org.junit.Test)

Example 8 with StorageCapacity

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

the class StorageDao method getStorageTablesItem.

public Map<String, StorageCapacity> getStorageTablesItem() {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    String sql = "SELECT * FROM storage";
    List<StorageCapacity> list = jdbcTemplate.query(sql, new RowMapper<StorageCapacity>() {

        public StorageCapacity mapRow(ResultSet rs, int rowNum) throws SQLException {
            return new StorageCapacity(rs.getString("type"), rs.getLong("time_stamp"), rs.getLong("capacity"), rs.getLong("free"));
        }
    });
    Map<String, StorageCapacity> map = new HashMap<>();
    for (StorageCapacity s : list) {
        map.put(s.getType(), s);
    }
    return map;
}
Also used : StorageCapacity(org.smartdata.model.StorageCapacity) SQLException(java.sql.SQLException) HashMap(java.util.HashMap) ResultSet(java.sql.ResultSet) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Example 9 with StorageCapacity

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

the class StorageDao method getStorageCapacity.

public StorageCapacity getStorageCapacity(String type) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    String sql = "SELECT * FROM storage WHERE type = ?";
    return jdbcTemplate.queryForObject(sql, new Object[] { type }, new RowMapper<StorageCapacity>() {

        public StorageCapacity mapRow(ResultSet rs, int rowNum) throws SQLException {
            return new StorageCapacity(rs.getString("type"), rs.getLong("time_stamp"), rs.getLong("capacity"), rs.getLong("free"));
        }
    });
}
Also used : StorageCapacity(org.smartdata.model.StorageCapacity) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

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