Skip to content

Commit

Permalink
Correct Data Center for the "Upload Image" dialog
Browse files Browse the repository at this point in the history
Signed-off-by: Stepan Ermakov <sermakov@orionsoft.ru>

This PR fixes the following issue: incorrect Data Center is displayed when uploading a disk image from "Storage Domain Disks" UI.

Steps to reproduce:

    1. Create a Storage Domain at non-Default Data Center.
    2. Open the Storage -> Domains -> <The created Storage Domain> -> Disks page.
    3. Select the Upload -> Start menu item. The "Upload image" dialog is displayed.

Expected behavior:
    The Data Center filed is disabled and displays the name of the non-Default Data Center.
Current behavior:
    The Data Center field is disabled and display the name of the Default Data Center.

Fixed in the following way: when "Upload image" dialog is displayed then query the Storage Domain details with information about its Data Center and select the Storage Domain's Data Center in the "Data Center" field
  • Loading branch information
sermakov-orion committed May 16, 2024
1 parent af1e3c1 commit d5fba38
Showing 1 changed file with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package org.ovirt.engine.ui.uicommonweb.models.storage;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.logging.Logger;

import org.ovirt.engine.core.common.action.ActionParametersBase;
import org.ovirt.engine.core.common.action.ActionType;
import org.ovirt.engine.core.common.action.AddDiskParameters;
import org.ovirt.engine.core.common.action.TransferDiskImageParameters;
import org.ovirt.engine.core.common.action.TransferImageStatusParameters;
import org.ovirt.engine.core.common.businessentities.StorageDomain;
import org.ovirt.engine.core.common.businessentities.StorageFormatType;
import org.ovirt.engine.core.common.businessentities.StoragePool;
import org.ovirt.engine.core.common.businessentities.storage.Disk;
Expand All @@ -21,6 +22,9 @@
import org.ovirt.engine.core.common.businessentities.storage.TransferClientType;
import org.ovirt.engine.core.common.businessentities.storage.TransferType;
import org.ovirt.engine.core.common.businessentities.storage.VolumeFormat;
import org.ovirt.engine.core.common.queries.IdQueryParameters;
import org.ovirt.engine.core.common.queries.QueryReturnValue;
import org.ovirt.engine.core.common.queries.QueryType;
import org.ovirt.engine.core.compat.Guid;
import org.ovirt.engine.core.compat.StringHelper;
import org.ovirt.engine.ui.frontend.Frontend;
Expand All @@ -30,6 +34,7 @@
import org.ovirt.engine.ui.uicommonweb.help.HelpTag;
import org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel;
import org.ovirt.engine.ui.uicommonweb.models.EntityModel;
import org.ovirt.engine.ui.uicommonweb.models.ListModel;
import org.ovirt.engine.ui.uicommonweb.models.Model;
import org.ovirt.engine.ui.uicommonweb.models.vms.AbstractDiskModel;
import org.ovirt.engine.ui.uicommonweb.models.vms.NewDiskModel;
Expand Down Expand Up @@ -169,11 +174,30 @@ public void initialize() {

getDataCenter().setIsChangeable(isChangeable);
if (!isChangeable) {
// Set the selected item on the storage domains list.
AsyncDataProvider.getInstance().getStorageDomainById(
new AsyncQuery<>(storageDomain -> {
getStorageDomain().setItems(Collections.singletonList(storageDomain));
}), limitToStorageDomainId);
// Set the selected item on the storage domains and data centers lists.
Frontend.getInstance().runQuery(
QueryType.GetStorageDomainListById,
new IdQueryParameters(limitToStorageDomainId),
new AsyncQuery<QueryReturnValue>(returnValue -> {
ArrayList<StorageDomain> domains = returnValue.getReturnValue();
if (!domains.isEmpty()) {
StorageDomain storageDomain = domains.get(0);
// Set the selected item on the storage domains list.
List<StorageDomain> availableDomains = new ArrayList<>();
availableDomains.add(storageDomain);
getStorageDomain().setItems(availableDomains);
Guid dcId = storageDomain.getStoragePoolId();
if (!Guid.isNullOrEmpty(dcId)) {
// Set selected data center if the list of data centers is populated.
if (!selectDataCenter(dcId)) {
//If the data center is not there then need to listen to the data centers list
//change to update the selected data center.
getDataCenter().getItemsChangedEvent()
.addListener((ev, sender, args) -> selectDataCenter(dcId));
}
}
}
}));
}
getStorageDomain().setIsChangeable(isChangeable);
getStorageType().setIsChangeable(false);
Expand All @@ -196,6 +220,21 @@ public int getMinimumDiskSize() {
protected boolean performUpdateHosts() {
return true;
}

private boolean selectDataCenter(Guid dcId) {
ListModel<StoragePool> dcList = getDataCenter();
//Find a data center with the desired Id
Optional<StoragePool> dataCenter = dcList.getItems().stream()
.filter(dc -> dcId.equals(dc.getId())).findFirst();
if (dataCenter.isPresent()) {
//Activate this data center in the data center dropdown list
dcList.setSelectedItem(dataCenter.get());
return true;
}
//Since we populate data centers asynchronously, we may have a situation when the needed
//data center is still not there. So, need to wait...
return false;
}
});
} else {
setDiskModel(new ReadOnlyDiskModel() {
Expand Down

0 comments on commit d5fba38

Please sign in to comment.