pkuwm commented on a change in pull request #846: Make ZKHelixAdmin and 
ZKHelixManager Realm-aware
URL: https://github.com/apache/helix/pull/846#discussion_r388683543
 
 

 ##########
 File path: 
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
 ##########
 @@ -1799,4 +1845,71 @@ private boolean 
validateWeightForResourceConfig(ClusterConfig clusterConfig,
             clusterConfig));
     return true;
   }
+
+  public static class Builder {
+    private String zkAddress;
+    private RealmAwareZkClient.RealmMode realmMode;
+    private RealmAwareZkClient.RealmAwareZkConnectionConfig 
realmAwareZkConnectionConfig;
+    private RealmAwareZkClient.RealmAwareZkClientConfig 
realmAwareZkClientConfig;
+
+    public Builder() {
+    }
+
+    public ZKHelixAdmin.Builder setZkAddress(String zkAddress) {
+      this.zkAddress = zkAddress;
+      return this;
+    }
+
+    public ZKHelixAdmin.Builder setRealmMode(RealmAwareZkClient.RealmMode 
realmMode) {
+      this.realmMode = realmMode;
+      return this;
+    }
+
+    public ZKHelixAdmin.Builder setRealmAwareZkConnectionConfig(
+        RealmAwareZkClient.RealmAwareZkConnectionConfig 
realmAwareZkConnectionConfig) {
+      realmAwareZkConnectionConfig = realmAwareZkConnectionConfig;
+      return this;
+    }
+
+    public ZKHelixAdmin.Builder setRealmAwareZkClientConfig(
+        RealmAwareZkClient.RealmAwareZkClientConfig realmAwareZkClientConfig) {
+      realmAwareZkClientConfig = realmAwareZkClientConfig;
+      return this;
+    }
+
+    public ZKHelixAdmin build() throws Exception {
+      validate();
+      return new ZKHelixAdmin(this);
+    }
+
+    /**
+     * Validate the given parameters before creating an instance of 
ConfigAccessor.
+     */
+    private void validate() {
+      // Resolve RealmMode based on other parameters
+      boolean isZkAddressSet = zkAddress != null && !zkAddress.isEmpty();
+      if (realmMode == RealmAwareZkClient.RealmMode.SINGLE_REALM && 
!isZkAddressSet) {
+        throw new HelixException(
+            "ConfigAccessor: RealmMode cannot be single-realm without a valid 
ZkAddress set!");
+      }
+      if (realmMode == null) {
+        realmMode = isZkAddressSet ? RealmAwareZkClient.RealmMode.SINGLE_REALM
+            : RealmAwareZkClient.RealmMode.MULTI_REALM;
+      }
+
+      // Resolve RealmAwareZkClientConfig
+      boolean isZkClientConfigSet = realmAwareZkClientConfig != null;
+      // Resolve which clientConfig to use
+      realmAwareZkClientConfig =
+          isZkClientConfigSet ? 
realmAwareZkClientConfig.createHelixZkClientConfig()
+              : new HelixZkClient.ZkClientConfig().setZkSerializer(new 
ZNRecordSerializer());
 
 Review comment:
   Done. We may want to make `ConfigAccessor` consistent with this?

----------------------------------------------------------------
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]

Reply via email to