helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hu...@apache.org
Subject [helix] 04/44: Rename instance health check enum to be more explicit
Date Sat, 25 May 2019 01:19:38 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 f798ae91fe505d691720b77b9983d39e21234fbe
Author: Yi Wang <ywang4@linkedin.com>
AuthorDate: Thu Mar 28 16:33:01 2019 -0700

    Rename instance health check enum to be more explicit
    
    RB=1612544
    G=helix-reviewers
    A=jxue
    
    Signed-off-by: Hunter Lee <hulee@linkedin.com>
---
 .../rest/server/service/InstanceServiceImpl.java   | 55 ++++++++++++++++------
 .../helix/rest/server/TestInstanceAccessor.java    |  6 +--
 2 files changed, 43 insertions(+), 18 deletions(-)

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 d179c27..710cad0 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
@@ -44,22 +44,25 @@ public class InstanceServiceImpl implements InstanceService {
   @Override
   public Map<String, Boolean> getInstanceStoppableCheck(String clusterId, String instanceName)
{
     Map<String, Boolean> healthStatus = new HashMap<>();
-    healthStatus.put(HealthStatus.HAS_VALID_CONFIG.name(), InstanceValidationUtil.hasValidConfig(_dataAccessor,
clusterId, instanceName));
-    if (!healthStatus.get(HealthStatus.HAS_VALID_CONFIG.name())) {
+    healthStatus.put(HealthCheck.INVALID_CONFIG.name(), InstanceValidationUtil.hasValidConfig(_dataAccessor,
clusterId, instanceName));
+    if (!healthStatus.get(HealthCheck.INVALID_CONFIG.name())) {
       _logger.error("The instance {} doesn't have valid configuration", instanceName);
       return healthStatus;
     }
 
     // Any exceptions occurred below due to invalid instance config shouldn't happen
-    healthStatus.put(HealthStatus.IS_ENABLED.name(), InstanceValidationUtil.isEnabled(_dataAccessor,
_configAccessor, clusterId, instanceName));
-    healthStatus.put(HealthStatus.IS_ALIVE.name(), InstanceValidationUtil.isAlive(_dataAccessor,
clusterId, instanceName));
-    healthStatus.put(HealthStatus.HAS_RESOURCE_ASSIGNED.name(), InstanceValidationUtil.hasResourceAssigned(_dataAccessor,
clusterId, instanceName));
-    healthStatus.put(HealthStatus.HAS_DISABLED_PARTITIONS.name(), InstanceValidationUtil.hasDisabledPartitions(_dataAccessor,
clusterId, instanceName));
-    healthStatus.put(HealthStatus.HAS_ERROR_PARTITIONS.name(), InstanceValidationUtil.hasErrorPartitions(_dataAccessor,
clusterId, instanceName));
+    healthStatus.put(
+        HealthCheck.INSTANCE_NOT_ENABLED.name(), InstanceValidationUtil.isEnabled(_dataAccessor,
_configAccessor, clusterId, instanceName));
+    healthStatus.put(HealthCheck.INSTANCE_NOT_ALIVE.name(), InstanceValidationUtil.isAlive(_dataAccessor,
clusterId, instanceName));
+    healthStatus.put(
+        HealthCheck.EMPTY_RESOURCE_ASSIGNMENT.name(), InstanceValidationUtil.hasResourceAssigned(_dataAccessor,
clusterId, instanceName));
+    healthStatus.put(HealthCheck.HAS_DISABLED_PARTITIONS.name(), !InstanceValidationUtil.hasDisabledPartitions(_dataAccessor,
clusterId, instanceName));
+    healthStatus.put(
+        HealthCheck.HAS_ERROR_PARTITION.name(), !InstanceValidationUtil.hasErrorPartitions(_dataAccessor,
clusterId, instanceName));
 
     try {
       boolean isStable = InstanceValidationUtil.isInstanceStable(_dataAccessor, instanceName);
-      healthStatus.put(HealthStatus.IS_STABLE.name(), isStable);
+      healthStatus.put(HealthCheck.INSTANCE_NOT_STABLE.name(), isStable);
     } catch (HelixException e) {
       _logger.error("Failed to check instance is stable, message: {}", e.getMessage());
       // TODO action on the stable check exception
@@ -68,13 +71,35 @@ public class InstanceServiceImpl implements InstanceService {
     return healthStatus;
   }
 
-  private enum HealthStatus {
-    IS_ALIVE,
-    IS_ENABLED,
-    HAS_RESOURCE_ASSIGNED,
+  public enum HealthCheck {
+    /**
+     * Check if instance is alive
+     */
+    INSTANCE_NOT_ALIVE,
+    /**
+     * Check if instance is enabled both in instance config and cluster config
+     */
+    INSTANCE_NOT_ENABLED,
+    /**
+     * Check if instance is stable
+     * Stable means all the ideal state mapping matches external view (view of current state).
+     */
+    INSTANCE_NOT_STABLE,
+    /**
+     * Check if instance has 0 resource assigned
+     */
+    EMPTY_RESOURCE_ASSIGNMENT,
+    /**
+     * Check if instance has disabled partitions
+     */
     HAS_DISABLED_PARTITIONS,
-    HAS_VALID_CONFIG,
-    HAS_ERROR_PARTITIONS,
-    IS_STABLE
+    /**
+     * Check if instance has valid configuration (pre-requisite for all checks)
+     */
+    INVALID_CONFIG,
+    /**
+     * Check if instance has error partitions
+     */
+    HAS_ERROR_PARTITION
   }
 }
diff --git a/helix-rest/src/test/java/org/apache/helix/rest/server/TestInstanceAccessor.java
b/helix-rest/src/test/java/org/apache/helix/rest/server/TestInstanceAccessor.java
index 54f85d6..12493c5 100644
--- a/helix-rest/src/test/java/org/apache/helix/rest/server/TestInstanceAccessor.java
+++ b/helix-rest/src/test/java/org/apache/helix/rest/server/TestInstanceAccessor.java
@@ -62,9 +62,9 @@ public class TestInstanceAccessor extends AbstractTestClass {
         Entity.entity(OBJECT_MAPPER.writeValueAsString(params), MediaType.APPLICATION_JSON_TYPE);
     Response response = new JerseyUriRequestBuilder("clusters/{}/instances/{}/stoppable")
         .format(CLUSTER_NAME, INSTANCE_NAME).post(this, entity);
-    String checkResult = response.readEntity(String.class);
-    Assert.assertEquals(checkResult,
-        "{\"stoppable\":false,\"failedChecks\":[\"Helix:HAS_DISABLED_PARTITIONS\",\"Helix:HAS_RESOURCE_ASSIGNED\",\"Helix:HAS_ERROR_PARTITIONS\",\"Helix:IS_ALIVE\"]}");
+    String stoppableCheckResult = response.readEntity(String.class);
+    Assert.assertEquals(stoppableCheckResult,
+        "{\"stoppable\":false,\"failedChecks\":[\"Helix:EMPTY_RESOURCE_ASSIGNMENT\",\"Helix:INSTANCE_NOT_ALIVE\"]}");
   }
 
   @Test (dependsOnMethods = "testIsInstanceStoppable")


Mime
View raw message