use of org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult in project ovirt-engine by oVirt.
the class Frontend method runMultipleAction.
/**
* Run multiple actions using the same {@code ActionType}.
* @param actionType The action type.
* @param parameters The list of parameters.
* @param isRunOnlyIfAllValidationPass A flag to only run the actions if all can be completed.
* @param callback The callback to call when the operation completes.
* @param state The state.
* @param showErrorDialog Should we show an error dialog?
* @param waitForResult a flag to return the result after running the whole action and not just the can do actions.
*/
public void runMultipleAction(final ActionType actionType, final List<ActionParametersBase> parameters, final boolean isRunOnlyIfAllValidationPass, final IFrontendMultipleActionAsyncCallback callback, final Object state, final boolean showErrorDialog, final boolean waitForResult) {
VdcOperationCallbackList<VdcOperation<ActionType, ActionParametersBase>, List<ActionReturnValue>> multiCallback = new VdcOperationCallbackList<VdcOperation<ActionType, ActionParametersBase>, List<ActionReturnValue>>() {
@Override
public void onSuccess(final List<VdcOperation<ActionType, ActionParametersBase>> operationList, final List<ActionReturnValue> resultObject) {
// $NON-NLS-1$
logger.finer("Frontend: successfully executed runMultipleAction, determining result!");
List<ActionReturnValue> failed = resultObject.stream().filter(v -> !v.isValid()).collect(Collectors.toList());
if (showErrorDialog && !failed.isEmpty()) {
translateErrors(failed);
getEventsHandler().runMultipleActionFailed(actionType, failed);
}
if (callback != null) {
callback.executed(new FrontendMultipleActionAsyncResult(actionType, parameters, resultObject, state));
}
fireAsyncActionSucceededEvent(state);
}
@Override
public void onFailure(final List<VdcOperation<ActionType, ActionParametersBase>> operation, final Throwable caught) {
if (ignoreFailure(caught)) {
return;
}
// $NON-NLS-1$
logger.log(Level.SEVERE, "Failed to execute runMultipleAction: " + caught, caught);
failureEventHandler(caught);
if (callback != null) {
callback.executed(new FrontendMultipleActionAsyncResult(actionType, parameters, null, state));
}
fireAsyncActionFailedEvent(state);
}
};
List<VdcOperation<?, ?>> operationList = parameters.stream().map(p -> new VdcOperation<>(actionType, p, !waitForResult, multiCallback, isRunOnlyIfAllValidationPass)).collect(Collectors.toList());
fireAsyncOperationStartedEvent(state);
if (operationList.isEmpty()) {
// it ourselves.
if (scheduler == null) {
scheduler = Scheduler.get();
}
scheduler.scheduleDeferred(() -> {
if (callback != null) {
List<ActionReturnValue> emptyResult = new ArrayList<>();
callback.executed(new FrontendMultipleActionAsyncResult(actionType, parameters, emptyResult, state));
}
});
} else {
getOperationManager().addOperationList(operationList);
}
}
use of org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult in project ovirt-engine by oVirt.
the class DataCenterGuideModel method onSelectHost.
public void onSelectHost() {
MoveHost model = (MoveHost) getWindow();
if (model.getProgress() != null) {
return;
}
if (!model.validate()) {
return;
}
model.setSelectedHosts(new ArrayList<MoveHostData>());
for (MoveHostData a : model.getItems()) {
if (a.getIsSelected()) {
model.getSelectedHosts().add(a);
}
}
Cluster cluster = model.getCluster().getSelectedItem();
final List<ActionParametersBase> parameterList = new ArrayList<>();
for (MoveHostData hostData : model.getSelectedHosts()) {
VDS host = hostData.getEntity();
// Try to change host's cluster as neccessary.
if (host.getClusterId() != null && !host.getClusterId().equals(cluster.getId())) {
parameterList.add(new ChangeVDSClusterParameters(cluster.getId(), host.getId()));
}
}
model.startProgress();
Frontend.getInstance().runMultipleAction(ActionType.ChangeVDSCluster, parameterList, new IFrontendMultipleActionAsyncCallback() {
@Override
public void executed(FrontendMultipleActionAsyncResult result) {
final DataCenterGuideModel dataCenterGuideModel = (DataCenterGuideModel) result.getState();
List<MoveHostData> hosts = ((MoveHost) dataCenterGuideModel.getWindow()).getSelectedHosts();
List<ActionReturnValue> retVals = result.getReturnValue();
final List<ActionParametersBase> activateVdsParameterList = new ArrayList<>();
if (retVals != null && hosts.size() == retVals.size()) {
int i = 0;
for (MoveHostData selectedHostData : hosts) {
VDS selectedHost = selectedHostData.getEntity();
if (selectedHost.getStatus() == VDSStatus.PendingApproval && retVals.get(i) != null && retVals.get(i).getSucceeded()) {
Frontend.getInstance().runAction(ActionType.ApproveVds, new ApproveVdsParameters(selectedHost.getId()), null, this);
} else if (selectedHostData.getActivateHost()) {
activateVdsParameterList.add(new VdsActionParameters(selectedHostData.getEntity().getId()));
}
i++;
}
}
if (activateVdsParameterList.isEmpty()) {
dataCenterGuideModel.getWindow().stopProgress();
dataCenterGuideModel.cancel();
dataCenterGuideModel.postAction();
} else {
final String searchString = getVdsSearchString((MoveHost) dataCenterGuideModel.getWindow());
Timer timer = new Timer() {
public void run() {
checkVdsClusterChangeSucceeded(searchString, parameterList, activateVdsParameterList);
}
};
timer.schedule(2000);
}
}
}, this);
}
use of org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult in project ovirt-engine by oVirt.
the class UiVdcMultipleActionTest method executeCallbacks.
private void executeCallbacks(boolean success, ActionFlowState flowState, List<IFrontendMultipleActionAsyncCallback> callbacks, boolean waitForResult) {
Collections.shuffle(callbacks);
for (IFrontendMultipleActionAsyncCallback callback : callbacks) {
assertNotAllDone(flowState);
ActionReturnValue result = new ActionReturnValue();
result.setValid(waitForResult || success);
result.setSucceeded(waitForResult && success);
callback.executed(new FrontendMultipleActionAsyncResult(ACTION_TYPE, null, Collections.singletonList(result)));
}
}
Aggregations