pkuwm commented on a change in pull request #838: Make ConfigAccessor and
ZkUtil realm-aware
URL: https://github.com/apache/helix/pull/838#discussion_r386703887
##########
File path:
zookeeper-api/src/main/java/org/apache/helix/zookeeper/api/client/RealmAwareZkClient.java
##########
@@ -373,6 +379,91 @@ public String getZkRealmShardingKey() {
public int getSessionTimeout() {
return _sessionTimeout;
}
+
+ public String getMsdsEndpoint() {
+ return _msdsEndpoint;
+ }
+
+ public HelixZkClient.ZkConnectionConfig createZkConnectionConfig()
+ throws IOException, InvalidRoutingDataException {
+ // Convert to a single-realm HelixZkClient's ZkConnectionConfig
+ if (_zkRealmShardingKey == null || _zkRealmShardingKey.isEmpty()) {
+ throw new ZkClientException(
+ "Cannot create ZkConnectionConfig because ZK realm sharding key is
either null or empty!");
+ }
+
+ String zkAddress;
+ // Look up the ZK address for the given ZK realm sharding key
+ if (_msdsEndpoint == null || _msdsEndpoint.isEmpty()) {
+ zkAddress = HttpRoutingDataReader.getMetadataStoreRoutingData()
+ .getMetadataStoreRealm(_zkRealmShardingKey);
+ } else {
+ zkAddress =
HttpRoutingDataReader.getMetadataStoreRoutingData(_msdsEndpoint)
+ .getMetadataStoreRealm(_zkRealmShardingKey);
+ }
+
+ return new
HelixZkClient.ZkConnectionConfig(zkAddress).setSessionTimeout(_sessionTimeout);
+ }
+
+ public static class Builder {
+ private RealmMode _realmMode;
+ private String _zkRealmShardingKey;
+ private String _msdsEndpoint;
+ private int _sessionTimeout = DEFAULT_SESSION_TIMEOUT;
+
+ public Builder() {
+ }
+
+ public Builder setRealmMode(RealmMode mode) {
+ _realmMode = mode;
+ return this;
+ }
+
+ public Builder setZkRealmShardingKey(String shardingKey) {
+ _zkRealmShardingKey = shardingKey;
+ return this;
+ }
+
+ public Builder setMsdsEndpoint(String msdsEndpoint) {
+ _msdsEndpoint = msdsEndpoint;
+ return this;
+ }
+
+ public Builder setSessionTimeout(int sessionTimeout) {
+ _sessionTimeout = sessionTimeout;
+ return this;
+ }
+
+ public RealmAwareZkConnectionConfig build() {
+ validate();
+ return new RealmAwareZkConnectionConfig(this);
+ }
+
+ /**
+ * Validate the internal fields of the builder before creating an
instance.
+ */
+ private void validate() {
+ boolean isRealmModeSet = _realmMode != null;
+ boolean isShardingKeySet = _zkRealmShardingKey != null &&
!_zkRealmShardingKey.isEmpty();
+ switch (isRealmModeSet ? _realmMode : RealmMode.MULTI_REALM) {
+ case MULTI_REALM:
+ if (isShardingKeySet && isRealmModeSet) {
+ throw new IllegalArgumentException(
+ "ZK sharding key cannot be set on multi-realm mode! Sharding
key: "
+ + _zkRealmShardingKey);
+ }
+ break;
+ case SINGLE_REALM:
+ if (!isShardingKeySet) {
+ throw new IllegalArgumentException(
+ "ZK sharding key must be set on single-realm mode!");
+ }
+ break;
+ default:
+ throw new ZkClientException("RealmAwareZkConnectionConfig: Unknown
mode!");
Review comment:
Do we want `ZkClientException`?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]