use of com.cloud.simulator.MockVolumeVO in project cloudstack by apache.
the class MockStorageManagerImpl method CopyVolume.
@Override
public CopyVolumeAnswer CopyVolume(CopyVolumeCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
boolean toSecondaryStorage = cmd.toSecondaryStorage();
MockSecStorageVO sec = null;
MockStoragePoolVO primaryStorage = null;
try {
txn.start();
sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStorageURL());
if (sec == null) {
return new CopyVolumeAnswer(cmd, false, "can't find secondary storage", null, null);
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when accessing secondary at " + cmd.getSecondaryStorageURL(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPool().getUuid());
if (primaryStorage == null) {
return new CopyVolumeAnswer(cmd, false, "Can't find primary storage", null, null);
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when accessing primary at " + cmd.getPool(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
MockVolumeVO volume = null;
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
if (volume == null) {
return new CopyVolumeAnswer(cmd, false, "cant' find volume" + cmd.getVolumePath(), null, null);
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when accessing volume at " + cmd.getVolumePath(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
String name = UUID.randomUUID().toString();
if (toSecondaryStorage) {
MockVolumeVO vol = new MockVolumeVO();
vol.setName(name);
vol.setPath(sec.getMountPoint() + name);
vol.setPoolId(sec.getId());
vol.setSize(volume.getSize());
vol.setStatus(Status.DOWNLOADED);
vol.setType(MockVolumeType.VOLUME);
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
vol = _mockVolumeDao.persist(vol);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when persisting volume " + vol.getName(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new CopyVolumeAnswer(cmd, true, null, sec.getMountPoint(), vol.getPath());
} else {
MockVolumeVO vol = new MockVolumeVO();
vol.setName(name);
vol.setPath(primaryStorage.getMountPoint() + name);
vol.setPoolId(primaryStorage.getId());
vol.setSize(volume.getSize());
vol.setStatus(Status.DOWNLOADED);
vol.setType(MockVolumeType.VOLUME);
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
vol = _mockVolumeDao.persist(vol);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when persisting volume " + vol.getName(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new CopyVolumeAnswer(cmd, true, null, primaryStorage.getMountPoint(), vol.getPath());
}
}
use of com.cloud.simulator.MockVolumeVO in project cloudstack by apache.
the class MockStorageManagerImpl method CreateVolumeFromSnapshot.
@Override
public CreateVolumeFromSnapshotAnswer CreateVolumeFromSnapshot(CreateVolumeFromSnapshotCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockVolumeVO backSnapshot = null;
MockStoragePoolVO primary = null;
try {
txn.start();
backSnapshot = _mockVolumeDao.findByName(cmd.getSnapshotUuid());
if (backSnapshot == null) {
return new CreateVolumeFromSnapshotAnswer(cmd, false, "can't find the backupsnapshot: " + cmd.getSnapshotUuid(), null);
}
primary = _mockStoragePoolDao.findByUuid(cmd.getPrimaryStoragePoolNameLabel());
if (primary == null) {
return new CreateVolumeFromSnapshotAnswer(cmd, false, "can't find the primary storage: " + cmd.getPrimaryStoragePoolNameLabel(), null);
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when creating volume from snapshot", ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
String uuid = UUID.randomUUID().toString();
MockVolumeVO volume = new MockVolumeVO();
volume.setName(uuid);
volume.setPath(primary.getMountPoint() + uuid);
volume.setPoolId(primary.getId());
volume.setSize(backSnapshot.getSize());
volume.setStatus(Status.DOWNLOADED);
volume.setType(MockVolumeType.VOLUME);
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
_mockVolumeDao.persist(volume);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when creating volume from snapshot " + volume, ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new CreateVolumeFromSnapshotAnswer(cmd, true, null, volume.getPath());
}
use of com.cloud.simulator.MockVolumeVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method ListTemplates.
@Override
public Answer ListTemplates(ListTemplateCommand cmd) {
MockSecStorageVO storage = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
if (storage == null) {
return new Answer(cmd, false, "Failed to get secondary storage");
}
List<MockVolumeVO> templates = _mockVolumeDao.findByStorageIdAndType(storage.getId(), MockVolumeType.TEMPLATE);
Map<String, TemplateInfo> templateInfos = new HashMap<String, TemplateInfo>();
for (MockVolumeVO template : templates) {
templateInfos.put(template.getName(), new TemplateInfo(template.getName(), template.getPath().replaceAll(storage.getMountPoint(), ""), template.getSize(), template.getSize(), true, false));
}
return new ListTemplateAnswer(cmd.getSecUrl(), templateInfos);
}
use of com.cloud.simulator.MockVolumeVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method preinstallTemplates.
@Override
public void preinstallTemplates(String url, long zoneId) {
MockSecStorageVO storage = _mockSecStorageDao.findByUrl(url);
if (storage == null) {
storage = new MockSecStorageVO();
URI uri;
try {
uri = new URI(url);
} catch (URISyntaxException e) {
return;
}
String nfsHost = uri.getHost();
String nfsPath = uri.getPath();
String path = nfsHost + ":" + nfsPath;
String dir = "/mnt/" + UUID.nameUUIDFromBytes(path.getBytes()).toString() + File.separator;
storage.setUrl(url);
storage.setCapacity(DEFAULT_HOST_STORAGE_SIZE);
storage.setMountPoint(dir);
storage = _mockSecStorageDao.persist(storage);
//preinstall default templates into secondary storage
long defaultTemplateSize = 2 * 1024 * 1024 * 1024L;
MockVolumeVO template = new MockVolumeVO();
template.setName("simulator-domR");
template.setPath(storage.getMountPoint() + "template/tmpl/1/9/" + UUID.randomUUID().toString());
template.setPoolId(storage.getId());
template.setSize(defaultTemplateSize);
template.setType(MockVolumeType.TEMPLATE);
template.setStatus(Status.DOWNLOADED);
_mockVolumeDao.persist(template);
template = new MockVolumeVO();
template.setName("simulator-Centos");
template.setPath(storage.getMountPoint() + "template/tmpl/1/10/" + UUID.randomUUID().toString());
template.setPoolId(storage.getId());
template.setSize(defaultTemplateSize);
template.setType(MockVolumeType.TEMPLATE);
template.setStatus(Status.DOWNLOADED);
_mockVolumeDao.persist(template);
}
}
use of com.cloud.simulator.MockVolumeVO 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);
}
Aggregations