use of org.ovirt.engine.core.common.action.ActionReturnValue 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.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class Frontend method runMultipleAction.
/**
* Run multiple actions using the same {@code ActionType}.
* @param actionType The action type.
* @param parameters The list of parameters.
* @param isRunOnlyIfAllValidationPass A flag to only run the actions if all can be completed.
* @param callback The callback to call when the operation completes.
* @param state The state.
* @param showErrorDialog Should we show an error dialog?
* @param waitForResult a flag to return the result after running the whole action and not just the can do actions.
*/
public void runMultipleAction(final ActionType actionType, final List<ActionParametersBase> parameters, final boolean isRunOnlyIfAllValidationPass, final IFrontendMultipleActionAsyncCallback callback, final Object state, final boolean showErrorDialog, final boolean waitForResult) {
VdcOperationCallbackList<VdcOperation<ActionType, ActionParametersBase>, List<ActionReturnValue>> multiCallback = new VdcOperationCallbackList<VdcOperation<ActionType, ActionParametersBase>, List<ActionReturnValue>>() {
@Override
public void onSuccess(final List<VdcOperation<ActionType, ActionParametersBase>> operationList, final List<ActionReturnValue> resultObject) {
// $NON-NLS-1$
logger.finer("Frontend: successfully executed runMultipleAction, determining result!");
List<ActionReturnValue> failed = resultObject.stream().filter(v -> !v.isValid()).collect(Collectors.toList());
if (showErrorDialog && !failed.isEmpty()) {
translateErrors(failed);
getEventsHandler().runMultipleActionFailed(actionType, failed);
}
if (callback != null) {
callback.executed(new FrontendMultipleActionAsyncResult(actionType, parameters, resultObject, state));
}
fireAsyncActionSucceededEvent(state);
}
@Override
public void onFailure(final List<VdcOperation<ActionType, ActionParametersBase>> operation, final Throwable caught) {
if (ignoreFailure(caught)) {
return;
}
// $NON-NLS-1$
logger.log(Level.SEVERE, "Failed to execute runMultipleAction: " + caught, caught);
failureEventHandler(caught);
if (callback != null) {
callback.executed(new FrontendMultipleActionAsyncResult(actionType, parameters, null, state));
}
fireAsyncActionFailedEvent(state);
}
};
List<VdcOperation<?, ?>> operationList = parameters.stream().map(p -> new VdcOperation<>(actionType, p, !waitForResult, multiCallback, isRunOnlyIfAllValidationPass)).collect(Collectors.toList());
fireAsyncOperationStartedEvent(state);
if (operationList.isEmpty()) {
// it ourselves.
if (scheduler == null) {
scheduler = Scheduler.get();
}
scheduler.scheduleDeferred(() -> {
if (callback != null) {
List<ActionReturnValue> emptyResult = new ArrayList<>();
callback.executed(new FrontendMultipleActionAsyncResult(actionType, parameters, emptyResult, state));
}
});
} else {
getOperationManager().addOperationList(operationList);
}
}
use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class Frontend method runMultipleActions.
private void runMultipleActions(final List<ActionType> actionTypes, final List<ActionParametersBase> parameters, final List<IFrontendActionAsyncCallback> callbacks, final IFrontendActionAsyncCallback failureCallback, final Object state, final boolean aggregateErrors, final List<ActionType> failedActions, final List<ActionReturnValue> failedReturnValues) {
if (actionTypes.isEmpty() || parameters.isEmpty() || callbacks.isEmpty()) {
if (aggregateErrors && failedReturnValues != null && !failedReturnValues.isEmpty()) {
getEventsHandler().runMultipleActionsFailed(failedActions, failedReturnValues);
}
return;
}
runAction(actionTypes.get(0), parameters.get(0), result -> {
ActionReturnValue returnValue = result.getReturnValue();
boolean success = returnValue != null && returnValue.getSucceeded();
if (success || failureCallback == null) {
IFrontendActionAsyncCallback callback = callbacks.get(0);
if (callback != null) {
callback.executed(result);
}
if (aggregateErrors && returnValue != null && (!returnValue.isValid() || !returnValue.getSucceeded())) {
failedActions.add(actionTypes.get(0));
failedReturnValues.add(returnValue);
}
actionTypes.remove(0);
parameters.remove(0);
callbacks.remove(0);
runMultipleActions(actionTypes, parameters, callbacks, failureCallback, state, aggregateErrors, failedActions, failedReturnValues);
} else {
failureCallback.executed(result);
}
}, state, !aggregateErrors || failureCallback != null);
}
use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class GWTRPCCommunicationProvider method logout.
/**
* Log the user out.
* @param callback The callback to call when the operation is complete.
*/
@Override
public void logout(final UserCallback callback) {
// Remove the rpc token when logging out.
xsrfRequestBuilder.setXsrfToken(null);
ActionReturnValue retVal = new ActionReturnValue();
retVal.setSucceeded(true);
callback.onSuccess(retVal);
}
use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class AddDataCenterRM method rollback3.
public void rollback3() {
Enlistment enlistment = context.enlistment;
EnlistmentContext enlistmentContext = (EnlistmentContext) enlistment.getContext();
HostListModel<?> model = enlistmentContext.getModel();
VDS host = context.hostFoundById;
boolean abort = false;
if (model.getSelectedItem() != null) {
// Perform rollback only when the host is in maintenance.
if (host.getStatus() != VDSStatus.Maintenance) {
abort = true;
}
} else {
abort = true;
}
if (abort) {
context.enlistment = null;
enlistment.done();
return;
}
StoragePool dataCenter = context.dataCenterFoundById;
// Perform rollback only when the Data Center is un uninitialized.
if (dataCenter.getStatus() != StoragePoolStatus.Uninitialized) {
context.enlistment = null;
enlistment.done();
return;
}
if (enlistmentContext.getOldClusterId() != null) {
// Switch host back to previous cluster.
Frontend.getInstance().runAction(ActionType.ChangeVDSCluster, new ChangeVDSClusterParameters(enlistmentContext.getOldClusterId(), host.getId()), result -> {
ActionReturnValue returnValue = result.getReturnValue();
context.changeVDSClusterReturnValue = returnValue;
rollback4();
});
} else {
context.enlistment = null;
enlistment.done();
}
}
Aggregations