Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log when Data Prepper is shutdown via the HTTP shutdown endpoint. #4001

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading