use of org.ovirt.engine.core.common.action.ActionType 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.core.common.action.ActionType 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);
}
use of org.ovirt.engine.core.common.action.ActionType in project ovirt-engine by oVirt.
the class StorageListModel 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 -> {
StorageListModel storageListModel = (StorageListModel) result.getState();
storageListModel.removeConnection = true;
ActionReturnValue actionReturnValue = result.getReturnValue();
storageListModel.storageDomain.setStorage((String) actionReturnValue.getActionReturnValue());
storageListModel.connection.setId((String) actionReturnValue.getActionReturnValue());
};
IFrontendActionAsyncCallback callback2 = result -> {
StorageListModel storageListModel = (StorageListModel) result.getState();
storageListModel.removeConnection = false;
storageListModel.onFinish(storageListModel.context, true, storageListModel.storageModel);
};
IFrontendActionAsyncCallback failureCallback = result -> {
StorageListModel storageListModel = (StorageListModel) result.getState();
if (storageListModel.removeConnection) {
storageListModel.cleanConnection(storageListModel.connection, storageListModel.hostId);
storageListModel.removeConnection = false;
}
storageListModel.onFinish(storageListModel.context, false, storageListModel.storageModel);
};
Frontend.getInstance().runMultipleActions(actionTypes, parameters, new ArrayList<>(Arrays.asList(new IFrontendActionAsyncCallback[] { callback1, callback2 })), failureCallback, this);
}
use of org.ovirt.engine.core.common.action.ActionType in project ovirt-engine by oVirt.
the class StorageListModel method saveNewPosixStorage.
public 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());
if (posixModel instanceof GlusterStorageModel) {
GlusterStorageModel glusterModel = (GlusterStorageModel) posixModel;
Guid glusterVolId = null;
if (glusterModel.getLinkGlusterVolume().getEntity()) {
glusterVolId = ((GlusterStorageModel) posixModel).getGlusterVolumes().getSelectedItem() != null ? ((GlusterStorageModel) posixModel).getGlusterVolumes().getSelectedItem().getId() : null;
}
connection.setGlusterVolumeId(glusterVolId);
}
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 -> {
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();
// Attach storage to data center as necessary.
StorageModel storageModel = (StorageModel) storageListModel.getWindow();
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(new IFrontendActionAsyncCallback[] { callback1, callback2 })), failureCallback, this);
}
use of org.ovirt.engine.core.common.action.ActionType in project ovirt-engine by oVirt.
the class RegisterTemplateModel method onSave.
protected void onSave() {
List<ActionParametersBase> parameters = prepareActionParameters();
ActionType actionType = ActionType.ImportVmTemplateFromConfiguration;
onSave(actionType, parameters);
}
Aggregations