From 82ca4cc6b48bed4b8f266f383fb329780a0ba6e2 Mon Sep 17 00:00:00 2001 From: David Venable Date: Tue, 23 Jan 2024 09:17:44 -0600 Subject: [PATCH] Log when Data Prepper is shutdown via the HTTP shutdown endpoint. Signed-off-by: David Venable --- .../pipeline/server/ShutdownHandler.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/data-prepper-core/src/main/java/org/opensearch/dataprepper/pipeline/server/ShutdownHandler.java b/data-prepper-core/src/main/java/org/opensearch/dataprepper/pipeline/server/ShutdownHandler.java index d83ce1898a..c204310035 100644 --- a/data-prepper-core/src/main/java/org/opensearch/dataprepper/pipeline/server/ShutdownHandler.java +++ b/data-prepper-core/src/main/java/org/opensearch/dataprepper/pipeline/server/ShutdownHandler.java @@ -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); @@ -27,8 +27,8 @@ 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(); @@ -36,9 +36,10 @@ public void handle(HttpExchange exchange) throws IOException { } 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 {