Search in sources :

Example 6 with ResourceSecurity

use of io.trino.server.security.ResourceSecurity in project trino by trinodb.

the class ThreadResource method getThreadInfo.

@ResourceSecurity(MANAGEMENT_READ)
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Info> getThreadInfo() {
    ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
    List<Info> threads = Arrays.stream(mbean.getThreadInfo(mbean.getAllThreadIds(), Integer.MAX_VALUE)).filter(Objects::nonNull).map(ThreadResource::toInfo).collect(Collectors.toUnmodifiableList());
    return Ordering.from(byName()).sortedCopy(threads);
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) Objects(java.util.Objects) ThreadInfo(java.lang.management.ThreadInfo) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ResourceSecurity(io.trino.server.security.ResourceSecurity)

Example 7 with ResourceSecurity

use of io.trino.server.security.ResourceSecurity in project trino by trinodb.

the class QueryResource method getAllQueryInfo.

@ResourceSecurity(AUTHENTICATED_USER)
@GET
public List<BasicQueryInfo> 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<BasicQueryInfo> builder = ImmutableList.builder();
    for (BasicQueryInfo queryInfo : queries) {
        if (stateFilter == null || queryInfo.getState() == expectedState) {
            builder.add(queryInfo);
        }
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) QueryState(io.trino.execution.QueryState) GET(javax.ws.rs.GET) ResourceSecurity(io.trino.server.security.ResourceSecurity)

Example 8 with ResourceSecurity

use of io.trino.server.security.ResourceSecurity in project trino by trinodb.

the class QueryResource method getQueryInfo.

@ResourceSecurity(AUTHENTICATED_USER)
@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.isEmpty()) {
        return Response.status(Status.GONE).build();
    }
    try {
        checkCanViewQueryOwnedBy(sessionContextFactory.extractAuthorizedIdentity(servletRequest, httpHeaders, alternateHeaderName), queryInfo.get().getSession().toIdentity(), accessControl);
        return Response.ok(queryInfo.get()).build();
    } catch (AccessDeniedException e) {
        throw new ForbiddenException();
    }
}
Also used : AccessDeniedException(io.trino.spi.security.AccessDeniedException) ForbiddenException(javax.ws.rs.ForbiddenException) QueryInfo(io.trino.execution.QueryInfo) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ResourceSecurity(io.trino.server.security.ResourceSecurity)

Example 9 with ResourceSecurity

use of io.trino.server.security.ResourceSecurity in project trino by trinodb.

the class QueryStateInfoResource method getQueryStateInfo.

@ResourceSecurity(AUTHENTICATED_USER)
@GET
@Path("{queryId}")
@Produces(MediaType.APPLICATION_JSON)
public QueryStateInfo getQueryStateInfo(@PathParam("queryId") String queryId, @Context HttpServletRequest servletRequest, @Context HttpHeaders httpHeaders) throws WebApplicationException {
    try {
        BasicQueryInfo queryInfo = dispatchManager.getQueryInfo(new QueryId(queryId));
        checkCanViewQueryOwnedBy(sessionContextFactory.extractAuthorizedIdentity(servletRequest, httpHeaders, alternateHeaderName), queryInfo.getSession().toIdentity(), accessControl);
        return getQueryStateInfo(queryInfo);
    } catch (AccessDeniedException e) {
        throw new ForbiddenException();
    } catch (NoSuchElementException e) {
        throw new WebApplicationException(NOT_FOUND);
    }
}
Also used : AccessDeniedException(io.trino.spi.security.AccessDeniedException) ForbiddenException(javax.ws.rs.ForbiddenException) WebApplicationException(javax.ws.rs.WebApplicationException) QueryId(io.trino.spi.QueryId) NoSuchElementException(java.util.NoSuchElementException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ResourceSecurity(io.trino.server.security.ResourceSecurity)

Example 10 with ResourceSecurity

use of io.trino.server.security.ResourceSecurity in project trino by trinodb.

the class QueryResource method cancelQuery.

@ResourceSecurity(AUTHENTICATED_USER)
@DELETE
@Path("{queryId}")
public void cancelQuery(@PathParam("queryId") QueryId queryId, @Context HttpServletRequest servletRequest, @Context HttpHeaders httpHeaders) {
    requireNonNull(queryId, "queryId is null");
    try {
        BasicQueryInfo queryInfo = dispatchManager.getQueryInfo(queryId);
        checkCanKillQueryOwnedBy(sessionContextFactory.extractAuthorizedIdentity(servletRequest, httpHeaders, alternateHeaderName), queryInfo.getSession().toIdentity(), accessControl);
        dispatchManager.cancelQuery(queryId);
    } catch (AccessDeniedException e) {
        throw new ForbiddenException();
    } catch (NoSuchElementException ignored) {
    }
}
Also used : AccessDeniedException(io.trino.spi.security.AccessDeniedException) ForbiddenException(javax.ws.rs.ForbiddenException) NoSuchElementException(java.util.NoSuchElementException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) 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