use of org.ovirt.engine.core.common.businessentities.storage.Image in project ovirt-engine by oVirt.
the class OvfManagerTest method createVmDisk.
private static DiskImage createVmDisk(VM vm) {
RandomUtils rnd = RandomUtils.instance();
DiskImage disk = new DiskImage();
disk.setId(Guid.newGuid());
disk.setVmSnapshotId(Guid.newGuid());
disk.setSize(rnd.nextLong(1000));
disk.setActualSize(rnd.nextLong(1000));
disk.setVolumeFormat(rnd.nextEnum(VolumeFormat.class));
disk.setVolumeType(rnd.nextEnum(VolumeType.class));
disk.setWipeAfterDelete(rnd.nextBoolean());
disk.setDiskAlias(generateRandomName());
disk.setDescription(generateRandomName());
disk.setImageId(Guid.newGuid());
disk.setStoragePoolId(Guid.newGuid());
disk.setPlugged(true);
disk.setAppList(rnd.nextPropertyString(100));
Image image = new Image();
image.setActive(true);
image.setVolumeFormat(rnd.nextEnum(VolumeFormat.class));
image.setId(disk.getImageId());
image.setSnapshotId(disk.getSnapshotId());
image.setStatus(ImageStatus.OK);
disk.setImage(image);
DiskVmElement diskVmElement = new DiskVmElement(disk.getId(), vm.getId());
diskVmElement.setBoot(rnd.nextBoolean());
diskVmElement.setDiskInterface(rnd.nextEnum(DiskInterface.class));
diskVmElement.setReadOnly(false);
diskVmElement.setPlugged(true);
disk.setDiskVmElements(Collections.singletonList(diskVmElement));
return disk;
}
use of org.ovirt.engine.core.common.businessentities.storage.Image in project ovirt-engine by oVirt.
the class RemoveCinderVolumeParentCommand method removeDiskFromDb.
protected void removeDiskFromDb(final CinderDisk cinderVolume, Snapshot updated) {
if (cinderVolume.getActive()) {
// Get the base volume and set it as active, so the disk will not disappear from the disks view.
Image baseVol = imageDao.get(cinderVolume.getId());
baseVol.setActive(true);
imageDao.update(baseVol);
}
imageStorageDomainMapDao.remove(cinderVolume.getImageId());
imageDao.remove(cinderVolume.getImageId());
diskImageDynamicDao.remove(cinderVolume.getImageId());
if (updated != null) {
snapshotDao.update(updated);
}
}
use of org.ovirt.engine.core.common.businessentities.storage.Image in project ovirt-engine by oVirt.
the class RemoveSnapshotSingleDiskCommandBase method syncDbRecords.
/**
* After merging the snapshots, update the image and snapshot records in the
* database to reflect the changes. This handles either forward or backwards
* merge (detected). It will either then remove the images, or mark them
* illegal (to handle the case where image deletion failed).
*
* @param removeImages Remove the images from the database, or if false, only
* mark them illegal
*/
protected void syncDbRecords(VmBlockJobType blockJobType, DiskImage imageFromVdsm, Set<Guid> imagesToUpdate, boolean removeImages) {
TransactionSupport.executeInNewTransaction(() -> {
// If deletion failed after a backwards merge, the snapshots' images need to be swapped
// as they would upon success. Instead of removing them, mark them illegal.
DiskImage baseImage = getDiskImage();
DiskImage topImage = getDestinationDiskImage();
// The vdsm merge verb may decide to perform a forward or backward merge.
if (topImage == null) {
log.info("No merge destination image, not updating image/snapshot association");
} else if (blockJobType == VmBlockJobType.PULL) {
handleForwardMerge(topImage, baseImage, imageFromVdsm);
} else {
handleBackwardMerge(topImage, baseImage, imageFromVdsm);
}
if (imagesToUpdate == null) {
log.error("Failed to update orphaned images in db: image list could not be retrieved");
return null;
}
for (Guid imageId : imagesToUpdate) {
if (removeImages) {
imageDao.remove(imageId);
} else {
// The (illegal && no-parent && no-children) status indicates an orphaned image.
Image image = imageDao.get(imageId);
image.setStatus(ImageStatus.ILLEGAL);
image.setParentId(Guid.Empty);
imageDao.update(image);
}
}
return null;
});
}
use of org.ovirt.engine.core.common.businessentities.storage.Image in project ovirt-engine by oVirt.
the class ImageDaoTest method updateStatusOfImagesByImageGroupId.
@Test
public void updateStatusOfImagesByImageGroupId() {
Image image = dao.get(EXISTING_IMAGE_ID);
List<DiskImage> snapshots = dbFacade.getDiskImageDao().getAllSnapshotsForImageGroup(image.getDiskId());
assertNotEquals(1, snapshots.size());
for (DiskImage diskImage : snapshots) {
assertNotSame(ImageStatus.LOCKED, diskImage.getImageStatus());
}
dao.updateStatusOfImagesByImageGroupId(image.getDiskId(), ImageStatus.LOCKED);
snapshots = dbFacade.getDiskImageDao().getAllSnapshotsForImageGroup(image.getDiskId());
for (DiskImage diskImage : snapshots) {
assertEquals(ImageStatus.LOCKED, diskImage.getImageStatus());
}
}
use of org.ovirt.engine.core.common.businessentities.storage.Image in project ovirt-engine by oVirt.
the class ImageDaoTest method testUpdateImageVmSnapshotId.
@Test
public void testUpdateImageVmSnapshotId() {
Guid guid = Guid.newGuid();
dao.updateImageVmSnapshotId(EXISTING_IMAGE_ID, guid);
Image imageFromDb = dao.get(EXISTING_IMAGE_ID);
assertNotNull(imageFromDb);
assertEquals("Image snapshot id wasn't updated properly", guid, imageFromDb.getSnapshotId());
}
Aggregations