HBASE-17603 REST API for scan should return 404 when table does not exist

This commit is contained in:
tedyu 2017-02-13 08:45:24 -08:00
parent 810427b950
commit 44f063350b
3 changed files with 20 additions and 3 deletions

View File

@ -33,11 +33,11 @@ import javax.ws.rs.core.UriInfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.rest.model.CellModel;
import org.apache.hadoop.hbase.rest.model.CellSetModel;
import org.apache.hadoop.hbase.rest.model.RowModel;
@ -106,6 +106,14 @@ public class ScannerInstanceResource extends ResourceBase {
return Response.status(Response.Status.GONE)
.type(MIMETYPE_TEXT).entity("Gone" + CRLF)
.build();
} catch (IllegalArgumentException e) {
Throwable t = e.getCause();
if (t instanceof TableNotFoundException) {
return Response.status(Response.Status.NOT_FOUND)
.type(MIMETYPE_TEXT).entity("Not found" + CRLF)
.build();
}
throw e;
}
if (value == null) {
if (LOG.isTraceEnabled()) {

View File

@ -24,10 +24,12 @@ import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.TableNotEnabledException;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.UnknownScannerException;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
@ -169,6 +171,10 @@ public class ScannerResultGenerator extends ResultGenerator {
result = scanner.next();
} catch (UnknownScannerException e) {
throw new IllegalArgumentException(e);
} catch (TableNotEnabledException tnee) {
throw new IllegalStateException(tnee);
} catch (TableNotFoundException tnfe) {
throw new IllegalArgumentException(tnfe);
} catch (IOException e) {
LOG.error(StringUtils.stringifyException(e));
}

View File

@ -358,6 +358,9 @@ public class TestScannerResource {
byte[] body = Bytes.toBytes(writer.toString());
Response response = client.put("/" + NONEXISTENT_TABLE +
"/scanner", Constants.MIMETYPE_XML, body);
String scannerURI = response.getLocation();
assertNotNull(scannerURI);
response = client.get(scannerURI, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 404);
}