Search in sources :

Example 86 with ActionReturnValue

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

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

the class AbstractVmInterfaceCommand method activateOrDeactivateNic.

protected boolean activateOrDeactivateNic(VmNic nic, PlugAction plugAction, boolean newNic) {
    ActivateDeactivateVmNicParameters parameters = new ActivateDeactivateVmNicParameters(nic, plugAction, newNic);
    parameters.setVmId(getParameters().getVmId());
    ActionReturnValue returnValue = runInternalAction(ActionType.ActivateDeactivateVmNic, parameters, cloneContextAndDetachFromParent());
    if (!returnValue.getSucceeded()) {
        propagateFailure(returnValue);
    }
    return returnValue.getSucceeded();
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ActivateDeactivateVmNicParameters(org.ovirt.engine.core.common.action.ActivateDeactivateVmNicParameters)

Example 88 with ActionReturnValue

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

the class SyncAllHostNetworksCommand method executeCommand.

@Override
protected void executeCommand() {
    PersistentHostSetupNetworksParameters parameters = generateSyncAllHostNetworksParameters();
    ActionReturnValue retVal = runInternalAction(ActionType.PersistentHostSetupNetworks, parameters, cloneContextAndDetachFromParent());
    if (!retVal.getSucceeded()) {
        propagateFailure(retVal);
    } else {
        setSucceeded(true);
    }
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters)

Example 89 with ActionReturnValue

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

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

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