Search in sources :

Example 6 with DataSetRefs

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

the class TestKafkaTopic method testPublishKafka.

@Test
public void testPublishKafka() {
    final String processorName = "PublishKafka";
    final String transitUri = "PLAINTEXT://0.example.com:6667/topicA";
    final ProvenanceEventRecord record = Mockito.mock(ProvenanceEventRecord.class);
    when(record.getComponentType()).thenReturn(processorName);
    when(record.getTransitUri()).thenReturn(transitUri);
    when(record.getEventType()).thenReturn(ProvenanceEventType.SEND);
    final ClusterResolvers clusterResolvers = Mockito.mock(ClusterResolvers.class);
    when(clusterResolvers.fromHostNames(matches(".+\\.example\\.com"))).thenReturn("cluster1");
    final AnalysisContext context = Mockito.mock(AnalysisContext.class);
    when(context.getClusterResolver()).thenReturn(clusterResolvers);
    final NiFiProvenanceEventAnalyzer analyzer = NiFiProvenanceEventAnalyzerFactory.getAnalyzer(processorName, transitUri, record.getEventType());
    assertNotNull(analyzer);
    final DataSetRefs refs = analyzer.analyze(context, record);
    assertEquals(0, refs.getInputs().size());
    assertEquals(1, refs.getOutputs().size());
    Referenceable ref = refs.getOutputs().iterator().next();
    assertEquals("topicA", ref.get(ATTR_NAME));
    assertEquals("topicA", ref.get("topic"));
    assertEquals("topicA@cluster1", ref.get(ATTR_QUALIFIED_NAME));
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) ClusterResolvers(org.apache.nifi.atlas.resolver.ClusterResolvers) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) DataSetRefs(org.apache.nifi.atlas.provenance.DataSetRefs) AnalysisContext(org.apache.nifi.atlas.provenance.AnalysisContext) NiFiProvenanceEventAnalyzer(org.apache.nifi.atlas.provenance.NiFiProvenanceEventAnalyzer) Test(org.junit.Test)

Example 7 with DataSetRefs

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

the class TestKafkaTopic method testConsumeKafka.

@Test
public void testConsumeKafka() {
    final String processorName = "ConsumeKafka";
    final String transitUri = "PLAINTEXT://0.example.com:6667/topicA";
    final ProvenanceEventRecord record = Mockito.mock(ProvenanceEventRecord.class);
    when(record.getComponentType()).thenReturn(processorName);
    when(record.getTransitUri()).thenReturn(transitUri);
    when(record.getEventType()).thenReturn(ProvenanceEventType.RECEIVE);
    final ClusterResolvers clusterResolvers = Mockito.mock(ClusterResolvers.class);
    when(clusterResolvers.fromHostNames(matches(".+\\.example\\.com"))).thenReturn("cluster1");
    final AnalysisContext context = Mockito.mock(AnalysisContext.class);
    when(context.getClusterResolver()).thenReturn(clusterResolvers);
    final NiFiProvenanceEventAnalyzer analyzer = NiFiProvenanceEventAnalyzerFactory.getAnalyzer(processorName, transitUri, record.getEventType());
    assertNotNull(analyzer);
    final DataSetRefs refs = analyzer.analyze(context, record);
    assertEquals(1, refs.getInputs().size());
    assertEquals(0, refs.getOutputs().size());
    Referenceable ref = refs.getInputs().iterator().next();
    assertEquals("kafka_topic", ref.getTypeName());
    assertEquals("topicA", ref.get(ATTR_NAME));
    assertEquals("topicA", ref.get("topic"));
    assertEquals("topicA@cluster1", ref.get(ATTR_QUALIFIED_NAME));
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) ClusterResolvers(org.apache.nifi.atlas.resolver.ClusterResolvers) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) DataSetRefs(org.apache.nifi.atlas.provenance.DataSetRefs) AnalysisContext(org.apache.nifi.atlas.provenance.AnalysisContext) NiFiProvenanceEventAnalyzer(org.apache.nifi.atlas.provenance.NiFiProvenanceEventAnalyzer) Test(org.junit.Test)

Example 8 with DataSetRefs

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

the class TestKafkaTopic method testConsumeKafkaRecord_0_10.

@Test
public void testConsumeKafkaRecord_0_10() {
    final String processorName = "ConsumeKafkaRecord_0_10";
    final String transitUri = "PLAINTEXT://0.example.com:6667/topicA";
    final ProvenanceEventRecord record = Mockito.mock(ProvenanceEventRecord.class);
    when(record.getComponentType()).thenReturn(processorName);
    when(record.getTransitUri()).thenReturn(transitUri);
    when(record.getEventType()).thenReturn(ProvenanceEventType.RECEIVE);
    final ClusterResolvers clusterResolvers = Mockito.mock(ClusterResolvers.class);
    when(clusterResolvers.fromHostNames(matches(".+\\.example\\.com"))).thenReturn("cluster1");
    final AnalysisContext context = Mockito.mock(AnalysisContext.class);
    when(context.getClusterResolver()).thenReturn(clusterResolvers);
    final NiFiProvenanceEventAnalyzer analyzer = NiFiProvenanceEventAnalyzerFactory.getAnalyzer(processorName, transitUri, record.getEventType());
    assertNotNull(analyzer);
    final DataSetRefs refs = analyzer.analyze(context, record);
    assertEquals(1, refs.getInputs().size());
    assertEquals(0, refs.getOutputs().size());
    Referenceable ref = refs.getInputs().iterator().next();
    assertEquals("kafka_topic", ref.getTypeName());
    assertEquals("topicA", ref.get(ATTR_NAME));
    assertEquals("topicA", ref.get("topic"));
    assertEquals("topicA@cluster1", ref.get(ATTR_QUALIFIED_NAME));
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) ClusterResolvers(org.apache.nifi.atlas.resolver.ClusterResolvers) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) DataSetRefs(org.apache.nifi.atlas.provenance.DataSetRefs) AnalysisContext(org.apache.nifi.atlas.provenance.AnalysisContext) NiFiProvenanceEventAnalyzer(org.apache.nifi.atlas.provenance.NiFiProvenanceEventAnalyzer) Test(org.junit.Test)

Example 9 with DataSetRefs

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

the class TestNiFiRemotePort method testRemoteInputPort.

@Test
public void testRemoteInputPort() {
    final String componentType = "Remote Input Port";
    final String transitUri = "http://0.example.com:8080/nifi-api/data-transfer/input-ports/port-guid/transactions/tx-guid/flow-files";
    final ProvenanceEventRecord sendEvent = Mockito.mock(ProvenanceEventRecord.class);
    when(sendEvent.getEventId()).thenReturn(123L);
    when(sendEvent.getComponentId()).thenReturn("port-guid");
    when(sendEvent.getComponentType()).thenReturn(componentType);
    when(sendEvent.getTransitUri()).thenReturn(transitUri);
    when(sendEvent.getEventType()).thenReturn(ProvenanceEventType.SEND);
    final ClusterResolvers clusterResolvers = Mockito.mock(ClusterResolvers.class);
    when(clusterResolvers.fromHostNames(matches(".+\\.example\\.com"))).thenReturn("cluster1");
    final List<ConnectionStatus> connections = new ArrayList<>();
    final ConnectionStatus connection = new ConnectionStatus();
    connection.setDestinationId("port-guid");
    connection.setDestinationName("inputPortA");
    connections.add(connection);
    final AnalysisContext context = Mockito.mock(AnalysisContext.class);
    when(context.getClusterResolver()).thenReturn(clusterResolvers);
    when(context.findConnectionTo(matches("port-guid"))).thenReturn(connections);
    final NiFiProvenanceEventAnalyzer analyzer = NiFiProvenanceEventAnalyzerFactory.getAnalyzer(componentType, transitUri, sendEvent.getEventType());
    assertNotNull(analyzer);
    final DataSetRefs refs = analyzer.analyze(context, sendEvent);
    assertEquals(0, refs.getInputs().size());
    assertEquals(1, refs.getOutputs().size());
    assertEquals(1, refs.getComponentIds().size());
    // Should report connected componentId.
    assertTrue(refs.getComponentIds().contains("port-guid"));
    Referenceable ref = refs.getOutputs().iterator().next();
    assertEquals(TYPE_NIFI_INPUT_PORT, ref.getTypeName());
    assertEquals("inputPortA", ref.get(ATTR_NAME));
    assertEquals("port-guid@cluster1", ref.get(ATTR_QUALIFIED_NAME));
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) ClusterResolvers(org.apache.nifi.atlas.resolver.ClusterResolvers) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) DataSetRefs(org.apache.nifi.atlas.provenance.DataSetRefs) ArrayList(java.util.ArrayList) AnalysisContext(org.apache.nifi.atlas.provenance.AnalysisContext) ConnectionStatus(org.apache.nifi.controller.status.ConnectionStatus) NiFiProvenanceEventAnalyzer(org.apache.nifi.atlas.provenance.NiFiProvenanceEventAnalyzer) Test(org.junit.Test)

Example 10 with DataSetRefs

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

the class Hive2JDBC method analyze.

@Override
public DataSetRefs analyze(AnalysisContext context, ProvenanceEventRecord event) {
    // Replace the colon so that the schema in the URI can be parsed correctly.
    final String transitUri = event.getTransitUri();
    if (transitUri == null) {
        return null;
    }
    final Matcher uriMatcher = URI_PATTERN.matcher(transitUri);
    if (!uriMatcher.matches()) {
        logger.warn("Unexpected transit URI: {}", new Object[] { transitUri });
        return null;
    }
    final String clusterName = context.getClusterResolver().fromHostNames(splitHostNames(uriMatcher.group(1)));
    String connectedDatabaseName = null;
    if (uriMatcher.groupCount() > 1) {
        // Try to find connected database name from connection parameters.
        final String[] connectionParams = uriMatcher.group(2).split(";");
        connectedDatabaseName = connectionParams[0];
    }
    if (StringUtils.isEmpty(connectedDatabaseName)) {
        // If not found, then use "default".
        connectedDatabaseName = "default";
    }
    final Set<Tuple<String, String>> inputTables = parseTableNames(connectedDatabaseName, event.getAttribute(ATTR_INPUT_TABLES));
    final Set<Tuple<String, String>> outputTables = parseTableNames(connectedDatabaseName, event.getAttribute(ATTR_OUTPUT_TABLES));
    if (inputTables.isEmpty() && outputTables.isEmpty()) {
        // If input/output tables are unknown, create database level lineage.
        return getDatabaseRef(event.getComponentId(), event.getEventType(), clusterName, connectedDatabaseName);
    }
    final DataSetRefs refs = new DataSetRefs(event.getComponentId());
    addRefs(refs, true, clusterName, inputTables);
    addRefs(refs, false, clusterName, outputTables);
    return refs;
}
Also used : Matcher(java.util.regex.Matcher) DataSetRefs(org.apache.nifi.atlas.provenance.DataSetRefs) 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