use of org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap in project ovirt-engine by oVirt.
the class ImageStorageDomainMapDaoTest method testGetAllByStorageDomainId.
@Test
public void testGetAllByStorageDomainId() {
List<ImageStorageDomainMap> result = dao.getAllByStorageDomainId(FixturesTool.STORAGE_DOMAIN_SCALE_SD5);
assertNotNull(result);
assertFalse(result.isEmpty());
for (ImageStorageDomainMap mapping : result) {
assertEquals(FixturesTool.STORAGE_DOMAIN_SCALE_SD5, mapping.getStorageDomainId());
}
}
use of org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap in project ovirt-engine by oVirt.
the class ImageStorageDomainMapDaoTest method testRemoveById.
@Test
public void testRemoveById() {
dao.remove(new ImageStorageDomainMapId(EXISTING_IMAGE_ID, FixturesTool.STORAGE_DOMAIN_SCALE_SD5));
List<ImageStorageDomainMap> entries = dao.getAllByStorageDomainId(EXISTING_IMAGE_ID);
for (ImageStorageDomainMap entry : entries) {
assertFalse(entry.getStorageDomainId().equals(FixturesTool.STORAGE_DOMAIN_SCALE_SD5));
}
assertNotNull(entries);
assertTrue(entries.isEmpty());
}
use of org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap in project ovirt-engine by oVirt.
the class AddCinderDiskCommand method addCinderDiskToDB.
protected void addCinderDiskToDB(final CinderDisk cinderDisk) {
TransactionSupport.executeInNewTransaction(() -> {
baseDiskDao.save(cinderDisk);
imageDao.save(cinderDisk.getImage());
imageStorageDomainMapDao.save(new ImageStorageDomainMap(cinderDisk.getImageId(), cinderDisk.getStorageIds().get(0), cinderDisk.getQuotaId(), cinderDisk.getDiskProfileId()));
DiskImageDynamic diskDynamic = new DiskImageDynamic();
diskDynamic.setId(cinderDisk.getImageId());
diskImageDynamicDao.save(diskDynamic);
if (getVm() != null) {
addDiskVmElementForDisk(getDiskVmElement());
addManagedDeviceForDisk(cinderDisk.getId());
}
return null;
});
}
use of org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap in project ovirt-engine by oVirt.
the class SnapshotsManager method synchronizeDisksFromSnapshot.
/**
* Synchronize the VM's Disks with the images from the snapshot:<br>
* <ul>
* <li>Existing disks are updated.</li>
* <li>Disks that don't exist anymore get re-added.</li>
* <ul>
* <li>If the image is still in the DB, the disk is linked to it.</li>
* <li>If the image is not in the DB anymore, the disk will be marked as "broken"</li>
* </ul>
* </ul>
*
* @param vmId
* The VM ID is needed to re-add disks.
* @param snapshotId
* The snapshot ID is used to find only the VM disks at the time.
* @param disksFromSnapshot
* The disks that existed in the snapshot.
*/
protected void synchronizeDisksFromSnapshot(Guid vmId, Guid snapshotId, Guid activeSnapshotId, List<DiskImage> disksFromSnapshot, String vmName) {
List<Guid> diskIdsFromSnapshot = new ArrayList<>();
// Sync disks that exist or existed in the snapshot.
int count = 1;
for (DiskImage diskImage : disksFromSnapshot) {
diskIdsFromSnapshot.add(diskImage.getId());
if (baseDiskDao.exists(diskImage.getId())) {
baseDiskDao.update(diskImage);
DiskVmElement dve = diskVmElementDao.get(diskImage.getDiskVmElementForVm(vmId).getId());
if (dve != null && !dve.equals(diskImage.getDiskVmElementForVm(vmId))) {
diskVmElementDao.update(diskImage.getDiskVmElementForVm(vmId));
}
} else {
// If can't find the image, insert it as illegal so that it can't be used and make the device unplugged.
if (diskImageDao.getSnapshotById(diskImage.getImageId()) == null) {
diskImage.setImageStatus(ImageStatus.ILLEGAL);
diskImage.setVmSnapshotId(activeSnapshotId);
imagesHandler.addImage(diskImage, true, (diskImage.getStorageIds() == null) ? null : new ImageStorageDomainMap(diskImage.getImageId(), diskImage.getStorageIds().get(0), diskImage.getQuotaId(), diskImage.getDiskProfileId()));
}
imagesHandler.addDiskToVm(diskImage, vmId);
}
diskImage.setDiskAlias(imagesHandler.getSuggestedDiskAlias(diskImage, vmName, count));
count++;
}
removeDisksNotInSnapshot(vmId, diskIdsFromSnapshot);
}
use of org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap in project ovirt-engine by oVirt.
the class CloneSingleCinderDiskCommand method addCinderDiskTemplateToDB.
protected void addCinderDiskTemplateToDB(final CinderDisk cinderDisk) {
TransactionSupport.executeInNewTransaction(() -> {
baseDiskDao.save(cinderDisk);
imageDao.save(cinderDisk.getImage());
DiskImageDynamic diskDynamic = new DiskImageDynamic();
diskDynamic.setId(cinderDisk.getImageId());
diskImageDynamicDao.save(diskDynamic);
ImageStorageDomainMap image_storage_domain_map = new ImageStorageDomainMap(cinderDisk.getImageId(), cinderDisk.getStorageIds().get(0), cinderDisk.getQuotaId(), cinderDisk.getDiskProfileId());
imageStorageDomainMapDao.save(image_storage_domain_map);
getCompensationContext().snapshotNewEntity(image_storage_domain_map);
getCompensationContext().snapshotNewEntity(diskDynamic);
getCompensationContext().snapshotNewEntity(cinderDisk.getImage());
getCompensationContext().snapshotNewEntity(cinderDisk);
getCompensationContext().stateChanged();
return null;
});
}
Aggregations