Search in sources :

Example 1 with RemoveImageParameters

use of org.ovirt.engine.core.common.action.RemoveImageParameters in project ovirt-engine by oVirt.

the class LiveMigrateDiskCommand method removeImage.

private void removeImage(Guid storageDomainId, Guid imageGroupId, Guid imageId, AuditLogType failureAuditLog) {
    RemoveImageParameters removeImageParams = new RemoveImageParameters(imageId);
    removeImageParams.setStorageDomainId(storageDomainId);
    removeImageParams.setParentCommand(ActionType.RemoveImage);
    removeImageParams.setDbOperationScope(ImageDbOperationScope.NONE);
    removeImageParams.setShouldLockImage(false);
    ActionReturnValue returnValue = runInternalAction(ActionType.RemoveImage, removeImageParams, cloneContextAndDetachFromParent());
    if (returnValue.getSucceeded()) {
        startPollingAsyncTasks(returnValue.getInternalVdsmTaskIdList());
    } else {
        addCustomValue("DiskAlias", baseDiskDao.get(imageGroupId).getDiskAlias());
        addCustomValue("StorageDomainName", storageDomainStaticDao.get(storageDomainId).getName());
        addCustomValue("UserName", getUserName());
        auditLogDirector.log(this, failureAuditLog);
    }
}
Also used : RemoveImageParameters(org.ovirt.engine.core.common.action.RemoveImageParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue)

Example 2 with RemoveImageParameters

use of org.ovirt.engine.core.common.action.RemoveImageParameters in project ovirt-engine by oVirt.

the class RestoreAllSnapshotsCommand method deleteOrphanedImages.

protected void deleteOrphanedImages(List<CinderDisk> cinderDisksToRemove) {
    ActionReturnValue returnValue;
    boolean noImagesRemovedYet = getTaskIdList().isEmpty();
    Set<Guid> deletedDisksIds = new HashSet<>();
    for (DiskImage image : diskImageDao.getImagesWithNoDisk(getVm().getId())) {
        if (!deletedDisksIds.contains(image.getId())) {
            deletedDisksIds.add(image.getId());
            if (image.getDiskStorageType() == DiskStorageType.CINDER) {
                cinderDisksToRemove.add((CinderDisk) image);
                continue;
            }
            returnValue = runAsyncTask(ActionType.RemoveImage, new RemoveImageParameters(image.getImageId()));
            if (!returnValue.getSucceeded() && noImagesRemovedYet) {
                setSucceeded(false);
                getReturnValue().setFault(returnValue.getFault());
                return;
            }
            noImagesRemovedYet = false;
        }
    }
}
Also used : RemoveImageParameters(org.ovirt.engine.core.common.action.RemoveImageParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) HashSet(java.util.HashSet)

Example 3 with RemoveImageParameters

use of org.ovirt.engine.core.common.action.RemoveImageParameters in project ovirt-engine by oVirt.

the class RestoreAllSnapshotsCommand method removeUnusedImages.

private void removeUnusedImages(List<CinderDisk> cinderVolumesToRemove) {
    Set<Guid> imageIdsUsedByActiveSnapshot = new HashSet<>();
    for (DiskImage diskImage : getImagesList()) {
        imageIdsUsedByActiveSnapshot.add(diskImage.getId());
    }
    List<DiskImage> imagesToRemove = new ArrayList<>();
    for (Guid snapshotToRemove : snapshotsToRemove) {
        List<DiskImage> snapshotDiskImages = diskImageDao.getAllSnapshotsForVmSnapshot(snapshotToRemove);
        imagesToRemove.addAll(snapshotDiskImages);
    }
    Set<Guid> removeInProcessImageIds = new HashSet<>();
    for (DiskImage diskImage : imagesToRemove) {
        if (imageIdsUsedByActiveSnapshot.contains(diskImage.getId()) || removeInProcessImageIds.contains(diskImage.getId())) {
            continue;
        }
        List<DiskImage> diskImagesFromPreviewSnap = imagesFromPreviewSnapshot.stream().filter(diskImageFromPreview -> diskImageFromPreview.getImageId().equals(diskImage.getImageId())).collect(Collectors.toList());
        if (!diskImagesFromPreviewSnap.isEmpty() && diskImagesFromPreviewSnap.get(0).getDiskStorageType() == DiskStorageType.CINDER) {
            cinderVolumesToRemove.add((CinderDisk) diskImagesFromPreviewSnap.get(0));
            continue;
        }
        ActionReturnValue retValue = runAsyncTask(ActionType.RemoveImage, new RemoveImageParameters(diskImage.getImageId()));
        if (retValue.getSucceeded()) {
            removeInProcessImageIds.add(diskImage.getImageId());
        } else {
            log.error("Failed to remove image '{}'", diskImage.getImageId());
        }
    }
}
Also used : LockMessagesMatchUtil(org.ovirt.engine.core.bll.LockMessagesMatchUtil) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) EngineException(org.ovirt.engine.core.common.errors.EngineException) SnapshotDao(org.ovirt.engine.core.dao.SnapshotDao) VmDynamicDao(org.ovirt.engine.core.dao.VmDynamicDao) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) RestoreAllSnapshotsParameters(org.ovirt.engine.core.common.action.RestoreAllSnapshotsParameters) VmStaticDao(org.ovirt.engine.core.dao.VmStaticDao) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) ActionType(org.ovirt.engine.core.common.action.ActionType) Future(java.util.concurrent.Future) DisksFilter(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter) Map(java.util.Map) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) Instance(javax.enterprise.inject.Instance) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) Set(java.util.Set) Collectors(java.util.stream.Collectors) ConcurrentChildCommandsExecutionCallback(org.ovirt.engine.core.bll.ConcurrentChildCommandsExecutionCallback) SnapshotType(org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType) Objects(java.util.Objects) ONLY_NOT_SHAREABLE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_NOT_SHAREABLE) List(java.util.List) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator) Optional(java.util.Optional) MultipleStorageDomainsValidator(org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator) AuditLogType(org.ovirt.engine.core.common.AuditLogType) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) QuotaConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter) VmLeaseVDSParameters(org.ovirt.engine.core.common.vdscommands.VmLeaseVDSParameters) QuotaStorageDependent(org.ovirt.engine.core.bll.quota.QuotaStorageDependent) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) LockProperties(org.ovirt.engine.core.common.action.LockProperties) Guid(org.ovirt.engine.core.compat.Guid) RestoreAllCinderSnapshotsParameters(org.ovirt.engine.core.common.action.RestoreAllCinderSnapshotsParameters) SnapshotActionEnum(org.ovirt.engine.core.common.businessentities.SnapshotActionEnum) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) OvfUtils(org.ovirt.engine.core.utils.OvfUtils) ArrayList(java.util.ArrayList) CommandCoordinatorUtil(org.ovirt.engine.core.bll.tasks.CommandCoordinatorUtil) ImageStatus(org.ovirt.engine.core.common.businessentities.storage.ImageStatus) HashSet(java.util.HashSet) Inject(javax.inject.Inject) CollectionUtils(org.apache.commons.collections.CollectionUtils) DiskImageDao(org.ovirt.engine.core.dao.DiskImageDao) ONLY_ACTIVE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_ACTIVE) VmCommand(org.ovirt.engine.core.bll.VmCommand) Pair(org.ovirt.engine.core.common.utils.Pair) RestoreFromSnapshotParameters(org.ovirt.engine.core.common.action.RestoreFromSnapshotParameters) ImagesHandler(org.ovirt.engine.core.bll.storage.disk.image.ImagesHandler) StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) SnapshotStatus(org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus) LockingGroup(org.ovirt.engine.core.common.locks.LockingGroup) EndProcedure(org.ovirt.engine.core.common.action.ActionParametersBase.EndProcedure) ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Scope(org.ovirt.engine.core.common.action.LockProperties.Scope) Typed(javax.enterprise.inject.Typed) QuotaStorageConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter) EngineError(org.ovirt.engine.core.common.errors.EngineError) ExecutionException(java.util.concurrent.ExecutionException) VM(org.ovirt.engine.core.common.businessentities.VM) CommandCallback(org.ovirt.engine.core.bll.tasks.interfaces.CommandCallback) PermissionSubject(org.ovirt.engine.core.bll.utils.PermissionSubject) RemoveImageParameters(org.ovirt.engine.core.common.action.RemoveImageParameters) VDSCommandType(org.ovirt.engine.core.common.vdscommands.VDSCommandType) Collections(java.util.Collections) VmInterfaceManager(org.ovirt.engine.core.bll.network.VmInterfaceManager) ImageDao(org.ovirt.engine.core.dao.ImageDao) RemoveImageParameters(org.ovirt.engine.core.common.action.RemoveImageParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) HashSet(java.util.HashSet)

Example 4 with RemoveImageParameters

use of org.ovirt.engine.core.common.action.RemoveImageParameters in project ovirt-engine by oVirt.

the class MoveImageGroupCommand method removeImage.

private void removeImage(Guid storageDomainId) {
    RemoveImageParameters removeImageParams = new RemoveImageParameters(getParameters().getImageId());
    removeImageParams.setStorageDomainId(storageDomainId);
    removeImageParams.setParentCommand(ActionType.RemoveImage);
    removeImageParams.setDbOperationScope(ImageDbOperationScope.NONE);
    removeImageParams.setShouldLockImage(false);
    removeImageParams.setCorrelationId(getParameters().getCorrelationId());
    // TODO: should be removed as async task manager issues would be resolved, done in order
    // to avoid operations on the image to wait for this remove operation as currently async
    // task manager calls the end methods of command based on the entity id.
    // the remove done here is a "clenaup", either on the source domain or on the target - so
    // other operations on the image shouldn't be dependent and wait for it.
    removeImageParams.setEntityInfo(new EntityInfo(VdcObjectType.Disk, Guid.newGuid()));
    ActionReturnValue returnValue = runInternalAction(ActionType.RemoveImage, removeImageParams, cloneContextAndDetachFromParent());
    if (returnValue.getSucceeded()) {
        startPollingAsyncTasks(returnValue.getInternalVdsmTaskIdList());
    } else {
        addAuditLogOnRemoveFailure();
    }
}
Also used : RemoveImageParameters(org.ovirt.engine.core.common.action.RemoveImageParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo)

Example 5 with RemoveImageParameters

use of org.ovirt.engine.core.common.action.RemoveImageParameters in project ovirt-engine by oVirt.

the class CreateImageTemplateCommand method revertTasks.

@Override
protected void revertTasks() {
    Guid destImageId = getDestinationDiskImage().getImageId();
    RemoveImageParameters p = new RemoveImageParameters(destImageId);
    p.setEntityInfo(new EntityInfo(VdcObjectType.Disk, destImageId));
    p.setParentParameters(p);
    p.setParentCommand(ActionType.RemoveImage);
    ActionReturnValue returnValue = checkAndPerformRollbackUsingCommand(ActionType.RemoveImage, p, null);
    if (returnValue.getSucceeded()) {
        startPollingAsyncTasks(returnValue.getInternalVdsmTaskIdList());
    }
}
Also used : RemoveImageParameters(org.ovirt.engine.core.common.action.RemoveImageParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

RemoveImageParameters (org.ovirt.engine.core.common.action.RemoveImageParameters)9 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)7 EntityInfo (org.ovirt.engine.core.common.asynctasks.EntityInfo)6 Guid (org.ovirt.engine.core.compat.Guid)4 HashSet (java.util.HashSet)2 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 Collectors (java.util.stream.Collectors)1 Instance (javax.enterprise.inject.Instance)1 Typed (javax.enterprise.inject.Typed)1 Inject (javax.inject.Inject)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1