org.apache.nifi.controller.status.ConnectionStatus Java Examples

The following examples show how to use org.apache.nifi.controller.status.ConnectionStatus. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ControllerFacade.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the status for the specified connection.
 *
 * @param connectionId connection id
 * @return the status for the specified connection
 */
public ConnectionStatus getConnectionStatus(final String connectionId) {
    final ProcessGroup root = getRootGroup();
    final Connection connection = root.findConnection(connectionId);

    // ensure the connection was found
    if (connection == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate connection with id '%s'.", connectionId));
    }

    // calculate the process group status
    final String groupId = connection.getProcessGroup().getIdentifier();
    final ProcessGroupStatus processGroupStatus = flowController.getEventAccess().getGroupStatus(groupId, NiFiUserUtils.getNiFiUser(), 1);
    if (processGroupStatus == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate group with id '%s'.", groupId));
    }

    final ConnectionStatus status = processGroupStatus.getConnectionStatus().stream().filter(connectionStatus -> connectionId.equals(connectionStatus.getId())).findFirst().orElse(null);
    if (status == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate connection with id '%s'.", connectionId));
    }

    return status;
}
 
Example #2
Source File: TestSiteToSiteStatusReportingTask.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static ConnectionStatus generateConnectionStatus(String id, String namePrefix) {
    ConnectionStatus cStatus = new ConnectionStatus();
    cStatus.setId(id);
    cStatus.setName(namePrefix + "-" + UUID.randomUUID().toString());
    cStatus.setBackPressureDataSizeThreshold("1 KB"); // sets backPressureBytesThreshold too
    cStatus.setBackPressureObjectThreshold(1l);
    cStatus.setInputBytes(2l);
    cStatus.setInputCount(3);
    cStatus.setMaxQueuedBytes(4l);
    cStatus.setMaxQueuedCount(5);
    cStatus.setOutputBytes(6);
    cStatus.setOutputCount(7);
    cStatus.setQueuedBytes(8l);
    cStatus.setQueuedCount(9);
    cStatus.setSourceId(id);
    cStatus.setSourceName("source");
    cStatus.setDestinationId(id);
    cStatus.setDestinationName(null);

    return cStatus;
}
 
Example #3
Source File: ConnectionStatusEnumerator.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public boolean moveNext() {
    currentRow = null;
    final ConnectionStatus connectionStatus = connectionStatusIterator.next();
    if (connectionStatus == null) {
        // If we are out of data, close the InputStream. We do this because
        // Calcite does not necessarily call our close() method.
        close();
        try {
            onFinish();
        } catch (final Exception e) {
            logger.error("Failed to perform tasks when enumerator was finished", e);
        }

        return false;
    }

    currentRow = filterColumns(connectionStatus);

    recordsRead++;
    return true;
}
 
Example #4
Source File: TestUnknownDataSet.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testSomethingHavingIncomingConnection() {
    final String processorName = "SomeProcessor";
    final String processorId = "processor-1234";
    final ProvenanceEventRecord record = Mockito.mock(ProvenanceEventRecord.class);
    when(record.getComponentType()).thenReturn(processorName);
    when(record.getComponentId()).thenReturn(processorId);
    when(record.getEventType()).thenReturn(ProvenanceEventType.CREATE);

    final NamespaceResolvers namespaceResolvers = Mockito.mock(NamespaceResolvers.class);
    when(namespaceResolvers.fromHostNames(matches(".+\\.example\\.com"))).thenReturn("namespace1");

    final List<ConnectionStatus> connections = new ArrayList<>();
    // The content of connection is not important, just create an empty status.
    connections.add(new ConnectionStatus());

    final AnalysisContext context = Mockito.mock(AnalysisContext.class);
    when(context.getNamespaceResolver()).thenReturn(namespaceResolvers);
    when(context.findConnectionTo(processorId)).thenReturn(connections);

    final NiFiProvenanceEventAnalyzer analyzer = NiFiProvenanceEventAnalyzerFactory.getAnalyzer(processorName, null, record.getEventType());
    assertNotNull(analyzer);

    final DataSetRefs refs = analyzer.analyze(context, record);
    assertNull("If the processor has incoming connections, no refs should be created", refs);
}
 
Example #5
Source File: AzureLogAnalyticsMetricsFactory.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static List<Metric> getConnectionStatusMetrics(ConnectionStatus status, String instanceId, String groupName){

        final String groupId = status.getGroupId();
        final String tags = String.format(
            "[source=%s][destination=%s][cname=%s]", status.getSourceName(), status.getDestinationName(),
            status.getName());
        MetricsBuilder builder= new MetricsBuilder(Metric.CATEGORY_CONNECTIONS,instanceId, groupId, groupName);

        builder.setTags(tags)
            .metric(MetricNames.INPUT_COUNT,status.getInputCount())
            .metric(MetricNames.INPUT_BYTES, status.getInputBytes())
            .metric(MetricNames.QUEUED_COUNT, status.getQueuedCount())
            .metric(MetricNames.QUEUED_BYTES, status.getQueuedBytes())
            .metric(MetricNames.OUTPUT_COUNT, status.getOutputCount())
            .metric(MetricNames.OUTPUT_BYTES, status.getOutputBytes());

        return builder.build();
    }
 
Example #6
Source File: StatusConfigReporterTest.java    From nifi-minifi with Apache License 2.0 6 votes vote down vote up
private void populateConnection() {
    ConnectionStatus connectionStatus = new ConnectionStatus();
    connectionStatus.setQueuedBytes(100);
    connectionStatus.setId("connectionId");
    connectionStatus.setName("connectionName");
    connectionStatus.setQueuedCount(10);
    connectionStatus.setInputCount(1);
    connectionStatus.setInputBytes(2);
    connectionStatus.setOutputCount(3);
    connectionStatus.setOutputBytes(4);

    Collection<ConnectionStatus> statusCollection = new ArrayList<>();
    statusCollection.add(connectionStatus);

    when(rootGroupStatus.getConnectionStatus()).thenReturn(statusCollection);
}
 
Example #7
Source File: StatusConfigReporter.java    From nifi-minifi with Apache License 2.0 6 votes vote down vote up
private static <E> Map<String, E> transformStatusCollection(Collection<E> statusCollection) {
    Map<String, E> statusMap = new HashMap<>();
    for (E status : statusCollection) {
        if (status instanceof ProcessorStatus) {
            statusMap.put(((ProcessorStatus) status).getId(), status);
            if (((ProcessorStatus) status).getName() != null) {
                statusMap.put(((ProcessorStatus) status).getName(), status);
            }
        } else if (status instanceof ConnectionStatus) {
            statusMap.put(((ConnectionStatus) status).getId(), status);
            if (((ConnectionStatus) status).getName() != null) {
                statusMap.put(((ConnectionStatus) status).getName(), status);
            }
        } else if (status instanceof RemoteProcessGroupStatus) {
            statusMap.put(((RemoteProcessGroupStatus) status).getId(), status);
            if (((RemoteProcessGroupStatus) status).getName() != null) {
                statusMap.put(((RemoteProcessGroupStatus) status).getName(), status);
            }
        }
    }
    return statusMap;
}
 
Example #8
Source File: StatusConfigReporter.java    From nifi-minifi with Apache License 2.0 6 votes vote down vote up
private static void handleConnectionRequest(RequestItem requestItem, ProcessGroupStatus rootGroupStatus, List<ConnectionStatusBean> connectionStatusList,
                                            Map<String, ConnectionStatus> connectionStatusMap, Logger logger) throws StatusRequestException {
    if (connectionStatusMap == null) {
        connectionStatusMap = transformStatusCollection(rootGroupStatus.getConnectionStatus());
    }

    if (requestItem.identifier.equalsIgnoreCase("all")) {
        if (!connectionStatusMap.isEmpty()) {
            for (ConnectionStatus connectionStatus : new HashSet<>(connectionStatusMap.values())) {
                connectionStatusList.add(parseConnectionStatusRequest(connectionStatus, requestItem.options, logger));
            }
        }
    } else {
        if (connectionStatusMap.containsKey(requestItem.identifier)) {
            connectionStatusList.add(parseConnectionStatusRequest(connectionStatusMap.get(requestItem.identifier), requestItem.options, logger));
        } else {
            logger.warn("Status for connection with key " + requestItem.identifier + " was requested but one does not exist");
            throw new StatusRequestException("No connection with key " + requestItem.identifier + " to report status on");
        }
    }

}
 
Example #9
Source File: NiFiFlowAnalyzer.java    From nifi with Apache License 2.0 6 votes vote down vote up
private boolean isHeadProcessor(NiFiFlow nifiFlow, List<ConnectionStatus> ins) {
    if (ins == null || ins.isEmpty()) {
        return true;
    }
    return ins.stream().allMatch(
            in -> {
                // If it has incoming relationship from other process components, then return false.
                final String sourceId = in.getSourceId();
                if (nifiFlow.isProcessComponent(sourceId)) {
                    return false;
                }
                // Check next level.
                final List<ConnectionStatus> incomingConnections = nifiFlow.getIncomingConnections(sourceId);
                return isHeadProcessor(nifiFlow, incomingConnections);
            }
    );
}
 
Example #10
Source File: ConnectionStatusPredictionsEnumerator.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public boolean moveNext() {
    currentRow = null;
    final ConnectionStatus connectionStatus = connectionStatusIterator.next();
    if (connectionStatus == null) {
        // If we are out of data, close the InputStream. We do this because
        // Calcite does not necessarily call our close() method.
        close();
        try {
            onFinish();
        } catch (final Exception e) {
            logger.error("Failed to perform tasks when enumerator was finished", e);
        }

        return false;
    }

    currentRow = filterColumns(connectionStatus);

    recordsRead++;
    return true;
}
 
Example #11
Source File: ConnectionStatusRecursiveIterator.java    From nifi with Apache License 2.0 6 votes vote down vote up
private ConnectionStatus getNextConnectionStatus() {
    if (connectionStatusIterator != null && connectionStatusIterator.hasNext()) {
        return connectionStatusIterator.next();
    }
    // No more connections in this PG, so move to the next
    connectionStatusIterator = null;
    Iterator<ProcessGroupStatus> i = iteratorBreadcrumb.peek();
    if (i == null) {
        return null;
    }

    if (i.hasNext()) {
        ProcessGroupStatus nextPG = i.next();
        iteratorBreadcrumb.push(nextPG.getProcessGroupStatus().iterator());
        connectionStatusIterator = nextPG.getConnectionStatus().iterator();
        return getNextConnectionStatus();
    } else {
        // No more child PGs, remove it from the breadcrumb trail and try again
        iteratorBreadcrumb.pop();
        return getNextConnectionStatus();
    }
}
 
Example #12
Source File: ControllerFacade.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the status for the specified connection.
 *
 * @param connectionId connection id
 * @return the status for the specified connection
 */
public ConnectionStatus getConnectionStatus(final String connectionId) {
    final ProcessGroup root = flowController.getGroup(flowController.getRootGroupId());
    final Connection connection = root.findConnection(connectionId);

    // ensure the connection was found
    if (connection == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate connection with id '%s'.", connectionId));
    }

    // calculate the process group status
    final String groupId = connection.getProcessGroup().getIdentifier();
    final ProcessGroupStatus processGroupStatus = flowController.getGroupStatus(groupId, NiFiUserUtils.getNiFiUser());
    if (processGroupStatus == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate group with id '%s'.", groupId));
    }

    final ConnectionStatus status = processGroupStatus.getConnectionStatus().stream().filter(connectionStatus -> connectionId.equals(connectionStatus.getId())).findFirst().orElse(null);
    if (status == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate connection with id '%s'.", connectionId));
    }

    return status;
}
 
Example #13
Source File: NiFiFlowAnalyzer.java    From nifi with Apache License 2.0 6 votes vote down vote up
private List<String> getNextProcessComponent(NiFiFlow nifiFlow, NiFiFlowPath path, String componentId) {
    final List<ConnectionStatus> outs = nifiFlow.getOutgoingConnections(componentId);
    if (outs == null || outs.isEmpty()) {
        return Collections.emptyList();
    }

    final List<String> nextProcessComponent = new ArrayList<>();
    for (ConnectionStatus out : outs) {
        final String destinationId = out.getDestinationId();
        if (path.getProcessComponentIds().contains(destinationId)) {
            // If the connection is pointing back to current path, then skip it to avoid loop.
            continue;
        }

        if (nifiFlow.isProcessComponent(destinationId)) {
            nextProcessComponent.add(destinationId);
        } else {
            nextProcessComponent.addAll(getNextProcessComponent(nifiFlow, path, destinationId));
        }
    }
    return nextProcessComponent;
}
 
Example #14
Source File: NiFiFlowAnalyzer.java    From nifi with Apache License 2.0 6 votes vote down vote up
private List<String> getIncomingProcessorsIds(NiFiFlow nifiFlow, List<ConnectionStatus> incomingConnections) {
    if (incomingConnections == null) {
        return Collections.emptyList();
    }

    final List<String> ids = new ArrayList<>();

    incomingConnections.forEach(c -> {
        // Ignore self relationship.
        final String sourceId = c.getSourceId();
        if (!sourceId.equals(c.getDestinationId())) {
            if (nifiFlow.isProcessor(sourceId)) {
                ids.add(sourceId);
            } else {
                ids.addAll(getIncomingProcessorsIds(nifiFlow, nifiFlow.getIncomingConnections(sourceId)));
            }
        }
    });

    return ids;
}
 
Example #15
Source File: TestNiFiRemotePort.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoteInputPortHTTP() {
    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 NamespaceResolvers namespaceResolvers = Mockito.mock(NamespaceResolvers.class);
    when(namespaceResolvers.fromHostNames(matches(".+\\.example\\.com"))).thenReturn("namespace1");

    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.getNamespaceResolver()).thenReturn(namespaceResolvers);
    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@namespace1", ref.get(ATTR_QUALIFIED_NAME));
}
 
Example #16
Source File: NiFiFlowAnalyzer.java    From nifi with Apache License 2.0 5 votes vote down vote up
public void analyzePaths(NiFiFlow nifiFlow) {
    final String rootProcessGroupId = nifiFlow.getRootProcessGroupId();

    // Now let's break it into flow paths.
    final Map<String, ProcessorStatus> processors = nifiFlow.getProcessors();
    final Set<String> headProcessComponents = processors.keySet().stream()
            .filter(pid -> {
                final List<ConnectionStatus> ins = nifiFlow.getIncomingConnections(pid);
                return isHeadProcessor(nifiFlow, ins);
            })
            .collect(Collectors.toSet());

    // Use RootInputPorts as headProcessors.
    headProcessComponents.addAll(nifiFlow.getRootInputPorts().keySet());

    headProcessComponents.forEach(startPid -> {
        // By using the startPid as its qualifiedName, it's guaranteed that
        // the same path will end up being the same Atlas entity.
        // However, if the first processor is replaced by another,
        // the flow path will have a different id, and the old path is logically deleted.
        final NiFiFlowPath path = nifiFlow.getOrCreateFlowPath(startPid);
        traverse(nifiFlow, path, startPid);
    });

    nifiFlow.getFlowPaths().values().forEach(path -> {
        if (processors.containsKey(path.getId())) {
            final ProcessorStatus processor = processors.get(path.getId());
            path.setGroupId(processor.getGroupId());
        } else {
            path.setGroupId(rootProcessGroupId);
        }
    });
}
 
Example #17
Source File: AzureLogAnalyticsReportingTask.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void populateConnectionStatuses(final ProcessGroupStatus groupStatus,
        final List<ConnectionStatus> statuses) {
    statuses.addAll(groupStatus.getConnectionStatus());
    for (final ProcessGroupStatus childGroupStatus : groupStatus.getProcessGroupStatus()) {
        populateConnectionStatuses(childGroupStatus, statuses);
    }
}
 
Example #18
Source File: StatusRequestParser.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
static ConnectionStatusBean parseConnectionStatusRequest(ConnectionStatus inputConnectionStatus, String statusTypes, Logger logger) {
    ConnectionStatusBean connectionStatusBean = new ConnectionStatusBean();
    connectionStatusBean.setId(inputConnectionStatus.getId());
    connectionStatusBean.setName(inputConnectionStatus.getName());

    String[] statusSplits = statusTypes.split(",");
    for (String statusType : statusSplits) {
        switch (statusType.toLowerCase().trim()) {
            case "health":
                ConnectionHealth connectionHealth = new ConnectionHealth();

                connectionHealth.setQueuedBytes(inputConnectionStatus.getQueuedBytes());
                connectionHealth.setQueuedCount(inputConnectionStatus.getQueuedCount());

                connectionStatusBean.setConnectionHealth(connectionHealth);
                break;
            case "stats":
                ConnectionStats connectionStats = new ConnectionStats();

                connectionStats.setInputBytes(inputConnectionStatus.getInputBytes());
                connectionStats.setInputCount(inputConnectionStatus.getInputCount());
                connectionStats.setOutputCount(inputConnectionStatus.getOutputCount());
                connectionStats.setOutputBytes(inputConnectionStatus.getOutputBytes());

                connectionStatusBean.setConnectionStats(connectionStats);
                break;
        }
    }
    return connectionStatusBean;
}
 
Example #19
Source File: ITReportLineageToAtlas.java    From nifi with Apache License 2.0 5 votes vote down vote up
public TemplateContentHander(String name) {
    rootPgStatus = new ProcessGroupStatus();
    rootPgStatus.setId(name);
    rootPgStatus.setName(name);
    pgStatus = rootPgStatus;
    current = rootPgStatus;
    pgStack.push(rootPgStatus);

    setters.put("id", idSetters);
    setters.put("name", nameSetters);

    idSetters.put(ProcessGroupStatus.class, s("processGroups",
            (o, id) -> ((ProcessGroupStatus) o).setId(id)));
    idSetters.put(ProcessorStatus.class, s("processors",
            (o, id) -> ((ProcessorStatus) o).setId(id)));

    idSetters.put(PortStatus.class, (o, id) -> ((PortStatus) o).setId(id));

    idSetters.put(ConnectionStatus.class, (o, id) -> {
        if (context.isConnectionSource) {
            ((ConnectionStatus) o).setSourceId(id);
        } else if (context.isConnectionDestination) {
            ((ConnectionStatus) o).setDestinationId(id);
        } else {
            ((ConnectionStatus) o).setId(id);
        }
    });

    nameSetters.put(ProcessGroupStatus.class, s("processGroups",
            (o, n) -> ((ProcessGroupStatus) o).setName(n)));

    nameSetters.put(ProcessorStatus.class, s("processors",
            (o, n) -> ((ProcessorStatus) o).setName(n)));

    nameSetters.put(PortStatus.class, (o, n) -> ((PortStatus) o).setName(n));

    nameSetters.put(ConnectionStatus.class, s("connections",
            (o, n) -> ((ConnectionStatus) o).setName(n)));
}
 
Example #20
Source File: AzureLogAnalyticsReportingTask.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * collect metrics to be sent to azure log analytics workspace
 *
 * @param instanceId          instance id
 * @param status              process group status
 * @param processGroupName    process group name
 * @param jvmMetricsCollected whether we want to collect jvm metrics or not
 * @return list of metrics collected
 */
protected List<Metric> collectMetrics(final String instanceId, final ProcessGroupStatus status,
        final String processGroupName, final boolean jvmMetricsCollected) {
    List<Metric> allMetrics = new ArrayList<>();

    // dataflow process group level metrics
    allMetrics.addAll(AzureLogAnalyticsMetricsFactory.getDataFlowMetrics(status, instanceId));

    // connections process group level metrics
    final List<ConnectionStatus> connectionStatuses = new ArrayList<>();
    populateConnectionStatuses(status, connectionStatuses);
    for (ConnectionStatus connectionStatus : connectionStatuses) {
        allMetrics.addAll(AzureLogAnalyticsMetricsFactory.getConnectionStatusMetrics(connectionStatus, instanceId,
                processGroupName));
    }

    // processor level metrics
    final List<ProcessorStatus> processorStatuses = new ArrayList<>();
    populateProcessorStatuses(status, processorStatuses);
    for (final ProcessorStatus processorStatus : processorStatuses) {
        allMetrics.addAll(
                AzureLogAnalyticsMetricsFactory.getProcessorMetrics(processorStatus, instanceId, processGroupName));
    }

    if (jvmMetricsCollected) {
        allMetrics.addAll(
                AzureLogAnalyticsMetricsFactory.getJvmMetrics(virtualMachineMetrics, instanceId, JVM_JOB_NAME));

    }
    return allMetrics;
}
 
Example #21
Source File: ITReportLineageToAtlas.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void setConnectionName(ConnectionStatus c) {
    if (c.getSourceName() == null || c.getSourceName().isEmpty()) {
        c.setSourceName(componentNames.get(c.getSourceId()));
    }
    if (c.getDestinationName() == null || c.getDestinationName().isEmpty()) {
        c.setDestinationName(componentNames.get(c.getDestinationId()));
    }
}
 
Example #22
Source File: TestUnknownDataSet.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateFlowFile() {
    final String processorName = "GenerateFlowFile";
    final String processorId = "processor-1234";
    final ProvenanceEventRecord record = Mockito.mock(ProvenanceEventRecord.class);
    when(record.getComponentType()).thenReturn(processorName);
    when(record.getComponentId()).thenReturn(processorId);
    when(record.getEventType()).thenReturn(ProvenanceEventType.CREATE);

    final NamespaceResolvers namespaceResolvers = Mockito.mock(NamespaceResolvers.class);
    when(namespaceResolvers.fromHostNames(matches(".+\\.example\\.com"))).thenReturn("namespace1");

    final List<ConnectionStatus> connections = new ArrayList<>();

    final AnalysisContext context = Mockito.mock(AnalysisContext.class);
    when(context.getNamespaceResolver()).thenReturn(namespaceResolvers);
    when(context.findConnectionTo(processorId)).thenReturn(connections);
    when(context.getNiFiNamespace()).thenReturn("test_namespace");

    final NiFiProvenanceEventAnalyzer analyzer = NiFiProvenanceEventAnalyzerFactory.getAnalyzer(processorName, null, 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("nifi_data", ref.getTypeName());
    assertEquals("GenerateFlowFile", ref.get(ATTR_NAME));
    assertEquals("processor-1234@test_namespace", ref.get(ATTR_QUALIFIED_NAME));
}
 
Example #23
Source File: ComponentMetrics.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static boolean isEmpty(final ConnectionStatus status) {
    for (final ConnectionStatusDescriptor descriptor : ConnectionStatusDescriptor.values()) {
        final Long value = descriptor.getDescriptor().getValueFunction().getValue(status);
        if (value != null && value > 0) {
            return false;
        }
    }

    return true;
}
 
Example #24
Source File: TestNiFiRemotePort.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoteOutputPortHTTP() {
    final String componentType = "Remote Output Port";
    final String transitUri = "http://0.example.com:8080/nifi-api/data-transfer/output-ports/port-guid/transactions/tx-guid/flow-files";
    final ProvenanceEventRecord record = Mockito.mock(ProvenanceEventRecord.class);
    when(record.getComponentId()).thenReturn("port-guid");
    when(record.getComponentType()).thenReturn(componentType);
    when(record.getTransitUri()).thenReturn(transitUri);
    when(record.getEventType()).thenReturn(ProvenanceEventType.RECEIVE);

    final NamespaceResolvers namespaceResolvers = Mockito.mock(NamespaceResolvers.class);
    when(namespaceResolvers.fromHostNames(matches(".+\\.example\\.com"))).thenReturn("namespace1");

    final List<ConnectionStatus> connections = new ArrayList<>();
    final ConnectionStatus connection = new ConnectionStatus();
    connection.setSourceId("port-guid");
    connection.setSourceName("outputPortA");
    connections.add(connection);

    final AnalysisContext context = Mockito.mock(AnalysisContext.class);
    when(context.getNamespaceResolver()).thenReturn(namespaceResolvers);
    when(context.findConnectionFrom(matches("port-guid"))).thenReturn(connections);

    final NiFiProvenanceEventAnalyzer analyzer = NiFiProvenanceEventAnalyzerFactory.getAnalyzer(componentType, 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(TYPE_NIFI_OUTPUT_PORT, ref.getTypeName());
    assertEquals("outputPortA", ref.get(ATTR_NAME));
    assertEquals("port-guid@namespace1", ref.get(ATTR_QUALIFIED_NAME));
}
 
Example #25
Source File: TestNiFiRemotePort.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoteOutputPortRAW() {
    final String componentType = "Remote Output Port";
    // The UUID in a Transit Uri is a FlowFile UUID
    final String transitUri = "nifi://0.example.com:8081/232018cc-a147-40c6-b148-21f9f814e93c";
    final ProvenanceEventRecord record = Mockito.mock(ProvenanceEventRecord.class);
    // Component Id is an UUID of the RemoteGroupPort instance acting as a S2S client.
    when(record.getComponentId()).thenReturn("s2s-client-component-guid");
    when(record.getComponentType()).thenReturn(componentType);
    when(record.getTransitUri()).thenReturn(transitUri);
    when(record.getEventType()).thenReturn(ProvenanceEventType.RECEIVE);
    when(record.getAttribute(SiteToSiteAttributes.S2S_PORT_ID.key())).thenReturn("remote-port-guid");

    final NamespaceResolvers namespaceResolvers = Mockito.mock(NamespaceResolvers.class);
    when(namespaceResolvers.fromHostNames(matches(".+\\.example\\.com"))).thenReturn("namespace1");

    final List<ConnectionStatus> connections = new ArrayList<>();
    final ConnectionStatus connection = new ConnectionStatus();
    connection.setSourceId("s2s-client-component-guid");
    connection.setSourceName("outputPortA");
    connections.add(connection);

    final AnalysisContext context = Mockito.mock(AnalysisContext.class);
    when(context.getNamespaceResolver()).thenReturn(namespaceResolvers);
    when(context.findConnectionFrom(matches("s2s-client-component-guid"))).thenReturn(connections);

    final NiFiProvenanceEventAnalyzer analyzer = NiFiProvenanceEventAnalyzerFactory.getAnalyzer(componentType, 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(TYPE_NIFI_OUTPUT_PORT, ref.getTypeName());
    assertEquals("outputPortA", ref.get(ATTR_NAME));
    assertEquals("remote-port-guid@namespace1", ref.get(ATTR_QUALIFIED_NAME));
}
 
Example #26
Source File: TestNiFiRootGroupPort.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testInputPortHTTP() {
    final String componentType = "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 receiveEvent = Mockito.mock(ProvenanceEventRecord.class);
    when(receiveEvent.getEventId()).thenReturn(123L);
    when(receiveEvent.getComponentId()).thenReturn("port-guid");
    when(receiveEvent.getComponentType()).thenReturn(componentType);
    when(receiveEvent.getTransitUri()).thenReturn(transitUri);
    when(receiveEvent.getEventType()).thenReturn(ProvenanceEventType.RECEIVE);

    final NamespaceResolvers namespaceResolvers = Mockito.mock(NamespaceResolvers.class);
    when(namespaceResolvers.fromHostNames(matches(".+\\.example\\.com"))).thenReturn("namespace1");

    final List<ConnectionStatus> connections = new ArrayList<>();
    final ConnectionStatus connection = new ConnectionStatus();
    connection.setSourceId("port-guid");
    connection.setSourceName("inputPortA");
    connections.add(connection);

    final AnalysisContext context = Mockito.mock(AnalysisContext.class);
    when(context.getNamespaceResolver()).thenReturn(namespaceResolvers);
    when(context.findConnectionFrom(matches("port-guid"))).thenReturn(connections);

    final NiFiProvenanceEventAnalyzer analyzer = NiFiProvenanceEventAnalyzerFactory.getAnalyzer(componentType, transitUri, receiveEvent.getEventType());
    assertNotNull(analyzer);

    final DataSetRefs refs = analyzer.analyze(context, receiveEvent);
    assertEquals(1, refs.getInputs().size());
    assertEquals(0, refs.getOutputs().size());
    assertEquals(1, refs.getComponentIds().size());
    // Should report connected componentId.
    assertTrue(refs.getComponentIds().contains("port-guid"));

    Referenceable ref = refs.getInputs().iterator().next();
    assertEquals(TYPE_NIFI_INPUT_PORT, ref.getTypeName());
    assertEquals("inputPortA", ref.get(ATTR_NAME));
    assertEquals("port-guid@namespace1", ref.get(ATTR_QUALIFIED_NAME));
}
 
Example #27
Source File: TestNiFiRootGroupPort.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoteOutputPortHTTP() {
    final String componentType = "Output Port";
    final String transitUri = "http://0.example.com:8080/nifi-api/data-transfer/output-ports/port-guid/transactions/tx-guid/flow-files";
    final ProvenanceEventRecord sendEvent = Mockito.mock(ProvenanceEventRecord.class);
    when(sendEvent.getComponentId()).thenReturn("port-guid");
    when(sendEvent.getComponentType()).thenReturn(componentType);
    when(sendEvent.getTransitUri()).thenReturn(transitUri);
    when(sendEvent.getEventType()).thenReturn(ProvenanceEventType.SEND);

    final NamespaceResolvers namespaceResolvers = Mockito.mock(NamespaceResolvers.class);
    when(namespaceResolvers.fromHostNames(matches(".+\\.example\\.com"))).thenReturn("namespace1");

    final List<ConnectionStatus> connections = new ArrayList<>();
    final ConnectionStatus connection = new ConnectionStatus();
    connection.setDestinationId("port-guid");
    connection.setDestinationName("outputPortA");
    connections.add(connection);

    final AnalysisContext context = Mockito.mock(AnalysisContext.class);
    when(context.getNamespaceResolver()).thenReturn(namespaceResolvers);
    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());
    Referenceable ref = refs.getOutputs().iterator().next();
    assertEquals(TYPE_NIFI_OUTPUT_PORT, ref.getTypeName());
    assertEquals("outputPortA", ref.get(ATTR_NAME));
    assertEquals("port-guid@namespace1", ref.get(ATTR_QUALIFIED_NAME));
}
 
Example #28
Source File: TestNiFiRootGroupPort.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoteInputPortRAW() {
    final String componentType = "Input Port";
    // The UUID in a Transit Uri is a FlowFile UUID
    final String transitUri = "nifi://0.example.com:8081/580b7989-a80b-4089-b25b-3f5e0103af82";
    final ProvenanceEventRecord receiveEvent = Mockito.mock(ProvenanceEventRecord.class);
    when(receiveEvent.getEventId()).thenReturn(123L);
    when(receiveEvent.getComponentId()).thenReturn("port-guid");
    when(receiveEvent.getComponentType()).thenReturn(componentType);
    when(receiveEvent.getTransitUri()).thenReturn(transitUri);
    when(receiveEvent.getEventType()).thenReturn(ProvenanceEventType.RECEIVE);

    final NamespaceResolvers namespaceResolvers = Mockito.mock(NamespaceResolvers.class);
    when(namespaceResolvers.fromHostNames(matches(".+\\.example\\.com"))).thenReturn("namespace1");

    final List<ConnectionStatus> connections = new ArrayList<>();
    final ConnectionStatus connection = new ConnectionStatus();
    connection.setSourceId("port-guid");
    connection.setSourceName("inputPortA");
    connections.add(connection);

    final AnalysisContext context = Mockito.mock(AnalysisContext.class);
    when(context.getNamespaceResolver()).thenReturn(namespaceResolvers);
    when(context.findConnectionFrom(matches("port-guid"))).thenReturn(connections);

    final NiFiProvenanceEventAnalyzer analyzer = NiFiProvenanceEventAnalyzerFactory.getAnalyzer(componentType, transitUri, receiveEvent.getEventType());
    assertNotNull(analyzer);

    final DataSetRefs refs = analyzer.analyze(context, receiveEvent);
    assertEquals(1, refs.getInputs().size());
    assertEquals(0, refs.getOutputs().size());
    assertEquals(1, refs.getComponentIds().size());
    // Should report connected componentId.
    assertTrue(refs.getComponentIds().contains("port-guid"));

    Referenceable ref = refs.getInputs().iterator().next();
    assertEquals(TYPE_NIFI_INPUT_PORT, ref.getTypeName());
    assertEquals("inputPortA", ref.get(ATTR_NAME));
    assertEquals("port-guid@namespace1", ref.get(ATTR_QUALIFIED_NAME));
}
 
Example #29
Source File: TestNiFiRootGroupPort.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoteOutputPortRAW() {
    final String componentType = "Output Port";
    // The UUID in a Transit Uri is a FlowFile UUID
    final String transitUri = "nifi://0.example.com:8081/232018cc-a147-40c6-b148-21f9f814e93c";
    final ProvenanceEventRecord sendEvent = Mockito.mock(ProvenanceEventRecord.class);
    when(sendEvent.getComponentId()).thenReturn("port-guid");
    when(sendEvent.getComponentType()).thenReturn(componentType);
    when(sendEvent.getTransitUri()).thenReturn(transitUri);
    when(sendEvent.getEventType()).thenReturn(ProvenanceEventType.SEND);

    final NamespaceResolvers namespaceResolvers = Mockito.mock(NamespaceResolvers.class);
    when(namespaceResolvers.fromHostNames(matches(".+\\.example\\.com"))).thenReturn("namespace1");

    final List<ConnectionStatus> connections = new ArrayList<>();
    final ConnectionStatus connection = new ConnectionStatus();
    connection.setDestinationId("port-guid");
    connection.setDestinationName("outputPortA");
    connections.add(connection);

    final AnalysisContext context = Mockito.mock(AnalysisContext.class);
    when(context.getNamespaceResolver()).thenReturn(namespaceResolvers);
    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());
    Referenceable ref = refs.getOutputs().iterator().next();
    assertEquals(TYPE_NIFI_OUTPUT_PORT, ref.getTypeName());
    assertEquals("outputPortA", ref.get(ATTR_NAME));
    assertEquals("port-guid@namespace1", ref.get(ATTR_QUALIFIED_NAME));
}
 
Example #30
Source File: TestNiFiFlowAnalyzer.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void connect(ProcessGroupStatus pg0, Tuple<String, String> comp0, Tuple<String, String> comp1) {
    ConnectionStatus conn = new ConnectionStatus();
    conn.setId(nextComponentId());
    conn.setGroupId(pg0.getId());

    conn.setSourceId(comp0.getKey());
    conn.setSourceName(comp0.getValue());

    conn.setDestinationId(comp1.getKey());
    conn.setDestinationName(comp1.getValue());

    pg0.getConnectionStatus().add(conn);
}