Search in sources :

Example 11 with QuerySubmission

use of org.apache.nifi.provenance.search.QuerySubmission in project nifi by apache.

the class TestLuceneEventIndex method addThenQueryWithEmptyQuery.

@Test(timeout = 60000)
public void addThenQueryWithEmptyQuery() throws InterruptedException {
    assumeFalse(isWindowsEnvironment());
    final RepositoryConfiguration repoConfig = createConfig();
    final IndexManager indexManager = new SimpleIndexManager(repoConfig);
    final LuceneEventIndex index = new LuceneEventIndex(repoConfig, indexManager, 1, EventReporter.NO_OP);
    final ProvenanceEventRecord event = createEvent();
    index.addEvent(event, new StorageSummary(event.getEventId(), "1.prov", "1", 1, 2L, 2L));
    final Query query = new Query(UUID.randomUUID().toString());
    final ArrayListEventStore eventStore = new ArrayListEventStore();
    eventStore.addEvent(event);
    index.initialize(eventStore);
    // We don't know how long it will take for the event to be indexed, so keep querying until
    // we get a result. The test will timeout after 5 seconds if we've still not succeeded.
    List<ProvenanceEventRecord> matchingEvents = Collections.emptyList();
    while (matchingEvents.isEmpty()) {
        final QuerySubmission submission = index.submitQuery(query, EventAuthorizer.GRANT_ALL, "unit test user");
        assertNotNull(submission);
        final QueryResult result = submission.getResult();
        assertNotNull(result);
        result.awaitCompletion(100, TimeUnit.MILLISECONDS);
        assertTrue(result.isFinished());
        assertNull(result.getError());
        matchingEvents = result.getMatchingEvents();
        assertNotNull(matchingEvents);
        // avoid crushing the CPU
        Thread.sleep(100L);
    }
    assertEquals(1, matchingEvents.size());
    assertEquals(event, matchingEvents.get(0));
}
Also used : SimpleIndexManager(org.apache.nifi.provenance.lucene.SimpleIndexManager) IndexManager(org.apache.nifi.provenance.lucene.IndexManager) QueryResult(org.apache.nifi.provenance.search.QueryResult) StorageSummary(org.apache.nifi.provenance.serialization.StorageSummary) QuerySubmission(org.apache.nifi.provenance.search.QuerySubmission) Query(org.apache.nifi.provenance.search.Query) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) RepositoryConfiguration(org.apache.nifi.provenance.RepositoryConfiguration) SimpleIndexManager(org.apache.nifi.provenance.lucene.SimpleIndexManager) ArrayListEventStore(org.apache.nifi.provenance.store.ArrayListEventStore) Test(org.junit.Test)

Example 12 with QuerySubmission

use of org.apache.nifi.provenance.search.QuerySubmission in project nifi by apache.

the class TestLuceneEventIndex method testQuerySpecificField.

@Test(timeout = 50000)
public void testQuerySpecificField() throws InterruptedException {
    final RepositoryConfiguration repoConfig = createConfig();
    final IndexManager indexManager = new SimpleIndexManager(repoConfig);
    final LuceneEventIndex index = new LuceneEventIndex(repoConfig, indexManager, 2, EventReporter.NO_OP);
    // add 2 events, one of which we will query for.
    final ProvenanceEventRecord event = createEvent();
    index.addEvent(event, new StorageSummary(event.getEventId(), "1.prov", "1", 1, 2L, 2L));
    index.addEvent(createEvent(), new StorageSummary(2L, "1.prov", "1", 1, 2L, 2L));
    // Create a query that searches for the event with the FlowFile UUID equal to the first event's.
    final Query query = new Query(UUID.randomUUID().toString());
    query.addSearchTerm(SearchTerms.newSearchTerm(SearchableFields.FlowFileUUID, event.getFlowFileUuid()));
    final ArrayListEventStore eventStore = new ArrayListEventStore();
    eventStore.addEvent(event);
    index.initialize(eventStore);
    // We don't know how long it will take for the event to be indexed, so keep querying until
    // we get a result. The test will timeout after 5 seconds if we've still not succeeded.
    List<ProvenanceEventRecord> matchingEvents = Collections.emptyList();
    while (matchingEvents.isEmpty()) {
        final QuerySubmission submission = index.submitQuery(query, EventAuthorizer.GRANT_ALL, "unit test user");
        assertNotNull(submission);
        final QueryResult result = submission.getResult();
        assertNotNull(result);
        result.awaitCompletion(100, TimeUnit.MILLISECONDS);
        assertTrue(result.isFinished());
        assertNull(result.getError());
        matchingEvents = result.getMatchingEvents();
        assertNotNull(matchingEvents);
        // avoid crushing the CPU
        Thread.sleep(100L);
    }
    assertEquals(1, matchingEvents.size());
    assertEquals(event, matchingEvents.get(0));
}
Also used : SimpleIndexManager(org.apache.nifi.provenance.lucene.SimpleIndexManager) IndexManager(org.apache.nifi.provenance.lucene.IndexManager) QueryResult(org.apache.nifi.provenance.search.QueryResult) StorageSummary(org.apache.nifi.provenance.serialization.StorageSummary) QuerySubmission(org.apache.nifi.provenance.search.QuerySubmission) Query(org.apache.nifi.provenance.search.Query) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) RepositoryConfiguration(org.apache.nifi.provenance.RepositoryConfiguration) SimpleIndexManager(org.apache.nifi.provenance.lucene.SimpleIndexManager) ArrayListEventStore(org.apache.nifi.provenance.store.ArrayListEventStore) Test(org.junit.Test)

Example 13 with QuerySubmission

use of org.apache.nifi.provenance.search.QuerySubmission in project nifi by apache.

the class PersistentProvenanceRepository method retrieveQuerySubmission.

@Override
public QuerySubmission retrieveQuerySubmission(final String queryIdentifier, final NiFiUser user) {
    final QuerySubmission submission = querySubmissionMap.get(queryIdentifier);
    final String userId = submission.getSubmitterIdentity();
    if (user == null && userId == null) {
        return submission;
    }
    if (user == null) {
        throw new AccessDeniedException("Cannot retrieve Provenance Query Submission because no user id was provided in the provenance request.");
    }
    if (userId == null || userId.equals(user.getIdentity())) {
        return submission;
    }
    throw new AccessDeniedException("Cannot retrieve Provenance Query Submission because " + user.getIdentity() + " is not the user who submitted the request.");
}
Also used : AccessDeniedException(org.apache.nifi.authorization.AccessDeniedException) QuerySubmission(org.apache.nifi.provenance.search.QuerySubmission)

Example 14 with QuerySubmission

use of org.apache.nifi.provenance.search.QuerySubmission in project nifi by apache.

the class ControllerFacade method deleteProvenanceQuery.

/**
 * Deletes the query with the specified id.
 *
 * @param provenanceId id
 */
public void deleteProvenanceQuery(final String provenanceId) {
    // get the query to the provenance repository
    final ProvenanceRepository provenanceRepository = flowController.getProvenanceRepository();
    final QuerySubmission querySubmission = provenanceRepository.retrieveQuerySubmission(provenanceId, NiFiUserUtils.getNiFiUser());
    if (querySubmission != null) {
        querySubmission.cancel();
    }
}
Also used : QuerySubmission(org.apache.nifi.provenance.search.QuerySubmission) ProvenanceRepository(org.apache.nifi.provenance.ProvenanceRepository)

Example 15 with QuerySubmission

use of org.apache.nifi.provenance.search.QuerySubmission in project nifi-minifi by apache.

the class MiNiFiPersistentProvenanceRepository method queryEvents.

QueryResult queryEvents(final Query query, final NiFiUser user) throws IOException {
    final QuerySubmission submission = submitQuery(query, user);
    final QueryResult result = submission.getResult();
    while (!result.isFinished()) {
        try {
            Thread.sleep(100L);
        } catch (final InterruptedException ie) {
            Thread.currentThread().interrupt();
        }
    }
    if (result.getError() != null) {
        throw new IOException(result.getError());
    }
    logger.info("{} got {} hits", query, result.getTotalHitCount());
    return result;
}
Also used : QueryResult(org.apache.nifi.provenance.search.QueryResult) QuerySubmission(org.apache.nifi.provenance.search.QuerySubmission) IOException(java.io.IOException)

Aggregations

QuerySubmission (org.apache.nifi.provenance.search.QuerySubmission)15 Query (org.apache.nifi.provenance.search.Query)8 QueryResult (org.apache.nifi.provenance.search.QueryResult)7 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 IOException (java.io.IOException)4 AccessDeniedException (org.apache.nifi.authorization.AccessDeniedException)4 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)4 ProvenanceRepository (org.apache.nifi.provenance.ProvenanceRepository)3 RepositoryConfiguration (org.apache.nifi.provenance.RepositoryConfiguration)3 StandardProvenanceEventRecord (org.apache.nifi.provenance.StandardProvenanceEventRecord)3 IndexManager (org.apache.nifi.provenance.lucene.IndexManager)3 SimpleIndexManager (org.apache.nifi.provenance.lucene.SimpleIndexManager)3 ArrayListEventStore (org.apache.nifi.provenance.store.ArrayListEventStore)3 StorageSummary (org.apache.nifi.provenance.serialization.StorageSummary)2 ProvenanceRequestDTO (org.apache.nifi.web.api.dto.provenance.ProvenanceRequestDTO)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1