narendly commented on a change in pull request #589: Add CloudConfig operations
URL: https://github.com/apache/helix/pull/589#discussion_r352883946
 
 

 ##########
 File path: helix-core/src/main/java/org/apache/helix/model/CloudConfig.java
 ##########
 @@ -0,0 +1,287 @@
+package org.apache.helix.model;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.helix.HelixException;
+import org.apache.helix.HelixProperty;
+import org.apache.helix.ZNRecord;
+
+
+/**
+ * Cloud configurations
+ */
+public class CloudConfig extends HelixProperty {
+  /**
+   * Configurable characteristics of a cloud.
+   * NOTE: Do NOT use this field name directly, use its corresponding 
getter/setter in the
+   * CloudConfig.
+   */
+  public enum CloudConfigProperty {
+    CLOUD_ENABLED, // determine whether the cluster is inside cloud 
environment.
+    CLOUD_ID, // the cloud Id that belongs to this cluster.
+    CLOUD_INFO_URLS, // the URLs from where to retrieve the cloud information.
+    CLOUD_INFO_FETCHER_CLASS_NAME, // the name of the function that fetches 
the topology.
+    CLOUD_INFO_PARSER_CLASS_NAME // the name of the function that parses the 
topology.
+  }
+
+  /* Default values */
+  public static final boolean DEFAULT_CLOUD_ENABLED = false;
+
+  /**
+   * Instantiate the CloudConfig for the cloud
+   * @param cluster
+   */
+  public CloudConfig(String cluster) {
+    super(cluster);
+  }
+
+  /**
+   * Instantiate with a pre-populated record
+   * @param record a ZNRecord corresponding to a cloud configuration
+   */
+  public CloudConfig(ZNRecord record) {
+    super(record);
+  }
+
+  /**
+   * Instantiate the config using each field individually.
+   * @param cluster
+   * @param enabled
+   * @param cloudID
+   * @param cloudInfoURLs
+   * @param cloudInfoParserClassName
+   */
+  public CloudConfig(String cluster, boolean enabled, String cloudID, 
List<String> cloudInfoURLs,
+      String cloudInfoFetcherClassName, String cloudInfoParserClassName) {
+    super(cluster);
+    _record.setBooleanField(CloudConfigProperty.CLOUD_ENABLED.name(), enabled);
+    _record.setSimpleField(CloudConfigProperty.CLOUD_ID.name(), cloudID);
+    _record.setListField(CloudConfigProperty.CLOUD_INFO_URLS.name(), 
cloudInfoURLs);
+    
_record.setSimpleField(CloudConfigProperty.CLOUD_INFO_FETCHER_CLASS_NAME.name(),
+        cloudInfoFetcherClassName);
+    
_record.setSimpleField(CloudConfigProperty.CLOUD_INFO_PARSER_CLASS_NAME.name(),
+        cloudInfoParserClassName);
+  }
+
+  /**
+   * Enable/Disable the CLOUD_ENABLED field.
+   * @param enabled
+   */
+  public void setCloudEnabled(boolean enabled) {
+    _record.setBooleanField(CloudConfigProperty.CLOUD_ENABLED.name(), enabled);
+  }
+
+  /**
+   * Whether CLOUD_ENABLED field is enabled or not.
+   * @return
+   */
+  public boolean isCloudEnabled() {
+    return _record.getBooleanField(CloudConfigProperty.CLOUD_ENABLED.name(), 
false);
+  }
+
+  /**
+   * Set the cloudID field.
+   * @param cloudID
+   */
+  public void setCloudID(String cloudID) {
+    _record.setSimpleField(CloudConfigProperty.CLOUD_ID.name(), cloudID);
+  }
+
+  /**
+   * Get the CloudID field.
+   * @return CloudID
+   */
+  public String getCloudID() {
+    return _record.getSimpleField(CloudConfigProperty.CLOUD_ID.name());
+  }
+
+  /**
+   * Set the CLOUD_INFO_URLS field.
+   * @param cloudInfoURLs
+   */
+  public void setCloudInfoURLs(List<String> cloudInfoURLs) {
+    _record.setListField(CloudConfigProperty.CLOUD_INFO_URLS.name(), 
cloudInfoURLs);
+  }
+
+  /**
+   * Get the CLOUD_INFO_URLS field.
+   * @return CLOUD_INFO_URLS field.
+   */
+  public List<String> getCloudInfoURLs() {
+    return _record.getListField(CloudConfigProperty.CLOUD_INFO_URLS.name());
+  }
+
+  /**
+   * Set the CLOUD_INFO_FETCHER_CLASS_NAME field.
+   * @param cloudInfoFetcherClassName
+   */
+  public void setCloudInfoFetcherClassName(String cloudInfoFetcherClassName) {
+    
_record.setSimpleField(CloudConfigProperty.CLOUD_INFO_FETCHER_CLASS_NAME.name(),
+        cloudInfoFetcherClassName);
+  }
+
+  /**
+   * Get the CLOUD_INFO_FETCHER_CLASS_NAME field.
+   * @return CLOUD_INFO_FETCHER_CLASS_NAME field.
+   */
+  public String getCloudInfoFetcherClassName() {
+    return 
_record.getSimpleField(CloudConfigProperty.CLOUD_INFO_FETCHER_CLASS_NAME.name());
+  }
+
+  /**
+   * Set the CLOUD_INFO_PARSER_CLASS_NAME field.
+   * @param cloudInfoParserClassName
+   */
+  public void setCloudInfoParserClassName(String cloudInfoParserClassName) {
+    
_record.setSimpleField(CloudConfigProperty.CLOUD_INFO_PARSER_CLASS_NAME.name(),
+        cloudInfoParserClassName);
+  }
+
+  /**
+   * Get the CLOUD_INFO_PARSER_CLASS_NAME field.
+   * @return CLOUD_INFO_PARSER_CLASS_NAME field.
+   */
+  public String getCloudInfoParserClassName() {
+    return 
_record.getSimpleField(CloudConfigProperty.CLOUD_INFO_PARSER_CLASS_NAME.name());
+  }
+
+  public static class Builder {
+    private String _clusterName = null;
+    private boolean _cloudEnabled = DEFAULT_CLOUD_ENABLED;
+    private String _cloudID;
+    private List<String> _cloudInfoURLList;
+    private String _cloudInfoFetcherClassName;
+    private String _cloudInfoParserClassName;
+
+    public CloudConfig build() {
+      validate();
+      return new CloudConfig(_clusterName, _cloudEnabled, _cloudID, 
_cloudInfoURLList,
+          _cloudInfoFetcherClassName, _cloudInfoParserClassName);
+    }
+
+    /**
+     * Default constructor
+     */
+    public Builder() {
+    }
+
+    /**
+     * Constructor with Cluster Name as input
+     * @param clusterName
+     */
+    public Builder(String clusterName) {
+      _clusterName = clusterName;
+    }
+
+    /**
+     * Constructor with CloudConfig as input
+     * @param cloudConfig
+     */
+    public Builder(CloudConfig cloudConfig) {
+      _cloudEnabled = cloudConfig.isCloudEnabled();
+      _cloudID = cloudConfig.getCloudID();
+      _cloudInfoURLList = cloudConfig.getCloudInfoURLs();
+      _cloudInfoFetcherClassName = cloudConfig.getCloudInfoFetcherClassName();
+      _cloudInfoParserClassName = cloudConfig.getCloudInfoParserClassName();
+    }
+
+    public Builder setClusterName(String v) {
+      _clusterName = v;
+      return this;
+    }
+
+    public Builder setCloudEnabled (boolean isEnabled) {
+      _cloudEnabled = isEnabled;
+      return this;
+    }
+
+    public Builder setCloudID (String v) {
+      _cloudID = v;
+      return this;
+    }
+
+    public Builder setCloudInfoURL (List<String> v) {
+      _cloudInfoURLList = v;
+      return this;
+    }
+
+    public Builder addCloudInfoURL (String v) {
+      if (_cloudInfoURLList == null) {
+        _cloudInfoURLList = new ArrayList<String>();
+      }
+      _cloudInfoURLList.add(v);
+      return this;
+    }
+
+    public Builder setCloudInfoFetcherClassName(String v) {
+      _cloudInfoFetcherClassName = v;
+      return this;
+    }
+
+    public Builder setCloudInfoParserClassName(String v) {
+      _cloudInfoParserClassName = v;
+      return this;
+    }
+
+    public String getClusterName() {
+      return _clusterName;
+    }
+
+    public boolean getCloudEnabled() {
+      return _cloudEnabled;
+    }
+
+    public String getCloudID() {
+      return _cloudID;
+    }
+
+    public List<String> getCloudInfoURLList() {
+      return _cloudInfoURLList;
+    }
+
+    public String getCloudInfoFetcherClassName() {
+      return _cloudInfoFetcherClassName;
+    }
+
+    public String getCloudInfoParserClassName() {
+      return _cloudInfoParserClassName;
+    }
+
+    private void validate() {
+      if (_cloudEnabled) {
 
 Review comment:
   I am not referring to whether a feature is enabled or not; rather, I'm 
pointing to whether CloudConfig object created is valid or not. These two are 
separate things. Shouldn't the validation logic validate regardless of whether 
the feature is enabled or not?

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