Search in sources :

Example 1 with BaseQueryLogic

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);
            }
        }
    }
}
Also used : GenericQueryConfiguration(datawave.webservice.query.configuration.GenericQueryConfiguration) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) QueryException(datawave.webservice.query.exception.QueryException) BaseQueryLogic(datawave.webservice.query.logic.BaseQueryLogic)

Example 2 with BaseQueryLogic

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();
}
Also used : QueryImpl(datawave.webservice.query.QueryImpl) TransformIterator(org.apache.commons.collections4.iterators.TransformIterator) ArrayList(java.util.ArrayList) BaseQueryLogic(datawave.webservice.query.logic.BaseQueryLogic) Test(org.junit.Test)

Example 3 with BaseQueryLogic

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());
}
Also used : DatawaveUser(datawave.security.authorization.DatawaveUser) ArrayList(java.util.ArrayList) DatawaveRoleManager(datawave.webservice.query.logic.DatawaveRoleManager) BaseQueryLogic(datawave.webservice.query.logic.BaseQueryLogic) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with BaseQueryLogic

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();
}
Also used : TransformIterator(org.apache.commons.collections4.iterators.TransformIterator) ArrayList(java.util.ArrayList) ResultsPage(datawave.webservice.query.cache.ResultsPage) QueryImpl(datawave.webservice.query.QueryImpl) BaseQueryLogic(datawave.webservice.query.logic.BaseQueryLogic) Test(org.junit.Test)

Example 5 with BaseQueryLogic

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());
}
Also used : DatawaveUser(datawave.security.authorization.DatawaveUser) ArrayList(java.util.ArrayList) DatawaveRoleManager(datawave.webservice.query.logic.DatawaveRoleManager) BaseQueryLogic(datawave.webservice.query.logic.BaseQueryLogic) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

BaseQueryLogic (datawave.webservice.query.logic.BaseQueryLogic)20 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)14 QueryImpl (datawave.webservice.query.QueryImpl)10 TransformIterator (org.apache.commons.collections4.iterators.TransformIterator)6 DatawavePrincipal (datawave.security.authorization.DatawavePrincipal)4 DatawaveUser (datawave.security.authorization.DatawaveUser)4 ResultsPage (datawave.webservice.query.cache.ResultsPage)4 DatawaveRoleManager (datawave.webservice.query.logic.DatawaveRoleManager)4 HashSet (java.util.HashSet)4 QueryException (datawave.webservice.query.exception.QueryException)3 GenericQueryConfiguration (datawave.webservice.query.configuration.GenericQueryConfiguration)2 Timed (com.codahale.metrics.annotation.Timed)1 InMemoryInstance (datawave.accumulo.inmemory.InMemoryInstance)1 GenerateQuerySessionId (datawave.annotation.GenerateQuerySessionId)1 BaseQueryMetric (datawave.microservice.querymetric.BaseQueryMetric)1 PageMetric (datawave.microservice.querymetric.BaseQueryMetric.PageMetric)1 QueryMetricFactoryImpl (datawave.microservice.querymetric.QueryMetricFactoryImpl)1 EasyRoleManager (datawave.webservice.query.logic.EasyRoleManager)1 QueryLogic (datawave.webservice.query.logic.QueryLogic)1