Search in sources :

Example 1 with HttpRequestSessionContext

use of io.prestosql.server.HttpRequestSessionContext in project hetu-core by openlookeng.

the class DataCenterStatementResource method postStatement.

@POST
@Path("/v1/dc/statement/{globalQueryId}")
@Produces(APPLICATION_JSON)
public synchronized Response postStatement(@PathParam("globalQueryId") String globalQueryId, DataCenterRequest request, @Context HttpServletRequest servletRequest, @Context UriInfo uriInfo) {
    if (isNull(request)) {
        throw badRequest(BAD_REQUEST, "SQL statement is empty");
    }
    SessionContext context = new HttpRequestSessionContext(servletRequest, groupProvider);
    DataCenterResponse response;
    try {
        PagePublisherQueryRunner queryRunner = this.queryManager.submit(globalQueryId, request.getQuery(), request.getClientId(), request.getMaxAnticipatedDelay(), context);
        if (queryRunner != null) {
            response = new DataCenterResponse(DataCenterResponse.State.SUBMITTED, queryRunner.getSlug(), queryRunner.getConsumer(request.getClientId()) != null);
        } else {
            response = new DataCenterResponse(DataCenterResponse.State.FINISHED_ALREADY, null, false);
        }
    } catch (IllegalStateException ex) {
        response = new DataCenterResponse(DataCenterResponse.State.FINISHED_ALREADY, null, false);
    }
    return Response.ok(response).build();
}
Also used : DataCenterResponse(io.prestosql.client.DataCenterResponse) HttpRequestSessionContext(io.prestosql.server.HttpRequestSessionContext) SessionContext(io.prestosql.server.SessionContext) HttpRequestSessionContext(io.prestosql.server.HttpRequestSessionContext) PagePublisherQueryRunner(io.prestosql.server.protocol.PagePublisherQueryRunner) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 2 with HttpRequestSessionContext

use of io.prestosql.server.HttpRequestSessionContext in project hetu-core by openlookeng.

the class AccessControlUtil method getUserForFilter.

public static Optional<String> getUserForFilter(AccessControl accessControl, ServerConfig serverConfig, HttpServletRequest servletRequest, GroupProvider groupProvider) {
    String sessionUser = AccessControlUtil.getUser(accessControl, new HttpRequestSessionContext(servletRequest, groupProvider));
    Optional<String> user = Optional.of(sessionUser);
    // if the user is admin, don't filter results by user.
    if (serverConfig.isAdmin(sessionUser)) {
        user = Optional.empty();
    }
    return user;
}
Also used : HttpRequestSessionContext(io.prestosql.server.HttpRequestSessionContext)

Example 3 with HttpRequestSessionContext

use of io.prestosql.server.HttpRequestSessionContext in project hetu-core by openlookeng.

the class CatalogResource method dropCatalog.

@DELETE
@Path("/{catalogName}")
@Produces(MediaType.APPLICATION_JSON)
public Response dropCatalog(@NotNull @PathParam("catalogName") String catalogName, @Context HttpServletRequest servletRequest) {
    checkCatalogName(catalogName);
    Response response;
    try {
        response = service.dropCatalog(catalogName, new HttpRequestSessionContext(servletRequest, groupProvider));
    } catch (WebApplicationException ex) {
        throw ex;
    } catch (Throwable ex) {
        throw badRequest(BAD_REQUEST, "drop catalog failed. please check your request info.");
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) HttpRequestSessionContext(io.prestosql.server.HttpRequestSessionContext) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 4 with HttpRequestSessionContext

use of io.prestosql.server.HttpRequestSessionContext in project hetu-core by openlookeng.

the class CatalogResource method updateCatalog.

@PUT
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public Response updateCatalog(@FormDataParam("catalogInformation") String catalogInfoJson, @FormDataParam("catalogConfigurationFiles") List<FormDataBodyPart> catalogConfigFileBodyParts, @FormDataParam("globalConfigurationFiles") List<FormDataBodyPart> globalConfigFilesBodyParts, @Context HttpServletRequest servletRequest) {
    CatalogInfo catalogInfo = toCatalogInfo(catalogInfoJson);
    try (CatalogFileInputStream configFiles = toCatalogFiles(catalogConfigFileBodyParts, globalConfigFilesBodyParts)) {
        return service.updateCatalog(catalogInfo, configFiles, new HttpRequestSessionContext(servletRequest, groupProvider));
    } catch (WebApplicationException ex) {
        throw ex;
    } catch (Throwable ex) {
        throw badRequest(BAD_REQUEST, "update catalog failed. please check your configuration.");
    } finally {
        closeInputStreams(catalogConfigFileBodyParts);
        closeInputStreams(globalConfigFilesBodyParts);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) HttpRequestSessionContext(io.prestosql.server.HttpRequestSessionContext) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 5 with HttpRequestSessionContext

use of io.prestosql.server.HttpRequestSessionContext in project hetu-core by openlookeng.

the class MetadataResource method getSchemasFromCatalog.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("schemas/{catalog}")
public Response getSchemasFromCatalog(@PathParam("catalog") String catalogName, @Context HttpServletRequest servletRequest) throws ExecutionException {
    String user = AccessControlUtil.getUser(accessControl, new HttpRequestSessionContext(servletRequest, groupProvider));
    CatalogSchema catalogSchema = schemaService.querySchemas(catalogName, user);
    return Response.ok(catalogSchema).build();
}
Also used : CatalogSchema(io.prestosql.queryeditorui.protocol.CatalogSchema) HttpRequestSessionContext(io.prestosql.server.HttpRequestSessionContext) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

HttpRequestSessionContext (io.prestosql.server.HttpRequestSessionContext)14 Produces (javax.ws.rs.Produces)12 Path (javax.ws.rs.Path)11 GET (javax.ws.rs.GET)5 POST (javax.ws.rs.POST)4 Consumes (javax.ws.rs.Consumes)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 CatalogSchema (io.prestosql.queryeditorui.protocol.CatalogSchema)2 SessionContext (io.prestosql.server.SessionContext)2 DELETE (javax.ws.rs.DELETE)2 PUT (javax.ws.rs.PUT)2 ImmutableList (com.google.common.collect.ImmutableList)1 Column (io.prestosql.client.Column)1 DataCenterResponse (io.prestosql.client.DataCenterResponse)1 NodeState (io.prestosql.metadata.NodeState)1 ExecutionError (io.prestosql.queryeditorui.protocol.ExecutionStatus.ExecutionError)1 ExecutionSuccess (io.prestosql.queryeditorui.protocol.ExecutionStatus.ExecutionSuccess)1 Table (io.prestosql.queryeditorui.protocol.Table)1 CreateSavedQueryBuilder (io.prestosql.queryeditorui.protocol.queries.CreateSavedQueryBuilder)1 SavedQuery (io.prestosql.queryeditorui.protocol.queries.SavedQuery)1