You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by vj...@apache.org on 2020/09/19 14:31:48 UTC

[hbase] branch branch-1 updated: HBASE-24481 REST - Fix incorrect response code of get-regions in rest api

This is an automated email from the ASF dual-hosted git repository.

vjasani pushed a commit to branch branch-1
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-1 by this push:
     new 20d0a32  HBASE-24481 REST - Fix incorrect response code of get-regions in rest api
20d0a32 is described below

commit 20d0a3269154b3053aec46d68e2dd055d758e69f
Author: KevinSmile <ke...@hotmail.com>
AuthorDate: Sat Sep 19 19:45:10 2020 +0530

    HBASE-24481 REST - Fix incorrect response code of get-regions in rest api
    
    Closes #2425
    
    Signed-off-by: Viraj Jasani <vj...@apache.org>
---
 .../main/java/org/apache/hadoop/hbase/rest/RegionsResource.java  | 3 +++
 .../java/org/apache/hadoop/hbase/rest/TestTableResource.java     | 9 +++++++++
 2 files changed, 12 insertions(+)

diff --git a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java
index 100dfd5..abb3aac 100644
--- a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java
+++ b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java
@@ -77,6 +77,9 @@ public class RegionsResource extends ResourceBase {
     servlet.getMetrics().incrementRequests(1);
     try {
       TableName tableName = TableName.valueOf(tableResource.getName());
+      if (!tableResource.exists()) {
+        throw new TableNotFoundException(tableName);
+      }
       TableInfoModel model = new TableInfoModel(tableName.getNameAsString());
 
       Connection connection = ConnectionFactory.createConnection(servlet.getConfiguration());
diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java
index 2551ee8..443ebe3 100644
--- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java
+++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java
@@ -257,4 +257,13 @@ public class TestTableResource {
     checkTableInfo(model);
   }
 
+  @Test
+  public void testTableNotFound() throws IOException {
+    String notExistTable = "notexist";
+    Response response1 = client.get("/" + notExistTable + "/schema", Constants.MIMETYPE_JSON);
+    assertEquals(404, response1.getCode());
+    Response response2 = client.get("/" + notExistTable + "/regions", Constants.MIMETYPE_XML);
+    assertEquals(404, response2.getCode());
+  }
+
 }