private OperationInfo getActiveOperationInfo(QueryHandle handle) throws HandleNotFoundException { // First look in running handles and handles that still can be fetched. OperationInfo opInfo = activeHandleCache.getIfPresent(handle); if (opInfo != null) { return opInfo; } throw new HandleNotFoundException(String.format("Invalid handle provided: %s", handle.getHandle())); }
private QueryHandle getQueryHandle(Map<String, String> sessionConf) throws HandleNotFoundException { return QueryHandle.fromId(sessionConf.get(Constants.Explore.QUERY_ID)); }
public static QueryHandle fromId(String id) { if (id.equals(NO_OP_ID)) { return NO_OP; } return new QueryHandle(id); }
@DELETE @Path("data/explore/queries/{id}") public void closeQuery(HttpRequest request, HttpResponder responder, @PathParam("id") String id) throws ExploreException, SQLException { try { final QueryHandle handle = QueryHandle.fromId(id); if (!handle.equals(QueryHandle.NO_OP)) { doAs(handle, new Callable<Void>() { @Override public Void call() throws Exception { exploreService.close(handle); return null; } }); } responder.sendStatus(HttpResponseStatus.OK); } catch (IllegalArgumentException e) { LOG.debug("Got exception:", e); responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage()); } catch (HandleNotFoundException e) { responder.sendStatus(HttpResponseStatus.NOT_FOUND); } }
private void doDownloadQueryResults(HttpResponder responder, QueryHandle handle) throws ExploreException, IOException { try { if (handle.equals(QueryHandle.NO_OP) || !exploreService.getStatus(handle).getStatus().equals(QueryStatus.OpStatus.FINISHED)) { responder.sendStatus(HttpResponseStatus.CONFLICT); return; } QueryResultsBodyProducer queryResultsBodyProducer = new QueryResultsBodyProducer(exploreService, handle); responder.sendContent(HttpResponseStatus.OK, queryResultsBodyProducer, EmptyHttpHeaders.INSTANCE); } 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, "Query is inactive"); } else { responder.sendStatus(HttpResponseStatus.NOT_FOUND); } } } }
@DELETE @Path("data/explore/queries/{id}") public void closeQuery(HttpRequest request, HttpResponder responder, @PathParam("id") String id) throws ExploreException, SQLException { try { final QueryHandle handle = QueryHandle.fromId(id); if (!handle.equals(QueryHandle.NO_OP)) { doAs(handle, new Callable<Void>() { @Override public Void call() throws Exception { exploreService.close(handle); return null; } }); } responder.sendStatus(HttpResponseStatus.OK); } catch (IllegalArgumentException e) { LOG.debug("Got exception:", e); responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage()); } catch (HandleNotFoundException e) { responder.sendStatus(HttpResponseStatus.NOT_FOUND); } }
private void doDownloadQueryResults(HttpResponder responder, QueryHandle handle) throws ExploreException, IOException { try { if (handle.equals(QueryHandle.NO_OP) || !exploreService.getStatus(handle).getStatus().equals(QueryStatus.OpStatus.FINISHED)) { responder.sendStatus(HttpResponseStatus.CONFLICT); return; } QueryResultsBodyProducer queryResultsBodyProducer = new QueryResultsBodyProducer(exploreService, handle); responder.sendContent(HttpResponseStatus.OK, queryResultsBodyProducer, EmptyHttpHeaders.INSTANCE); } 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, "Query is inactive"); } else { responder.sendStatus(HttpResponseStatus.NOT_FOUND); } } } }
private OperationInfo getActiveOperationInfo(QueryHandle handle) throws HandleNotFoundException { // First look in running handles and handles that still can be fetched. OperationInfo opInfo = activeHandleCache.getIfPresent(handle); if (opInfo != null) { return opInfo; } throw new HandleNotFoundException(String.format("Invalid handle provided: %s", handle.getHandle())); }
private QueryHandle getQueryHandle(Map<String, String> sessionConf) throws HandleNotFoundException { return QueryHandle.fromId(sessionConf.get(Constants.Explore.QUERY_ID)); }
@GET @Path("data/explore/queries/{id}/schema") public void getQueryResultsSchema(HttpRequest request, HttpResponder responder, @PathParam("id") String id) throws ExploreException { try { final QueryHandle handle = QueryHandle.fromId(id); List<ColumnDesc> schema; if (!handle.equals(QueryHandle.NO_OP)) { schema = doAs(handle, new Callable<List<ColumnDesc>>() { @Override public List<ColumnDesc> call() throws Exception { return exploreService.getResultSchema(handle); } }); } else { schema = Lists.newArrayList(); } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(schema)); } 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); } }
public static QueryHandle fromId(String id) { if (id.equals(NO_OP_ID)) { return NO_OP; } return new QueryHandle(id); }
@Override public Void execute(R request, HttpResponder responder) throws IllegalArgumentException, SQLException, ExploreException, IOException { QueryHandle handle = execution.execute(request, responder); JsonObject json = new JsonObject(); json.addProperty("handle", handle.getHandle()); responder.sendJson(HttpResponseStatus.OK, json.toString()); return null; } });
@POST @Path("data/explore/queries/{id}/download") public void downloadQueryResults(HttpRequest request, final HttpResponder responder, @PathParam("id") final String id) throws ExploreException, IOException, SQLException, HandleNotFoundException { // NOTE: this call is a POST because it is not idempotent: cursor of results is moved final QueryHandle handle = QueryHandle.fromId(id); doAs(handle, new Callable<Void>() { @Override public Void call() throws Exception { doDownloadQueryResults(responder, handle); return null; } }); }
@GET @Path("data/explore/queries/{id}/schema") public void getQueryResultsSchema(HttpRequest request, HttpResponder responder, @PathParam("id") String id) throws ExploreException { try { final QueryHandle handle = QueryHandle.fromId(id); List<ColumnDesc> schema; if (!handle.equals(QueryHandle.NO_OP)) { schema = doAs(handle, new Callable<List<ColumnDesc>>() { @Override public List<ColumnDesc> call() throws Exception { return exploreService.getResultSchema(handle); } }); } else { schema = Lists.newArrayList(); } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(schema)); } 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); } }
public static QueryHandle generate() { return new QueryHandle(UUID.randomUUID().toString()); }
@Override public Void execute(R request, HttpResponder responder) throws IllegalArgumentException, SQLException, ExploreException, IOException { QueryHandle handle = execution.execute(request, responder); JsonObject json = new JsonObject(); json.addProperty("handle", handle.getHandle()); responder.sendJson(HttpResponseStatus.OK, json.toString()); return null; } });
@POST @Path("data/explore/queries/{id}/download") public void downloadQueryResults(HttpRequest request, final HttpResponder responder, @PathParam("id") final String id) throws ExploreException, IOException, SQLException, HandleNotFoundException { // NOTE: this call is a POST because it is not idempotent: cursor of results is moved final QueryHandle handle = QueryHandle.fromId(id); doAs(handle, new Callable<Void>() { @Override public Void call() throws Exception { doDownloadQueryResults(responder, handle); return null; } }); }