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());
}
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);
}
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));
}
}
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);
}
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);
}
}
Aggregations