From 85bd8eef2c4ff190ce3c248979e61280e2b4d5d5 Mon Sep 17 00:00:00 2001 From: Istvan Toth Date: Wed, 19 Jun 2024 10:02:43 +0200 Subject: [PATCH] HBASE-28662 Removing missing scanner via REST should return 404 (#5989) Signed-off-by: Duo Zhang --- .../hadoop/hbase/rest/ScannerInstanceResource.java | 10 ++++++++++ .../apache/hadoop/hbase/rest/TestScannerResource.java | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ScannerInstanceResource.java b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ScannerInstanceResource.java index 951cafc8632a..28ba60fa19b7 100644 --- a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ScannerInstanceResource.java +++ b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ScannerInstanceResource.java @@ -161,6 +161,11 @@ public Response getBinary(final @Context UriInfo uriInfo) { } servlet.getMetrics().incrementRequests(1); try { + if (generator == null) { + servlet.getMetrics().incrementFailedGetRequests(1); + return Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT) + .entity("Not found" + CRLF).build(); + } Cell value = generator.next(); if (value == null) { if (LOG.isTraceEnabled()) { @@ -199,6 +204,11 @@ public Response delete(final @Context UriInfo uriInfo) { return Response.status(Response.Status.FORBIDDEN).type(MIMETYPE_TEXT) .entity("Forbidden" + CRLF).build(); } + if (generator == null) { + servlet.getMetrics().incrementFailedDeleteRequests(1); + return Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT) + .entity("Not found" + CRLF).build(); + } if (ScannerResource.delete(id)) { servlet.getMetrics().incrementSucessfulDeleteRequests(1); } else { diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java index 4e23c708ff1c..46be9a149601 100644 --- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java +++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java @@ -393,4 +393,10 @@ public void testTableScanWithTableDisable() throws IOException { response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF); assertEquals(410, response.getCode()); } + + @Test + public void deleteNonExistent() throws IOException { + Response response = client.delete("/" + TABLE + "/scanner/NONEXISTENT_SCAN"); + assertEquals(404, response.getCode()); + } }