use of datawave.webservice.result.VoidResponse in project datawave by NationalSecurityAgency.
the class ModelBean method deleteMapping.
private VoidResponse deleteMapping(datawave.webservice.model.Model model, String modelTableName, boolean reloadCache) {
VoidResponse response = new VoidResponse();
Connector connector = null;
BatchWriter writer = null;
String tableName = this.checkModelTableName(modelTableName);
try {
Map<String, String> trackingMap = connectionFactory.getTrackingMap(Thread.currentThread().getStackTrace());
connector = connectionFactory.getConnection(AccumuloConnectionFactory.Priority.LOW, trackingMap);
writer = connector.createBatchWriter(tableName, new BatchWriterConfig().setMaxLatency(BATCH_WRITER_MAX_LATENCY, TimeUnit.MILLISECONDS).setMaxMemory(BATCH_WRITER_MAX_MEMORY).setMaxWriteThreads(BATCH_WRITER_MAX_THREADS));
for (FieldMapping mapping : model.getFields()) {
Mutation m = ModelKeyParser.createDeleteMutation(mapping, model.getName());
writer.addMutation(m);
}
} catch (Exception e) {
log.error("Could not delete mapping.", e);
QueryException qe = new QueryException(DatawaveErrorCode.MAPPING_DELETION_ERROR, e);
response.addException(qe.getBottomQueryException());
throw new DatawaveWebApplicationException(qe, response);
} finally {
if (null != writer) {
try {
writer.close();
} catch (MutationsRejectedException e1) {
QueryException qe = new QueryException(DatawaveErrorCode.WRITER_CLOSE_ERROR, e1);
log.error(qe);
response.addException(qe);
throw new DatawaveWebApplicationException(qe, response);
}
}
if (null != connector) {
try {
connectionFactory.returnConnection(connector);
} catch (Exception e) {
log.error("Error returning connection to factory", e);
}
}
}
if (reloadCache)
cache.reloadCache(tableName);
return response;
}
use of datawave.webservice.result.VoidResponse in project datawave by NationalSecurityAgency.
the class ModificationCacheBean method reloadMutableFieldCache.
/**
* @return datawave.webservice.result.VoidResponse
* @RequestHeader X-ProxiedEntitiesChain use when proxying request for user
* @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 202 if asynch is true - see Location response header for the job URI location
* @HTTP 400 invalid or missing parameter
* @HTTP 500 internal server error
*/
@GET
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff" })
@Path("/reloadCache")
@GZIP
@JmxManaged
public VoidResponse reloadMutableFieldCache() {
this.clearCache();
log.trace("cleared cache");
final VoidResponse resp = new VoidResponse();
Connector con = null;
BatchScanner s = null;
try {
Map<String, String> trackingMap = connectionFactory.getTrackingMap(Thread.currentThread().getStackTrace());
log.trace("getting mutable list from table " + this.modificationConfiguration.getTableName());
log.trace("modificationConfiguration.getPoolName() = " + modificationConfiguration.getPoolName());
con = connectionFactory.getConnection(modificationConfiguration.getPoolName(), Priority.ADMIN, trackingMap);
log.trace("got connection");
s = ScannerHelper.createBatchScanner(con, this.modificationConfiguration.getTableName(), Collections.singleton(con.securityOperations().getUserAuthorizations(con.whoami())), 8);
s.setRanges(Collections.singleton(new Range()));
s.fetchColumnFamily(MODIFICATION_COLUMN);
for (Entry<Key, Value> e : s) {
// Field name is in the row and datatype is in the colq.
String datatype = e.getKey().getColumnQualifier().toString();
log.trace("datatype = " + datatype);
String fieldName = e.getKey().getRow().toString();
log.trace("fieldname = " + fieldName);
if (null == cache.get(datatype))
cache.put(datatype, new HashSet<>());
cache.get(datatype).add(fieldName);
}
log.trace("cache size = " + cache.size());
for (Entry<String, Set<String>> e : cache.entrySet()) {
log.trace("datatype = " + e.getKey() + ", fieldcount = " + e.getValue().size());
}
} catch (Exception e) {
log.error("Error during initialization of ModificationCacheBean", e);
throw new EJBException("Error during initialization of ModificationCacheBean", e);
} finally {
if (null != s)
s.close();
try {
connectionFactory.returnConnection(con);
} catch (Exception e) {
log.error("Error returning connection to pool", e);
}
}
return resp;
}
use of datawave.webservice.result.VoidResponse in project datawave by NationalSecurityAgency.
the class QueryExecutorBean method close.
private VoidResponse close(String id, Principal principal) {
VoidResponse response = new VoidResponse();
try {
boolean connectionRequestCanceled = accumuloConnectionRequestBean.cancelConnectionRequest(id, principal);
Pair<QueryLogic<?>, Connector> tuple = qlCache.pollIfOwnedBy(id, ((DatawavePrincipal) principal).getShortName());
if (tuple == null) {
try {
RunningQuery query = getQueryById(id, principal);
close(query);
} catch (Exception e) {
log.debug("Failed to close " + id + ", checking if closed previously");
// if this is a query that is in the closed query cache, then we have already successfully closed this query so ignore
if (!closedQueryCache.exists(id)) {
log.debug("Failed to close " + id + ", checking if connection request was canceled");
// if connection request was canceled, then the call was successful even if a RunningQuery was not found
if (!connectionRequestCanceled) {
log.error("Failed to close " + id, e);
throw e;
}
}
}
response.addMessage(id + " closed.");
} else {
QueryLogic<?> logic = tuple.getFirst();
try {
logic.close();
} catch (Exception e) {
log.error("Exception occurred while closing query logic; may be innocuous if scanners were running.", e);
}
connectionFactory.returnConnection(tuple.getSecond());
response.addMessage(id + " closed before create completed.");
}
// no longer need to remember this query
closedQueryCache.remove(id);
return response;
} catch (DatawaveWebApplicationException e) {
throw e;
} catch (Exception e) {
QueryException qe = new QueryException(DatawaveErrorCode.CLOSE_ERROR, e, MessageFormat.format("query_id: {0}", id));
log.error(qe, e);
response.addException(qe.getBottomQueryException());
int statusCode = qe.getBottomQueryException().getStatusCode();
throw new DatawaveWebApplicationException(qe, response, statusCode);
}
}
use of datawave.webservice.result.VoidResponse in project datawave by NationalSecurityAgency.
the class QueryExecutorBean method disableTracing.
/**
* <strong>JBossAdministrator or Administrator credentials required.</strong> Disables tracing that was previously enabled using the
* {@link #enableTracing(String, String)} method.
*
* @param queryRegex
* (optional) the query regular expression defining queries to disable tracing
* @param user
* (optional) the user name for which to disable query tracing
* @return datawave.webservice.result.VoidResponse
*
* @HTTP 200 success
* @HTTP 400 if neither queryRegex nor user are specified
* @HTTP 401 if the user does not have Administrative credentials
*/
@GET
@Path("/disableTracing")
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff" })
@RolesAllowed({ "Administrator", "JBossAdministrator" })
@Override
public VoidResponse disableTracing(@QueryParam("queryRegex") String queryRegex, @QueryParam("user") String user) {
VoidResponse response = new VoidResponse();
if (queryRegex == null && user == null) {
BadRequestQueryException qe = new BadRequestQueryException(DatawaveErrorCode.QUERY_REGEX_OR_USER_REQUIRED);
response.addException(qe);
throw new BadRequestException(qe, response);
} else if (queryRegex == null) {
traceInfos.removeAll(user);
response.addMessage("All query tracing for " + user + " is disabled. Per-query tracing is still possible.");
} else {
traceInfos.remove(user, PatternWrapper.wrap(queryRegex));
response.addMessage("Queries for user " + user + " matching " + queryRegex + " have been disabled. Per-query tracing is still possible.");
}
// Put updated map back in the cache
queryTraceCache.put("traceInfos", traceInfos);
return response;
}
use of datawave.webservice.result.VoidResponse in project datawave by NationalSecurityAgency.
the class QueryExecutorBean method execute.
/**
* @param logicName
* @param queryParameters
*
* @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 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
@Produces("*/*")
@Path("/{logicName}/execute")
@GZIP
@Interceptors({ ResponseInterceptor.class, RequiredInterceptor.class })
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@Override
@Timed(name = "dw.query.executeQuery", absolute = true)
public StreamingOutput execute(@PathParam("logicName") String logicName, MultivaluedMap<String, String> queryParameters, @Context HttpHeaders httpHeaders) {
/**
* This method captures the metrics on the query instead of doing it in the QueryMetricsEnrichmentInterceptor. The ExecuteStreamingOutputResponse class
* is returned from this method and executed in the JAX-RS layer. It updates the metrics which are then updated on each call to the _next method.
*/
Collection<String> proxyServers = null;
Principal p = ctx.getCallerPrincipal();
DatawavePrincipal dp;
if (p instanceof DatawavePrincipal) {
dp = (DatawavePrincipal) p;
proxyServers = dp.getProxyServers();
}
final MediaType PB_MEDIA_TYPE = new MediaType("application", "x-protobuf");
final MediaType YAML_MEDIA_TYPE = new MediaType("application", "x-yaml");
final VoidResponse response = new VoidResponse();
// HttpHeaders.getAcceptableMediaTypes returns a priority sorted list of acceptable response types.
// Find the first one in the list that we support.
MediaType responseType = null;
for (MediaType type : httpHeaders.getAcceptableMediaTypes()) {
if (type.equals(MediaType.APPLICATION_XML_TYPE) || type.equals(MediaType.APPLICATION_JSON_TYPE) || type.equals(PB_MEDIA_TYPE) || type.equals(YAML_MEDIA_TYPE)) {
responseType = type;
break;
}
}
if (null == responseType) {
QueryException qe = new QueryException(DatawaveErrorCode.UNSUPPORTED_MEDIA_TYPE);
response.setHasResults(false);
response.addException(qe);
throw new DatawaveWebApplicationException(qe, response, MediaType.APPLICATION_XML_TYPE);
}
// reference query necessary to avoid NPEs in getting the Transformer and BaseResponse
Query q = new QueryImpl();
Date now = new Date();
q.setBeginDate(now);
q.setEndDate(now);
q.setExpirationDate(now);
q.setQuery("test");
q.setQueryAuthorizations("ALL");
ResultsPage emptyList = new ResultsPage();
// Find the response class
Class<?> responseClass;
try {
QueryLogic<?> l = queryLogicFactory.getQueryLogic(logicName, p);
QueryLogicTransformer t = l.getTransformer(q);
BaseResponse refResponse = t.createResponse(emptyList);
responseClass = refResponse.getClass();
} catch (Exception e) {
QueryException qe = new QueryException(DatawaveErrorCode.QUERY_TRANSFORM_ERROR, e);
log.error(qe, e);
response.setHasResults(false);
response.addException(qe.getBottomQueryException());
int statusCode = qe.getBottomQueryException().getStatusCode();
throw new DatawaveWebApplicationException(qe, response, statusCode, MediaType.APPLICATION_XML_TYPE);
}
SerializationType s;
if (responseType.equals(MediaType.APPLICATION_XML_TYPE)) {
s = SerializationType.XML;
} else if (responseType.equals(MediaType.APPLICATION_JSON_TYPE)) {
s = SerializationType.JSON;
} else if (responseType.equals(PB_MEDIA_TYPE)) {
if (!(Message.class.isAssignableFrom(responseClass))) {
QueryException qe = new QueryException(DatawaveErrorCode.BAD_RESPONSE_CLASS, MessageFormat.format("Response class: {0}", responseClass));
response.setHasResults(false);
response.addException(qe);
throw new DatawaveWebApplicationException(qe, response, MediaType.APPLICATION_XML_TYPE);
}
s = SerializationType.PB;
} else if (responseType.equals(YAML_MEDIA_TYPE)) {
if (!(Message.class.isAssignableFrom(responseClass))) {
QueryException qe = new QueryException(DatawaveErrorCode.BAD_RESPONSE_CLASS, MessageFormat.format("Response class: {0}", responseClass));
response.setHasResults(false);
response.addException(qe);
throw new DatawaveWebApplicationException(qe, response, MediaType.APPLICATION_XML_TYPE);
}
s = SerializationType.YAML;
} else {
QueryException qe = new QueryException(DatawaveErrorCode.INVALID_FORMAT, MessageFormat.format("format: {0}", responseType.toString()));
response.setHasResults(false);
response.addException(qe);
throw new DatawaveWebApplicationException(qe, response, MediaType.APPLICATION_XML_TYPE);
}
long start = System.nanoTime();
GenericResponse<String> createResponse = null;
try {
createResponse = this.createQuery(logicName, queryParameters, httpHeaders);
} catch (Throwable t) {
if (t instanceof DatawaveWebApplicationException) {
QueryException qe = (QueryException) ((DatawaveWebApplicationException) t).getCause();
response.setHasResults(false);
response.addException(qe.getBottomQueryException());
int statusCode = qe.getBottomQueryException().getStatusCode();
throw new DatawaveWebApplicationException(qe, response, statusCode, MediaType.APPLICATION_XML_TYPE);
} else {
throw t;
}
}
long createCallTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
final String queryId = createResponse.getResult();
// We created the query and put into cache, get the RunningQuery object
final RunningQuery rq = queryCache.get(queryId);
rq.getMetric().setCreateCallTime(createCallTime);
final Collection<String> proxies = proxyServers;
final SerializationType serializationType = s;
final Class<?> queryResponseClass = responseClass;
return new ExecuteStreamingOutputResponse(queryId, queryResponseClass, response, rq, serializationType, proxies);
}
Aggregations