Jackie-Jiang commented on a change in pull request #5902: URL: https://github.com/apache/incubator-pinot/pull/5902#discussion_r473459274
########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotInstanceRestletResource.java ########## @@ -196,4 +197,25 @@ public SuccessResponse updateInstance( } return new SuccessResponse("Instance successfully updated"); } + + @PUT + @Path("/instances/{instanceName}/updateTags") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Update the tags of the specified instance", consumes = MediaType.APPLICATION_JSON, notes = "Update the tags of the specified instance") + @ApiResponses(value = {@ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 500, message = "Internal error")}) + public SuccessResponse updateInstanceTags( + @ApiParam(value = "Instance name", required = true, example = "Server_a.b.com_20000 | Broker_my.broker.com_30000") @PathParam("instanceName") String instanceName, + @ApiParam(value = "Comma separated tags list", required = true) @QueryParam("tags") String tags) { + LOGGER.info("Instance update request received for instance: {}", instanceName); Review comment: Also log the tags ########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotInstanceRestletResource.java ########## @@ -196,4 +197,25 @@ public SuccessResponse updateInstance( } return new SuccessResponse("Instance successfully updated"); } + + @PUT + @Path("/instances/{instanceName}/updateTags") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Update the tags of the specified instance", consumes = MediaType.APPLICATION_JSON, notes = "Update the tags of the specified instance") + @ApiResponses(value = {@ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 500, message = "Internal error")}) + public SuccessResponse updateInstanceTags( + @ApiParam(value = "Instance name", required = true, example = "Server_a.b.com_20000 | Broker_my.broker.com_30000") @PathParam("instanceName") String instanceName, + @ApiParam(value = "Comma separated tags list", required = true) @QueryParam("tags") String tags) { + LOGGER.info("Instance update request received for instance: {}", instanceName); + if (tags == null) { + throw new ControllerApplicationException(LOGGER, "Must provide tags to update", Response.Status.BAD_REQUEST); + } + PinotResourceManagerResponse response = pinotHelixResourceManager.updateInstanceTags(instanceName, tags); + if (!response.isSuccessful()) { + throw new ControllerApplicationException(LOGGER, + "Failure to update instance tags. Reason: " + response.getMessage(), Response.Status.INTERNAL_SERVER_ERROR); Review comment: If the instance does not exist, we should return `BAD_REQUEST` ########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java ########## @@ -399,6 +400,28 @@ public synchronized PinotResourceManagerResponse updateInstance(String instanceI } } + /** + * Updates the tags of the specified instance ID + */ + public synchronized PinotResourceManagerResponse updateInstanceTags(String instanceIdToUpdate, String tags) { + InstanceConfig instanceConfig = getHelixInstanceConfig(instanceIdToUpdate); + if (instanceConfig == null) { + return PinotResourceManagerResponse.failure("Instance " + instanceIdToUpdate + " does not exists"); + } + String[] newTags = tags.split(","); + List<String> existingTags = Lists.newArrayList(instanceConfig.getTags()); + for (String tag : existingTags) { + instanceConfig.removeTag(tag); + } + for (String tag : newTags) { + instanceConfig.addTag(tag); + } Review comment: Can be simplified as following (not sure why Helix does not provide `setTags()`), also `StringUtils.split()` has better performance than `String.split()` which takes a regex ```suggestion List<String> tagList = Arrays.asList(StringUtils.split(tags, ',')); instanceConfig.getRecord().setListField(InstanceConfig.InstanceConfigProperty.TAG_LIST.name(), tagList); ``` ########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/ControllerRequestURLBuilder.java ########## @@ -53,6 +53,10 @@ public String forInstance(String instanceName) { return StringUtil.join("/", _baseUrl, "instances", instanceName); } + public String forInstanceUpdateTags(String instanceName, String tagsList) { Review comment: Pass in a `List<String>` so that it is easier to use? ---------------------------------------------------------------- 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 --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org