Search in sources :

Example 6 with SearchableField

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

the class SearchableFieldParser method extractSearchableFields.

public static List<SearchableField> extractSearchableFields(final String indexedFieldString, final boolean predefinedField) {
    final List<SearchableField> searchableFields = new ArrayList<>();
    if (indexedFieldString != null) {
        final String[] split = indexedFieldString.split(",");
        for (String fieldName : split) {
            fieldName = fieldName.trim();
            if (fieldName.isEmpty()) {
                continue;
            }
            final SearchableField searchableField;
            if (predefinedField) {
                searchableField = SearchableFields.getSearchableField(fieldName);
            } else {
                searchableField = SearchableFields.newSearchableAttribute(fieldName);
            }
            if (searchableField == null) {
                throw new RuntimeException("Invalid Configuration: Provenance Repository configured to Index field '" + fieldName + "', but this is not a valid field");
            }
            searchableFields.add(searchableField);
        }
    }
    return searchableFields;
}
Also used : ArrayList(java.util.ArrayList) SearchableField(org.apache.nifi.provenance.search.SearchableField)

Example 7 with SearchableField

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

the class TestPersistentProvenanceRepository method testAddToMultipleLogsAndRecover.

@Test
public void testAddToMultipleLogsAndRecover() throws IOException, InterruptedException {
    assumeFalse(isWindowsEnvironment());
    final List<SearchableField> searchableFields = new ArrayList<>();
    searchableFields.add(SearchableFields.ComponentID);
    final RepositoryConfiguration config = createConfiguration();
    config.setMaxEventFileCapacity(1024L * 1024L);
    config.setMaxEventFileLife(2, TimeUnit.SECONDS);
    config.setSearchableFields(searchableFields);
    repo = new PersistentProvenanceRepository(config, DEFAULT_ROLLOVER_MILLIS);
    repo.initialize(getEventReporter(), null, null, IdentifierLookup.EMPTY);
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("abc", "xyz");
    attributes.put("xyz", "abc");
    attributes.put("uuid", UUID.randomUUID().toString());
    final ProvenanceEventBuilder builder = new StandardProvenanceEventRecord.Builder();
    builder.setEventTime(System.currentTimeMillis());
    builder.setEventType(ProvenanceEventType.RECEIVE);
    builder.setTransitUri("nifi://unit-test");
    builder.fromFlowFile(createFlowFile(3L, 3000L, attributes));
    builder.setComponentId("1234");
    builder.setComponentType("dummy processor");
    final ProvenanceEventRecord record = builder.build();
    for (int i = 0; i < 10; i++) {
        repo.registerEvent(record);
    }
    // create a different component id so that we can make sure we query this record.
    builder.setComponentId("XXXX");
    attributes.put("uuid", "11111111-1111-1111-1111-111111111111");
    builder.fromFlowFile(createFlowFile(11L, 11L, attributes));
    repo.registerEvent(builder.build());
    repo.waitForRollover();
    // Give the repo time to shutdown (i.e., close all file handles, etc.)
    Thread.sleep(500L);
    // Create a new repo and add another record with component id XXXX so that we can ensure that it's added to a different
    // log file than the previous one.
    attributes.put("uuid", "22222222-2222-2222-2222-222222222222");
    builder.fromFlowFile(createFlowFile(11L, 11L, attributes));
    repo.registerEvent(builder.build());
    repo.waitForRollover();
    final Query query = new Query(UUID.randomUUID().toString());
    query.addSearchTerm(SearchTerms.newSearchTerm(SearchableFields.ComponentID, "XXXX"));
    query.setMaxResults(100);
    final QueryResult result = repo.queryEvents(query, createUser());
    assertEquals(2, result.getMatchingEvents().size());
    for (final ProvenanceEventRecord match : result.getMatchingEvents()) {
        System.out.println(match);
    }
}
Also used : Query(org.apache.nifi.provenance.search.Query) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SearchableField(org.apache.nifi.provenance.search.SearchableField) QueryResult(org.apache.nifi.provenance.search.QueryResult) Test(org.junit.Test)

Aggregations

SearchableField (org.apache.nifi.provenance.search.SearchableField)7 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 Document (org.apache.lucene.document.Document)2 LongField (org.apache.lucene.document.LongField)2 ProvenanceEventType (org.apache.nifi.provenance.ProvenanceEventType)2 ProvenanceRepository (org.apache.nifi.provenance.ProvenanceRepository)2 Query (org.apache.nifi.provenance.search.Query)2 Map (java.util.Map)1 Pattern (java.util.regex.Pattern)1 IntField (org.apache.lucene.document.IntField)1 StringField (org.apache.lucene.document.StringField)1 QueryResult (org.apache.nifi.provenance.search.QueryResult)1 QuerySubmission (org.apache.nifi.provenance.search.QuerySubmission)1 SearchTerm (org.apache.nifi.provenance.search.SearchTerm)1 Filter (org.apache.nifi.util.RingBuffer.Filter)1 ProvenanceOptionsDTO (org.apache.nifi.web.api.dto.provenance.ProvenanceOptionsDTO)1 ProvenanceRequestDTO (org.apache.nifi.web.api.dto.provenance.ProvenanceRequestDTO)1 ProvenanceSearchableFieldDTO (org.apache.nifi.web.api.dto.provenance.ProvenanceSearchableFieldDTO)1 Test (org.junit.Test)1