Search in sources :

Example 1 with EngineException

use of org.ovirt.engine.core.common.errors.EngineException 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 2 with EngineException

use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.

the class AddVmTemplateCommand method executeCommand.

@Override
protected void executeCommand() {
    // relevant only if template created from vm
    if (isVmInDb) {
        VmDynamic vmDynamic = vmDynamicDao.get(getVmId());
        if (!isVmStatusValid(vmDynamic.getStatus())) {
            throw new EngineException(EngineError.IRS_IMAGE_STATUS_ILLEGAL);
        }
        vmHandler.lockVm(vmDynamic, getCompensationContext());
    }
    setActionReturnValue(Guid.Empty);
    // set template id as base for new templates
    if (!isTemplateVersion()) {
        getParameters().setBaseTemplateId(getVmTemplateId());
        if (StringUtils.isEmpty(getParameters().getTemplateVersionName())) {
            getParameters().setTemplateVersionName(BASE_TEMPLATE_VERSION_NAME);
        }
    } else {
        // template version name should be the same as the base template name
        setVmTemplateName(getBaseTemplate().getName());
        String jobId = updateVmsJobHashMap.remove(getParameters().getBaseTemplateId());
        if (!StringUtils.isEmpty(jobId)) {
            log.info("Cancelling current running update for vms for base template id '{}'", getParameters().getBaseTemplateId());
            try {
                updateVmsJobMap.remove(getParameters().getBaseTemplateId()).cancel(true);
            } catch (Exception e) {
                log.warn("Failed deleting job '{}' at cancelRecoveryJob", jobId);
            }
        }
    }
    TransactionSupport.executeInNewTransaction(() -> {
        addVmTemplateToDb();
        getCompensationContext().stateChanged();
        return null;
    });
    final Map<Guid, Guid> srcDeviceIdToTargetDeviceIdMapping = addAllTemplateDisks();
    srcDeviceIdToTargetDeviceIdMapping.forEach((oldImageId, newImageId) -> addTemplateDiskVmElement(newImageId, oldImageId));
    TransactionSupport.executeInNewTransaction(() -> {
        addPermission();
        addVmInterfaces(srcDeviceIdToTargetDeviceIdMapping);
        Set<GraphicsType> graphicsToSkip = getParameters().getGraphicsDevices().keySet();
        if (isVmInDb) {
            getVmDeviceUtils().copyVmDevices(getVmId(), getVmTemplateId(), srcDeviceIdToTargetDeviceIdMapping, getParameters().isSoundDeviceEnabled(), getParameters().isConsoleEnabled(), getParameters().isVirtioScsiEnabled(), getVmDeviceUtils().hasMemoryBalloon(getVmId()), graphicsToSkip, false, getEffectiveCompatibilityVersion());
        } else {
            // for instance type and new template without a VM
            getVmDeviceUtils().copyVmDevices(VmTemplateHandler.BLANK_VM_TEMPLATE_ID, getVmTemplateId(), srcDeviceIdToTargetDeviceIdMapping, getParameters().isSoundDeviceEnabled(), getParameters().isConsoleEnabled(), getParameters().isVirtioScsiEnabled(), Boolean.TRUE.equals(getParameters().isBalloonEnabled()), graphicsToSkip, false, getEffectiveCompatibilityVersion());
        }
        updateWatchdog(getVmTemplateId());
        updateRngDevice(getVmTemplateId());
        addGraphicsDevice();
        setSucceeded(true);
        return null;
    });
    if (getParameters().getTemplateType() != VmEntityType.INSTANCE_TYPE) {
        vmHandler.warnMemorySizeLegal(getVmTemplate(), getVm().getCompatibilityVersion());
    }
    // means that there are no asynchronous tasks to execute and that we can
    // end the command synchronously
    pendingAsyncTasks = !getReturnValue().getVdsmTaskIdList().isEmpty() || !commandCoordinatorUtil.getChildCommandIds(getCommandId()).isEmpty();
    if (!pendingAsyncTasks) {
        endSuccessfullySynchronous();
    }
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Example 3 with EngineException

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

Example 4 with EngineException

use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.

the class ImportVmTemplateCommand method moveOrCopyAllImageGroups.

@Override
protected void moveOrCopyAllImageGroups(final Guid containerID, final Iterable<DiskImage> disks) {
    TransactionSupport.executeInNewTransaction(() -> {
        for (DiskImage disk : disks) {
            Guid originalDiskId = newDiskIdForDisk.get(disk.getId()).getId();
            Guid destinationDomain = imageToDestinationDomainMap.get(originalDiskId);
            MoveOrCopyImageGroupParameters p = new MoveOrCopyImageGroupParameters(containerID, originalDiskId, newDiskIdForDisk.get(disk.getId()).getImageId(), disk.getId(), disk.getImageId(), destinationDomain, ImageOperation.Copy);
            p.setParentCommand(getActionType());
            p.setUseCopyCollapse(true);
            p.setVolumeType(disk.getVolumeType());
            p.setVolumeFormat(disk.getVolumeFormat());
            p.setCopyVolumeType(CopyVolumeType.SharedVol);
            p.setSourceDomainId(getParameters().getSourceDomainId());
            p.setForceOverride(getParameters().getForceOverride());
            p.setImportEntity(true);
            p.setEntityInfo(new EntityInfo(VdcObjectType.VmTemplate, containerID));
            p.setRevertDbOperationScope(ImageDbOperationScope.IMAGE);
            for (DiskImage diskImage : getParameters().getVmTemplate().getDiskList()) {
                if (originalDiskId.equals(diskImage.getId())) {
                    p.setQuotaId(diskImage.getQuotaId());
                    p.setDiskProfileId(diskImage.getDiskProfileId());
                    break;
                }
            }
            p.setParentParameters(getParameters());
            ActionReturnValue vdcRetValue = runInternalActionWithTasksContext(ActionType.CopyImageGroup, p);
            if (!vdcRetValue.getSucceeded()) {
                throw vdcRetValue.getFault() != null ? new EngineException(vdcRetValue.getFault().getError()) : new EngineException(EngineError.ENGINE);
            }
            getReturnValue().getVdsmTaskIdList().addAll(vdcRetValue.getInternalVdsmTaskIdList());
        }
        return null;
    });
}
Also used : MoveOrCopyImageGroupParameters(org.ovirt.engine.core.common.action.MoveOrCopyImageGroupParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 5 with EngineException

use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.

the class GlusterGeoRepSyncJob method refreshGeoRepDataForVolume.

/**
 * Exposing this to be called via BLL command in case of force sync of geo-replication session data for volume
 */
public void refreshGeoRepDataForVolume(final GlusterVolumeEntity volume) {
    if (volume == null) {
        throw new EngineException(EngineError.GlusterVolumeGeoRepSyncFailed, "No volume information");
    }
    Cluster cluster = clusterDao.get(volume.getClusterId());
    discoverGeoRepDataInCluster(cluster, volume);
    List<GlusterGeoRepSession> geoRepSessions = geoRepDao.getGeoRepSessions(volume.getId());
    refreshGeoRepSessionStatusForSessions(cluster, geoRepSessions);
}
Also used : EngineException(org.ovirt.engine.core.common.errors.EngineException) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) GlusterGeoRepSession(org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession)

Aggregations

EngineException (org.ovirt.engine.core.common.errors.EngineException)107 Guid (org.ovirt.engine.core.compat.Guid)30 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)25 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)25 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)18 ArrayList (java.util.ArrayList)17 VDS (org.ovirt.engine.core.common.businessentities.VDS)11 HashMap (java.util.HashMap)7 Pair (org.ovirt.engine.core.common.utils.Pair)7 HashSet (java.util.HashSet)6 List (java.util.List)6 Callable (java.util.concurrent.Callable)6 Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)6 IOException (java.io.IOException)5 EntityInfo (org.ovirt.engine.core.common.asynctasks.EntityInfo)5 Map (java.util.Map)4 PersistentHostSetupNetworksParameters (org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters)4 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)4 Set (java.util.Set)3 VdsActionParameters (org.ovirt.engine.core.common.action.VdsActionParameters)3