xiangfu0 commented on code in PR #12497:
URL: https://github.com/apache/pinot/pull/12497#discussion_r1502493581
##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/ZookeeperResource.java:
##########
@@ -256,6 +257,56 @@ public SuccessResponse putData(
}
}
+ @POST
+ @Path("/zk/create")
+ @Authorize(targetType = TargetType.CLUSTER, action =
Actions.Cluster.UPDATE_ZNODE)
+ @Authenticate(AccessType.CREATE)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create a node at a given path")
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 204,
message = "No Content"),
+ @ApiResponse(code = 400, message = "Bad Request"), @ApiResponse(code =
500, message = "Internal server error")
+ })
+ public SuccessResponse createNode(
+ @ApiParam(value = "Zookeeper Path, must start with /", required = true)
@QueryParam("path") String path,
+ @ApiParam(value = "Content") @QueryParam("data") @Nullable String data,
+ @ApiParam(value = "ttl", defaultValue = "-1") @QueryParam("ttl")
@DefaultValue("-1") int ttl,
+ @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",
Review Comment:
I feel it's ok to create an empty znode. You can put a warning for this.
##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/ZookeeperResource.java:
##########
@@ -256,6 +257,56 @@ public SuccessResponse putData(
}
}
+ @POST
+ @Path("/zk/create")
+ @Authorize(targetType = TargetType.CLUSTER, action =
Actions.Cluster.UPDATE_ZNODE)
+ @Authenticate(AccessType.CREATE)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create a node at a given path")
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 204,
message = "No Content"),
+ @ApiResponse(code = 400, message = "Bad Request"), @ApiResponse(code =
500, message = "Internal server error")
+ })
+ public SuccessResponse createNode(
Review Comment:
This is pretty much the same as putData API, except ttl option.
Should you add a new parameter like `force` default to `true` into `putData`
API instead of creating a new one?
You can add a new exception into it like `NodeAlreadyExist`.
##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/ZookeeperResource.java:
##########
@@ -256,6 +257,56 @@ public SuccessResponse putData(
}
}
+ @POST
+ @Path("/zk/create")
+ @Authorize(targetType = TargetType.CLUSTER, action =
Actions.Cluster.UPDATE_ZNODE)
+ @Authenticate(AccessType.CREATE)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create a node at a given path")
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 204,
message = "No Content"),
+ @ApiResponse(code = 400, message = "Bad Request"), @ApiResponse(code =
500, message = "Internal server error")
+ })
+ public SuccessResponse createNode(
+ @ApiParam(value = "Zookeeper Path, must start with /", required = true)
@QueryParam("path") String path,
+ @ApiParam(value = "Content") @QueryParam("data") @Nullable String data,
+ @ApiParam(value = "ttl", defaultValue = "-1") @QueryParam("ttl")
@DefaultValue("-1") int ttl,
+ @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);
+ }
+ ZNRecord znRecord;
+ try {
+ znRecord = MAPPER.readValue(data, ZNRecord.class);
+ } catch (Exception e) {
+ throw new ControllerApplicationException(LOGGER, "Failed to deserialize
the data", Response.Status.BAD_REQUEST,
+ e);
+ }
+
+ boolean result;
+ try {
+ result = _pinotHelixResourceManager.createZKNode(path, znRecord,
accessOption, ttl);
+ } catch (Exception e) {
+ throw new ControllerApplicationException(LOGGER, "Failed to create znode
at path: " + path,
+ Response.Status.INTERNAL_SERVER_ERROR, e);
+ }
+ if (result) {
+ return new SuccessResponse("Successfully updated path: " + path);
+ } else {
+ throw new ControllerApplicationException(LOGGER, "ZNode already exists
at path: " + path,
Review Comment:
how do you know is due to znode already exists?
Shall we check the znode existence first then throw or check znode exist
inside the else then throw?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]