This is an automated email from the ASF dual-hosted git repository.

kishoreg pushed a commit to branch zookeeper-put-api
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git

commit 418b6ad24e53f5a177da5aec586e78ff99e94e33
Author: kishoreg <g.kish...@gmail.com>
AuthorDate: Sun Aug 30 01:01:44 2020 -0700

    Adding api to edit ZK path
---
 .../api/resources/ZookeeperResource.java           | 38 ++++++++++++++++++++++
 .../helix/core/PinotHelixResourceManager.java      |  4 +++
 2 files changed, 42 insertions(+)

diff --git 
a/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/ZookeeperResource.java
 
b/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/ZookeeperResource.java
index 3093052..f4c00ba 100644
--- 
a/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/ZookeeperResource.java
+++ 
b/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/ZookeeperResource.java
@@ -19,6 +19,7 @@
 package org.apache.pinot.controller.api.resources;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
+import com.google.common.base.Charsets;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
@@ -30,11 +31,14 @@ import java.util.Map;
 import javax.inject.Inject;
 import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
+import org.apache.helix.AccessOption;
 import org.apache.helix.ZNRecord;
 import org.apache.helix.manager.zk.ZNRecordSerializer;
 import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
@@ -75,6 +79,40 @@ public class ZookeeperResource {
     return null;
   }
 
+  @PUT
+  @Path("/zk/put")
+  @Produces(MediaType.TEXT_PLAIN)
+  @ApiOperation(value = "Get content of the znode")
+  @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 putData(
+      @ApiParam(value = "Zookeeper Path, must start with /", required = true, 
defaultValue = "/") @QueryParam("path") @DefaultValue("") String path,
+      @ApiParam(value = "Content", required = true) @QueryParam("data") 
@DefaultValue("") String content,
+      @ApiParam(value = "expectedVersion", required = true, defaultValue = 
"-1") @QueryParam("expectedVersion") @DefaultValue("-1") String expectedVersion,
+      @ApiParam(value = "accessOption", required = true, defaultValue = "1") 
@QueryParam("accessOption") @DefaultValue("1") String accessOption) {
+    path = validateAndNormalizeZKPath(path);
+    ZNRecord record = null;
+    if (content != null) {
+      record = (ZNRecord) 
_znRecordSerializer.deserialize(content.getBytes(Charsets.UTF_8));
+    }
+    try {
+      boolean result = pinotHelixResourceManager
+          .setZKData(path, record, Integer.parseInt(expectedVersion), 
Integer.parseInt(accessOption));
+      if (result) {
+        return new SuccessResponse("Successfully Updated path: " + path);
+      } else {
+        throw new ControllerApplicationException(LOGGER, "Failed to update 
path: " + path,
+            Response.Status.INTERNAL_SERVER_ERROR);
+      }
+    } catch (Exception e) {
+      throw new ControllerApplicationException(LOGGER, "Failed to update path: 
" + path,
+          Response.Status.INTERNAL_SERVER_ERROR, e);
+    }
+  }
+
   @GET
   @Path("/zk/ls")
   @Produces(MediaType.APPLICATION_JSON)
diff --git 
a/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
 
b/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
index 7b6c468..f07b6be 100644
--- 
a/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
+++ 
b/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
@@ -1191,6 +1191,10 @@ public class PinotHelixResourceManager {
     }
   }
 
+  public boolean setZKData(String path, ZNRecord record, int expectedVersion, 
int accessOption) {
+    return _helixDataAccessor.getBaseDataAccessor().set(path, record, 
expectedVersion, accessOption);
+  }
+
   public ZNRecord readZKData(String path) {
     return _helixDataAccessor.getBaseDataAccessor().get(path, null, -1);
   }


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

Reply via email to