jackjlli commented on code in PR #8994:
URL: https://github.com/apache/pinot/pull/8994#discussion_r910467470


##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/ZookeeperResource.java:
##########
@@ -140,6 +141,60 @@ public SuccessResponse delete(
     }
   }
 
+  @PUT
+  @Path("/zk/putChildren")
+  @Authenticate(AccessType.UPDATE)
+  @Produces(MediaType.APPLICATION_JSON)
+  @Consumes(MediaType.APPLICATION_JSON)
+  @ApiOperation(value = "Update the content of multiple znRecord node under 
the same path")
+  @ApiResponses(value = {
+      @ApiResponse(code = 200, message = "Success"),
+      @ApiResponse(code = 404, message = "ZK Path not found"),
+      @ApiResponse(code = 204, message = "No Content"),
+      @ApiResponse(code = 500, message = "Internal server error")
+  })
+  public SuccessResponse putChildren(
+      @ApiParam(value = "Zookeeper path of parent, must start with /", 
required = true) @QueryParam("path") String path,
+      @ApiParam(value = "Content") @QueryParam("data") @Nullable String data,
+      @ApiParam(value = "expectedVersion", defaultValue = "-1") 
@QueryParam("expectedVersion") @DefaultValue("-1")
+          int expectedVersion,
+      @ApiParam(value = "accessOption", defaultValue = "1") 
@QueryParam("accessOption") @DefaultValue("1")
+          int accessOption,
+      @Nullable String payload) {
+
+    path = validateAndNormalizeZKPath(path, false);
+
+    if (StringUtils.isEmpty(data)) {
+      data = payload;
+    }
+    if (StringUtils.isEmpty(data)) {
+      throw new ControllerApplicationException(LOGGER, "Must provide data 
through query parameter or payload",
+          Response.Status.BAD_REQUEST);
+    }
+    List<ZNRecord> znRecords;
+    try {
+      znRecords = MAPPER.readValue(data, new TypeReference<List<ZNRecord>>() { 
});
+    } catch (Exception e) {
+      throw new ControllerApplicationException(LOGGER, "Failed to deserialize 
the data", Response.Status.BAD_REQUEST,

Review Comment:
   nit: it'd be good to print out how the data looks like in the response?



##########
pinot-controller/src/test/java/org/apache/pinot/controller/api/resources/ZookeeperResourceTest.java:
##########
@@ -115,5 +115,23 @@ public void testZookeeperDataEndpoints()
     recordList = 
ZookeeperResource.MAPPER.readValue(result.getBytes(StandardCharsets.UTF_8),
         new TypeReference<List<ZNRecord>>() { });
     Assert.assertEquals(recordList.size(), 2);
+
+    // CASE 4: put all children back into a different path
+    String path4 = path + "/testCase4";
+    params = "path=" + path4 + "&expectedVersion=" + expectedVersion + 
"&accessOption=" + accessOption;
+
+    // validate that zk/putChildren will insert all correctly to another path
+    urlPut = 
TEST_INSTANCE.getControllerRequestURLBuilder().forZkPutChildren(path);
+    String encodedChildrenData = 
ZookeeperResource.MAPPER.writeValueAsString(recordList);
+    result = ControllerTest.sendPutRequest(urlPut + "?" + params, 
encodedChildrenData);
+
+    // validate that zk/getChildren from new path should result in the same 
recordList
+    urlGet = 
TEST_INSTANCE.getControllerRequestURLBuilder().forZkGetChildren(path);
+    result = ControllerTest.sendGetRequest(urlGet);
+
+    List<ZNRecord> newRecordList = 
ZookeeperResource.MAPPER.readValue(result.getBytes(StandardCharsets.UTF_8),

Review Comment:
   nit: rename it to `actualRecordList`.



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

To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to