Search in sources :

Example 51 with EngineException

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

the class CommandAsyncTask method endCommandAction.

private void endCommandAction() {
    CommandMultiAsyncTasks entityInfo = getCommandMultiAsyncTasks();
    ActionReturnValue actionReturnValue = null;
    ExecutionContext context = null;
    boolean endActionRuntimeException = false;
    AsyncTask dbAsyncTask = getParameters().getDbAsyncTask();
    ArrayList<ActionParametersBase> imagesParameters = new ArrayList<>();
    for (EndedTaskInfo taskInfo : entityInfo.getEndedTasksInfo().getTasksInfo()) {
        ActionParametersBase childTaskParameters = taskInfo.getTaskParameters().getDbAsyncTask().getTaskParameters();
        boolean childTaskGroupSuccess = childTaskParameters.getTaskGroupSuccess() && taskInfo.getTaskStatus().getTaskEndedSuccessfully();
        childTaskParameters.setTaskGroupSuccess(childTaskGroupSuccess);
        if (!childTaskParameters.equals(dbAsyncTask.getActionParameters())) {
            imagesParameters.add(childTaskParameters);
        }
    }
    dbAsyncTask.getActionParameters().setImagesParameters(imagesParameters);
    try {
        log.info("CommandAsyncTask::endCommandAction [within thread] context: Attempting to endAction '{}',", dbAsyncTask.getActionParameters().getCommandType());
        try {
            actionReturnValue = coco.endAction(this);
        } catch (EngineException ex) {
            log.error("{}: {}", getErrorMessage(), ex.getMessage());
            log.debug("Exception", ex);
        } catch (RuntimeException ex) {
            log.error(getErrorMessage(), ex);
            endActionRuntimeException = true;
        }
    } catch (RuntimeException Ex2) {
        log.error("CommandAsyncTask::endCommandAction [within thread]: An exception has been thrown (not" + " related to 'endAction' itself)", Ex2);
        endActionRuntimeException = true;
    } finally {
        // if a RuntimeExcpetion occurs we clear the task from db and perform no other action
        if (endActionRuntimeException) {
            handleEndActionRuntimeException(entityInfo, dbAsyncTask);
        } else {
            boolean isTaskGroupSuccess = dbAsyncTask.getActionParameters().getTaskGroupSuccess();
            handleEndActionResult(entityInfo, actionReturnValue, context, isTaskGroupSuccess);
        }
    }
}
Also used : CommandMultiAsyncTasks(org.ovirt.engine.core.bll.CommandMultiAsyncTasks) ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) AsyncTask(org.ovirt.engine.core.common.businessentities.AsyncTask) ArrayList(java.util.ArrayList) EngineException(org.ovirt.engine.core.common.errors.EngineException) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) EndedTaskInfo(org.ovirt.engine.core.common.asynctasks.EndedTaskInfo)

Example 52 with EngineException

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

the class MacPoolPerClusterTest method testModifyOfExistingMacPool.

@Test
public void testModifyOfExistingMacPool() throws Exception {
    final String macAddress1 = "00:00:00:00:00:01";
    final String macAddress2 = "00:00:00:00:00:02";
    MacPool macPool = createMacPool(macAddress1, macAddress1);
    Cluster cluster = createCluster(macPool);
    mockCluster(cluster);
    mockGettingAllMacPools(macPool);
    macPoolPerCluster.initialize();
    assertThat(getMacPool(cluster.getId()).addMac(MAC_FROM), is(true));
    assertThat(getMacPool(cluster.getId()).addMac(MAC_FROM), is(false));
    final String allocatedMac = allocateMac(cluster);
    /*needed due to implementation of modifyPool;
        modify assumes, that all allocated macs is used for vmNics. If allocatedMac succeeded it's expected that all
        vmNics were also successfully persisted to db or all allocated macs were returned to the pool. So after
        allocation we need to mock db, otherwise re-init in modifyPool would return improper results.*/
    mockUsedMacsInSystem(getMacPool(cluster.getId()).getId(), allocatedMac, MAC_FROM);
    assertThat(allocatedMac, is(macAddress1));
    try {
        allocateMac(cluster);
        fail("this allocation should not succeed, MAC should be full.");
    } catch (EngineException e) {
    // ok, this exception should occur.
    }
    macPool.setAllowDuplicateMacAddresses(true);
    final MacRange macRange = new MacRange();
    macRange.setMacFrom(macAddress1);
    macRange.setMacTo(macAddress2);
    macPool.setRanges(Collections.singletonList(macRange));
    macPoolPerCluster.modifyPool(macPool);
    assertThat(getMacPool(cluster.getId()).addMac(MAC_FROM), is(true));
    assertThat(allocateMac(cluster), is(macAddress2));
}
Also used : MacPool(org.ovirt.engine.core.common.businessentities.MacPool) MacRange(org.ovirt.engine.core.common.businessentities.MacRange) EngineException(org.ovirt.engine.core.common.errors.EngineException) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Test(org.junit.Test)

Example 53 with EngineException

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

the class MergeCommand method executeCommand.

@Override
public void executeCommand() {
    boolean mergeRunning = false;
    try {
        VDSReturnValue vdsReturnValue = runVdsCommand(VDSCommandType.Merge, createVDSParameters());
        if (vdsReturnValue.getSucceeded()) {
            Guid jobId = (Guid) vdsReturnValue.getReturnValue();
            persistBlockJobPlaceholder(jobId);
            getParameters().setVmJobId(jobId);
            persistCommand(getParameters().getParentCommand(), true);
            log.debug("Merge started successfully");
            mergeRunning = true;
        } else {
            log.error("Failed to start Merge on VDS");
        }
    } catch (EngineException e) {
        log.error("Engine exception thrown while sending merge command", e);
        if (e.getErrorCode() == EngineError.imageErr || e.getErrorCode() == EngineError.mergeErr) {
            // In this case, we are not certain whether merge is currently running or
            // whether one of the relevant volumes already removed from the chain. In these cases,
            // we want to verify the current state; therefore, we consider the merge to be running.
            mergeRunning = true;
        }
    } finally {
        if (mergeRunning) {
            setSucceeded(true);
        } else {
            setCommandStatus(CommandStatus.FAILED);
        }
    }
}
Also used : EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 54 with EngineException

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

the class MergeStatusCommand method getVolumeChain.

private Set<Guid> getVolumeChain() {
    Map[] vms = null;
    try {
        vms = getVms();
    } catch (EngineException e) {
        log.error("Failed to retrieve images list of VM {}. Retrying ...", getParameters().getVmId(), e);
    }
    if (vms == null || vms.length == 0) {
        log.error("Failed to retrieve VM information");
        return null;
    }
    Map vm = vms[0];
    if (vm == null || vm.get(VdsProperties.vm_guid) == null) {
        log.error("Received incomplete VM information");
        return null;
    }
    Guid vmId = new Guid((String) vm.get(VdsProperties.vm_guid));
    if (!vmId.equals(getParameters().getVmId())) {
        log.error("Invalid VM returned when querying status: expected '{}', got '{}'", getParameters().getVmId(), vmId);
        return null;
    }
    Set<Guid> images = new HashSet<>();
    DiskImage activeDiskImage = getParameters().getActiveImage();
    for (Object o : (Object[]) vm.get(VdsProperties.Devices)) {
        Map device = (Map<String, Object>) o;
        if (VdsProperties.Disk.equals(device.get(VdsProperties.Type)) && activeDiskImage.getId().equals(Guid.createGuidFromString((String) device.get(VdsProperties.ImageId)))) {
            Object[] volumeChain = (Object[]) device.get(VdsProperties.VolumeChain);
            for (Object v : volumeChain) {
                Map<String, Object> volume = (Map<String, Object>) v;
                images.add(Guid.createGuidFromString((String) volume.get(VdsProperties.VolumeId)));
            }
            break;
        }
    }
    return images;
}
Also used : EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) Map(java.util.Map) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) HashSet(java.util.HashSet)

Example 55 with EngineException

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

the class InitVdsOnUpCommand method proceedVdsStats.

private Pair<Boolean, List<StorageDomainStatic>> proceedVdsStats(boolean shouldCheckReportedDomains, StoragePool storagePool) {
    Pair<Boolean, List<StorageDomainStatic>> returnValue = new Pair<>(true, null);
    try {
        runVdsCommand(VDSCommandType.GetStats, new VdsIdAndVdsVDSCommandParametersBase(getVds()));
        if (shouldCheckReportedDomains) {
            List<Guid> problematicDomainsIds = fetchDomainsReportedAsProblematic(getVds().getDomains(), storagePool);
            for (Guid domainId : problematicDomainsIds) {
                StorageDomainStatic domainInfo = storageDomainStaticDao.get(domainId);
                log.error("Storage Domain '{}' of pool '{}' is in problem in host '{}'", domainInfo != null ? domainInfo.getStorageName() : domainId, getStoragePool().getName(), getVds().getName());
                if (domainInfo == null || domainInfo.getStorageDomainType().isDataDomain()) {
                    returnValue.setFirst(false);
                    if (returnValue.getSecond() == null) {
                        returnValue.setSecond(new ArrayList<>());
                    }
                    returnValue.getSecond().add(domainInfo);
                }
            }
        }
    } catch (EngineException e) {
        log.error("Could not get Host statistics for Host '{}': {}", getVds().getName(), e.getMessage());
        log.debug("Exception", e);
        returnValue.setFirst(false);
    }
    return returnValue;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) VdsIdAndVdsVDSCommandParametersBase(org.ovirt.engine.core.common.vdscommands.VdsIdAndVdsVDSCommandParametersBase) EngineException(org.ovirt.engine.core.common.errors.EngineException) List(java.util.List) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) Pair(org.ovirt.engine.core.common.utils.Pair)

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