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);
}
});
}
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);
}
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);
}
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);
}
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);
}
Aggregations