You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@helix.apache.org by GitBox <gi...@apache.org> on 2019/07/22 21:09:32 UTC

[GitHub] [helix] kaisun2000 commented on a change in pull request #339: Implementation of stateModelDef modification in REST 2.0

kaisun2000 commented on a change in pull request #339: Implementation of stateModelDef modification in REST 2.0
URL: https://github.com/apache/helix/pull/339#discussion_r306034091
 
 

 ##########
 File path: helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java
 ##########
 @@ -431,9 +426,104 @@ public Response getClusterStateModelDefinition(@PathParam("clusterId") String cl
     StateModelDefinition stateModelDef =
         dataAccessor.getProperty(dataAccessor.keyBuilder().stateModelDef(statemodel));
 
+    if (stateModelDef == null) {
+      return  notFound();
+    }
     return JSONRepresentation(stateModelDef.getRecord());
   }
 
+  @PUT
+  @Path("{clusterId}/statemodeldefs/{statemodel}")
+  public Response createClusterStateModelDefinition(
+      @PathParam("clusterId") String clusterId,
+      @PathParam("statemodel") String statemodel,
+      String content
+  ) {
+    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 valid ZNRecord!");
+    }
+    HelixZkClient zkClient = getHelixZkClient();
+    String path = PropertyPathBuilder.stateModelDef(clusterId);
+    try {
+      ZKUtil.createChildren(zkClient, path, record);
+    } catch (Exception e) {
 
 Review comment:
   There could be other exceptions not necessarily as InvalidACLException/InterruptedException/ZkNodeExistsException I guess. The idea is to catch them and log them instead of let the framework handle them, which they would return 500, instead of badRequest, which give an idea as unable to create the znode. 

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


With regards,
Apache Git Services