pkuwm commented on a change in pull request #797: Add REST API to add, remove
and update CustomizedStateAggregationConfig
URL: https://github.com/apache/helix/pull/797#discussion_r382872659
##########
File path:
helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java
##########
@@ -267,6 +268,129 @@ public Response getClusterConfig(@PathParam("clusterId")
String clusterId) {
return JSONRepresentation(config.getRecord());
}
+
+ @PUT
+ @Path("{clusterId}/customizedstateaggregationconfig")
+ public Response addCustomizedStateAggregationConfig(@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 {
+ CustomizedStateAggregationConfig customizedStateAggregationConfig =
+ new CustomizedStateAggregationConfig.Builder(record).build();
+ admin.addCustomizedStateAggregationConfig(clusterId,
customizedStateAggregationConfig);
+ } catch (HelixException ex) {
+ _logger.error("Error in adding a CustomizedStateAggregationConfig to
cluster: " + clusterId,
+ ex);
+ return badRequest(ex.getMessage());
+ } catch (Exception ex) {
+ _logger.error("Cannot add CustomizedStateAggregationConfig to cluster: "
+ clusterId, ex);
+ return serverError(ex);
+ }
+
+ return OK();
+ }
+
+ @DELETE
+ @Path("{clusterId}/customizedstateaggregationconfig")
+ public Response
removeCustomizedStateAggregationConfig(@PathParam("clusterId") String
clusterId) {
+ HelixZkClient zkClient = getHelixZkClient();
+ if (!ZKUtil.isClusterSetup(clusterId, zkClient)) {
+ return notFound("Cluster is not properly setup!");
+ }
+
+ HelixAdmin admin = getHelixAdmin();
+ try {
+ admin.removeCustomizedStateAggregationConfig(clusterId);
+ } catch (HelixException ex) {
+ _logger.error("Error in removing CustomizedStateAggregationConfig to
cluster: " + clusterId,
+ ex);
+ return badRequest(ex.getMessage());
+ } catch (Exception ex) {
+ _logger.error("Cannot remove CustomizedStateAggregationConfig to
cluster: " + clusterId, ex);
+ return serverError(ex);
+ }
+
+ return OK();
+ }
+
+ @GET
+ @Path("{clusterId}/customizedstateaggregationconfig")
+ public Response getCustomizedStateAggregationConfig(@PathParam("clusterId")
String clusterId) {
+ HelixZkClient zkClient = getHelixZkClient();
+ if (!ZKUtil.isClusterSetup(clusterId, zkClient)) {
+ return notFound();
+ }
+
+ ConfigAccessor configAccessor = getConfigAccessor();
+ CustomizedStateAggregationConfig customizedStateAggregationConfig =
+ configAccessor.getCustomizedStateAggregationConfig(clusterId);
+
+ if (customizedStateAggregationConfig != null) {
+ return JSONRepresentation(customizedStateAggregationConfig.getRecord());
+ }
+
+ return notFound();
+ }
+
+ @POST
+ @Path("{clusterId}/customizedstateaggregationconfig")
+ public Response
updateCustomizedStateAggregationConfig(@PathParam("clusterId") String clusterId,
+ @QueryParam("command") String commandStr, @QueryParam("type") String
type) {
+
+ 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: {
Review comment:
I would remove `{}` for `case` blocks.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]