Omer Frenkel has uploaded a new change for review.

Change subject: core: dont use getVmPayload query for updateVmVersionCommand
......................................................................

core: dont use getVmPayload query for updateVmVersionCommand

when calling getVmPayloadQuery from updateVmVersionCommand there is NPE
because the current-user is null, since this command is executed
internaly.

replaced the call to the query with a simple db query

Change-Id: I37472aff69087e23cf4206819c84c0e0f115fcc2
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1148379
Signed-off-by: Omer Frenkel <ofren...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmVersionCommand.java
1 file changed, 14 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/20/34320/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmVersionCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmVersionCommand.java
index 6a8a662..10724b8 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmVersionCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmVersionCommand.java
@@ -26,6 +26,7 @@
 import org.ovirt.engine.core.common.businessentities.Permissions;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VmBase;
+import org.ovirt.engine.core.common.businessentities.VmDevice;
 import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType;
 import org.ovirt.engine.core.common.businessentities.VmPayload;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
@@ -190,14 +191,7 @@
             addVmParams.setWatchdog(watchdogs.get(0));
         }
 
-        if (!StringUtils.isEmpty(getParameters().getSessionId())) {
-            VmPayload payload = runInternalQuery(VdcQueryType.GetVmPayload,
-                    new IdQueryParameters(getVmTemplateId())).getReturnValue();
-
-            if (payload != null) {
-                addVmParams.setVmPayload(payload);
-            }
-        }
+        loadVmPayload(addVmParams);
 
         // when this initiated from down vm event (restore stateless vm)
         // then there is no session, so using the current user.
@@ -212,6 +206,18 @@
                 ExecutionHandler.createDefaultContextForTasks(getContext(), 
getLock()));
     }
 
+    private void loadVmPayload(AddVmParameters addVmParams) {
+        List<VmDevice> vmDevices = getVmDeviceDao()
+                .getVmDeviceByVmIdAndType(getVmTemplateId(),
+                        VmDeviceGeneralType.DISK);
+        for (VmDevice vmDevice : vmDevices) {
+            if (VmPayload.isPayload(vmDevice.getSpecParams())) {
+                addVmParams.setVmPayload(new VmPayload(vmDevice));
+                return;
+            }
+        }
+    }
+
     /**
      * Copy fields that annotated with {@link CopyOnNewVersion} from the new 
template version to the vm
      *


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I37472aff69087e23cf4206819c84c0e0f115fcc2
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.5
Gerrit-Owner: Omer Frenkel <ofren...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to