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 2013/11/07 02:19:30 UTC
[22/53] [abbrv] git commit: [HELIX-100] Support participant auto join
setting
[HELIX-100] Support participant auto join setting
Project: http://git-wip-us.apache.org/repos/asf/incubator-helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-helix/commit/c506e958
Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/c506e958
Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/c506e958
Branch: refs/heads/master
Commit: c506e958f8163a1e3f8ab5f2e0cab8711ac26866
Parents: ae10d00
Author: Kanak Biscuitwala <ka...@apache.org>
Authored: Tue Oct 1 13:02:29 2013 -0700
Committer: Kanak Biscuitwala <ka...@apache.org>
Committed: Wed Nov 6 13:17:35 2013 -0800
----------------------------------------------------------------------
.../main/java/org/apache/helix/api/Cluster.java | 15 ++++--
.../helix/api/accessor/ClusterAccessor.java | 11 +++--
.../apache/helix/api/config/ClusterConfig.java | 49 ++++++++++++++++++--
.../helix/model/ClusterConfiguration.java | 17 +++++++
.../org/apache/helix/api/TestUpdateConfig.java | 7 +--
.../apache/helix/examples/NewModelExample.java | 9 +---
6 files changed, 87 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/c506e958/helix-core/src/main/java/org/apache/helix/api/Cluster.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/api/Cluster.java b/helix-core/src/main/java/org/apache/helix/api/Cluster.java
index 3d24498..04c87d4 100644
--- a/helix-core/src/main/java/org/apache/helix/api/Cluster.java
+++ b/helix-core/src/main/java/org/apache/helix/api/Cluster.java
@@ -86,12 +86,13 @@ public class Cluster {
* @param stateModelMap
* @param userConfig
* @param isPaused
+ * @param autoJoinAllowed
*/
public Cluster(ClusterId id, Map<ResourceId, Resource> resourceMap,
Map<ParticipantId, Participant> participantMap, Map<ControllerId, Controller> controllerMap,
ControllerId leaderId, Map<ConstraintType, ClusterConstraints> constraintMap,
Map<StateModelDefId, StateModelDefinition> stateModelMap, UserConfig userConfig,
- boolean isPaused) {
+ boolean isPaused, boolean autoJoinAllowed) {
// build the config
// Guava's transform and "copy" functions really return views so the maps all reflect each other
@@ -113,7 +114,7 @@ public class Cluster {
new ClusterConfig.Builder(id).addResources(resourceConfigMap.values())
.addParticipants(participantConfigMap.values()).addConstraints(constraintMap.values())
.addStateModelDefinitions(stateModelMap.values()).pausedStatus(isPaused)
- .userConfig(userConfig).build();
+ .userConfig(userConfig).autoJoin(autoJoinAllowed).build();
_resourceMap = ImmutableMap.copyOf(resourceMap);
@@ -260,7 +261,7 @@ public class Cluster {
}
/**
- * Check the pasued status of the cluster
+ * Check the paused status of the cluster
* @return true if paused, false otherwise
*/
public boolean isPaused() {
@@ -268,6 +269,14 @@ public class Cluster {
}
/**
+ * Check if the cluster supports participants automatically joining
+ * @return true if allowed, false if disallowed
+ */
+ public boolean autoJoinAllowed() {
+ return _config.autoJoinAllowed();
+ }
+
+ /**
* Get the ClusterConfig specifying this cluster
* @return ClusterConfig
*/
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/c506e958/helix-core/src/main/java/org/apache/helix/api/accessor/ClusterAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/api/accessor/ClusterAccessor.java b/helix-core/src/main/java/org/apache/helix/api/accessor/ClusterAccessor.java
index 3047c34..8768d8e 100644
--- a/helix-core/src/main/java/org/apache/helix/api/accessor/ClusterAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/api/accessor/ClusterAccessor.java
@@ -104,8 +104,11 @@ public class ClusterAccessor {
_accessor.createProperty(_keyBuilder.constraint(constraints.getType().toString()),
constraints);
}
- _accessor.createProperty(_keyBuilder.clusterConfig(),
- ClusterConfiguration.from(cluster.getUserConfig()));
+ ClusterConfiguration clusterConfig = ClusterConfiguration.from(cluster.getUserConfig());
+ if (cluster.autoJoinAllowed()) {
+ clusterConfig.setAutoJoinAllowed(cluster.autoJoinAllowed());
+ }
+ _accessor.createProperty(_keyBuilder.clusterConfig(), clusterConfig);
if (cluster.isPaused()) {
pauseCluster();
}
@@ -292,9 +295,11 @@ public class ClusterAccessor {
boolean isPaused = pauseSignal != null;
ClusterConfiguration clusterUserConfig = _accessor.getProperty(_keyBuilder.clusterConfig());
+ boolean autoJoinAllowed = false;
UserConfig userConfig;
if (clusterUserConfig != null) {
userConfig = UserConfig.from(clusterUserConfig);
+ autoJoinAllowed = clusterUserConfig.autoJoinAllowed();
} else {
userConfig = new UserConfig(Scope.cluster(_clusterId));
}
@@ -307,7 +312,7 @@ public class ClusterAccessor {
// create the cluster snapshot object
return new Cluster(_clusterId, resourceMap, participantMap, controllerMap, leaderId,
- clusterConstraintMap, stateModelMap, userConfig, isPaused);
+ clusterConstraintMap, stateModelMap, userConfig, isPaused, autoJoinAllowed);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/c506e958/helix-core/src/main/java/org/apache/helix/api/config/ClusterConfig.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/api/config/ClusterConfig.java b/helix-core/src/main/java/org/apache/helix/api/config/ClusterConfig.java
index 79b4f61..1cc09e3 100644
--- a/helix-core/src/main/java/org/apache/helix/api/config/ClusterConfig.java
+++ b/helix-core/src/main/java/org/apache/helix/api/config/ClusterConfig.java
@@ -59,6 +59,7 @@ public class ClusterConfig {
private final Map<StateModelDefId, StateModelDefinition> _stateModelMap;
private final UserConfig _userConfig;
private final boolean _isPaused;
+ private final boolean _autoJoin;
/**
* Initialize a cluster configuration. Also see ClusterConfig.Builder
@@ -69,12 +70,13 @@ public class ClusterConfig {
* @param stateModelMap map of state model id to state model definition
* @param userConfig user-defined cluster properties
* @param isPaused true if paused, false if active
+ * @param allowAutoJoin true if participants can join automatically, false otherwise
*/
private ClusterConfig(ClusterId id, Map<ResourceId, ResourceConfig> resourceMap,
Map<ParticipantId, ParticipantConfig> participantMap,
Map<ConstraintType, ClusterConstraints> constraintMap,
Map<StateModelDefId, StateModelDefinition> stateModelMap, UserConfig userConfig,
- boolean isPaused) {
+ boolean isPaused, boolean allowAutoJoin) {
_id = id;
_resourceMap = ImmutableMap.copyOf(resourceMap);
_participantMap = ImmutableMap.copyOf(participantMap);
@@ -82,6 +84,7 @@ public class ClusterConfig {
_stateModelMap = ImmutableMap.copyOf(stateModelMap);
_userConfig = userConfig;
_isPaused = isPaused;
+ _autoJoin = allowAutoJoin;
}
/**
@@ -240,11 +243,20 @@ public class ClusterConfig {
}
/**
+ * Check if this cluster allows participants to join automatically
+ * @return true if allowed, false if disallowed
+ */
+ public boolean autoJoinAllowed() {
+ return _autoJoin;
+ }
+
+ /**
* Update context for a ClusterConfig
*/
public static class Delta {
private enum Fields {
- USER_CONFIG
+ USER_CONFIG,
+ AUTO_JOIN
}
private Set<Fields> _updateFields;
@@ -369,7 +381,7 @@ public class ClusterConfig {
/*
* Set the user configuration
* @param userConfig user-specified properties
- * @return Builder
+ * @return Delta
*/
public Delta setUserConfig(UserConfig userConfig) {
_builder.userConfig(userConfig);
@@ -378,6 +390,17 @@ public class ClusterConfig {
}
/**
+ * Allow or disallow participants from automatically being able to join the cluster
+ * @param autoJoin true if allowed, false if disallowed
+ * @return Delta
+ */
+ public Delta setAutoJoin(boolean autoJoin) {
+ _builder.autoJoin(autoJoin);
+ _updateFields.add(Fields.AUTO_JOIN);
+ return this;
+ }
+
+ /**
* Create a ClusterConfig that is the combination of an existing ClusterConfig and this delta
* @param orig the original ClusterConfig
* @return updated ClusterConfig
@@ -389,12 +412,16 @@ public class ClusterConfig {
new Builder(orig.getId()).addResources(orig.getResourceMap().values())
.addParticipants(orig.getParticipantMap().values())
.addStateModelDefinitions(orig.getStateModelMap().values())
- .userConfig(orig.getUserConfig()).pausedStatus(orig.isPaused());
+ .userConfig(orig.getUserConfig()).pausedStatus(orig.isPaused())
+ .autoJoin(orig.autoJoinAllowed());
for (Fields field : _updateFields) {
switch (field) {
case USER_CONFIG:
builder.userConfig(deltaConfig.getUserConfig());
break;
+ case AUTO_JOIN:
+ builder.autoJoin(deltaConfig.autoJoinAllowed());
+ break;
}
}
// add constraint deltas
@@ -434,6 +461,7 @@ public class ClusterConfig {
private final Map<StateModelDefId, StateModelDefinition> _stateModelMap;
private UserConfig _userConfig;
private boolean _isPaused;
+ private boolean _autoJoin;
/**
* Initialize builder for a cluster
@@ -446,6 +474,7 @@ public class ClusterConfig {
_constraintMap = new HashMap<ConstraintType, ClusterConstraints>();
_stateModelMap = new HashMap<StateModelDefId, StateModelDefinition>();
_isPaused = false;
+ _autoJoin = false;
_userConfig = new UserConfig(Scope.cluster(id));
}
@@ -661,6 +690,16 @@ public class ClusterConfig {
}
/**
+ * Allow or disallow participants from automatically being able to join the cluster
+ * @param autoJoin true if allowed, false if disallowed
+ * @return Builder
+ */
+ public Builder autoJoin(boolean autoJoin) {
+ _autoJoin = autoJoin;
+ return this;
+ }
+
+ /**
* Set the user configuration
* @param userConfig user-specified properties
* @return Builder
@@ -676,7 +715,7 @@ public class ClusterConfig {
*/
public ClusterConfig build() {
return new ClusterConfig(_id, _resourceMap, _participantMap, _constraintMap, _stateModelMap,
- _userConfig, _isPaused);
+ _userConfig, _isPaused, _autoJoin);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/c506e958/helix-core/src/main/java/org/apache/helix/model/ClusterConfiguration.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/ClusterConfiguration.java b/helix-core/src/main/java/org/apache/helix/model/ClusterConfiguration.java
index 99981b4..d733a5c 100644
--- a/helix-core/src/main/java/org/apache/helix/model/ClusterConfiguration.java
+++ b/helix-core/src/main/java/org/apache/helix/model/ClusterConfiguration.java
@@ -1,5 +1,6 @@
package org.apache.helix.model;
+import org.apache.helix.HelixManager;
import org.apache.helix.HelixProperty;
import org.apache.helix.ZNRecord;
import org.apache.helix.api.config.UserConfig;
@@ -45,6 +46,22 @@ public class ClusterConfiguration extends HelixProperty {
}
/**
+ * Determine if participants can automatically join the cluster
+ * @return true if allowed, false if disallowed
+ */
+ public boolean autoJoinAllowed() {
+ return _record.getBooleanField(HelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, false);
+ }
+
+ /**
+ * Set if participants can automatically join the cluster
+ * @param autoJoinAllowed true if allowed, false if disallowed
+ */
+ public void setAutoJoinAllowed(boolean autoJoinAllowed) {
+ _record.setBooleanField(HelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, autoJoinAllowed);
+ }
+
+ /**
* Create a new ClusterConfiguration from a UserConfig
* @param userConfig user-defined configuration properties
* @return ClusterConfiguration
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/c506e958/helix-core/src/test/java/org/apache/helix/api/TestUpdateConfig.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/api/TestUpdateConfig.java b/helix-core/src/test/java/org/apache/helix/api/TestUpdateConfig.java
index 7999ab4..74781cd 100644
--- a/helix-core/src/test/java/org/apache/helix/api/TestUpdateConfig.java
+++ b/helix-core/src/test/java/org/apache/helix/api/TestUpdateConfig.java
@@ -133,10 +133,10 @@ public class TestUpdateConfig {
new ClusterConfig.Builder(clusterId)
.addStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, master, 2)
.addStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, slave, 3)
- .userConfig(userConfig).build();
+ .userConfig(userConfig).autoJoin(true).build();
// update: overwrite user config, change master constraint, remove slave constraint, add offline
- // constraint
+ // constraint, change auto join
UserConfig newUserConfig = new UserConfig(Scope.cluster(clusterId));
newUserConfig.setSimpleField("key2", "value2");
ClusterConfig updated =
@@ -144,7 +144,7 @@ public class TestUpdateConfig {
.addStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, master, 1)
.removeStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, slave)
.addStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, offline, "R")
- .setUserConfig(newUserConfig).mergeInto(config);
+ .setUserConfig(newUserConfig).setAutoJoin(false).mergeInto(config);
Assert.assertEquals(
updated.getStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, master), "1");
Assert.assertEquals(
@@ -153,5 +153,6 @@ public class TestUpdateConfig {
updated.getStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, offline), "R");
Assert.assertNull(updated.getUserConfig().getSimpleField("key1"));
Assert.assertEquals(updated.getUserConfig().getSimpleField("key2"), "value2");
+ Assert.assertFalse(updated.autoJoinAllowed());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/c506e958/helix-examples/src/main/java/org/apache/helix/examples/NewModelExample.java
----------------------------------------------------------------------
diff --git a/helix-examples/src/main/java/org/apache/helix/examples/NewModelExample.java b/helix-examples/src/main/java/org/apache/helix/examples/NewModelExample.java
index 75e7a50..804df10 100644
--- a/helix-examples/src/main/java/org/apache/helix/examples/NewModelExample.java
+++ b/helix-examples/src/main/java/org/apache/helix/examples/NewModelExample.java
@@ -2,7 +2,6 @@ package org.apache.helix.examples;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.TimeUnit;
import org.apache.helix.BaseDataAccessor;
import org.apache.helix.HelixDataAccessor;
@@ -23,13 +22,12 @@ import org.apache.helix.api.id.PartitionId;
import org.apache.helix.api.id.ResourceId;
import org.apache.helix.api.id.StateModelDefId;
import org.apache.helix.controller.rebalancer.context.FullAutoRebalancerContext;
-import org.apache.helix.manager.zk.ZKHelixAdmin;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
import org.apache.helix.manager.zk.ZkClient;
import org.apache.helix.model.StateModelDefinition;
import org.apache.helix.model.Transition;
+import org.apache.helix.util.ZKClientPool;
import org.apache.log4j.Logger;
import com.google.common.collect.Lists;
@@ -100,10 +98,7 @@ public class NewModelExample {
ClusterConfig cluster = clusterBuilder.build();
// set up accessors to work with ZooKeeper-persisted data
- int timeOutInSec = Integer.parseInt(System.getProperty(ZKHelixAdmin.CONNECTION_TIMEOUT, "30"));
- ZkClient zkClient = new ZkClient(args[0], timeOutInSec * 1000);
- zkClient.setZkSerializer(new ZNRecordSerializer());
- zkClient.waitUntilConnected(timeOutInSec, TimeUnit.SECONDS);
+ ZkClient zkClient = ZKClientPool.getZkClient(args[0]);
BaseDataAccessor<ZNRecord> baseDataAccessor = new ZkBaseDataAccessor<ZNRecord>(zkClient);
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterId.stringify(), baseDataAccessor);