Search in sources :

Example 6 with Image

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;
}
Also used : VolumeFormat(org.ovirt.engine.core.common.businessentities.storage.VolumeFormat) VolumeType(org.ovirt.engine.core.common.businessentities.storage.VolumeType) RandomUtils(org.ovirt.engine.core.utils.RandomUtils) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Image(org.ovirt.engine.core.common.businessentities.storage.Image) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 7 with Image

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);
    }
}
Also used : DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Image(org.ovirt.engine.core.common.businessentities.storage.Image)

Example 8 with Image

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;
    });
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Image(org.ovirt.engine.core.common.businessentities.storage.Image) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 9 with Image

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());
    }
}
Also used : DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Image(org.ovirt.engine.core.common.businessentities.storage.Image) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test)

Example 10 with Image

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());
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Image(org.ovirt.engine.core.common.businessentities.storage.Image) Test(org.junit.Test)

Aggregations

DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)11 Image (org.ovirt.engine.core.common.businessentities.storage.Image)11 Test (org.junit.Test)3 Guid (org.ovirt.engine.core.compat.Guid)3 DiskInterface (org.ovirt.engine.core.common.businessentities.storage.DiskInterface)1 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)1 RepoImage (org.ovirt.engine.core.common.businessentities.storage.RepoImage)1 VolumeClassification (org.ovirt.engine.core.common.businessentities.storage.VolumeClassification)1 VolumeFormat (org.ovirt.engine.core.common.businessentities.storage.VolumeFormat)1 VolumeType (org.ovirt.engine.core.common.businessentities.storage.VolumeType)1 GetVolumeInfoVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.GetVolumeInfoVDSCommandParameters)1 RandomUtils (org.ovirt.engine.core.utils.RandomUtils)1