public void postOnSaveInternalChangeCluster(UpdateVdsActionParameters parameters, boolean approveInitiated) { Frontend.getInstance().runAction(ActionType.UpdateVds, parameters, result -> { Object[] array = (Object[]) result.getState(); HostListModel<Void> localModel = (HostListModel<Void>) array[0]; boolean localApproveInitiated = (Boolean) array[1]; localModel.postOnSaveInternal(result.getReturnValue(), localApproveInitiated); }, new Object[] { this, approveInitiated }); }
@Override public void onFailure(final VdcOperation<ActionType, ActionParametersBase> operation, final Throwable caught) { if (ignoreFailure(caught)) { return; } logger.log(Level.SEVERE, "Failed to execute runAction: " + caught, caught); //$NON-NLS-1$ failureEventHandler(caught); FrontendActionAsyncResult f = new FrontendActionAsyncResult(actionType, parameters, null, state); if (callback != null) { callback.executed(f); } fireAsyncActionFailedEvent(state); } });
/** * Run the following test case. * <ol> * <li>Run a single action</li> * <li>Return success.</li> * <li>Check to make sure the callback is called</li> * </ol> */ @Test public void testrunActionImpl_success() { ActionParametersBase testParameters = new ActionParametersBase(); frontend.runAction(ActionType.AddDisk, testParameters, mockActionCallback, testState, false); verify(mockService).runAction(eq(ActionType.AddDisk), eq(testParameters), callbackAction.capture()); ActionReturnValue returnValue = new ActionReturnValue(); callbackAction.getValue().onSuccess(returnValue); verify(mockActionCallback).executed(callbackParam.capture()); assertEquals(testParameters, callbackParam.getValue().getParameters(), "Parameters should match"); //$NON-NLS-1$ assertEquals(returnValue, callbackParam.getValue().getReturnValue(), "Result should match"); //$NON-NLS-1$ assertEquals(testState, callbackParam.getValue().getState(), "States should match"); //$NON-NLS-1$ assertEquals(ActionType.AddDisk, callbackParam.getValue().getActionType(), "Action type should match"); //$NON-NLS-1$ verifyAsyncActionStartedAndSucceeded(); }
public FrontendActionAsyncResult(ActionType actionType, ActionParametersBase parameters, ActionReturnValue returnValue, Object state) { setActionType(actionType); setParameters(parameters); setReturnValue(returnValue); setState(state); } }
public FrontendActionAsyncResult(ActionType actionType, ActionParametersBase parameters, ActionReturnValue returnValue) { setActionType(actionType); setParameters(parameters); setReturnValue(returnValue); }
private IFrontendActionAsyncCallback addNetworkCallback() { return result -> postAddNetwork(result.getReturnValue()); }
private void updateStorageDomain() { Frontend.getInstance().runAction(ActionType.UpdateStorageDomain, new StorageDomainManagementParameter(this.storageDomain), result -> { StorageListModel storageListModel = (StorageListModel) result.getState(); storageListModel.onFinish(storageListModel.context, true, storageListModel.storageModel); }, this); }
@Override public void executed(FrontendActionAsyncResult result) { ActionReturnValue returnValue = result.getReturnValue(); if (returnValue != null && returnValue.getSucceeded()) { sucessCount++; // we wait until all subscribed events have been removed and then // invoke the AddEventSubscription action if (toAddList.size() > 0 && sucessCount == toRemoveList.size()) { Frontend.getInstance().runMultipleAction(ActionType.AddEventSubscription, toAddList); } } } }
@Override protected void doExecute() { super.doExecute(); ArrayList<ActionParametersBase> parameters = getParameters(); if (parameters.isEmpty()) { cancel(); return; } Frontend.getInstance().runMultipleActions(getActionType(), parameters, result -> { MoveDiskModel localModel = (MoveDiskModel) result.getState(); localModel.cancel(); }, this); }
public void postImportFileStorage(TaskContext context, boolean isSucceeded, IStorageModel model, String message) { Frontend.getInstance().runAction(ActionType.DisconnectStorageServerConnection, new StorageServerConnectionParametersBase(fileConnection, hostId, false), result -> { ActionReturnValue returnValue = result.getReturnValue(); boolean success = returnValue != null && returnValue.getSucceeded(); if (success) { fileConnection = null; } Object[] array = (Object[]) result.getState(); onFinish((TaskContext) array[0], (Boolean) array[1], (IStorageModel) array[2], (String) array[3]); }, new Object[] {context, isSucceeded, model, message}); }
/** * Run the following test case. * <ol> * <li>Run a single action</li> * <li>Force a failure with an HTTP status code = 404</li> * <li>Check to make sure the failure event is fired</li> * <li>Check to make sure the callback is called</li> * </ol> */ @Test public void testrunActionImpl_404_failure() { ActionParametersBase testParameters = new ActionParametersBase(); frontend.runAction(ActionType.AddDisk, testParameters, mockActionCallback, testState, false); verify(mockService).runAction(eq(ActionType.AddDisk), eq(testParameters), callbackAction.capture()); StatusCodeException exception = new StatusCodeException(HttpServletResponse.SC_NOT_FOUND, "404 status code"); //$NON-NLS-1$ callbackAction.getValue().onFailure(exception); verify(mockFrontendFailureEvent).raise(eq(Frontend.class), (FrontendFailureEventArgs) any()); verify(mockActionCallback).executed(callbackParam.capture()); assertEquals(testParameters, callbackParam.getValue().getParameters(), "Parameters should match"); //$NON-NLS-1$ assertNull(callbackParam.getValue().getReturnValue(), "Result should be null"); //$NON-NLS-1$ assertEquals(testState, callbackParam.getValue().getState(), "States should match"); //$NON-NLS-1$ assertEquals(ActionType.AddDisk, callbackParam.getValue().getActionType(), "Action type should match"); //$NON-NLS-1$ verifyAsyncActionStartedAndFailed(); }
private void initiateResumeUploadStartTransfer(FrontendActionAsyncResult result) { if (result.getReturnValue() != null && result.getReturnValue().getSucceeded()) { ImageTransfer rv = result.getReturnValue().getActionReturnValue(); setCommandId(rv.getId()); setBytesSent(rv.getBytesSent()); setBytesEndOffset(rv.getBytesTotal()); startStatusPolling(); } else { setProgressStr(messages.uploadImageFailedToResumeMessage(result.getReturnValue().getDescription())); } }
@Override public void executed(FrontendActionAsyncResult result) { StorageListModel storageListModel = (StorageListModel) result.getState(); StorageModel storageModel = (StorageModel) getWindow(); SanStorageModelBase sanStorageModelBase = (SanStorageModelBase) storageModel.getCurrentStorageItem();
/** * 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); }
public void importFileStorageInit() { if (fileConnection != null) { // Clean nfs connection Frontend.getInstance().runAction(ActionType.DisconnectStorageServerConnection, new StorageServerConnectionParametersBase(fileConnection, hostId, false), result -> { StorageListModel storageListModel = (StorageListModel) result.getState(); ActionReturnValue returnVal = result.getReturnValue(); boolean success = returnVal != null && returnVal.getSucceeded(); if (success) { storageListModel.fileConnection = null; } storageListModel.importFileStoragePostInit(); }, this); } else { importFileStoragePostInit(); } }
/** * Run the following test case. * <ol> * <li>Run a single action</li> * <li>Return logical failure, validate=false.</li> * <li>Check to make sure the failure event is fired</li> * <li>Check to make sure the callback is called</li> * </ol> * Test just the handler method. */ @Test public void testHandleActionResult() { ActionParametersBase testParameters = new ActionParametersBase(); ActionReturnValue returnValue = new ActionReturnValue(); returnValue.setValid(false); // Yes this is the default, but to make sure. frontend.handleActionResult(ActionType.AddDisk, testParameters, returnValue, mockActionCallback, testState, false); verify(mockActionCallback).executed(callbackParam.capture()); assertEquals(testParameters, callbackParam.getValue().getParameters(), "Parameters should match"); //$NON-NLS-1$ assertEquals(returnValue, callbackParam.getValue().getReturnValue(), "Result should match"); //$NON-NLS-1$ assertEquals(testState, callbackParam.getValue().getState(), "States should match"); //$NON-NLS-1$ assertEquals(ActionType.AddDisk, callbackParam.getValue().getActionType(), "Action type should match"); //$NON-NLS-1$ }
private void onSave() { if (getProgress() != null || !validate()) { return; } startProgress(); MacPool macPool = flush(); Frontend.getInstance().runAction(actionType, new MacPoolParameters(macPool), result -> { stopProgress(); if (result.getReturnValue() != null && result.getReturnValue().getSucceeded()) { onActionSucceeded((Guid) result.getReturnValue().getActionReturnValue()); } }); }
private void addBond() { AddIscsiBondParameters params = new AddIscsiBondParameters(createIscsiBond()); startProgress(); Frontend.getInstance().runAction(ActionType.AddIscsiBond, params, result -> { IscsiBondModel model = (IscsiBondModel) result.getState(); model.stopProgress(); model.cancel(); }, this); }
@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)); } }
public void onAddCluster() { ClusterModel model = (ClusterModel) getWindow(); Cluster cluster = ClusterListModel.buildCluster(model, new Cluster()); if (model.getProgress() != null) { return; } model.startProgress(); Frontend.getInstance().runAction(ActionType.AddCluster, new ManagementNetworkOnClusterOperationParameters(cluster), result -> { DataCenterGuideModel localModel = (DataCenterGuideModel) result.getState(); localModel.postOnAddCluster(result.getReturnValue()); }, this); }