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);
}
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);
}
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);
}
}
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);
}
}
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);
}
Aggregations