Search in sources :

Example 91 with ActionReturnValue

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

the class RestoreAllSnapshotsCommand method restoreAllCinderDisks.

protected boolean restoreAllCinderDisks(List<CinderDisk> cinderDisksToRestore, List<CinderDisk> cinderDisksToRemove, List<CinderDisk> cinderVolumesToRemove, Guid removedSnapshotId) {
    Future<ActionReturnValue> future = commandCoordinatorUtil.executeAsyncCommand(ActionType.RestoreAllCinderSnapshots, buildCinderChildCommandParameters(cinderDisksToRestore, cinderDisksToRemove, cinderVolumesToRemove, removedSnapshotId), cloneContextAndDetachFromParent());
    try {
        ActionReturnValue actionReturnValue = future.get();
        if (!actionReturnValue.getSucceeded()) {
            getReturnValue().setFault(actionReturnValue.getFault());
            log.error("Error while restoring Cinder snapshot");
            return false;
        }
    } catch (InterruptedException | ExecutionException e) {
        log.error("Error deleting Cinder volumes for restore snapshot", e);
        return false;
    }
    return true;
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ExecutionException(java.util.concurrent.ExecutionException)

Example 92 with ActionReturnValue

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

the class RemoveSnapshotSingleDiskLiveCommand method performNextOperation.

@Override
public boolean performNextOperation(int completedChildCount) {
    // Steps are executed such that:
    // a) all logic before the command runs is idempotent
    // b) the command is the last action in the step
    // This allows for recovery after a crash at any point during command execution.
    log.debug("Proceeding with execution of RemoveSnapshotSingleDiskLiveCommand");
    if (getParameters().getCommandStep() == null) {
        getParameters().setCommandStep(getInitialMergeStepForImage(getParameters().getImageId()));
        getParameters().setChildCommands(new HashMap<>());
    }
    // Upon recovery or after invoking a new child command, our map may be missing an entry
    syncChildCommandList(getParameters());
    Guid currentChildId = getCurrentChildId(getParameters());
    ActionReturnValue actionReturnValue = null;
    if (currentChildId != null) {
        actionReturnValue = commandCoordinatorUtil.getCommandReturnValue(currentChildId);
        getParameters().setCommandStep(getParameters().getNextCommandStep());
    }
    log.info("Executing Live Merge command step '{}'", getParameters().getCommandStep());
    Pair<ActionType, ? extends ActionParametersBase> nextCommand = null;
    switch(getParameters().getCommandStep()) {
        case EXTEND:
            nextCommand = new Pair<>(ActionType.MergeExtend, buildMergeParameters());
            getParameters().setNextCommandStep(RemoveSnapshotSingleDiskStep.MERGE);
            break;
        case MERGE:
            nextCommand = new Pair<>(ActionType.Merge, buildMergeParameters());
            getParameters().setNextCommandStep(RemoveSnapshotSingleDiskStep.MERGE_STATUS);
            break;
        case MERGE_STATUS:
            nextCommand = new Pair<>(ActionType.MergeStatus, buildMergeParameters());
            getParameters().setNextCommandStep(RemoveSnapshotSingleDiskStep.DESTROY_IMAGE);
            break;
        case DESTROY_IMAGE:
            if (actionReturnValue != null) {
                getParameters().setMergeStatusReturnValue(actionReturnValue.getActionReturnValue());
            } else if (getParameters().getMergeStatusReturnValue() == null) {
                // If the images were already merged, just add the orphaned image
                getParameters().setMergeStatusReturnValue(synthesizeMergeStatusReturnValue());
            }
            nextCommand = buildDestroyCommand(ActionType.DestroyImage, getActionType(), new ArrayList<>(getParameters().getMergeStatusReturnValue().getImagesToRemove()));
            getParameters().setNextCommandStep(RemoveSnapshotSingleDiskStep.REDUCE_IMAGE);
            break;
        case REDUCE_IMAGE:
            nextCommand = buildReduceImageCommand();
            getParameters().setNextCommandStep(RemoveSnapshotSingleDiskStep.COMPLETE);
            break;
        case COMPLETE:
            setCommandStatus(CommandStatus.SUCCEEDED);
            break;
    }
    persistCommand(getParameters().getParentCommand(), true);
    if (nextCommand != null) {
        commandCoordinatorUtil.executeAsyncCommand(nextCommand.getFirst(), nextCommand.getSecond(), cloneContextAndDetachFromParent());
        // Add the child, but wait, it's a race!  child will start, task may spawn, get polled, and we won't have the child id
        return true;
    } else {
        return false;
    }
}
Also used : ActionType(org.ovirt.engine.core.common.action.ActionType) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid)

Example 93 with ActionReturnValue

use of org.ovirt.engine.core.common.action.ActionReturnValue 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 94 with ActionReturnValue

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

the class UpdateVmDiskCommandTest method testAmendFailedWithPropertyChange.

@Test
public void testAmendFailedWithPropertyChange() {
    DiskImage oldDisk = createDiskImage();
    oldDisk.setVolumeFormat(VolumeFormat.COW);
    oldDisk.setQcowCompat(QcowCompat.QCOW2_V2);
    oldDisk.setDiskAlias("Test");
    oldDisk.setDiskDescription("Test_Desc");
    when(diskDao.get(diskImageGuid)).thenReturn(oldDisk);
    DiskImage newDisk = DiskImage.copyOf(oldDisk);
    newDisk.setQcowCompat(QcowCompat.QCOW2_V3);
    newDisk.setDiskAlias("New Disk Alias");
    command.getParameters().setDiskInfo(newDisk);
    initializeCommand();
    ActionReturnValue ret = new ActionReturnValue();
    ret.setSucceeded(false);
    ArrayList<String> msgList = new ArrayList<>();
    msgList.add(EngineMessage.ACTION_TYPE_FAILED_AMEND_NOT_SUPPORTED_BY_DC_VERSION.toString());
    ret.setValidationMessages(msgList);
    when(backend.runInternalAction(eq(ActionType.AmendImageGroupVolumes), any(), any())).thenReturn(ret);
    mockVdsCommandSetVolumeDescription();
    mockGetAllSnapshotsForDisk(Collections.singletonList(oldDisk));
    command.executeVmCommand();
    verify(command, times(1)).amendDiskImage();
    verify(command, times(1)).setVolumeDescription(any(), any());
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ArrayList(java.util.ArrayList) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Example 95 with ActionReturnValue

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

the class AttachStorageDomainToPoolCommandTest method statusSetInMap.

@Test
public void statusSetInMap() {
    cmd.init();
    Guid storageDomainId = cmd.getStorageDomainId();
    Guid poolId = cmd.getStoragePoolId();
    doNothing().when(cmd).attemptToActivateDomain();
    doReturn(Collections.singletonList(new Pair<>(Guid.newGuid(), true))).when(cmd).connectHostsInUpToDomainStorageServer();
    StoragePool pool = new StoragePool();
    pool.setId(poolId);
    pool.setStatus(StoragePoolStatus.Up);
    when(storagePoolDao.get(any())).thenReturn(pool);
    when(isoMapDao.get(any())).thenReturn(map);
    when(storageDomainDao.getForStoragePool(any(), any())).thenReturn(new StorageDomain());
    when(storageDomainStaticDao.get(any())).thenReturn(new StorageDomainStatic());
    doReturn(pool.getId()).when(cmd).getStoragePoolIdFromVds();
    ActionReturnValue actionReturnValue = new ActionReturnValue();
    actionReturnValue.setSucceeded(true);
    when(backendInternal.runInternalAction(any(), any(), any())).thenReturn(actionReturnValue);
    StorageDomainStatic storageDomain = new StorageDomainStatic();
    storageDomain.setId(Guid.newGuid());
    storageDomain.setStorageDomainType(StorageDomainType.ImportExport);
    mockGetStorageDomainInfoVdsCommand(storageDomain);
    mockAttachStorageDomainVdsCommand();
    when(vdsDao.get(any())).thenReturn(vds);
    doReturn(Collections.emptyList()).when(cmd).getEntitiesFromStorageOvfDisk(storageDomainId, pool.getId());
    doReturn(Collections.emptyList()).when(cmd).getAllOVFDisks(storageDomainId, pool.getId());
    doAnswer(invocation -> {
        map = (StoragePoolIsoMap) invocation.getArguments()[0];
        return null;
    }).when(isoMapDao).save(any());
    cmd.setCompensationContext(mock(CompensationContext.class));
    cmd.executeCommand();
    assertNotNull(map);
    assertEquals(StorageDomainStatus.Maintenance, map.getStatus());
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) CompensationContext(org.ovirt.engine.core.bll.context.CompensationContext) Guid(org.ovirt.engine.core.compat.Guid) Pair(org.ovirt.engine.core.common.utils.Pair) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Aggregations

ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)293 ArrayList (java.util.ArrayList)57 Guid (org.ovirt.engine.core.compat.Guid)55 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)50 Test (org.junit.Test)37 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)27 ActionType (org.ovirt.engine.core.common.action.ActionType)26 EngineException (org.ovirt.engine.core.common.errors.EngineException)25 VDS (org.ovirt.engine.core.common.businessentities.VDS)23 HashSet (java.util.HashSet)16 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)15 ExecutionException (java.util.concurrent.ExecutionException)13 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)13 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)13 StorageServerConnectionParametersBase (org.ovirt.engine.core.common.action.StorageServerConnectionParametersBase)12 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)12 List (java.util.List)11 ChangeVDSClusterParameters (org.ovirt.engine.core.common.action.ChangeVDSClusterParameters)11 VM (org.ovirt.engine.core.common.businessentities.VM)11 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)11