Search in sources :

Example 16 with EngineFault

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

the class FrontendActionTest method testHandleActionResult_isRaiseErrorModalPanel_withActionMessageSizeGreaterThan1.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a single action</li>
 *   <li>Return logical failure, validate=false.</li>
 *   <li>isRaiseErrorModalPanel returns true.</li>
 *   <li>Check to make sure the failure event is fired</li>
 *   <li>Check to make sure the callback is called</li>
 * </ol>
 * Test just the handler method.
 */
@Test
public void testHandleActionResult_isRaiseErrorModalPanel_withActionMessageSizeGreaterThan1() {
    EngineFault testFault = new EngineFault();
    ArrayList<String> translatedErrors = new ArrayList<>(Arrays.asList("Translated Message 1", // $NON-NLS-1$ //$NON-NLS-2$
    "Translated Message 2"));
    when(mockEventsHandler.isRaiseErrorModalPanel(ActionType.AddDisk, testFault)).thenReturn(true);
    when(mockValidateErrorsTranslator.translateErrorText(any())).thenReturn(translatedErrors);
    ActionParametersBase testParameters = new ActionParametersBase();
    ActionReturnValue returnValue = new ActionReturnValue();
    returnValue.setFault(testFault);
    // $NON-NLS-1$
    returnValue.setDescription("This is a description");
    // $NON-NLS-1$
    returnValue.getValidationMessages().add("Message 1");
    // $NON-NLS-1$
    returnValue.getValidationMessages().add("Message 2");
    // Yes this is the default, but to make sure.
    returnValue.setValid(false);
    frontend.handleActionResult(ActionType.AddDisk, testParameters, returnValue, mockActionCallback, testState, true);
    verify(mockActionCallback).executed(callbackParam.capture());
    // $NON-NLS-1$
    assertEquals("Parameters should match", testParameters, callbackParam.getValue().getParameters());
    // $NON-NLS-1$
    assertEquals("Result should match", returnValue, callbackParam.getValue().getReturnValue());
    // $NON-NLS-1$
    assertEquals("States should match", testState, callbackParam.getValue().getState());
    assertEquals(// $NON-NLS-1$
    "Action type should match", // $NON-NLS-1$
    ActionType.AddDisk, callbackParam.getValue().getActionType());
    ArgumentCaptor<FrontendFailureEventArgs> failureCaptor = ArgumentCaptor.forClass(FrontendFailureEventArgs.class);
    verify(mockFrontendFailureEvent).raise(eq(Frontend.class), failureCaptor.capture());
    assertEquals(// $NON-NLS-1$ //$NON-NLS-2$
    "Text should match", // $NON-NLS-1$ //$NON-NLS-2$
    "Translated Message 1", failureCaptor.getValue().getMessages().get(0).getText());
    assertEquals(// $NON-NLS-1$ //$NON-NLS-2$
    "Text should match", // $NON-NLS-1$ //$NON-NLS-2$
    "Translated Message 2", failureCaptor.getValue().getMessages().get(1).getText());
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EngineFault(org.ovirt.engine.core.common.errors.EngineFault) ArrayList(java.util.ArrayList) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) Test(org.junit.Test)

Example 17 with EngineFault

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

the class RemoveStorageDomainCommand method executeCommand.

@Override
protected void executeCommand() {
    final StorageDomain dom = getStorageDomain();
    VDS vds = getVds();
    boolean format = getParameters().getDoFormat();
    setSucceeded(false);
    if (detachLocalStorageDomain(dom)) {
        return;
    }
    if (format) {
        Pair<Boolean, EngineFault> connectResult = connectStorage();
        if (!connectResult.getFirst()) {
            getReturnValue().setFault(connectResult.getSecond());
            return;
        }
        boolean failed = !formatStorage(dom, vds);
        disconnectStorage();
        if (failed) {
            return;
        }
    }
    TransactionSupport.executeInNewTransaction(() -> {
        getStorageHelper(dom).storageDomainRemoved(dom.getStorageStaticData());
        storageDomainDao.remove(dom.getId());
        return null;
    });
    setSucceeded(true);
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) VDS(org.ovirt.engine.core.common.businessentities.VDS) EngineFault(org.ovirt.engine.core.common.errors.EngineFault)

Example 18 with EngineFault

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

the class RecoveryStoragePoolCommand method executeCommand.

@Override
protected void executeCommand() {
    StorageDomain newMasterDomain = loadTargetedMasterDomain();
    if (storageHelperDirector.getItem(newMasterDomain.getStorageType()).connectStorageToDomainByVdsId(newMasterDomain, getVds().getId())) {
        getEventQueue().submitEventSync(new Event(getParameters().getStoragePoolId(), getParameters().getNewMasterDomainId(), null, EventType.RECOVERY, ""), () -> {
            getParameters().setStorageDomainId(getMasterDomainIdFromDb());
            StoragePoolIsoMap domainPoolMap = new StoragePoolIsoMap(getParameters().getNewMasterDomainId(), getParameters().getStoragePoolId(), StorageDomainStatus.Active);
            storagePoolIsoMapDao.save(domainPoolMap);
            getParameters().setVdsId(getVds().getId());
            ActionReturnValue returnVal = runInternalAction(ActionType.ReconstructMasterDomain, getParameters(), cloneContextAndDetachFromParent());
            boolean reconstructVerbExecuted = (returnVal.getActionReturnValue() != null) ? (Boolean) returnVal.getActionReturnValue() : false;
            storagePoolDao.updateStatus(getStoragePool().getId(), StoragePoolStatus.NonResponsive);
            if (!reconstructVerbExecuted) {
                storagePoolIsoMapDao.remove(domainPoolMap.getId());
            }
            if (returnVal.getSucceeded()) {
                updateStorageDomainFormatIfNeeded(loadTargetedMasterDomain());
            }
            setSucceeded(returnVal.getSucceeded());
            return new EventResult(reconstructVerbExecuted, EventType.RECONSTRUCT);
        });
    } else {
        getReturnValue().setFault(new EngineFault(new EngineException(EngineError.StorageServerConnectionError, "Failed to connect storage"), EngineError.StorageServerConnectionError));
    }
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) EventResult(org.ovirt.engine.core.common.eventqueue.EventResult) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) EngineFault(org.ovirt.engine.core.common.errors.EngineFault) EngineException(org.ovirt.engine.core.common.errors.EngineException) Event(org.ovirt.engine.core.common.eventqueue.Event)

Example 19 with EngineFault

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

the class AddVdsSpmIdCommand method buildFaultResult.

private void buildFaultResult() {
    EngineFault fault = new EngineFault();
    fault.setError(EngineError.ReachedMaxNumberOfHostsInDC);
    fault.setMessage(Backend.getInstance().getVdsErrorsTranslator().translateErrorTextSingle(fault.getError().toString()));
    getReturnValue().setFault(fault);
}
Also used : EngineFault(org.ovirt.engine.core.common.errors.EngineFault)

Example 20 with EngineFault

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

the class HotSetNumberOfCpusCommand method executeCommand.

/**
 * Execution shall perform a call to VDSM to set the number of CPUs.
 * The guest OS will plug/unplug CPUs if the current guest configuration is lower/higher than
 * the requested number respectively.
 */
@Override
protected void executeCommand() {
    VDSReturnValue vdsReturnValue = runVdsCommand(VDSCommandType.SetNumberOfCpus, new SetNumberOfCpusVDSCommand.Params(getVm().getRunOnVds(), getVm().getId(), getParameters().getVm().getNumOfCpus()));
    if (vdsReturnValue.getSucceeded()) {
        setSucceeded(true);
    } else {
        EngineFault fault = new EngineFault();
        fault.setError(vdsReturnValue.getVdsError().getCode());
        fault.setMessage(vdsReturnValue.getVdsError().getMessage());
        getReturnValue().setFault(fault);
    }
}
Also used : SetNumberOfCpusVDSCommand(org.ovirt.engine.core.vdsbroker.SetNumberOfCpusVDSCommand) EngineFault(org.ovirt.engine.core.common.errors.EngineFault) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Aggregations

EngineFault (org.ovirt.engine.core.common.errors.EngineFault)20 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)6 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)6 Test (org.junit.Test)4 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)4 Pair (org.ovirt.engine.core.common.utils.Pair)3 ArrayList (java.util.ArrayList)2 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)2 StorageServerConnections (org.ovirt.engine.core.common.businessentities.StorageServerConnections)2 EngineException (org.ovirt.engine.core.common.errors.EngineException)2 StorageServerConnectionManagementVDSParameters (org.ovirt.engine.core.common.vdscommands.StorageServerConnectionManagementVDSParameters)2 Guid (org.ovirt.engine.core.compat.Guid)2 Map (java.util.Map)1 StorageServerConnectionParametersBase (org.ovirt.engine.core.common.action.StorageServerConnectionParametersBase)1 StoragePoolIsoMap (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap)1 VDS (org.ovirt.engine.core.common.businessentities.VDS)1 LUNStorageServerConnectionMap (org.ovirt.engine.core.common.businessentities.storage.LUNStorageServerConnectionMap)1 Event (org.ovirt.engine.core.common.eventqueue.Event)1 EventResult (org.ovirt.engine.core.common.eventqueue.EventResult)1 DestroyImageVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.DestroyImageVDSCommandParameters)1