This is an automated email from the ASF dual-hosted git repository. jiajunwang pushed a commit to branch helix-0.9.x in repository https://gitbox.apache.org/repos/asf/helix.git
commit db5b29738ebd251fcdc3a597285c0089fe6ba9a8 Author: Hunter Lee <[email protected]> AuthorDate: Wed Apr 8 15:33:21 2020 -0700 Fix ClusterAccessor::createCluster wrt CloudConfig (#937) The logic for ClusterAccessor was faulty in that it called createCluster() twice. This PR fixes this. --- .../server/resources/helix/ClusterAccessor.java | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java index f8e1d86..ccbe12a 100644 --- a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java +++ b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java @@ -137,10 +137,10 @@ public class ClusterAccessor extends AbstractHelixResource { public Response createCluster(@PathParam("clusterId") String clusterId, @DefaultValue("false") @QueryParam("recreate") String recreate, @DefaultValue("false") @QueryParam("addCloudConfig") String addCloudConfig, - String content) { + String cloudConfigManifest) { - boolean recreateIfExists = Boolean.valueOf(recreate); - boolean cloudConfigIncluded = Boolean.valueOf(addCloudConfig); + boolean recreateIfExists = Boolean.parseBoolean(recreate); + boolean cloudConfigIncluded = Boolean.parseBoolean(addCloudConfig); ClusterSetup clusterSetup = getClusterSetup(); @@ -150,20 +150,21 @@ public class ClusterAccessor extends AbstractHelixResource { if (cloudConfigIncluded) { ZNRecord record; try { - record = toZNRecord(content); - } catch (IOException e) { - _logger.error("Failed to deserialize user's input " + content + ", Exception: " + e); - return badRequest("Input is not a vaild ZNRecord!"); - } - try { + record = toZNRecord(cloudConfigManifest); cloudConfig = new CloudConfig.Builder(record).build(); - clusterSetup.addCluster(clusterId, recreateIfExists, cloudConfig); - } catch (Exception ex) { - _logger.error("Error in adding a CloudConfig to cluster: " + clusterId, ex); - return badRequest(ex.getMessage()); + } catch (IOException | HelixException e) { + String errMsg = "Failed to generate a valid CloudConfig from " + cloudConfigManifest; + _logger.error(errMsg, e); + return badRequest(errMsg + " Exception: " + e.getMessage()); } } - clusterSetup.addCluster(clusterId, recreateIfExists, cloudConfig); + + try { + clusterSetup.addCluster(clusterId, recreateIfExists, cloudConfig); + } catch (Exception ex) { + _logger.error("Failed to create cluster {}. Exception: {}.", clusterId, ex); + return serverError(ex); + } return created(); }
