helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject helix git commit: [HELIX-592] addCluster should respect overwriteExisitng when adding stateModel Definations.
Date Wed, 13 May 2015 03:05:34 GMT
Repository: helix
Updated Branches:
  refs/heads/helix-0.6.x 8a279a366 -> 3b13ce4cc


[HELIX-592] addCluster should respect overwriteExisitng when adding stateModel Definations.


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

Branch: refs/heads/helix-0.6.x
Commit: 3b13ce4cca610c344b000568df2b599e1c4aaa93
Parents: 8a279a3
Author: Lei Xia <lxia@linkedin.com>
Authored: Mon May 11 11:35:20 2015 -0700
Committer: Lei Xia <lxia@linkedin.com>
Committed: Tue May 12 13:43:30 2015 -0700

----------------------------------------------------------------------
 .../webapp/TestHelixAdminScenariosRest.java      |  2 +-
 .../main/java/org/apache/helix/HelixAdmin.java   | 12 ++++++++++++
 .../apache/helix/manager/zk/ZKHelixAdmin.java    | 19 +++++++++++++++----
 .../org/apache/helix/tools/ClusterSetup.java     | 10 ++++++++--
 .../helix/manager/zk/TestZkHelixAdmin.java       |  9 ++-------
 .../apache/helix/tools/TestHelixAdminCli.java    |  7 +------
 6 files changed, 39 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/3b13ce4c/helix-admin-webapp/src/test/java/org/apache/helix/webapp/TestHelixAdminScenariosRest.java
----------------------------------------------------------------------
diff --git a/helix-admin-webapp/src/test/java/org/apache/helix/webapp/TestHelixAdminScenariosRest.java
b/helix-admin-webapp/src/test/java/org/apache/helix/webapp/TestHelixAdminScenariosRest.java
index 8082f04..0b49096 100644
--- a/helix-admin-webapp/src/test/java/org/apache/helix/webapp/TestHelixAdminScenariosRest.java
+++ b/helix-admin-webapp/src/test/java/org/apache/helix/webapp/TestHelixAdminScenariosRest.java
@@ -220,7 +220,7 @@ public class TestHelixAdminScenariosRest extends AdminTestBase {
     Assert.assertTrue(response.contains("\\ClusterTest"));
 
     // Add already exist cluster
-    response = assertSuccessPostOperation(url, addClusterCmd("clusterTest"), true);
+    response = assertSuccessPostOperation(url, addClusterCmd("clusterTest"), false);
 
     // delete cluster without resource and instance
     Assert.assertTrue(ZKUtil.isClusterSetup("Klazt3rz", _gZkClient));

http://git-wip-us.apache.org/repos/asf/helix/blob/3b13ce4c/helix-core/src/main/java/org/apache/helix/HelixAdmin.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/HelixAdmin.java b/helix-core/src/main/java/org/apache/helix/HelixAdmin.java
index 47ff113..fbfab26 100644
--- a/helix-core/src/main/java/org/apache/helix/HelixAdmin.java
+++ b/helix-core/src/main/java/org/apache/helix/HelixAdmin.java
@@ -232,10 +232,22 @@ public interface HelixAdmin {
    * @param clusterName
    * @param stateModelDef
    * @param record
+   * @return true if successfully created, or if state model definition already exists
    */
   void addStateModelDef(String clusterName, String stateModelDef, StateModelDefinition record);
 
   /**
+   * Add a state model definition
+   * @param clusterName
+   * @param stateModelDef
+   * @param record
+   * @param recreateIfExists If the state definition already exists, it will delete it and
recreate
+   * @return true if successfully created, or if state model definition already exists
+   */
+  void addStateModelDef(String clusterName, String stateModelDef, StateModelDefinition record,
+      boolean recreateIfExists);
+
+  /**
    * Drop a resource from a cluster
    * @param clusterName
    * @param resourceName

http://git-wip-us.apache.org/repos/asf/helix/blob/3b13ce4c/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
----------------------------------------------------------------------
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 be0d17a..ecf84f8 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
@@ -715,14 +715,26 @@ public class ZKHelixAdmin implements HelixAdmin {
   @Override
   public void addStateModelDef(String clusterName, String stateModelDef,
       StateModelDefinition stateModel) {
+    addStateModelDef(clusterName, stateModelDef, stateModel, false);
+  }
+
+  @Override
+  public void addStateModelDef(String clusterName, String stateModelDef,
+      StateModelDefinition stateModel, boolean recreateIfExists) {
     if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
       throw new HelixException("cluster " + clusterName + " is not setup yet");
     }
     String stateModelDefPath = HelixUtil.getStateModelDefinitionPath(clusterName);
     String stateModelPath = stateModelDefPath + "/" + stateModelDef;
     if (_zkClient.exists(stateModelPath)) {
-      logger.warn("Skip the operation.State Model directory exists:" + stateModelPath);
-      throw new HelixException("State model path " + stateModelPath + " already exists.");
+      if (recreateIfExists) {
+        logger.info("Operation.State Model directory exists:" + stateModelPath +
+            ", remove and recreate.");
+        _zkClient.deleteRecursive(stateModelPath);
+      } else {
+        logger.info("Skip the operation. State Model directory exists:" + stateModelPath);
+        return;
+      }
     }
 
     HelixDataAccessor accessor =
@@ -980,8 +992,7 @@ public class ZKHelixAdmin implements HelixAdmin {
       throw new IllegalArgumentException(
           "state model definition must have same id as state model def name");
     }
-    addStateModelDef(clusterName, stateModelDefName, new StateModelDefinition(record));
-
+    addStateModelDef(clusterName, stateModelDefName, new StateModelDefinition(record), false);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/helix/blob/3b13ce4c/helix-core/src/main/java/org/apache/helix/tools/ClusterSetup.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/tools/ClusterSetup.java b/helix-core/src/main/java/org/apache/helix/tools/ClusterSetup.java
index 3a06a2c..37c4915 100644
--- a/helix-core/src/main/java/org/apache/helix/tools/ClusterSetup.java
+++ b/helix-core/src/main/java/org/apache/helix/tools/ClusterSetup.java
@@ -153,7 +153,7 @@ public class ClusterSetup {
 
     for (BuiltInStateModelDefinitions def : BuiltInStateModelDefinitions.values()) {
       addStateModelDef(clusterName, def.getStateModelDefinition().getId(),
-                       def.getStateModelDefinition());
+                       def.getStateModelDefinition(), overwritePrevious);
     }
   }
 
@@ -330,10 +330,16 @@ public class ClusterSetup {
     return _admin;
   }
 
-  public void addStateModelDef(String clusterName, String stateModelDef, StateModelDefinition
record) {
+  public void addStateModelDef(String clusterName, String stateModelDef,
+      StateModelDefinition record) {
     _admin.addStateModelDef(clusterName, stateModelDef, record);
   }
 
+  public void addStateModelDef(String clusterName, String stateModelDef,
+      StateModelDefinition record, boolean overwritePrevious) {
+    _admin.addStateModelDef(clusterName, stateModelDef, record, overwritePrevious);
+  }
+
   public void addResourceToCluster(String clusterName, String resourceName, int numResources,
       String stateModelRef) {
     addResourceToCluster(clusterName, resourceName, numResources, stateModelRef,

http://git-wip-us.apache.org/repos/asf/helix/blob/3b13ce4c/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java
index bbaca31..65333d1 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java
@@ -127,13 +127,8 @@ public class TestZkHelixAdmin extends ZkUnitTestBase {
     tool.addStateModelDef(clusterName, "MasterSlave", new StateModelDefinition(
         StateModelConfigGenerator.generateConfigForMasterSlave()));
     stateModelRecord = StateModelConfigGenerator.generateConfigForMasterSlave();
-    try {
-      tool.addStateModelDef(clusterName, stateModelRecord.getId(), new StateModelDefinition(
-          stateModelRecord));
-      Assert.fail("should fail if add an already-existing state model");
-    } catch (HelixException e) {
-      // OK
-    }
+    tool.addStateModelDef(clusterName, stateModelRecord.getId(), new StateModelDefinition(
+        stateModelRecord));
     list = tool.getStateModelDefs(clusterName);
     AssertJUnit.assertEquals(list.size(), 1);
 

http://git-wip-us.apache.org/repos/asf/helix/blob/3b13ce4c/helix-core/src/test/java/org/apache/helix/tools/TestHelixAdminCli.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/tools/TestHelixAdminCli.java b/helix-core/src/test/java/org/apache/helix/tools/TestHelixAdminCli.java
index 9fcacbd..0f77657 100644
--- a/helix-core/src/test/java/org/apache/helix/tools/TestHelixAdminCli.java
+++ b/helix-core/src/test/java/org/apache/helix/tools/TestHelixAdminCli.java
@@ -69,12 +69,7 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
 
     // Add already exist cluster
     command = "--zkSvr localhost:2183 -addCluster clusterTest";
-    try {
-      ClusterSetup.processCommandLineArgs(command.split("\\s+"));
-      Assert.fail("ClusterSetup should fail since clusterTest already exists");
-    } catch (Exception e) {
-      // OK
-    }
+    ClusterSetup.processCommandLineArgs(command.split("\\s+"));
 
     // make sure clusters are properly setup
     Assert.assertTrue(ZKUtil.isClusterSetup("Klazt3rz", _gZkClient));


Mime
View raw message