HBASE-20614 REST scan API with incorrect filter text file throws HTTP 503 Service Unavailable error
Signed-off-by: Andrew Purtell <apurtell@apache.org>
This commit is contained in:
parent
239d12dae8
commit
1120f33c38
|
@ -38,6 +38,10 @@ import javax.ws.rs.core.UriInfo;
|
|||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
|
||||
import org.apache.hadoop.hbase.TableNotFoundException;
|
||||
import org.apache.hadoop.hbase.filter.Filter;
|
||||
import org.apache.hadoop.hbase.rest.model.ScannerModel;
|
||||
|
@ -108,12 +112,14 @@ public class ScannerResource extends ResourceBase {
|
|||
servlet.getMetrics().incrementSucessfulPutRequests(1);
|
||||
return Response.created(uri).build();
|
||||
} catch (Exception e) {
|
||||
LOG.error("Exception occured while processing " + uriInfo.getAbsolutePath() + " : ", e);
|
||||
servlet.getMetrics().incrementFailedPutRequests(1);
|
||||
if (e instanceof TableNotFoundException) {
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
.type(MIMETYPE_TEXT).entity("Not found" + CRLF)
|
||||
.build();
|
||||
} else if (e instanceof RuntimeException) {
|
||||
} else if (e instanceof RuntimeException
|
||||
|| e instanceof JsonMappingException | e instanceof JsonParseException) {
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
|
||||
.build();
|
||||
|
|
|
@ -21,12 +21,17 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||
import org.apache.hadoop.hbase.rest.ScannerResultGenerator;
|
||||
import org.apache.hadoop.hbase.testclassification.RestTests;
|
||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
|
||||
@Category({RestTests.class, SmallTests.class})
|
||||
public class TestScannerModel extends TestModelBase<ScannerModel> {
|
||||
|
||||
|
@ -117,4 +122,33 @@ public class TestScannerModel extends TestModelBase<ScannerModel> {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExistingFilter() throws Exception {
|
||||
final String CORRECT_FILTER = "{\"type\": \"PrefixFilter\", \"value\": \"cg==\"}";
|
||||
verifyException(CORRECT_FILTER);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNonExistingFilter() throws Exception {
|
||||
final String UNKNOWN_FILTER = "{\"type\": \"UnknownFilter\", \"value\": \"cg==\"}";
|
||||
verifyException(UNKNOWN_FILTER);
|
||||
}
|
||||
|
||||
@Test(expected = JsonMappingException.class)
|
||||
public void testIncorrectFilterThrowsJME() throws Exception {
|
||||
final String JME_FILTER = "{\"invalid_tag\": \"PrefixFilter\", \"value\": \"cg==\"}";
|
||||
verifyException(JME_FILTER);
|
||||
}
|
||||
|
||||
@Test(expected = JsonParseException.class)
|
||||
public void tesIncorrecttFilterThrowsJPE() throws Exception {
|
||||
final String JPE_FILTER = "{\"type\": \"PrefixFilter\",, \"value\": \"cg==\"}";
|
||||
verifyException(JPE_FILTER);
|
||||
}
|
||||
|
||||
private void verifyException(final String FILTER) throws Exception {
|
||||
ScannerModel model = new ScannerModel();
|
||||
model.setFilter(FILTER);
|
||||
ScannerResultGenerator.buildFilterFromModel(model);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue