use of org.apache.bookkeeper.bookie.Cookie in project bookkeeper by apache.
the class RecoveryBookieService method handle.
@Override
public HttpServiceResponse handle(HttpServiceRequest request) throws Exception {
HttpServiceResponse response = new HttpServiceResponse();
String requestBody = request.getBody();
RecoveryRequestJsonBody requestJsonBody;
if (requestBody == null) {
response.setCode(HttpServer.StatusCode.NOT_FOUND);
response.setBody("No request body provide.");
return response;
}
try {
requestJsonBody = JsonUtil.fromJson(requestBody, RecoveryRequestJsonBody.class);
LOG.debug("bookie_src: [" + requestJsonBody.bookieSrc.get(0) + "], delete_cookie: [" + requestJsonBody.deleteCookie + "]");
} catch (JsonUtil.ParseJsonException e) {
LOG.error("Meet Exception: ", e);
response.setCode(HttpServer.StatusCode.NOT_FOUND);
response.setBody("ERROR parameters: " + e.getMessage());
return response;
}
if (HttpServer.Method.PUT == request.getMethod() && !requestJsonBody.bookieSrc.isEmpty()) {
runFunctionWithRegistrationManager(conf, rm -> {
String[] bookieSrcString = requestJsonBody.bookieSrc.get(0).split(":");
BookieSocketAddress bookieSrc = new BookieSocketAddress(bookieSrcString[0], Integer.parseInt(bookieSrcString[1]));
boolean deleteCookie = requestJsonBody.deleteCookie;
executor.execute(() -> {
try {
LOG.info("Start recovering bookie.");
bka.recoverBookieData(bookieSrc);
if (deleteCookie) {
Versioned<Cookie> cookie = Cookie.readFromRegistrationManager(rm, bookieSrc);
cookie.getValue().deleteFromRegistrationManager(rm, bookieSrc, cookie.getVersion());
}
LOG.info("Complete recovering bookie");
} catch (Exception e) {
LOG.error("Exception occurred while recovering bookie", e);
}
});
return null;
});
response.setCode(HttpServer.StatusCode.OK);
response.setBody("Success send recovery request command.");
return response;
} else {
response.setCode(HttpServer.StatusCode.NOT_FOUND);
response.setBody("Not found method. Should be PUT method");
return response;
}
}
Aggregations