Ori Liel has uploaded a new change for review.

Change subject: restapi: Update VM - Validate against empty domain (#1049080)
......................................................................

restapi: Update VM - Validate against empty domain (#1049080)

When updating VM, if <domain> supplied, verify that
<domain><name> supplied as well.

Bug-Url: http://bugzilla.redhat.com/1049080
Change-Id: If0555c4a26e4fe99058d490a3f5808248683a1fa
Signed-off-by: Ori Liel <[email protected]>
---
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/logging/Messages.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
M 
backend/manager/modules/restapi/jaxrs/src/main/resources/org/ovirt/engine/api/restapi/logging/Messages.properties
3 files changed, 14 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/83/23983/1

diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/logging/Messages.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/logging/Messages.java
index bb5ef4d..bce9e76 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/logging/Messages.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/logging/Messages.java
@@ -13,6 +13,8 @@
 
     INCOMPLETE_PARAMS_DETAIL_TEMPLATE,
 
+    INCOMPLETE_PARAMS_CONDITIONAL,
+
     INVALID_ENUM_REASON,
 
     INVALID_ENUM_DETAIL,
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 ec29494..3a24d08 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
@@ -39,6 +39,7 @@
 import org.ovirt.engine.api.resource.VmReportedDevicesResource;
 import org.ovirt.engine.api.resource.VmResource;
 import org.ovirt.engine.api.resource.WatchdogsResource;
+import org.ovirt.engine.api.restapi.logging.Messages;
 import org.ovirt.engine.api.restapi.types.VmMapper;
 import org.ovirt.engine.core.common.VdcObjectType;
 import org.ovirt.engine.core.common.action.ChangeVMClusterParameters;
@@ -98,6 +99,7 @@
     @Override
     public VM update(VM incoming) {
         validateEnums(VM.class, incoming);
+        validateParameters(incoming);
         if (incoming.isSetCluster() && (incoming.getCluster().isSetId() || 
incoming.getCluster().isSetName())) {
             Guid clusterId = lookupClusterId(incoming);
             if(!clusterId.toString().equals(get().getCluster().getId())){
@@ -123,6 +125,15 @@
                              new UpdateParametersProvider()));
     }
 
+    private void validateParameters(VM incoming) {
+        if (incoming.isSetDomain() && !incoming.getDomain().isSetName()) {
+            throw new WebFaultException(null,
+                    localize(Messages.INCOMPLETE_PARAMS_REASON),
+                    localize(Messages.INCOMPLETE_PARAMS_CONDITIONAL, "Domain", 
"Domain name"),
+                    Response.Status.BAD_REQUEST);
+        }
+    }
+
     private String getHostId(String hostName) {
         return getEntity(VDS.class, SearchType.VDS, "Hosts: name=" + 
hostName).getId().toString();
     }
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/resources/org/ovirt/engine/api/restapi/logging/Messages.properties
 
b/backend/manager/modules/restapi/jaxrs/src/main/resources/org/ovirt/engine/api/restapi/logging/Messages.properties
index 82627de..862df74 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/resources/org/ovirt/engine/api/restapi/logging/Messages.properties
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/resources/org/ovirt/engine/api/restapi/logging/Messages.properties
@@ -4,6 +4,7 @@
 ASYNCHRONOUS_TASK_FAILED=Asynchronous task failed
 INCOMPLETE_PARAMS_REASON=Incomplete parameters
 INCOMPLETE_PARAMS_DETAIL_TEMPLATE={0} {1} required for {2}
+INCOMPLETE_PARAMS_CONDITIONAL=If {0} supplied, {1} expected to be supplied as 
well. 
 INVALID_ENUM_REASON=Invalid value
 INVALID_ENUM_DETAIL={0} is not a member of {1}
 BROKEN_CONSTRAINT_REASON=Broken immutability constraint


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If0555c4a26e4fe99058d490a3f5808248683a1fa
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Ori Liel <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to