use of io.trino.server.security.ResourceSecurity in project trino by trinodb.
the class ClusterStatsResource method getClusterStats.
@ResourceSecurity(WEB_UI)
@GET
@Produces(MediaType.APPLICATION_JSON)
public ClusterStats getClusterStats() {
long runningQueries = 0;
long blockedQueries = 0;
long queuedQueries = 0;
long activeNodes = nodeManager.getNodes(NodeState.ACTIVE).stream().filter(node -> isIncludeCoordinator || !node.isCoordinator()).count();
long activeCoordinators = nodeManager.getNodes(NodeState.ACTIVE).stream().filter(InternalNode::isCoordinator).count();
long totalAvailableProcessors = clusterMemoryManager.getTotalAvailableProcessors();
long runningDrivers = 0;
double memoryReservation = 0;
long totalInputRows = dispatchManager.getStats().getConsumedInputRows().getTotalCount();
long totalInputBytes = dispatchManager.getStats().getConsumedInputBytes().getTotalCount();
long totalCpuTimeSecs = dispatchManager.getStats().getConsumedCpuTimeSecs().getTotalCount();
for (BasicQueryInfo query : dispatchManager.getQueries()) {
if (query.getState() == QueryState.QUEUED) {
queuedQueries++;
} else if (query.getState() == QueryState.RUNNING) {
if (query.getQueryStats().isFullyBlocked()) {
blockedQueries++;
} else {
runningQueries++;
}
}
if (!query.getState().isDone()) {
totalInputBytes += query.getQueryStats().getRawInputDataSize().toBytes();
totalInputRows += query.getQueryStats().getRawInputPositions();
totalCpuTimeSecs += query.getQueryStats().getTotalCpuTime().getValue(SECONDS);
memoryReservation += query.getQueryStats().getUserMemoryReservation().toBytes();
runningDrivers += query.getQueryStats().getRunningDrivers();
}
}
return new ClusterStats(runningQueries, blockedQueries, queuedQueries, activeCoordinators, activeNodes, runningDrivers, totalAvailableProcessors, memoryReservation, totalInputRows, totalInputBytes, totalCpuTimeSecs);
}
use of io.trino.server.security.ResourceSecurity in project trino by trinodb.
the class WebUiStaticResource method getFile.
@ResourceSecurity(WEB_UI)
@GET
@Path("/ui/{path: .*}")
public Response getFile(@PathParam("path") String path, @Context ServletContext servletContext) throws IOException {
if (path.isEmpty()) {
path = "index.html";
}
String fullPath = "/webapp/" + path;
if (!isCanonical(fullPath)) {
// consider redirecting to the absolute path
return Response.status(NOT_FOUND).build();
}
URL resource = getClass().getResource(fullPath);
if (resource == null) {
return Response.status(NOT_FOUND).build();
}
return Response.ok(resource.openStream(), servletContext.getMimeType(resource.toString())).build();
}
use of io.trino.server.security.ResourceSecurity in project trino by trinodb.
the class WorkerResource method getThreads.
@ResourceSecurity(WEB_UI)
@GET
@Path("{nodeId}/task/{taskId}")
public Response getThreads(@PathParam("taskId") TaskId task, @PathParam("nodeId") String nodeId, @Context HttpServletRequest servletRequest, @Context HttpHeaders httpHeaders) {
QueryId queryId = task.getQueryId();
Optional<QueryInfo> queryInfo = dispatchManager.getFullQueryInfo(queryId);
if (queryInfo.isPresent()) {
try {
checkCanViewQueryOwnedBy(sessionContextFactory.extractAuthorizedIdentity(servletRequest, httpHeaders, alternateHeaderName), queryInfo.get().getSession().toIdentity(), accessControl);
return proxyJsonResponse(nodeId, "v1/task/" + task);
} 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 UiQueryResource method getAllQueryInfo.
@ResourceSecurity(WEB_UI)
@GET
public List<TrimmedBasicQueryInfo> getAllQueryInfo(@QueryParam("state") String stateFilter, @Context HttpServletRequest servletRequest, @Context HttpHeaders httpHeaders) {
QueryState expectedState = stateFilter == null ? null : QueryState.valueOf(stateFilter.toUpperCase(Locale.ENGLISH));
List<BasicQueryInfo> queries = dispatchManager.getQueries();
queries = filterQueries(sessionContextFactory.extractAuthorizedIdentity(servletRequest, httpHeaders, alternateHeaderName), queries, accessControl);
ImmutableList.Builder<TrimmedBasicQueryInfo> builder = ImmutableList.builder();
for (BasicQueryInfo queryInfo : queries) {
if (stateFilter == null || queryInfo.getState() == expectedState) {
builder.add(new TrimmedBasicQueryInfo(queryInfo));
}
}
return builder.build();
}
use of io.trino.server.security.ResourceSecurity in project trino by trinodb.
the class TaskResource method createOrUpdateTask.
@ResourceSecurity(INTERNAL_ONLY)
@POST
@Path("{taskId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public void createOrUpdateTask(@PathParam("taskId") TaskId taskId, TaskUpdateRequest taskUpdateRequest, @Context UriInfo uriInfo, @Suspended AsyncResponse asyncResponse) {
requireNonNull(taskUpdateRequest, "taskUpdateRequest is null");
Session session = taskUpdateRequest.getSession().toSession(sessionPropertyManager, taskUpdateRequest.getExtraCredentials());
if (injectFailure(session.getTraceToken(), taskId, RequestType.CREATE_OR_UPDATE_TASK, asyncResponse)) {
return;
}
TaskInfo taskInfo = taskManager.updateTask(session, taskId, taskUpdateRequest.getFragment(), taskUpdateRequest.getSplitAssignments(), taskUpdateRequest.getOutputIds(), taskUpdateRequest.getDynamicFilterDomains());
if (shouldSummarize(uriInfo)) {
taskInfo = taskInfo.summarize();
}
asyncResponse.resume(Response.ok().entity(taskInfo).build());
}
Aggregations