use of com.cloud.simulator.MockVolumeVO in project cloudstack by apache.
the class MockStorageManagerImpl method Destroy.
@Override
public Answer Destroy(DestroyCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolume().getPath());
if (volume != null) {
_mockVolumeDao.remove(volume.getId());
}
if (cmd.getVmName() != null) {
MockVm vm = _mockVMDao.findByVmName(cmd.getVmName());
if (vm != null) {
_mockVMDao.remove(vm.getId());
}
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when destroying volume " + cmd.getVolume().getPath(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new Answer(cmd);
}
use of com.cloud.simulator.MockVolumeVO in project cloudstack by apache.
the class MockStorageManagerImpl method createVolume.
@Override
public CreateAnswer createVolume(CreateCommand cmd) {
StorageFilerTO sf = cmd.getPool();
DiskProfile dskch = cmd.getDiskCharacteristics();
MockStoragePoolVO storagePool = null;
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid());
txn.commit();
if (storagePool == null) {
return new CreateAnswer(cmd, "Failed to find storage pool: " + sf.getUuid());
}
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when finding storage " + sf.getUuid(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
String volumeName = UUID.randomUUID().toString();
MockVolumeVO volume = new MockVolumeVO();
volume.setPoolId(storagePool.getId());
volume.setName(volumeName);
volume.setPath(storagePool.getMountPoint() + volumeName);
volume.setSize(dskch.getSize());
volume.setType(MockVolumeType.VOLUME);
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
volume = _mockVolumeDao.persist(volume);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when saving volume " + volume, ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
VolumeTO volumeTo = new VolumeTO(cmd.getVolumeId(), dskch.getType(), sf.getType(), sf.getUuid(), volume.getName(), storagePool.getMountPoint(), volume.getPath(), volume.getSize(), null);
return new CreateAnswer(cmd, volumeTo);
}
Aggregations