use of com.cloud.simulator.MockVolumeVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method findVolumeFromSecondary.
private MockVolumeVO findVolumeFromSecondary(String path, String ssUrl, MockVolumeType type) {
String volumePath = path.replaceAll(ssUrl, "");
MockSecStorageVO secStorage = _mockSecStorageDao.findByUrl(ssUrl);
if (secStorage == null) {
return null;
}
volumePath = secStorage.getMountPoint() + volumePath;
volumePath = volumePath.replaceAll("//", "/");
MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(volumePath);
if (volume == null) {
return null;
}
return volume;
}
use of com.cloud.simulator.MockVolumeVO in project cloudstack by apache.
the class MockStorageManagerImpl method AttachIso.
@Override
public Answer AttachIso(AttachIsoCommand cmd) {
MockVolumeVO iso = findVolumeFromSecondary(cmd.getIsoPath(), cmd.getStoreUrl(), MockVolumeType.ISO);
if (iso == null) {
return new Answer(cmd, false, "Failed to find the iso: " + cmd.getIsoPath() + "on secondary storage " + cmd.getStoreUrl());
}
String vmName = cmd.getVmName();
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockVMVO vm = null;
try {
txn.start();
vm = _mockVMDao.findByVmName(vmName);
txn.commit();
if (vm == null) {
return new Answer(cmd, false, "can't find vm :" + vmName);
}
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when attaching iso to vm " + vmName, 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 preinstallTemplates.
@Override
public void preinstallTemplates(String url, long zoneId) {
MockSecStorageVO storage = null;
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
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/100/" + UUID.randomUUID().toString());
template.setPoolId(storage.getId());
template.setSize(defaultTemplateSize);
template.setType(MockVolumeType.TEMPLATE);
template.setStatus(Status.DOWNLOADED);
template = _mockVolumeDao.persist(template);
template = new MockVolumeVO();
template.setName("simulator-Centos");
template.setPath(storage.getMountPoint() + "template/tmpl/1/111/" + UUID.randomUUID().toString());
template.setPoolId(storage.getId());
template.setSize(defaultTemplateSize);
template.setType(MockVolumeType.TEMPLATE);
template.setStatus(Status.DOWNLOADED);
template = _mockVolumeDao.persist(template);
txn.commit();
}
} catch (Exception ex) {
throw new CloudRuntimeException("Unable to find sec storage at " + url, ex);
} finally {
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
use of com.cloud.simulator.MockVolumeVO in project cloudstack by apache.
the class MockStorageManagerImpl method ManageSnapshot.
@Override
public ManageSnapshotAnswer ManageSnapshot(ManageSnapshotCommand cmd) {
String volPath = cmd.getVolumePath();
MockVolumeVO volume = null;
MockStoragePoolVO storagePool = null;
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
volume = _mockVolumeDao.findByStoragePathAndType(volPath);
if (volume == null) {
return new ManageSnapshotAnswer(cmd, false, "Can't find the volume");
}
storagePool = _mockStoragePoolDao.findById(volume.getPoolId());
if (storagePool == null) {
return new ManageSnapshotAnswer(cmd, false, "Can't find the storage pooll");
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Unable to perform snapshot", ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
String mountPoint = storagePool.getMountPoint();
MockVolumeVO snapshot = new MockVolumeVO();
snapshot.setName(cmd.getSnapshotName());
snapshot.setPath(mountPoint + cmd.getSnapshotName());
snapshot.setSize(volume.getSize());
snapshot.setPoolId(storagePool.getId());
snapshot.setType(MockVolumeType.SNAPSHOT);
snapshot.setStatus(Status.DOWNLOADED);
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 saving snapshot " + snapshot, ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new ManageSnapshotAnswer(cmd, snapshot.getId(), snapshot.getPath(), true, "");
}
use of com.cloud.simulator.MockVolumeVO in project cloudstack by apache.
the class MockStorageManagerImpl method CreatePrivateTemplateFromVolume.
@Override
public CreatePrivateTemplateAnswer CreatePrivateTemplateFromVolume(CreatePrivateTemplateFromVolumeCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockVolumeVO volume = null;
MockSecStorageVO sec = null;
try {
txn.start();
volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
if (volume == null) {
return new CreatePrivateTemplateAnswer(cmd, false, "cant' find volume" + cmd.getVolumePath());
}
sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStorageUrl());
if (sec == null) {
return new CreatePrivateTemplateAnswer(cmd, false, "can't find secondary storage");
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when creating private template from volume");
} 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(volume.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("Encountered " + ex.getMessage() + " when persisting template " + template.getName(), 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