You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by hu...@apache.org on 2019/06/24 23:49:31 UTC

[helix] 09/15: Catch exception and log error when helix-admin-webapp fails to read data from certain path

This is an automated email from the ASF dual-hosted git repository.

hulee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git

commit d6a9b1a69551e11957c01eda2e590cdd6864fd86
Author: Yi Wang <yw...@linkedin.com>
AuthorDate: Wed Apr 24 16:50:30 2019 -0700

    Catch exception and log error when helix-admin-webapp fails to read data from certain path
    
    RB=1644066
    BUG=https://jira01.corp.linkedin.com:8443/browse/EXC-114388
    G=helix-reviewers
    A=jxue
    
    Signed-off-by: Hunter Lee <hu...@linkedin.com>
---
 .../org/apache/helix/webapp/resources/ResourceUtil.java   | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ResourceUtil.java b/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ResourceUtil.java
index f47d6db..78a760a 100644
--- a/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ResourceUtil.java
+++ b/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ResourceUtil.java
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.helix.BaseDataAccessor;
+import org.apache.helix.HelixException;
 import org.apache.helix.PropertyKey;
 import org.apache.helix.manager.zk.ZkBaseDataAccessor;
 import org.apache.helix.manager.zk.ZkClient;
@@ -38,8 +39,12 @@ import org.codehaus.jackson.map.SerializationConfig;
 import org.restlet.Context;
 import org.restlet.Request;
 import org.restlet.data.Form;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 
 public class ResourceUtil {
+  private static final Logger LOG = LoggerFactory.getLogger(ResourceUtil.class);
   private static final String EMPTY_ZNRECORD_STRING =
       objectToJson(ClusterRepresentationUtil.EMPTY_ZNRECORD);
 
@@ -134,8 +139,14 @@ public class ResourceUtil {
   }
 
   public static String readZkAsBytes(ZkClient zkclient, PropertyKey propertyKey) {
-    byte[] bytes = zkclient.readData(propertyKey.getPath());
-    return bytes == null ? EMPTY_ZNRECORD_STRING : new String(bytes);
+    try {
+      byte[] bytes = zkclient.readData(propertyKey.getPath());
+      return new String(bytes);
+    } catch (Exception e) {
+      String errorMessage = "Exception occurred when reading data from path: " + propertyKey.getPath();
+      LOG.error(errorMessage, e);
+      throw new HelixException(errorMessage, e);
+    }
   }
 
   static String extractSimpleFieldFromZNRecord(String recordStr, String key) {