jiajunwang commented on a change in pull request #647: Add java API to create 
cluster with CloudConfig
URL: https://github.com/apache/helix/pull/647#discussion_r359072038
 
 

 ##########
 File path: helix-core/src/main/java/org/apache/helix/tools/ClusterSetup.java
 ##########
 @@ -176,6 +179,31 @@ public void close() {
     }
   }
 
+  public void addCluster(String clusterName, boolean overwritePrevious, 
CloudConfig cloudConfig)
+      throws HelixException {
+    if (cloudConfig != null) {
+      if (cloudConfig.isCloudEnabled()) {
+        String cloudID = cloudConfig.getCloudID();
+        String cloudProvider = cloudConfig.getCloudProvider();
+        List<String> cloudInfoSources = cloudConfig.getCloudInfoSources();
+        String cloudProcessorName = cloudConfig.getCloudInfoProcessorName();
+
+        // Validate the cloudConfig in the builder
+        // If it is invalid, do not even create a cluster
+        CloudConfig.Builder builder = new CloudConfig.Builder(clusterName, 
true,
+            CloudProvider.valueOf(cloudProvider), cloudID, cloudInfoSources, 
cloudProcessorName);
+
+        CloudConfig validatedCloudConfig = builder.build();
+        addCluster(clusterName, overwritePrevious);
+        _admin.addCloudConfig(clusterName, validatedCloudConfig);
+      } else {
+        addCluster(clusterName, overwritePrevious);
+      }
+    } else {
+      throw new HelixException("Cannot add the cluster, cloudConfig is null!");
+    }
+  }
+
   public void addCluster(String clusterName, boolean overwritePrevious) {
     _admin.addCluster(clusterName, overwritePrevious);
 
 Review comment:
   In general, usually, we do this in a reverse way. The method with less 
parameters should call the method with more parameters. I think that is why you 
have the awkward condition check in the method above.

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