Juan Hernandez has uploaded a new change for review.

Change subject: restapi: Reload host after cluster update
......................................................................

restapi: Reload host after cluster update

When a host is updated the backend requires an special handling of the
cluster: due to permissions issues it has to be changed with the special
ChangeVDSCluster command. The rest of properties of the host can be
changed with the UpdateVds command. Due to this limitation the REST API
performs the update in two steps: first it checks if the cluster needs
to be udpated and then runs the ChangeVDSCluster command, then it
updates the rest of the attributes with the UpdateVds command. But the
host entity is loaded before the first command, and then passed to the
second as a parameter, thus it contains the old cluster id. The
UpdateVds command checks this and refuses the execute the operation
because it thinks that the cluster is changing. To solve this problem we
are reloading the entity after changing the cluster and before sending
it to the UpdateVds command.

Change-Id: If6470ad9ce07a3a5f68146d0b73b2f50ba508b0f
Bug-Url: https://bugzilla.redhat.com/1046336
Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com>
---
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostResourceTest.java
2 files changed, 8 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/47/22747/1

diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java
index 062a35e..3e89771 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java
@@ -86,6 +86,11 @@
             if (!clusterId.equals(entity.getVdsGroupId())) {
                 performAction(VdcActionType.ChangeVDSCluster,
                         new ChangeVDSClusterParameters(clusterId, guid));
+
+                // After changing the cluster with the specialized command we 
need to reload the entity, so that it
+                // contains the new cluster id. If we don't do this the next 
command will think that we are trying
+                // to change the cluster, and it will explicitly refuse to 
perform the update.
+                entity = getEntity(hostResolver, true);
             }
         }
         return performUpdate(incoming,
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostResourceTest.java
index 352d6a5..5c68434 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostResourceTest.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostResourceTest.java
@@ -191,7 +191,7 @@
 
     @Test
     public void testUpdateWithClusterId() throws Exception {
-        setUpGetEntityExpectations(2);
+        setUpGetEntityExpectations(3);
         setUriInfo(setUpActionExpectations(VdcActionType.ChangeVDSCluster,
                 ChangeVDSClusterParameters.class,
                 new String[] { "ClusterId", "VdsId" },
@@ -218,7 +218,7 @@
     @Test
     public void testUpdateWithClusterName() throws Exception {
         String clusterName = "Default";
-        setUpGetEntityExpectations(2);
+        setUpGetEntityExpectations(3);
         setUpGetEntityExpectations(
                 "Cluster: name=" + clusterName,
                 SearchType.Cluster,
@@ -349,7 +349,7 @@
 
     @Test
     public void testApproveChangingCluster() throws Exception {
-        setUpGetEntityExpectations(3);
+        setUpGetEntityExpectations(4);
 
         setUriInfo(setUpActionExpectations(VdcActionType.ChangeVDSCluster,
                                            ChangeVDSClusterParameters.class,


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If6470ad9ce07a3a5f68146d0b73b2f50ba508b0f
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.3
Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to