Search in sources :

Example 36 with VDSReturnValue

use of org.ovirt.engine.core.common.vdscommands.VDSReturnValue in project ovirt-engine by oVirt.

the class RebootVmCommand method perform.

@Override
protected void perform() {
    if (isColdReboot()) {
        ActionReturnValue returnValue = runInternalAction(ActionType.ShutdownVm, new ShutdownVmParameters(getVmId(), false));
        setReturnValue(returnValue);
        setSucceeded(returnValue.getSucceeded());
        if (getSucceeded()) {
            resourceManager.getVmManager(getVmId()).setColdReboot(true);
        }
    } else {
        final VDSReturnValue returnValue = runVdsCommand(VDSCommandType.RebootVm, new VdsAndVmIDVDSParametersBase(getVdsId(), getVmId()));
        setActionReturnValue(returnValue.getReturnValue());
        setSucceeded(returnValue.getSucceeded());
    }
}
Also used : VdsAndVmIDVDSParametersBase(org.ovirt.engine.core.common.vdscommands.VdsAndVmIDVDSParametersBase) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ShutdownVmParameters(org.ovirt.engine.core.common.action.ShutdownVmParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 37 with VDSReturnValue

use of org.ovirt.engine.core.common.vdscommands.VDSReturnValue in project ovirt-engine by oVirt.

the class CreateSnapshotCommand method performImageVdsmOperation.

@Override
protected boolean performImageVdsmOperation() {
    setDestinationImageId(Guid.isNullOrEmpty(getParameters().getDestinationImageId()) ? Guid.newGuid() : getParameters().getDestinationImageId());
    persistCommandIfNeeded();
    newDiskImage = cloneDiskImage(getDestinationImageId());
    newDiskImage.setStorageIds(new ArrayList<>(Arrays.asList(getDestinationStorageDomainId())));
    setStoragePoolId(newDiskImage.getStoragePoolId() != null ? newDiskImage.getStoragePoolId() : Guid.Empty);
    getParameters().setStoragePoolId(getStoragePoolId());
    // override volume type and volume format to sparse and cow according to
    // storage team request
    newDiskImage.setVolumeType(VolumeType.Sparse);
    newDiskImage.setVolumeFormat(VolumeFormat.COW);
    try {
        Guid taskId = persistAsyncTaskPlaceHolder(getParameters().getParentCommand());
        VDSReturnValue vdsReturnValue = runVdsCommand(VDSCommandType.CreateVolume, new CreateVolumeVDSCommandParameters(getStoragePoolId(), getDestinationStorageDomainId(), getImageGroupId(), getImage().getImageId(), getDiskImage().getSize(), newDiskImage.getVolumeType(), newDiskImage.getVolumeFormat(), getDiskImage().getId(), getDestinationImageId(), "", getStoragePool().getCompatibilityVersion(), getDiskImage().getContentType()));
        if (vdsReturnValue != null && vdsReturnValue.getSucceeded()) {
            getParameters().setVdsmTaskIds(new ArrayList<>());
            getParameters().getVdsmTaskIds().add(createTask(taskId, vdsReturnValue.getCreationInfo(), getParameters().getParentCommand(), VdcObjectType.Storage, getParameters().getStorageDomainId(), getParameters().getDestinationImageId()));
            getReturnValue().getInternalVdsmTaskIdList().add(getParameters().getVdsmTaskIds().get(0));
            // Shouldn't happen anymore:
            if (getDestinationImageId().equals(Guid.Empty)) {
                throw new RuntimeException();
            }
            return true;
        }
    } catch (Exception e) {
        log.error("Failed creating snapshot from image id '{}'", getImage().getImageId());
        commandCoordinatorUtil.logAndFailTaskOfCommandWithEmptyVdsmId(getAsyncTaskId(), "Create snapshot failed at VDSM. DB task ID is " + getAsyncTaskId());
        throw new EngineException(EngineError.VolumeCreationError);
    }
    return false;
}
Also used : CreateVolumeVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.CreateVolumeVDSCommandParameters) EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) EngineException(org.ovirt.engine.core.common.errors.EngineException) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 38 with VDSReturnValue

use of org.ovirt.engine.core.common.vdscommands.VDSReturnValue in project ovirt-engine by oVirt.

the class RestoreAllSnapshotsCommand method updateLeaseInfo.

private boolean updateLeaseInfo(Guid snapshotLeaseDomainId) {
    if (snapshotLeaseDomainId == null) {
        // there was no lease for the snapshot
        vmDynamicDao.updateVmLeaseInfo(getParameters().getVmId(), null);
        return true;
    }
    VDSReturnValue retVal = null;
    try {
        retVal = runVdsCommand(VDSCommandType.GetVmLeaseInfo, new VmLeaseVDSParameters(getStoragePoolId(), snapshotLeaseDomainId, getParameters().getVmId()));
    } catch (EngineException e) {
        log.error("Failure in getting lease info for VM {}, message: {}", getParameters().getVmId(), e.getMessage());
    }
    if (retVal == null || !retVal.getSucceeded()) {
        log.error("Failed to get info on the lease of VM {}", getParameters().getVmId());
        return false;
    }
    vmDynamicDao.updateVmLeaseInfo(getParameters().getVmId(), (Map<String, String>) retVal.getReturnValue());
    return true;
}
Also used : EngineException(org.ovirt.engine.core.common.errors.EngineException) VmLeaseVDSParameters(org.ovirt.engine.core.common.vdscommands.VmLeaseVDSParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 39 with VDSReturnValue

use of org.ovirt.engine.core.common.vdscommands.VDSReturnValue in project ovirt-engine by oVirt.

the class DiskImagesValidator method diskImagesOnStorage.

/**
 * checks that the given disks do not exist on the target storage domains
 * @param imageToDestinationDomainMap map containing the destination domain for each of the disks
 * @param storagePoolId the storage pool ID to check whether the disks are residing on
 * @return validation result indicating whether the disks don't exist on the target storage domains
 */
public ValidationResult diskImagesOnStorage(Map<Guid, Guid> imageToDestinationDomainMap, Guid storagePoolId) {
    Map<Guid, List<Guid>> domainImages = new HashMap<>();
    for (DiskImage diskImage : diskImages) {
        Guid targetStorageDomainId = imageToDestinationDomainMap.get(diskImage.getId());
        List<Guid> imagesOnStorageDomain = domainImages.get(targetStorageDomainId);
        if (imagesOnStorageDomain == null) {
            VDSReturnValue returnValue = Backend.getInstance().getResourceManager().runVdsCommand(VDSCommandType.GetImagesList, new GetImagesListVDSCommandParameters(targetStorageDomainId, storagePoolId));
            if (returnValue.getSucceeded()) {
                imagesOnStorageDomain = (List<Guid>) returnValue.getReturnValue();
                domainImages.put(targetStorageDomainId, imagesOnStorageDomain);
            } else {
                return new ValidationResult(EngineMessage.ERROR_GET_IMAGE_LIST, String.format("$sdName %1$s", getStorageDomainStaticDao().get(targetStorageDomainId).getName()));
            }
        }
        if (imagesOnStorageDomain.contains(diskImage.getId())) {
            return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_ALREADY_CONTAINS_DISK);
        }
    }
    return ValidationResult.VALID;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) GetImagesListVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetImagesListVDSCommandParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 40 with VDSReturnValue

use of org.ovirt.engine.core.common.vdscommands.VDSReturnValue in project ovirt-engine by oVirt.

the class GetUnregisteredDisksQueryTest method prepareMocks.

/**
 * Mock the VDSBroker and the Daos
 */
private void prepareMocks() {
    DiskImage existingDiskImage = mock(DiskImage.class);
    when(existingDiskImage.getId()).thenReturn(existingDiskId);
    List<DiskImage> existingDiskImages = Collections.singletonList(existingDiskImage);
    // Mock the get images List VDS command
    VDSReturnValue volListReturnValue = new VDSReturnValue();
    volListReturnValue.setSucceeded(true);
    volListReturnValue.setReturnValue(importDiskIds);
    doReturn(volListReturnValue).when(vdsBroker).runVdsCommand(eq(VDSCommandType.GetImagesList), any());
    // Mock the get unregistered disk query
    when(backendMock.runInternalQuery(eq(QueryType.GetUnregisteredDisk), any(), any())).thenAnswer(invocation -> {
        GetUnregisteredDiskQueryParameters p = (GetUnregisteredDiskQueryParameters) invocation.getArguments()[1];
        QueryReturnValue unregDiskReturnValue = new QueryReturnValue();
        unregDiskReturnValue.setSucceeded(true);
        DiskImage newDiskImage = mock(DiskImage.class);
        when(newDiskImage.getId()).thenReturn(p.getDiskId());
        unregDiskReturnValue.setReturnValue(newDiskImage);
        return unregDiskReturnValue;
    });
    doReturn(storagePoolId).when(getQuery()).getStoragePoolId();
    doReturn(storageDomainId).when(getQuery()).getStorageDomainId();
    when(diskImageDaoMock.getAllSnapshotsForStorageDomain(eq(storageDomainId))).thenReturn(existingDiskImages);
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) GetUnregisteredDiskQueryParameters(org.ovirt.engine.core.common.queries.GetUnregisteredDiskQueryParameters) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Aggregations

VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)250 Guid (org.ovirt.engine.core.compat.Guid)65 ArrayList (java.util.ArrayList)43 VDS (org.ovirt.engine.core.common.businessentities.VDS)29 EngineException (org.ovirt.engine.core.common.errors.EngineException)29 Pair (org.ovirt.engine.core.common.utils.Pair)26 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)23 List (java.util.List)16 Test (org.junit.Test)15 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)15 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)15 VdsIdVDSCommandParametersBase (org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase)15 HashMap (java.util.HashMap)13 VDSError (org.ovirt.engine.core.common.errors.VDSError)13 Map (java.util.Map)11 Callable (java.util.concurrent.Callable)11 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)11 StoragePoolIsoMap (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap)11 EngineLock (org.ovirt.engine.core.utils.lock.EngineLock)9 GlusterGeoRepSession (org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession)8