Gilad Chaplik has uploaded a new change for review.

Change subject: engine: Allow empty quota in audit mode (#855633)
......................................................................

engine: Allow empty quota in audit mode (#855633)

https://bugzilla.redhat.com/855633

this is a known issue since preliminary design,
when in permissive (audit) mode, we fail any quota related command.
changed it now to allow 'no-quota' in permissive (audit) mode,
and a proper message will be delivered to audit log in this case, to
inform the user.

Change-Id: Ib52cfc882ea07223b69041cc4fc2ccc7aae77752
Signed-off-by: Gilad Chaplik <gchap...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.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/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/tree/AbstractSubTabTree.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmDiskListModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/storage/TemplatesTree.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/storage/VMsTree.java
9 files changed, 59 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/59/8059/1

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 7dead2f..7ab063c 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
@@ -165,9 +165,16 @@
                 return true;
             }
             for (StorageQuotaValidationParameter param : parameters) {
-                if (param.getQuotaId() == null || param.getStorageDomainId() 
== null) {
-                    
canDoActionMessages.add(VdcBllMessages.ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID.toString());
-                    return false;
+                if (param.getQuotaId() == null || 
Guid.Empty.equals(param.getQuotaId())
+                        || param.getStorageDomainId() == null) {
+                    if 
(QuotaEnforcementTypeEnum.HARD_ENFORCEMENT.equals(storagePool.getQuotaEnforcementType()))
 {
+                        
canDoActionMessages.add(VdcBllMessages.ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID.toString());
+                        return false;
+                    } else {
+                        
logPair.setFirst(AuditLogType.MISSING_QUOTA_STORAGE_PARAMETERS_PERMISSIVE_MODE);
+                        logPair.setSecond(new AuditLogableBase());
+                        return true;
+                    }
                 }
             }
 
@@ -425,15 +432,22 @@
             Guid vdsGroupId,
             Guid quotaId,
             ArrayList<String> canDoActionMessages) {
+        Pair<AuditLogType, AuditLogableBase> logPair = new Pair<AuditLogType, 
AuditLogableBase>();
         lock.readLock().lock();
         try {
             if 
(QuotaEnforcementTypeEnum.DISABLED.equals(storagePool.getQuotaEnforcementType()))
 {
                 return true;
             }
 
-            if (vdsGroupId == null || vdsGroupId.equals(Guid.Empty) || quotaId 
== null) {
-                
canDoActionMessages.add(VdcBllMessages.ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID.toString());
-                return false;
+            if (vdsGroupId == null || Guid.Empty.equals(vdsGroupId) || quotaId 
== null || Guid.Empty.equals(quotaId)) {
+                if 
(QuotaEnforcementTypeEnum.HARD_ENFORCEMENT.equals(storagePool.getQuotaEnforcementType()))
 {
+                    
canDoActionMessages.add(VdcBllMessages.ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID.toString());
+                    return false;
+                } else {
+                    
logPair.setFirst(AuditLogType.MISSING_QUOTA_CLUSTER_PARAMETERS_PERMISSIVE_MODE);
+                    logPair.setSecond(new AuditLogableBase());
+                    return true;
+                }
             }
 
             if (!storagePoolQuotaMap.containsKey(storagePool.getId())) {
@@ -478,6 +492,9 @@
             return false;
         } finally {
             lock.readLock().unlock();
+            if (logPair.getFirst() != null) {
+                AuditLogDirector.log(logPair.getSecond(), logPair.getFirst());
+            }
         }
 
     }
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 6f329f0..2833de9 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
@@ -176,6 +176,8 @@
     USER_EXCEEDED_QUOTA_STORAGE_LIMIT(3010),
     USER_EXCEEDED_QUOTA_STORAGE_THRESHOLD(3011),
     QUOTA_STORAGE_RESIZE_LOWER_THEN_CONSUMPTION(3012),
+    MISSING_QUOTA_STORAGE_PARAMETERS_PERMISSIVE_MODE(3013),
+    MISSING_QUOTA_CLUSTER_PARAMETERS_PERMISSIVE_MODE(3014),
 
     // 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 e180022..f91d896 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
@@ -376,6 +376,8 @@
         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);
+        
mSeverities.put(AuditLogType.MISSING_QUOTA_STORAGE_PARAMETERS_PERMISSIVE_MODE, 
AuditLogSeverity.WARNING);
+        
mSeverities.put(AuditLogType.MISSING_QUOTA_CLUSTER_PARAMETERS_PERMISSIVE_MODE, 
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 77fa24f..61fc3d7 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
@@ -112,6 +112,8 @@
 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}: the 
new size set for this quota is less than current disk utilization.
+MISSING_QUOTA_STORAGE_PARAMETERS_PERMISSIVE_MODE=Missing Quota for Disk, 
proceeding since in Permissive (Audit) mode.
+MISSING_QUOTA_CLUSTER_PARAMETERS_PERMISSIVE_MODE=Missing Quota for VM, 
proceeding since in Permissive (Audit) mode.
 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}.
@@ -545,5 +547,5 @@
 GLUSTER_HOST_ADD_FAILED=Failed to add gluster server ${VdsName} into Cluster 
${VdsGroupName}.
 GLUSTER_HOST_REMOVE_FAILED=Failed to remove gluster server ${VdsName} from 
Cluster ${VdsGroupName}.
 GLUSTER_SERVERS_LIST_FAILED=Failed to fetch gluster peer list from server 
${VdsName} on Cluster ${VdsGroupName}.
-HA_VM_FAILED=Highly Available VM ${VmName} failed. It will be restarted 
automatically.
-HA_VM_RESTART_FAILED=Restart of the Highly Available VM ${VmName} failed.
+HA_VM_FAILED=Highly Available VM ${VmName} failed. It will be restarted 
automatically.
+HA_VM_RESTART_FAILED=Restart of the Highly Available VM ${VmName} failed.
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/tree/AbstractSubTabTree.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/tree/AbstractSubTabTree.java
index 64bac57..aeceae2 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/tree/AbstractSubTabTree.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/tree/AbstractSubTabTree.java
@@ -202,7 +202,9 @@
                     rootItem = oldRootItemsMap.get(rootItem.getUserObject());
                 }
                 else {
-                    rootItem.addItem(getEmptyRoot());
+                    if (getEmptyRoot() != null) {
+                        rootItem.addItem(getEmptyRoot());
+                    }
                 }
             } else {
                 for (N node : getNodeObjects(root)) {
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmDiskListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmDiskListModel.java
index 6a16db4..780470a 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmDiskListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmDiskListModel.java
@@ -638,7 +638,7 @@
             
diskImage.setSizeInGigabytes(Integer.parseInt(model.getSize().getEntity().toString()));
             diskImage.setvolume_type((VolumeType) 
model.getVolumeType().getSelectedItem());
             diskImage.setvolume_format(model.getVolumeFormat());
-            if (model.getQuota().getIsAvailable()) {
+            if (model.getQuota().getIsAvailable() && 
model.getQuota().getSelectedItem() != null) {
                 diskImage.setQuotaId(((Quota) 
model.getQuota().getSelectedItem()).getId());
             }
 
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
index cc67753..d1b08ba 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
@@ -2322,6 +2322,10 @@
                                             
.setvolume_format(DataProvider.GetDiskVolumeFormat(
                                                     (VolumeType) 
disk.getVolumeType().getSelectedItem(),
                                                     
storageDomain.getstorage_type()));
+                                    if (disk.getQuota().getSelectedItem() != 
null) {
+                                        
dict.get(templateDisk.getId()).setQuotaId(((Quota) disk.getQuota()
+                                                .getSelectedItem()).getId());
+                                    }
                                 }
                             }
 
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/storage/TemplatesTree.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/storage/TemplatesTree.java
index da0e26f..458118b 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/storage/TemplatesTree.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/storage/TemplatesTree.java
@@ -2,6 +2,7 @@
 
 import java.util.ArrayList;
 
+import org.ovirt.engine.core.common.businessentities.BusinessEntity;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.Quota;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
@@ -27,7 +28,9 @@
     ApplicationResources resources;
     ApplicationConstants constants;
 
-    public TemplatesTree(CommonApplicationResources resources, 
CommonApplicationConstants constants, ApplicationTemplates templates) {
+    public TemplatesTree(CommonApplicationResources resources,
+            CommonApplicationConstants constants,
+            ApplicationTemplates templates) {
         super(resources, constants, templates);
         this.resources = (ApplicationResources) resources;
         this.constants = (ApplicationConstants) constants;
@@ -75,9 +78,12 @@
 
     @Override
     protected boolean getIsNodeEnabled(DiskImage disk) {
-        if (listModel.getEntity() instanceof Quota) {
+        if (listModel.getEntity() == null) {
             return true;
         }
+        if (listModel.getEntity() instanceof Quota) {
+            return ((BusinessEntity) 
listModel.getEntity()).getId().equals(((DiskImage) disk).getQuotaId());
+        }
         return disk.getstorage_ids().contains(((storage_domains) 
listModel.getEntity()).getId());
     }
 }
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/storage/VMsTree.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/storage/VMsTree.java
index 5197393..335572e 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/storage/VMsTree.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/storage/VMsTree.java
@@ -8,6 +8,7 @@
 import org.ovirt.engine.core.common.businessentities.Disk.DiskStorageType;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.LunDisk;
+import org.ovirt.engine.core.common.businessentities.Quota;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.ui.common.CommonApplicationConstants;
 import org.ovirt.engine.ui.common.CommonApplicationResources;
@@ -32,7 +33,9 @@
     ApplicationResources resources;
     ApplicationConstants constants;
 
-    public VMsTree(CommonApplicationResources resources, 
CommonApplicationConstants constants, ApplicationTemplates templates) {
+    public VMsTree(CommonApplicationResources resources,
+            CommonApplicationConstants constants,
+            ApplicationTemplates templates) {
         super(resources, constants, templates);
         this.resources = (ApplicationResources) resources;
         this.constants = (ApplicationConstants) constants;
@@ -66,7 +69,7 @@
     @Override
     protected TreeItem getLeafItem(Disk disk) {
         if (disk.getDiskStorageType() == DiskStorageType.IMAGE) {
-            return getSnapshotNode(((DiskImage)disk).getSnapshots());
+            return getSnapshotNode(((DiskImage) disk).getSnapshots());
         } else {
             return null;
         }
@@ -84,7 +87,13 @@
     @Override
     protected boolean getIsNodeEnabled(Disk disk) {
         if (disk.getDiskStorageType() == DiskStorageType.IMAGE) {
-            return 
((DiskImage)disk).getstorage_ids().get(0).equals(((BusinessEntity) 
listModel.getEntity()).getId());
+            if (listModel.getEntity() instanceof Quota) {
+                return ((BusinessEntity) 
listModel.getEntity()).getId().equals(((DiskImage) disk).getQuotaId());
+            } else {
+                return ((DiskImage) disk).getstorage_ids()
+                        .get(0)
+                        .equals(((BusinessEntity) 
listModel.getEntity()).getId());
+            }
         } else {
             return true;
         }


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

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

Reply via email to