Search in sources :

Example 76 with EngineException

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

the class FenceVdsBaseCommand method executeCommand.

@Override
protected void executeCommand() {
    log.info("Power-Management: {} of host '{}' initiated.", getAction(), getVdsName());
    audit(AuditLogType.FENCE_OPERATION_STARTED);
    VDSStatus lastStatus = getVds().getStatus();
    FenceOperationResult result = null;
    try {
        setup();
        result = createHostFenceActionExecutor(getVds(), getParameters().getFencingPolicy()).fence(getAction());
        handleResult(result);
        if (getSucceeded()) {
            log.info("Power-Management: {} host '{}' succeeded.", getAction(), getVdsName());
            audit(AuditLogType.FENCE_OPERATION_SUCCEEDED);
        } else {
            log.info("Power-Management: {} host '{}' failed.", getAction(), getVdsName());
            audit(AuditLogType.FENCE_OPERATION_FAILED);
        }
    } finally {
        if (!getSucceeded()) {
            setStatus(lastStatus);
            if (result != null && result.getStatus() != Status.SKIPPED_DUE_TO_POLICY) {
                // show alert only if command was not skipped due to fencing policy
                alertIfPowerManagementOperationFailed();
            }
            throw new EngineException(EngineError.VDS_FENCE_OPERATION_FAILED);
        } else {
            teardown();
        }
    }
}
Also used : VDSStatus(org.ovirt.engine.core.common.businessentities.VDSStatus) FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Example 77 with EngineException

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

the class ExternalNetworkManagerTest method testDeallocateIfExternalThrowException.

@Test
public void testDeallocateIfExternalThrowException() {
    nic.setName(NIC_NAME);
    nic.setId(NIC_ID);
    provider.setName(PROVIDER_NAME);
    doThrow(new EngineException()).when(networkProviderProxy).deallocate(nic);
    underTest.deallocateIfExternal();
    verify(auditLogDirector).log(auditLogableCaptor.capture(), same(AuditLogType.REMOVE_PORT_FROM_EXTERNAL_PROVIDER_FAILED));
    final Map<String, String> capturedCustomValues = auditLogableCaptor.getValue().getCustomValues();
    assertThat(capturedCustomValues, hasEntry("nicname", NIC_NAME));
    assertThat(capturedCustomValues, hasEntry("nicid", NIC_ID.toString()));
    assertThat(capturedCustomValues, hasEntry("providername", PROVIDER_NAME));
}
Also used : EngineException(org.ovirt.engine.core.common.errors.EngineException) Test(org.junit.Test)

Example 78 with EngineException

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

the class UpdateGlusterHookCommand method executeCommand.

@Override
protected void executeCommand() {
    // check source to copy hook from - if engine copy or server copy
    final boolean copyfromEngine = getParameters().getSourceServerId() == null;
    entity = getGlusterHook();
    addCustomValue(GlusterConstants.HOOK_NAME, entity.getName());
    final String hookContent;
    final String hookChecksum;
    final GlusterHookContentType hookContentType;
    if (copyfromEngine) {
        hookContent = entity.getContent();
        hookChecksum = entity.getChecksum();
        hookContentType = entity.getContentType();
    } else {
        // use a server's copy
        GlusterServerHook sourceServerHook = glusterHooksDao.getGlusterServerHook(entity.getId(), getParameters().getSourceServerId());
        VDSReturnValue retValue = runVdsCommand(VDSCommandType.GetGlusterHookContent, new GlusterHookVDSParameters(getParameters().getSourceServerId(), entity.getGlusterCommand(), entity.getStage(), entity.getName()));
        if (!retValue.getSucceeded()) {
            // throw exception as we cannot continue without content
            log.error("Failed to get content from server with id '{}': {}", getParameters().getSourceServerId(), retValue.getExceptionString());
            throw new EngineException(retValue.getVdsError().getCode(), retValue.getVdsError().getMessage());
        }
        hookContent = (String) retValue.getReturnValue();
        hookChecksum = sourceServerHook.getChecksum();
        hookContentType = sourceServerHook.getContentType();
    }
    List<Callable<Pair<Guid, VDSReturnValue>>> taskList = new ArrayList<>();
    List<Guid> serverIdsToUpdate = new ArrayList<>();
    if (copyfromEngine) {
        for (final GlusterServerHook serverHook : getContentConflictServerHooks()) {
            serverIdsToUpdate.add(serverHook.getServerId());
        }
    } else {
        // need to be updated with hook content
        for (final VDS server : glusterUtil.getAllUpServers(entity.getClusterId())) {
            if (!server.getId().equals(getParameters().getSourceServerId())) {
                serverIdsToUpdate.add(server.getId());
            }
        }
    }
    for (final Guid serverId : serverIdsToUpdate) {
        taskList.add(() -> {
            VDSReturnValue returnValue;
            returnValue = runVdsCommand(VDSCommandType.UpdateGlusterHook, new GlusterHookVDSParameters(serverId, entity.getGlusterCommand(), entity.getStage(), entity.getName(), hookContent, hookChecksum));
            return new Pair<>(serverId, returnValue);
        });
    }
    setSucceeded(true);
    if (!taskList.isEmpty()) {
        List<Pair<Guid, VDSReturnValue>> pairResults = ThreadPoolUtil.invokeAll(taskList);
        for (Pair<Guid, VDSReturnValue> pairResult : pairResults) {
            VDSReturnValue retValue = pairResult.getSecond();
            if (!retValue.getSucceeded()) {
                errors.add(retValue.getVdsError().getMessage());
            }
        }
    } else {
        setSucceeded(false);
    }
    if (errors.size() > 0) {
        setSucceeded(false);
        errorType = AuditLogType.GLUSTER_HOOK_UPDATE_FAILED;
        handleVdsErrors(getAuditLogTypeValue(), errors);
        addCustomValue(GlusterConstants.FAILURE_MESSAGE, StringUtils.join(errors, System.lineSeparator()));
    }
    if (getSucceeded() && !copyfromEngine) {
        // update server's content copy
        entity.setChecksum(hookChecksum);
        entity.setContent(hookContent);
        entity.setContentType(hookContentType);
    }
    if (getSucceeded()) {
        entity.removeContentConflict();
        updateGlusterHook(entity);
    }
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) EngineException(org.ovirt.engine.core.common.errors.EngineException) ArrayList(java.util.ArrayList) GlusterHookContentType(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookContentType) Guid(org.ovirt.engine.core.compat.Guid) Callable(java.util.concurrent.Callable) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook) GlusterHookVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.GlusterHookVDSParameters) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 79 with EngineException

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

the class UpdateHostNicVfsConfigCommand method executeCommand.

@Override
protected void executeCommand() {
    boolean result = true;
    HostNicVfsConfig oldVfsConfig = getVfsConfig();
    boolean allNetworksAllowedChanged = isAllNetworksAllowed() != oldVfsConfig.isAllNetworksAllowed();
    super.executeCommand();
    // Check if 'allNetworksAllowed' has changed
    if (allNetworksAllowedChanged) {
        oldVfsConfig.setAllNetworksAllowed(isAllNetworksAllowed());
        if (isAllNetworksAllowed()) {
            oldVfsConfig.setNetworks(Collections.emptySet());
            oldVfsConfig.setNetworkLabels(Collections.emptySet());
        }
    }
    boolean shouldRefreshHost = false;
    if (wasNumOfVfsChanged()) {
        shouldRefreshHost = true;
        String deviceName = networkDeviceHelper.getPciDeviceNameByNic(getNic());
        try {
            VDSReturnValue returnValue = runVdsCommand(VDSCommandType.HostDevChangeNumVfs, new HostDevChangeNumVfsVDSParameters(getVdsId(), deviceName, getNumOfVfs()));
            result = returnValue.getSucceeded();
        } catch (EngineException e) {
            throw new EngineException(EngineError.UPDATE_NUM_VFS_FAILURE);
        }
    }
    if (result) {
        setSucceeded(saveChangesToDb(shouldRefreshHost, oldVfsConfig, allNetworksAllowedChanged));
    }
}
Also used : HostNicVfsConfig(org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig) EngineException(org.ovirt.engine.core.common.errors.EngineException) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) HostDevChangeNumVfsVDSParameters(org.ovirt.engine.core.common.vdscommands.HostDevChangeNumVfsVDSParameters)

Example 80 with EngineException

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

the class DestroyImageCommand method executeCommand.

@Override
protected void executeCommand() {
    getParameters().setEntityInfo(new EntityInfo(VdcObjectType.Disk, getParameters().getImageGroupId()));
    VDSReturnValue vdsReturnValue = null;
    try {
        vdsReturnValue = runVdsCommand(VDSCommandType.DestroyImage, createVDSParameters());
    } catch (EngineException e) {
        log.error("Failed to delete image {}/{}", getParameters().getImageGroupId(), getParameters().getImageList().stream().findFirst().get(), e);
        if (!getParameters().isLiveMerge()) {
            throw e;
        }
    }
    if (vdsReturnValue != null && vdsReturnValue.getCreationInfo() != null) {
        Guid taskId = persistAsyncTaskPlaceHolder(getParameters().getParentCommand());
        Guid result = createTask(taskId, vdsReturnValue.getCreationInfo(), getParameters().getParentCommand(), VdcObjectType.Storage, getParameters().getStorageDomainId());
        getTaskIdList().add(result);
        log.info("Successfully started task to remove orphaned volumes resulting from live merge");
    } else {
        log.info("Retrying deleting image {}/{}", getParameters().getImageGroupId(), getParameters().getImageList().stream().findFirst().get());
        MergeStatusReturnValue returnValue = new MergeStatusReturnValue(VmBlockJobType.COMMIT, new HashSet<>(getParameters().getImageList()));
        getReturnValue().setActionReturnValue(returnValue);
        // At this point, we know that this command was executed during live merge and it is safe to do
        // the casting in the next line.
        ((RemoveSnapshotSingleDiskParameters) getParameters().getParentParameters()).setNextCommandStep(RemoveSnapshotSingleDiskStep.DESTROY_IMAGE);
    }
    setSucceeded(true);
    setCommandStatus(CommandStatus.SUCCEEDED);
}
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) RemoveSnapshotSingleDiskParameters(org.ovirt.engine.core.common.action.RemoveSnapshotSingleDiskParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) MergeStatusReturnValue(org.ovirt.engine.core.common.action.MergeStatusReturnValue)

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