Search in sources :

Example 11 with ImagesContainterParametersBase

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

the class CreateAllTemplateDisksCommand method buildCloneCinderDiskCommandParameters.

private ImagesContainterParametersBase buildCloneCinderDiskCommandParameters(CinderDisk cinderDisk) {
    ImagesContainterParametersBase createParams = new ImagesContainterParametersBase(cinderDisk.getImageId());
    DiskImage templateDisk = getParameters().getDiskInfoDestinationMap().get(cinderDisk.getId());
    createParams.setDiskAlias(templateDisk.getDiskAlias());
    createParams.setStorageDomainId(templateDisk.getStorageIds().get(0));
    createParams.setParentCommand(getActionType());
    createParams.setParentParameters(getParameters());
    createParams.setVmSnapshotId(vmSnapshotId);
    return createParams;
}
Also used : ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 12 with ImagesContainterParametersBase

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

the class RemoveAllCinderSnapshotDisksCommand method getCinderDiskSnapshotParameter.

private ImagesContainterParametersBase getCinderDiskSnapshotParameter(CinderDisk cinderDisk) {
    ImagesContainterParametersBase removeCinderSnapshotParams = new ImagesContainterParametersBase(cinderDisk.getImageId());
    removeCinderSnapshotParams.setDestinationImageId(cinderDisk.getImageId());
    removeCinderSnapshotParams.setStorageDomainId(cinderDisk.getStorageIds().get(0));
    removeCinderSnapshotParams.setParentCommand(getActionType());
    removeCinderSnapshotParams.setParentParameters(getParameters());
    removeCinderSnapshotParams.setEndProcedure(EndProcedure.COMMAND_MANAGED);
    return removeCinderSnapshotParams;
}
Also used : ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase)

Example 13 with ImagesContainterParametersBase

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

the class TryBackToAllSnapshotsOfVmCommand method tryBackAllCinderDisks.

protected boolean tryBackAllCinderDisks(List<CinderDisk> cinderDisks, Guid newSnapshotId) {
    for (CinderDisk disk : cinderDisks) {
        ImagesContainterParametersBase params = buildCinderChildCommandParameters(disk, newSnapshotId);
        ActionReturnValue actionReturnValue = runInternalAction(ActionType.TryBackToCinderSnapshot, params, cloneContextAndDetachFromParent());
        if (!actionReturnValue.getSucceeded()) {
            log.error("Error cloning Cinder disk for preview. '{}': {}", disk.getDiskAlias());
            getReturnValue().setFault(actionReturnValue.getFault());
            return false;
        }
    }
    return true;
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk)

Example 14 with ImagesContainterParametersBase

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

the class TryBackToAllSnapshotsOfVmCommand method executeVmCommand.

@Override
protected void executeVmCommand() {
    final boolean restoreMemory = isRestoreMemory();
    final Guid newActiveSnapshotId = Guid.newGuid();
    final Snapshot snapshotToBePreviewed = getDstSnapshot();
    final Snapshot previousActiveSnapshot = snapshotDao.get(getVmId(), SnapshotType.ACTIVE);
    final Guid previousActiveSnapshotId = previousActiveSnapshot.getId();
    final List<DiskImage> images = getImagesToPreview();
    // Images list without those that are excluded from preview
    final List<DiskImage> filteredImages = (List<DiskImage>) CollectionUtils.subtract(images, getImagesExcludedFromPreview(images, previousActiveSnapshotId, newActiveSnapshotId));
    if (log.isInfoEnabled()) {
        log.info("Previewing snapshot {} with the disks:\n{}", getSnapshotName(), filteredImages.stream().map(disk -> String.format("%s (%s) to imageId %s", disk.getName(), disk.getId().toString(), disk.getImageId().toString())).collect(Collectors.joining("\n")));
    }
    final List<CinderDisk> cinderDisks = new ArrayList<>();
    TransactionSupport.executeInNewTransaction(() -> {
        getCompensationContext().snapshotEntity(previousActiveSnapshot);
        snapshotDao.remove(previousActiveSnapshotId);
        getSnapshotsManager().addSnapshot(previousActiveSnapshotId, "Active VM before the preview", SnapshotStatus.LOCKED, SnapshotType.PREVIEW, getVm(), true, previousActiveSnapshot.getMemoryDiskId(), previousActiveSnapshot.getMetadataDiskId(), null, null, null, getCompensationContext());
        getSnapshotsManager().addActiveSnapshot(newActiveSnapshotId, getVm(), SnapshotStatus.OK, restoreMemory ? snapshotToBePreviewed.getMemoryDiskId() : null, restoreMemory ? snapshotToBePreviewed.getMetadataDiskId() : null, snapshotToBePreviewed.getCreationDate(), images, getCompensationContext());
        // being executed in the same transaction so we can restore the vm config and end the command.
        if (!filteredImages.isEmpty()) {
            getCompensationContext().stateChanged();
        } else {
            vmStaticDao.incrementDbGeneration(getVm().getId());
            restoreVmConfigFromSnapshot();
        }
        return null;
    });
    initializeSnapshotsLeasesParams();
    if (!filteredImages.isEmpty()) {
        vmHandler.lockVm(getVm().getDynamicData(), getCompensationContext());
        freeLock();
        TransactionSupport.executeInNewTransaction(new TransactionMethod<Void>() {

            @Override
            public Void runInTransaction() {
                for (DiskImage image : filteredImages) {
                    if (image.getDiskStorageType() == DiskStorageType.CINDER) {
                        cinderDisks.add((CinderDisk) image);
                        continue;
                    }
                    ActionReturnValue actionReturnValue = runInternalActionWithTasksContext(ActionType.TryBackToSnapshot, buildTryBackToSnapshotParameters(newActiveSnapshotId, image));
                    if (actionReturnValue.getSucceeded()) {
                        getTaskIdList().addAll(actionReturnValue.getInternalVdsmTaskIdList());
                    } else if (actionReturnValue.getFault() != null) {
                        // if we have a fault, forward it to the user
                        throw new EngineException(actionReturnValue.getFault().getError(), actionReturnValue.getFault().getMessage());
                    } else {
                        log.error("Cannot create snapshot");
                        throw new EngineException(EngineError.IRS_IMAGE_STATUS_ILLEGAL);
                    }
                }
                if (getParameters().getLeaseAction() == LeaseAction.CREATE_NEW_LEASE) {
                    if (!addVmLease(getParameters().getDstLeaseDomainId(), getVm().getId(), false)) {
                        log.error("Failed to create lease for VM '{}' on storage domain '{}'", getVm().getName(), getParameters().getDstLeaseDomainId());
                        throw new EngineException(EngineError.FailedToCreateLease);
                    }
                }
                if (!cinderDisks.isEmpty() && !tryBackAllCinderDisks(cinderDisks, newActiveSnapshotId)) {
                    throw new EngineException(EngineError.CINDER_ERROR, "Failed to preview a snapshot!");
                }
                return null;
            }

            private ImagesContainterParametersBase buildTryBackToSnapshotParameters(final Guid newActiveSnapshotId, DiskImage image) {
                ImagesContainterParametersBase params = new ImagesContainterParametersBase(image.getImageId());
                params.setParentCommand(ActionType.TryBackToAllSnapshotsOfVm);
                params.setVmSnapshotId(newActiveSnapshotId);
                params.setEntityInfo(getParameters().getEntityInfo());
                params.setParentParameters(getParameters());
                params.setQuotaId(image.getQuotaId());
                return params;
            }
        });
    } else {
        // if there are no disks to restore, no compensation context is saved and the VM Configuration
        // (including clusterCompatibilityVersionOrigin) is already restored at this point. Otherwise,
        // if disks are being restored, the VM Configuration is restored later in endSuccessfully()
        updateClusterCompatibilityVersionToOldCluster(true);
    }
    setSucceeded(true);
}
Also used : ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase) ArrayList(java.util.ArrayList) EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) List(java.util.List) ArrayList(java.util.ArrayList) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 15 with ImagesContainterParametersBase

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

the class RemoveSnapshotCommand method endVmCommand.

@Override
protected void endVmCommand() {
    initializeObjectState();
    if (getParameters().getTaskGroupSuccess()) {
        snapshotDao.remove(getParameters().getSnapshotId());
    } else {
        List<String> failedToRemoveDisks = new ArrayList<>();
        Snapshot snapshot = snapshotDao.get(getParameters().getSnapshotId());
        for (ActionParametersBase parameters : getParameters().getImagesParameters()) {
            ImagesContainterParametersBase imagesParams = parameters instanceof ImagesContainterParametersBase ? (ImagesContainterParametersBase) parameters : null;
            if (imagesParams == null) {
                // instances of ImagesContainterParametersBase objects.
                continue;
            }
            if (imagesParams.getTaskGroupSuccess()) {
                snapshot = imagesHandler.prepareSnapshotConfigWithoutImageSingleImage(snapshot, imagesParams.getImageId(), ovfManager);
            } else {
                log.error("Could not delete image '{}' from snapshot '{}'", imagesParams.getImageId(), getParameters().getSnapshotId());
                DiskImage diskImage = diskImageDao.getSnapshotById(imagesParams.getImageId());
                failedToRemoveDisks.add(diskImage.getDiskAlias());
            }
        }
        // Remove memory volume and update the dao.
        // Note: on failure, we can treat memory volume deletion as deleting an image
        // and remove it from the snapshot entity (rollback isn't applicable).
        snapshot.setMemoryDiskId(null);
        snapshot.setMetadataDiskId(null);
        snapshotDao.update(snapshot);
        if (!failedToRemoveDisks.isEmpty()) {
            addCustomValue("DiskAliases", StringUtils.join(failedToRemoveDisks, ", "));
            auditLogDirector.log(this, AuditLogType.USER_REMOVE_SNAPSHOT_FINISHED_FAILURE_PARTIAL_SNAPSHOT);
        }
        snapshotDao.updateStatus(getParameters().getSnapshotId(), SnapshotStatus.OK);
    }
    super.endVmCommand();
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase) ArrayList(java.util.ArrayList) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Aggregations

ImagesContainterParametersBase (org.ovirt.engine.core.common.action.ImagesContainterParametersBase)16 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)8 Guid (org.ovirt.engine.core.compat.Guid)8 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)7 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)7 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)2 ImageStatus (org.ovirt.engine.core.common.businessentities.storage.ImageStatus)2 Collection (java.util.Collection)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 BaseImagesCommand (org.ovirt.engine.core.bll.storage.disk.image.BaseImagesCommand)1 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)1 ActionType (org.ovirt.engine.core.common.action.ActionType)1 RemoveCinderDiskParameters (org.ovirt.engine.core.common.action.RemoveCinderDiskParameters)1 RemoveCinderDiskVolumeParameters (org.ovirt.engine.core.common.action.RemoveCinderDiskVolumeParameters)1 RestoreFromSnapshotParameters (org.ovirt.engine.core.common.action.RestoreFromSnapshotParameters)1 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)1 ImageStorageDomainMapId (org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMapId)1