ofri masad has uploaded a new change for review.

Change subject: engine: Add notification to quota resize (#848289)
......................................................................

engine: Add notification to quota resize (#848289)

https://bugzilla.redhat.com/848289

When a user would edit a storage quota to be smaller then the
current utilization he would get a message in the log notifying him
about this situation.

An alert icon will appear next to the quota utilization status in
the edit-quota dialog next to any exceeded storage quota.

Change-Id: I5ef7f831120cafa10aa55e51db0270915b221c9f
Signed-off-by: Ofri Masad <oma...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/QuotaCRUDCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateQuotaCommand.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
M 
backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/quota/QuotaPopupView.java
A 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/table/column/QuotaUtilizationStatusColumn.java
7 files changed, 81 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/24/7824/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/QuotaCRUDCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/QuotaCRUDCommand.java
index 0719461..398298e 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/QuotaCRUDCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/QuotaCRUDCommand.java
@@ -36,6 +36,10 @@
         this.quota = quota;
     }
 
+    protected void refreshQuotaFromDB() {
+        this.quota = getQuotaDAO().getById(getQuotaId());
+    }
+
     protected boolean checkQuotaValidationCommon(Quota quota, List<String> 
messages) {
         if (quota == null) {
             
messages.add(VdcBllMessages.ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID.toString());
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 85210e5..d3a29dc 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
@@ -13,6 +13,8 @@
 import org.ovirt.engine.core.common.businessentities.QuotaVdsGroup;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.VdcBllMessages;
+import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector;
+import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase;
 import org.ovirt.engine.core.dao.QuotaDAO;
 
 public class UpdateQuotaCommand extends QuotaCRUDCommand {
@@ -50,6 +52,7 @@
         QuotaDAO dao = getQuotaDAO();
         dao.update(getParameters().getQuota());
         getReturnValue().setSucceeded(true);
+        afterEdit();
     }
 
     protected void removeQuotaFromCache() {
@@ -77,8 +80,6 @@
     /**
      * Set quota from the parameter
      *
-     * @param parameters
-     * @return
      */
     private void setQuotaParameter() {
         Quota quotaParameter = getParameters().getQuota();
@@ -97,4 +98,25 @@
         }
         setQuota(quotaParameter);
     }
+
+    private void afterEdit() {
+        refreshQuotaFromDB();
+        boolean newSizeUnderCurrentConsumption =
+        (getQuota().getGlobalQuotaStorage() != null && 
getQuota().getGlobalQuotaStorage().getStorageSizeGB() != null
+                && 
!getQuota().getGlobalQuotaStorage().getStorageSizeGB().equals(QuotaStorage.UNLIMITED)
+                && getQuota().getGlobalQuotaStorage().getStorageSizeGB()
+                < getQuota().getGlobalQuotaStorage().getStorageSizeGBUsage()); 
// for global quota
+        //for specific quota
+        if (getQuota().getQuotaStorages() != null) {
+            for (QuotaStorage quotaStorage : getQuota().getQuotaStorages()) {
+                newSizeUnderCurrentConsumption |= 
quotaStorage.getStorageSizeGB() < quotaStorage.getStorageSizeGBUsage();
+            }
+        }
+
+        if (newSizeUnderCurrentConsumption){
+            AuditLogableBase logable = new AuditLogableBase();
+            logable.AddCustomValue("QuotaName", getQuotaName());
+            AuditLogDirector.log(logable, 
AuditLogType.QUOTA_STORAGE_RESIZE_LOWER_THEN_CONSUMPTION);
+        }
+    }
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
index 963e212..da375b5 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
@@ -175,6 +175,7 @@
     USER_EXCEEDED_QUOTA_STORAGE_GRACE_LIMIT(3009),
     USER_EXCEEDED_QUOTA_STORAGE_LIMIT(3010),
     USER_EXCEEDED_QUOTA_STORAGE_THRESHOLD(3011),
+    QUOTA_STORAGE_RESIZE_LOWER_THEN_CONSUMPTION(3012),
 
     // Gluster Audit Logs
     GLUSTER_VOLUME_CREATE(4000),
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
index 007043c..d5389d8 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
@@ -374,6 +374,7 @@
         mSeverities.put(AuditLogType.USER_EXCEEDED_QUOTA_STORAGE_GRACE_LIMIT, 
AuditLogSeverity.ERROR);
         mSeverities.put(AuditLogType.USER_EXCEEDED_QUOTA_STORAGE_LIMIT, 
AuditLogSeverity.WARNING);
         mSeverities.put(AuditLogType.USER_EXCEEDED_QUOTA_STORAGE_THRESHOLD, 
AuditLogSeverity.WARNING);
+        
mSeverities.put(AuditLogType.QUOTA_STORAGE_RESIZE_LOWER_THEN_CONSUMPTION, 
AuditLogSeverity.WARNING);
     }
 
     private static void initVMSeverities() {
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
index 5dded16..8e5bc27 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
@@ -111,6 +111,7 @@
 USER_EXCEEDED_QUOTA_STORAGE_GRACE_LIMIT=Storage-Quota ${QuotaName} limit 
exceeded and operation was blocked. Utilization(used/requested): 
${CurrentStorage}%/${Requested}% - Please select a different quota or contact 
your administrator to extend the the quota.
 USER_EXCEEDED_QUOTA_STORAGE_LIMIT=Storage-Quota ${QuotaName} limit exceeded 
and entered the grace zone. Utilization: ${CurrentStorage}% (It is advised to 
select a different quota or contact your administrator to extend the the quota).
 USER_EXCEEDED_QUOTA_STORAGE_THRESHOLD=Storage-Quota ${QuotaName} is about to 
exceed. Utilization: ${CurrentStorage}%
+QUOTA_STORAGE_RESIZE_LOWER_THEN_CONSUMPTION=Storage-Quota ${QuotaName}: new 
size is under the current utilization.
 USER_MOVED_VM=VM ${VmName} moving to Domain ${StorageDomainName} was initiated 
by ${UserName}.
 USER_MOVED_VM_FINISHED_SUCCESS=Moving VM ${VmName} to Domain 
${StorageDomainName} has been completed.
 USER_MOVED_VM_FINISHED_FAILURE=Failed to complete moving of VM ${VmName} to 
Domain ${StorageDomainName}.
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/quota/QuotaPopupView.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/quota/QuotaPopupView.java
index af9c97a..0825b27 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/quota/QuotaPopupView.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/quota/QuotaPopupView.java
@@ -42,6 +42,7 @@
 import com.google.gwt.user.client.ui.Label;
 import com.google.gwt.user.client.ui.ScrollPanel;
 import com.google.inject.Inject;
+import 
org.ovirt.engine.ui.webadmin.widget.table.column.QuotaUtilizationStatusColumn;
 
 public class QuotaPopupView extends AbstractModelBoundPopupView<QuotaModel> 
implements QuotaPopupPresenterWidget.ViewDef, SliderValueChange {
 
@@ -250,6 +251,8 @@
             }
         }, constants.storageNameQuota(), "200px"); //$NON-NLS-1$
 
+        quotaStorageTable.addColumn(new QuotaUtilizationStatusColumn(), 
constants.empty(), "10px"); //$NON-NLS-1$
+
         quotaStorageTable.addColumn(new TextColumnWithTooltip<QuotaStorage>() {
             @Override
             public String getValue(QuotaStorage object) {
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/table/column/QuotaUtilizationStatusColumn.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/table/column/QuotaUtilizationStatusColumn.java
new file mode 100644
index 0000000..c515178
--- /dev/null
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/table/column/QuotaUtilizationStatusColumn.java
@@ -0,0 +1,47 @@
+package org.ovirt.engine.ui.webadmin.widget.table.column;
+
+import org.ovirt.engine.core.common.businessentities.QuotaStorage;
+
+import com.google.gwt.resources.client.ImageResource;
+import org.ovirt.engine.ui.common.widget.table.column.ImageResourceColumn;
+import org.ovirt.engine.ui.webadmin.ApplicationResources;
+import org.ovirt.engine.ui.webadmin.gin.ClientGinjectorProvider;
+
+
+public class QuotaUtilizationStatusColumn extends 
ImageResourceColumn<QuotaStorage> {
+
+    @Override
+    public ImageResource getValue(QuotaStorage quota) {
+        if (getQuotaExceeded(quota)) {
+            setTitle("Quota exceeded");//$NON-NLS-1$
+        }
+
+        return getQuotaExceeded(quota) ? getResources().alertImage() : null;
+    }
+
+    private boolean getQuotaExceeded(QuotaStorage quota){
+//        if (quota.getGlobalQuotaStorage() == null || 
quota.getGlobalQuotaStorage().getStorageSizeGB() == null) {
+//            return true;
+//        }
+//
+//        boolean isUnlimited = 
quota.getGlobalQuotaStorage().getStorageSizeGB().equals(QuotaStorage.UNLIMITED);
+//        boolean sizeUnderCurrentConsumption;
+//        // for global quota
+//        sizeUnderCurrentConsumption = 
quota.getGlobalQuotaStorage().getStorageSizeGB()
+//                < quota.getGlobalQuotaStorage().getStorageSizeGBUsage();
+//        //for specific quota
+//        if (quota.getQuotaStorages() != null) {
+//            for (QuotaStorage quotaStorage : quota.getQuotaStorages()) {
+//                sizeUnderCurrentConsumption |= 
quotaStorage.getStorageSizeGB() < quotaStorage.getStorageSizeGBUsage();
+//            }
+//        }
+//
+//        return !isUnlimited && sizeUnderCurrentConsumption;
+        return quota.getStorageSizeGB() < quota.getStorageSizeGBUsage();
+    }
+
+    private ApplicationResources getResources() {
+        // Get a reference to the application resources:
+        return ClientGinjectorProvider.instance().getApplicationResources();
+    }
+}


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5ef7f831120cafa10aa55e51db0270915b221c9f
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: ofri masad <oma...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to