Omer Frenkel has uploaded a new change for review.

Change subject: rest: dont always use vm dynamic values
......................................................................

rest: dont always use vm dynamic values

Currently, when getting vm, some fields always show the dynamic values
(if exists) which contains information that is relevant for the
current/last run, for example, if vm has SPICE as display type, but on
run-once the user choose VNC, VNC will be shown while the vm is running.
another scenario, when user start the vm with SPICE and after that
change to VNC, SPICE is always shown, even if user explicitly request
the next_run info.

in this patch another option is added to the mapper to allow the caller
to decide if he wants the dynamic value or not, and it is used for the
next_run scenario. all other cases were not changed.

Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1128453
Change-Id: Iae643bd7f887171b389b71d31a36362ba0168709
Signed-off-by: Omer Frenkel <ofren...@redhat.com>
---
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
M 
backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
2 files changed, 33 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/06/32006/1

diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
index fd4bfa6..f15580b 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
@@ -104,7 +104,11 @@
     public VM get() {
         VM vm;
         if (isNextRunRequested()) {
-            vm  = performGet(VdcQueryType.GetVmNextRunConfiguration, new 
IdQueryParameters(guid));
+            org.ovirt.engine.core.common.businessentities.VM entity =
+                    
getEntity(org.ovirt.engine.core.common.businessentities.VM.class, 
VdcQueryType.GetVmNextRunConfiguration,
+                            new IdQueryParameters(guid), id, true);
+            vm = addLinks(populate(VmMapper.map(entity, null, false), entity));
+
         } else {
             vm = performGet(VdcQueryType.GetVmByVmId, new 
IdQueryParameters(guid));
         }
diff --git 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
index 7d7907a..f4aa4d3 100644
--- 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
+++ 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
@@ -249,6 +249,10 @@
 
     @Mapping(from = org.ovirt.engine.core.common.businessentities.VM.class, to 
= org.ovirt.engine.api.model.VM.class)
     public static VM map(org.ovirt.engine.core.common.businessentities.VM 
entity, VM template) {
+        return map(entity, template, true);
+    }
+
+    public static VM map(org.ovirt.engine.core.common.businessentities.VM 
entity, VM template, boolean showDynamicInfo) {
         VM model = template != null ? template : new VM();
 
         mapVmBaseEntityToModel(model, entity.getStaticData());
@@ -300,12 +304,32 @@
             pool.setId(entity.getVmPoolId().toString());
             model.setVmPool(pool);
         }
-        if (entity.getDynamicData() != null && 
entity.getStatus().isRunningOrPaused()) {
-            if (model.getOs() != null && entity.getBootSequence() != null) {
-                for (Boot boot : map(entity.getBootSequence(), null)) {
+
+        // some fields (like boot-order,display..) have static value (= the 
permanent config)
+        // and dynamic value (current/last run value, that can be different in 
case of run-once or edit while running)
+        if (showDynamicInfo && entity.getDynamicData() != null && 
entity.getStatus().isRunningOrPaused()) {
+           if (model.getOs() != null && entity.getBootSequence() != null) {
+               for (Boot boot : map(entity.getBootSequence(), null)) {
+                   model.getOs().getBoot().add(boot);
+               }
+           }
+
+            model.setDisplay(new Display());
+            model.getDisplay().setType(map(entity.getDisplayType(), null));
+        } else {
+            if (model.getOs() != null) {
+                for (Boot boot : map(entity.getDefaultBootSequence(), null)) {
                     model.getOs().getBoot().add(boot);
                 }
             }
+            if (entity.getDefaultDisplayType() != null) {
+                model.setDisplay(new Display());
+                model.getDisplay().setType(map(entity.getDefaultDisplayType(), 
null));
+            }
+        }
+
+        // fill dynamic data
+        if (entity.getDynamicData() != null && 
entity.getStatus().isRunningOrPaused()) {
             if(entity.getRunOnVds() != null) {
                 model.setHost(new Host());
                 model.getHost().setId(entity.getRunOnVds().toString());
@@ -336,8 +360,7 @@
             if (entity.getLastStartTime() != null) {
                 model.setStartTime(DateMapper.map(entity.getLastStartTime(), 
null));
             }
-            model.setDisplay(new Display());
-            model.getDisplay().setType(map(entity.getDisplayType(), null));
+
             model.getDisplay().setAddress(entity.getDisplayIp());
             Integer displayPort = entity.getDisplay();
             model.getDisplay().setPort(displayPort==null || displayPort==-1 ? 
null : displayPort);
@@ -345,16 +368,6 @@
             model.getDisplay().setSecurePort(displaySecurePort==null || 
displaySecurePort==-1 ? null : displaySecurePort);
             model.getDisplay().setMonitors(entity.getNumOfMonitors());
             model.getDisplay().setSingleQxlPci(entity.getSingleQxlPci());
-        } else {
-            if (model.getOs() != null) {
-                for (Boot boot : map(entity.getDefaultBootSequence(), null)) {
-                    model.getOs().getBoot().add(boot);
-                }
-            }
-            if (entity.getDefaultDisplayType() != null) {
-                model.setDisplay(new Display());
-                model.getDisplay().setType(map(entity.getDefaultDisplayType(), 
null));
-            }
         }
         if (entity.getLastStopTime() != null) {
             model.setStopTime(DateMapper.map(entity.getLastStopTime(), null));


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iae643bd7f887171b389b71d31a36362ba0168709
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
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