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:28:39 UTC

[hbase] branch branch-2.2 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-2.2
in repository https://gitbox.apache.org/repos/asf/hbase.git


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

commit ddd30d70b52e60033b8c293a1244041f4020d24b
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 8e93acf..e6483c3 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
@@ -76,6 +76,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 7cbc631..b069693 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
@@ -261,5 +261,14 @@ 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());
+  }
+
 }