StevenLuMT commented on code in PR #4541:
URL: https://github.com/apache/bookkeeper/pull/4541#discussion_r1955442058


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/server/http/service/BookieCookieService.java:
##########
@@ -0,0 +1,67 @@
+package org.apache.bookkeeper.server.http.service;
+
+import java.net.UnknownHostException;
+import java.util.Map;
+import org.apache.bookkeeper.bookie.BookieException;
+import org.apache.bookkeeper.bookie.Cookie;
+import org.apache.bookkeeper.conf.ServerConfiguration;
+import org.apache.bookkeeper.http.HttpServer;
+import org.apache.bookkeeper.http.service.HttpEndpointService;
+import org.apache.bookkeeper.http.service.HttpServiceRequest;
+import org.apache.bookkeeper.http.service.HttpServiceResponse;
+import org.apache.bookkeeper.meta.MetadataDrivers;
+import org.apache.bookkeeper.net.BookieId;
+import org.apache.bookkeeper.net.BookieSocketAddress;
+import org.apache.bookkeeper.versioning.LongVersion;
+import org.apache.bookkeeper.versioning.Versioned;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BookieCookieService implements HttpEndpointService {
+    static final Logger LOG = 
LoggerFactory.getLogger(BookieCookieService.class);
+    private final ServerConfiguration conf;
+
+    public BookieCookieService(ServerConfiguration conf) {
+        this.conf = conf;
+    }
+
+    @Override
+    public HttpServiceResponse handle(HttpServiceRequest request) throws 
Exception {
+        Map<String, String> params = request.getParams();
+        if (params == null || !params.containsKey("bookie_id")) {
+            return new HttpServiceResponse("Not found bookie id. Should 
provide bookie_id=<ip:port>",
+                    HttpServer.StatusCode.BAD_REQUEST);
+        }
+
+        String bookieIdStr = params.get("bookie_id");
+        try {
+            new BookieSocketAddress(bookieIdStr);
+        } catch (UnknownHostException nhe) {
+            return new HttpServiceResponse("Illegal bookie id. Should provide 
bookie_id=<ip:port>",
+                    HttpServer.StatusCode.BAD_REQUEST);
+        }
+
+        BookieId bookieId = BookieId.parse(bookieIdStr);
+        return MetadataDrivers.runFunctionWithRegistrationManager(conf, 
registrationManager -> {
+            try {
+                switch (request.getMethod()) {
+                    case GET:
+                        Versioned<Cookie> cookie = 
Cookie.readFromRegistrationManager(registrationManager, bookieId);
+                        return new HttpServiceResponse(cookie.toString(), 
HttpServer.StatusCode.OK);
+                    case DELETE:

Review Comment:
   There is nothing wrong with adding new interfaces, 
   
   but I think deleting cookies is a bit risky and does not comply with data 
integrity specifications. Although this is available in the old Command 
command, I suggest you still go through the node offline process 
`./bin/bookkeeper shell decommissionbookie [-bookieid <bookieaddress>]`



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

Reply via email to