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:
Nihal Jain 2018-05-30 18:09:41 +05:30 committed by Andrew Purtell
parent cc6fc1f04f
commit 16af11bb10
2 changed files with 41 additions and 1 deletions

View File

@ -38,6 +38,10 @@ import javax.ws.rs.core.UriInfo;
import org.apache.yetus.audience.InterfaceAudience; import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.TableNotFoundException;
import org.apache.hadoop.hbase.filter.Filter; import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.rest.model.ScannerModel; import org.apache.hadoop.hbase.rest.model.ScannerModel;
@ -108,12 +112,14 @@ public class ScannerResource extends ResourceBase {
servlet.getMetrics().incrementSucessfulPutRequests(1); servlet.getMetrics().incrementSucessfulPutRequests(1);
return Response.created(uri).build(); return Response.created(uri).build();
} catch (Exception e) { } catch (Exception e) {
LOG.error("Exception occured while processing " + uriInfo.getAbsolutePath() + " : ", e);
servlet.getMetrics().incrementFailedPutRequests(1); servlet.getMetrics().incrementFailedPutRequests(1);
if (e instanceof TableNotFoundException) { if (e instanceof TableNotFoundException) {
return Response.status(Response.Status.NOT_FOUND) return Response.status(Response.Status.NOT_FOUND)
.type(MIMETYPE_TEXT).entity("Not found" + CRLF) .type(MIMETYPE_TEXT).entity("Not found" + CRLF)
.build(); .build();
} else if (e instanceof RuntimeException) { } else if (e instanceof RuntimeException
|| e instanceof JsonMappingException | e instanceof JsonParseException) {
return Response.status(Response.Status.BAD_REQUEST) return Response.status(Response.Status.BAD_REQUEST)
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF) .type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
.build(); .build();

View File

@ -21,12 +21,17 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import org.apache.hadoop.hbase.HBaseClassTestRule; 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.RestTests;
import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
@Category({RestTests.class, SmallTests.class}) @Category({RestTests.class, SmallTests.class})
public class TestScannerModel extends TestModelBase<ScannerModel> { 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);
}
} }