Tal Nisan has uploaded a new change for review.

Change subject: webadmin: Block adding of mixed domain to a pool if not 
supported by version
......................................................................

webadmin: Block adding of mixed domain to a pool if not supported by version

When adding a new storage domain via webadmin where the compatibility
version does not support mixed storage types we might encounter a situation
where the domain is created and the attach to the data center is failing
and the setup is left with an unattached domain, to prevent that we now
disallow addition from a storage type (block/file) to a data center that
does not support mixed types and already have attached domains of another
storage type (e.g. adding an iSCSI storage domain to a v3.3 data center
V3.3 with an NFS domain attached will be prohibited)

Change-Id: Ib31884e6fd5a7868e9bb21c9566bcd2e445de52a
Bug-Url: https://bugzilla.redhat.com/1085395
Signed-off-by: Tal Nisan <[email protected]>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/NewEditStorageModelBehavior.java
3 files changed, 75 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/39/27139/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java
index 3e97178..6b16e49 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java
@@ -116,6 +116,7 @@
     UserSessionTimeOutInterval(ConfigAuthType.User),
     DefaultMaximumMigrationDowntime,
     IscsiMultipathingSupported;
+    MixedDomainTypesInDataCenter;
 
     public static enum ConfigAuthType {
         Admin,
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java
index f42e9f4..b183b36 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java
@@ -202,7 +202,7 @@
 
 
     // cached os's support for display types (given compatibility version)
-    private static Map<Integer, Map<Version, List<DisplayType>>> displayTypes;
+           private static Map<Integer, Map<Version, List<DisplayType>>> 
displayTypes;
 
     public static String getDefaultConfigurationVersion() {
         return _defaultConfigurationVersion;
@@ -3525,6 +3525,10 @@
         
Frontend.getInstance().runQuery(VdcQueryType.GetNumberOfActiveVmsInVdsGroupByVdsGroupId,
 new IdQueryParameters(clusterId), aQuery);
     }
 
+    public static boolean isMixedStorageDomainsSupported(Version version) {
+        return (Boolean) 
getConfigValuePreConverted(ConfigurationValues.MixedDomainTypesInDataCenter, 
version.toString());
+    }
+
     private static ArrayList<VDSGroup> 
getClusterByServiceList(ArrayList<VDSGroup> list,
             boolean supportsVirtService,
             boolean supportsGlusterService) {
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/NewEditStorageModelBehavior.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/NewEditStorageModelBehavior.java
index a8b88f3..e0b9e65 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/NewEditStorageModelBehavior.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/NewEditStorageModelBehavior.java
@@ -1,9 +1,16 @@
 package org.ovirt.engine.ui.uicommonweb.models.storage;
 
+import java.util.List;
+
 import org.ovirt.engine.core.common.businessentities.StorageDomainType;
 import org.ovirt.engine.core.common.businessentities.StoragePool;
 import org.ovirt.engine.core.common.businessentities.StoragePoolStatus;
+import org.ovirt.engine.core.common.businessentities.StorageType;
+import org.ovirt.engine.core.common.queries.IdQueryParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryReturnValue;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
 import org.ovirt.engine.ui.frontend.AsyncQuery;
+import org.ovirt.engine.ui.frontend.Frontend;
 import org.ovirt.engine.ui.frontend.INewAsyncCallback;
 import org.ovirt.engine.ui.uicommonweb.Linq;
 import org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider;
@@ -65,46 +72,83 @@
     }
 
     public void postUpdateItemsAvailability(IStorageModel item, boolean 
isNoExportOrIsoStorageAttached) {
-        StoragePool dataCenter = (StoragePool) 
getModel().getDataCenter().getSelectedItem();
-        Model model = (Model) item;
-
-        boolean isItemSelectable = isItemSelectable(item, dataCenter, 
isNoExportOrIsoStorageAttached);
-        model.setIsSelectable(isItemSelectable);
-
-        onStorageModelUpdated(item);
+        StoragePool dataCenter = getModel().getDataCenter().getSelectedItem();
+        checkCanItemBeSelected(item, dataCenter, 
isNoExportOrIsoStorageAttached);
     }
 
-    private boolean isItemSelectable(IStorageModel item, StoragePool 
dataCenter, boolean isNoExportOrIsoStorageAttached) {
+    private void checkCanItemBeSelected(final IStorageModel item, StoragePool 
dataCenter, boolean isNoExportOrIsoStorageAttached) {
         boolean isExistingStorage = getModel().getStorage() != null &&
                 item.getType() == getModel().getStorage().getStorageType();
 
+        // If we are in edit mode then the type of the entity edited should 
appear in the selection
         if (isExistingStorage) {
-            return true;
+            updateItemSelectability(item, true);
+            return;
         }
 
+        // Local types should not be selectable for shared data centers and 
vice versa
         if (isLocalStorage(item) != dataCenter.isLocal()) {
-            return false;
+            updateItemSelectability(item, false);
+            return;
         }
 
         boolean isNoneDataCenter = 
dataCenter.getId().equals(StorageModel.UnassignedDataCenterId);
         boolean isDataDomain = item.getRole() == StorageDomainType.Data;
 
+        // For 'None' data center we allow all data types and no ISO/Export, 
no reason for further checks
         if (isNoneDataCenter) {
-            // 'None' Data Center can create only Data Storage Domain
-            return isDataDomain;
-        } else {
-            boolean isExportDomain = item.getRole() == 
StorageDomainType.ImportExport;
-            boolean canAttachExportDomain = isNoExportOrIsoStorageAttached &&
-                    dataCenter.getStatus() != StoragePoolStatus.Uninitialized;
-
-            boolean isIsoDomain = item.getRole() == StorageDomainType.ISO;
-            boolean canAttachIsoDomain = isNoExportOrIsoStorageAttached &&
-                    dataCenter.getStatus() != StoragePoolStatus.Uninitialized;
-
-            return isExportDomain && canAttachExportDomain ||
-                    isIsoDomain && canAttachIsoDomain ||
-                    isDataDomain;
-
+            updateItemSelectability(item, isDataDomain);
+            return;
         }
+
+        boolean isExportDomain = item.getRole() == 
StorageDomainType.ImportExport;
+        boolean canAttachExportDomain = isNoExportOrIsoStorageAttached &&
+                dataCenter.getStatus() != StoragePoolStatus.Uninitialized;
+
+        boolean isIsoDomain = item.getRole() == StorageDomainType.ISO;
+        boolean canAttachIsoDomain = isNoExportOrIsoStorageAttached &&
+                dataCenter.getStatus() != StoragePoolStatus.Uninitialized;
+
+        if ((isExportDomain && canAttachExportDomain) || (isIsoDomain && 
canAttachIsoDomain)) {
+            updateItemSelectability(item, true);
+            return;
+        }
+
+        if (isDataDomain) {
+            if (isLocalStorage(item)) {
+                updateItemSelectability(item, true);
+                return;
+            }
+
+            if 
(AsyncDataProvider.isMixedStorageDomainsSupported(dataCenter.getcompatibility_version()))
 {
+                updateItemSelectability(item, true);
+                return;
+            } else {
+                IdQueryParameters params = new 
IdQueryParameters(dataCenter.getId());
+                
Frontend.getInstance().runQuery(VdcQueryType.GetStorageTypesInPoolByPoolId, 
params,
+                        new AsyncQuery(this, new INewAsyncCallback() {
+                            @Override
+                            public void onSuccess(Object model, Object 
ReturnValue) {
+                                List<StorageType> storageTypes = 
((VdcQueryReturnValue) ReturnValue).getReturnValue();
+                                for (StorageType storageType : storageTypes) {
+                                    if (storageType.isBlockDomain() != 
item.getType().isBlockDomain()) {
+                                        updateItemSelectability(item, false);
+                                        return;
+                                    }
+                                }
+                                updateItemSelectability(item, true);
+                                return;
+                            }
+                        }));
+                return;
+            }
+        }
+        updateItemSelectability(item, false);
+    }
+
+    private void updateItemSelectability(IStorageModel item, boolean 
isSelectable) {
+        Model model = (Model) item;
+        model.setIsSelectable(isSelectable);
+        onStorageModelUpdated(item);
     }
 }


-- 
To view, visit http://gerrit.ovirt.org/27139
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib31884e6fd5a7868e9bb21c9566bcd2e445de52a
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.4
Gerrit-Owner: Tal Nisan <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to