Search in sources :

Example 6 with StandardProvenanceEventRecord

use of org.apache.nifi.provenance.StandardProvenanceEventRecord in project nifi by apache.

the class DocsReader method getRecord.

private ProvenanceEventRecord getRecord(final Document d, final RecordReader reader) throws IOException {
    final IndexableField blockField = d.getField(FieldNames.BLOCK_INDEX);
    if (blockField == null) {
        reader.skipTo(getByteOffset(d, reader));
    } else {
        reader.skipToBlock(blockField.numericValue().intValue());
    }
    StandardProvenanceEventRecord record;
    while ((record = reader.nextRecord()) != null) {
        final IndexableField idField = d.getField(SearchableFields.Identifier.getSearchableFieldName());
        if (idField == null || idField.numericValue().longValue() == record.getEventId()) {
            break;
        }
    }
    if (record == null) {
        logger.warn("Failed to read Provenance Event for '" + d + "'. The event file may be missing or corrupted");
    }
    return record;
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord)

Example 7 with StandardProvenanceEventRecord

use of org.apache.nifi.provenance.StandardProvenanceEventRecord in project nifi by apache.

the class LookupTableEventRecord method getEvent.

@SuppressWarnings("unchecked")
public static StandardProvenanceEventRecord getEvent(final Record record, final String storageFilename, final long storageByteOffset, final int maxAttributeLength, final long eventIdStartOffset, final long startTimeOffset, final List<String> componentIds, final List<String> componentTypes, final List<String> queueIds, final List<String> eventTypes) {
    final Map<String, String> previousAttributes = truncateAttributes((Map<String, String>) record.getFieldValue(EventFieldNames.PREVIOUS_ATTRIBUTES), maxAttributeLength);
    final Map<String, String> updatedAttributes = truncateAttributes((Map<String, String>) record.getFieldValue(EventFieldNames.UPDATED_ATTRIBUTES), maxAttributeLength);
    final List<String> childUuids = (List<String>) record.getFieldValue(EventFieldNames.CHILD_UUIDS);
    final List<String> parentUuids = (List<String>) record.getFieldValue(EventFieldNames.PARENT_UUIDS);
    final StandardProvenanceEventRecord.Builder builder = new StandardProvenanceEventRecord.Builder();
    builder.setAlternateIdentifierUri((String) record.getFieldValue(EventFieldNames.ALTERNATE_IDENTIFIER));
    builder.setChildUuids(childUuids);
    builder.setDetails((String) record.getFieldValue(EventFieldNames.EVENT_DETAILS));
    builder.setParentUuids(parentUuids);
    builder.setPreviousAttributes(previousAttributes);
    builder.setRelationship((String) record.getFieldValue(EventFieldNames.RELATIONSHIP));
    builder.setSourceSystemFlowFileIdentifier((String) record.getFieldValue(EventFieldNames.SOURCE_SYSTEM_FLOWFILE_IDENTIFIER));
    builder.setTransitUri((String) record.getFieldValue(EventFieldNames.TRANSIT_URI));
    builder.setUpdatedAttributes(updatedAttributes);
    builder.setComponentId(readLookupValue(record.getFieldValue(EventFieldNames.COMPONENT_ID), componentIds));
    builder.setComponentType(readLookupValue(record.getFieldValue(EventFieldNames.COMPONENT_TYPE), componentTypes));
    builder.setSourceQueueIdentifier(readLookupValue(record.getFieldValue(EventFieldNames.SOURCE_QUEUE_IDENTIFIER), queueIds));
    // Determine the event type
    final Integer eventTypeOrdinal = (Integer) record.getFieldValue(EventFieldNames.EVENT_TYPE);
    ProvenanceEventType eventType;
    if (eventTypeOrdinal == null || eventTypeOrdinal > eventTypes.size() || eventTypeOrdinal < 0) {
        eventType = ProvenanceEventType.UNKNOWN;
    } else {
        try {
            eventType = ProvenanceEventType.valueOf(eventTypes.get(eventTypeOrdinal));
        } catch (final Exception e) {
            eventType = ProvenanceEventType.UNKNOWN;
        }
    }
    builder.setEventType(eventType);
    // Determine appropriate UUID for the event
    String uuid = null;
    switch(eventType) {
        case CLONE:
        case FORK:
        case REPLAY:
            if (parentUuids != null && !parentUuids.isEmpty()) {
                uuid = parentUuids.get(0);
            }
            break;
        case JOIN:
            if (childUuids != null && !childUuids.isEmpty()) {
                uuid = childUuids.get(0);
            }
            break;
    }
    if (uuid == null) {
        uuid = updatedAttributes == null ? null : updatedAttributes.get(CoreAttributes.UUID.key());
        if (uuid == null) {
            uuid = previousAttributes == null ? null : previousAttributes.get(CoreAttributes.UUID.key());
        }
    }
    builder.setFlowFileUUID(uuid);
    builder.setEventDuration((Integer) record.getFieldValue(EventFieldNames.EVENT_DURATION));
    builder.setEventTime(addLong((Integer) record.getFieldValue(EventFieldNames.EVENT_TIME), startTimeOffset));
    builder.setFlowFileEntryDate(addLong((Integer) record.getFieldValue(EventFieldNames.FLOWFILE_ENTRY_DATE), startTimeOffset));
    builder.setLineageStartDate(addLong((Integer) record.getFieldValue(EventFieldNames.LINEAGE_START_DATE), startTimeOffset));
    final Integer eventId = (Integer) record.getFieldValue(EventFieldNames.EVENT_IDENTIFIER);
    if (eventId != null) {
        builder.setEventId(eventId.longValue() + eventIdStartOffset);
    }
    builder.setStorageLocation(storageFilename, storageByteOffset);
    final Record previousClaimRecord = (Record) record.getFieldValue(EventFieldNames.PREVIOUS_CONTENT_CLAIM);
    if (previousClaimRecord != null) {
        builder.setPreviousContentClaim((String) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_CONTAINER), (String) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_SECTION), (String) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_IDENTIFIER), (Long) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_OFFSET), (Long) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_SIZE));
    }
    final Object contentClaimObject = record.getFieldValue(EventFieldNames.CONTENT_CLAIM);
    // NO_VALUE type
    builder.setCurrentContentClaim(null, null, null, null, 0L);
    if (contentClaimObject != null) {
        if (contentClaimObject instanceof String) {
            final String contentClaimDescription = (String) contentClaimObject;
            switch(contentClaimDescription) {
                case EventFieldNames.UNCHANGED_VALUE:
                    builder.setCurrentContentClaim((String) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_CONTAINER), (String) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_SECTION), (String) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_IDENTIFIER), (Long) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_OFFSET), (Long) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_SIZE));
                    break;
            }
        } else if (contentClaimObject instanceof Record) {
            final Record currentClaimRecord = (Record) contentClaimObject;
            builder.setCurrentContentClaim((String) currentClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_CONTAINER), (String) currentClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_SECTION), (String) currentClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_IDENTIFIER), (Long) currentClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_OFFSET), (Long) currentClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_SIZE));
        }
    }
    return builder.build();
}
Also used : StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) List(java.util.List) Record(org.apache.nifi.repository.schema.Record) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) FieldMapRecord(org.apache.nifi.repository.schema.FieldMapRecord) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) ProvenanceEventType(org.apache.nifi.provenance.ProvenanceEventType)

Example 8 with StandardProvenanceEventRecord

use of org.apache.nifi.provenance.StandardProvenanceEventRecord in project nifi by apache.

the class DumpEventFile method main.

public static void main(final String[] args) throws IOException {
    if (args.length != 1) {
        printUsage();
        return;
    }
    final File file = new File(args[0]);
    if (!file.exists()) {
        System.out.println("Cannot find file " + file.getAbsolutePath());
        return;
    }
    try (final RecordReader reader = RecordReaders.newRecordReader(file, Collections.emptyList(), 65535)) {
        StandardProvenanceEventRecord event;
        int index = 0;
        while ((event = reader.nextRecord()) != null) {
            final long byteOffset = reader.getBytesConsumed();
            final String string = stringify(event, index++, byteOffset);
            System.out.println(string);
        }
    }
}
Also used : StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) RecordReader(org.apache.nifi.provenance.serialization.RecordReader) File(java.io.File)

Aggregations

StandardProvenanceEventRecord (org.apache.nifi.provenance.StandardProvenanceEventRecord)8 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)3 EOFException (java.io.EOFException)2 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 FlowFileQueue (org.apache.nifi.controller.queue.FlowFileQueue)2 ContentClaim (org.apache.nifi.controller.repository.claim.ContentClaim)2 ResourceClaim (org.apache.nifi.controller.repository.claim.ResourceClaim)2 RecordReader (org.apache.nifi.provenance.serialization.RecordReader)2 FieldMapRecord (org.apache.nifi.repository.schema.FieldMapRecord)2 Record (org.apache.nifi.repository.schema.Record)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IndexableField (org.apache.lucene.index.IndexableField)1