[GitHub] [helix] dasahcc commented on a change in pull request #675: Add REST API for Cluster Creation with CloudConfig

2020-01-15 Thread GitBox
dasahcc commented on a change in pull request #675: Add REST API for Cluster 
Creation with CloudConfig
URL: https://github.com/apache/helix/pull/675#discussion_r367131650
 
 

 ##
 File path: 
helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java
 ##
 @@ -514,6 +533,119 @@ private boolean doesClusterExist(String cluster) {
 return ZKUtil.isClusterSetup(cluster, zkClient);
   }
 
+  @PUT
+  @Path("{clusterId}/cloudconfig")
+  public Response addCloudConfig(@PathParam("clusterId") String clusterId, 
String content) {
+
+HelixZkClient zkClient = getHelixZkClient();
+if (!ZKUtil.isClusterSetup(clusterId, zkClient)) {
+  return notFound("Cluster is not properly setup!");
+}
+
+HelixAdmin admin = getHelixAdmin();
+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 {
+  CloudConfig cloudConfig = new CloudConfig.Builder(record).build();
+  admin.addCloudConfig(clusterId, cloudConfig);
+} catch (HelixException ex) {
+  _logger.error("Error in adding a CloudConfig to cluster: " + clusterId, 
ex);
+  return badRequest(ex.getMessage());
+} catch (Exception ex) {
+  _logger.error("Cannot add CloudConfig to cluster: " + clusterId, ex);
+  return badRequest(ex.getMessage());
 
 Review comment:
   This is not badRequest. It may be something related to internal server 
error. 


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org
For additional commands, e-mail: reviews-h...@helix.apache.org



[GitHub] [helix] dasahcc commented on a change in pull request #675: Add REST API for Cluster Creation with CloudConfig

2020-01-07 Thread GitBox
dasahcc commented on a change in pull request #675: Add REST API for Cluster 
Creation with CloudConfig
URL: https://github.com/apache/helix/pull/675#discussion_r363901582
 
 

 ##
 File path: 
helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/CloudAccessor.java
 ##
 @@ -0,0 +1,152 @@
+package org.apache.helix.rest.server.resources.helix;
+
+/*
+ * 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.io.IOException;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+import org.apache.helix.ConfigAccessor;
+import org.apache.helix.HelixAdmin;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.manager.zk.ZKUtil;
+import org.apache.helix.manager.zk.client.HelixZkClient;
+import org.apache.helix.model.CloudConfig;
+import org.apache.helix.model.HelixConfigScope;
+import org.apache.helix.model.builder.HelixConfigScopeBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Path("/clusters")
+public class CloudAccessor extends AbstractHelixResource {
+  private static Logger _logger = 
LoggerFactory.getLogger(CloudAccessor.class.getName());
+
+  @PUT
+  @Path("{clusterId}/cloudconfig")
+  public Response addCloudConfig(@PathParam("clusterId") String clusterId, 
String content) {
+
+HelixZkClient zkClient = getHelixZkClient();
+if (!ZKUtil.isClusterSetup(clusterId, zkClient)) {
+  return notFound();
+}
+
+HelixAdmin admin = getHelixAdmin();
+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 {
+  CloudConfig cloudConfig = new CloudConfig.Builder(record).build();
+  admin.addCloudConfig(clusterId, cloudConfig);
+} catch (Exception ex) {
 
 Review comment:
   Let's have another catch for HelixException to differentiate it with other 
general error. It could be validation exception.
   
   Same as following places.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org
For additional commands, e-mail: reviews-h...@helix.apache.org



[GitHub] [helix] dasahcc commented on a change in pull request #675: Add REST API for Cluster Creation with CloudConfig

2020-01-07 Thread GitBox
dasahcc commented on a change in pull request #675: Add REST API for Cluster 
Creation with CloudConfig
URL: https://github.com/apache/helix/pull/675#discussion_r363902937
 
 

 ##
 File path: 
helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/CloudAccessor.java
 ##
 @@ -0,0 +1,152 @@
+package org.apache.helix.rest.server.resources.helix;
+
+/*
+ * 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.io.IOException;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+import org.apache.helix.ConfigAccessor;
+import org.apache.helix.HelixAdmin;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.manager.zk.ZKUtil;
+import org.apache.helix.manager.zk.client.HelixZkClient;
+import org.apache.helix.model.CloudConfig;
+import org.apache.helix.model.HelixConfigScope;
+import org.apache.helix.model.builder.HelixConfigScopeBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Path("/clusters")
+public class CloudAccessor extends AbstractHelixResource {
+  private static Logger _logger = 
LoggerFactory.getLogger(CloudAccessor.class.getName());
+
+  @PUT
+  @Path("{clusterId}/cloudconfig")
+  public Response addCloudConfig(@PathParam("clusterId") String clusterId, 
String content) {
+
+HelixZkClient zkClient = getHelixZkClient();
+if (!ZKUtil.isClusterSetup(clusterId, zkClient)) {
+  return notFound();
+}
+
+HelixAdmin admin = getHelixAdmin();
+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 {
+  CloudConfig cloudConfig = new CloudConfig.Builder(record).build();
+  admin.addCloudConfig(clusterId, cloudConfig);
+} catch (Exception ex) {
+  _logger.error("Error in adding a CloudConfig to cluster: " + clusterId, 
ex);
+  return badRequest(ex.getMessage());
+}
+
+return OK();
+  }
+
+  @GET
+  @Path("{clusterId}/cloudconfig")
+  public Response getCloudConfig(@PathParam("clusterId") String clusterId) {
+
+HelixZkClient zkClient = getHelixZkClient();
+if (!ZKUtil.isClusterSetup(clusterId, zkClient)) {
+  return notFound();
+}
+
+ConfigAccessor configAccessor = new ConfigAccessor(zkClient);
+CloudConfig cloudConfig = configAccessor.getCloudConfig(clusterId);
+
+if (cloudConfig != null) {
+  return JSONRepresentation(cloudConfig.getRecord());
+}
+
+return notFound();
+  }
+
+  @POST
+  @Path("{clusterId}/cloudconfig")
+  public Response updateCloudConfig(@PathParam("clusterId") String clusterId,
+  @QueryParam("command") String commandStr, String content) {
+
+HelixZkClient zkClient = getHelixZkClient();
+if (!ZKUtil.isClusterSetup(clusterId, zkClient)) {
+  return notFound();
+}
+
+// Here to update cloud config
+Command command;
+if (commandStr == null || commandStr.isEmpty()) {
+  command = Command.update; // Default behavior
+} else {
+  try {
+command = getCommand(commandStr);
+  } catch (HelixException ex) {
+return badRequest(ex.getMessage());
+  }
+}
+
+HelixAdmin admin = getHelixAdmin();
+try {
+  switch (command) {
+case delete: {
+  admin.removeCloudConfig(clusterId);
+}
+break;
+case update: {
+  ZNRecord record;
 
 Review comment:
   move record read before command switch.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: 

[GitHub] [helix] dasahcc commented on a change in pull request #675: Add REST API for Cluster Creation with CloudConfig

2020-01-07 Thread GitBox
dasahcc commented on a change in pull request #675: Add REST API for Cluster 
Creation with CloudConfig
URL: https://github.com/apache/helix/pull/675#discussion_r363902396
 
 

 ##
 File path: 
helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/CloudAccessor.java
 ##
 @@ -0,0 +1,152 @@
+package org.apache.helix.rest.server.resources.helix;
+
+/*
+ * 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.io.IOException;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+import org.apache.helix.ConfigAccessor;
+import org.apache.helix.HelixAdmin;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.manager.zk.ZKUtil;
+import org.apache.helix.manager.zk.client.HelixZkClient;
+import org.apache.helix.model.CloudConfig;
+import org.apache.helix.model.HelixConfigScope;
+import org.apache.helix.model.builder.HelixConfigScopeBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Path("/clusters")
+public class CloudAccessor extends AbstractHelixResource {
+  private static Logger _logger = 
LoggerFactory.getLogger(CloudAccessor.class.getName());
+
+  @PUT
+  @Path("{clusterId}/cloudconfig")
+  public Response addCloudConfig(@PathParam("clusterId") String clusterId, 
String content) {
+
+HelixZkClient zkClient = getHelixZkClient();
+if (!ZKUtil.isClusterSetup(clusterId, zkClient)) {
 
 Review comment:
   This is not a good practice here. User may get confused with 404 and without 
any other information here. Let's have clear message that cluster is not 
properly setup.
   
   Same as following places.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org
For additional commands, e-mail: reviews-h...@helix.apache.org



[GitHub] [helix] dasahcc commented on a change in pull request #675: Add REST API for Cluster Creation with CloudConfig

2020-01-07 Thread GitBox
dasahcc commented on a change in pull request #675: Add REST API for Cluster 
Creation with CloudConfig
URL: https://github.com/apache/helix/pull/675#discussion_r363897194
 
 

 ##
 File path: 
helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/CloudAccessor.java
 ##
 @@ -0,0 +1,152 @@
+package org.apache.helix.rest.server.resources.helix;
+
+/*
+ * 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.io.IOException;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+import org.apache.helix.ConfigAccessor;
+import org.apache.helix.HelixAdmin;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.manager.zk.ZKUtil;
+import org.apache.helix.manager.zk.client.HelixZkClient;
+import org.apache.helix.model.CloudConfig;
+import org.apache.helix.model.HelixConfigScope;
+import org.apache.helix.model.builder.HelixConfigScopeBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Path("/clusters")
+public class CloudAccessor extends AbstractHelixResource {
+  private static Logger _logger = 
LoggerFactory.getLogger(CloudAccessor.class.getName());
+
+  @PUT
+  @Path("{clusterId}/cloudconfig")
+  public Response addCloudConfig(@PathParam("clusterId") String clusterId, 
String content) {
+
+HelixZkClient zkClient = getHelixZkClient();
+if (!ZKUtil.isClusterSetup(clusterId, zkClient)) {
+  return notFound();
+}
+
+HelixAdmin admin = getHelixAdmin();
+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!");
+}
 
 Review comment:
   Let's make it as a general function in AbstractResourceAccessor since it has 
been widely used in the code.
   
   Same as following places


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org
For additional commands, e-mail: reviews-h...@helix.apache.org



[GitHub] [helix] dasahcc commented on a change in pull request #675: Add REST API for Cluster Creation with CloudConfig

2020-01-07 Thread GitBox
dasahcc commented on a change in pull request #675: Add REST API for Cluster 
Creation with CloudConfig
URL: https://github.com/apache/helix/pull/675#discussion_r363896739
 
 

 ##
 File path: 
helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java
 ##
 @@ -132,18 +133,42 @@ public Response getClusterInfo(@PathParam("clusterId") 
String clusterId) {
   @PUT
   @Path("{clusterId}")
   public Response createCluster(@PathParam("clusterId") String clusterId,
-  @DefaultValue("false") @QueryParam("recreate") String recreate) {
+  @DefaultValue("false") @QueryParam("recreate") String recreate,
+  @DefaultValue("false") @QueryParam("addCloudConfig") String 
addCloudConfig,
+  String content) {
+
 boolean recreateIfExists = Boolean.valueOf(recreate);
+boolean cloudConfigIncluded = Boolean.valueOf(addCloudConfig);
+
+
 ClusterSetup clusterSetup = getClusterSetup();
 
-try {
-  clusterSetup.addCluster(clusterId, recreateIfExists);
-} catch (Exception ex) {
-  _logger.error("Failed to create cluster " + clusterId + ", exception: " 
+ ex);
-  return serverError(ex);
-}
+if (!cloudConfigIncluded) {
 
 Review comment:
   Let's reorganize the code. There are duplicated pieces.
   
   You can:
   
   1. Define CloudConfig object
   2. Create this object if enabled and move this piece of code to a separate 
function. Otherwise, keep it as null.
   3. Call the addCluster with CloudConfig object.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org
For additional commands, e-mail: reviews-h...@helix.apache.org



[GitHub] [helix] dasahcc commented on a change in pull request #675: Add REST API for Cluster Creation with CloudConfig

2020-01-07 Thread GitBox
dasahcc commented on a change in pull request #675: Add REST API for Cluster 
Creation with CloudConfig
URL: https://github.com/apache/helix/pull/675#discussion_r363887244
 
 

 ##
 File path: 
helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/CloudAccessor.java
 ##
 @@ -0,0 +1,152 @@
+package org.apache.helix.rest.server.resources.helix;
+
+/*
+ * 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.io.IOException;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+import org.apache.helix.ConfigAccessor;
+import org.apache.helix.HelixAdmin;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.manager.zk.ZKUtil;
+import org.apache.helix.manager.zk.client.HelixZkClient;
+import org.apache.helix.model.CloudConfig;
+import org.apache.helix.model.HelixConfigScope;
+import org.apache.helix.model.builder.HelixConfigScopeBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Path("/clusters")
 
 Review comment:
   Does this work? It conflict with ClusterAccessor. It would be better to 
merge the logic into ClusterAccessor.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org
For additional commands, e-mail: reviews-h...@helix.apache.org