You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by jx...@apache.org on 2022/04/27 22:42:38 UTC

[helix] branch master updated: support common input for operational input on Maintenance Management API (#2055)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 25cd8ba19 support common input for operational input on Maintenance Management API  (#2055)
25cd8ba19 is described below

commit 25cd8ba19db14a9a282e03f605c6ca19b4cf16cf
Author: xyuanlu <xy...@gmail.com>
AuthorDate: Wed Apr 27 15:42:34 2022 -0700

    support common input for operational input on Maintenance Management API  (#2055)
    
    support common input for operational input on Maintenance Management API
---
 .../MaintenanceManagementService.java                 | 19 +++++++++++++++----
 .../TestMaintenanceManagementService.java             |  4 +++-
 .../helix/rest/server/TestPerInstanceAccessor.java    | 18 ++++++++++++++++++
 3 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/MaintenanceManagementService.java b/helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/MaintenanceManagementService.java
index 1aaea7121..440898b62 100644
--- a/helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/MaintenanceManagementService.java
+++ b/helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/MaintenanceManagementService.java
@@ -78,6 +78,9 @@ public class MaintenanceManagementService {
   private static final String CUSTOM_INSTANCE_CHECK_HTTP_REQUESTS_DURATION =
       MetricRegistry.name(InstanceService.class, "custom_instance_check_http_requests_duration");
   public static final String ALL_HEALTH_CHECK_NONBLOCK = "allHealthCheckNonBlock";
+  public static final String HELIX_INSTANCE_STOPPABLE_CHECK = "HelixInstanceStoppableCheck";
+  public static final String HELIX_CUSTOM_STOPPABLE_CHECK = "CustomInstanceStoppableCheck";
+  public static final String OPERATION_CONFIG_SHARED_INPUT = "OperationConfigSharedInput";
 
   private final ConfigAccessor _configAccessor;
   private final CustomRestClient _customRestClient;
@@ -361,6 +364,11 @@ public class MaintenanceManagementService {
           PerInstanceAccessor.PerInstanceProperties.continueOnFailures.name();
       Map<String, Map<String, String>> operationConfigSet = new HashMap<>();
 
+      Map<String, String> commonOperationConfig =
+          (operationConfig == null || !operationConfig.containsKey(OPERATION_CONFIG_SHARED_INPUT))
+              ? Collections.emptyMap()
+              : getMapFromJsonPayload(operationConfig.get(OPERATION_CONFIG_SHARED_INPUT));
+
       // perform operation check
       for (OperationInterface operationClass : operationAbstractClassList) {
         String operationClassName = operationClass.getClass().getName();
@@ -368,6 +376,8 @@ public class MaintenanceManagementService {
             (operationConfig == null || !operationConfig.containsKey(operationClassName))
                 ? Collections.emptyMap()
                 : getMapFromJsonPayload(operationConfig.get(operationClassName));
+        commonOperationConfig
+            .forEach(singleOperationConfig::putIfAbsent);
         operationConfigSet.put(operationClassName, singleOperationConfig);
         boolean continueOnFailures =
             singleOperationConfig.containsKey(continueOnFailuresName) && getBooleanFromJsonPayload(
@@ -468,14 +478,15 @@ public class MaintenanceManagementService {
     // CostumeInstanceStoppableCheck. We should add finer grain check groups to choose from
     // i.e. HELIX:INSTANCE_NOT_ENABLED, CUSTOM_PARTITION_HEALTH_FAILURE:PARTITION_INITIAL_STATE_FAIL etc.
     for (String healthCheck : healthChecks) {
-      if (healthCheck.equals("HelixInstanceStoppableCheck")) {
+      if (healthCheck.equals(HELIX_INSTANCE_STOPPABLE_CHECK)) {
         // this is helix own check
         instancesForNext =
             batchHelixInstanceStoppableCheck(clusterId, instancesForNext, finalStoppableChecks);
-      } else if (healthCheck.equals("CustomInstanceStoppableCheck")) {
+      } else if (healthCheck.equals(HELIX_CUSTOM_STOPPABLE_CHECK)) {
         // custom check, includes custom Instance check and partition check.
-        instancesForNext = batchCustomInstanceStoppableCheck(clusterId, instancesForNext, finalStoppableChecks,
-            healthCheckConfig);
+        instancesForNext =
+            batchCustomInstanceStoppableCheck(clusterId, instancesForNext, finalStoppableChecks,
+                healthCheckConfig);
       } else {
         throw new UnsupportedOperationException(healthCheck + " is not supported yet!");
       }
diff --git a/helix-rest/src/test/java/org/apache/helix/rest/clusterMaintenanceService/TestMaintenanceManagementService.java b/helix-rest/src/test/java/org/apache/helix/rest/clusterMaintenanceService/TestMaintenanceManagementService.java
index c9ed4b1fd..87883d7fa 100644
--- a/helix-rest/src/test/java/org/apache/helix/rest/clusterMaintenanceService/TestMaintenanceManagementService.java
+++ b/helix-rest/src/test/java/org/apache/helix/rest/clusterMaintenanceService/TestMaintenanceManagementService.java
@@ -176,6 +176,7 @@ public class TestMaintenanceManagementService {
     Assert.assertEquals(actual.getFailedChecks().size(), expectedFailedChecksSize);
     Assert.assertEquals(actual.getFailedChecks().get(0), expectedFailedCheck);
   }
+
   @Test
   public void testCustomPartitionCheckWithSkipZKRead() throws IOException {
     // Let ZK result is health, but http request is unhealthy.
@@ -256,7 +257,7 @@ public class TestMaintenanceManagementService {
     Assert.assertEquals(instanceInfo2.getOperationResult(), "DummyTakeOperationResult");
   }
 
-    /*
+  /*
    * Tests stoppable check api when all checks query is enabled. After helix own check fails,
    * the subsequent checks should be performed.
    */
@@ -294,6 +295,7 @@ public class TestMaintenanceManagementService {
     verify(_customRestClient, times(2))
         .getPartitionStoppableCheck(anyString(), nullable(List.class), anyMap());
   }
+
   // TODO re-enable the test when partition health checks get decoupled
   @Test(enabled = false)
   public void testGetInstanceStoppableCheckWhenPartitionsCheckFail() throws IOException {
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 d8e18d7e9..ab87864ad 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
@@ -193,6 +193,24 @@ public class TestPerInstanceAccessor extends AbstractTestClass {
   }
 
   @Test(dependsOnMethods = "testTakeInstanceOperationCheckFailure")
+  public void testTakeInstanceOperationCheckFailureCommonInput() throws IOException {
+    System.out.println("Start test :" + TestHelper.getTestMethodName());
+    String payload = "{ \"operation_list\" : [\"org.apache.helix.rest.server.TestOperationImpl\"],"
+        + "\"operation_config\": { \"OperationConfigSharedInput\" :"
+        + " {\"instance0\": true, \"instance2\": true, "
+        + "\"instance3\": true, \"instance4\": true, \"instance5\": true, "
+        + " \"value\" : \"i001\", \"list_value\" : [\"list1\"]}}} ";
+    Response response = new JerseyUriRequestBuilder("clusters/{}/instances/{}/takeInstance")
+        .format(STOPPABLE_CLUSTER, "instance0")
+        .post(this, Entity.entity(payload, MediaType.APPLICATION_JSON_TYPE));
+    String takeInstanceResult = response.readEntity(String.class);
+
+    Map<String, Object> actualMap = OBJECT_MAPPER.readValue(takeInstanceResult, Map.class);
+    Assert.assertFalse((boolean)actualMap.get("successful"));
+    System.out.println("End test :" + TestHelper.getTestMethodName());
+  }
+
+  @Test(dependsOnMethods = "testTakeInstanceOperationCheckFailureCommonInput")
   public void testTakeInstanceOperationCheckFailureNonBlocking() throws IOException {
     System.out.println("Start test :" + TestHelper.getTestMethodName());
     String payload = "{ \"operation_list\" : [\"org.apache.helix.rest.server.TestOperationImpl\"],"