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 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())); }
@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; } });
@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; } });
/** * Writes the {@link Credentials} of the current user to a file in the {@link #credentialsDir}, for a particular query * * @param queryHandle the query handler for the current operation * @return a File where the credentials were written. */ private File writeCredentialsFile(QueryHandle queryHandle) throws IOException, ExploreException { File credentialsFile = new File(credentialsDir, queryHandle.getHandle()); // create a local file with restricted permissions // only allow the owner to read/write, since it contains credentials Files.createFile(credentialsFile.toPath(), FileUtils.OWNER_ONLY_RW); LOG.debug("Writing credentials to file: {}", credentialsFile); try (DataOutputStream os = new DataOutputStream(Files.newOutputStream(credentialsFile.toPath()))) { Credentials credentials = UserGroupInformation.getCurrentUser().getCredentials(); credentials.writeTokenStorageToStream(os); } return credentialsFile; }
/** * Writes the {@link Credentials} of the current user to a file in the {@link #credentialsDir}, for a particular query * * @param queryHandle the query handler for the current operation * @return a File where the credentials were written. */ private File writeCredentialsFile(QueryHandle queryHandle) throws IOException, ExploreException { File credentialsFile = new File(credentialsDir, queryHandle.getHandle()); // create a local file with restricted permissions // only allow the owner to read/write, since it contains credentials Files.createFile(credentialsFile.toPath(), FileUtils.OWNER_ONLY_RW); LOG.debug("Writing credentials to file: {}", credentialsFile); try (DataOutputStream os = new DataOutputStream(Files.newOutputStream(credentialsFile.toPath()))) { Credentials credentials = UserGroupInformation.getCurrentUser().getCredentials(); credentials.writeTokenStorageToStream(os); } return credentialsFile; }
private void disableDataset(HttpResponder responder, final DatasetId datasetId, final DatasetSpecification spec) { try { QueryHandle handle = impersonator.doAs(datasetId, new Callable<QueryHandle>() { @Override public QueryHandle call() throws Exception { return exploreTableManager.disableDataset(datasetId, spec); } }); JsonObject json = new JsonObject(); json.addProperty("handle", handle.getHandle()); responder.sendJson(HttpResponseStatus.OK, json.toString()); } catch (Throwable e) { LOG.error("Got exception while trying to disable explore on dataset {}", datasetId, e); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage()); } }
public QueryInfo(long timestamp, String query, QueryHandle handle, QueryStatus status, boolean isActive) { this.timestamp = timestamp; this.statement = query; this.queryHandle = handle.getHandle(); this.status = status.getStatus(); this.hasResults = status.hasResults(); this.isActive = isActive; }
private void disableDataset(HttpResponder responder, final DatasetId datasetId, final DatasetSpecification spec) { try { QueryHandle handle = impersonator.doAs(datasetId, new Callable<QueryHandle>() { @Override public QueryHandle call() throws Exception { return exploreTableManager.disableDataset(datasetId, spec); } }); JsonObject json = new JsonObject(); json.addProperty("handle", handle.getHandle()); responder.sendJson(HttpResponseStatus.OK, json.toString()); } catch (Throwable e) { LOG.error("Got exception while trying to disable explore on dataset {}", datasetId, e); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage()); } }
public QueryInfo(long timestamp, String query, QueryHandle handle, QueryStatus status, boolean isActive) { this.timestamp = timestamp; this.statement = query; this.queryHandle = handle.getHandle(); this.status = status.getStatus(); this.hasResults = status.hasResults(); this.isActive = isActive; }
@Override public List<QueryResult> nextResults(QueryHandle handle, int size) throws ExploreException, HandleNotFoundException { HttpResponse response = doPost(String.format("data/explore/queries/%s/%s", handle.getHandle(), "next"), GSON.toJson(ImmutableMap.of("size", size)), null); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return parseJson(response, ROW_LIST_TYPE); } else if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new HandleNotFoundException("Handle " + handle.getHandle() + "not found."); } throw new ExploreException("Cannot get next results. Reason: " + response); }
@Override public void close(QueryHandle handle) throws ExploreException, HandleNotFoundException { HttpResponse response = doDelete(String.format("data/explore/queries/%s", handle.getHandle())); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return; } else if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new HandleNotFoundException("Handle " + handle.getHandle() + "not found."); } throw new ExploreException("Cannot close operation. Reason: " + response); }
@Override public List<QueryResult> nextResults(QueryHandle handle, int size) throws ExploreException, HandleNotFoundException { HttpResponse response = doPost(String.format("data/explore/queries/%s/%s", handle.getHandle(), "next"), GSON.toJson(ImmutableMap.of("size", size)), null); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return parseJson(response, ROW_LIST_TYPE); } else if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new HandleNotFoundException("Handle " + handle.getHandle() + "not found."); } throw new ExploreException("Cannot get next results. Reason: " + response); }
@Override public void close(QueryHandle handle) throws ExploreException, HandleNotFoundException { HttpResponse response = doDelete(String.format("data/explore/queries/%s", handle.getHandle())); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return; } else if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new HandleNotFoundException("Handle " + handle.getHandle() + "not found."); } throw new ExploreException("Cannot close operation. Reason: " + response); }
@Override public QueryStatus getStatus(QueryHandle handle) throws ExploreException, HandleNotFoundException { HttpResponse response = doGet(String.format("data/explore/queries/%s/%s", handle.getHandle(), "status")); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return parseJson(response, QueryStatus.class); } else if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new HandleNotFoundException("Handle " + handle.getHandle() + "not found."); } throw new ExploreException("Cannot get status. Reason: " + response); }
@Override public List<ColumnDesc> getResultSchema(QueryHandle handle) throws ExploreException, HandleNotFoundException { HttpResponse response = doGet(String.format("data/explore/queries/%s/%s", handle.getHandle(), "schema")); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return parseJson(response, COL_DESC_LIST_TYPE); } else if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new HandleNotFoundException("Handle " + handle.getHandle() + "not found."); } throw new ExploreException("Cannot get result schema. Reason: " + response); }
@Override public List<ColumnDesc> getResultSchema(QueryHandle handle) throws ExploreException, HandleNotFoundException { HttpResponse response = doGet(String.format("data/explore/queries/%s/%s", handle.getHandle(), "schema")); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return parseJson(response, COL_DESC_LIST_TYPE); } else if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new HandleNotFoundException("Handle " + handle.getHandle() + "not found."); } throw new ExploreException("Cannot get result schema. Reason: " + response); }
@Override public QueryStatus getStatus(QueryHandle handle) throws ExploreException, HandleNotFoundException { HttpResponse response = doGet(String.format("data/explore/queries/%s/%s", handle.getHandle(), "status")); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return parseJson(response, QueryStatus.class); } else if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new HandleNotFoundException("Handle " + handle.getHandle() + "not found."); } throw new ExploreException("Cannot get status. Reason: " + response); }
@Override public List<QueryResult> previewResults(QueryHandle handle) throws ExploreException, HandleNotFoundException, SQLException { HttpResponse response = doPost(String.format("data/explore/queries/%s/%s", handle.getHandle(), "preview"), null, null); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return parseJson(response, ROW_LIST_TYPE); } else if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new HandleNotFoundException("Handle " + handle.getHandle() + "not found."); } throw new ExploreException("Cannot get results preview. Reason: " + response); }
@Override public List<QueryResult> previewResults(QueryHandle handle) throws ExploreException, HandleNotFoundException, SQLException { HttpResponse response = doPost(String.format("data/explore/queries/%s/%s", handle.getHandle(), "preview"), null, null); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return parseJson(response, ROW_LIST_TYPE); } else if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new HandleNotFoundException("Handle " + handle.getHandle() + "not found."); } throw new ExploreException("Cannot get results preview. Reason: " + response); }