use of org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback in project ovirt-engine by oVirt.
the class DataCenterGuideModel method saveNewNfsStorage.
public void saveNewNfsStorage() {
StorageModel model = (StorageModel) getWindow();
NfsStorageModel nfsModel = (NfsStorageModel) model.getCurrentStorageItem();
VDS host = model.getHost().getSelectedItem();
hostId = host.getId();
// Create storage connection.
StorageServerConnections tempVar = new StorageServerConnections();
tempVar.setConnection(path);
tempVar.setStorageType(nfsModel.getType());
connection = tempVar;
ArrayList<ActionType> actionTypes = new ArrayList<>();
ArrayList<ActionParametersBase> parameters = new ArrayList<>();
actionTypes.add(ActionType.AddStorageServerConnection);
actionTypes.add(ActionType.AddNFSStorageDomain);
actionTypes.add(ActionType.DisconnectStorageServerConnection);
parameters.add(new StorageServerConnectionParametersBase(connection, host.getId(), false));
StorageDomainManagementParameter tempVar2 = new StorageDomainManagementParameter(storageDomain);
tempVar2.setVdsId(host.getId());
parameters.add(tempVar2);
parameters.add(new StorageServerConnectionParametersBase(connection, host.getId(), false));
IFrontendActionAsyncCallback callback1 = result -> {
DataCenterGuideModel dataCenterGuideModel = (DataCenterGuideModel) result.getState();
ActionReturnValue actionReturnValue = result.getReturnValue();
dataCenterGuideModel.storageDomain.setStorage((String) actionReturnValue.getActionReturnValue());
};
IFrontendActionAsyncCallback callback2 = result -> {
DataCenterGuideModel dataCenterGuideModel = (DataCenterGuideModel) result.getState();
ActionReturnValue actionReturnValue = result.getReturnValue();
dataCenterGuideModel.storageId = actionReturnValue.getActionReturnValue();
};
IFrontendActionAsyncCallback callback3 = result -> {
DataCenterGuideModel dataCenterGuideModel = (DataCenterGuideModel) result.getState();
StorageModel storageModel = (StorageModel) dataCenterGuideModel.getWindow();
// Attach storage to data center as neccessary.
StoragePool dataCenter = storageModel.getDataCenter().getSelectedItem();
if (!dataCenter.getId().equals(StorageModel.UnassignedDataCenterId)) {
dataCenterGuideModel.attachStorageToDataCenter(dataCenterGuideModel.storageId, dataCenter.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, callback3 })), failureCallback, this);
}
use of org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback in project ovirt-engine by oVirt.
the class DataCenterGuideModel method saveNewLocalStorage.
public void saveNewLocalStorage() {
StorageModel model = (StorageModel) getWindow();
LocalStorageModel localModel = (LocalStorageModel) model.getCurrentStorageItem();
VDS host = model.getHost().getSelectedItem();
hostId = host.getId();
// Create storage connection.
StorageServerConnections tempVar = new StorageServerConnections();
tempVar.setConnection(path);
tempVar.setStorageType(localModel.getType());
connection = tempVar;
ArrayList<ActionType> actionTypes = new ArrayList<>();
ArrayList<ActionParametersBase> parameters = new ArrayList<>();
actionTypes.add(ActionType.AddStorageServerConnection);
actionTypes.add(ActionType.AddLocalStorageDomain);
parameters.add(new StorageServerConnectionParametersBase(connection, host.getId(), false));
StorageDomainManagementParameter tempVar2 = new StorageDomainManagementParameter(storageDomain);
tempVar2.setVdsId(host.getId());
parameters.add(tempVar2);
IFrontendActionAsyncCallback callback1 = result -> {
DataCenterGuideModel dataCenterGuideModel = (DataCenterGuideModel) result.getState();
dataCenterGuideModel.removeConnection = true;
ActionReturnValue actionReturnValue = result.getReturnValue();
dataCenterGuideModel.storageDomain.setStorage((String) actionReturnValue.getActionReturnValue());
};
IFrontendActionAsyncCallback callback2 = result -> {
DataCenterGuideModel dataCenterGuideModel = (DataCenterGuideModel) result.getState();
dataCenterGuideModel.removeConnection = false;
dataCenterGuideModel.onFinish(dataCenterGuideModel.context, true, dataCenterGuideModel.storageModel);
};
IFrontendActionAsyncCallback failureCallback = result -> {
DataCenterGuideModel dataCenterGuideModel = (DataCenterGuideModel) result.getState();
if (dataCenterGuideModel.removeConnection) {
dataCenterGuideModel.cleanConnection(dataCenterGuideModel.connection, dataCenterGuideModel.hostId);
dataCenterGuideModel.removeConnection = false;
}
dataCenterGuideModel.onFinish(dataCenterGuideModel.context, false, dataCenterGuideModel.storageModel);
};
Frontend.getInstance().runMultipleActions(actionTypes, parameters, new ArrayList<>(Arrays.asList(new IFrontendActionAsyncCallback[] { callback1, callback2 })), failureCallback, this);
}
use of org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback in project ovirt-engine by oVirt.
the class VolumeGeoRepListModel method updateConfig.
private void updateConfig() {
ArrayList<ActionType> actionTypes = new ArrayList<>();
ArrayList<ActionParametersBase> parameters = new ArrayList<>();
List<IFrontendActionAsyncCallback> callbacks;
final GlusterVolumeGeoReplicationSessionConfigModel geoRepConfigModel = (GlusterVolumeGeoReplicationSessionConfigModel) getWindow();
LinkedHashMap<String, String> oldConfigs = geoRepConfigModel.getConfigs();
geoRepConfigModel.startProgress();
for (EntityModel<Pair<Boolean, GlusterGeoRepSessionConfiguration>> newConfigEntity : geoRepConfigModel.getConfigsModel().getItems()) {
Pair<Boolean, GlusterGeoRepSessionConfiguration> newConfigPair = newConfigEntity.getEntity();
GlusterGeoRepSessionConfiguration newConfig = newConfigPair.getSecond();
boolean isOldConfigNull = oldConfigs.get(newConfig.getKey()) == null;
boolean isNewConfigNull = newConfig.getValue() == null;
if (!isNewConfigNull && !newConfig.getValue().isEmpty() && (isOldConfigNull || !newConfig.getValue().equals(oldConfigs.get(newConfig.getKey())))) {
actionTypes.add(ActionType.SetGeoRepConfig);
parameters.add(geoRepConfigModel.formGeoRepConfigParameters(newConfig));
}
if (newConfigPair.getFirst()) {
actionTypes.add(ActionType.ResetDefaultGeoRepConfig);
parameters.add(geoRepConfigModel.formGeoRepConfigParameters(newConfig));
}
}
int numberOfConfigUpdates = parameters.size();
if (numberOfConfigUpdates == 0) {
geoRepConfigModel.stopProgress();
closeWindow();
return;
}
callbacks = new ArrayList<>(Collections.nCopies(numberOfConfigUpdates, (IFrontendActionAsyncCallback) null));
callbacks.set(numberOfConfigUpdates - 1, result -> {
geoRepConfigModel.stopProgress();
closeWindow();
});
// Failure call back. Update the config list just to reflect any new changes and default error msg
// dialog is thrown.
Frontend.getInstance().runMultipleActions(actionTypes, parameters, callbacks, result -> fetchConfigForSession(geoRepConfigModel.getGeoRepSession()), this);
}
use of org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback in project ovirt-engine by oVirt.
the class NewDiskModel method store.
@Override
public void store(IFrontendActionAsyncCallback callback) {
if (getProgress() != null || !validate()) {
return;
}
startProgress();
AddDiskParameters parameters = new AddDiskParameters(getDiskVmElement(), getDisk());
parameters.setPlugDiskToVm(getIsPlugged().getEntity());
if (getDiskStorageType().getEntity() == DiskStorageType.IMAGE || getDiskStorageType().getEntity() == DiskStorageType.CINDER) {
StorageDomain storageDomain = getStorageDomain().getSelectedItem();
parameters.setStorageDomainId(storageDomain.getId());
}
IFrontendActionAsyncCallback onFinished = callback != null ? callback : result -> {
NewDiskModel diskModel = (NewDiskModel) result.getState();
diskModel.stopProgress();
diskModel.cancel();
postSave();
};
Frontend.getInstance().runAction(ActionType.AddDisk, parameters, onFinished, this);
}
use of org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback in project ovirt-engine by oVirt.
the class FrontendActionTest method testrunMultipleActions_1action.
/**
* Run the following test case.
* <ol>
* <li>Run MultipleActions with a single action, that is successful.</li>
* <li>Check to make sure the callback is called</li>
* </ol>
*/
@Test
public void testrunMultipleActions_1action() {
List<ActionType> actionTypes = new ArrayList<>();
actionTypes.add(ActionType.AddDisk);
List<ActionParametersBase> testParameters = new ArrayList<>();
testParameters.add(new ActionParametersBase());
List<IFrontendActionAsyncCallback> callbacks = new ArrayList<>();
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());
// $NON-NLS-1$
assertEquals("List size should be 0", 0, actionTypes.size());
// $NON-NLS-1$
assertEquals("List size should be 0", 0, testParameters.size());
// $NON-NLS-1$
assertEquals("List size should be 0", 0, callbacks.size());
verifyAsyncActionStartedAndSucceeded();
}
Aggregations