use of io.trino.server.security.ResourceSecurity in project trino by trinodb.
the class UiQueryResource method getQueryInfo.
@ResourceSecurity(WEB_UI)
@GET
@Path("{queryId}")
public Response getQueryInfo(@PathParam("queryId") QueryId queryId, @Context HttpServletRequest servletRequest, @Context HttpHeaders httpHeaders) {
requireNonNull(queryId, "queryId is null");
Optional<QueryInfo> queryInfo = dispatchManager.getFullQueryInfo(queryId);
if (queryInfo.isPresent()) {
try {
checkCanViewQueryOwnedBy(sessionContextFactory.extractAuthorizedIdentity(servletRequest, httpHeaders, alternateHeaderName), queryInfo.get().getSession().toIdentity(), accessControl);
return Response.ok(queryInfo.get()).build();
} catch (AccessDeniedException e) {
throw new ForbiddenException();
}
}
return Response.status(Status.GONE).build();
}
use of io.trino.server.security.ResourceSecurity in project trino by trinodb.
the class TaskResource method deleteTask.
@ResourceSecurity(INTERNAL_ONLY)
@DELETE
@Path("{taskId}")
@Produces(MediaType.APPLICATION_JSON)
public TaskInfo deleteTask(@PathParam("taskId") TaskId taskId, @QueryParam("abort") @DefaultValue("true") boolean abort, @Context UriInfo uriInfo) {
requireNonNull(taskId, "taskId is null");
TaskInfo taskInfo;
if (abort) {
taskInfo = taskManager.abortTask(taskId);
} else {
taskInfo = taskManager.cancelTask(taskId);
}
if (shouldSummarize(uriInfo)) {
taskInfo = taskInfo.summarize();
}
return taskInfo;
}
use of io.trino.server.security.ResourceSecurity in project trino by trinodb.
the class TaskResource method getTaskInfo.
@ResourceSecurity(INTERNAL_ONLY)
@GET
@Path("{taskId}")
@Produces(MediaType.APPLICATION_JSON)
public void getTaskInfo(@PathParam("taskId") TaskId taskId, @HeaderParam(TRINO_CURRENT_VERSION) Long currentVersion, @HeaderParam(TRINO_MAX_WAIT) Duration maxWait, @Context UriInfo uriInfo, @Suspended AsyncResponse asyncResponse) {
requireNonNull(taskId, "taskId is null");
if (injectFailure(taskManager.getTraceToken(taskId), taskId, RequestType.GET_TASK_INFO, asyncResponse)) {
return;
}
if (currentVersion == null || maxWait == null) {
TaskInfo taskInfo = taskManager.getTaskInfo(taskId);
if (shouldSummarize(uriInfo)) {
taskInfo = taskInfo.summarize();
}
asyncResponse.resume(taskInfo);
return;
}
Duration waitTime = randomizeWaitTime(maxWait);
ListenableFuture<TaskInfo> futureTaskInfo = addTimeout(taskManager.getTaskInfo(taskId, currentVersion), () -> taskManager.getTaskInfo(taskId), waitTime, timeoutExecutor);
if (shouldSummarize(uriInfo)) {
futureTaskInfo = Futures.transform(futureTaskInfo, TaskInfo::summarize, directExecutor());
}
// For hard timeout, add an additional time to max wait for thread scheduling contention and GC
Duration timeout = new Duration(waitTime.toMillis() + ADDITIONAL_WAIT_TIME.toMillis(), MILLISECONDS);
bindAsyncResponse(asyncResponse, futureTaskInfo, responseExecutor).withTimeout(timeout);
}
use of io.trino.server.security.ResourceSecurity in project trino by trinodb.
the class TaskResource method getTaskStatus.
@ResourceSecurity(INTERNAL_ONLY)
@GET
@Path("{taskId}/status")
@Produces(MediaType.APPLICATION_JSON)
public void getTaskStatus(@PathParam("taskId") TaskId taskId, @HeaderParam(TRINO_CURRENT_VERSION) Long currentVersion, @HeaderParam(TRINO_MAX_WAIT) Duration maxWait, @Context UriInfo uriInfo, @Suspended AsyncResponse asyncResponse) {
requireNonNull(taskId, "taskId is null");
if (injectFailure(taskManager.getTraceToken(taskId), taskId, RequestType.GET_TASK_STATUS, asyncResponse)) {
return;
}
if (currentVersion == null || maxWait == null) {
TaskStatus taskStatus = taskManager.getTaskStatus(taskId);
asyncResponse.resume(taskStatus);
return;
}
Duration waitTime = randomizeWaitTime(maxWait);
// TODO: With current implementation, a newly completed driver group won't trigger immediate HTTP response,
// leading to a slight delay of approx 1 second, which is not a major issue for any query that are heavy weight enough
// to justify group-by-group execution. In order to fix this, REST endpoint /v1/{task}/status will need change.
ListenableFuture<TaskStatus> futureTaskStatus = addTimeout(taskManager.getTaskStatus(taskId, currentVersion), () -> taskManager.getTaskStatus(taskId), waitTime, timeoutExecutor);
// For hard timeout, add an additional time to max wait for thread scheduling contention and GC
Duration timeout = new Duration(waitTime.toMillis() + ADDITIONAL_WAIT_TIME.toMillis(), MILLISECONDS);
bindAsyncResponse(asyncResponse, futureTaskStatus, responseExecutor).withTimeout(timeout);
}
use of io.trino.server.security.ResourceSecurity in project trino by trinodb.
the class TaskResource method getResults.
@ResourceSecurity(INTERNAL_ONLY)
@GET
@Path("{taskId}/results/{bufferId}/{token}")
@Produces(TRINO_PAGES)
public void getResults(@PathParam("taskId") TaskId taskId, @PathParam("bufferId") OutputBufferId bufferId, @PathParam("token") long token, @HeaderParam(TRINO_MAX_SIZE) DataSize maxSize, @Suspended AsyncResponse asyncResponse) {
requireNonNull(taskId, "taskId is null");
requireNonNull(bufferId, "bufferId is null");
if (injectFailure(taskManager.getTraceToken(taskId), taskId, RequestType.GET_RESULTS, asyncResponse)) {
return;
}
TaskState state = taskManager.getTaskStatus(taskId).getState();
boolean taskFailed = state == TaskState.ABORTED || state == TaskState.FAILED;
long start = System.nanoTime();
ListenableFuture<BufferResult> bufferResultFuture = taskManager.getTaskResults(taskId, bufferId, token, maxSize);
Duration waitTime = randomizeWaitTime(DEFAULT_MAX_WAIT_TIME);
bufferResultFuture = addTimeout(bufferResultFuture, () -> BufferResult.emptyResults(taskManager.getTaskInstanceId(taskId), token, false), waitTime, timeoutExecutor);
ListenableFuture<Response> responseFuture = Futures.transform(bufferResultFuture, result -> {
List<Slice> serializedPages = result.getSerializedPages();
GenericEntity<?> entity = null;
Status status;
if (serializedPages.isEmpty()) {
status = Status.NO_CONTENT;
} else {
entity = new GenericEntity<>(serializedPages, new TypeToken<List<Slice>>() {
}.getType());
status = Status.OK;
}
return Response.status(status).entity(entity).header(TRINO_TASK_INSTANCE_ID, result.getTaskInstanceId()).header(TRINO_PAGE_TOKEN, result.getToken()).header(TRINO_PAGE_NEXT_TOKEN, result.getNextToken()).header(TRINO_BUFFER_COMPLETE, result.isBufferComplete()).header(TRINO_TASK_FAILED, taskFailed).build();
}, directExecutor());
// For hard timeout, add an additional time to max wait for thread scheduling contention and GC
Duration timeout = new Duration(waitTime.toMillis() + ADDITIONAL_WAIT_TIME.toMillis(), MILLISECONDS);
bindAsyncResponse(asyncResponse, responseFuture, responseExecutor).withTimeout(timeout, Response.status(Status.NO_CONTENT).header(TRINO_TASK_INSTANCE_ID, taskManager.getTaskInstanceId(taskId)).header(TRINO_PAGE_TOKEN, token).header(TRINO_PAGE_NEXT_TOKEN, token).header(TRINO_BUFFER_COMPLETE, false).header(TRINO_TASK_FAILED, taskFailed).build());
responseFuture.addListener(() -> readFromOutputBufferTime.add(Duration.nanosSince(start)), directExecutor());
asyncResponse.register((CompletionCallback) throwable -> resultsRequestTime.add(Duration.nanosSince(start)));
}
Aggregations