Search in sources :

Example 11 with DataSetRefs

use of org.apache.nifi.atlas.provenance.DataSetRefs in project nifi by apache.

the class CompleteFlowPathLineage method analyzeLineagePath.

private void analyzeLineagePath(AnalysisContext analysisContext, LineagePath lineagePath) {
    final List<ProvenanceEventRecord> events = lineagePath.getEvents();
    final DataSetRefs parentRefs = new DataSetRefs(events.get(0).getComponentId());
    events.forEach(event -> {
        final DataSetRefs refs = executeAnalyzer(analysisContext, event);
        if (refs == null || refs.isEmpty()) {
            return;
        }
        refs.getInputs().forEach(parentRefs::addInput);
        refs.getOutputs().forEach(parentRefs::addOutput);
    });
    lineagePath.setRefs(parentRefs);
    // Analyse parents.
    lineagePath.getParents().forEach(parent -> analyzeLineagePath(analysisContext, parent));
}
Also used : ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) DataSetRefs(org.apache.nifi.atlas.provenance.DataSetRefs)

Example 12 with DataSetRefs

use of org.apache.nifi.atlas.provenance.DataSetRefs in project nifi by apache.

the class PutHiveStreaming method analyze.

@Override
public DataSetRefs analyze(AnalysisContext context, ProvenanceEventRecord event) {
    final URI uri = parseUri(event.getTransitUri());
    final String clusterName = context.getClusterResolver().fromHostNames(uri.getHost());
    final Set<Tuple<String, String>> outputTables = parseTableNames(null, event.getAttribute(ATTR_OUTPUT_TABLES));
    if (outputTables.isEmpty()) {
        return null;
    }
    final DataSetRefs refs = new DataSetRefs(event.getComponentId());
    outputTables.forEach(tableName -> {
        final Referenceable ref = createTableRef(clusterName, tableName);
        refs.addOutput(ref);
    });
    return refs;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) DataSetRefs(org.apache.nifi.atlas.provenance.DataSetRefs) URI(java.net.URI) Tuple(org.apache.nifi.util.Tuple)

Example 13 with DataSetRefs

use of org.apache.nifi.atlas.provenance.DataSetRefs in project nifi by apache.

the class UnknownInput method analyze.

@Override
public DataSetRefs analyze(AnalysisContext context, ProvenanceEventRecord event) {
    final String componentId = event.getComponentId();
    final DataSetRefs refs = new DataSetRefs(componentId);
    final Referenceable ref = createDataSetRef(context, event);
    refs.addInput(ref);
    return refs;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) DataSetRefs(org.apache.nifi.atlas.provenance.DataSetRefs)

Example 14 with DataSetRefs

use of org.apache.nifi.atlas.provenance.DataSetRefs in project nifi by apache.

the class UnknownOutput method analyze.

@Override
public DataSetRefs analyze(AnalysisContext context, ProvenanceEventRecord event) {
    final String componentId = event.getComponentId();
    final DataSetRefs refs = new DataSetRefs(componentId);
    final Referenceable ref = createDataSetRef(context, event);
    refs.addOutput(ref);
    return refs;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) DataSetRefs(org.apache.nifi.atlas.provenance.DataSetRefs)

Example 15 with DataSetRefs

use of org.apache.nifi.atlas.provenance.DataSetRefs in project nifi by apache.

the class CompleteFlowPathLineage method processEvent.

@Override
public void processEvent(AnalysisContext analysisContext, NiFiFlow nifiFlow, ProvenanceEventRecord event) {
    if (!ProvenanceEventType.DROP.equals(event.getEventType())) {
        return;
    }
    final ComputeLineageResult lineage = analysisContext.queryLineage(event.getEventId());
    // Construct a tree model to traverse backwards.
    final Map<String, List<LineageNode>> lineageTree = new HashMap<>();
    analyzeLineageTree(lineage, lineageTree);
    final LineagePath lineagePath = new LineagePath();
    extractLineagePaths(analysisContext, lineageTree, lineagePath, event);
    analyzeLineagePath(analysisContext, lineagePath);
    // Input and output data set are both required to report lineage.
    List<Tuple<NiFiFlowPath, DataSetRefs>> createdFlowPaths = new ArrayList<>();
    if (lineagePath.isComplete()) {
        createCompleteFlowPath(nifiFlow, lineagePath, createdFlowPaths);
        for (Tuple<NiFiFlowPath, DataSetRefs> createdFlowPath : createdFlowPaths) {
            final NiFiFlowPath flowPath = createdFlowPath.getKey();
            createEntity(toReferenceable(flowPath, nifiFlow));
            addDataSetRefs(nifiFlow, Collections.singleton(flowPath), createdFlowPath.getValue());
        }
        createdFlowPaths.clear();
    }
}
Also used : ComputeLineageResult(org.apache.nifi.provenance.lineage.ComputeLineageResult) HashMap(java.util.HashMap) NiFiFlowPath(org.apache.nifi.atlas.NiFiFlowPath) DataSetRefs(org.apache.nifi.atlas.provenance.DataSetRefs) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Tuple(org.apache.nifi.util.Tuple)

Aggregations

DataSetRefs (org.apache.nifi.atlas.provenance.DataSetRefs)26 Referenceable (org.apache.atlas.typesystem.Referenceable)22 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)21 AnalysisContext (org.apache.nifi.atlas.provenance.AnalysisContext)19 NiFiProvenanceEventAnalyzer (org.apache.nifi.atlas.provenance.NiFiProvenanceEventAnalyzer)18 ClusterResolvers (org.apache.nifi.atlas.resolver.ClusterResolvers)18 Test (org.junit.Test)18 HashMap (java.util.HashMap)7 ArrayList (java.util.ArrayList)6 ConnectionStatus (org.apache.nifi.controller.status.ConnectionStatus)5 Tuple (org.apache.nifi.util.Tuple)4 NiFiFlowPath (org.apache.nifi.atlas.NiFiFlowPath)3 List (java.util.List)2 ComputeLineageResult (org.apache.nifi.provenance.lineage.ComputeLineageResult)2 URI (java.net.URI)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Matcher (java.util.regex.Matcher)1