Search in sources :

Example 6 with ProcessorStatus

use of org.apache.nifi.controller.status.ProcessorStatus in project nifi by apache.

the class NiFiFlowAnalyzer method analyzePaths.

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);
        }
    });
}
Also used : Logger(org.slf4j.Logger) ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) Tuple(org.apache.nifi.util.Tuple) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Map(java.util.Map) ConnectionStatus(org.apache.nifi.controller.status.ConnectionStatus) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) Collections(java.util.Collections) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) ArrayList(java.util.ArrayList) List(java.util.List) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus)

Example 7 with ProcessorStatus

use of org.apache.nifi.controller.status.ProcessorStatus in project nifi by apache.

the class TestNiFiFlowAnalyzer method testMultiPathsJoint.

@Test
public void testMultiPathsJoint() throws Exception {
    ProcessGroupStatus rootPG = createEmptyProcessGroupStatus();
    final ProcessorStatus pr0 = createProcessor(rootPG, "org.apache.nifi.processors.standard.GenerateFlowFile");
    final ProcessorStatus pr1 = createProcessor(rootPG, "org.apache.nifi.processors.standard.UpdateAttribute");
    final ProcessorStatus pr2 = createProcessor(rootPG, "org.apache.nifi.processors.standard.ListenTCP");
    final ProcessorStatus pr3 = createProcessor(rootPG, "org.apache.nifi.processors.standard.LogAttribute");
    // Result should be as follows:
    // pathA = 0 -> 1 (-> 3)
    // pathB = 2 (-> 3)
    // pathC = 3
    connect(rootPG, pr0, pr1);
    connect(rootPG, pr1, pr3);
    connect(rootPG, pr2, pr3);
    final NiFiFlowAnalyzer analyzer = new NiFiFlowAnalyzer();
    final NiFiFlow nifiFlow = new NiFiFlow(rootPG.getId());
    nifiFlow.setClusterName("cluster1");
    analyzer.analyzeProcessGroup(nifiFlow, rootPG);
    assertEquals(4, nifiFlow.getProcessors().size());
    analyzer.analyzePaths(nifiFlow);
    final Map<String, NiFiFlowPath> paths = nifiFlow.getFlowPaths();
    assertEquals(3, paths.size());
    // Order is not guaranteed
    final NiFiFlowPath pathA = paths.get(pr0.getId());
    final NiFiFlowPath pathB = paths.get(pr2.getId());
    final NiFiFlowPath pathC = paths.get(pr3.getId());
    assertEquals(2, pathA.getProcessComponentIds().size());
    assertEquals(1, pathB.getProcessComponentIds().size());
    assertEquals(1, pathC.getProcessComponentIds().size());
    // A queue is added as input for the joint point.
    assertEquals(1, pathC.getInputs().size());
    final AtlasObjectId queue = pathC.getInputs().iterator().next();
    assertEquals(TYPE_NIFI_QUEUE, queue.getTypeName());
    assertEquals(toQualifiedName("cluster1", pathC.getId()), queue.getUniqueAttributes().get(ATTR_QUALIFIED_NAME));
    // Should be able to find a path from a given processor GUID.
    final NiFiFlowPath pathForPr0 = nifiFlow.findPath(pr0.getId());
    final NiFiFlowPath pathForPr1 = nifiFlow.findPath(pr1.getId());
    final NiFiFlowPath pathForPr2 = nifiFlow.findPath(pr2.getId());
    final NiFiFlowPath pathForPr3 = nifiFlow.findPath(pr3.getId());
    assertEquals(pathA, pathForPr0);
    assertEquals(pathA, pathForPr1);
    assertEquals(pathB, pathForPr2);
    assertEquals(pathC, pathForPr3);
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) Test(org.junit.Test)

Example 8 with ProcessorStatus

use of org.apache.nifi.controller.status.ProcessorStatus in project nifi by apache.

the class TestNiFiFlowAnalyzer method testMultiPaths.

@Test
public void testMultiPaths() throws Exception {
    ProcessGroupStatus rootPG = createEmptyProcessGroupStatus();
    final ProcessorStatus pr0 = createProcessor(rootPG, "GenerateFlowFile");
    final ProcessorStatus pr1 = createProcessor(rootPG, "UpdateAttribute");
    final ProcessorStatus pr2 = createProcessor(rootPG, "ListenTCP");
    final ProcessorStatus pr3 = createProcessor(rootPG, "LogAttribute");
    connect(rootPG, pr0, pr1);
    connect(rootPG, pr2, pr3);
    final NiFiFlowAnalyzer analyzer = new NiFiFlowAnalyzer();
    final NiFiFlow nifiFlow = new NiFiFlow(rootPG.getId());
    analyzer.analyzeProcessGroup(nifiFlow, rootPG);
    assertEquals(4, nifiFlow.getProcessors().size());
    analyzer.analyzePaths(nifiFlow);
    final Map<String, NiFiFlowPath> paths = nifiFlow.getFlowPaths();
    assertEquals(2, paths.size());
    // Order is not guaranteed
    final NiFiFlowPath pathA = paths.get(pr0.getId());
    final NiFiFlowPath pathB = paths.get(pr2.getId());
    assertEquals(2, pathA.getProcessComponentIds().size());
    assertEquals(2, pathB.getProcessComponentIds().size());
    // Should be able to find a path from a given processor GUID.
    final NiFiFlowPath pathForPr0 = nifiFlow.findPath(pr0.getId());
    final NiFiFlowPath pathForPr1 = nifiFlow.findPath(pr1.getId());
    final NiFiFlowPath pathForPr2 = nifiFlow.findPath(pr2.getId());
    final NiFiFlowPath pathForPr3 = nifiFlow.findPath(pr3.getId());
    assertEquals(pathA, pathForPr0);
    assertEquals(pathA, pathForPr1);
    assertEquals(pathB, pathForPr2);
    assertEquals(pathB, pathForPr3);
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) Test(org.junit.Test)

Example 9 with ProcessorStatus

use of org.apache.nifi.controller.status.ProcessorStatus in project nifi by apache.

the class TestNiFiFlowAnalyzer method testSingleProcessor.

@Test
public void testSingleProcessor() throws Exception {
    ProcessGroupStatus rootPG = createEmptyProcessGroupStatus();
    final ProcessorStatus pr0 = createProcessor(rootPG, "GenerateFlowFile");
    final NiFiFlowAnalyzer analyzer = new NiFiFlowAnalyzer();
    final NiFiFlow nifiFlow = new NiFiFlow(rootPG.getId());
    analyzer.analyzeProcessGroup(nifiFlow, rootPG);
    assertEquals(1, nifiFlow.getProcessors().size());
    analyzer.analyzePaths(nifiFlow);
    final Map<String, NiFiFlowPath> paths = nifiFlow.getFlowPaths();
    assertEquals(1, paths.size());
    // first path
    final NiFiFlowPath path0 = paths.get(pr0.getId());
    assertEquals(path0.getId(), path0.getProcessComponentIds().get(0));
    assertEquals(rootPG.getId(), path0.getGroupId());
    // Should be able to find a path from a given processor GUID.
    final NiFiFlowPath pathForPr0 = nifiFlow.findPath(pr0.getId());
    assertEquals(path0, pathForPr0);
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) Test(org.junit.Test)

Example 10 with ProcessorStatus

use of org.apache.nifi.controller.status.ProcessorStatus in project nifi by apache.

the class TestNiFiFlowAnalyzer method testProcessorsWithinSinglePath.

@Test
public void testProcessorsWithinSinglePath() throws Exception {
    ProcessGroupStatus rootPG = createEmptyProcessGroupStatus();
    final ProcessorStatus pr0 = createProcessor(rootPG, "GenerateFlowFile");
    final ProcessorStatus pr1 = createProcessor(rootPG, "UpdateAttribute");
    connect(rootPG, pr0, pr1);
    final NiFiFlowAnalyzer analyzer = new NiFiFlowAnalyzer();
    final NiFiFlow nifiFlow = new NiFiFlow(rootPG.getId());
    analyzer.analyzeProcessGroup(nifiFlow, rootPG);
    assertEquals(2, nifiFlow.getProcessors().size());
    analyzer.analyzePaths(nifiFlow);
    final Map<String, NiFiFlowPath> paths = nifiFlow.getFlowPaths();
    assertEquals(1, paths.size());
    // Should be able to find a path from a given processor GUID.
    final NiFiFlowPath pathForPr0 = nifiFlow.findPath(pr0.getId());
    final NiFiFlowPath pathForPr1 = nifiFlow.findPath(pr1.getId());
    final NiFiFlowPath path0 = paths.get(pr0.getId());
    assertEquals(path0, pathForPr0);
    assertEquals(path0, pathForPr1);
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) Test(org.junit.Test)

Aggregations

ProcessorStatus (org.apache.nifi.controller.status.ProcessorStatus)31 ProcessGroupStatus (org.apache.nifi.controller.status.ProcessGroupStatus)21 ArrayList (java.util.ArrayList)18 ConnectionStatus (org.apache.nifi.controller.status.ConnectionStatus)12 PortStatus (org.apache.nifi.controller.status.PortStatus)9 RemoteProcessGroupStatus (org.apache.nifi.controller.status.RemoteProcessGroupStatus)9 Test (org.junit.Test)9 List (java.util.List)6 Map (java.util.Map)6 ProcessorNode (org.apache.nifi.controller.ProcessorNode)6 ProcessGroup (org.apache.nifi.groups.ProcessGroup)6 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)6 HashMap (java.util.HashMap)5 Set (java.util.Set)5 ValidationResult (org.apache.nifi.components.ValidationResult)5 Collection (java.util.Collection)4 Collections (java.util.Collections)4 Date (java.util.Date)4 LinkedHashMap (java.util.LinkedHashMap)4 LinkedHashSet (java.util.LinkedHashSet)4