Search in sources :

Example 1 with GenerateQuerySessionId

use of datawave.annotation.GenerateQuerySessionId in project datawave by NationalSecurityAgency.

the class CachedResultsBean method reset.

/**
 * Re-allocate resources for these cached results and reset paging to the beginning
 *
 * @param queryId
 *            user defined id for this query
 *
 * @return datawave.webservice.result.CachedResultsResponse
 * @RequestHeader X-ProxiedEntitiesChain use when proxying request for user by specifying a chain of DNs of the identities to proxy
 * @RequestHeader X-ProxiedIssuersChain required when using X-ProxiedEntitiesChain, specify one issuer DN per subject DN listed in X-ProxiedEntitiesChain
 * @ResponseHeader query-session-id this header and value will be in the Set-Cookie header, subsequent calls for this session will need to supply the
 *                 query-session-id header in the request in a Cookie header or as a query parameter
 * @ResponseHeader X-OperationTimeInMS time spent on the server performing the operation, does not account for network or result serialization
 *
 * @HTTP 200 success
 * @HTTP 500 internal server error
 */
@PUT
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml" })
@javax.ws.rs.Path("/{queryId}/reset")
@Interceptors({ RequiredInterceptor.class, ResponseInterceptor.class })
@GenerateQuerySessionId(cookieBasePath = "/DataWave/CachedResults/")
@Timed(name = "dw.cachedr.close", absolute = true)
public CachedResultsResponse reset(@PathParam("queryId") @Required("queryId") String queryId) {
    CreateQuerySessionIDFilter.QUERY_ID.set(null);
    CachedResultsResponse response = new CachedResultsResponse();
    // Find out who/what called this method
    Principal p = ctx.getCallerPrincipal();
    String owner = getOwnerFromPrincipal(p);
    try {
        CachedRunningQuery crq = null;
        try {
            // Get the CachedRunningQuery object from the cache
            try {
                crq = retrieve(queryId, owner);
            } catch (IOException e) {
                throw new PreConditionFailedQueryException(DatawaveErrorCode.CACHED_RESULTS_IMPORT_ERROR);
            }
            if (null == crq)
                throw new PreConditionFailedQueryException(DatawaveErrorCode.QUERY_NOT_CACHED);
            if (!crq.getUser().equals(owner)) {
                throw new UnauthorizedQueryException(DatawaveErrorCode.QUERY_OWNER_MISMATCH, MessageFormat.format("{0} != {1}", crq.getUser(), owner));
            }
            synchronized (crq) {
                if (crq.isActivated() == true) {
                    crq.closeConnection(log);
                }
                Connection connection = ds.getConnection();
                String logicName = crq.getQueryLogicName();
                QueryLogic<?> queryLogic = queryFactory.getQueryLogic(logicName, p);
                crq.activate(connection, queryLogic);
                response.setQueryId(crq.getQueryId());
                response.setOriginalQueryId(crq.getOriginalQueryId());
                response.setViewName(crq.getView());
                response.setAlias(crq.getAlias());
                response.setTotalRows(crq.getTotalRows());
            }
            CreateQuerySessionIDFilter.QUERY_ID.set(queryId);
            return response;
        } finally {
            // Push metrics
            if (null != crq && crq.getQueryLogic().getCollectQueryMetrics() == true) {
                try {
                    metrics.updateMetric(crq.getMetric());
                } catch (Exception e1) {
                    log.error("Error updating metrics", e1);
                }
            }
        }
    } catch (Exception e) {
        response.addMessage(e.getMessage());
        QueryException qe = new QueryException(DatawaveErrorCode.RESET_CALL_ERROR, e);
        log.error(qe);
        response.addException(qe.getBottomQueryException());
        int statusCode = qe.getBottomQueryException().getStatusCode();
        throw new DatawaveWebApplicationException(qe, response, statusCode);
    }
}
Also used : PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) NoResultsQueryException(datawave.webservice.query.exception.NoResultsQueryException) QueryCanceledQueryException(datawave.webservice.query.exception.QueryCanceledQueryException) QueryException(datawave.webservice.query.exception.QueryException) UnauthorizedQueryException(datawave.webservice.query.exception.UnauthorizedQueryException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) Connection(java.sql.Connection) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) IOException(java.io.IOException) CachedResultsResponse(datawave.webservice.result.CachedResultsResponse) Principal(java.security.Principal) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) EJBException(javax.ejb.EJBException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) NoResultsQueryException(datawave.webservice.query.exception.NoResultsQueryException) BatchUpdateException(java.sql.BatchUpdateException) SQLException(java.sql.SQLException) IOException(java.io.IOException) QueryCanceledQueryException(datawave.webservice.query.exception.QueryCanceledQueryException) QueryException(datawave.webservice.query.exception.QueryException) QueryCanceledException(datawave.webservice.common.exception.QueryCanceledException) PreConditionFailedException(datawave.webservice.common.exception.PreConditionFailedException) NotFoundException(datawave.webservice.common.exception.NotFoundException) UnauthorizedQueryException(datawave.webservice.query.exception.UnauthorizedQueryException) UnauthorizedException(datawave.webservice.common.exception.UnauthorizedException) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) NoResultsException(datawave.webservice.common.exception.NoResultsException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) MalformedURLException(java.net.MalformedURLException) UnauthorizedQueryException(datawave.webservice.query.exception.UnauthorizedQueryException) GenerateQuerySessionId(datawave.annotation.GenerateQuerySessionId) Interceptors(javax.interceptor.Interceptors) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) PUT(javax.ws.rs.PUT)

Example 2 with GenerateQuerySessionId

use of datawave.annotation.GenerateQuerySessionId in project datawave by NationalSecurityAgency.

the class QueryExecutorBean method defineQuery.

/**
 * @param queryLogicName
 * @param queryParameters
 * @return
 */
@POST
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff" })
@Path("/{logicName}/define")
@GZIP
@GenerateQuerySessionId(cookieBasePath = "/DataWave/Query/")
@EnrichQueryMetrics(methodType = MethodType.CREATE)
@Interceptors({ RequiredInterceptor.class, ResponseInterceptor.class })
@Timed(name = "dw.query.defineQuery", absolute = true)
public GenericResponse<String> defineQuery(@Required("logicName") @PathParam("logicName") String queryLogicName, MultivaluedMap<String, String> queryParameters, @Context HttpHeaders httpHeaders) {
    CreateQuerySessionIDFilter.QUERY_ID.set(null);
    QueryData qd = validateQuery(queryLogicName, queryParameters, httpHeaders);
    GenericResponse<String> response = new GenericResponse<>();
    // We need to put a disconnected RunningQuery instance into the cache. Otherwise TRANSIENT queries
    // will not exist when reset is called.
    Span defineSpan = null;
    RunningQuery rq;
    try {
        MultivaluedMap<String, String> optionalQueryParameters = new MultivaluedMapImpl<>();
        optionalQueryParameters.putAll(qp.getUnknownParameters(queryParameters));
        Query q = persister.create(qd.userDn, qd.dnList, marking, queryLogicName, qp, optionalQueryParameters);
        response.setResult(q.getId().toString());
        // If we're supposed to trace this query, then turn tracing on and set information about the query
        // onto the span so that it is saved in the trace table.
        TInfo traceInfo = null;
        boolean shouldTraceQuery = shouldTraceQuery(qp.getQuery(), qd.userid, false);
        if (shouldTraceQuery) {
            Span span = Trace.on("query:" + q.getId());
            log.debug("Tracing query " + q.getId() + " [" + qp.getQuery() + "] on trace ID " + Long.toHexString(span.traceId()));
            for (Entry<String, List<String>> param : queryParameters.entrySet()) {
                span.data(param.getKey(), param.getValue().get(0));
            }
            traceInfo = Tracer.traceInfo();
            defineSpan = Trace.start("query:define");
        }
        AccumuloConnectionFactory.Priority priority = qd.logic.getConnectionPriority();
        rq = new RunningQuery(metrics, null, priority, qd.logic, q, qp.getAuths(), qd.p, new RunningQueryTimingImpl(queryExpirationConf, qp.getPageTimeout()), this.executor, this.predictor, this.metricFactory);
        rq.setActiveCall(true);
        rq.getMetric().setProxyServers(qd.proxyServers);
        rq.setTraceInfo(traceInfo);
        queryCache.put(q.getId().toString(), rq);
        rq.setActiveCall(false);
        CreateQuerySessionIDFilter.QUERY_ID.set(q.getId().toString());
        return response;
    } catch (DatawaveWebApplicationException e) {
        throw e;
    } catch (Exception e) {
        log.error("Error accessing optional query parameters", e);
        QueryException qe = new QueryException(DatawaveErrorCode.RUNNING_QUERY_CACHE_ERROR, e);
        response.addException(qe.getBottomQueryException());
        int statusCode = qe.getBottomQueryException().getStatusCode();
        throw new DatawaveWebApplicationException(qe, response, statusCode);
    } finally {
        if (null != defineSpan) {
            // couple milliseconds just to ensure we get something saved.
            try {
                Thread.sleep(2);
            } catch (InterruptedException e) {
            // ignore
            }
            defineSpan.stop();
        // TODO: not sure this makes any sense anymore in Accumulo 1.8.1
        // if (null != defineSpan.parent()) {
        // // Stop the main query span since we're done working with it on this thread.
        // // We'll continue it later.
        // defineSpan.parent().stop();
        // }
        }
    }
}
Also used : TInfo(org.apache.accumulo.core.trace.thrift.TInfo) Query(datawave.webservice.query.Query) GenericResponse(datawave.webservice.result.GenericResponse) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) Span(org.apache.accumulo.core.trace.Span) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) CancellationException(java.util.concurrent.CancellationException) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) WebApplicationException(javax.ws.rs.WebApplicationException) HeuristicMixedException(javax.transaction.HeuristicMixedException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) NoResultsQueryException(datawave.webservice.query.exception.NoResultsQueryException) IOException(java.io.IOException) QueryException(datawave.webservice.query.exception.QueryException) BadRequestException(datawave.webservice.common.exception.BadRequestException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) UnauthorizedQueryException(datawave.webservice.query.exception.UnauthorizedQueryException) JAXBException(javax.xml.bind.JAXBException) UnauthorizedException(datawave.webservice.common.exception.UnauthorizedException) NoResultsException(datawave.webservice.common.exception.NoResultsException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RollbackException(javax.transaction.RollbackException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) AccumuloConnectionFactory(datawave.webservice.common.connection.AccumuloConnectionFactory) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) NoResultsQueryException(datawave.webservice.query.exception.NoResultsQueryException) QueryException(datawave.webservice.query.exception.QueryException) UnauthorizedQueryException(datawave.webservice.query.exception.UnauthorizedQueryException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) ArrayList(java.util.ArrayList) List(java.util.List) RunningQueryTimingImpl(datawave.webservice.query.cache.RunningQueryTimingImpl) Path(javax.ws.rs.Path) GenerateQuerySessionId(datawave.annotation.GenerateQuerySessionId) Interceptors(javax.interceptor.Interceptors) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GZIP(org.jboss.resteasy.annotations.GZIP) EnrichQueryMetrics(datawave.webservice.query.annotation.EnrichQueryMetrics)

Example 3 with GenerateQuerySessionId

use of datawave.annotation.GenerateQuerySessionId in project datawave by NationalSecurityAgency.

the class QueryExecutorBean method lookupContentByUUIDBatch.

/**
 * @param queryParameters
 * @param httpHeaders
 * @return content results, either as a paged BaseQueryResponse or StreamingOutput
 * @RequestHeader X-ProxiedEntitiesChain use when proxying request for user, by specifying a chain of DNs of the identities to proxy
 * @RequestHeader X-ProxiedIssuersChain required when using X-ProxiedEntitiesChain, specify one issuer DN per subject DN listed in X-ProxiedEntitiesChain
 * @ResponseHeader query-session-id this header and value will be in the Set-Cookie header, subsequent calls for this session will need to supply the
 *                 query-session-id header in the request in a Cookie header or as a query parameter
 * @ResponseHeader X-OperationTimeInMS time spent on the server performing the operation, does not account for network or result serialization
 * @ResponseHeader X-Partial-Results true if the page contains less than the requested number of results
 *
 * @HTTP 200 success
 * @HTTP 204 success and no results
 * @HTTP 400 invalid or missing parameter
 * @HTTP 500 internal server error
 */
@POST
@Path("/lookupContentUUID")
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff" })
@GZIP
@GenerateQuerySessionId(cookieBasePath = "/DataWave/Query/")
@Interceptors({ ResponseInterceptor.class, RequiredInterceptor.class })
@Override
@Timed(name = "dw.query.lookupContentUUIDBatch", absolute = true)
public <T> T lookupContentByUUIDBatch(MultivaluedMap<String, String> queryParameters, @Required("httpHeaders") @Context HttpHeaders httpHeaders) {
    if (!queryParameters.containsKey("uuidPairs")) {
        throw new BadRequestException(new IllegalArgumentException("uuidPairs missing from query parameters"), new VoidResponse());
    }
    T response = null;
    String queryId = null;
    try {
        String uuidPairs = queryParameters.getFirst("uuidPairs");
        String streaming = queryParameters.getFirst("streaming");
        boolean streamingOutput = false;
        if (!StringUtils.isEmpty(streaming)) {
            streamingOutput = Boolean.parseBoolean(streaming);
        }
        // Create the criteria for looking up the respective events, which we need to get the shard IDs and column families
        // required for the content lookup
        final PostUUIDCriteria criteria = new PostUUIDCriteria(uuidPairs, queryParameters);
        // Set the HTTP headers if a streamed response is required
        if (streamingOutput) {
            criteria.setStreamingOutputHeaders(httpHeaders);
        }
        response = this.lookupUUIDUtil.lookupContentByUUIDs(criteria);
        if (response instanceof BaseQueryResponse) {
            queryId = ((BaseQueryResponse) response).getQueryId();
        }
        return response;
    } finally {
        if (null != queryId) {
            asyncClose(queryId);
        }
    }
}
Also used : GET(javax.ws.rs.GET) POST(javax.ws.rs.POST) PUT(javax.ws.rs.PUT) VoidResponse(datawave.webservice.result.VoidResponse) BaseQueryResponse(datawave.webservice.result.BaseQueryResponse) BadRequestException(datawave.webservice.common.exception.BadRequestException) PostUUIDCriteria(datawave.webservice.query.util.PostUUIDCriteria) Path(javax.ws.rs.Path) GenerateQuerySessionId(datawave.annotation.GenerateQuerySessionId) Interceptors(javax.interceptor.Interceptors) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 4 with GenerateQuerySessionId

use of datawave.annotation.GenerateQuerySessionId in project datawave by NationalSecurityAgency.

the class QueryExecutorBean method createQuery.

/**
 * @param queryLogicName
 * @param queryParameters
 * @return
 */
@POST
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff" })
@Path("/{logicName}/create")
@GZIP
@GenerateQuerySessionId(cookieBasePath = "/DataWave/Query/")
@EnrichQueryMetrics(methodType = MethodType.CREATE)
@Interceptors({ RequiredInterceptor.class, ResponseInterceptor.class })
@Timed(name = "dw.query.createQuery", absolute = true)
public GenericResponse<String> createQuery(@Required("logicName") @PathParam("logicName") String queryLogicName, MultivaluedMap<String, String> queryParameters, @Context HttpHeaders httpHeaders) {
    CreateQuerySessionIDFilter.QUERY_ID.set(null);
    QueryData qd = validateQuery(queryLogicName, queryParameters, httpHeaders);
    GenericResponse<String> response = new GenericResponse<>();
    Query q = null;
    Connector connection = null;
    AccumuloConnectionFactory.Priority priority;
    Span createSpan = null;
    RunningQuery rq = null;
    try {
        // Default hasResults to true. If a query logic is actually able to set this value,
        // then their value will overwrite this one. Otherwise, we return true so that
        // callers know they have to call next (even though next may not return results).
        response.setHasResults(true);
        AuditType auditType = qd.logic.getAuditType(null);
        try {
            MultivaluedMap<String, String> optionalQueryParameters = new MultivaluedMapImpl<>();
            optionalQueryParameters.putAll(qp.getUnknownParameters(queryParameters));
            q = persister.create(qd.userDn, qd.dnList, marking, queryLogicName, qp, optionalQueryParameters);
            auditType = qd.logic.getAuditType(q);
        } finally {
            queryParameters.add(PrivateAuditConstants.AUDIT_TYPE, auditType.name());
            if (!auditType.equals(AuditType.NONE)) {
                // audit the query before its executed.
                try {
                    try {
                        List<String> selectors = qd.logic.getSelectors(q);
                        if (selectors != null && !selectors.isEmpty()) {
                            queryParameters.put(PrivateAuditConstants.SELECTORS, selectors);
                        }
                    } catch (Exception e) {
                        log.error("Error accessing query selector", e);
                    }
                    // if the user didn't set an audit id, use the query id
                    if (!queryParameters.containsKey(AuditParameters.AUDIT_ID)) {
                        queryParameters.putSingle(AuditParameters.AUDIT_ID, q.getId().toString());
                    }
                    auditor.audit(queryParameters);
                } catch (IllegalArgumentException e) {
                    log.error("Error validating audit parameters", e);
                    BadRequestQueryException qe = new BadRequestQueryException(DatawaveErrorCode.MISSING_REQUIRED_PARAMETER, e);
                    response.addException(qe);
                    throw new BadRequestException(qe, response);
                } catch (Exception e) {
                    log.error("Error auditing query", e);
                    QueryException qe = new QueryException(DatawaveErrorCode.QUERY_AUDITING_ERROR, e);
                    response.addException(qe);
                    throw qe;
                }
            }
        }
        priority = qd.logic.getConnectionPriority();
        Map<String, String> trackingMap = connectionFactory.getTrackingMap(Thread.currentThread().getStackTrace());
        addQueryToTrackingMap(trackingMap, q);
        accumuloConnectionRequestBean.requestBegin(q.getId().toString());
        try {
            connection = connectionFactory.getConnection(qd.logic.getConnPoolName(), priority, trackingMap);
        } finally {
            accumuloConnectionRequestBean.requestEnd(q.getId().toString());
        }
        // If we're supposed to trace this query, then turn tracing on and set information about the query
        // onto the span so that it is saved in the trace table.
        TInfo traceInfo = null;
        boolean shouldTraceQuery = shouldTraceQuery(qp.getQuery(), qd.userid, qp.isTrace());
        if (shouldTraceQuery) {
            Span span = Trace.on("query:" + q.getId());
            log.debug("Tracing query " + q.getId() + " [" + qp.getQuery() + "] on trace ID " + Long.toHexString(span.traceId()));
            for (Entry<String, List<String>> param : queryParameters.entrySet()) {
                span.data(param.getKey(), param.getValue().get(0));
            }
            traceInfo = Tracer.traceInfo();
            createSpan = Trace.start("query:create");
        }
        // hold on to a reference of the query logic so we cancel it if need be.
        qlCache.add(q.getId().toString(), qd.userid, qd.logic, connection);
        rq = new RunningQuery(metrics, null, priority, qd.logic, q, qp.getAuths(), qd.p, new RunningQueryTimingImpl(queryExpirationConf, qp.getPageTimeout()), this.executor, this.predictor, this.metricFactory);
        rq.setActiveCall(true);
        rq.setTraceInfo(traceInfo);
        rq.getMetric().setProxyServers(qd.proxyServers);
        rq.setConnection(connection);
        // Put in the cache by id. Don't put the cache in by name because multiple users may use the same name
        // and only the last one will be in the cache.
        queryCache.put(q.getId().toString(), rq);
        response.setResult(q.getId().toString());
        rq.setActiveCall(false);
        CreateQuerySessionIDFilter.QUERY_ID.set(q.getId().toString());
        return response;
    } catch (Throwable t) {
        response.setHasResults(false);
        if (rq != null) {
            rq.getMetric().setError(t);
        }
        // close the logic on exception
        try {
            if (null != qd.logic) {
                qd.logic.close();
            }
        } catch (Exception e) {
            log.error("Exception occured while closing query logic; may be innocuous if scanners were running.", e);
        }
        if (null != connection) {
            try {
                connectionFactory.returnConnection(connection);
            } catch (Exception e) {
                log.error("Error returning connection on failed create", e);
            }
        }
        try {
            if (null != q)
                persister.remove(q);
        } catch (Exception e) {
            response.addException(new QueryException(DatawaveErrorCode.DEPERSIST_ERROR, e).getBottomQueryException());
        }
        /*
             * Allow web services to throw their own WebApplicationExceptions
             */
        if (t instanceof Error && !(t instanceof TokenMgrError)) {
            log.error(t.getMessage(), t);
            throw (Error) t;
        } else if (t instanceof WebApplicationException) {
            log.error(t.getMessage(), t);
            throw ((WebApplicationException) t);
        } else if (t instanceof InterruptedException) {
            if (rq != null) {
                rq.getMetric().setLifecycle(QueryMetric.Lifecycle.CANCELLED);
            }
            log.info("Query " + q.getId() + " canceled on request");
            QueryException qe = new QueryException(DatawaveErrorCode.QUERY_CANCELED, t);
            response.addException(qe.getBottomQueryException());
            int statusCode = qe.getBottomQueryException().getStatusCode();
            throw new DatawaveWebApplicationException(qe, response, statusCode);
        } else {
            log.error(t.getMessage(), t);
            QueryException qe = new QueryException(DatawaveErrorCode.RUNNING_QUERY_CACHE_ERROR, t);
            response.addException(qe.getBottomQueryException());
            int statusCode = qe.getBottomQueryException().getStatusCode();
            throw new DatawaveWebApplicationException(qe, response, statusCode);
        }
    } finally {
        if (createSpan != null) {
            createSpan.stop();
        // TODO: not sure this makes any sense anymore in Accumulo 1.8.1
        // Stop the main query span since we're done working with it on this thread.
        // We'll continue it later.
        // createSpan.parent().stop();
        }
        if (null != q) {
            // - Remove the logic from the cache
            qlCache.poll(q.getId().toString());
        }
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Query(datawave.webservice.query.Query) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) WebApplicationException(javax.ws.rs.WebApplicationException) Span(org.apache.accumulo.core.trace.Span) AccumuloConnectionFactory(datawave.webservice.common.connection.AccumuloConnectionFactory) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) ArrayList(java.util.ArrayList) List(java.util.List) TInfo(org.apache.accumulo.core.trace.thrift.TInfo) GenericResponse(datawave.webservice.result.GenericResponse) AuditType(datawave.webservice.common.audit.Auditor.AuditType) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) TokenMgrError(org.apache.commons.jexl2.parser.TokenMgrError) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) TokenMgrError(org.apache.commons.jexl2.parser.TokenMgrError) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) CancellationException(java.util.concurrent.CancellationException) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) WebApplicationException(javax.ws.rs.WebApplicationException) HeuristicMixedException(javax.transaction.HeuristicMixedException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) NoResultsQueryException(datawave.webservice.query.exception.NoResultsQueryException) IOException(java.io.IOException) QueryException(datawave.webservice.query.exception.QueryException) BadRequestException(datawave.webservice.common.exception.BadRequestException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) UnauthorizedQueryException(datawave.webservice.query.exception.UnauthorizedQueryException) JAXBException(javax.xml.bind.JAXBException) UnauthorizedException(datawave.webservice.common.exception.UnauthorizedException) NoResultsException(datawave.webservice.common.exception.NoResultsException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RollbackException(javax.transaction.RollbackException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) NoResultsQueryException(datawave.webservice.query.exception.NoResultsQueryException) QueryException(datawave.webservice.query.exception.QueryException) UnauthorizedQueryException(datawave.webservice.query.exception.UnauthorizedQueryException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) BadRequestException(datawave.webservice.common.exception.BadRequestException) RunningQueryTimingImpl(datawave.webservice.query.cache.RunningQueryTimingImpl) Path(javax.ws.rs.Path) GenerateQuerySessionId(datawave.annotation.GenerateQuerySessionId) Interceptors(javax.interceptor.Interceptors) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GZIP(org.jboss.resteasy.annotations.GZIP) EnrichQueryMetrics(datawave.webservice.query.annotation.EnrichQueryMetrics)

Example 5 with GenerateQuerySessionId

use of datawave.annotation.GenerateQuerySessionId in project datawave by NationalSecurityAgency.

the class QueryExecutorBean method lookupUUIDBatch.

/**
 * @param queryParameters
 * @param httpHeaders
 * @return event results, either as a paged BaseQueryResponse or StreamingOutput
 * @RequestHeader X-ProxiedEntitiesChain use when proxying request for user, by specifying a chain of DNs of the identities to proxy
 * @RequestHeader X-ProxiedIssuersChain required when using X-ProxiedEntitiesChain, specify one issuer DN per subject DN listed in X-ProxiedEntitiesChain
 * @ResponseHeader query-session-id this header and value will be in the Set-Cookie header, subsequent calls for this session will need to supply the
 *                 query-session-id header in the request in a Cookie header or as a query parameter
 * @ResponseHeader X-OperationTimeInMS time spent on the server performing the operation, does not account for network or result serialization
 * @ResponseHeader X-Partial-Results true if the page contains less than the requested number of results
 *
 * @HTTP 200 success
 * @HTTP 204 success and no results
 * @HTTP 400 invalid or missing parameter
 * @HTTP 500 internal server error
 */
@POST
@Path("/lookupUUID")
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff" })
@GZIP
@GenerateQuerySessionId(cookieBasePath = "/DataWave/Query/")
@Interceptors({ ResponseInterceptor.class, RequiredInterceptor.class })
@Override
@Timed(name = "dw.query.lookupUUIDBatch", absolute = true)
public <T> T lookupUUIDBatch(MultivaluedMap<String, String> queryParameters, @Required("httpHeaders") @Context HttpHeaders httpHeaders) {
    if (!queryParameters.containsKey("uuidPairs")) {
        throw new BadRequestException(new IllegalArgumentException("uuidPairs missing from query parameters"), new VoidResponse());
    }
    T response;
    String queryId = null;
    try {
        String uuidPairs = queryParameters.getFirst("uuidPairs");
        String streaming = queryParameters.getFirst("streaming");
        boolean streamingOutput = false;
        if (!StringUtils.isEmpty(streaming)) {
            streamingOutput = Boolean.parseBoolean(streaming);
        }
        final PostUUIDCriteria criteria = new PostUUIDCriteria(uuidPairs, queryParameters);
        if (streamingOutput) {
            criteria.setStreamingOutputHeaders(httpHeaders);
        }
        response = this.lookupUUIDUtil.createUUIDQueryAndNext(criteria);
        if (response instanceof BaseQueryResponse) {
            queryId = ((BaseQueryResponse) response).getQueryId();
        }
        return response;
    } finally {
        if (null != queryId) {
            asyncClose(queryId);
        }
    }
}
Also used : GET(javax.ws.rs.GET) POST(javax.ws.rs.POST) PUT(javax.ws.rs.PUT) VoidResponse(datawave.webservice.result.VoidResponse) BaseQueryResponse(datawave.webservice.result.BaseQueryResponse) BadRequestException(datawave.webservice.common.exception.BadRequestException) PostUUIDCriteria(datawave.webservice.query.util.PostUUIDCriteria) Path(javax.ws.rs.Path) GenerateQuerySessionId(datawave.annotation.GenerateQuerySessionId) Interceptors(javax.interceptor.Interceptors) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GZIP(org.jboss.resteasy.annotations.GZIP)

Aggregations

GenerateQuerySessionId (datawave.annotation.GenerateQuerySessionId)13 Timed (com.codahale.metrics.annotation.Timed)11 Interceptors (javax.interceptor.Interceptors)11 Produces (javax.ws.rs.Produces)11 POST (javax.ws.rs.POST)10 QueryException (datawave.webservice.query.exception.QueryException)8 DatawaveWebApplicationException (datawave.webservice.common.exception.DatawaveWebApplicationException)7 NoResultsException (datawave.webservice.common.exception.NoResultsException)7 BadRequestQueryException (datawave.webservice.query.exception.BadRequestQueryException)7 NoResultsQueryException (datawave.webservice.query.exception.NoResultsQueryException)7 NotFoundQueryException (datawave.webservice.query.exception.NotFoundQueryException)7 PreConditionFailedQueryException (datawave.webservice.query.exception.PreConditionFailedQueryException)7 UnauthorizedQueryException (datawave.webservice.query.exception.UnauthorizedQueryException)7 IOException (java.io.IOException)7 Path (javax.ws.rs.Path)7 UnauthorizedException (datawave.webservice.common.exception.UnauthorizedException)6 GZIP (org.jboss.resteasy.annotations.GZIP)6 BadRequestException (datawave.webservice.common.exception.BadRequestException)5 MultivaluedMapImpl (org.jboss.resteasy.specimpl.MultivaluedMapImpl)4 DatawavePrincipal (datawave.security.authorization.DatawavePrincipal)3