You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by ka...@apache.org on 2014/03/25 22:34:50 UTC
[2/2] git commit: [HELIX-410] Fix parsing and filtering of resources
in ClusterStateVerifier
[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/d932c3ba
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/d932c3ba
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/d932c3ba
Branch: refs/heads/master
Commit: d932c3ba2f36929dcfd7b674749d0b63dedd2b0d
Parents: 1e1449d
Author: Kanak Biscuitwala <ka...@apache.org>
Authored: Thu Mar 20 15:41:09 2014 -0700
Committer: Kanak Biscuitwala <ka...@apache.org>
Committed: Tue Mar 25 14:34:23 2014 -0700
----------------------------------------------------------------------
.../helix/tools/ClusterStateVerifier.java | 32 ++++++++++++++++++--
.../helix/tools/TestClusterStateVerifier.java | 5 +++
2 files changed, 35 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/helix/blob/d932c3ba/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 973736b..3da9250 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
@@ -47,6 +47,7 @@ import org.apache.helix.ZNRecord;
import org.apache.helix.api.Cluster;
import org.apache.helix.api.State;
import org.apache.helix.api.accessor.ClusterAccessor;
+import org.apache.helix.api.config.ResourceConfig;
import org.apache.helix.api.id.ClusterId;
import org.apache.helix.api.id.ParticipantId;
import org.apache.helix.api.id.PartitionId;
@@ -272,7 +273,8 @@ public class ClusterStateVerifier {
ClusterAccessor clusterAccessor = new ClusterAccessor(ClusterId.from(clusterName), accessor);
Cluster cluster = clusterAccessor.readCluster();
// calculate best possible state
- BestPossibleStateOutput bestPossOutput = ClusterStateVerifier.calcBestPossState(cluster);
+ BestPossibleStateOutput bestPossOutput =
+ ClusterStateVerifier.calcBestPossState(cluster, resources);
// set error states
if (errStates != null) {
@@ -439,6 +441,11 @@ public class ClusterStateVerifier {
*/
static BestPossibleStateOutput calcBestPossState(Cluster cluster) throws Exception {
+ return calcBestPossState(cluster, null);
+ }
+
+ static BestPossibleStateOutput calcBestPossState(Cluster cluster, Set<String> resources)
+ throws Exception {
ClusterEvent event = new ClusterEvent("sampleEvent");
event.addAttribute("Cluster", cluster);
@@ -447,6 +454,20 @@ public class ClusterStateVerifier {
BestPossibleStateCalcStage bpStage = new BestPossibleStateCalcStage();
runStage(event, rcState);
+
+ // Filter resources if specified
+ if (resources != null) {
+ Map<ResourceId, ResourceConfig> resourceMap =
+ event.getAttribute(AttributeName.RESOURCES.toString());
+ Iterator<ResourceId> it = resourceMap.keySet().iterator();
+ while (it.hasNext()) {
+ ResourceId resourceId = it.next();
+ if (!resources.contains(resourceId.toString())) {
+ it.remove();
+ }
+ }
+ }
+
runStage(event, csStage);
runStage(event, bpStage);
@@ -607,12 +628,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;
}
@@ -674,7 +702,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/d932c3ba/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 22aa1ff..abd1dd8 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
@@ -121,6 +121,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();