Search in sources :

Example 1 with FrontendMultipleActionAsyncResult

use of org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult 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);
    }
}
Also used : QueryType(org.ovirt.engine.core.common.queries.QueryType) MessageFormatter(org.ovirt.engine.ui.frontend.IFrontendEventsHandler.MessageFormatter) Arrays(java.util.Arrays) FrontendActionAsyncResult(org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) Inject(com.google.inject.Inject) FrontendMultipleActionAsyncResult(org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult) VdcOperation(org.ovirt.engine.ui.frontend.communication.VdcOperation) Event(org.ovirt.engine.ui.uicompat.Event) VdcOperationCallback(org.ovirt.engine.ui.frontend.communication.VdcOperationCallback) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) IFrontendMultipleActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) EngineFault(org.ovirt.engine.core.common.errors.EngineFault) ActionType(org.ovirt.engine.core.common.action.ActionType) Map(java.util.Map) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) GwtEvent(com.google.gwt.event.shared.GwtEvent) HasHandlers(com.google.gwt.event.shared.HasHandlers) UserCallback(org.ovirt.engine.ui.frontend.communication.UserCallback) FrontendMultipleQueryAsyncResult(org.ovirt.engine.ui.uicompat.FrontendMultipleQueryAsyncResult) LinkedList(java.util.LinkedList) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) EventBus(com.google.gwt.event.shared.EventBus) AsyncOperationCompleteEvent(org.ovirt.engine.ui.frontend.communication.AsyncOperationCompleteEvent) Collection(java.util.Collection) AsyncOperationStartedEvent(org.ovirt.engine.ui.frontend.communication.AsyncOperationStartedEvent) VdcOperationManager(org.ovirt.engine.ui.frontend.communication.VdcOperationManager) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) RefreshActiveModelEvent(org.ovirt.engine.ui.frontend.communication.RefreshActiveModelEvent) Scheduler(com.google.gwt.core.client.Scheduler) List(java.util.List) StatusCodeException(com.google.gwt.user.client.rpc.StatusCodeException) VdcOperationCallbackList(org.ovirt.engine.ui.frontend.communication.VdcOperationCallbackList) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants) Collections(java.util.Collections) IFrontendMultipleQueryAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendMultipleQueryAsyncCallback) ActionType(org.ovirt.engine.core.common.action.ActionType) VdcOperation(org.ovirt.engine.ui.frontend.communication.VdcOperation) ArrayList(java.util.ArrayList) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) FrontendMultipleActionAsyncResult(org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult) VdcOperationCallbackList(org.ovirt.engine.ui.frontend.communication.VdcOperationCallbackList) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) VdcOperationCallbackList(org.ovirt.engine.ui.frontend.communication.VdcOperationCallbackList)

Example 2 with FrontendMultipleActionAsyncResult

use of org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult in project ovirt-engine by oVirt.

the class DataCenterGuideModel method onSelectHost.

public void onSelectHost() {
    MoveHost model = (MoveHost) getWindow();
    if (model.getProgress() != null) {
        return;
    }
    if (!model.validate()) {
        return;
    }
    model.setSelectedHosts(new ArrayList<MoveHostData>());
    for (MoveHostData a : model.getItems()) {
        if (a.getIsSelected()) {
            model.getSelectedHosts().add(a);
        }
    }
    Cluster cluster = model.getCluster().getSelectedItem();
    final List<ActionParametersBase> parameterList = new ArrayList<>();
    for (MoveHostData hostData : model.getSelectedHosts()) {
        VDS host = hostData.getEntity();
        // Try to change host's cluster as neccessary.
        if (host.getClusterId() != null && !host.getClusterId().equals(cluster.getId())) {
            parameterList.add(new ChangeVDSClusterParameters(cluster.getId(), host.getId()));
        }
    }
    model.startProgress();
    Frontend.getInstance().runMultipleAction(ActionType.ChangeVDSCluster, parameterList, new IFrontendMultipleActionAsyncCallback() {

        @Override
        public void executed(FrontendMultipleActionAsyncResult result) {
            final DataCenterGuideModel dataCenterGuideModel = (DataCenterGuideModel) result.getState();
            List<MoveHostData> hosts = ((MoveHost) dataCenterGuideModel.getWindow()).getSelectedHosts();
            List<ActionReturnValue> retVals = result.getReturnValue();
            final List<ActionParametersBase> activateVdsParameterList = new ArrayList<>();
            if (retVals != null && hosts.size() == retVals.size()) {
                int i = 0;
                for (MoveHostData selectedHostData : hosts) {
                    VDS selectedHost = selectedHostData.getEntity();
                    if (selectedHost.getStatus() == VDSStatus.PendingApproval && retVals.get(i) != null && retVals.get(i).getSucceeded()) {
                        Frontend.getInstance().runAction(ActionType.ApproveVds, new ApproveVdsParameters(selectedHost.getId()), null, this);
                    } else if (selectedHostData.getActivateHost()) {
                        activateVdsParameterList.add(new VdsActionParameters(selectedHostData.getEntity().getId()));
                    }
                    i++;
                }
            }
            if (activateVdsParameterList.isEmpty()) {
                dataCenterGuideModel.getWindow().stopProgress();
                dataCenterGuideModel.cancel();
                dataCenterGuideModel.postAction();
            } else {
                final String searchString = getVdsSearchString((MoveHost) dataCenterGuideModel.getWindow());
                Timer timer = new Timer() {

                    public void run() {
                        checkVdsClusterChangeSucceeded(searchString, parameterList, activateVdsParameterList);
                    }
                };
                timer.schedule(2000);
            }
        }
    }, this);
}
Also used : IFrontendMultipleActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback) MoveHost(org.ovirt.engine.ui.uicommonweb.models.hosts.MoveHost) VDS(org.ovirt.engine.core.common.businessentities.VDS) ArrayList(java.util.ArrayList) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) ApproveVdsParameters(org.ovirt.engine.core.common.action.hostdeploy.ApproveVdsParameters) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) FrontendMultipleActionAsyncResult(org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult) Timer(com.google.gwt.user.client.Timer) ChangeVDSClusterParameters(org.ovirt.engine.core.common.action.ChangeVDSClusterParameters) VdsActionParameters(org.ovirt.engine.core.common.action.VdsActionParameters) AddVdsActionParameters(org.ovirt.engine.core.common.action.hostdeploy.AddVdsActionParameters) MoveHostData(org.ovirt.engine.ui.uicommonweb.models.hosts.MoveHostData) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with FrontendMultipleActionAsyncResult

use of org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult in project ovirt-engine by oVirt.

the class UiVdcMultipleActionTest method executeCallbacks.

private void executeCallbacks(boolean success, ActionFlowState flowState, List<IFrontendMultipleActionAsyncCallback> callbacks, boolean waitForResult) {
    Collections.shuffle(callbacks);
    for (IFrontendMultipleActionAsyncCallback callback : callbacks) {
        assertNotAllDone(flowState);
        ActionReturnValue result = new ActionReturnValue();
        result.setValid(waitForResult || success);
        result.setSucceeded(waitForResult && success);
        callback.executed(new FrontendMultipleActionAsyncResult(ACTION_TYPE, null, Collections.singletonList(result)));
    }
}
Also used : IFrontendMultipleActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback) FrontendMultipleActionAsyncResult(org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue)

Aggregations

FrontendMultipleActionAsyncResult (org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult)3 IFrontendMultipleActionAsyncCallback (org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)2 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)2 Scheduler (com.google.gwt.core.client.Scheduler)1 EventBus (com.google.gwt.event.shared.EventBus)1 GwtEvent (com.google.gwt.event.shared.GwtEvent)1 HasHandlers (com.google.gwt.event.shared.HasHandlers)1 Timer (com.google.gwt.user.client.Timer)1 StatusCodeException (com.google.gwt.user.client.rpc.StatusCodeException)1 Inject (com.google.inject.Inject)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1