Gilad Chaplik has uploaded a new change for review.

Change subject: engine: Quota API engine fixups
......................................................................

engine: Quota API engine fixups

Since quota was added only via UI till now, some bugs were
masked and now smoked out:

- Set default values for quota grace and threshold (hard/soft
limits).
- Enable javax.validation annotations for Quata entity.
- Return quota UUID when creating quota (setActionReturnValue).
- Fix Error message.

Change-Id: I51a7e9430c7c494a1608578e1f50e27c0e8a79ad
Signed-off-by: Gilad Chaplik <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddQuotaCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateQuotaCommand.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddQuotaCommandTest.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/QuotaCRUDParameters.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.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
10 files changed, 57 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/03/39903/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddQuotaCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddQuotaCommand.java
index a371fa1..e91ec23 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddQuotaCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddQuotaCommand.java
@@ -12,7 +12,10 @@
 import org.ovirt.engine.core.common.businessentities.Quota;
 import org.ovirt.engine.core.common.businessentities.QuotaStorage;
 import org.ovirt.engine.core.common.businessentities.QuotaVdsGroup;
+import org.ovirt.engine.core.common.config.Config;
+import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.common.validation.group.CreateEntity;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.utils.transaction.TransactionMethod;
 import org.ovirt.engine.core.utils.transaction.TransactionSupport;
@@ -60,6 +63,7 @@
             copyQuotaPermissions();
         }
         getReturnValue().setSucceeded(true);
+        setActionReturnValue(getQuota().getId());
         return null;
     }
 
@@ -105,7 +109,25 @@
                 quotaVdsGroup.setQuotaVdsGroupId(Guid.newGuid());
             }
         }
+        setQuotaThresholdDefaults(quotaParameter);
         setQuota(quotaParameter);
+    }
+
+    // set defaults for hard and soft limits.
+    private void setQuotaThresholdDefaults(Quota quotaParameter) {
+        // TODO: 0 can be a valid value??
+        if (quotaParameter.getGraceStoragePercentage() == 0) {
+            quotaParameter.setGraceStoragePercentage(Config.<Integer> 
getValue(ConfigValues.QuotaGraceStorage));
+        }
+        if (quotaParameter.getGraceVdsGroupPercentage() == 0) {
+            quotaParameter.setGraceVdsGroupPercentage(Config.<Integer> 
getValue(ConfigValues.QuotaGraceVdsGroup));
+        }
+        if (quotaParameter.getThresholdStoragePercentage() == 0) {
+            quotaParameter.setThresholdStoragePercentage(Config.<Integer> 
getValue(ConfigValues.QuotaThresholdStorage));
+        }
+        if (quotaParameter.getThresholdVdsGroupPercentage() == 0) {
+            quotaParameter.setThresholdVdsGroupPercentage(Config.<Integer> 
getValue(ConfigValues.QuotaThresholdVdsGroup));
+        }
     }
 
     @Override
@@ -128,4 +150,10 @@
             
MultiLevelAdministrationHandler.addPermission(permissionsList.toArray(new 
Permission[permissionsList.size()]));
         }
     }
+
+    @Override
+    protected List<Class<?>> getValidationGroups() {
+        addValidationGroup(CreateEntity.class);
+        return super.getValidationGroups();
+    }
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateQuotaCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateQuotaCommand.java
index 69742b9..631883a 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateQuotaCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateQuotaCommand.java
@@ -12,6 +12,7 @@
 import org.ovirt.engine.core.common.businessentities.QuotaStorage;
 import org.ovirt.engine.core.common.businessentities.QuotaVdsGroup;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.common.validation.group.UpdateEntity;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase;
 import org.ovirt.engine.core.dao.QuotaDAO;
@@ -102,4 +103,10 @@
             auditLogDirector.log(logable, 
AuditLogType.QUOTA_STORAGE_RESIZE_LOWER_THEN_CONSUMPTION);
         }
     }
+
+    @Override
+    protected List<Class<?>> getValidationGroups() {
+        addValidationGroup(UpdateEntity.class);
+        return super.getValidationGroups();
+    }
 }
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddQuotaCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddQuotaCommandTest.java
index ee8b3f8..bb41914 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddQuotaCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddQuotaCommandTest.java
@@ -4,8 +4,10 @@
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
+import static org.ovirt.engine.core.utils.MockConfigRule.mockConfig;
 
 import org.junit.Before;
+import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
@@ -14,8 +16,10 @@
 import org.ovirt.engine.core.common.businessentities.Quota;
 import org.ovirt.engine.core.common.businessentities.QuotaStorage;
 import org.ovirt.engine.core.common.businessentities.QuotaVdsGroup;
+import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dao.QuotaDAO;
+import org.ovirt.engine.core.utils.MockConfigRule;
 
 @RunWith(MockitoJUnitRunner.class)
 public class AddQuotaCommandTest {
@@ -27,6 +31,14 @@
      */
     private AddQuotaCommand command;
 
+    @ClassRule
+    public static MockConfigRule mcr = new MockConfigRule(
+            mockConfig(ConfigValues.QuotaGraceStorage, 20),
+            mockConfig(ConfigValues.QuotaGraceVdsGroup, 20),
+            mockConfig(ConfigValues.QuotaThresholdStorage, 80),
+            mockConfig(ConfigValues.QuotaThresholdVdsGroup, 80)
+            );
+
     @Before
     public void testSetup() {
         mockQuotaDAO();
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/QuotaCRUDParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/QuotaCRUDParameters.java
index e0c14c4..2f82230 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/QuotaCRUDParameters.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/QuotaCRUDParameters.java
@@ -2,13 +2,17 @@
 
 import java.io.Serializable;
 
+import javax.validation.Valid;
+
 import org.ovirt.engine.core.common.businessentities.Quota;
 import org.ovirt.engine.core.compat.Guid;
 
 public class QuotaCRUDParameters extends StoragePoolParametersBase implements 
Serializable {
     private static final long serialVersionUID = -3821623510049174551L;
 
+    @Valid
     private Guid quotaId;
+    @Valid
     private Quota quota;
     private boolean copyPermissions;
 
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
index 8ac5b34..62b3696 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
@@ -881,6 +881,7 @@
     ACTION_TYPE_FAILED_QUOTA_STORAGE_LIMIT_EXCEEDED(ErrorType.CONFLICT),
     ACTION_TYPE_FAILED_QUOTA_VDS_GROUP_LIMIT_EXCEEDED(ErrorType.CONFLICT),
     USER_NOT_AUTHORIZED_TO_CONSUME_QUOTA(ErrorType.NO_PERMISSION),
+    ACTION_TYPE_FAILED_QUOTA_STORAGE_GLOBAL_OR_SPCECIFIC(ErrorType.CONFLICT),
     ACTION_TYPE_FAILED_NOT_A_VM_NETWORK(ErrorType.CONFLICT),
     ACTION_TYPE_FAILED_NETWORK_NOT_IN_CLUSTER(ErrorType.CONFLICT),
     
ACTION_TYPE_FAILED_INTERFACE_NETWORK_NOT_CONFIGURED(ErrorType.BAD_PARAMETERS),
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
index f858899..30c20d3 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
@@ -314,7 +314,7 @@
 
     // Quota
     GetQuotaByStoragePoolId,
-    GetQuotaByQuotaId,
+    GetQuotaByQuotaId(VdcQueryAuthType.User),
     GetQuotaVdsGroupByQuotaId,
     GetQuotaStorageByQuotaId,
     GetVmsRelatedToQuotaId,
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 9bf07b6..aea17b0 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -949,7 +949,7 @@
 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_SPECIFIC_AND_GENERAL=Cannot ${action} 
${type}. Limitation can not be configured as specific and general for the same 
Quota. Please choose whether the limitation should be enforced on the Data 
Center (global) or for specific storage domain or cluster.
 ACTION_TYPE_FAILED_QUOTA_LIMIT_IS_NOT_SPECIFIC_OR_GENERAL=Cannot ${action} 
${type}. Quota limitation must be configured specific or general.
 ACTION_TYPE_FAILED_QUOTA_NAME_RESERVED_FOR_DEFAULT=Cannot ${action} ${type}. 
The prefix DefaultQuota is reserved for the default quota.
 ACTION_TYPE_FAILED_QUOTA_CAN_NOT_HAVE_DEFAULT_INDICATION=Cannot ${action} 
${type}. Quota can not have default indication.
diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
index 2d1f427..2a9a60c 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
@@ -2544,7 +2544,7 @@
     @DefaultStringValue("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.")
     String ACTION_TYPE_FAILED_QUOTA_IS_NO_LONGER_AVAILABLE_IN_SYSTEM();
 
-    @DefaultStringValue("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.")
+    @DefaultStringValue("Cannot ${action} ${type}. Limitation can not be 
configured as specific and general for the same Quota. Please choose whether 
the limitation should be enforced on the Data Center (global) or for specific 
storage domain or cluster.")
     String ACTION_TYPE_FAILED_QUOTA_LIMIT_IS_SPECIFIC_AND_GENERAL();
 
     @DefaultStringValue("Cannot ${action} ${type}. Quota limitation must be 
configured specific or general.")
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 97e1f20..01cc0d4 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
@@ -853,7 +853,7 @@
 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_SPECIFIC_AND_GENERAL=Cannot ${action} 
${type}. Limitation can not be configured as specific and general for the same 
Quota. Please choose whether the limitation should be enforced on the Data 
Center (global) or for specific storage domain or cluster.
 ACTION_TYPE_FAILED_QUOTA_LIMIT_IS_NOT_SPECIFIC_OR_GENERAL=Cannot ${action} 
${type}. Quota limitation must be configured specific or general.
 ACTION_TYPE_FAILED_QUOTA_NAME_RESERVED_FOR_DEFAULT=Cannot ${action} ${type}. 
The prefix DefaultQuota is reserved for the default quota.
 ACTION_TYPE_FAILED_QUOTA_CAN_NOT_HAVE_DEFAULT_INDICATION=Cannot ${action} 
${type}. Quota can not have default indication.
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 de15003..bbfaba6 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
@@ -942,7 +942,7 @@
 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_SPECIFIC_AND_GENERAL=Cannot ${action} 
${type}. Limitation can not be configured as specific and general for the same 
Quota. Please choose whether the limitation should be enforced on the Data 
Center (global) or for specific storage domain or cluster.
 ACTION_TYPE_FAILED_QUOTA_LIMIT_IS_NOT_SPECIFIC_OR_GENERAL=Cannot ${action} 
${type}. Quota limitation must be configured specific or general.
 ACTION_TYPE_FAILED_QUOTA_NAME_RESERVED_FOR_DEFAULT=Cannot ${action} ${type}. 
The prefix DefaultQuota is reserved for the default quota.
 ACTION_TYPE_FAILED_QUOTA_CAN_NOT_HAVE_DEFAULT_INDICATION=Cannot ${action} 
${type}. Quota can not have default indication.


-- 
To view, visit https://gerrit.ovirt.org/39903
To unsubscribe, visit https://gerrit.ovirt.org/settings

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

Reply via email to