use of datawave.webservice.query.logic.QueryLogic in project datawave by NationalSecurityAgency.
the class BulkResultsFileOutputMapper method setup.
@Override
protected void setup(org.apache.hadoop.mapreduce.Mapper<Key, Value, Key, Value>.Context context) throws IOException, InterruptedException {
if (System.getProperty("ignore.weld.startMain") == null) {
// Disable CDI extensions in Jersey libs
System.setProperty("com.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager", "true");
weld = new Weld("STATIC_INSTANCE");
weld.initialize();
}
super.setup(context);
Query query;
try {
Class<? extends Query> queryImplClass = Class.forName(context.getConfiguration().get(QUERY_IMPL_CLASS)).asSubclass(Query.class);
query = deserializeQuery(context.getConfiguration().get(QUERY_LOGIC_SETTINGS), queryImplClass);
} catch (JAXBException e) {
throw new RuntimeException("Error deserializing Query", e);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Error instantiating query impl class " + context.getConfiguration().get(QUERY_IMPL_CLASS), e);
}
final Configuration configuration = context.getConfiguration();
this.setApplicationContext(configuration.get(SPRING_CONFIG_LOCATIONS));
String logicName = context.getConfiguration().get(QUERY_LOGIC_NAME);
QueryLogic<?> logic = (QueryLogic<?>) super.applicationContext.getBean(logicName);
t = logic.getTransformer(query);
Assert.notNull(logic.getMarkingFunctions());
Assert.notNull(logic.getResponseObjectFactory());
this.format = SerializationFormat.valueOf(context.getConfiguration().get(RESULT_SERIALIZATION_FORMAT));
}
use of datawave.webservice.query.logic.QueryLogic in project datawave by NationalSecurityAgency.
the class BulkResultsTableOutputMapper method setup.
@Override
protected void setup(org.apache.hadoop.mapreduce.Mapper<Key, Value, Text, Mutation>.Context context) throws IOException, InterruptedException {
super.setup(context);
Query query;
try {
String base64EncodedQuery = context.getConfiguration().get(BulkResultsFileOutputMapper.QUERY_LOGIC_SETTINGS);
Class<? extends Query> queryImplClass = Class.forName(context.getConfiguration().get(BulkResultsFileOutputMapper.QUERY_IMPL_CLASS)).asSubclass(Query.class);
query = BulkResultsFileOutputMapper.deserializeQuery(base64EncodedQuery, queryImplClass);
} catch (JAXBException e) {
throw new RuntimeException("Error deserializing Query", e);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Error instantiating query impl class " + context.getConfiguration().get(BulkResultsFileOutputMapper.QUERY_IMPL_CLASS), e);
}
QueryLogic<?> logic = (QueryLogic<?>) super.applicationContext.getBean(QUERY_LOGIC_NAME);
t = logic.getTransformer(query);
this.tableName = new Text(context.getConfiguration().get(TABLE_NAME));
this.format = SerializationFormat.valueOf(context.getConfiguration().get(BulkResultsFileOutputMapper.RESULT_SERIALIZATION_FORMAT));
}
use of datawave.webservice.query.logic.QueryLogic 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.query.logic.QueryLogic in project datawave by NationalSecurityAgency.
the class QueryExecutorBean method listQueryLogic.
/**
* List QueryLogic types that are currently available
*
* @HTTP 200 Success
* @return datawave.webservice.result.QueryLogicResponse
* @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
*/
@Path("/listQueryLogic")
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "text/html" })
@GET
@Interceptors({ ResponseInterceptor.class })
@Override
@Timed(name = "dw.query.listQueryLogic", absolute = true)
public QueryLogicResponse listQueryLogic() {
QueryLogicResponse response = new QueryLogicResponse();
List<QueryLogic<?>> logicList = queryLogicFactory.getQueryLogicList();
List<QueryLogicDescription> logicConfigurationList = new ArrayList<>();
// reference query necessary to avoid NPEs in getting the Transformer and BaseResponse
Query q = new QueryImpl();
Date now = new Date();
q.setExpirationDate(now);
q.setQuery("test");
q.setQueryAuthorizations("ALL");
for (QueryLogic<?> l : logicList) {
try {
QueryLogicDescription d = new QueryLogicDescription(l.getLogicName());
d.setAuditType(l.getAuditType(null).toString());
d.setLogicDescription(l.getLogicDescription());
Set<String> optionalQueryParameters = l.getOptionalQueryParameters();
if (optionalQueryParameters != null) {
d.setSupportedParams(new ArrayList<>(optionalQueryParameters));
}
Set<String> requiredQueryParameters = l.getRequiredQueryParameters();
if (requiredQueryParameters != null) {
d.setRequiredParams(new ArrayList<>(requiredQueryParameters));
}
Set<String> exampleQueries = l.getExampleQueries();
if (exampleQueries != null) {
d.setExampleQueries(new ArrayList<>(exampleQueries));
}
Set<String> requiredRoles = l.getRoleManager().getRequiredRoles();
if (requiredRoles != null) {
List<String> requiredRolesList = new ArrayList<>();
requiredRolesList.addAll(l.getRoleManager().getRequiredRoles());
d.setRequiredRoles(requiredRolesList);
}
try {
d.setResponseClass(l.getResponseClass(q));
} catch (QueryException e) {
log.error(e, e);
response.addException(e);
d.setResponseClass("unknown");
}
List<String> querySyntax = new ArrayList<>();
try {
Method m = l.getClass().getMethod("getQuerySyntaxParsers");
Object result = m.invoke(l);
if (result instanceof Map<?, ?>) {
Map<?, ?> map = (Map<?, ?>) result;
for (Object o : map.keySet()) querySyntax.add(o.toString());
}
} catch (Exception e) {
log.warn("Unable to get query syntax for query logic: " + l.getClass().getCanonicalName());
}
if (querySyntax.isEmpty()) {
querySyntax.add("CUSTOM");
}
d.setQuerySyntax(querySyntax);
logicConfigurationList.add(d);
} catch (Exception e) {
log.error("Error setting query logic description", e);
}
}
Collections.sort(logicConfigurationList, Comparator.comparing(QueryLogicDescription::getName));
response.setQueryLogicList(logicConfigurationList);
return response;
}
use of datawave.webservice.query.logic.QueryLogic in project datawave by NationalSecurityAgency.
the class BasicQueryBean method getQueryLogic.
private BaseQueryLogic getQueryLogic(String logicName) {
BaseQueryLogic theLogic = null;
List<QueryLogic<?>> logicList = queryLogicFactory.getQueryLogicList();
for (QueryLogic<?> l : logicList) {
try {
if (l.getLogicName().equals(logicName)) {
return (BaseQueryLogic) l;
}
} catch (Exception e) {
log.error("Error getting query logic name", e);
}
}
return theLogic;
}
Aggregations