use of org.ovirt.engine.core.common.action.ActionType in project ovirt-engine by oVirt.
the class AttachDiskModel method store.
@Override
public void store(IFrontendActionAsyncCallback callback) {
if (getProgress() != null || !validate()) {
return;
}
ArrayList<ActionType> actionTypes = new ArrayList<>();
ArrayList<ActionParametersBase> paramerterList = new ArrayList<>();
ArrayList<IFrontendActionAsyncCallback> callbacks = new ArrayList<>();
IFrontendActionAsyncCallback onFinishCallback = callback != null ? callback : result -> {
NewDiskModel diskModel = (NewDiskModel) result.getState();
diskModel.stopProgress();
diskModel.cancel();
};
List<EntityModel<DiskModel>> disksToAttach = getSelectedDisks();
for (int i = 0; i < disksToAttach.size(); i++) {
DiskModel disk = disksToAttach.get(i).getEntity();
/*
IDE disks can be activated only when the VM is down.
Other disks can be hot plugged.
*/
boolean activate = false;
if (getIsPlugged().getEntity()) {
activate = disk.getDiskInterface().getSelectedItem() == DiskInterface.IDE ? getVm().getStatus() == VMStatus.Down : true;
}
DiskVmElement dve = new DiskVmElement(disk.getDisk().getId(), getVm().getId());
dve.setBoot(disk.getIsBootable().getEntity());
dve.setDiskInterface(disk.getDiskInterface().getSelectedItem());
dve.setReadOnly(disk.isReadOnly());
AttachDetachVmDiskParameters parameters = new AttachDetachVmDiskParameters(dve, activate);
actionTypes.add(ActionType.AttachDiskToVm);
paramerterList.add(parameters);
callbacks.add(i == disksToAttach.size() - 1 ? onFinishCallback : null);
}
startProgress();
Frontend.getInstance().runMultipleActions(actionTypes, paramerterList, callbacks, null, this);
}
use of org.ovirt.engine.core.common.action.ActionType in project ovirt-engine by oVirt.
the class UserListModel method onAdd.
public void onAdd(final boolean closeWindow) {
AdElementListModel model = (AdElementListModel) getWindow();
if (model.getProgress() != null) {
return;
}
if (model.getSelectedItems() == null) {
cancel();
return;
}
List<EntityModel<DbUser>> selectedItems = new ArrayList<>();
for (EntityModel<DbUser> dbUserEntity : model.getItems()) {
if (dbUserEntity.getIsSelected()) {
selectedItems.add(dbUserEntity);
}
}
List<ActionType> actionsList = new ArrayList<>(selectedItems.size());
List<ActionParametersBase> parametersList = new ArrayList<>(selectedItems.size());
ActionParametersBase parameters = null;
for (EntityModel<DbUser> item : selectedItems) {
if (item.getEntity().isGroup()) {
actionsList.add(ActionType.AddGroup);
DbGroup grp = new DbGroup();
grp.setExternalId(item.getEntity().getExternalId());
grp.setName(item.getEntity().getFirstName());
grp.setNamespace(item.getEntity().getNamespace());
grp.setId(item.getEntity().getId());
grp.setDomain(item.getEntity().getDomain());
parameters = new AddGroupParameters(grp);
} else {
actionsList.add(ActionType.AddUser);
parameters = new AddUserParameters(item.getEntity());
}
parametersList.add(parameters);
}
model.startProgress();
IFrontendActionAsyncCallback lastCallback = result -> {
AdElementListModel localModel = (AdElementListModel) result.getState();
localModel.stopProgress();
// Refresh user list.
syncSearch();
if (closeWindow) {
cancel();
}
};
Collection<EntityModel<DbUser>> currentItems = model.getItems();
List<IFrontendActionAsyncCallback> callbacksList = new ArrayList<>(selectedItems.size());
for (EntityModel<DbUser> user : selectedItems) {
callbacksList.add(nopCallback);
currentItems.remove(user);
}
callbacksList.remove(callbacksList.size() - 1);
callbacksList.add(lastCallback);
// Refresh display
model.setItems(null);
model.setItems(currentItems);
Frontend.getInstance().runMultipleActions(actionsList, parametersList, callbacksList, lastCallback, model);
}
use of org.ovirt.engine.core.common.action.ActionType 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.core.common.action.ActionType 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.core.common.action.ActionType 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);
}
Aggregations