Yair Zaslavsky has uploaded a new change for review.

Change subject: core: Improve error logging when there are LDAP queries errors
......................................................................

core: Improve error logging when there are LDAP queries errors

The following patch improves logging of LDAP queries errors.
It will try to get the root cause of the exception, and to return
a friendly string for it

Signed-off-by: Yair Zaslavsky <[email protected]>
Change-Id: Iebfc85569ba1aa8bd840f7239f83b7f921a4bd8a
Bug-Url: https://bugzilla.redhat.com/865098
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/DirectorySearcher.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/GetRootDSE.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/LdapBrokerUtils.java
3 files changed, 32 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/28/9028/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/DirectorySearcher.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/DirectorySearcher.java
index 9927c7a..33725e7 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/DirectorySearcher.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/DirectorySearcher.java
@@ -114,7 +114,7 @@
                 domain.scoreLdapServer(ldapURI, 
handlingResponse.getServerScore());
                 log.errorFormat("Failed ldap search server {0} due to {1}. We 
{2} try the next server",
                         ldapURI,
-                        translatedException.getMessage(),
+                        
LdapBrokerUtils.getFriendlyExceptionMessage(translatedException),
                         handlingResponse.isTryNextServer() ? "should" : 
"should not");
                 log.debugFormat("Failed ldap search server {0} due to {1}. We 
{2} try the next server",
                         ldapURI,
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/GetRootDSE.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/GetRootDSE.java
index 418f67c..db9a681 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/GetRootDSE.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/GetRootDSE.java
@@ -72,7 +72,10 @@
             }
 
         } catch (NamingException e) {
-            log.errorFormat("Failed to query rootDSE for LDAP server {0} due 
to {1}", ldapURI, e.getMessage());
+            String message = LdapBrokerUtils.getFriendlyExceptionMessage(e);
+
+            log.errorFormat("Failed to query rootDSE for LDAP server {0} due 
to {1}", ldapURI, message);
+
             throw new DirectoryServiceException(e);
         } finally {
             closeContext(ctx);
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/LdapBrokerUtils.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/LdapBrokerUtils.java
index 6ba8f49..f8586b3 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/LdapBrokerUtils.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/LdapBrokerUtils.java
@@ -1,5 +1,6 @@
 package org.ovirt.engine.core.bll.adbroker;
 
+import java.net.SocketTimeoutException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -9,11 +10,13 @@
 import java.util.Map;
 import java.util.Set;
 
+import javax.naming.CommunicationException;
 import javax.naming.InvalidNameException;
 import javax.naming.ldap.LdapName;
 import javax.naming.ldap.Rdn;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.exception.ExceptionUtils;
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.businessentities.AdUser;
 import org.ovirt.engine.core.common.businessentities.ad_groups;
@@ -395,4 +398,28 @@
         env.put("com.sun.jndi.ldap.connect.timeout", 
Long.toString(Config.<Integer> GetValue(ConfigValues.LDAPConnectTimeout) * 
1000));
     }
 
+    /**
+     * Gets a string representing a friendly version for possible
+     * exceptions that are thrown during LDAP queries
+     * @param th throwable object to get friendly string representation for
+     * @return friendly version if possible, or the original exception message 
if not
+     */
+    public static String getFriendlyExceptionMessage(Throwable th) {
+        Throwable ex = ExceptionUtils.getRootCause(th);
+        //Root cause should return the real root cause of the exception
+        //in chain of Exception wrapping
+        //If it fails to return it, the friendly version should be
+        //checked for type of the passed throwable
+        if (ex == null) {
+            ex = th;
+        }
+        if (ex instanceof SocketTimeoutException) {
+            return "connection timeout";
+        }
+        if (ex instanceof CommunicationException) {
+            return "communication error";
+        }
+        return th.getMessage();
+    }
+
 }


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

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

Reply via email to