Search in sources :

Example 6 with ImagesContainterParametersBase

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

the class RestoreAllSnapshotsCommand method executeVmCommand.

@Override
protected void executeVmCommand() {
    if (!getImagesList().isEmpty()) {
        lockVmWithCompensationIfNeeded();
        if (!isInternalExecution()) {
            freeLock();
        }
    }
    initializeSnapshotsLeasesDomainIds();
    restoreSnapshotAndRemoveObsoleteSnapshots(getSnapshot());
    boolean succeeded = removeLeaseIfNeeded();
    List<CinderDisk> cinderDisksToRestore = new ArrayList<>();
    for (DiskImage image : imagesToRestore) {
        if (image.getImageStatus() != ImageStatus.ILLEGAL) {
            if (image.getDiskStorageType() == DiskStorageType.CINDER) {
                cinderDisksToRestore.add((CinderDisk) image);
                continue;
            }
            ImagesContainterParametersBase params = new RestoreFromSnapshotParameters(image.getImageId(), getVmId(), getSnapshot(), removedSnapshot.getId());
            ActionReturnValue returnValue = runAsyncTask(ActionType.RestoreFromSnapshot, params);
            // Save the first fault
            if (succeeded && !returnValue.getSucceeded()) {
                succeeded = false;
                getReturnValue().setFault(returnValue.getFault());
            }
        }
    }
    List<CinderDisk> cinderVolumesToRemove = new ArrayList<>();
    List<CinderDisk> cinderDisksToRemove = new ArrayList<>();
    removeUnusedImages(cinderVolumesToRemove);
    if (getSnapshot().getType() == SnapshotType.REGULAR) {
        snapshotsToRemove.addAll(findSnapshotsWithOnlyIllegalDisks());
        setNewerVmConfigurationsAsBroken();
    }
    removeSnapshotsFromDB();
    succeeded = updateLeaseInfoIfNeeded() && succeeded;
    if (!getTaskIdList().isEmpty() || !cinderDisksToRestore.isEmpty() || !cinderVolumesToRemove.isEmpty()) {
        deleteOrphanedImages(cinderDisksToRemove);
        if (!restoreCinderDisks(removedSnapshot.getId(), cinderDisksToRestore, cinderDisksToRemove, cinderVolumesToRemove)) {
            log.error("Error to restore Cinder volumes snapshots");
        }
    } else {
        vmStaticDao.incrementDbGeneration(getVm().getId());
        snapshotDao.updateStatus(getSnapshot().getId(), SnapshotStatus.OK);
        unlockVm();
    }
    setSucceeded(succeeded);
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase) ArrayList(java.util.ArrayList) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) RestoreFromSnapshotParameters(org.ovirt.engine.core.common.action.RestoreFromSnapshotParameters)

Example 7 with ImagesContainterParametersBase

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

the class RemoveCinderSnapshotCommandCallback method childCommandsExecutionEnded.

@Override
protected void childCommandsExecutionEnded(CommandBase<?> command, boolean anyFailed, List<Guid> childCmdIds, CommandExecutionStatus status, int completedChildren) {
    RemoveCinderSnapshotDiskCommand<ImagesContainterParametersBase> removeCinderSnapshotDiskCommand = (RemoveCinderSnapshotDiskCommand<ImagesContainterParametersBase>) command;
    ImagesContainterParametersBase parameters = removeCinderSnapshotDiskCommand.getParameters();
    Guid diskId = parameters.getDestinationImageId();
    if (!removeCinderSnapshotDiskCommand.getCinderBroker().isSnapshotExist(diskId)) {
        // Cinder snapshot has been deleted successfully
        setCommandEndStatus(command, false, status, childCmdIds);
        return;
    }
    ImageStatus imageStatus = removeCinderSnapshotDiskCommand.getCinderBroker().getSnapshotStatus(diskId);
    DiskImage disk = diskImageDao.getSnapshotById(diskId);
    if (imageStatus != null && imageStatus != disk.getImageStatus()) {
        switch(imageStatus) {
            case ILLEGAL:
                setCommandEndStatus(command, true, status, childCmdIds);
                break;
        }
    }
}
Also used : ImageStatus(org.ovirt.engine.core.common.businessentities.storage.ImageStatus) ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 8 with ImagesContainterParametersBase

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

the class RestoreAllCinderSnapshotsCommand method executeVmCommand.

@Override
protected void executeVmCommand() {
    for (CinderDisk cinderDisk : getParameters().getCinderDisksToRestore()) {
        ImagesContainterParametersBase params = getRestoreFromSnapshotParams(cinderDisk);
        restoreCinderDisk(cinderDisk, params);
        // In case we want to undo the previewed snapshot.
        if (getParameters().getSnapshot().getType() == Snapshot.SnapshotType.STATELESS) {
            Guid activeSnapshotId = snapshotDao.get(getParameters().getVmId(), Snapshot.SnapshotType.ACTIVE).getId();
            updateCinderDiskSnapshot(cinderDisk.getId(), activeSnapshotId, cinderDisk.getVmSnapshotId());
        } else if (getParameters().getSnapshot().getType() != Snapshot.SnapshotType.REGULAR) {
            updateCinderDiskSnapshot(cinderDisk.getId(), getParameters().getSnapshot().getId(), null);
        }
    }
    List<CinderDisk> cinderDisksToRemove = getParameters().getCinderDisksToRemove();
    for (CinderDisk cinderDisk : cinderDisksToRemove) {
        RemoveCinderDiskParameters removeDiskParam = new RemoveCinderDiskParameters(cinderDisk.getImageId());
        removeDiskParam.setRemovedVolume(cinderDisk);
        removeDiskParam.setParentCommand(getActionType());
        removeDiskParam.setStorageDomainId(cinderDisk.getStorageIds().get(0));
        removeDiskParam.setParentParameters(getParameters());
        removeDiskParam.setEndProcedure(EndProcedure.COMMAND_MANAGED);
        Future<ActionReturnValue> future = commandCoordinatorUtil.executeAsyncCommand(ActionType.RemoveCinderDisk, removeDiskParam, cloneContextAndDetachFromParent());
        try {
            future.get();
        } catch (InterruptedException | ExecutionException e) {
            log.error("Error removing Cinder disk", e);
        }
    }
    List<CinderDisk> cinderVolumesToRemove = getParameters().getCinderVolumesToRemove();
    for (CinderDisk cinderVolume : cinderVolumesToRemove) {
        RemoveCinderDiskVolumeParameters removeDiskVolumeParam = new RemoveCinderDiskVolumeParameters(cinderVolume);
        removeDiskVolumeParam.setParentCommand(getActionType());
        removeDiskVolumeParam.setParentParameters(getParameters());
        removeDiskVolumeParam.setEndProcedure(EndProcedure.COMMAND_MANAGED);
        Future<ActionReturnValue> future = commandCoordinatorUtil.executeAsyncCommand(ActionType.RemoveCinderDiskVolume, removeDiskVolumeParam, cloneContextAndDetachFromParent());
        try {
            future.get();
        } catch (InterruptedException | ExecutionException e) {
            log.error("Error removing Cinder disk", e);
        }
    }
    setSucceeded(true);
}
Also used : RemoveCinderDiskParameters(org.ovirt.engine.core.common.action.RemoveCinderDiskParameters) RemoveCinderDiskVolumeParameters(org.ovirt.engine.core.common.action.RemoveCinderDiskVolumeParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase) Guid(org.ovirt.engine.core.compat.Guid) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) ExecutionException(java.util.concurrent.ExecutionException)

Example 9 with ImagesContainterParametersBase

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

the class CreateAllTemplateDisksCommand method addVmTemplateCinderDisks.

private boolean addVmTemplateCinderDisks(Map<Guid, Guid> srcDeviceIdToTargetDeviceIdMapping) {
    List<CinderDisk> cinderDisks = getCinderDisks();
    if (cinderDisks.isEmpty()) {
        return true;
    }
    // Create Cinder disk templates
    Map<Guid, Guid> diskImageMap = new HashMap<>();
    for (CinderDisk cinderDisk : cinderDisks) {
        ImagesContainterParametersBase params = buildCloneCinderDiskCommandParameters(cinderDisk);
        ActionReturnValue returnValue = runInternalAction(ActionType.CloneSingleCinderDisk, params, cloneContext().withoutExecutionContext().withoutLock());
        if (!returnValue.getSucceeded()) {
            log.error("Error cloning Cinder disk '{}'", cinderDisk.getDiskAlias());
            getReturnValue().setFault(returnValue.getFault());
            return false;
        }
        Guid imageId = returnValue.getActionReturnValue();
        diskImageMap.put(cinderDisk.getId(), imageId);
    }
    srcDeviceIdToTargetDeviceIdMapping.putAll(diskImageMap);
    return true;
}
Also used : HashMap(java.util.HashMap) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase) Guid(org.ovirt.engine.core.compat.Guid) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk)

Example 10 with ImagesContainterParametersBase

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

the class CloneSingleCinderDiskCommandCallback method childCommandsExecutionEnded.

@Override
protected void childCommandsExecutionEnded(CommandBase<?> command, boolean anyFailed, List<Guid> childCmdIds, CommandExecutionStatus status, int completedChildren) {
    BaseImagesCommand<ImagesContainterParametersBase> cloneCinderDiskCommand = (BaseImagesCommand<ImagesContainterParametersBase>) command;
    ImagesContainterParametersBase parameters = cloneCinderDiskCommand.getParameters();
    ImageStatus imageStatus = cloneCinderDiskCommand.getCinderBroker().getDiskStatus(parameters.getDestinationImageId());
    DiskImage disk = (CinderDisk) diskDao.get(parameters.getContainerId());
    if (imageStatus != null && imageStatus != disk.getImageStatus()) {
        switch(imageStatus) {
            case OK:
                setCommandEndStatus(command, false, status, childCmdIds);
                break;
            case ILLEGAL:
                setCommandEndStatus(command, true, status, childCmdIds);
                break;
        }
    }
}
Also used : ImageStatus(org.ovirt.engine.core.common.businessentities.storage.ImageStatus) ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase) BaseImagesCommand(org.ovirt.engine.core.bll.storage.disk.image.BaseImagesCommand) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

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