Yaniv Bronhaim has uploaded a new change for review.
Change subject: Parsing http body return on error and improve output
......................................................................
Parsing http body return on error and improve output
Instead of generalizing the error by using PROVIDER_FAILURE, foreman
starts to provide full description of the failure reason, such as:
Body: {
"error": {"id":17,"errors":{"root_pass":["should be 8 characters or more"]},
"full_messages":["Root password should be 8 characters or more"]}
}
In this patch we add the "full_messages" to engine.log
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1124891
Change-Id: I1a5717baa06665e475e64a8f91e23ffcb01e17b4
Signed-off-by: Yaniv Bronhaim <[email protected]>
---
A
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/host/provider/foreman/ForemanError.java
A
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/host/provider/foreman/ForemanErrorWrapper.java
M
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/host/provider/foreman/ForemanHostProviderProxy.java
3 files changed, 35 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/01/35201/1
diff --git
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/host/provider/foreman/ForemanError.java
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/host/provider/foreman/ForemanError.java
new file mode 100644
index 0000000..603037e
--- /dev/null
+++
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/host/provider/foreman/ForemanError.java
@@ -0,0 +1,18 @@
+package org.ovirt.engine.core.bll.host.provider.foreman;
+
+import java.io.Serializable;
+import java.util.Map;
+
+public class ForemanError implements Serializable {
+ private static final long serialVersionUID = 468697212133957494L;
+ private Map<String, String[]> errors;
+ private String[] full_messages;
+
+ public String[] getFull_messages() { return full_messages; }
+
+ public void setFull_messages(String[] full_messages) { this.full_messages
= full_messages; }
+
+ public Map<String, String[]> getErrors() { return errors; }
+
+ public void setErrors(Map<String, String[]> errors) { this.errors =
errors; }
+}
diff --git
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/host/provider/foreman/ForemanErrorWrapper.java
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/host/provider/foreman/ForemanErrorWrapper.java
new file mode 100644
index 0000000..7b564d0
--- /dev/null
+++
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/host/provider/foreman/ForemanErrorWrapper.java
@@ -0,0 +1,13 @@
+package org.ovirt.engine.core.bll.host.provider.foreman;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+public class ForemanErrorWrapper {
+ @JsonProperty("error")
+ private ForemanError fe;
+
+ public ForemanError getForemanError() {
+ return fe;
+ }
+
+ public void setForemanError(ForemanError fe) { this.fe = fe; }
+}
diff --git
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/host/provider/foreman/ForemanHostProviderProxy.java
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/host/provider/foreman/ForemanHostProviderProxy.java
index 38af618..61d2ba3 100644
---
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/host/provider/foreman/ForemanHostProviderProxy.java
+++
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/host/provider/foreman/ForemanHostProviderProxy.java
@@ -27,6 +27,7 @@
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
+import org.apache.commons.lang.StringUtils;
import org.ovirt.engine.core.bll.host.provider.HostProviderProxy;
import org.ovirt.engine.core.bll.provider.BaseProviderProxy;
import org.ovirt.engine.core.bll.provider.ExternalTrustStoreInitializer;
@@ -350,7 +351,9 @@
// after post request the return value is HTTP_MOVED_TEMP on
success
if (result != HttpURLConnection.HTTP_OK && result !=
HttpURLConnection.HTTP_MOVED_TEMP) {
- throw new VdcBLLException(VdcBllErrors.PROVIDER_FAILURE);
+ ForemanErrorWrapper ferr =
objectMapper.readValue(httpMethod.getResponseBody(), ForemanErrorWrapper.class);
+ String err =
StringUtils.join(ferr.getForemanError().getFull_messages(), ", ");
+ throw new VdcBLLException(VdcBllErrors.PROVIDER_FAILURE, err);
}
} catch (HttpException e) {
handleException(e);
--
To view, visit http://gerrit.ovirt.org/35201
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1a5717baa06665e475e64a8f91e23ffcb01e17b4
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.5
Gerrit-Owner: Yaniv Bronhaim <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches