helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [33/50] [abbrv] helix git commit: Support Helix REST enable/disable partitions
Date Thu, 25 Jan 2018 21:49:24 GMT
Support Helix REST enable/disable partitions


Project: http://git-wip-us.apache.org/repos/asf/helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/4ff98fb1
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/4ff98fb1
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/4ff98fb1

Branch: refs/heads/master
Commit: 4ff98fb19ffc1b21893089a9d4d4e61864248647
Parents: 7fc03f4
Author: Junkai Xue <jxue@linkedin.com>
Authored: Thu Nov 16 17:39:12 2017 -0800
Committer: Junkai Xue <jxue@linkedin.com>
Committed: Wed Jan 24 18:32:35 2018 -0800

----------------------------------------------------------------------
 .../rest/server/resources/AbstractResource.java |  2 +
 .../rest/server/resources/InstanceAccessor.java | 15 ++++++++
 .../helix/rest/server/TestInstanceAccessor.java | 40 ++++++++++++++++++--
 3 files changed, 54 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/4ff98fb1/helix-rest/src/main/java/org/apache/helix/rest/server/resources/AbstractResource.java
----------------------------------------------------------------------
diff --git a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/AbstractResource.java
b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/AbstractResource.java
index 70f713a..a89ae5d 100644
--- a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/AbstractResource.java
+++ b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/AbstractResource.java
@@ -67,6 +67,8 @@ public class AbstractResource {
     disable,
     enableMaintenanceMode,
     disableMaintenanceMode,
+    enablePartitions,
+    disablePartitions,
     update,
     delete,
     rebalance,

http://git-wip-us.apache.org/repos/asf/helix/blob/4ff98fb1/helix-rest/src/main/java/org/apache/helix/rest/server/resources/InstanceAccessor.java
----------------------------------------------------------------------
diff --git a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/InstanceAccessor.java
b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/InstanceAccessor.java
index 72ffc19..eeecba9 100644
--- a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/InstanceAccessor.java
+++ b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/InstanceAccessor.java
@@ -259,6 +259,21 @@ public class InstanceAccessor extends AbstractResource {
           admin.removeInstanceTag(clusterId, instanceName, tag);
         }
         break;
+      case enablePartitions:
+        admin.enablePartition(true, clusterId, instanceName,
+            node.get(InstanceProperties.resource.name()).getTextValue(),
+            (List<String>) OBJECT_MAPPER
+                .readValue(node.get(InstanceProperties.partitions.name()).toString(),
+                    OBJECT_MAPPER.getTypeFactory()
+                        .constructCollectionType(List.class, String.class)));
+        break;
+      case disablePartitions:
+        admin.enablePartition(false, clusterId, instanceName,
+            node.get(InstanceProperties.resource.name()).getTextValue(),
+            (List<String>) OBJECT_MAPPER
+                .readValue(node.get(InstanceProperties.partitions.name()).toString(),
+                    OBJECT_MAPPER.getTypeFactory().constructCollectionType(List.class, String.class)));
+        break;
       default:
         _logger.error("Unsupported command :" + command);
         return badRequest("Unsupported command :" + command);

http://git-wip-us.apache.org/repos/asf/helix/blob/4ff98fb1/helix-rest/src/test/java/org/apache/helix/rest/server/TestInstanceAccessor.java
----------------------------------------------------------------------
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 6c83bef..947ba49 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
@@ -137,10 +137,10 @@ public class TestInstanceAccessor extends AbstractTestClass {
         Response.Status.OK.getStatusCode());
     Assert.assertEquals(_configAccessor.getInstanceConfig(CLUSTER_NAME, INSTANCE_NAME).getTags(),
         ImmutableList.of("tag2"));
-
-    // TODO (JK): Reenable this after storage node bug fixed.
-    /*
+    
+    // TODO: Reenable the test after storage node fix the problem
     // Batch disable instances
+    /*
     List<String> instancesToDisable = Arrays.asList(
         new String[] { CLUSTER_NAME + "localhost_12918", CLUSTER_NAME + "localhost_12919",
             CLUSTER_NAME + "localhost_12920"
@@ -166,6 +166,40 @@ public class TestInstanceAccessor extends AbstractTestClass {
     Assert.assertEquals(clusterConfig.getDisabledInstances().keySet(),
         new HashSet<>(Arrays.asList(CLUSTER_NAME + "localhost_12919")));
     */
+
+    // Test enable disable partitions
+    String dbName = "_db_0_";
+    List<String> partitionsToDisable = Arrays.asList(
+        new String[] { CLUSTER_NAME + dbName + "0", CLUSTER_NAME + dbName + "1",
+            CLUSTER_NAME + dbName + "3"
+        });
+
+    entity = Entity.entity(OBJECT_MAPPER.writeValueAsString(ImmutableMap
+            .of(AbstractResource.Properties.id.name(), INSTANCE_NAME,
+                InstanceAccessor.InstanceProperties.resource.name(),
+                CLUSTER_NAME + dbName.substring(0, dbName.length() - 1),
+                InstanceAccessor.InstanceProperties.partitions.name(), partitionsToDisable)),
+        MediaType.APPLICATION_JSON_TYPE);
+    post("clusters/" + CLUSTER_NAME + "/instances/" + INSTANCE_NAME,
+        ImmutableMap.of("command", "disablePartitions"), entity,
+        Response.Status.OK.getStatusCode());
+    InstanceConfig instanceConfig = _configAccessor.getInstanceConfig(CLUSTER_NAME, INSTANCE_NAME);
+    Assert.assertEquals(new HashSet<>(instanceConfig.getDisabledPartitionsMap()
+            .get(CLUSTER_NAME + dbName.substring(0, dbName.length() - 1))),
+        new HashSet<>(partitionsToDisable));
+    entity = Entity.entity(OBJECT_MAPPER.writeValueAsString(ImmutableMap
+        .of(AbstractResource.Properties.id.name(), INSTANCE_NAME,
+            InstanceAccessor.InstanceProperties.resource.name(),
+            CLUSTER_NAME + dbName.substring(0, dbName.length() - 1),
+            InstanceAccessor.InstanceProperties.partitions.name(),
+            ImmutableList.of(CLUSTER_NAME + dbName + "1"))), MediaType.APPLICATION_JSON_TYPE);
+
+    post("clusters/" + CLUSTER_NAME + "/instances/" + INSTANCE_NAME,
+        ImmutableMap.of("command", "enablePartitions"), entity, Response.Status.OK.getStatusCode());
+    instanceConfig = _configAccessor.getInstanceConfig(CLUSTER_NAME, INSTANCE_NAME);
+    Assert.assertEquals(new HashSet<>(instanceConfig.getDisabledPartitionsMap()
+            .get(CLUSTER_NAME + dbName.substring(0, dbName.length() - 1))),
+        new HashSet<>(Arrays.asList(CLUSTER_NAME + dbName + "0", CLUSTER_NAME + dbName
+ "3")));
   }
 
   @Test(dependsOnMethods = "updateInstance")


Mime
View raw message