use of datawave.webservice.query.logic.BaseQueryLogic in project datawave by NationalSecurityAgency.
the class RunningQuery method setConnection.
public void setConnection(Connector connection) throws Exception {
// the internal logic
if (connection == null) {
this.connection = null;
return;
}
try {
addNDC();
applyPrediction(null);
this.connection = connection;
long start = System.currentTimeMillis();
GenericQueryConfiguration configuration = this.logic.initialize(this.connection, this.settings, this.calculatedAuths);
this.lastPageNumber = 0;
this.logic.setupQuery(configuration);
this.iter = this.logic.getTransformIterator(this.settings);
// the configuration query string should now hold the planned query
this.getMetric().setPlan(configuration.getQueryString());
this.getMetric().setSetupTime((System.currentTimeMillis() - start));
this.getMetric().setLifecycle(QueryMetric.Lifecycle.INITIALIZED);
testForUncaughtException(0);
// TODO: applyPrediction("Plan");
} catch (Exception e) {
log.error(e.getMessage(), e);
if (this.logic instanceof BaseQueryLogic && this.logic.getCollectQueryMetrics() && null != this.getMetric()) {
GenericQueryConfiguration config = ((BaseQueryLogic) this.logic).getConfig();
if (null != config) {
this.getMetric().setPlan(config.getQueryString());
}
}
this.getMetric().setError(e);
throw e;
} finally {
// update AbstractRunningQuery.lastUsed in case this operation took a long time
touch();
removeNDC();
if (this.queryMetrics != null) {
try {
this.queryMetrics.updateMetric(this.getMetric());
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
}
use of datawave.webservice.query.logic.BaseQueryLogic in project datawave by NationalSecurityAgency.
the class CompositeQueryLogicTest method testQueryLogicNoData.
@Test
public void testQueryLogicNoData() throws Exception {
List<BaseQueryLogic<?>> logics = new ArrayList<>();
TestQueryLogic logic1 = new TestQueryLogic();
TestQueryLogic2 logic2 = new TestQueryLogic2();
logics.add(logic1);
logics.add(logic2);
QueryImpl settings = new QueryImpl();
settings.setPagesize(100);
settings.setQueryAuthorizations(auths.serialize());
settings.setQuery("FOO == 'BAR'");
settings.setParameters(new HashSet<>());
settings.setId(UUID.randomUUID());
CompositeQueryLogic c = new CompositeQueryLogic();
/**
* RunningQuery.setupConnection()
*/
c.setQueryLogics(logics);
c.initialize((Connector) null, (Query) settings, Collections.singleton(auths));
c.setupQuery(null);
TransformIterator iter = c.getTransformIterator((Query) settings);
/**
* RunningQuery.next() - iterate over results coming from tablet server through the TransformIterator to turn them into the objects.
*/
List<Object> results = new ArrayList<>();
while (iter.hasNext()) {
Object o = iter.next();
if (null == o)
break;
Assert.assertTrue(o instanceof TestQueryResponse);
results.add((TestQueryResponse) o);
}
Assert.assertEquals(0, results.size());
c.close();
}
use of datawave.webservice.query.logic.BaseQueryLogic in project datawave by NationalSecurityAgency.
the class CompositeQueryLogicTest method testCanRunQueryLogic2.
@Test
public void testCanRunQueryLogic2() throws Exception {
List<BaseQueryLogic<?>> logics = new ArrayList<>();
TestQueryLogic logic1 = new TestQueryLogic();
HashSet<String> roles = new HashSet<>();
roles.add("TESTROLE");
logic1.setRoleManager(new DatawaveRoleManager(roles));
TestQueryLogic2 logic2 = new TestQueryLogic2();
HashSet<String> roles2 = new HashSet<>();
roles2.add("NONTESTROLE");
logic2.setRoleManager(new DatawaveRoleManager(roles2));
logics.add(logic1);
logics.add(logic2);
CompositeQueryLogic c = new CompositeQueryLogic();
c.setQueryLogics(logics);
DatawaveUser u = new DatawaveUser(SubjectIssuerDNPair.of("CN=Other User Name ouser, OU=acme", "CN=ca, OU=acme"), UserType.USER, null, Collections.singleton("TESTROLE"), null, 0L);
DatawavePrincipal p = new DatawavePrincipal(Collections.singletonList(u));
Assert.assertTrue(c.canRunQuery(p));
Assert.assertEquals(1, c.getQueryLogics().size());
}
use of datawave.webservice.query.logic.BaseQueryLogic in project datawave by NationalSecurityAgency.
the class CompositeQueryLogicTest method testQueryLogic.
@Test
public // testQueryLogic with max.results.override not set
void testQueryLogic() throws Exception {
Logger.getLogger(CompositeQueryLogic.class).setLevel(Level.TRACE);
Logger.getLogger(CompositeQueryLogicResults.class).setLevel(Level.TRACE);
Logger.getLogger(CompositeQueryLogicTransformer.class).setLevel(Level.TRACE);
List<BaseQueryLogic<?>> logics = new ArrayList<>();
TestQueryLogic logic1 = new TestQueryLogic();
TestQueryLogic2 logic2 = new TestQueryLogic2();
logics.add(logic1);
logics.add(logic2);
logic1.getData().put(key1, value1);
logic1.getData().put(key2, value2);
logic2.getData().put(key3, value3);
logic2.getData().put(key4, value4);
logic1.getData().put(key5, value5);
logic1.getData().put(key6, value6);
logic2.getData().put(key7, value7);
logic2.getData().put(key8, value8);
QueryImpl settings = new QueryImpl();
settings.setPagesize(100);
settings.setQueryAuthorizations(auths.toString());
settings.setQuery("FOO == 'BAR'");
settings.setParameters(new HashSet<>());
settings.setId(UUID.randomUUID());
CompositeQueryLogic c = new CompositeQueryLogic();
// max.results.override is set to -1 when it is not passed in as it is an optional paramter
logic1.setMaxResults(-1);
logic2.setMaxResults(-1);
/**
* RunningQuery.setupConnection()
*/
c.setQueryLogics(logics);
c.initialize((Connector) null, (Query) settings, Collections.singleton(auths));
c.setupQuery(null);
TransformIterator iter = c.getTransformIterator((Query) settings);
/**
* RunningQuery.next() - iterate over results coming from tablet server through the TransformIterator to turn them into the objects.
*/
List<Object> results = new ArrayList<>();
while (iter.hasNext()) {
Object o = iter.next();
if (null == o)
break;
Assert.assertTrue(o instanceof TestQueryResponse);
results.add((TestQueryResponse) o);
}
Assert.assertEquals(8, results.size());
ResultsPage page = new ResultsPage(results, Status.COMPLETE);
/**
* QueryExecutorBean.next() - transform list of objects into JAXB response
*/
TestQueryResponseList response = (TestQueryResponseList) c.getTransformer((Query) settings).createResponse(page);
Assert.assertEquals(8, response.getResponses().size());
for (TestQueryResponse r : response.getResponses()) {
Assert.assertNotNull(r);
}
c.close();
}
use of datawave.webservice.query.logic.BaseQueryLogic in project datawave by NationalSecurityAgency.
the class CompositeQueryLogicTest method testCannotRunQueryLogic2.
@Test
public void testCannotRunQueryLogic2() throws Exception {
List<BaseQueryLogic<?>> logics = new ArrayList<>();
TestQueryLogic logic1 = new TestQueryLogic();
HashSet<String> roles = new HashSet<>();
roles.add("NONTESTROLE");
logic1.setRoleManager(new DatawaveRoleManager(roles));
TestQueryLogic2 logic2 = new TestQueryLogic2();
HashSet<String> roles2 = new HashSet<>();
roles2.add("NONTESTROLE");
logic2.setRoleManager(new DatawaveRoleManager(roles2));
logics.add(logic1);
logics.add(logic2);
CompositeQueryLogic c = new CompositeQueryLogic();
c.setQueryLogics(logics);
DatawaveUser u = new DatawaveUser(SubjectIssuerDNPair.of("CN=Other User Name ouser, OU=acme", "CN=ca, OU=acme"), UserType.USER, null, Collections.singleton("TESTROLE"), null, 0L);
DatawavePrincipal p = new DatawavePrincipal(Collections.singletonList(u));
Assert.assertFalse(c.canRunQuery(p));
Assert.assertEquals(0, c.getQueryLogics().size());
}
Aggregations