use of org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback 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);
}
use of org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback in project ovirt-engine by oVirt.
the class Frontend method runMultipleActions.
private void runMultipleActions(final List<ActionType> actionTypes, final List<ActionParametersBase> parameters, final List<IFrontendActionAsyncCallback> callbacks, final IFrontendActionAsyncCallback failureCallback, final Object state, final boolean aggregateErrors, final List<ActionType> failedActions, final List<ActionReturnValue> failedReturnValues) {
if (actionTypes.isEmpty() || parameters.isEmpty() || callbacks.isEmpty()) {
if (aggregateErrors && failedReturnValues != null && !failedReturnValues.isEmpty()) {
getEventsHandler().runMultipleActionsFailed(failedActions, failedReturnValues);
}
return;
}
runAction(actionTypes.get(0), parameters.get(0), result -> {
ActionReturnValue returnValue = result.getReturnValue();
boolean success = returnValue != null && returnValue.getSucceeded();
if (success || failureCallback == null) {
IFrontendActionAsyncCallback callback = callbacks.get(0);
if (callback != null) {
callback.executed(result);
}
if (aggregateErrors && returnValue != null && (!returnValue.isValid() || !returnValue.getSucceeded())) {
failedActions.add(actionTypes.get(0));
failedReturnValues.add(returnValue);
}
actionTypes.remove(0);
parameters.remove(0);
callbacks.remove(0);
runMultipleActions(actionTypes, parameters, callbacks, failureCallback, state, aggregateErrors, failedActions, failedReturnValues);
} else {
failureCallback.executed(result);
}
}, state, !aggregateErrors || failureCallback != null);
}
use of org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback in project ovirt-engine by oVirt.
the class UiVdcAction method internalRunAction.
@Override
void internalRunAction() {
IFrontendActionAsyncCallback callback = createCallback();
Frontend.getInstance().runAction(actionType, parameters, callback, showErrorDialogOnFirstFailure);
}
use of org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback 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);
}
}
use of org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback in project ovirt-engine by oVirt.
the class StorageListModel 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 storageConnection = new StorageServerConnections();
storageConnection.setConnection(path);
storageConnection.setStorageType(nfsModel.getType());
if (isConnectionOverriden()) {
storageConnection.setNfsVersion((NfsVersion) ((EntityModel) nfsModel.getVersion().getSelectedItem()).getEntity());
storageConnection.setNfsRetrans(nfsModel.getRetransmissions().asConvertible().nullableShort());
storageConnection.setNfsTimeo(nfsModel.getTimeout().asConvertible().nullableShort());
storageConnection.setMountOptions(nfsModel.getMountOptions().getEntity());
}
connection = storageConnection;
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());
StoragePool dataCenter = model.getDataCenter().getSelectedItem();
tempVar2.setStoragePoolId(dataCenter.getId());
parameters.add(tempVar2);
parameters.add(new StorageServerConnectionParametersBase(connection, host.getId(), false));
IFrontendActionAsyncCallback callback1 = result -> {
StorageListModel storageListModel = (StorageListModel) result.getState();
ActionReturnValue actionReturnValue = result.getReturnValue();
storageListModel.storageDomain.setStorage((String) actionReturnValue.getActionReturnValue());
storageListModel.connection.setId((String) actionReturnValue.getActionReturnValue());
};
IFrontendActionAsyncCallback callback2 = result -> {
StorageListModel storageListModel = (StorageListModel) result.getState();
ActionReturnValue actionReturnValue = result.getReturnValue();
storageListModel.storageId = actionReturnValue.getActionReturnValue();
};
IFrontendActionAsyncCallback callback3 = result -> {
StorageListModel storageListModel = (StorageListModel) result.getState();
StorageModel storageModel = (StorageModel) storageListModel.getWindow();
// Attach storage to data center as necessary.
StoragePool dataCenter1 = storageModel.getDataCenter().getSelectedItem();
if (!dataCenter1.getId().equals(StorageModel.UnassignedDataCenterId)) {
storageListModel.attachStorageToDataCenter(storageListModel.storageId, dataCenter1.getId(), storageModel.getActivateDomain().getEntity());
}
storageListModel.onFinish(storageListModel.context, true, storageListModel.storageModel);
};
IFrontendActionAsyncCallback failureCallback = result -> {
StorageListModel storageListModel = (StorageListModel) result.getState();
storageListModel.cleanConnection(storageListModel.connection, storageListModel.hostId);
storageListModel.onFinish(storageListModel.context, false, storageListModel.storageModel);
};
Frontend.getInstance().runMultipleActions(actionTypes, parameters, new ArrayList<>(Arrays.asList(callback1, callback2, callback3)), failureCallback, this);
}
Aggregations