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();
}
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;
}
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;
}
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);
}
}
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();
}
Aggregations