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 fe66049e7ae037e129d4e1428f8eccc13a939bc7
Author: Kai Sun <[email protected]>
AuthorDate: Tue May 14 13:55:33 2019 -0700

    Title: Helix-1842: add a resource/cluster to super cluster with default 
FULL_AUTO
    
    Current v2 rest api, adding a cluster to supercluster will put the new 
ideastate to SEMI_AUTO. In this change, we make the default as follwing:
    
    REBALANCE_MODE = FULL_AUTO,
    replicas = 3,
    REBALANCER = DelayedAutoRebalancer,
    REBALANCE_STRATEGY = CrushEdRebalanceStrategy.
    
    Also, we will indeed make the replicas of controller to be 3, instead of 
all of the controllers as currently implemented.
    
    address the first batch of reviews from hunter and jiajun.
    address further comments
    
    RB=1666833
    BUG=Helix-1842
    G=helix-reviewers
    R=jxue,jjwang,ywang4,lxia,hulee,eblumena
    A=hulee,jjwang
    
    Signed-off-by: Hunter Lee <[email protected]>
---
 .../org/apache/helix/manager/zk/ZKHelixAdmin.java  | 16 +++++++++-------
 .../helix/rest/server/TestClusterAccessor.java     | 22 ++++++++++++++++++++++
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git 
a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java 
b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
index 3db3849..a8dfcc9 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
@@ -53,6 +53,9 @@ import org.apache.helix.PropertyKey.Builder;
 import org.apache.helix.PropertyPathBuilder;
 import org.apache.helix.PropertyType;
 import org.apache.helix.ZNRecord;
+import org.apache.helix.controller.rebalancer.DelayedAutoRebalancer;
+import 
org.apache.helix.controller.rebalancer.strategy.CrushEdRebalanceStrategy;
+import org.apache.helix.controller.rebalancer.strategy.CrushRebalanceStrategy;
 import org.apache.helix.controller.rebalancer.strategy.RebalanceStrategy;
 import org.apache.helix.manager.zk.client.HelixZkClient;
 import org.apache.helix.manager.zk.client.SharedZkClientFactory;
@@ -84,6 +87,7 @@ import org.slf4j.LoggerFactory;
 public class ZKHelixAdmin implements HelixAdmin {
   public static final String CONNECTION_TIMEOUT = "helixAdmin.timeOutInSec";
   private static final String MAINTENANCE_ZNODE_ID = "maintenance";
+  private static final int DEFAULT_SUPERCLUSTER_REPLICA = 3;
 
   private final HelixZkClient _zkClient;
   private final ConfigAccessor _configAccessor;
@@ -1064,18 +1068,16 @@ public class ZKHelixAdmin implements HelixAdmin {
 
     idealState.setNumPartitions(1);
     idealState.setStateModelDefRef("LeaderStandby");
+    idealState.setRebalanceMode(RebalanceMode.FULL_AUTO);
+    idealState.setRebalancerClassName(DelayedAutoRebalancer.class.getName());
+    idealState.setRebalanceStrategy(CrushEdRebalanceStrategy.class.getName());
+    // TODO: Give user an option, say from RestAPI to config the number of 
replicas.
+    idealState.setReplicas(Integer.toString(DEFAULT_SUPERCLUSTER_REPLICA));
 
     List<String> controllers = getInstancesInCluster(grandCluster);
     if (controllers.size() == 0) {
       throw new HelixException("Grand cluster " + grandCluster + " has no 
instances");
     }
-    idealState.setReplicas(Integer.toString(controllers.size()));
-    Collections.shuffle(controllers);
-    idealState.getRecord().setListField(clusterName, controllers);
-    idealState.setPartitionState(clusterName, controllers.get(0), "LEADER");
-    for (int i = 1; i < controllers.size(); i++) {
-      idealState.setPartitionState(clusterName, controllers.get(i), "STANDBY");
-    }
 
     ZKHelixDataAccessor accessor =
         new ZKHelixDataAccessor(grandCluster, new 
ZkBaseDataAccessor<ZNRecord>(_zkClient));
diff --git 
a/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java
 
b/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java
index 2bfa4ce..b8254c6 100644
--- 
a/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java
+++ 
b/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java
@@ -35,9 +35,12 @@ import org.apache.helix.HelixDataAccessor;
 import org.apache.helix.PropertyKey;
 import org.apache.helix.TestHelper;
 import org.apache.helix.ZNRecord;
+import org.apache.helix.controller.rebalancer.DelayedAutoRebalancer;
+import 
org.apache.helix.controller.rebalancer.strategy.CrushEdRebalanceStrategy;
 import org.apache.helix.manager.zk.ZKHelixDataAccessor;
 import org.apache.helix.manager.zk.ZKUtil;
 import org.apache.helix.model.ClusterConfig;
+import org.apache.helix.model.IdealState;
 import org.apache.helix.model.InstanceConfig;
 import org.apache.helix.model.MaintenanceSignal;
 import org.apache.helix.rest.common.HelixRestNamespace;
@@ -392,6 +395,25 @@ public class TestClusterAccessor extends AbstractTestClass 
{
         
accessor.getBaseDataAccessor().exists(accessor.keyBuilder().maintenance().getPath(),
 0));
   }
 
+  @Test()
+  public void testActivateSuperCluster() {
+    System.out.println("Start test :" + TestHelper.getTestMethodName());
+    String cluster = "TestCluster_0";
+    post("clusters/" + cluster,
+        ImmutableMap.of("command", "activate", "superCluster", "superCluster"),
+        Entity.entity("", MediaType.APPLICATION_JSON_TYPE), Response.Status.OK 
.getStatusCode());
+
+    HelixDataAccessor accessor = new ZKHelixDataAccessor(_superCluster, 
_baseAccessor);
+    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+
+    IdealState idealState = 
accessor.getProperty(keyBuilder.idealStates(cluster));
+    Assert.assertEquals(idealState.getRebalanceMode(), 
IdealState.RebalanceMode.FULL_AUTO);
+    Assert.assertEquals(idealState.getRebalancerClassName(), 
DelayedAutoRebalancer.class.getName());
+    Assert.assertEquals(idealState.getRebalanceStrategy(), 
CrushEdRebalanceStrategy.class.getName());
+    // Note, set expected replicas value to 3, as the same value of 
DEFAULT_SUPERCLUSTER_REPLICA in ClusterAccessor.
+    Assert.assertEquals(idealState.getReplicas(), "3");
+  }
+
   private ClusterConfig getClusterConfigFromRest(String cluster) throws 
IOException {
     String body = get("clusters/" + cluster + "/configs", null, 
Response.Status.OK.getStatusCode(), true);
 

Reply via email to