}
@Override
public StoragePoolInfo getLocalStorage(String hostGuid, Long storageSize) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
MockHost host = null;
try {
txn.start();
host = _mockHostDao.findByGuid(hostGuid);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Unable to find host " + hostGuid, ex);
} finally {
txn.close();
txn = Transaction.open(Transaction.CLOUD_DB);
txn.close();
}
if (storageSize == null) {
storageSize = DEFAULT_HOST_STORAGE_SIZE;
}
txn = Transaction.open(Transaction.SIMULATOR_DB);
MockStoragePoolVO storagePool = null;
try {
txn.start();
storagePool = _mockStoragePoolDao.findByHost(hostGuid);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when finding storagePool " + storagePool, ex);
} finally {
txn.close();
txn = Transaction.open(Transaction.CLOUD_DB);
txn.close();
}
if (storagePool == null) {
String uuid = UUID.randomUUID().toString();
storagePool = new MockStoragePoolVO();
storagePool.setUuid(uuid);
storagePool.setMountPoint("/mnt/" + uuid + File.separator);
storagePool.setCapacity(storageSize);
storagePool.setHostGuid(hostGuid);
storagePool.setStorageType(StoragePoolType.Filesystem);
txn = Transaction.open(Transaction.SIMULATOR_DB);
try {
txn.start();
storagePool = _mockStoragePoolDao.persist(storagePool);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when saving storagePool " + storagePool, ex);
} finally {
txn.close();
txn = Transaction.open(Transaction.CLOUD_DB);
txn.close();
}
}
return new StoragePoolInfo(storagePool.getUuid(), host.getPrivateIpAddress(), storagePool.getMountPoint(),
storagePool.getMountPoint(), storagePool.getPoolType(), storagePool.getCapacity(), 0);
}