Gilad Chaplik has uploaded a new change for review.

Change subject: core: avoid NPE in rollback quota (#846777)
......................................................................

core: avoid NPE in rollback quota (#846777)

https://bugzilla.redhat.com/846777

Ensuring rollback quota succeeds and doesn't interrupt the
normal flow of command ending. this solution of try/catch should be revisited
because it may hide errors in quota mechanism.

Change-Id: I688ef23e96c94e34852c02682d0bca243718cdbb
Signed-off-by: Gilad Chaplik <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmTemplateCommand.java
2 files changed, 17 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/32/7632/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
index 6422e86..35e27db 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
@@ -306,8 +306,12 @@
      */
     @SuppressWarnings({ "unchecked", "synthetic-access" })
     protected void compensate() {
-        if (this instanceof Quotable) {
-            ((Quotable) this).rollbackQuota();
+        try {
+            if (this instanceof Quotable) {
+                ((Quotable) this).rollbackQuota();
+            }
+        } catch (Exception e) {
+            log.debug("RollbackQuota: failed (may be because quota is 
disabled)", e);
         }
         TransactionSupport.executeInNewTransaction(new 
TransactionMethod<Object>() {
             @Override
@@ -1132,8 +1136,12 @@
     @Override
     public void Rollback() {
         log.errorFormat("Transaction rolled-back for command: {0}.", 
CommandBase.this.getClass().getName());
-        if (this instanceof Quotable) {
-            ((Quotable) this).rollbackQuota();
+        try {
+            if (this instanceof Quotable) {
+                ((Quotable) this).rollbackQuota();
+            }
+        } catch (Exception e) {
+            log.debug("RollbackQuota: failed (may be because quota is 
disabled)", e);
         }
         cancelTasks();
     }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmTemplateCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmTemplateCommand.java
index b3f03d8..4b0ca3a 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmTemplateCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmTemplateCommand.java
@@ -273,10 +273,12 @@
 
     private void rollbackDisksQuota() {
         List<Guid> quotaList = new ArrayList<Guid>();
-        for (DiskImage image : imageTemplates) {
-            quotaList.add(image.getQuotaId());
+        if (imageTemplates != null) {
+            for (DiskImage image : imageTemplates) {
+                quotaList.add(image.getQuotaId());
+            }
+            getQuotaManager().rollbackQuota(getStoragePool(), quotaList);
         }
-        getQuotaManager().rollbackQuota(getStoragePool(), quotaList);
     }
 
     @Override


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I688ef23e96c94e34852c02682d0bca243718cdbb
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