Search in sources :

Example 1 with NotFoundQueryException

use of datawave.webservice.query.exception.NotFoundQueryException in project datawave by NationalSecurityAgency.

the class DocumentSerialization method consumeHeader.

public static InputStream consumeHeader(byte[] data) throws InvalidDocumentHeader {
    if (null == data || 3 > data.length) {
        QueryException qe = new QueryException(DatawaveErrorCode.DATA_INVALID_ERROR, MessageFormat.format("Length: {0}", (null != data ? data.length : null)));
        throw new InvalidDocumentHeader(qe);
    }
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    int magic = readUShort(bais);
    if (DOC_MAGIC != magic) {
        NotFoundQueryException qe = new NotFoundQueryException(DatawaveErrorCode.EXPECTED_HEADER_NOT_FOUND);
        throw new InvalidDocumentHeader(qe);
    }
    int compression = readUByte(bais);
    if (NONE == compression) {
        return new ByteArrayInputStream(data, 3, data.length - 3);
    } else if (GZIP == compression) {
        ByteArrayInputStream bytes = new ByteArrayInputStream(data, 3, data.length - 3);
        return new InflaterInputStream(bytes, new Inflater(), 1024);
    } else {
        BadRequestQueryException qe = new BadRequestQueryException(DatawaveErrorCode.UNKNOWN_COMPRESSION_SCHEME, MessageFormat.format("{0}", compression));
        throw new InvalidDocumentHeader(qe);
    }
}
Also used : InvalidDocumentHeader(datawave.query.exceptions.InvalidDocumentHeader) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) QueryException(datawave.webservice.query.exception.QueryException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) ByteArrayInputStream(java.io.ByteArrayInputStream) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) InflaterInputStream(java.util.zip.InflaterInputStream) Inflater(java.util.zip.Inflater) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException)

Example 2 with NotFoundQueryException

use of datawave.webservice.query.exception.NotFoundQueryException in project datawave by NationalSecurityAgency.

the class FunctionQueryNodeBuilder method build.

public JexlNode build(QueryNode queryNode) {
    JexlNode returnNode = null;
    int depth = 0;
    QueryNode parent = queryNode;
    while ((parent = parent.getParent()) != null) {
        depth++;
    }
    if (queryNode instanceof FunctionQueryNode) {
        FunctionQueryNode functionQueryNode = (FunctionQueryNode) queryNode;
        String functionName = functionQueryNode.getFunction();
        List<String> parameterList = functionQueryNode.getParameterList();
        JexlQueryFunction referenceFunction = allowedFunctionMap.get(functionName.toUpperCase());
        if (referenceFunction == null) {
            NotFoundQueryException qe = new NotFoundQueryException(DatawaveErrorCode.FUNCTION_NOT_FOUND, MessageFormat.format("{0}", functionName));
            throw new IllegalArgumentException(qe);
        }
        // if more than one term in quotes, use an AdjNode
        JexlQueryFunction function = (JexlQueryFunction) referenceFunction.duplicate();
        returnNode = new JexlFunctionNode(function, parameterList, depth, queryNode.getParent());
    }
    return returnNode;
}
Also used : JexlFunctionNode(datawave.query.language.parser.jexl.JexlFunctionNode) FieldQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode) FunctionQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.FunctionQueryNode) QueryNode(org.apache.lucene.queryparser.flexible.core.nodes.QueryNode) FunctionQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.FunctionQueryNode) JexlNode(datawave.query.language.parser.jexl.JexlNode) JexlQueryFunction(datawave.query.language.functions.jexl.JexlQueryFunction) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException)

Example 3 with NotFoundQueryException

use of datawave.webservice.query.exception.NotFoundQueryException in project datawave by NationalSecurityAgency.

the class CachedResultsBean method status.

/**
 * Returns status of the requested cached result
 *
 * @param queryId
 * @return List of attribute names that can be used in subsequent queries
 *
 * @return {@code datawave.webservice.result.GenericResponse<String>}
 * @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 X-OperationTimeInMS time spent on the server performing the operation, does not account for network or result serialization
 *
 * @HTTP 200 success
 * @HTTP 404 not found
 * @HTTP 412 not yet loaded
 * @HTTP 500 internal server error
 */
@GET
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf" })
@javax.ws.rs.Path("/{queryId}/status")
@GZIP
@Interceptors({ RequiredInterceptor.class, ResponseInterceptor.class })
@Timed(name = "dw.cachedr.status", absolute = true)
public GenericResponse<String> status(@PathParam("queryId") @Required("queryId") String queryId) {
    GenericResponse<String> response = new GenericResponse<>();
    // Find out who/what called this method
    Principal p = ctx.getCallerPrincipal();
    String owner = getOwnerFromPrincipal(p);
    CachedRunningQuery crq;
    try {
        crq = retrieve(queryId, owner);
    } catch (IOException e1) {
        PreConditionFailedQueryException e = new PreConditionFailedQueryException(DatawaveErrorCode.CACHED_RESULTS_IMPORT_ERROR, e1);
        response.addException(e);
        response.setResult("CachedResult not found");
        throw new PreConditionFailedException(e, response);
    }
    if (null == crq) {
        NotFoundQueryException e = new NotFoundQueryException(DatawaveErrorCode.CACHED_RESULT_NOT_FOUND);
        response.addException(e);
        response.setResult("CachedResult not found");
        throw new NotFoundException(e, response);
    }
    if (!crq.getUser().equals(owner)) {
        UnauthorizedQueryException e = new UnauthorizedQueryException(DatawaveErrorCode.QUERY_OWNER_MISMATCH, MessageFormat.format("{0} != {1}", crq.getUser(), owner));
        response.addException(e);
        response.setResult("Current user does not match user that defined query.");
        throw new UnauthorizedException(e, response);
    }
    CachedRunningQuery.Status status = crq.getStatus();
    if (status == null) {
        response.setResult(CachedRunningQuery.Status.NONE.toString());
    } else {
        response.setResult(status.toString());
    }
    if (crq.getStatusMessage() != null && crq.getStatusMessage().isEmpty() == false) {
        response.addMessage(crq.getStatusMessage());
    }
    return response;
}
Also used : GenericResponse(datawave.webservice.result.GenericResponse) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) NotFoundException(datawave.webservice.common.exception.NotFoundException) IOException(java.io.IOException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) UnauthorizedQueryException(datawave.webservice.query.exception.UnauthorizedQueryException) PreConditionFailedException(datawave.webservice.common.exception.PreConditionFailedException) UnauthorizedException(datawave.webservice.common.exception.UnauthorizedException) Principal(java.security.Principal) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) Interceptors(javax.interceptor.Interceptors) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 4 with NotFoundQueryException

use of datawave.webservice.query.exception.NotFoundQueryException in project datawave by NationalSecurityAgency.

the class CachedResultsBean method cancelLoad.

/**
 * Cancel the load process.
 *
 * @param originalQueryId
 *
 * @return datawave.webservice.result.VoidResponse
 * @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
 * @RequestHeader query-session-id session id value used for load balancing purposes. query-session-id can be placed 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 401 caller is not authorized to cancel the query
 */
@PUT
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff" })
@javax.ws.rs.Path("/{queryId}/cancel")
@GZIP
@ClearQuerySessionId
@Interceptors({ RequiredInterceptor.class, ResponseInterceptor.class })
@Timed(name = "dw.cachedr.cancel", absolute = true)
public VoidResponse cancelLoad(@PathParam("queryId") @Required("queryId") String originalQueryId) {
    // Find out who/what called this method
    Principal p = ctx.getCallerPrincipal();
    String owner = getOwnerFromPrincipal(p);
    VoidResponse response = new VoidResponse();
    try {
        // check if query is even loading
        RunningQuery query = CachedResultsBean.loadingQueryMap.get(originalQueryId);
        if (query == null) {
            NotFoundQueryException e = new NotFoundQueryException(DatawaveErrorCode.NO_QUERY_OBJECT_MATCH);
            throw new NotFoundException(e, response);
        } else {
            if (query.getSettings().getOwner().equals(owner)) {
                accumuloConnectionRequestBean.cancelConnectionRequest(originalQueryId);
                query.cancel();
                response.addMessage("CachedResults load canceled.");
            } else {
                UnauthorizedQueryException e = new UnauthorizedQueryException(DatawaveErrorCode.QUERY_OWNER_MISMATCH, MessageFormat.format("{0} != {1}", query.getSettings().getOwner(), owner));
                throw new UnauthorizedException(e, response);
            }
        }
        return response;
    } catch (DatawaveWebApplicationException e) {
        throw e;
    } catch (Exception e) {
        QueryException qe = new QueryException(DatawaveErrorCode.CANCELLATION_ERROR, e, MessageFormat.format("query_id: {0}", originalQueryId));
        log.error(qe);
        response.addException(qe.getBottomQueryException());
        int statusCode = qe.getBottomQueryException().getStatusCode();
        throw new DatawaveWebApplicationException(qe, response, statusCode);
    }
}
Also used : RunningQuery(datawave.webservice.query.runner.RunningQuery) 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) VoidResponse(datawave.webservice.result.VoidResponse) UnauthorizedException(datawave.webservice.common.exception.UnauthorizedException) NotFoundException(datawave.webservice.common.exception.NotFoundException) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) Principal(java.security.Principal) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) 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) Interceptors(javax.interceptor.Interceptors) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ClearQuerySessionId(datawave.annotation.ClearQuerySessionId) GZIP(org.jboss.resteasy.annotations.GZIP) PUT(javax.ws.rs.PUT)

Example 5 with NotFoundQueryException

use of datawave.webservice.query.exception.NotFoundQueryException in project datawave by NationalSecurityAgency.

the class MapReduceStatePersisterBean method updateState.

/**
 * Update the state of the Bulk Results entry
 *
 * @param mapReduceJobId
 *            job id
 * @param state
 *            new state
 * @throws QueryException
 *             when zero or more than one result is found for the id
 */
@PermitAll
public void updateState(String mapReduceJobId, MapReduceState state) throws QueryException {
    // We have the mapreduce job id and the new state, but we need to find out which id and sid this relates to
    // so that we can create a new mutation to put into the table.
    List<MapReduceServiceJobIndex> results = null;
    // Find the index entry for the jobid
    Connector c = null;
    try {
        Map<String, String> trackingMap = connectionFactory.getTrackingMap(Thread.currentThread().getStackTrace());
        c = connectionFactory.getConnection(AccumuloConnectionFactory.Priority.ADMIN, trackingMap);
        tableCheck(c);
        try (Scanner scanner = ScannerHelper.createScanner(c, INDEX_TABLE_NAME, Collections.singleton(new Authorizations()))) {
            Range range = new Range(mapReduceJobId, mapReduceJobId);
            scanner.setRange(range);
            for (Entry<Key, Value> entry : scanner) {
                if (null == results)
                    results = new ArrayList<>();
                results.add(MapReduceServiceJobIndex.parse(entry.getKey(), state));
            }
        }
    } catch (Exception e) {
        QueryException qe = new QueryException(DatawaveErrorCode.JOB_ID_LOOKUP_ERROR, e, MessageFormat.format("job_id: {0}", mapReduceJobId));
        log.error(qe);
        throw qe;
    } finally {
        try {
            connectionFactory.returnConnection(c);
        } catch (Exception e) {
            log.error("Error returning connection to pool", e);
        }
    }
    if (null == results)
        throw new NotFoundQueryException(DatawaveErrorCode.NO_QUERY_OBJECT_MATCH);
    if (results.size() > 1)
        throw new NotFoundQueryException(DatawaveErrorCode.TOO_MANY_QUERY_OBJECT_MATCHES);
    else {
        MapReduceServiceJobIndex r = results.get(0);
        // We will insert a new history column in the table
        Mutation m = new Mutation(r.getId());
        m.put(r.getUser(), STATE + NULL + r.getMapReduceJobId(), new Value(r.getState().getBytes()));
        c = null;
        BatchWriter writer = null;
        try {
            Map<String, String> trackingMap = connectionFactory.getTrackingMap(Thread.currentThread().getStackTrace());
            c = connectionFactory.getConnection(AccumuloConnectionFactory.Priority.ADMIN, trackingMap);
            tableCheck(c);
            writer = c.createBatchWriter(TABLE_NAME, new BatchWriterConfig().setMaxLatency(10, TimeUnit.SECONDS).setMaxMemory(10240L).setMaxWriteThreads(1));
            writer.addMutation(m);
            writer.flush();
        } catch (RuntimeException re) {
            throw re;
        } catch (Exception e) {
            QueryException qe = new QueryException(DatawaveErrorCode.JOB_STATE_UPDATE_ERROR, e, MessageFormat.format("job_id: {0}", mapReduceJobId));
            log.error(qe);
            throw qe;
        } finally {
            try {
                if (null != writer)
                    writer.close();
                connectionFactory.returnConnection(c);
            } catch (Exception e) {
                log.error("Error creating query", e);
            }
        }
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) ArrayList(java.util.ArrayList) Range(org.apache.accumulo.core.data.Range) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) QueryException(datawave.webservice.query.exception.QueryException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) QueryException(datawave.webservice.query.exception.QueryException) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) Mutation(org.apache.accumulo.core.data.Mutation) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Key(org.apache.accumulo.core.data.Key) PermitAll(javax.annotation.security.PermitAll)

Aggregations

NotFoundQueryException (datawave.webservice.query.exception.NotFoundQueryException)28 QueryException (datawave.webservice.query.exception.QueryException)15 IOException (java.io.IOException)15 UnauthorizedQueryException (datawave.webservice.query.exception.UnauthorizedQueryException)14 BadRequestQueryException (datawave.webservice.query.exception.BadRequestQueryException)12 Produces (javax.ws.rs.Produces)12 GZIP (org.jboss.resteasy.annotations.GZIP)12 DatawavePrincipal (datawave.security.authorization.DatawavePrincipal)11 DatawaveWebApplicationException (datawave.webservice.common.exception.DatawaveWebApplicationException)10 NotFoundException (datawave.webservice.common.exception.NotFoundException)10 Principal (java.security.Principal)10 UnauthorizedException (datawave.webservice.common.exception.UnauthorizedException)8 PreConditionFailedQueryException (datawave.webservice.query.exception.PreConditionFailedQueryException)8 Query (datawave.webservice.query.Query)7 MapReduceInfoResponseList (datawave.webservice.results.mr.MapReduceInfoResponseList)7 GET (javax.ws.rs.GET)7 NoResultsQueryException (datawave.webservice.query.exception.NoResultsQueryException)6 GenericResponse (datawave.webservice.result.GenericResponse)6 MapReduceInfoResponse (datawave.webservice.results.mr.MapReduceInfoResponse)6 ArrayList (java.util.ArrayList)6