Search in sources :

Example 1 with QueryLogic

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));
}
Also used : Query(datawave.webservice.query.Query) Configuration(org.apache.hadoop.conf.Configuration) JAXBException(javax.xml.bind.JAXBException) QueryLogic(datawave.webservice.query.logic.QueryLogic) Weld(org.jboss.weld.environment.se.Weld)

Example 2 with QueryLogic

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));
}
Also used : Query(datawave.webservice.query.Query) JAXBException(javax.xml.bind.JAXBException) Text(org.apache.hadoop.io.Text) QueryLogic(datawave.webservice.query.logic.QueryLogic)

Example 3 with QueryLogic

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);
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) 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) VoidResponse(datawave.webservice.result.VoidResponse) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) QueryLogic(datawave.webservice.query.logic.QueryLogic) 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)

Example 4 with QueryLogic

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;
}
Also used : Query(datawave.webservice.query.Query) ArrayList(java.util.ArrayList) QueryLogic(datawave.webservice.query.logic.QueryLogic) Method(java.lang.reflect.Method) QueryLogicResponse(datawave.webservice.result.QueryLogicResponse) Date(java.util.Date) 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) QueryImpl(datawave.webservice.query.QueryImpl) 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) QueryLogicDescription(datawave.webservice.query.result.logic.QueryLogicDescription) Map(java.util.Map) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Path(javax.ws.rs.Path) Interceptors(javax.interceptor.Interceptors) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 5 with QueryLogic

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;
}
Also used : QueryLogic(datawave.webservice.query.logic.QueryLogic) BaseQueryLogic(datawave.webservice.query.logic.BaseQueryLogic) BaseQueryLogic(datawave.webservice.query.logic.BaseQueryLogic) QueryException(datawave.webservice.query.exception.QueryException)

Aggregations

QueryLogic (datawave.webservice.query.logic.QueryLogic)22 BaseQueryLogic (datawave.webservice.query.logic.BaseQueryLogic)15 Query (datawave.webservice.query.Query)11 QueryException (datawave.webservice.query.exception.QueryException)11 Test (org.junit.Test)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 QueryMetricFactoryImpl (datawave.microservice.querymetric.QueryMetricFactoryImpl)9 QueryImpl (datawave.webservice.query.QueryImpl)9 Date (java.util.Date)9 HashSet (java.util.HashSet)9 BadRequestException (datawave.webservice.common.exception.BadRequestException)8 DatawaveWebApplicationException (datawave.webservice.common.exception.DatawaveWebApplicationException)8 QueryParametersImpl (datawave.webservice.query.QueryParametersImpl)8 QueryPersistence (datawave.webservice.query.QueryPersistence)8 NoResultsQueryException (datawave.webservice.query.exception.NoResultsQueryException)8 IOException (java.io.IOException)8 UUID (java.util.UUID)8 NoResultsException (datawave.webservice.common.exception.NoResultsException)7 ArrayList (java.util.ArrayList)7 Set (java.util.Set)7