ofri masad has uploaded a new change for review.

Change subject: engine: Prevent move to empty quota (#845070)
......................................................................

engine: Prevent move to empty quota (#845070)

https://bugzilla.redhat.com/845070

When a user was moving a disk to a domain with no defined quota (when
quota is enforced) he got an uninformative error.

The ability to move to a domain with no quota was blocked using the
validate mechanism. When quota is enforced the user must choose a domain
with a defined quota.

The massage was fixed to inform the user that the selected domain has no
assigned quota (in case a quota is available but not relevant).

Change-Id: Iab0baf6f583f06197286a976211bada4a0654cb2
Signed-off-by: Ofri Masad <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/MoveOrCopyDiskModel.java
A 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/validation/SelectedQuotaValidation.java
M 
frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
M 
frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
9 files changed, 56 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/36/7736/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
index cc17f98..1014c85 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
@@ -381,8 +381,10 @@
     @Override
     public boolean validateAndSetQuota() {
         if (ImageOperation.Move.equals(getParameters().getOperation())) {
-            getQuotaManager().decreaseStorageQuota(getStoragePool(),
-                    getSourceStorageQuotaListParameters());
+            // If source and destination are in the same quota - do nothing 
and return true
+            if (getImage().getQuotaId() != null && 
getImage().getQuotaId().equals(getQuotaId())) {
+                return true;
+            }
             if (getQuotaManager()
                     .validateAndSetStorageQuota(getStoragePool(),
                             getDestQuotaListParameters(),
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java
index 3fd096f..816ae53 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java
@@ -251,7 +251,7 @@
                                 }
                             }
                             if (!hasStorageId) {
-                                
canDoActionMessages.add(VdcBllMessages.ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID.toString());
+                                
canDoActionMessages.add(VdcBllMessages.ACTION_TYPE_FAILED_NO_QUOTA_SET_FOR_DOMAIN.toString());
                                 return false;
                             }
                         }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
index 16cc0f2..c1259ba 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
@@ -594,6 +594,7 @@
     VM_CANNOT_RUN_FROM_DISK_WITHOUT_PLUGGED_DISK,
     ACTION_TYPE_FAILED_QUOTA_NOT_EXIST,
     ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID,
+    ACTION_TYPE_FAILED_NO_QUOTA_SET_FOR_DOMAIN,
     ACTION_TYPE_FAILED_QUOTA_IS_NO_LONGER_AVAILABLE_IN_SYSTEM,
     ACTION_TYPE_FAILED_QUOTA_LIMIT_IS_SPECIFIC_AND_GENERAL,
     ACTION_TYPE_FAILED_QUOTA_LIMIT_IS_NOT_SPECIFIC_OR_GENERAL,
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
index 9e72b70..93f88db 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -626,6 +626,7 @@
 # Quota messages.
 ACTION_TYPE_FAILED_QUOTA_NOT_EXIST=Cannot ${action} ${type}. Quota doesn't 
exist.
 ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID=Cannot ${action} ${type}. Quota is not 
valid.
+ACTION_TYPE_FAILED_NO_QUOTA_SET_FOR_DOMAIN=Cannot ${action} ${type}. No quota 
is defined for the selected domain. Assign a quota to the domain or select a 
different domain.
 ACTION_TYPE_FAILED_QUOTA_IS_NO_LONGER_AVAILABLE_IN_SYSTEM=Cannot ${action} 
${type}. The quota associated with VM ${VmName} is no longer available. This 
may be a result of an import or snapshot restoring actions. Please reassign a 
quota to this VM.
 ACTION_TYPE_FAILED_QUOTA_LIMIT_IS_SPECIFIC_AND_GENERAL=Cannot ${action} 
${type}. Limitation can not be configured as specific and general in the same 
Quota. Please choose whether the limitation should be enforced on the Data 
Center or on specific storage.
 ACTION_TYPE_FAILED_QUOTA_LIMIT_IS_NOT_SPECIFIC_OR_GENERAL=Cannot ${action} 
${type}. Quota limitation must be configured specific or general.
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/MoveOrCopyDiskModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/MoveOrCopyDiskModel.java
index 748915c..c35df4c 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/MoveOrCopyDiskModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/MoveOrCopyDiskModel.java
@@ -6,6 +6,7 @@
 import org.ovirt.engine.core.common.action.MoveOrCopyImageGroupParameters;
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
 import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum;
 import org.ovirt.engine.core.common.businessentities.Disk;
 import org.ovirt.engine.core.common.businessentities.Disk.DiskStorageType;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
@@ -26,6 +27,8 @@
 import org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider;
 import org.ovirt.engine.ui.uicommonweb.models.ListModel;
 import org.ovirt.engine.ui.uicommonweb.models.vms.DiskModel;
+import org.ovirt.engine.ui.uicommonweb.validation.IValidation;
+import org.ovirt.engine.ui.uicommonweb.validation.SelectedQuotaValidation;
 import org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult;
 import org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback;
 
@@ -244,6 +247,10 @@
             return;
         }
 
+        if (!this.Validate()) {
+            return;
+        }
+
         boolean iSingleStorageDomain = (Boolean) 
getIsSingleStorageDomain().getEntity();
 
         ArrayList<VdcActionParametersBase> parameters = new 
ArrayList<VdcActionParametersBase>();
@@ -327,4 +334,20 @@
             OnCopy();
         }
     }
+
+    public boolean Validate() {
+        if (getQuotaEnforcementType() == QuotaEnforcementTypeEnum.DISABLED
+                || getQuotaEnforcementType() == 
QuotaEnforcementTypeEnum.SOFT_ENFORCEMENT) {
+            return true;
+        }
+
+        boolean isValid = true;
+        for (DiskModel diskModel : getDisks()) {
+            diskModel.getQuota().ValidateSelectedItem(new IValidation[]{new 
SelectedQuotaValidation()});
+            isValid &= diskModel.getQuota().getIsValid();
+        }
+
+        return isValid;
+    }
 }
+
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/validation/SelectedQuotaValidation.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/validation/SelectedQuotaValidation.java
new file mode 100644
index 0000000..a8599b3
--- /dev/null
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/validation/SelectedQuotaValidation.java
@@ -0,0 +1,21 @@
+package org.ovirt.engine.ui.uicommonweb.validation;
+
+import org.ovirt.engine.core.compat.StringHelper;
+import org.ovirt.engine.ui.uicompat.ConstantsManager;
+
+@SuppressWarnings("unused")
+public class SelectedQuotaValidation implements IValidation
+{
+    @Override
+    public ValidationResult Validate(Object value)
+    {
+        ValidationResult result = new ValidationResult();
+
+        if (value == null || (value instanceof String && 
StringHelper.isNullOrEmpty((String) value))) {
+            result.setSuccess(false);
+            
result.getReasons().add(ConstantsManager.getInstance().getConstants().quotaMustBeSelectedInvalidReason());
+        }
+
+        return result;
+    }
+}
diff --git 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java
 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java
index dedb76a..5596b7a 100644
--- 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java
+++ 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java
@@ -909,6 +909,9 @@
     @DefaultStringValue("This field can't be empty.")
     String thisFieldCantBeEmptyInvalidReason();
 
+    @DefaultStringValue("Quota enforcement activated. Quota must be defined 
for the selected storage domain")
+    String quotaMustBeSelectedInvalidReason();
+
     @DefaultStringValue("New Role")
     String newRoleTitle();
 
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index 0ee1b6d..8391f66 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -621,6 +621,7 @@
 # Quota messages.
 ACTION_TYPE_FAILED_QUOTA_NOT_EXIST=Cannot ${action} ${type}. Quota doesn't 
exist.
 ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID=Cannot ${action} ${type}. Quota is not 
valid.
+ACTION_TYPE_FAILED_NO_QUOTA_SET_FOR_DOMAIN=Cannot ${action} ${type}. No quota 
is defined for the selected domain. Assign a quota to the domain or select a 
different domain.
 ACTION_TYPE_FAILED_QUOTA_IS_NO_LONGER_AVAILABLE_IN_SYSTEM=Cannot ${action} 
${type}. The quota associated with VM ${VmName} is no longer available. This 
may be a result of an import or snapshot restoring actions. Please reassign a 
quota to this VM.
 ACTION_TYPE_FAILED_QUOTA_LIMIT_IS_SPECIFIC_AND_GENERAL=Cannot ${action} 
${type}. Limitation can not be configured as specific and general in the same 
Quota. Please choose whether the limitation should be enforced on the Data 
Center or on specific storage.
 ACTION_TYPE_FAILED_QUOTA_LIMIT_IS_NOT_SPECIFIC_OR_GENERAL=Cannot ${action} 
${type}. Quota limitation must be configured specific or general.
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index aed23c1..a9a33f0 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -620,6 +620,7 @@
 # Quota messages.
 ACTION_TYPE_FAILED_QUOTA_NOT_EXIST=Cannot ${action} ${type}. Quota doesn't 
exist.
 ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID=Cannot ${action} ${type}. Quota is not 
valid.
+ACTION_TYPE_FAILED_NO_QUOTA_SET_FOR_DOMAIN=Cannot ${action} ${type}. No quota 
is defined for the selected domain. Assign a quota to the domain or select a 
different domain.
 ACTION_TYPE_FAILED_QUOTA_IS_NO_LONGER_AVAILABLE_IN_SYSTEM=Cannot ${action} 
${type}. The quota associated with VM ${VmName} is no longer available. This 
may be a result of an import or snapshot restoring actions. Please reassign a 
quota to this VM.
 ACTION_TYPE_FAILED_QUOTA_LIMIT_IS_SPECIFIC_AND_GENERAL=Cannot ${action} 
${type}. Limitation can not be configured as specific and general in the same 
Quota. Please choose whether the limitation should be enforced on the Data 
Center or on specific storage.
 ACTION_TYPE_FAILED_QUOTA_LIMIT_IS_NOT_SPECIFIC_OR_GENERAL=Cannot ${action} 
${type}. Quota limitation must be configured specific or general.


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

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

Reply via email to