use of io.cdap.cdap.proto.QueryHandle in project cdap by caskdata.
the class ExploreExecutorHttpHandler method disableDataset.
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());
}
}
use of io.cdap.cdap.proto.QueryHandle in project cdap by caskdata.
the class ExploreQueryExecutorHttpHandler method closeQuery.
@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);
}
}
use of io.cdap.cdap.proto.QueryHandle in project cdap by caskdata.
the class AbstractExploreClient method getFutureResultsFromHandle.
/**
* Create a {@link ListenableFuture} object by polling the Explore service using the
* {@link ListenableFuture} containing a {@link QueryHandle}.
*/
private ListenableFuture<ExploreExecutionResult> getFutureResultsFromHandle(final ListenableFuture<QueryHandle> futureHandle) {
final StatementExecutionFuture resultFuture = new StatementExecutionFuture(this, futureHandle);
Futures.addCallback(futureHandle, new FutureCallback<QueryHandle>() {
@Override
public void onSuccess(final QueryHandle handle) {
boolean mustCloseHandle;
try {
QueryStatus status = getStatus(handle);
if (!status.getStatus().isDone()) {
final String userId = SecurityRequestContext.getUserId();
final String userIp = SecurityRequestContext.getUserIP();
executor.schedule(new Runnable() {
@Override
public void run() {
SecurityRequestContext.setUserId(userId);
SecurityRequestContext.setUserIP(userIp);
onSuccess(handle);
}
}, 300, TimeUnit.MILLISECONDS);
return;
}
if (QueryStatus.OpStatus.ERROR.equals(status.getStatus())) {
throw new SQLException(status.getErrorMessage(), status.getSqlState());
}
ExploreExecutionResult result = new ClientExploreExecutionResult(AbstractExploreClient.this, handle, status);
mustCloseHandle = !resultFuture.set(result) || !status.hasResults();
} catch (Exception e) {
mustCloseHandle = true;
resultFuture.setException(e);
}
if (mustCloseHandle) {
try {
close(handle);
} catch (Throwable t) {
LOG.warn("Failed to close handle {}", handle, t);
}
}
}
@Override
public void onFailure(Throwable t) {
resultFuture.setException(t);
}
}, executor);
return resultFuture;
}
use of io.cdap.cdap.proto.QueryHandle in project cdap by caskdata.
the class InMemoryExploreServiceTest method runCommand.
private static void runCommand(String namespace, String command, boolean expectedHasResult, List<ColumnDesc> expectedColumnDescs, List<QueryResult> expectedResults) throws Exception {
QueryHandle handle = exploreService.execute(new NamespaceId(namespace), command);
QueryStatus status = waitForCompletionStatus(handle);
Assert.assertEquals(QueryStatus.OpStatus.FINISHED, status.getStatus());
Assert.assertEquals(expectedHasResult, status.hasResults());
Assert.assertEquals(expectedColumnDescs, exploreService.getResultSchema(handle));
Assert.assertEquals(expectedResults.toString(), trimColumnValues(exploreService.nextResults(handle, 100)).toString());
exploreService.close(handle);
}
use of io.cdap.cdap.proto.QueryHandle in project cdap by caskdata.
the class BaseHiveExploreServiceTest method deleteNamespace.
/**
* Delete a namespace because app fabric is not started in explore tests.
*/
protected static void deleteNamespace(NamespaceId namespaceId) throws Exception {
namespacePathLocator.get(namespaceId).delete(true);
if (!NamespaceId.DEFAULT.equals(namespaceId)) {
QueryHandle handle = exploreService.deleteNamespace(namespaceId);
waitForCompletionStatus(handle, 50, TimeUnit.MILLISECONDS, 40);
}
namespaceAdmin.delete(namespaceId);
}
Aggregations