Search in sources :

Example 1 with FrontendActionAsyncResult

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

Example 2 with FrontendActionAsyncResult

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);
}
Also used : FrontendActionAsyncResult(org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult) ActionType(org.ovirt.engine.core.common.action.ActionType) VdcOperation(org.ovirt.engine.ui.frontend.communication.VdcOperation) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Example 3 with FrontendActionAsyncResult

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);
}
Also used : FrontendActionAsyncResult(org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback)

Example 4 with FrontendActionAsyncResult

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);
    }
}
Also used : FrontendActionAsyncResult(org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult) EngineFault(org.ovirt.engine.core.common.errors.EngineFault)

Example 5 with FrontendActionAsyncResult

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);
    }
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) FrontendActionAsyncResult(org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult) Set(java.util.Set) HashSet(java.util.HashSet) StorageDomainManagementParameter(org.ovirt.engine.core.common.action.StorageDomainManagementParameter) ReduceSANStorageDomainDevicesCommandParameters(org.ovirt.engine.core.common.action.ReduceSANStorageDomainDevicesCommandParameters) ExtendSANStorageDomainParameters(org.ovirt.engine.core.common.action.ExtendSANStorageDomainParameters) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) HashSet(java.util.HashSet)

Aggregations

FrontendActionAsyncResult (org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult)6 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)3 IFrontendActionAsyncCallback (org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback)3 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)1 ActionType (org.ovirt.engine.core.common.action.ActionType)1 ExtendSANStorageDomainParameters (org.ovirt.engine.core.common.action.ExtendSANStorageDomainParameters)1 ReduceSANStorageDomainDevicesCommandParameters (org.ovirt.engine.core.common.action.ReduceSANStorageDomainDevicesCommandParameters)1 StorageDomainManagementParameter (org.ovirt.engine.core.common.action.StorageDomainManagementParameter)1 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)1 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)1 EngineFault (org.ovirt.engine.core.common.errors.EngineFault)1 VdcOperation (org.ovirt.engine.ui.frontend.communication.VdcOperation)1 UnitVmModelNetworkAsyncCallback (org.ovirt.engine.ui.uicommonweb.models.vms.UnitVmModelNetworkAsyncCallback)1