use of com.cloud.simulator.MockSecStorageVO in project cloudstack by apache.
the class MockStorageManagerImpl method BackupSnapshot.
@Override
public BackupSnapshotAnswer BackupSnapshot(BackupSnapshotCommand cmd, SimulatorInfo info) {
// emulate xenserver backupsnapshot, if the base volume is deleted, then
// backupsnapshot failed
MockVolumeVO volume = null;
MockVolumeVO snapshot = null;
MockSecStorageVO secStorage = null;
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
if (volume == null) {
return new BackupSnapshotAnswer(cmd, false, "Can't find base volume: " + cmd.getVolumePath(), null, true);
}
String snapshotPath = cmd.getSnapshotUuid();
snapshot = _mockVolumeDao.findByStoragePathAndType(snapshotPath);
if (snapshot == null) {
return new BackupSnapshotAnswer(cmd, false, "can't find snapshot" + snapshotPath, null, true);
}
String secStorageUrl = cmd.getSecondaryStorageUrl();
secStorage = _mockSecStorageDao.findByUrl(secStorageUrl);
if (secStorage == null) {
return new BackupSnapshotAnswer(cmd, false, "can't find sec storage" + snapshotPath, null, true);
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when backing up snapshot");
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
MockVolumeVO newsnapshot = new MockVolumeVO();
String name = UUID.randomUUID().toString();
newsnapshot.setName(name);
newsnapshot.setPath(secStorage.getMountPoint() + name);
newsnapshot.setPoolId(secStorage.getId());
newsnapshot.setSize(snapshot.getSize());
newsnapshot.setStatus(Status.DOWNLOADED);
newsnapshot.setType(MockVolumeType.SNAPSHOT);
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
snapshot = _mockVolumeDao.persist(snapshot);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when backing up snapshot " + newsnapshot, ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new BackupSnapshotAnswer(cmd, true, null, newsnapshot.getName(), true);
}
Aggregations