Search in sources :

Example 11 with HandleNotFoundException

use of co.cask.cdap.explore.service.HandleNotFoundException in project cdap by caskdata.

the class ExploreQueryExecutorHttpHandler method getQueryStatus.

@GET
@Path("data/explore/queries/{id}/status")
public void getQueryStatus(HttpRequest request, HttpResponder responder, @PathParam("id") String id) throws ExploreException {
    try {
        final QueryHandle handle = QueryHandle.fromId(id);
        QueryStatus status;
        if (!handle.equals(QueryHandle.NO_OP)) {
            status = doAs(handle, new Callable<QueryStatus>() {

                @Override
                public QueryStatus call() throws Exception {
                    return exploreService.getStatus(handle);
                }
            });
        } else {
            status = QueryStatus.NO_OP;
        }
        responder.sendJson(HttpResponseStatus.OK, GSON.toJson(status));
    } catch (IllegalArgumentException e) {
        LOG.debug("Got exception:", e);
        responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    } catch (SQLException e) {
        LOG.debug("Got exception:", e);
        responder.sendString(HttpResponseStatus.BAD_REQUEST, String.format("[SQLState %s] %s", e.getSQLState(), e.getMessage()));
    } catch (HandleNotFoundException e) {
        responder.sendStatus(HttpResponseStatus.NOT_FOUND);
    } catch (ExploreException | RuntimeException e) {
        LOG.debug("Got exception:", e);
        throw e;
    }
}
Also used : HandleNotFoundException(co.cask.cdap.explore.service.HandleNotFoundException) SQLException(java.sql.SQLException) QueryHandle(co.cask.cdap.proto.QueryHandle) QueryStatus(co.cask.cdap.proto.QueryStatus) Callable(java.util.concurrent.Callable) ExploreException(co.cask.cdap.explore.service.ExploreException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 12 with HandleNotFoundException

use of co.cask.cdap.explore.service.HandleNotFoundException in project cdap by caskdata.

the class ExploreQueryExecutorHttpHandler method getQueryResultPreview.

@POST
@Path("data/explore/queries/{id}/preview")
public void getQueryResultPreview(HttpRequest request, HttpResponder responder, @PathParam("id") String id) throws ExploreException {
    // NOTE: this call is a POST because it is not idempotent: cursor of results is moved
    try {
        final QueryHandle handle = QueryHandle.fromId(id);
        List<QueryResult> results;
        if (handle.equals(QueryHandle.NO_OP)) {
            results = Lists.newArrayList();
        } else {
            results = doAs(handle, new Callable<List<QueryResult>>() {

                @Override
                public List<QueryResult> call() throws Exception {
                    return exploreService.previewResults(handle);
                }
            });
        }
        responder.sendJson(HttpResponseStatus.OK, GSON.toJson(results));
    } catch (IllegalArgumentException e) {
        LOG.debug("Got exception:", e);
        responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    } catch (SQLException e) {
        LOG.debug("Got exception:", e);
        responder.sendString(HttpResponseStatus.BAD_REQUEST, String.format("[SQLState %s] %s", e.getSQLState(), e.getMessage()));
    } catch (HandleNotFoundException e) {
        if (e.isInactive()) {
            responder.sendString(HttpResponseStatus.CONFLICT, "Preview is unavailable for inactive queries.");
            return;
        }
        responder.sendStatus(HttpResponseStatus.NOT_FOUND);
    }
}
Also used : HandleNotFoundException(co.cask.cdap.explore.service.HandleNotFoundException) QueryResult(co.cask.cdap.proto.QueryResult) SQLException(java.sql.SQLException) QueryHandle(co.cask.cdap.proto.QueryHandle) Callable(java.util.concurrent.Callable) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

HandleNotFoundException (co.cask.cdap.explore.service.HandleNotFoundException)12 SQLException (java.sql.SQLException)10 QueryHandle (co.cask.cdap.proto.QueryHandle)8 Path (javax.ws.rs.Path)7 ExploreException (co.cask.cdap.explore.service.ExploreException)5 QueryResult (co.cask.cdap.proto.QueryResult)5 Callable (java.util.concurrent.Callable)5 IOException (java.io.IOException)4 POST (javax.ws.rs.POST)4 QueryStatus (co.cask.cdap.proto.QueryStatus)3 ColumnDesc (co.cask.cdap.proto.ColumnDesc)2 FileNotFoundException (java.io.FileNotFoundException)2 CancellationException (java.util.concurrent.CancellationException)2 ExecutionException (java.util.concurrent.ExecutionException)2 Lock (java.util.concurrent.locks.Lock)2 GET (javax.ws.rs.GET)2 RowMaker (co.cask.cdap.cli.util.RowMaker)1 Table (co.cask.cdap.cli.util.table.Table)1 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)1 ExploreExecutionResult (co.cask.cdap.explore.client.ExploreExecutionResult)1