Search in sources :

Example 11 with ImageStorageDomainMap

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

Example 12 with ImageStorageDomainMap

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

Example 13 with ImageStorageDomainMap

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

Example 14 with ImageStorageDomainMap

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

Example 15 with ImageStorageDomainMap

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

Aggregations

ImageStorageDomainMap (org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap)17 Test (org.junit.Test)7 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)6 DiskImageDynamic (org.ovirt.engine.core.common.businessentities.storage.DiskImageDynamic)4 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)3 ImageStorageDomainMapId (org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMapId)3 Guid (org.ovirt.engine.core.compat.Guid)3 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 OvfEntityData (org.ovirt.engine.core.common.businessentities.OvfEntityData)1 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)1 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)1 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)1 VmStatic (org.ovirt.engine.core.common.businessentities.VmStatic)1