narendly commented on a change in pull request #838: Make ConfigAccessor and
ZkUtil realm-aware
URL: https://github.com/apache/helix/pull/838#discussion_r386573265
##########
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) {
Review comment:
That's what this piece of logic is doing.
Moving validation logic to a validate() function is a lot cleaner and
promotes better organization. The constructor only constructs.
I am not understanding your question/comment clearly - could you clarify?
----------------------------------------------------------------
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]