Search in sources :

Example 1 with SessionContext

use of io.prestosql.server.SessionContext 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 SessionContext

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

the class QueuedStatementResource method postStatement.

@POST
@Path("/v1/statement")
@Produces(APPLICATION_JSON)
public Response postStatement(String statement, @HeaderParam(X_FORWARDED_PROTO) String xForwardedProto, @Context HttpServletRequest servletRequest, @Context UriInfo uriInfo) {
    if (isNullOrEmpty(statement)) {
        throw badRequest(BAD_REQUEST, "SQL statement is empty");
    }
    // only active coordinator is ready to accept new queries
    NodeState state = nodeStateChangeHandler.getState();
    if (state != ACTIVE) {
        throw badRequest(SERVICE_UNAVAILABLE, "This coordinator is not active so can not accept queries");
    }
    SessionContext sessionContext = new HttpRequestSessionContext(servletRequest, groupProvider);
    Query query = new Query(statement, sessionContext, dispatchManager);
    queries.put(query.getQueryId(), query);
    return Response.ok(query.getQueryResults(query.getLastToken(), uriInfo, xForwardedProto)).build();
}
Also used : NodeState(io.prestosql.metadata.NodeState) HttpRequestSessionContext(io.prestosql.server.HttpRequestSessionContext) SessionContext(io.prestosql.server.SessionContext) HttpRequestSessionContext(io.prestosql.server.HttpRequestSessionContext) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

HttpRequestSessionContext (io.prestosql.server.HttpRequestSessionContext)2 SessionContext (io.prestosql.server.SessionContext)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 DataCenterResponse (io.prestosql.client.DataCenterResponse)1 NodeState (io.prestosql.metadata.NodeState)1 PagePublisherQueryRunner (io.prestosql.server.protocol.PagePublisherQueryRunner)1