Search in sources :

Example 1 with UriBuilder

use of org.apache.hbase.thirdparty.javax.ws.rs.core.UriBuilder in project hbase by apache.

the class ScannerResource method update.

Response update(final ScannerModel model, final boolean replace, final UriInfo uriInfo) {
    servlet.getMetrics().incrementRequests(1);
    if (servlet.isReadOnly()) {
        return Response.status(Response.Status.FORBIDDEN).type(MIMETYPE_TEXT).entity("Forbidden" + CRLF).build();
    }
    byte[] endRow = model.hasEndRow() ? model.getEndRow() : null;
    RowSpec spec = null;
    if (model.getLabels() != null) {
        spec = new RowSpec(model.getStartRow(), endRow, model.getColumns(), model.getStartTime(), model.getEndTime(), model.getMaxVersions(), model.getLabels());
    } else {
        spec = new RowSpec(model.getStartRow(), endRow, model.getColumns(), model.getStartTime(), model.getEndTime(), model.getMaxVersions());
    }
    try {
        Filter filter = ScannerResultGenerator.buildFilterFromModel(model);
        String tableName = tableResource.getName();
        ScannerResultGenerator gen = new ScannerResultGenerator(tableName, spec, filter, model.getCaching(), model.getCacheBlocks(), model.getLimit());
        String id = gen.getID();
        ScannerInstanceResource instance = new ScannerInstanceResource(tableName, id, gen, model.getBatch());
        scanners.put(id, instance);
        if (LOG.isTraceEnabled()) {
            LOG.trace("new scanner: " + id);
        }
        UriBuilder builder = uriInfo.getAbsolutePathBuilder();
        URI uri = builder.path(id).build();
        servlet.getMetrics().incrementSucessfulPutRequests(1);
        return Response.created(uri).build();
    } catch (Exception e) {
        LOG.error("Exception occurred 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 || e instanceof JsonMappingException | e instanceof JsonParseException) {
            return Response.status(Response.Status.BAD_REQUEST).type(MIMETYPE_TEXT).entity("Bad request" + CRLF).build();
        }
        return Response.status(Response.Status.SERVICE_UNAVAILABLE).type(MIMETYPE_TEXT).entity("Unavailable" + CRLF).build();
    }
}
Also used : JsonParseException(com.fasterxml.jackson.core.JsonParseException) URI(java.net.URI) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) Filter(org.apache.hadoop.hbase.filter.Filter) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) UriBuilder(org.apache.hbase.thirdparty.javax.ws.rs.core.UriBuilder)

Aggregations

JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 IOException (java.io.IOException)1 URI (java.net.URI)1 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)1 Filter (org.apache.hadoop.hbase.filter.Filter)1 UriBuilder (org.apache.hbase.thirdparty.javax.ws.rs.core.UriBuilder)1