Search in sources :

Example 1 with ResourceSecurity

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);
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) NodeState(io.trino.metadata.NodeState) InternalNodeManager(io.trino.metadata.InternalNodeManager) ResourceSecurity(io.trino.server.security.ResourceSecurity) DispatchManager(io.trino.dispatcher.DispatchManager) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) BasicQueryInfo(io.trino.server.BasicQueryInfo) NodeSchedulerConfig(io.trino.execution.scheduler.NodeSchedulerConfig) Path(javax.ws.rs.Path) QueryState(io.trino.execution.QueryState) Inject(javax.inject.Inject) ClusterMemoryManager(io.trino.memory.ClusterMemoryManager) InternalNode(io.trino.metadata.InternalNode) MediaType(javax.ws.rs.core.MediaType) Objects.requireNonNull(java.util.Objects.requireNonNull) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) WEB_UI(io.trino.server.security.ResourceSecurity.AccessType.WEB_UI) SECONDS(java.util.concurrent.TimeUnit.SECONDS) BasicQueryInfo(io.trino.server.BasicQueryInfo) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ResourceSecurity(io.trino.server.security.ResourceSecurity)

Example 2 with ResourceSecurity

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();
}
Also used : URL(java.net.URL) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ResourceSecurity(io.trino.server.security.ResourceSecurity)

Example 3 with ResourceSecurity

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();
}
Also used : AccessDeniedException(io.trino.spi.security.AccessDeniedException) ForbiddenException(javax.ws.rs.ForbiddenException) QueryId(io.trino.spi.QueryId) QueryInfo(io.trino.execution.QueryInfo) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ResourceSecurity(io.trino.server.security.ResourceSecurity)

Example 4 with ResourceSecurity

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();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryState(io.trino.execution.QueryState) GET(javax.ws.rs.GET) ResourceSecurity(io.trino.server.security.ResourceSecurity)

Example 5 with ResourceSecurity

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());
}
Also used : TaskInfo(io.trino.execution.TaskInfo) Session(io.trino.Session) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ResourceSecurity(io.trino.server.security.ResourceSecurity)

Aggregations

ResourceSecurity (io.trino.server.security.ResourceSecurity)15 GET (javax.ws.rs.GET)12 Path (javax.ws.rs.Path)12 Produces (javax.ws.rs.Produces)8 AccessDeniedException (io.trino.spi.security.AccessDeniedException)5 ForbiddenException (javax.ws.rs.ForbiddenException)5 TaskInfo (io.trino.execution.TaskInfo)4 ImmutableList (com.google.common.collect.ImmutableList)3 Duration (io.airlift.units.Duration)3 QueryInfo (io.trino.execution.QueryInfo)3 QueryState (io.trino.execution.QueryState)3 BasicQueryInfo (io.trino.server.BasicQueryInfo)3 DELETE (javax.ws.rs.DELETE)3 Session (io.trino.Session)2 TaskStatus (io.trino.execution.TaskStatus)2 QueryId (io.trino.spi.QueryId)2 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 Iterables.transform (com.google.common.collect.Iterables.transform)1 TypeToken (com.google.common.reflect.TypeToken)1