Search in sources :

Example 46 with EngineException

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

the class VdsEventListener method onMomPolicyChange.

// TODO asynch event handler - design infra code to allow async events in segregated thread
public void onMomPolicyChange(@Observes @MomPolicyUpdate final Cluster cluster) {
    if (cluster == null) {
        return;
    }
    List<VDS> activeHostsInCluster = vdsDao.getAllForClusterWithStatus(cluster.getId(), VDSStatus.Up);
    // collect all Active hosts into a callable list
    List<Callable<Object>> callables = new LinkedList<>();
    for (final VDS vds : activeHostsInCluster) {
        callables.add(() -> {
            try {
                resourceManagerProvider.get().runVdsCommand(VDSCommandType.SetMOMPolicyParameters, new MomPolicyVDSParameters(vds, cluster.isEnableBallooning(), cluster.isEnableKsm(), cluster.isKsmMergeAcrossNumaNodes()));
            } catch (EngineException e) {
                log.error("Could not update MoM policy on host '{}'", vds.getName());
            }
            return null;
        });
    }
    // run all VDSCommands concurrently with executor
    if (callables.size() > 0) {
        ThreadPoolUtil.invokeAll(callables);
    }
}
Also used : MomPolicyVDSParameters(org.ovirt.engine.core.common.vdscommands.MomPolicyVDSParameters) VDS(org.ovirt.engine.core.common.businessentities.VDS) EngineException(org.ovirt.engine.core.common.errors.EngineException) Callable(java.util.concurrent.Callable) LinkedList(java.util.LinkedList)

Example 47 with EngineException

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

the class LoginOnBehalfCommand method getDbUserForPrincipalName.

private DbUser getDbUserForPrincipalName(String principalName, String authzName) {
    Map<String, Object> response = SsoOAuthServiceUtils.fetchPrincipalRecord(getSessionDataContainer().getSsoAccessToken(getParameters().getSessionId()), authzName, principalName, false, false);
    ExtMap principalRecord = null;
    if (response.containsKey("result")) {
        Collection<ExtMap> records = (Collection<ExtMap>) response.get("result");
        if (!records.isEmpty()) {
            principalRecord = records.iterator().next();
        }
    }
    if (principalRecord == null) {
        throw new EngineException(EngineError.PRINCIPAL_NOT_FOUND, String.format("%s in domain '%s", principalName, authzName));
    }
    DbUser user = new DbUser(directoryUtils.mapPrincipalRecordToDirectoryUser(authzName, principalRecord));
    user.setId(Guid.newGuid());
    return user;
}
Also used : ExtMap(org.ovirt.engine.api.extensions.ExtMap) EngineException(org.ovirt.engine.core.common.errors.EngineException) Collection(java.util.Collection) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 48 with EngineException

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

the class ConvertVmCommand method executeVmCommand.

@Override
protected void executeVmCommand() {
    try {
        VDSReturnValue retValue = runVdsCommand();
        if (retValue.getSucceeded()) {
            monitorV2VJob(JobStatus.WAIT_FOR_START);
            setSucceeded(true);
        } else {
            log.error("Failed to convert VM");
            setCommandStatus(CommandStatus.FAILED);
        }
    } catch (EngineException e) {
        log.error("Failed to convert VM", e);
        setCommandStatus(CommandStatus.FAILED);
    }
}
Also used : EngineException(org.ovirt.engine.core.common.errors.EngineException) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 49 with EngineException

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

the class HostSetupNetworksCommand method executeCommand.

@Override
protected void executeCommand() {
    if (noChangesDetected()) {
        log.info("No changes were detected in setup networks for host '{}' (ID: '{}')", getVdsName(), getVdsId());
        setSucceeded(true);
        return;
    }
    try (EngineLock monitoringLock = acquireMonitorLock("Host setup networks")) {
        int timeout = getSetupNetworksTimeout();
        FutureVDSCall<VDSReturnValue> setupNetworksTask = invokeSetupNetworksCommand(timeout);
        try {
            VDSReturnValue retVal = setupNetworksTask.get(timeout, TimeUnit.SECONDS);
            if (retVal != null) {
                if (!retVal.getSucceeded() && retVal.getVdsError() == null && getParameters().rollbackOnFailure()) {
                    throw new EngineException(EngineError.SETUP_NETWORKS_ROLLBACK, retVal.getExceptionString());
                }
                VdsHandler.handleVdsResult(retVal);
                if (retVal.getSucceeded()) {
                    VDSReturnValue returnValue = runVdsCommand(VDSCommandType.GetCapabilities, new VdsIdAndVdsVDSCommandParametersBase(getVds()));
                    VDS updatedHost = (VDS) returnValue.getReturnValue();
                    persistNetworkChanges(updatedHost);
                }
                setSucceeded(true);
            }
        } catch (TimeoutException e) {
            log.debug("Host Setup networks command timed out for {} seconds", timeout);
        }
    }
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) VdsIdAndVdsVDSCommandParametersBase(org.ovirt.engine.core.common.vdscommands.VdsIdAndVdsVDSCommandParametersBase) EngineException(org.ovirt.engine.core.common.errors.EngineException) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) TimeoutException(java.util.concurrent.TimeoutException)

Example 50 with EngineException

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

the class VdsCommandsHelper method runVdsCommand.

private VDSReturnValue runVdsCommand(VDSCommandType vdsCommandType, VdsIdVDSCommandParametersBase params, Guid storagePoolId, CommandBase<?> cmd, boolean performFailover) {
    Set<Guid> executedHosts = new HashSet<>();
    VDSReturnValue returnValue = null;
    if (params.getVdsId() == null) {
        chooseHostForExecution(params, storagePoolId, cmd, Collections.emptyList());
        if (params.getVdsId() == null) {
            throw new EngineException(EngineError.RESOURCE_MANAGER_VDS_NOT_FOUND, "No host was found to perform the operation");
        }
    }
    int attempts = 0;
    while (attempts <= Config.<Integer>getValue(ConfigValues.HsmCommandFailOverRetries)) {
        try {
            attempts++;
            returnValue = resourceManager.runVdsCommand(vdsCommandType, params);
            if (returnValue != null && returnValue.getSucceeded()) {
                return returnValue;
            }
        } catch (EngineException e) {
            returnValue = e.getVdsReturnValue();
        }
        executedHosts.add(params.getVdsId());
        if (!performFailover || (returnValue != null && !returnValue.isCanTryOnDifferentVds())) {
            break;
        }
        chooseHostForExecution(params, storagePoolId, cmd, executedHosts);
        if (params.getVdsId() == null) {
            break;
        }
    }
    return VdsHandler.handleVdsResult(returnValue);
}
Also used : EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) HashSet(java.util.HashSet) 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