Search in sources :

Example 1 with QueryImplListResponse

use of datawave.webservice.result.QueryImplListResponse in project datawave by NationalSecurityAgency.

the class HudBean method getRunningQueries.

/**
 * Return true if there is at least one log in the last 60 minutes.
 *
 * @return
 * @throws org.apache.accumulo.core.client.TableNotFoundException
 */
@Path("/runningqueries/{userid}")
@GET
public String getRunningQueries(@PathParam("userid") String userId) throws Exception {
    DatawavePrincipal principal = getPrincipal();
    boolean isAnAdmin = isAnAdmin(principal);
    QueryImplListResponse runningQueries = null;
    if (isAnAdmin) {
        runningQueries = queryExecutor.listQueriesForUser(userId);
    } else {
        runningQueries = queryExecutor.listUserQueries();
    }
    List<Query> queryList = runningQueries.getQuery();
    List<HudQuerySummary> querySummaryList = new ArrayList<>();
    for (Query query : queryList) {
        HudQuerySummary summary = summaryBuilder.build(query);
        String queryId = query.getId().toString();
        List<? extends BaseQueryMetric> queryMetricsList;
        queryMetricsList = queryMetrics.query(queryId).getResult();
        if (queryMetricsList != null && !queryMetricsList.isEmpty()) {
            BaseQueryMetric qm = queryMetricsList.get(0);
            List<PageMetric> pageMetrics = qm.getPageTimes();
            summary.setPageMetrics(pageMetrics);
            summary.setCreateDate(qm.getCreateDate().getTime());
            summary.setNumPages(qm.getNumPages());
            summary.setNumResults(qm.getNumResults());
            summary.setLastUpdated(qm.getLastUpdated().getTime());
            summary.setLifeCycle(qm.getLifecycle().toString());
        }
        querySummaryList.add(summary);
    }
    return gson.toJson(querySummaryList);
}
Also used : QueryImplListResponse(datawave.webservice.result.QueryImplListResponse) Query(datawave.webservice.query.Query) PageMetric(datawave.microservice.querymetric.BaseQueryMetric.PageMetric) ArrayList(java.util.ArrayList) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) BaseQueryMetric(datawave.microservice.querymetric.BaseQueryMetric) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with QueryImplListResponse

use of datawave.webservice.result.QueryImplListResponse in project datawave by NationalSecurityAgency.

the class ExtendedQueryExecutorBeanTest method testList_HappyPath.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testList_HappyPath() throws Exception {
    // Set local test input
    String queryName = "queryName";
    String queryLogicName = "queryLogicName";
    String userName = "userName";
    String sid = "sid";
    UUID queryId = UUID.randomUUID();
    List<String> dnList = Collections.singletonList("userDn");
    HashMap<String, Collection<String>> authsMap = new HashMap<>();
    authsMap.put("USERDN", Arrays.asList("AUTH_1"));
    // Set expectations
    expect(this.context.getCallerPrincipal()).andReturn(this.principal);
    expect(this.principal.getName()).andReturn(userName);
    expect(this.principal.getShortName()).andReturn(sid);
    expect(this.principal.getPrimaryUser()).andReturn(dwUser);
    expect(this.dwUser.getAuths()).andReturn(Collections.singletonList("AUTH_1"));
    expect(this.principal.getProxiedUsers()).andReturn(Collections.singletonList(dwUser));
    expect(this.principal.getAuthorizations()).andReturn((Collection) Arrays.asList(Arrays.asList("AUTH_1")));
    expect(this.persister.findByName(queryName)).andReturn(Arrays.asList((Query) this.query));
    expect(this.query.getOwner()).andReturn(sid).anyTimes();
    expect(this.query.getUserDN()).andReturn(sid).anyTimes();
    expect(this.query.getQueryLogicName()).andReturn(queryLogicName).anyTimes();
    expect(this.queryLogicFactory.getQueryLogic(queryLogicName, principal)).andReturn((QueryLogic) this.queryLogic1);
    expect(this.queryLogic1.getConnectionPriority()).andReturn(Priority.HIGH);
    expect(this.query.getQueryAuthorizations()).andReturn(null).anyTimes();
    expect(this.queryLogic1.getCollectQueryMetrics()).andReturn(false);
    expect(this.query.getId()).andReturn(queryId).anyTimes();
    expect(this.query.getQuery()).andReturn(queryName).anyTimes();
    expect(this.query.getBeginDate()).andReturn(null).anyTimes();
    expect(this.query.getEndDate()).andReturn(null).anyTimes();
    expect(this.query.getColumnVisibility()).andReturn(null).anyTimes();
    expect(this.cache.containsKey(queryId.toString())).andReturn(false);
    expect(this.query.getQueryName()).andReturn(null).anyTimes();
    expect(this.query.getPagesize()).andReturn(0).anyTimes();
    expect(this.query.getPageTimeout()).andReturn(-1).anyTimes();
    expect(this.query.getExpirationDate()).andReturn(null).anyTimes();
    expect(this.query.getParameters()).andReturn((Set) Collections.emptySet()).anyTimes();
    expect(this.query.getDnList()).andReturn(dnList).anyTimes();
    expect(this.queryLogic1.getResultLimit(dnList)).andReturn(-1L);
    expect(this.queryLogic1.getMaxResults()).andReturn(-1L);
    this.cache.put(eq(queryId.toString()), isA(RunningQuery.class));
    // Run the test
    PowerMock.replayAll();
    QueryExecutorBean subject = new QueryExecutorBean();
    setInternalState(subject, EJBContext.class, context);
    setInternalState(subject, QueryCache.class, cache);
    setInternalState(subject, ClosedQueryCache.class, closedCache);
    setInternalState(subject, Persister.class, persister);
    setInternalState(subject, QueryLogicFactory.class, queryLogicFactory);
    setInternalState(subject, QueryExpirationConfiguration.class, queryExpirationConf);
    setInternalState(subject, QueryParameters.class, new QueryParametersImpl());
    setInternalState(subject, QueryMetricFactory.class, new QueryMetricFactoryImpl());
    QueryImplListResponse result1 = subject.list(queryName);
    PowerMock.verifyAll();
    // Verify results
    assertNotNull("QueryLogicResponse should not be returned null", result1);
}
Also used : QueryImplListResponse(datawave.webservice.result.QueryImplListResponse) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Query(datawave.webservice.query.Query) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) QueryParametersImpl(datawave.webservice.query.QueryParametersImpl) Collection(java.util.Collection) UUID(java.util.UUID) QueryMetricFactoryImpl(datawave.microservice.querymetric.QueryMetricFactoryImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with QueryImplListResponse

use of datawave.webservice.result.QueryImplListResponse in project datawave by NationalSecurityAgency.

the class QueryExecutorBean method list.

/**
 * Lists queries for the current user with the given name.
 *
 * @param name
 *            the name of the query to locate (@Required)
 * @see datawave.webservice.query.runner.QueryExecutorBean#list(String) list(String) for the @Required definition
 *
 * @return datawave.webservice.result.QueryImplListResponse
 * @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 if the query with {@code name} does not belong to caller, you will never see it
 * @HTTP 404 queries not found using {@code name}
 * @HTTP 400 if {@code name} parameter is not included
 * @HTTP 500 internal server error
 */
@GET
@Path("/list")
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff" })
@GZIP
@Interceptors({ RequiredInterceptor.class, ResponseInterceptor.class })
@Override
@Timed(name = "dw.query.listQueryByName", absolute = true)
public QueryImplListResponse list(@Required("name") @QueryParam("name") String name) {
    QueryImplListResponse response = new QueryImplListResponse();
    List<Query> results = new ArrayList<>();
    try {
        List<RunningQuery> query = getQueryByName(name);
        if (null != query) {
            for (RunningQuery rq : query) results.add(rq.getSettings());
        }
        response.setQuery(results);
        return response;
    } catch (DatawaveWebApplicationException e) {
        throw e;
    } catch (Exception e) {
        QueryException qe = new QueryException(DatawaveErrorCode.LIST_ERROR, e);
        response.addException(qe.getBottomQueryException());
        int statusCode = qe.getBottomQueryException().getStatusCode();
        throw new DatawaveWebApplicationException(qe, response, statusCode);
    }
}
Also used : QueryImplListResponse(datawave.webservice.result.QueryImplListResponse) 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) Query(datawave.webservice.query.Query) ArrayList(java.util.ArrayList) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) 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) 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) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 4 with QueryImplListResponse

use of datawave.webservice.result.QueryImplListResponse in project datawave by NationalSecurityAgency.

the class QueryExecutorBean method get.

/**
 * Lists query info for the given id.
 *
 * @param id
 *            - the id of the query to locate (@Required)
 * @see datawave.webservice.query.runner.QueryExecutorBean#get(String) get(String) for the @Required definition
 *
 * @return datawave.webservice.result.QueryImplListResponse
 * @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 queries not found using {@code id}
 * @HTTP 500 internal server error
 */
@GET
@Path("/{id}")
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff" })
@GZIP
@Interceptors({ RequiredInterceptor.class, ResponseInterceptor.class })
@Timed(name = "dw.query.listQueryByID", absolute = true)
public QueryImplListResponse get(@Required("id") @PathParam("id") String id) {
    QueryImplListResponse response = new QueryImplListResponse();
    List<Query> results = new ArrayList<>();
    try {
        RunningQuery query = getQueryById(id);
        if (null != query) {
            results.add(query.getSettings());
        }
        response.setQuery(results);
        return response;
    } catch (DatawaveWebApplicationException e) {
        throw e;
    } catch (Exception e) {
        QueryException qe = new QueryException(DatawaveErrorCode.QUERY_GET_ERROR, e, MessageFormat.format("queryID: {0}", id));
        log.error(qe, e);
        response.addException(qe.getBottomQueryException());
        int statusCode = qe.getBottomQueryException().getStatusCode();
        throw new DatawaveWebApplicationException(qe, response, statusCode);
    }
}
Also used : QueryImplListResponse(datawave.webservice.result.QueryImplListResponse) 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) Query(datawave.webservice.query.Query) ArrayList(java.util.ArrayList) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) 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) 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) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 5 with QueryImplListResponse

use of datawave.webservice.result.QueryImplListResponse in project datawave by NationalSecurityAgency.

the class ExtendedQueryExecutorBeanTest method testGet_HappyPath.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGet_HappyPath() throws Exception {
    // Set local test input
    String userName = "userName";
    String sid = "sid";
    UUID queryId = UUID.randomUUID();
    // Set expectations
    expect(this.context.getCallerPrincipal()).andReturn(this.principal);
    expect(this.principal.getName()).andReturn(userName);
    expect(this.principal.getShortName()).andReturn(sid);
    expect(this.principal.getAuthorizations()).andReturn((Collection) Arrays.asList(Arrays.asList("AUTH_1")));
    expect(this.cache.get(queryId.toString())).andReturn(this.runningQuery);
    expect(this.runningQuery.getSettings()).andReturn(this.query).times(2);
    expect(this.query.getOwner()).andReturn(sid);
    // Run the test
    PowerMock.replayAll();
    QueryExecutorBean subject = new QueryExecutorBean();
    setInternalState(subject, EJBContext.class, context);
    setInternalState(subject, QueryCache.class, cache);
    setInternalState(subject, ClosedQueryCache.class, closedCache);
    setInternalState(subject, QueryMetricFactory.class, new QueryMetricFactoryImpl());
    QueryImplListResponse result1 = subject.get(queryId.toString());
    PowerMock.verifyAll();
    // Verify results
    assertNotNull("Expected non-null response", result1);
}
Also used : QueryImplListResponse(datawave.webservice.result.QueryImplListResponse) UUID(java.util.UUID) QueryMetricFactoryImpl(datawave.microservice.querymetric.QueryMetricFactoryImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

QueryImplListResponse (datawave.webservice.result.QueryImplListResponse)7 QueryMetricFactoryImpl (datawave.microservice.querymetric.QueryMetricFactoryImpl)4 Query (datawave.webservice.query.Query)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 ArrayList (java.util.ArrayList)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Timed (com.codahale.metrics.annotation.Timed)2 BadRequestException (datawave.webservice.common.exception.BadRequestException)2 DatawaveWebApplicationException (datawave.webservice.common.exception.DatawaveWebApplicationException)2 NoResultsException (datawave.webservice.common.exception.NoResultsException)2 UnauthorizedException (datawave.webservice.common.exception.UnauthorizedException)2 BadRequestQueryException (datawave.webservice.query.exception.BadRequestQueryException)2 NoResultsQueryException (datawave.webservice.query.exception.NoResultsQueryException)2 NotFoundQueryException (datawave.webservice.query.exception.NotFoundQueryException)2 PreConditionFailedQueryException (datawave.webservice.query.exception.PreConditionFailedQueryException)2 QueryException (datawave.webservice.query.exception.QueryException)2 UnauthorizedQueryException (datawave.webservice.query.exception.UnauthorizedQueryException)2 IOException (java.io.IOException)2