Skip to content

Commit

Permalink
Log when Data Prepper is shutdown via the HTTP shutdown endpoint. (#4001
Browse files Browse the repository at this point in the history
)

Signed-off-by: David Venable <dlv@amazon.com>
  • Loading branch information
dlvenable authored Jan 23, 2024
1 parent 878c443 commit 191a514
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

package org.opensearch.dataprepper.pipeline.server;

import org.opensearch.dataprepper.DataPrepper;
import javax.ws.rs.HttpMethod;
import java.io.IOException;
import java.net.HttpURLConnection;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import org.opensearch.dataprepper.DataPrepper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.HttpMethod;
import java.io.IOException;
import java.net.HttpURLConnection;

/**
* HttpHandler to handle requests to shut down the data prepper instance
*/
public class ShutdownHandler implements HttpHandler {

private final DataPrepper dataPrepper;
private static final Logger LOG = LoggerFactory.getLogger(ShutdownHandler.class);

Expand All @@ -27,18 +27,19 @@ public ShutdownHandler(final DataPrepper dataPrepper) {
}

@Override
public void handle(HttpExchange exchange) throws IOException {
String requestMethod = exchange.getRequestMethod();
public void handle(final HttpExchange exchange) throws IOException {
final String requestMethod = exchange.getRequestMethod();
if (!requestMethod.equals(HttpMethod.POST)) {
exchange.sendResponseHeaders(HttpURLConnection.HTTP_BAD_METHOD, 0);
exchange.getResponseBody().close();
return;
}

try {
LOG.info("Received HTTP shutdown request to shutdown Data Prepper. Shutdown pipelines and server.");
dataPrepper.shutdownPipelines();
exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, 0);
} catch (Exception e) {
} catch (final Exception e) {
LOG.error("Caught exception shutting down data prepper", e);
exchange.sendResponseHeaders(HttpURLConnection.HTTP_INTERNAL_ERROR, 0);
} finally {
Expand Down

0 comments on commit 191a514

Please sign in to comment.