liangyepianzhou commented on code in PR #4541:
URL: https://github.com/apache/bookkeeper/pull/4541#discussion_r1955660854
##########
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:
Why not add a method to add a cookie while we have a method to delete a
cookie.
--
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]