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