Search in sources :

Example 1 with ImageStorageDomainMapId

use of org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMapId 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 2 with ImageStorageDomainMapId

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

the class RemoveAllVmTemplateImageTemplatesCommand method executeCommand.

@SuppressWarnings("unchecked")
@Override
protected void executeCommand() {
    List<DiskImage> imageTemplates = DisksFilter.filterImageDisks(diskDao.getAllForVm(getVmTemplateId()), ONLY_ACTIVE);
    for (DiskImage template : imageTemplates) {
        // remove this disk in all domain that were sent
        for (Guid domain : (Collection<Guid>) CollectionUtils.intersection(getParameters().getStorageDomainsList(), template.getStorageIds())) {
            ImagesContainterParametersBase tempVar = new ImagesContainterParametersBase(template.getImageId(), getVmTemplateId());
            tempVar.setStorageDomainId(domain);
            tempVar.setStoragePoolId(template.getStoragePoolId());
            tempVar.setImageGroupID(template.getId());
            tempVar.setEntityInfo(getParameters().getEntityInfo());
            tempVar.setWipeAfterDelete(template.isWipeAfterDelete());
            tempVar.setTransactionScopeOption(TransactionScopeOption.RequiresNew);
            tempVar.setParentCommand(getActionType());
            tempVar.setParentParameters(getParameters());
            ActionReturnValue actionReturnValue = runInternalActionWithTasksContext(ActionType.RemoveTemplateSnapshot, tempVar);
            if (actionReturnValue.getSucceeded()) {
                getReturnValue().getInternalVdsmTaskIdList().addAll(actionReturnValue.getInternalVdsmTaskIdList());
            } else {
                log.error("Can't remove image id '{}' for template id '{}' from domain id '{}' due to: {}.", template.getImageId(), getVmTemplateId(), domain, actionReturnValue.getFault().getMessage());
            }
            imageStorageDomainMapDao.remove(new ImageStorageDomainMapId(template.getImageId(), domain));
        }
        DiskImage diskImage = diskImageDao.get(template.getImageId());
        if (diskImage != null) {
            baseDiskDao.remove(template.getId());
            vmDeviceDao.remove(new VmDeviceId(diskImage.getImageId(), getVmTemplateId()));
            imageStorageDomainMapDao.remove(diskImage.getImageId());
            imageDao.remove(template.getImageId());
        }
    }
    setSucceeded(true);
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase) ImageStorageDomainMapId(org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMapId) Collection(java.util.Collection) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 3 with ImageStorageDomainMapId

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

the class CopyImageGroupCommand method endSuccessfully.

@Override
protected void endSuccessfully() {
    if (shouldUpdateStorageDisk()) {
        List<DiskImage> snapshots = diskImageDao.getAllSnapshotsForImageGroup(getParameters().getDestImageGroupId());
        setSnapshotForShareableDisk(snapshots);
        for (DiskImage snapshot : snapshots) {
            imageStorageDomainMapDao.remove(new ImageStorageDomainMapId(snapshot.getImageId(), snapshot.getStorageIds().get(0)));
            imageStorageDomainMapDao.save(new ImageStorageDomainMap(snapshot.getImageId(), getParameters().getStorageDomainId(), getParameters().getQuotaId(), getParameters().getDiskProfileId()));
            setQcowCompatForSnapshot(snapshot, null);
        }
    }
    super.endSuccessfully();
}
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 ImageStorageDomainMapId

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

the class CopyImageGroupCommand method endWithFailure.

@Override
protected void endWithFailure() {
    if (!getParameters().isImportEntity()) {
        unLockImage();
    }
    if (getParameters().getAddImageDomainMapping()) {
        // remove image-storage mapping
        imageStorageDomainMapDao.remove(new ImageStorageDomainMapId(getParameters().getImageId(), getParameters().getStorageDomainId()));
    }
    revertTasks();
    setSucceeded(true);
}
Also used : ImageStorageDomainMapId(org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMapId)

Example 5 with ImageStorageDomainMapId

use of org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMapId 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)

Aggregations

ImageStorageDomainMapId (org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMapId)6 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)3 ImageStorageDomainMap (org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap)3 Collection (java.util.Collection)1 Test (org.junit.Test)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1 ImagesContainterParametersBase (org.ovirt.engine.core.common.action.ImagesContainterParametersBase)1 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)1 Guid (org.ovirt.engine.core.compat.Guid)1