use of org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult in project ovirt-engine by oVirt.
the class UiVdcActionTest method executeCallbacks.
@Override
protected void executeCallbacks(boolean success, ActionFlowState flowState, List<IFrontendActionAsyncCallback> callbacks) {
Collections.shuffle(callbacks);
for (IFrontendActionAsyncCallback callback : callbacks) {
assertNotAllDone(flowState);
ActionReturnValue result = new ActionReturnValue();
result.setValid(true);
result.setSucceeded(success);
callback.executed(new FrontendActionAsyncResult(ACTION_TYPE, null, result));
}
}
use of org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult in project ovirt-engine by oVirt.
the class Frontend method runAction.
/**
* Run an action of the specified action type using the passed in parameters, also pass in a state object.
* @param actionType The action type of the action to perform.
* @param parameters The parameters of the action.
* @param callback The callback to call when the action is completed.
* @param state The state object.
* @param showErrorDialog Whether to show a pop-up dialog with the error or not.
*/
public void runAction(final ActionType actionType, final ActionParametersBase parameters, final IFrontendActionAsyncCallback callback, final Object state, final boolean showErrorDialog) {
VdcOperation<ActionType, ActionParametersBase> operation = new VdcOperation<>(actionType, parameters, new VdcOperationCallback<VdcOperation<ActionType, ActionParametersBase>, ActionReturnValue>() {
@Override
public void onSuccess(final VdcOperation<ActionType, ActionParametersBase> operation, final ActionReturnValue result) {
// $NON-NLS-1$
logger.finer("Frontend: sucessfully executed runAction, determining result!");
handleActionResult(actionType, parameters, result, callback != null ? callback : NULLABLE_ASYNC_CALLBACK, state, showErrorDialog);
fireAsyncActionSucceededEvent(state);
}
@Override
public void onFailure(final VdcOperation<ActionType, ActionParametersBase> operation, final Throwable caught) {
if (ignoreFailure(caught)) {
return;
}
// $NON-NLS-1$
logger.log(Level.SEVERE, "Failed to execute runAction: " + caught, caught);
failureEventHandler(caught);
FrontendActionAsyncResult f = new FrontendActionAsyncResult(actionType, parameters, null, state);
if (callback != null) {
callback.executed(f);
}
fireAsyncActionFailedEvent(state);
}
});
fireAsyncOperationStartedEvent(state);
getOperationManager().addOperation(operation);
}
use of org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult in project ovirt-engine by oVirt.
the class Frontend method runMultipleActions.
/**
* A convenience method that calls {@link #runMultipleActions(ActionType, List, List, Object, boolean)} with just a single
* callback to be called when all actions have succeeded and error aggregation.
*
* @param actionType The action to be repeated.
* @param parameters The parameters of each action.
* @param successCallback The callback to be executed when all actions have succeeded.
* @param state State object
*/
public void runMultipleActions(final ActionType actionType, final List<ActionParametersBase> parameters, final IFrontendActionAsyncCallback successCallback, final Object state) {
if (parameters == null || parameters.isEmpty()) {
if (successCallback != null) {
successCallback.executed(new FrontendActionAsyncResult(actionType, null, null, state));
}
return;
}
int n = parameters.size();
IFrontendActionAsyncCallback[] callbacks = new IFrontendActionAsyncCallback[n];
callbacks[n - 1] = successCallback;
runMultipleActions(actionType, parameters, new LinkedList<>(Arrays.asList(callbacks)), state, true);
}
use of org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult in project ovirt-engine by oVirt.
the class Frontend method handleActionResult.
/**
* Handle the result(s) of an action.
* @param actionType The action type.
* @param parameters The parameters of the action.
* @param result The result of the action.
* @param callback The callback to call.
* @param state The state before the action happened.
* @param showErrorDialog Should we show an error dialog?
*/
void handleActionResult(final ActionType actionType, final ActionParametersBase parameters, final ActionReturnValue result, final IFrontendActionAsyncCallback callback, final Object state, final boolean showErrorDialog) {
// $NON-NLS-1$
logger.log(Level.FINER, "Retrieved action result from RunAction.");
FrontendActionAsyncResult f = new FrontendActionAsyncResult(actionType, parameters, result, state);
boolean failedOnValidate = !result.isValid();
if (failedOnValidate) {
result.setValidationMessages((ArrayList<String>) translateError(result));
} else if (!result.getSucceeded()) {
EngineFault fault = result.getFault();
String message = result.getExecuteFailedMessages().size() > 1 ? translateExecuteFailedMessages(result.getExecuteFailedMessages()) : translateEngineFault(fault);
fault.setMessage(message);
if (showErrorDialog && result.getIsSynchronous() && getEventsHandler() != null) {
getEventsHandler().runActionExecutionFailed(actionType, fault);
}
}
callback.executed(f);
// only needed for validate failure
if (showErrorDialog && failedOnValidate && (getEventsHandler() != null) && getEventsHandler().isRaiseErrorModalPanel(actionType, result.getFault())) {
ArrayList<String> messages = result.getValidationMessages();
failureEventHandler(result.getDescription(), // $NON-NLS-1$
messages.isEmpty() ? Collections.singletonList(getConstants().noValidateMessage()) : messages);
}
}
use of org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult in project ovirt-engine by oVirt.
the class StorageListModel method saveSanStorage.
private void saveSanStorage(TaskContext context) {
this.context = context;
StorageModel model = (StorageModel) getWindow();
SanStorageModelBase sanModel = (SanStorageModelBase) model.getCurrentStorageItem();
StorageDomain storage = getSelectedItem();
boolean isNew = model.getStorage() == null;
storageDomain = isNew ? new StorageDomainStatic() : (StorageDomainStatic) Cloner.clone(storage.getStorageStaticData());
storageDomain.setStorageType(isNew ? sanModel.getType() : storageDomain.getStorageType());
storageDomain.setStorageDomainType(isNew ? sanModel.getRole() : storageDomain.getStorageDomainType());
storageDomain.setStorageFormat(isNew ? sanModel.getContainer().getFormat().getSelectedItem() : storageDomain.getStorageFormat());
storageDomain.setDescription(model.getDescription().getEntity());
storageDomain.setComment(model.getComment().getEntity());
saveCommonStorageProperties(model);
if (isNew) {
saveNewSanStorage();
} else {
Frontend.getInstance().runAction(ActionType.UpdateStorageDomain, new StorageDomainManagementParameter(storageDomain), new IFrontendActionAsyncCallback() {
@Override
public void executed(FrontendActionAsyncResult result) {
StorageListModel storageListModel = (StorageListModel) result.getState();
StorageModel storageModel = (StorageModel) getWindow();
SanStorageModelBase sanStorageModelBase = (SanStorageModelBase) storageModel.getCurrentStorageItem();
boolean force = sanStorageModelBase.isForce();
StorageDomain storageDomain1 = storageListModel.getSelectedItem();
HashSet<String> lunIds = new HashSet<>();
for (LunModel lun : sanStorageModelBase.getAddedLuns()) {
lunIds.add(lun.getLunId());
}
if (lunIds.size() > 0) {
Frontend.getInstance().runAction(ActionType.ExtendSANStorageDomain, new ExtendSANStorageDomainParameters(storageDomain1.getId(), new HashSet<>(lunIds), force), null, this);
}
Set<String> lunToRefreshIds = sanStorageModelBase.getLunsToRefresh();
if (lunToRefreshIds.size() > 0) {
Frontend.getInstance().runAction(ActionType.RefreshLunsSize, new ExtendSANStorageDomainParameters(storageDomain1.getId(), lunToRefreshIds, false), null, this);
}
if (storageDomain1.getStatus() == StorageDomainStatus.Maintenance) {
Set<String> lunsToRemoveIds = sanStorageModelBase.getLunsToRemove();
if (lunsToRemoveIds.size() > 0) {
Frontend.getInstance().runAction(ActionType.ReduceSANStorageDomainDevices, new ReduceSANStorageDomainDevicesCommandParameters(storageDomain1.getId(), new ArrayList<>(lunsToRemoveIds)), null, this);
}
}
storageListModel.onFinish(storageListModel.context, true, storageListModel.storageModel);
}
}, this);
}
}
Aggregations