Search in sources :

Example 1 with IFrontendActionAsyncCallback

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

the class FrontendActionTest method testrunMultipleActions_multipleaction_success_all.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run MultipleActions with multiple actions, that are successful.</li>
 *   <li>Check to make sure the callback is called</li>
 * </ol>
 */
@Test
public void testrunMultipleActions_multipleaction_success_all() {
    List<ActionType> actionTypes = new ArrayList<>();
    actionTypes.add(ActionType.AddDisk);
    actionTypes.add(ActionType.AddBricksToGlusterVolume);
    List<ActionParametersBase> testParameters = new ArrayList<>();
    testParameters.add(new ActionParametersBase());
    testParameters.add(new ActionParametersBase());
    List<IFrontendActionAsyncCallback> callbacks = new ArrayList<>();
    callbacks.add(mockActionCallback);
    callbacks.add(mockActionCallback);
    frontend.runMultipleActions(actionTypes, testParameters, callbacks, mockActionFailureCallback, testState);
    verify(mockService).runAction(eq(ActionType.AddDisk), eq(testParameters.get(0)), callbackAction.capture());
    ActionReturnValue returnValue = new ActionReturnValue();
    returnValue.setValid(true);
    returnValue.setSucceeded(true);
    callbackAction.getValue().onSuccess(returnValue);
    verify(mockActionCallback).executed(callbackParam.capture());
    assertEquals(returnValue, callbackParam.getValue().getReturnValue());
    // Second call to runAction, the size of the parameters should have decreased
    verify(mockService).runAction(eq(ActionType.AddBricksToGlusterVolume), eq(testParameters.get(0)), callbackAction.capture());
    returnValue = new ActionReturnValue();
    returnValue.setValid(true);
    returnValue.setSucceeded(true);
    callbackAction.getValue().onSuccess(returnValue);
    verify(mockActionCallback, times(2)).executed(callbackParam.capture());
    assertEquals(returnValue, callbackParam.getValue().getReturnValue());
    verifyAsyncActionStartedAndSucceeded();
}
Also used : ActionType(org.ovirt.engine.core.common.action.ActionType) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) ArrayList(java.util.ArrayList) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) Test(org.junit.Test)

Example 2 with IFrontendActionAsyncCallback

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

the class FrontendActionTest method testrunMultipleActions_multipleaction_success_first_failure_second_success.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run MultipleActions with multiple actions, first failure, and second success.</li>
 *   <li>Check to make sure the failure callback is called for the first action</li>
 *   <li>Make sure the success callback is never called for the second action</li>
 * </ol>
 */
@Test
public void testrunMultipleActions_multipleaction_success_first_failure_second_success() {
    List<ActionType> actionTypes = new ArrayList<>();
    actionTypes.add(ActionType.AddDisk);
    actionTypes.add(ActionType.AddBricksToGlusterVolume);
    List<ActionParametersBase> testParameters = new ArrayList<>();
    testParameters.add(new ActionParametersBase());
    testParameters.add(new ActionParametersBase());
    List<IFrontendActionAsyncCallback> callbacks = new ArrayList<>();
    callbacks.add(mockActionCallback);
    callbacks.add(mockActionCallback);
    frontend.runMultipleActions(actionTypes, testParameters, callbacks, mockActionFailureCallback, testState);
    verify(mockService).runAction(eq(ActionType.AddDisk), eq(testParameters.get(0)), callbackAction.capture());
    ActionReturnValue returnValue = new ActionReturnValue();
    returnValue.setValid(false);
    returnValue.setSucceeded(false);
    callbackAction.getValue().onSuccess(returnValue);
    verify(mockActionFailureCallback).executed(callbackParam.capture());
    assertEquals(returnValue, callbackParam.getValue().getReturnValue());
    // Second call to runAction, the size of the parameters should have decreased
    verify(mockService, never()).runAction(eq(ActionType.AddBricksToGlusterVolume), eq(testParameters.get(0)), callbackAction.capture());
    verifyAsyncActionStartedAndSucceeded();
}
Also used : ActionType(org.ovirt.engine.core.common.action.ActionType) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) ArrayList(java.util.ArrayList) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) Test(org.junit.Test)

Example 3 with IFrontendActionAsyncCallback

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

the class ClusterGlusterHookListModel method onResolveConflicts.

/*
     * If there are multiple types of conflicts found for a hook and the user choose to resolve them. The conflicts will
     * be resolved in the following order 1)Content Conflict, 2)Status Conflict, 3)Missing Conflict
     *
     * If any conflict resolution is failed the next one will not be executed
     */
private void onResolveConflicts() {
    final GlusterHookResolveConflictsModel resolveConflictsModel = (GlusterHookResolveConflictsModel) getWindow();
    if (resolveConflictsModel == null) {
        return;
    }
    if (!resolveConflictsModel.isAnyResolveActionSelected()) {
        resolveConflictsModel.setMessage(ConstantsManager.getInstance().getConstants().noResolveActionSelectedGlusterHook());
        return;
    }
    resolveConflictsModel.startProgress();
    GlusterHookEntity hookEntity = resolveConflictsModel.getGlusterHookEntity();
    ArrayList<ActionType> actionTypes = new ArrayList<>();
    ArrayList<ActionParametersBase> parameters = new ArrayList<>();
    ArrayList<IFrontendActionAsyncCallback> callbacks = new ArrayList<>();
    if (resolveConflictsModel.getResolveContentConflict().getEntity()) {
        actionTypes.add(ActionType.UpdateGlusterHook);
        GlusterServerHook serverHook = resolveConflictsModel.getServerHooksList().getSelectedItem();
        Guid serverId = (serverHook == null) ? null : serverHook.getServerId();
        parameters.add(new GlusterHookManageParameters(hookEntity.getId(), serverId));
        IFrontendActionAsyncCallback callback = result -> {
            if (result.getReturnValue().getSucceeded()) {
                resolveConflictsModel.getResolveContentConflict().setEntity(Boolean.FALSE);
                resolveConflictsModel.getResolveContentConflict().setIsChangeable(Boolean.FALSE);
            }
        };
        callbacks.add(callback);
    }
    if (resolveConflictsModel.getResolveStatusConflict().getEntity()) {
        boolean isEnable = resolveConflictsModel.getResolveStatusConflictEnable().getEntity();
        actionTypes.add(isEnable ? ActionType.EnableGlusterHook : ActionType.DisableGlusterHook);
        parameters.add(new GlusterHookParameters(hookEntity.getId()));
        IFrontendActionAsyncCallback callback = result -> {
            if (result.getReturnValue().getSucceeded()) {
                resolveConflictsModel.getResolveStatusConflict().setEntity(Boolean.FALSE);
                resolveConflictsModel.getResolveStatusConflict().setIsChangeable(Boolean.FALSE);
            }
        };
        callbacks.add(callback);
    }
    if (resolveConflictsModel.getResolveMissingConflict().getEntity()) {
        boolean isAdd = resolveConflictsModel.getResolveMissingConflictCopy().getEntity();
        actionTypes.add(isAdd ? ActionType.AddGlusterHook : ActionType.RemoveGlusterHook);
        parameters.add(new GlusterHookManageParameters(hookEntity.getId()));
        IFrontendActionAsyncCallback callback = result -> {
            if (result.getReturnValue().getSucceeded()) {
                resolveConflictsModel.getResolveMissingConflict().setEntity(Boolean.FALSE);
                resolveConflictsModel.getResolveMissingConflict().setIsChangeable(Boolean.FALSE);
            }
        };
        callbacks.add(callback);
    }
    IFrontendActionAsyncCallback onFinishCallback = result -> {
        if (result.getReturnValue().getSucceeded()) {
            resolveConflictsModel.stopProgress();
            cancel();
            syncSearch();
        }
    };
    IFrontendActionAsyncCallback failureCallback = result -> resolveConflictsModel.stopProgress();
    // Replacing the last callback with onFinishCallback, as we just want to close the dialog and execute the search
    if (callbacks.size() > 0) {
        callbacks.remove(callbacks.size() - 1);
        callbacks.add(onFinishCallback);
        Frontend.getInstance().runMultipleActions(actionTypes, parameters, callbacks, failureCallback, null);
    }
}
Also used : GlusterHookManageParameters(org.ovirt.engine.core.common.action.gluster.GlusterHookManageParameters) GlusterHookEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookEntity) GlusterHookStatus(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookStatus) Guid(org.ovirt.engine.core.compat.Guid) GlusterHookContentType(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookContentType) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook) ApplicationMode(org.ovirt.engine.core.common.mode.ApplicationMode) SearchableListModel(org.ovirt.engine.ui.uicommonweb.models.SearchableListModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ActionType(org.ovirt.engine.core.common.action.ActionType) Frontend(org.ovirt.engine.ui.frontend.Frontend) List(java.util.List) GlusterHookParameters(org.ovirt.engine.core.common.action.gluster.GlusterHookParameters) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) GlusterClusterParameters(org.ovirt.engine.core.common.action.gluster.GlusterClusterParameters) GlusterHookParameters(org.ovirt.engine.core.common.action.gluster.GlusterHookParameters) ActionType(org.ovirt.engine.core.common.action.ActionType) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) GlusterHookManageParameters(org.ovirt.engine.core.common.action.gluster.GlusterHookManageParameters) GlusterHookEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookEntity) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook)

Example 4 with IFrontendActionAsyncCallback

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

the class BookmarkListModel method onRemove.

public void onRemove() {
    Bookmark selectedBookmark = (Bookmark) getSelectedItem();
    BookmarksParametersBase parameters = new BookmarksParametersBase(selectedBookmark.getId());
    IFrontendActionAsyncCallback async = result -> postOnSave(result.getReturnValue());
    getWindow().startProgress();
    Frontend.getInstance().runAction(ActionType.RemoveBookmark, parameters, async);
}
Also used : QueryType(org.ovirt.engine.core.common.queries.QueryType) Guid(org.ovirt.engine.core.compat.Guid) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) Event(org.ovirt.engine.ui.uicompat.Event) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) SearchableListModel(org.ovirt.engine.ui.uicommonweb.models.SearchableListModel) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) ArrayList(java.util.ArrayList) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) ActionType(org.ovirt.engine.core.common.action.ActionType) Frontend(org.ovirt.engine.ui.frontend.Frontend) BookmarksOperationParameters(org.ovirt.engine.core.common.action.BookmarksOperationParameters) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) BookmarksParametersBase(org.ovirt.engine.core.common.action.BookmarksParametersBase) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) Bookmark(org.ovirt.engine.core.common.businessentities.Bookmark) Serializable(java.io.Serializable) List(java.util.List) EventDefinition(org.ovirt.engine.ui.uicompat.EventDefinition) Comparator(java.util.Comparator) Collections(java.util.Collections) Bookmark(org.ovirt.engine.core.common.businessentities.Bookmark) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) BookmarksParametersBase(org.ovirt.engine.core.common.action.BookmarksParametersBase)

Example 5 with IFrontendActionAsyncCallback

use of org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback 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));
    }
}
Also used : FrontendActionAsyncResult(org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback)

Aggregations

IFrontendActionAsyncCallback (org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback)24 ArrayList (java.util.ArrayList)17 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)16 ActionType (org.ovirt.engine.core.common.action.ActionType)16 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)15 List (java.util.List)10 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)10 Guid (org.ovirt.engine.core.compat.Guid)10 Frontend (org.ovirt.engine.ui.frontend.Frontend)10 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)10 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)10 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)10 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)10 QueryType (org.ovirt.engine.core.common.queries.QueryType)9 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)9 HashSet (java.util.HashSet)8 Set (java.util.Set)8 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)8 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)8 StorageDomainManagementParameter (org.ovirt.engine.core.common.action.StorageDomainManagementParameter)7