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