Search in sources :

Example 1 with Parameter

use of datawave.webservice.query.QueryImpl.Parameter in project datawave by NationalSecurityAgency.

the class ShardQueryLogic method configureDocumentAggregation.

void configureDocumentAggregation(Query settings) {
    Parameter disabledIndexOnlyDocument = settings.findParameter(QueryOptions.DISABLE_DOCUMENTS_WITHOUT_EVENTS);
    if (null != disabledIndexOnlyDocument) {
        final String disabledIndexOnlyDocumentStr = disabledIndexOnlyDocument.getParameterValue().trim();
        if (org.apache.commons.lang.StringUtils.isNotBlank(disabledIndexOnlyDocumentStr)) {
            Boolean disabledIndexOnlyDocuments = Boolean.parseBoolean(disabledIndexOnlyDocumentStr);
            setDisableIndexOnlyDocuments(disabledIndexOnlyDocuments);
        }
    }
}
Also used : Parameter(datawave.webservice.query.QueryImpl.Parameter)

Example 2 with Parameter

use of datawave.webservice.query.QueryImpl.Parameter in project datawave by NationalSecurityAgency.

the class DocumentTransformerSupport method setEventQueryDataDecoratorTransformer.

@Override
public void setEventQueryDataDecoratorTransformer(EventQueryDataDecoratorTransformer eventQueryDataDecoratorTransformer) {
    this.eventQueryDataDecoratorTransformer = eventQueryDataDecoratorTransformer;
    Set<Parameter> parameters = this.settings.getParameters();
    if (eventQueryDataDecoratorTransformer != null && parameters != null) {
        List<String> requestedDecorators = new ArrayList<>();
        for (Parameter p : parameters) {
            if (p.getParameterName().equals("data.decorators")) {
                String decoratorString = p.getParameterValue();
                if (decoratorString != null) {
                    requestedDecorators.addAll(Arrays.asList(decoratorString.split(",")));
                    this.eventQueryDataDecoratorTransformer.setRequestedDecorators(requestedDecorators);
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Parameter(datawave.webservice.query.QueryImpl.Parameter)

Example 3 with Parameter

use of datawave.webservice.query.QueryImpl.Parameter in project datawave by NationalSecurityAgency.

the class QueryExecutorBean method next.

private BaseQueryResponse next(final String id, boolean checkForContentLookup) {
    // in case we don't make it to creating the response from the QueryLogic
    BaseQueryResponse response = responseObjectFactory.getEventQueryResponse();
    Collection<String> proxyServers = null;
    Principal p = ctx.getCallerPrincipal();
    String userid = p.getName();
    if (p instanceof DatawavePrincipal) {
        DatawavePrincipal dp = (DatawavePrincipal) p;
        userid = dp.getShortName();
        proxyServers = dp.getProxyServers();
    }
    Span span = null;
    RunningQuery query = null;
    Query contentLookupSettings = null;
    try {
        ctx.getUserTransaction().begin();
        // Not calling getQueryById() here. We don't want to pull the persisted definition.
        query = queryCache.get(id);
        // The lock should be released at the end of the method call.
        if (!queryCache.lock(id)) {
            throw new QueryException(DatawaveErrorCode.QUERY_LOCKED_ERROR);
        }
        // an error.
        if (null == query || null == query.getConnection()) {
            // status code.
            if (null == query) {
                List<Query> queries = persister.findById(id);
                if (queries == null || queries.size() != 1) {
                    throw new NotFoundQueryException(DatawaveErrorCode.NO_QUERY_OBJECT_MATCH, MessageFormat.format("{0}", id));
                }
            }
            throw new PreConditionFailedQueryException(DatawaveErrorCode.QUERY_TIMEOUT_OR_SERVER_ERROR, MessageFormat.format("id = {0}", id));
        } else {
            // Validate the query belongs to the caller
            if (!query.getSettings().getOwner().equals(userid)) {
                throw new UnauthorizedQueryException(DatawaveErrorCode.QUERY_OWNER_MISMATCH, MessageFormat.format("{0} != {1}", userid, query.getSettings().getOwner()));
            }
            // Set the active call and get next
            query.setActiveCall(true);
            response = _next(query, id, proxyServers, span);
            // Conditionally swap the standard response with content
            if (checkForContentLookup) {
                final Query settings = query.getSettings();
                final Parameter contentLookupParam = settings.findParameter(LookupUUIDUtil.PARAM_CONTENT_LOOKUP);
                if ((null != contentLookupParam) && Boolean.parseBoolean(contentLookupParam.getParameterValue())) {
                    contentLookupSettings = settings;
                }
            }
            // Unset the active call and return
            query.setActiveCall(false);
        }
    } catch (NoResultsException e) {
        if (query != null) {
            query.setActiveCall(false);
            if (query.getLogic().getCollectQueryMetrics()) {
                try {
                    // do not set the error message here - zero results is not an error that should be added to metrics
                    metrics.updateMetric(query.getMetric());
                } catch (Exception e1) {
                    log.error(e1.getMessage());
                }
            }
        }
        try {
            ctx.getUserTransaction().setRollbackOnly();
        } catch (Exception ex) {
            log.error("Error marking transaction for roll back", ex);
        }
        // close the query, as there were no results and we are done here
        close(id);
        // remember that we auto-closed this query
        closedQueryCache.add(id);
        throw e;
    } catch (DatawaveWebApplicationException e) {
        if (query != null) {
            query.setActiveCall(false);
            if (query.getLogic().getCollectQueryMetrics()) {
                query.getMetric().setError(e);
                try {
                    metrics.updateMetric(query.getMetric());
                } catch (Exception e1) {
                    log.error("Error updating query metrics", e1);
                }
            }
        }
        try {
            ctx.getUserTransaction().setRollbackOnly();
        } catch (Exception ex) {
            log.error("Error marking transaction for roll back", ex);
        }
        if (e.getCause() instanceof NoResultsException) {
            close(id);
            // remember that we auto-closed this query
            closedQueryCache.add(id);
        }
        throw e;
    } catch (Exception e) {
        log.error("Query Failed", e);
        if (query != null) {
            query.setActiveCall(false);
            if (query.getLogic().getCollectQueryMetrics() == true) {
                query.getMetric().setError(e);
                try {
                    metrics.updateMetric(query.getMetric());
                } catch (Exception e1) {
                    log.error("Error updating query metrics", e1);
                }
            }
        }
        try {
            ctx.getUserTransaction().setRollbackOnly();
        } catch (Exception ex) {
            log.error("Error marking transaction for roll back", ex);
        }
        QueryException qe = new QueryException(DatawaveErrorCode.QUERY_NEXT_ERROR, e, MessageFormat.format("query id: {0}", id));
        if (e.getCause() instanceof NoResultsException) {
            log.debug("Got a nested NoResultsException", e);
            close(id);
            // remember that we auto-closed this query
            closedQueryCache.add(id);
        } else {
            try {
                close(id);
            } catch (Exception ce) {
                log.error(qe, ce);
            }
            log.error(qe, e);
            response.addException(qe.getBottomQueryException());
        }
        int statusCode = qe.getBottomQueryException().getStatusCode();
        throw new DatawaveWebApplicationException(qe, response, statusCode);
    } finally {
        queryCache.unlock(id);
        try {
            if (ctx.getUserTransaction().getStatus() == Status.STATUS_MARKED_ROLLBACK) {
                ctx.getUserTransaction().rollback();
            } else if (ctx.getUserTransaction().getStatus() != Status.STATUS_NO_TRANSACTION) {
                // no reason to commit if transaction not started, ie Query not found exception
                ctx.getUserTransaction().commit();
            }
        } catch (IllegalStateException e) {
            log.error("Error committing transaction: thread not associated with transaction", e);
        } catch (RollbackException e) {
            log.error("Error committing transaction: marked for rollback due to error", e);
        } catch (HeuristicMixedException e) {
            log.error("Error committing transaction: partial commit of resources", e);
        } catch (HeuristicRollbackException e) {
            log.error("Error committing transaction: resources rolled back transaction", e);
        } catch (Exception e) {
            log.error("Error committing transaction: Unknown error", e);
        } finally {
            // Stop timing on this trace, if any
            if (span != null) {
                span.stop();
            }
        }
    }
    // If applicable, perform a paged content lookup (i.e., not streamed), replacing its results in the returned response
    if (null != contentLookupSettings) {
        final NextContentCriteria criteria = new NextContentCriteria(id, contentLookupSettings);
        response = this.lookupUUIDUtil.lookupContentByNextResponse(criteria, response);
    }
    return response;
}
Also used : NoResultsException(datawave.webservice.common.exception.NoResultsException) Query(datawave.webservice.query.Query) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) RollbackException(javax.transaction.RollbackException) Span(org.apache.accumulo.core.trace.Span) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) 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) UnauthorizedQueryException(datawave.webservice.query.exception.UnauthorizedQueryException) 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) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) NextContentCriteria(datawave.webservice.query.util.NextContentCriteria) BaseQueryResponse(datawave.webservice.result.BaseQueryResponse) HeuristicMixedException(javax.transaction.HeuristicMixedException) Parameter(datawave.webservice.query.QueryImpl.Parameter) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) Principal(java.security.Principal) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal)

Example 4 with Parameter

use of datawave.webservice.query.QueryImpl.Parameter in project datawave by NationalSecurityAgency.

the class QueryExecutorBean method updateQueryParams.

private void updateQueryParams(Query q, String queryLogicName, String query, Date beginDate, Date endDate, String queryAuthorizations, Date expirationDate, Integer pagesize, Integer pageTimeout, Long maxResultsOverride, String parameters) throws CloneNotSupportedException {
    Principal p = ctx.getCallerPrincipal();
    // TODO: add validation for all these sets
    if (queryLogicName != null) {
        QueryLogic<?> logic = queryLogicFactory.getQueryLogic(queryLogicName, p);
        q.setQueryLogicName(logic.getLogicName());
    }
    if (query != null) {
        q.setQuery(query);
    }
    if (beginDate != null) {
        q.setBeginDate(beginDate);
    }
    if (endDate != null) {
        q.setEndDate(endDate);
    }
    if (queryAuthorizations != null) {
        q.setQueryAuthorizations(queryAuthorizations);
    }
    if (expirationDate != null) {
        q.setExpirationDate(expirationDate);
    }
    if (pagesize != null) {
        q.setPagesize(pagesize);
    }
    if (pageTimeout != null) {
        q.setPageTimeout(pageTimeout);
    }
    if (maxResultsOverride != null) {
        q.setMaxResultsOverride(maxResultsOverride);
    }
    if (parameters != null) {
        Set<Parameter> params = new HashSet<>();
        String[] param = parameters.split(QueryImpl.PARAMETER_SEPARATOR);
        for (String yyy : param) {
            String[] parts = yyy.split(QueryImpl.PARAMETER_NAME_VALUE_SEPARATOR);
            if (parts.length == 2) {
                params.add(new Parameter(parts[0], parts[1]));
            }
        }
        q.setParameters(params);
    }
}
Also used : Parameter(datawave.webservice.query.QueryImpl.Parameter) Principal(java.security.Principal) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) HashSet(java.util.HashSet)

Example 5 with Parameter

use of datawave.webservice.query.QueryImpl.Parameter in project datawave-query-metric-service by NationalSecurityAgency.

the class QueryMetricsDetailListResponse method getMainContent.

@Override
public String getMainContent() {
    StringBuilder builder = new StringBuilder(), pageTimesBuilder = new StringBuilder();
    builder.append("<table>\n");
    builder.append("<tr>");
    builder.append("<th>Visibility</th><th>Query Date</th><th>User</th><th>UserDN</th><th>Proxy Server(s)</th><th>Query ID</th><th>Query Type</th>");
    builder.append("<th>Query Logic</th><th id=\"query-header\">Query</th><th>Query Plan</th><th>Query Name</th><th>Begin Date</th><th>End Date</th><th>Parameters</th><th>Query Auths</th>");
    builder.append("<th>Server</th>");
    builder.append("<th>Predictions</th>");
    builder.append("<th>Login Time (ms)</th>");
    builder.append("<th>Query Setup Time (ms)</th><th>Query Setup Call Time (ms)</th><th>Number Pages</th><th>Number Results</th>");
    builder.append("<th>Doc Ranges</th><th>FI Ranges</th>");
    builder.append("<th>Sources</th><th>Next Calls</th><th>Seek Calls</th><th>Yield Count</th><th>Version</th>");
    builder.append("<th>Total Page Time (ms)</th><th>Total Page Call Time (ms)</th><th>Total Page Serialization Time (ms)</th>");
    builder.append("<th>Total Page Bytes Sent (uncompressed)</th><th>Lifecycle</th><th>Elapsed Time</th><th>Error Code</th><th>Error Message</th>");
    builder.append("</tr>\n");
    pageTimesBuilder.append("<table>\n");
    pageTimesBuilder.append("<tr><th>Page number</th><th>Page requested</th><th>Page returned</th><th>Response time (ms)</th>");
    pageTimesBuilder.append("<th>Page size</th><th>Call time (ms)</th><th>Login time (ms)</th><th>Serialization time (ms)</th>");
    pageTimesBuilder.append("<th>Bytes written (uncompressed)</th></tr>");
    TreeMap<Date, QueryMetric> metricMap = new TreeMap<Date, QueryMetric>(Collections.reverseOrder());
    for (QueryMetric metric : this.getResult()) {
        metricMap.put(metric.getCreateDate(), metric);
    }
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HHmmss");
    int x = 0;
    for (QueryMetric metric : metricMap.values()) {
        // highlight alternating rows
        if (x % 2 == 0) {
            builder.append("<tr class=\"highlight\">\n");
        } else {
            builder.append("<tr>\n");
        }
        x++;
        builder.append("<td>").append(metric.getColumnVisibility()).append("</td>");
        builder.append("<td style=\"min-width:125px !important;\">").append(sdf.format(metric.getCreateDate())).append("</td>");
        builder.append("<td>").append(metric.getUser()).append("</td>");
        String userDN = metric.getUserDN();
        builder.append("<td style=\"min-width:500px !important;\">").append(userDN == null ? "" : userDN).append("</td>");
        String proxyServers = metric.getProxyServers() == null ? "" : StringUtils.join(metric.getProxyServers(), "<BR/>");
        builder.append("<td>").append(proxyServers).append("</td>");
        builder.append("<td>").append(metric.getQueryId()).append("</td>");
        builder.append("<td>").append(metric.getQueryType()).append("</td>");
        builder.append("<td>").append(metric.getQueryLogic()).append("</td>");
        builder.append("<td style=\"word-wrap: break-word;\">").append(StringEscapeUtils.escapeHtml4(metric.getQuery())).append("</td>");
        builder.append("<td style=\"word-wrap: break-word;\">").append(StringEscapeUtils.escapeHtml4(metric.getPlan())).append("</td>");
        builder.append("<td>").append(metric.getQueryName()).append("</td>");
        String beginDate = metric.getBeginDate() == null ? "" : sdf.format(metric.getBeginDate());
        builder.append("<td style=\"min-width:125px !important;\">").append(beginDate).append("</td>");
        String endDate = metric.getEndDate() == null ? "" : sdf.format(metric.getEndDate());
        builder.append("<td style=\"min-width:125px !important;\">").append(endDate).append("</td>");
        Set<Parameter> parameters = metric.getParameters();
        builder.append("<td>").append(parameters == null ? "" : toParametersString(parameters)).append("</td>");
        String queryAuths = metric.getQueryAuthorizations() == null ? "" : metric.getQueryAuthorizations().replaceAll(",", " ");
        builder.append("<td style=\"word-wrap: break-word; min-width:300px !important;\">").append(queryAuths).append("</td>");
        builder.append("<td>").append(metric.getHost()).append("</td>");
        if (metric.getPredictions() != null && !metric.getPredictions().isEmpty()) {
            builder.append("<td>");
            String delimiter = "";
            List<Prediction> predictions = new ArrayList<Prediction>(metric.getPredictions());
            Collections.sort(predictions);
            for (Prediction prediction : predictions) {
                builder.append(delimiter).append(prediction.getName()).append(" = ").append(prediction.getPrediction());
                delimiter = "<br>";
            }
        } else {
            builder.append("<td/>");
        }
        builder.append("<td>").append(numToString(metric.getLoginTime(), 0)).append("</td>");
        builder.append("<td>").append(metric.getSetupTime()).append("</td>");
        builder.append("<td>").append(numToString(metric.getCreateCallTime(), 0)).append("</td>\n");
        builder.append("<td>").append(metric.getNumPages()).append("</td>");
        builder.append("<td>").append(metric.getNumResults()).append("</td>");
        builder.append("<td>").append(metric.getDocRanges()).append("</td>");
        builder.append("<td>").append(metric.getFiRanges()).append("</td>");
        builder.append("<td>").append(metric.getSourceCount()).append("</td>");
        builder.append("<td>").append(metric.getNextCount()).append("</td>");
        builder.append("<td>").append(metric.getSeekCount()).append("</td>");
        builder.append("<td>").append(metric.getYieldCount()).append("</td>");
        builder.append("<td>").append(metric.getVersion()).append("</td>");
        long count = 0l;
        long callTime = 0l;
        long serializationTime = 0l;
        long bytesSent = 0l;
        int y = 0;
        for (PageMetric p : metric.getPageTimes()) {
            count += p.getReturnTime();
            callTime += (p.getCallTime()) == -1 ? 0 : p.getCallTime();
            serializationTime += (p.getSerializationTime()) == -1 ? 0 : p.getSerializationTime();
            bytesSent += (p.getBytesWritten()) == -1 ? 0 : p.getBytesWritten();
            if (y % 2 == 0) {
                pageTimesBuilder.append("<tr class=\"highlight\">");
            } else {
                pageTimesBuilder.append("<tr>");
            }
            y++;
            String pageRequestedStr = "";
            long pageRequested = p.getPageRequested();
            if (pageRequested > 0) {
                pageRequestedStr = sdf.format(new Date(pageRequested));
            }
            String pageReturnedStr = "";
            long pageReturned = p.getPageReturned();
            if (pageReturned > 0) {
                pageReturnedStr = sdf.format(new Date(pageReturned));
            }
            pageTimesBuilder.append("<td>").append(numToString(p.getPageNumber(), 1)).append("</td>");
            pageTimesBuilder.append("<td>").append(pageRequestedStr).append("</td>");
            pageTimesBuilder.append("<td>").append(pageReturnedStr).append("</td>");
            pageTimesBuilder.append("<td>").append(p.getReturnTime()).append("</td>");
            pageTimesBuilder.append("<td>").append(p.getPagesize()).append("</td>");
            pageTimesBuilder.append("<td>").append(numToString(p.getCallTime(), 0)).append("</td>");
            pageTimesBuilder.append("<td>").append(numToString(p.getLoginTime(), 0)).append("</td>");
            pageTimesBuilder.append("<td>").append(numToString(p.getSerializationTime(), 0)).append("</td>");
            pageTimesBuilder.append("<td>").append(numToString(p.getBytesWritten(), 0)).append("</td></tr>");
        }
        builder.append("<td>").append(count).append("</td>\n");
        builder.append("<td>").append(numToString(callTime, 0)).append("</td>\n");
        builder.append("<td>").append(numToString(serializationTime, 0)).append("</td>\n");
        builder.append("<td>").append(numToString(bytesSent, 0)).append("</td>\n");
        builder.append("<td>").append(metric.getLifecycle()).append("</td>");
        builder.append("<td>").append(metric.getElapsedTime()).append("</td>");
        String errorCode = metric.getErrorCode();
        builder.append("<td style=\"word-wrap: break-word;\">").append((errorCode == null) ? "" : StringEscapeUtils.escapeHtml4(errorCode)).append("</td>");
        String errorMessage = metric.getErrorMessage();
        builder.append("<td style=\"word-wrap: break-word;\">").append((errorMessage == null) ? "" : StringEscapeUtils.escapeHtml4(errorMessage)).append("</td>");
        builder.append("\n</tr>\n");
    }
    builder.append("</table>\n<br/>\n");
    pageTimesBuilder.append("</table>\n");
    builder.append(pageTimesBuilder);
    return builder.toString();
}
Also used : PageMetric(datawave.microservice.querymetric.BaseQueryMetric.PageMetric) Prediction(datawave.microservice.querymetric.BaseQueryMetric.Prediction) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Date(java.util.Date) Parameter(datawave.webservice.query.QueryImpl.Parameter) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

Parameter (datawave.webservice.query.QueryImpl.Parameter)17 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)4 DatawavePrincipal (datawave.security.authorization.DatawavePrincipal)3 BadRequestException (datawave.webservice.common.exception.BadRequestException)3 DatawaveWebApplicationException (datawave.webservice.common.exception.DatawaveWebApplicationException)3 NoResultsException (datawave.webservice.common.exception.NoResultsException)3 UnauthorizedException (datawave.webservice.common.exception.UnauthorizedException)3 Query (datawave.webservice.query.Query)3 BadRequestQueryException (datawave.webservice.query.exception.BadRequestQueryException)3 NoResultsQueryException (datawave.webservice.query.exception.NoResultsQueryException)3 NotFoundQueryException (datawave.webservice.query.exception.NotFoundQueryException)3 PreConditionFailedQueryException (datawave.webservice.query.exception.PreConditionFailedQueryException)3 QueryException (datawave.webservice.query.exception.QueryException)3 UnauthorizedQueryException (datawave.webservice.query.exception.UnauthorizedQueryException)3 IOException (java.io.IOException)3 CancellationException (java.util.concurrent.CancellationException)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 HeuristicMixedException (javax.transaction.HeuristicMixedException)3 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)3