use of com.cloud.simulator.MockSecStorageVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method CreatePrivateTemplateFromVolume.
@Override
public CreatePrivateTemplateAnswer CreatePrivateTemplateFromVolume(CreatePrivateTemplateFromVolumeCommand cmd) {
MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
if (volume == null) {
return new CreatePrivateTemplateAnswer(cmd, false, "cant' find volume" + cmd.getVolumePath());
}
MockSecStorageVO sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStorageUrl());
if (sec == null) {
return new CreatePrivateTemplateAnswer(cmd, false, "can't find secondary storage");
}
MockVolumeVO template = new MockVolumeVO();
String uuid = UUID.randomUUID().toString();
template.setName(uuid);
template.setPath(sec.getMountPoint() + uuid);
template.setPoolId(sec.getId());
template.setSize(volume.getSize());
template.setStatus(Status.DOWNLOADED);
template.setType(MockVolumeType.TEMPLATE);
template = _mockVolumeDao.persist(template);
return new CreatePrivateTemplateAnswer(cmd, true, "", template.getName(), template.getSize(), template.getSize(), template.getName(), ImageFormat.QCOW2);
}
use of com.cloud.simulator.MockSecStorageVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method Download.
@Override
public DownloadAnswer Download(DownloadCommand cmd) {
MockSecStorageVO ssvo = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
if (ssvo == null) {
return new DownloadAnswer("can't find secondary storage", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
}
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);
volume = _mockVolumeDao.persist(volume);
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.MockSecStorageVO in project CloudStack-archive by CloudStack-extras.
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 = _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();
MockVolumeVO snapshot = _mockVolumeDao.findByStoragePathAndType(snapshotPath);
if (snapshot == null) {
return new BackupSnapshotAnswer(cmd, false, "can't find snapshot" + snapshotPath, null, true);
}
String secStorageUrl = cmd.getSecondaryStorageUrl();
MockSecStorageVO secStorage = _mockSecStorageDao.findByUrl(secStorageUrl);
if (secStorage == null) {
return new BackupSnapshotAnswer(cmd, false, "can't find sec storage" + snapshotPath, null, true);
}
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);
newsnapshot = _mockVolumeDao.persist(newsnapshot);
return new BackupSnapshotAnswer(cmd, true, null, newsnapshot.getName(), true);
}
use of com.cloud.simulator.MockSecStorageVO 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);
}
use of com.cloud.simulator.MockSecStorageVO 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);
}
Aggregations