use of com.cloud.simulator.MockVolumeVO in project cloudstack by apache.
the class MockStorageManagerImpl method DownloadProcess.
@Override
public DownloadAnswer DownloadProcess(DownloadProgressCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
String volumeId = cmd.getJobId();
MockVolumeVO volume = _mockVolumeDao.findById(Long.parseLong(volumeId));
if (volume == null) {
return new DownloadAnswer("Can't find the downloading volume", Status.ABANDONED);
}
long size = Math.min(volume.getSize() + DEFAULT_TEMPLATE_SIZE / 5, DEFAULT_TEMPLATE_SIZE);
volume.setSize(size);
double volumeSize = volume.getSize();
double pct = volumeSize / DEFAULT_TEMPLATE_SIZE;
if (pct >= 1.0) {
volume.setStatus(Status.DOWNLOADED);
_mockVolumeDao.update(volume.getId(), volume);
txn.commit();
return new DownloadAnswer(cmd.getJobId(), 100, cmd, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED, volume.getPath(), volume.getName());
} else {
_mockVolumeDao.update(volume.getId(), volume);
txn.commit();
return new DownloadAnswer(cmd.getJobId(), (int) (pct * 100.0), cmd, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS, volume.getPath(), volume.getName());
}
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error during download job " + cmd.getJobId(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
use of com.cloud.simulator.MockVolumeVO in project cloudstack by apache.
the class MockStorageManagerImpl method Download.
@Override
public DownloadAnswer Download(DownloadCommand cmd) {
MockSecStorageVO ssvo = null;
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
ssvo = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
if (ssvo == null) {
return new DownloadAnswer("can't find secondary storage", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error accessing secondary storage " + cmd.getSecUrl(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
MockVolumeVO volume = new MockVolumeVO();
volume.setPoolId(ssvo.getId());
volume.setName(cmd.getName());
volume.setPath(ssvo.getMountPoint() + cmd.getName());
volume.setSize(0);
volume.setType(MockVolumeType.TEMPLATE);
volume.setStatus(Status.DOWNLOAD_IN_PROGRESS);
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();
}
return new DownloadAnswer(String.valueOf(volume.getId()), 0, "Downloading", Status.DOWNLOAD_IN_PROGRESS, cmd.getName(), cmd.getName(), volume.getSize(), volume.getSize(), null);
}
use of com.cloud.simulator.MockVolumeVO 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);
}
use of com.cloud.simulator.MockVolumeVO in project cloudstack by apache.
the class MockStorageManagerImpl method primaryStorageDownload.
@Override
public PrimaryStorageDownloadAnswer primaryStorageDownload(PrimaryStorageDownloadCommand cmd) {
MockVolumeVO template = findVolumeFromSecondary(cmd.getUrl(), cmd.getSecondaryStorageUrl(), MockVolumeType.TEMPLATE);
if (template == null) {
return new PrimaryStorageDownloadAnswer("Can't find primary storage");
}
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockStoragePoolVO primaryStorage = null;
try {
txn.start();
primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPoolUuid());
txn.commit();
if (primaryStorage == null) {
return new PrimaryStorageDownloadAnswer("Can't find primary storage");
}
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when finding primary storagee " + cmd.getPoolUuid(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
String volumeName = UUID.randomUUID().toString();
MockVolumeVO newVolume = new MockVolumeVO();
newVolume.setName(volumeName);
newVolume.setPath(primaryStorage.getMountPoint() + volumeName);
newVolume.setPoolId(primaryStorage.getId());
newVolume.setSize(template.getSize());
newVolume.setType(MockVolumeType.VOLUME);
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
_mockVolumeDao.persist(newVolume);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when saving volume " + newVolume, ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new PrimaryStorageDownloadAnswer(newVolume.getPath(), newVolume.getSize());
}
use of com.cloud.simulator.MockVolumeVO in project cloudstack by apache.
the class MockStorageManagerImpl method CreatePrivateTemplateFromSnapshot.
@Override
public CreatePrivateTemplateAnswer CreatePrivateTemplateFromSnapshot(CreatePrivateTemplateFromSnapshotCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockVolumeVO snapshot = null;
MockSecStorageVO sec = null;
try {
txn.start();
String snapshotUUId = cmd.getSnapshotUuid();
snapshot = _mockVolumeDao.findByName(snapshotUUId);
if (snapshot == null) {
snapshotUUId = cmd.getSnapshotName();
snapshot = _mockVolumeDao.findByName(snapshotUUId);
if (snapshot == null) {
return new CreatePrivateTemplateAnswer(cmd, false, "can't find snapshot:" + snapshotUUId);
}
}
sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStorageUrl());
if (sec == null) {
return new CreatePrivateTemplateAnswer(cmd, false, "can't find secondary storage");
}
txn.commit();
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
MockVolumeVO template = new MockVolumeVO();
String uuid = UUID.randomUUID().toString();
template.setName(uuid);
template.setPath(sec.getMountPoint() + uuid);
template.setPoolId(sec.getId());
template.setSize(snapshot.getSize());
template.setStatus(Status.DOWNLOADED);
template.setType(MockVolumeType.TEMPLATE);
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
template = _mockVolumeDao.persist(template);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when saving template " + template, ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new CreatePrivateTemplateAnswer(cmd, true, "", template.getName(), template.getSize(), template.getSize(), template.getName(), ImageFormat.QCOW2);
}
Aggregations