helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject [2/2] git commit: [HELIX-410] Fix parsing and filtering of resources in ClusterStateVerifier
Date Sat, 12 Apr 2014 18:44:46 GMT
[HELIX-410] Fix parsing and filtering of resources in ClusterStateVerifier


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

Branch: refs/heads/helix-0.6.2-release
Commit: 8b0c373b551499bdc4d5268af1d95a7b9c0442bf
Parents: c10f304
Author: Kanak Biscuitwala <kanak@apache.org>
Authored: Thu Mar 20 15:41:09 2014 -0700
Committer: Kanak Biscuitwala <kanak@apache.org>
Committed: Sat Apr 12 11:41:15 2014 -0700

----------------------------------------------------------------------
 .../stages/BestPossibleStateCalcStage.java      |  1 +
 .../helix/tools/ClusterStateVerifier.java       | 26 +++++++++++++++++---
 .../helix/tools/TestClusterStateVerifier.java   |  5 ++++
 3 files changed, 29 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/8b0c373b/helix-core/src/main/java/org/apache/helix/controller/stages/BestPossibleStateCalcStage.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/controller/stages/BestPossibleStateCalcStage.java
b/helix-core/src/main/java/org/apache/helix/controller/stages/BestPossibleStateCalcStage.java
index cc171a0..458218c 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/stages/BestPossibleStateCalcStage.java
+++ b/helix-core/src/main/java/org/apache/helix/controller/stages/BestPossibleStateCalcStage.java
@@ -88,6 +88,7 @@ public class BestPossibleStateCalcStage extends AbstractBaseStage {
         // if ideal state is deleted, use an empty one
         logger.info("resource:" + resourceName + " does not exist anymore");
         idealState = new IdealState(resourceName);
+        idealState.setStateModelDefRef(resource.getStateModelDefRef());
       }
 
       Rebalancer rebalancer = null;

http://git-wip-us.apache.org/repos/asf/helix/blob/8b0c373b/helix-core/src/main/java/org/apache/helix/tools/ClusterStateVerifier.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/tools/ClusterStateVerifier.java b/helix-core/src/main/java/org/apache/helix/tools/ClusterStateVerifier.java
index 3a3a09e..bd749c3 100644
--- a/helix-core/src/main/java/org/apache/helix/tools/ClusterStateVerifier.java
+++ b/helix-core/src/main/java/org/apache/helix/tools/ClusterStateVerifier.java
@@ -60,6 +60,7 @@ import org.apache.helix.manager.zk.ZkClient;
 import org.apache.helix.model.ExternalView;
 import org.apache.helix.model.IdealState;
 import org.apache.helix.model.Partition;
+import org.apache.helix.model.Resource;
 import org.apache.helix.util.ZKClientPool;
 import org.apache.log4j.Logger;
 
@@ -269,7 +270,8 @@ public class ClusterStateVerifier {
       }
 
       // calculate best possible state
-      BestPossibleStateOutput bestPossOutput = ClusterStateVerifier.calcBestPossState(cache);
+      BestPossibleStateOutput bestPossOutput =
+          ClusterStateVerifier.calcBestPossState(cache, resources);
       Map<String, Map<Partition, Map<String, String>>> bestPossStateMap
=
           bestPossOutput.getStateMap();
 
@@ -426,8 +428,12 @@ public class ClusterStateVerifier {
    * @return
    * @throws Exception
    */
-
   static BestPossibleStateOutput calcBestPossState(ClusterDataCache cache) throws Exception
{
+    return calcBestPossState(cache, null);
+  }
+
+  static BestPossibleStateOutput calcBestPossState(ClusterDataCache cache, Set<String>
resources)
+      throws Exception {
     ClusterEvent event = new ClusterEvent("sampleEvent");
     event.addAttribute("ClusterDataCache", cache);
 
@@ -436,6 +442,13 @@ public class ClusterStateVerifier {
     BestPossibleStateCalcStage bpStage = new BestPossibleStateCalcStage();
 
     runStage(event, rcState);
+
+    // Filter resources if specified
+    if (resources != null) {
+      Map<String, Resource> resourceMap = event.getAttribute(AttributeName.RESOURCES.toString());
+      resourceMap.keySet().retainAll(resources);
+    }
+
     runStage(event, csStage);
     runStage(event, bpStage);
 
@@ -597,12 +610,19 @@ public class ClusterStateVerifier {
     sleepIntervalOption.setArgs(1);
     sleepIntervalOption.setArgName("Polling period value (Optional), default=1s");
 
+    Option resourcesOption =
+        OptionBuilder.withLongOpt(resources).withDescription("Specific set of resources to
verify")
+            .create();
+    resourcesOption.setArgs(1);
+    resourcesOption.setArgName("Comma-separated resource names, default is all resources");
+
     Options options = new Options();
     options.addOption(helpOption);
     options.addOption(zkServerOption);
     options.addOption(clusterOption);
     options.addOption(timeoutOption);
     options.addOption(sleepIntervalOption);
+    options.addOption(resourcesOption);
 
     return options;
   }
@@ -664,7 +684,7 @@ public class ClusterStateVerifier {
 
       // Allow specifying resources explicitly
       if (resourceStr != null) {
-        String[] resources = resourceStr.split(resourceStr);
+        String[] resources = resourceStr.split("[\\s,]");
         resourceSet = Sets.newHashSet(resources);
       }
 

http://git-wip-us.apache.org/repos/asf/helix/blob/8b0c373b/helix-core/src/test/java/org/apache/helix/tools/TestClusterStateVerifier.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/tools/TestClusterStateVerifier.java
b/helix-core/src/test/java/org/apache/helix/tools/TestClusterStateVerifier.java
index ae154d3..dc6bd45 100644
--- a/helix-core/src/test/java/org/apache/helix/tools/TestClusterStateVerifier.java
+++ b/helix-core/src/test/java/org/apache/helix/tools/TestClusterStateVerifier.java
@@ -119,6 +119,11 @@ public class TestClusterStateVerifier extends ZkUnitTestBase {
         ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
             _clusterName, null, Sets.newHashSet(RESOURCES[1])));
     Assert.assertTrue(result);
+    String[] args = {
+        "--zkSvr", ZK_ADDR, "--cluster", _clusterName, "--resources", RESOURCES[1]
+    };
+    result = ClusterStateVerifier.verifyState(args);
+    Assert.assertTrue(result);
 
     // But the full cluster verification should fail
     boolean fullResult = new BestPossAndExtViewZkVerifier(ZK_ADDR, _clusterName).verify();


Mime
View raw message