Search in sources :

Example 21 with ActionReturnValue

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

the class VmSnapshotListModel method onCloneVM.

private void onCloneVM() {
    UnitVmModel model = (UnitVmModel) getWindow();
    CloneVmFromSnapshotModelBehavior behavior = (CloneVmFromSnapshotModelBehavior) model.getBehavior();
    Snapshot snapshot = getSelectedItem();
    if (snapshot == null) {
        cancel();
        return;
    }
    if (!model.validate()) {
        return;
    }
    VM vm = behavior.getVm();
    // Save changes.
    buildVmOnClone(model, vm);
    vm.setUseHostCpuFlags(model.getHostCpu().getEntity());
    vm.setDiskMap(behavior.getVm().getDiskMap());
    HashMap<Guid, DiskImage> imageToDestinationDomainMap = model.getDisksAllocationModel().getImageToDestinationDomainMap();
    AddVmFromSnapshotParameters parameters = new AddVmFromSnapshotParameters(vm.getStaticData(), snapshot.getId());
    parameters.setDiskInfoDestinationMap(imageToDestinationDomainMap);
    parameters.setConsoleEnabled(model.getIsConsoleDeviceEnabled().getEntity());
    parameters.setVirtioScsiEnabled(model.getIsVirtioScsiEnabled().getEntity());
    parameters.setBalloonEnabled(model.getMemoryBalloonDeviceEnabled().getEntity());
    BuilderExecutor.build(model, parameters, new UnitToGraphicsDeviceParamsBuilder());
    if (!StringHelper.isNullOrEmpty(model.getVmId().getEntity())) {
        parameters.setVmId(new Guid(model.getVmId().getEntity()));
    }
    model.startProgress();
    Frontend.getInstance().runAction(ActionType.AddVmFromSnapshot, parameters, result -> {
        VmSnapshotListModel vmSnapshotListModel = (VmSnapshotListModel) result.getState();
        vmSnapshotListModel.getWindow().stopProgress();
        ActionReturnValue returnValueBase = result.getReturnValue();
        if (returnValueBase != null && returnValueBase.getSucceeded()) {
            vmSnapshotListModel.cancel();
            vmSnapshotListModel.updateActionAvailability();
        }
    }, this);
}
Also used : UnitToGraphicsDeviceParamsBuilder(org.ovirt.engine.ui.uicommonweb.builders.vm.UnitToGraphicsDeviceParamsBuilder) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) VM(org.ovirt.engine.core.common.businessentities.VM) Guid(org.ovirt.engine.core.compat.Guid) AddVmFromSnapshotParameters(org.ovirt.engine.core.common.action.AddVmFromSnapshotParameters) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 22 with ActionReturnValue

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

the class UiVdcActionTest method executeCallbacks.

@Override
protected void executeCallbacks(boolean success, ActionFlowState flowState, List<IFrontendActionAsyncCallback> callbacks) {
    Collections.shuffle(callbacks);
    for (IFrontendActionAsyncCallback callback : callbacks) {
        assertNotAllDone(flowState);
        ActionReturnValue result = new ActionReturnValue();
        result.setValid(true);
        result.setSucceeded(success);
        callback.executed(new FrontendActionAsyncResult(ACTION_TYPE, null, result));
    }
}
Also used : FrontendActionAsyncResult(org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback)

Example 23 with ActionReturnValue

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

the class AddVmCommand method addVmCinderDisks.

protected void addVmCinderDisks(Collection<DiskImage> templateDisks) {
    List<CinderDisk> cinderDisks = DisksFilter.filterCinderDisks(templateDisks);
    if (cinderDisks.isEmpty()) {
        return;
    }
    Map<Guid, Guid> diskImageMap = new HashMap<>();
    for (CinderDisk cinderDisk : cinderDisks) {
        ImagesContainterParametersBase params = buildCloneCinderDiskCommandParameters(cinderDisk);
        ActionReturnValue actionReturnValue = runInternalAction(ActionType.CloneSingleCinderDisk, params, cloneContext().withoutExecutionContext().withoutLock());
        if (!actionReturnValue.getSucceeded()) {
            log.error("Error cloning Cinder disk '{}': {}", cinderDisk.getDiskAlias());
            getReturnValue().setFault(actionReturnValue.getFault());
            return;
        }
        Guid imageId = actionReturnValue.getActionReturnValue();
        diskImageMap.put(cinderDisk.getId(), imageId);
    }
    srcDiskIdToTargetDiskIdMapping.putAll(diskImageMap);
}
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 24 with ActionReturnValue

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

the class AddVmCommand method addVmImages.

protected boolean addVmImages() {
    if (!vmDisksSource.getDiskTemplateMap().isEmpty()) {
        if (getVm().getStatus() != VMStatus.Down) {
            log.error("Cannot add images. VM is not Down");
            throw new EngineException(EngineError.IRS_IMAGE_STATUS_ILLEGAL);
        }
        lockVM();
        Collection<DiskImage> templateDisks = getImagesToCheckDestinationStorageDomains();
        List<DiskImage> diskImages = DisksFilter.filterImageDisks(templateDisks, ONLY_NOT_SHAREABLE, ONLY_ACTIVE);
        for (DiskImage image : diskImages) {
            ActionReturnValue result = runInternalActionWithTasksContext(getDiskCreationCommandType(), buildDiskCreationParameters(image));
            // if couldn't create snapshot then stop the transaction and the command
            if (!result.getSucceeded()) {
                throw new EngineException(result.getFault().getError());
            } else {
                getTaskIdList().addAll(result.getInternalVdsmTaskIdList());
                DiskImage newImage = result.getActionReturnValue();
                srcDiskIdToTargetDiskIdMapping.put(image.getId(), newImage.getId());
            }
        }
        // Clone volumes for Cinder disk templates
        addVmCinderDisks(templateDisks);
    }
    return true;
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EngineException(org.ovirt.engine.core.common.errors.EngineException) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 25 with ActionReturnValue

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

the class ImportVmFromExternalProviderCommand method createDisk.

protected Guid createDisk(DiskImage image) {
    ActionReturnValue actionReturnValue = runInternalActionWithTasksContext(ActionType.AddDisk, buildAddDiskParameters(image));
    if (!actionReturnValue.getSucceeded()) {
        throw new EngineException(actionReturnValue.getFault().getError(), "Failed to create disk!");
    }
    getTaskIdList().addAll(actionReturnValue.getInternalVdsmTaskIdList());
    return actionReturnValue.getActionReturnValue();
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EngineException(org.ovirt.engine.core.common.errors.EngineException)

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