Search in sources :

Example 1 with ImageStorageDomainMap

use of org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap in project ovirt-engine by oVirt.

the class ImportVmTemplateFromConfigurationCommand method populateDisksCopies.

private void populateDisksCopies(List<ImageStorageDomainMap> copiedTemplateDisks, List<DiskImage> originalTemplateImages, Guid storageDomainId) {
    List<Guid> imagesContainedInStorageDomain = getImagesGuidFromStorage(storageDomainId, getStoragePoolId());
    for (DiskImage templateDiskImage : originalTemplateImages) {
        if (storageDomainId.equals(templateDiskImage.getStorageIds().get(0))) {
            // The original Storage Domain was already saved. skipping it.
            continue;
        }
        if (imagesContainedInStorageDomain.contains(templateDiskImage.getId())) {
            log.info("Found a copied image of '{}' on Storage Domain id '{}'", templateDiskImage.getId(), storageDomainId);
            ImageStorageDomainMap imageStorageDomainMap = new ImageStorageDomainMap(templateDiskImage.getImageId(), storageDomainId, templateDiskImage.getQuotaId(), templateDiskImage.getDiskProfileId());
            copiedTemplateDisks.add(imageStorageDomainMap);
        }
    }
}
Also used : ImageStorageDomainMap(org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 2 with ImageStorageDomainMap

use of org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap in project ovirt-engine by oVirt.

the class ImportVmTemplateFromConfigurationCommand method findAndSaveDiskCopies.

private void findAndSaveDiskCopies() {
    List<OvfEntityData> ovfEntityDataList = unregisteredOVFDataDao.getByEntityIdAndStorageDomain(ovfEntityData.getEntityId(), null);
    List<ImageStorageDomainMap> copiedTemplateDisks = new LinkedList<>();
    for (OvfEntityData ovfEntityDataFetched : ovfEntityDataList) {
        populateDisksCopies(copiedTemplateDisks, getImages(), ovfEntityDataFetched.getStorageDomainId());
    }
    saveImageStorageDomainMapList(copiedTemplateDisks);
}
Also used : ImageStorageDomainMap(org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) LinkedList(java.util.LinkedList)

Example 3 with ImageStorageDomainMap

use of org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap in project ovirt-engine by oVirt.

the class LiveMigrateDiskCommand method moveDiskInDB.

private void moveDiskInDB(final Guid sourceStorageDomainId, final Guid targetStorageDomainId, final Guid targetQuota, final Guid targetDiskProfile) {
    if (isMoveDiskInDbSucceded(targetStorageDomainId)) {
        return;
    }
    TransactionSupport.executeInScope(TransactionScopeOption.Required, () -> {
        for (DiskImage di : diskImageDao.getAllSnapshotsForImageGroup(getParameters().getImageGroupID())) {
            imageStorageDomainMapDao.remove(new ImageStorageDomainMapId(di.getImageId(), sourceStorageDomainId));
            imageStorageDomainMapDao.save(new ImageStorageDomainMap(di.getImageId(), targetStorageDomainId, targetQuota, targetDiskProfile));
            // an exception, we store locally the old quota and disk profile id.
            if (sourceQuotaId == null) {
                sourceQuotaId = di.getQuotaId();
            }
            if (sourceDiskProfileId == null) {
                sourceDiskProfileId = di.getDiskProfileId();
            }
        }
        return null;
    });
}
Also used : ImageStorageDomainMap(org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap) ImageStorageDomainMapId(org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMapId) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 4 with ImageStorageDomainMap

use of org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap in project ovirt-engine by oVirt.

the class ImagesHandler method saveImage.

/**
 * The following method unify saving of image, it will be also saved with its storage
 * mapping.
 */
public ImageStorageDomainMap saveImage(DiskImage diskImage) {
    imageDao.save(diskImage.getImage());
    ImageStorageDomainMap imageStorageDomainMap = new ImageStorageDomainMap(diskImage.getImageId(), diskImage.getStorageIds().get(0), diskImage.getQuotaId(), diskImage.getDiskProfileId());
    imageStorageDomainMapDao.save(imageStorageDomainMap);
    return imageStorageDomainMap;
}
Also used : ImageStorageDomainMap(org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap)

Example 5 with ImageStorageDomainMap

use of org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap in project ovirt-engine by oVirt.

the class BaseImagesCommand method addDiskImageToDb.

protected void addDiskImageToDb(DiskImage image, CompensationContext compensationContext, boolean active) {
    image.setActive(active);
    imageDao.save(image.getImage());
    DiskImageDynamic diskDynamic = updateDiskImageDynamicIntoDB(image);
    ImageStorageDomainMap imageStorageDomainMap = new ImageStorageDomainMap(image.getImageId(), image.getStorageIds().get(0), image.getQuotaId(), image.getDiskProfileId());
    imageStorageDomainMapDao.save(imageStorageDomainMap);
    boolean isDiskAdded = saveDiskIfNotExists(image);
    if (compensationContext != null) {
        compensationContext.snapshotNewEntity(image.getImage());
        compensationContext.snapshotNewEntity(diskDynamic);
        compensationContext.snapshotNewEntity(imageStorageDomainMap);
        if (isDiskAdded) {
            compensationContext.snapshotNewEntity(image);
        }
        compensationContext.stateChanged();
    }
}
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