Search in sources :

Example 91 with EngineException

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

the class ExportVmCommand method copyAllMemoryImages.

private void copyAllMemoryImages(Guid containerID) {
    for (Snapshot snapshot : snapshotsWithMemory) {
        // copy the memory dump image
        DiskImage dumpImage = (DiskImage) diskDao.get(snapshot.getMemoryDiskId());
        ActionReturnValue vdcRetValue = runInternalActionWithTasksContext(ActionType.CopyImageGroup, buildMoveOrCopyImageGroupParametersForMemoryDumpImage(containerID, dumpImage));
        if (!vdcRetValue.getSucceeded()) {
            throw new EngineException(vdcRetValue.getFault().getError(), "Failed during ExportVmCommand");
        }
        // TODO: Currently REST-API doesn't support coco for async commands, remove when bug 1199011 fixed
        getTaskIdList().addAll(vdcRetValue.getVdsmTaskIdList());
        // copy the memory configuration (of the VM) image
        // This volume is always of type 'sparse' and format 'cow' so no need to convert,
        // and there're no snapshots for it so no reason to use copy collapse
        DiskImage confImage = (DiskImage) diskDao.get(snapshot.getMetadataDiskId());
        vdcRetValue = runInternalActionWithTasksContext(ActionType.CopyImageGroup, buildMoveOrCopyImageGroupParameters(containerID, confImage));
        if (!vdcRetValue.getSucceeded()) {
            throw new EngineException(vdcRetValue.getFault().getError(), "Failed during ExportVmCommand");
        }
        // TODO: Currently REST-API doesn't support coco for async commands, remove when bug 1199011 fixed
        getTaskIdList().addAll(vdcRetValue.getVdsmTaskIdList());
    }
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) 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 92 with EngineException

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

the class LoginOnBehalfCommand method getDbUser.

private DbUser getDbUser() {
    DbUser dbUser = null;
    switch(getParameters().getQueryType()) {
        case ByInternalId:
            logInfo = String.format("for internal id %s", getParameters().getUserId());
            dbUser = dbUserDao.get(getParameters().getUserId());
            break;
        case ByPrincipalName:
            logInfo = String.format("for principal name: %s, authz name: %s", getParameters().getPrincipalName(), getParameters().getAuthzName());
            dbUser = getDbUserForPrincipalName(getParameters().getPrincipalName(), getParameters().getAuthzName());
            break;
        case ByExternalId:
            logInfo = String.format("for external id: %s, authz name: %s", getParameters().getExternalId(), getParameters().getAuthzName());
            dbUser = dbUserDao.getByExternalId(getParameters().getAuthzName(), getParameters().getExternalId());
            break;
    }
    if (dbUser == null) {
        throw new EngineException(EngineError.PRINCIPAL_NOT_FOUND, "User not found in database");
    }
    return dbUser;
}
Also used : EngineException(org.ovirt.engine.core.common.errors.EngineException) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 93 with EngineException

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

the class RunVmCommand method runVm.

protected void runVm() {
    setActionReturnValue(VMStatus.Down);
    if (getVdsToRunOn()) {
        VMStatus status = null;
        try {
            acquireHostDevicesLock();
            if (connectLunDisks(getVdsId()) && updateCinderDisksConnections()) {
                if (!checkRequiredHostDevicesAvailability()) {
                    // (while the host-device lock wasn't being held) we need to bail here
                    throw new EngineException(EngineError.HOST_DEVICES_TAKEN_BY_OTHER_VM);
                } else {
                    status = createVm();
                    ExecutionHandler.setAsyncJob(getExecutionContext(), true);
                    markHostDevicesAsUsed();
                }
            }
        } catch (EngineException e) {
            // re-throw it. otherwise, continue (the vm will be down and a re-run will be triggered)
            switch(e.getErrorCode()) {
                // should never get here with errorCode = 'Done' though
                case Done:
                case exist:
                    cleanupPassthroughVnics();
                    reportCompleted();
                    throw e;
                // probably wrong xml format sent.
                case VDS_NETWORK_ERROR:
                case PROVIDER_FAILURE:
                case HOST_DEVICES_TAKEN_BY_OTHER_VM:
                    runningFailed();
                    throw e;
                default:
                    log.warn("Failed to run VM '{}': {}", getVmName(), e.getMessage());
            }
        } finally {
            releaseHostDevicesLock();
            freeLock();
        }
        setActionReturnValue(status);
        if (status != null && (status.isRunning() || status == VMStatus.RestoringState)) {
            setSucceeded(true);
        } else {
            // Try to rerun Vm on different vds no need to log the command because it is
            // being logged inside the rerun
            log.info("Trying to rerun VM '{}'", getVm().getName());
            setCommandShouldBeLogged(false);
            setSucceeded(true);
            rerun();
        }
    } else {
        runningFailed();
    }
}
Also used : EngineException(org.ovirt.engine.core.common.errors.EngineException) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus)

Example 94 with EngineException

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

the class InitVdsOnUpCommand method refreshHostDeviceList.

private void refreshHostDeviceList() {
    try {
        CommandContext ctx = cloneContext();
        ctx.getExecutionContext().setJobRequired(false);
        runInternalAction(ActionType.RefreshHostDevices, new VdsActionParameters(getVdsId()), ctx);
    } catch (EngineException e) {
        log.error("Could not refresh host devices for host '{}'", getVds().getName());
    }
}
Also used : CommandContext(org.ovirt.engine.core.bll.context.CommandContext) VdsActionParameters(org.ovirt.engine.core.common.action.VdsActionParameters) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Example 95 with EngineException

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

the class ReduceImageCommand method executeCommand.

@Override
protected void executeCommand() {
    if (getStorageDomain().getStorageType().isFileDomain()) {
        log.info("Reduce image isn't required for file based domains");
        setSucceeded(true);
        return;
    }
    if (!isReduceVolumeSupported()) {
        log.info("Reduce image isn't supported in {}", getStoragePool().getCompatibilityVersion());
        setSucceeded(true);
        return;
    }
    if (!isInternalMerge()) {
        log.info("Reduce image isn't supported for active image merge");
        setSucceeded(true);
        return;
    }
    getParameters().setEntityInfo(new EntityInfo(VdcObjectType.Disk, getParameters().getImageGroupId()));
    boolean prepareImageSucceeded = false;
    boolean reduceImageSucceeded = false;
    if (!getParameters().isVmRunningOnSpm()) {
        // The VM isn't running on the SPM but the reduce command is performed on the SPM, hence
        // we have to prepare the image on the SPM
        log.debug("Preparing image {}/{} on the SPM", getParameters().getImageGroupId(), getParameters().getImageId());
        try {
            prepareImage();
            prepareImageSucceeded = true;
        } catch (EngineException e) {
            log.error("Failed to prepare image {}/{} on the SPM", getParameters().getImageGroupId(), getParameters().getImageId());
        }
    }
    if (!getParameters().isVmRunningOnSpm() && !prepareImageSucceeded) {
        // As we don't want to fail the live merge because of a failure to reduce the image, we still mark the
        // command as succeeded.
        setSucceeded(true);
        return;
    }
    try {
        VDSReturnValue vdsReturnValue = runVdsCommand(VDSCommandType.ReduceImage, creaeteReduceImageVDSCommandParameters());
        if (vdsReturnValue.getSucceeded()) {
            Guid taskId = persistAsyncTaskPlaceHolder(getParameters().getParentCommand());
            getTaskIdList().add(createTask(taskId, vdsReturnValue.getCreationInfo(), getParameters().getParentCommand(), VdcObjectType.Storage, getParameters().getStorageDomainId()));
            reduceImageSucceeded = true;
        }
    } catch (EngineException e) {
        log.error("Reducing image {}/{} failed", getParameters().getImageGroupId(), getParameters().getImageId());
    }
    if (prepareImageSucceeded && !reduceImageSucceeded) {
        try {
            teardownImage();
        } catch (EngineException e) {
            log.error("Failed to teardown image {}/{} on the SPM", getParameters().getImageGroupId(), getParameters().getImageId());
        }
    }
    setSucceeded(true);
}
Also used : EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

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