helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hu...@apache.org
Subject [helix] 08/44: Swallow exceptions during health status checks for getting instance by id
Date Sat, 25 May 2019 01:19:42 GMT
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 b4e9d4b83fc955a024dce6c43fce98231c2d4c7c
Author: Yi Wang <ywang4@linkedin.com>
AuthorDate: Mon Apr 1 15:54:21 2019 -0700

    Swallow exceptions during health status checks for getting instance by id
    
    RB=1615554
    G=helix-reviewers
    A=jxue
    
    Signed-off-by: Hunter Lee <hulee@linkedin.com>
---
 .../helix/rest/server/json/instance/InstanceInfo.java  |  5 +++++
 .../helix/rest/server/service/InstanceServiceImpl.java | 11 +++++++++--
 .../helix/rest/server/TestPerInstanceAccessor.java     | 18 ++++++++++++++++++
 3 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/helix-rest/src/main/java/org/apache/helix/rest/server/json/instance/InstanceInfo.java
b/helix-rest/src/main/java/org/apache/helix/rest/server/json/instance/InstanceInfo.java
index b1600ce..f258c92 100644
--- a/helix-rest/src/main/java/org/apache/helix/rest/server/json/instance/InstanceInfo.java
+++ b/helix-rest/src/main/java/org/apache/helix/rest/server/json/instance/InstanceInfo.java
@@ -106,6 +106,11 @@ public class InstanceInfo {
       return this;
     }
 
+    public Builder healthStatus(boolean isHealth) {
+      this.isHealth = isHealth;
+      return this;
+    }
+
     public InstanceInfo build() {
       return new InstanceInfo(this);
     }
diff --git a/helix-rest/src/main/java/org/apache/helix/rest/server/service/InstanceServiceImpl.java
b/helix-rest/src/main/java/org/apache/helix/rest/server/service/InstanceServiceImpl.java
index 22ac30b..a928b98 100644
--- a/helix-rest/src/main/java/org/apache/helix/rest/server/service/InstanceServiceImpl.java
+++ b/helix-rest/src/main/java/org/apache/helix/rest/server/service/InstanceServiceImpl.java
@@ -24,8 +24,10 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
+
 import org.apache.helix.ConfigAccessor;
 import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
 import org.apache.helix.model.CurrentState;
 import org.apache.helix.model.InstanceConfig;
 import org.apache.helix.model.LiveInstance;
@@ -123,8 +125,13 @@ public class InstanceServiceImpl implements InstanceService {
       }
       instanceInfoBuilder.partitions(partitions);
     }
-    instanceInfoBuilder
-        .healthStatus(getInstanceHealthStatus(clusterId, instanceName, healthChecks));
+    try {
+      Map<String, Boolean> healthStatus = getInstanceHealthStatus(clusterId, instanceName,
healthChecks);
+      instanceInfoBuilder.healthStatus(healthStatus);
+    } catch (HelixException ex) {
+      _logger.error("Exception while getting health status: {}, reporting health status as
unHealth", ex);
+      instanceInfoBuilder.healthStatus(false);
+    }
 
     return instanceInfoBuilder.build();
   }
diff --git a/helix-rest/src/test/java/org/apache/helix/rest/server/TestPerInstanceAccessor.java
b/helix-rest/src/test/java/org/apache/helix/rest/server/TestPerInstanceAccessor.java
index 1a9a6da..f58bc69 100644
--- a/helix-rest/src/test/java/org/apache/helix/rest/server/TestPerInstanceAccessor.java
+++ b/helix-rest/src/test/java/org/apache/helix/rest/server/TestPerInstanceAccessor.java
@@ -26,6 +26,7 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.core.MediaType;
@@ -39,6 +40,7 @@ import org.apache.helix.manager.zk.ZKHelixDataAccessor;
 import org.apache.helix.model.InstanceConfig;
 import org.apache.helix.model.Message;
 import org.apache.helix.rest.server.resources.AbstractResource;
+import org.apache.helix.rest.server.resources.helix.InstancesAccessor;
 import org.apache.helix.rest.server.resources.helix.PerInstanceAccessor;
 import org.apache.helix.rest.server.util.JerseyUriRequestBuilder;
 import org.apache.helix.util.InstanceValidationUtil;
@@ -130,6 +132,22 @@ public class TestPerInstanceAccessor extends AbstractTestClass {
   }
 
   @Test(dependsOnMethods = "testGetMessagesByStateModelDef")
+  public void testGetAllInstances() throws IOException {
+    System.out.println("Start test :" + TestHelper.getTestMethodName());
+    String body = new JerseyUriRequestBuilder("clusters/{}/instances").isBodyReturnExpected(true)
+        .format(CLUSTER_NAME).get(this);
+
+    JsonNode node = OBJECT_MAPPER.readTree(body);
+    String instancesStr = node.get(InstancesAccessor.InstancesProperties.instances.name()).toString();
+    Assert.assertNotNull(instancesStr);
+
+    Set<String> instances = OBJECT_MAPPER.readValue(instancesStr,
+        OBJECT_MAPPER.getTypeFactory().constructCollectionType(Set.class, String.class));
+    Assert.assertEquals(instances, _instancesMap.get(CLUSTER_NAME), "Instances from response:
"
+        + instances + " vs instances actually: " + _instancesMap.get(CLUSTER_NAME));
+  }
+
+  @Test(dependsOnMethods = "testGetAllInstances")
   public void testGetInstanceById() throws IOException {
     System.out.println("Start test :" + TestHelper.getTestMethodName());
     String body = new JerseyUriRequestBuilder("clusters/{}/instances/{}").isBodyReturnExpected(true)


Mime
View raw message