use of org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback in project ovirt-engine by oVirt.
the class FrontendActionTest method testrunMultipleActions_multipleaction_success_first_success_second_failure.
/**
* Run the following test case.
* <ol>
* <li>Run MultipleActions with multiple actions, first success, and second failure.</li>
* <li>Check to make sure the success callback is called for the first action</li>
* <li>Check to make sure the failure callback is called for the second action</li>
* </ol>
*/
@Test
public void testrunMultipleActions_multipleaction_success_first_success_second_failure() {
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
verify(mockService).runAction(eq(ActionType.AddBricksToGlusterVolume), eq(testParameters.get(0)), callbackAction.capture());
returnValue = new ActionReturnValue();
returnValue.setValid(false);
returnValue.setSucceeded(false);
callbackAction.getValue().onSuccess(returnValue);
verify(mockActionFailureCallback).executed(callbackParam.capture());
assertEquals(returnValue, callbackParam.getValue().getReturnValue());
verifyAsyncActionStartedAndSucceeded();
}
use of org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback in project ovirt-engine by oVirt.
the class SanStorageModelBase method connectTargets.
private void connectTargets() {
VDS host = getContainer().getHost().getSelectedItem();
if (host == null) {
return;
}
ArrayList<ActionType> actionTypes = new ArrayList<>();
ArrayList<ActionParametersBase> parameters = new ArrayList<>();
ArrayList<IFrontendActionAsyncCallback> callbacks = new ArrayList<>();
final SanStorageModelBase sanStorageModel = this;
IFrontendActionAsyncCallback loginCallback = result -> sanStorageModel.postLogin(result.getReturnValue(), sanStorageModel);
for (int i = 0; i < targetsToConnect.size(); i++) {
SanTargetModel model = targetsToConnect.get(i);
StorageServerConnections connection = new StorageServerConnections();
connection.setStorageType(StorageType.ISCSI);
// $NON-NLS-1$
connection.setUserName(getUseUserAuth().getEntity() ? getUserName().getEntity() : "");
// $NON-NLS-1$
connection.setPassword(getUseUserAuth().getEntity() ? getPassword().getEntity() : "");
connection.setIqn(model.getName());
connection.setConnection(model.getAddress());
connection.setPort(String.valueOf(model.getPort()));
connection.setPortal(model.getPortal());
actionTypes.add(ActionType.ConnectStorageToVds);
parameters.add(new StorageServerConnectionParametersBase(connection, host.getId(), false));
callbacks.add(loginCallback);
}
Object target = getWidgetModel() != null ? getWidgetModel() : getContainer();
Frontend.getInstance().runMultipleActions(actionTypes, parameters, callbacks, null, target);
}
use of org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback in project ovirt-engine by oVirt.
the class EditDiskModel method store.
@Override
public void store(IFrontendActionAsyncCallback callback) {
if (getProgress() != null || !validate()) {
return;
}
startProgress();
VmDiskOperationParameterBase parameters = new VmDiskOperationParameterBase(getDiskVmElement(), getDisk());
IFrontendActionAsyncCallback onFinished = callback != null ? callback : result -> {
EditDiskModel diskModel = (EditDiskModel) result.getState();
diskModel.stopProgress();
diskModel.cancel();
};
Frontend.getInstance().runAction(ActionType.UpdateVmDisk, parameters, onFinished, this);
}
use of org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback in project ovirt-engine by oVirt.
the class DataCenterGuideModel method saveNewPosixStorage.
private void saveNewPosixStorage() {
StorageModel model = (StorageModel) getWindow();
PosixStorageModel posixModel = (PosixStorageModel) model.getCurrentStorageItem();
VDS host = model.getHost().getSelectedItem();
hostId = host.getId();
// Create storage connection.
StorageServerConnections connection = new StorageServerConnections();
connection.setConnection(path);
connection.setStorageType(posixModel.getType());
connection.setVfsType(posixModel.getVfsType().getEntity());
connection.setMountOptions(posixModel.getMountOptions().getEntity());
this.connection = connection;
ArrayList<ActionType> actionTypes = new ArrayList<>();
ArrayList<ActionParametersBase> parameters = new ArrayList<>();
actionTypes.add(ActionType.AddStorageServerConnection);
actionTypes.add(posixModel.getAddStorageDomainVdcAction());
parameters.add(new StorageServerConnectionParametersBase(this.connection, host.getId(), false));
StorageDomainManagementParameter parameter = new StorageDomainManagementParameter(storageDomain);
parameter.setVdsId(host.getId());
StoragePool dataCenter = model.getDataCenter().getSelectedItem();
parameter.setStoragePoolId(dataCenter.getId());
parameters.add(parameter);
IFrontendActionAsyncCallback callback1 = result -> {
DataCenterGuideModel dataCenterGuideModel = (DataCenterGuideModel) result.getState();
ActionReturnValue actionReturnValue = result.getReturnValue();
dataCenterGuideModel.storageDomain.setStorage((String) actionReturnValue.getActionReturnValue());
dataCenterGuideModel.connection.setId((String) actionReturnValue.getActionReturnValue());
};
IFrontendActionAsyncCallback callback2 = result -> {
DataCenterGuideModel dataCenterGuideModel = (DataCenterGuideModel) result.getState();
ActionReturnValue actionReturnValue = result.getReturnValue();
dataCenterGuideModel.storageId = actionReturnValue.getActionReturnValue();
// Attach storage to data center as necessary.
StorageModel storageModel = (StorageModel) dataCenterGuideModel.getWindow();
StoragePool selectedDataCenter = storageModel.getDataCenter().getSelectedItem();
if (!selectedDataCenter.getId().equals(StorageModel.UnassignedDataCenterId)) {
dataCenterGuideModel.attachStorageToDataCenter(dataCenterGuideModel.storageId, selectedDataCenter.getId());
}
dataCenterGuideModel.onFinish(dataCenterGuideModel.context, true, dataCenterGuideModel.storageModel);
};
IFrontendActionAsyncCallback failureCallback = result -> {
DataCenterGuideModel dataCenterGuideModel = (DataCenterGuideModel) result.getState();
dataCenterGuideModel.cleanConnection(dataCenterGuideModel.connection, dataCenterGuideModel.hostId);
dataCenterGuideModel.onFinish(dataCenterGuideModel.context, false, dataCenterGuideModel.storageModel);
};
Frontend.getInstance().runMultipleActions(actionTypes, parameters, new ArrayList<>(Arrays.asList(new IFrontendActionAsyncCallback[] { callback1, callback2 })), failureCallback, this);
}
Aggregations