This is an automated email from the ASF dual-hosted git repository.
szaszm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new 4f262dc7ea NIFI-13604 Python Source processors can be triggered
without creating new FlowFiles
4f262dc7ea is described below
commit 4f262dc7ea9f1ea169932dfd4addb85526d436a6
Author: Peter Gyori <[email protected]>
AuthorDate: Thu Aug 8 22:49:05 2024 +0200
NIFI-13604 Python Source processors can be triggered without creating new
FlowFiles
Closes #9159
Signed-off-by: Marton Szasz <[email protected]>
---
.../src/main/asciidoc/python-developer-guide.adoc | 2 ++
.../nifi/python/processor/FlowFileSourceProxy.java | 3 ++
.../PythonControllerInteractionIT.java | 10 +++++++
.../src/main/resources/extensions/CreateNothing.py | 32 ++++++++++++++++++++++
4 files changed, 47 insertions(+)
diff --git a/nifi-docs/src/main/asciidoc/python-developer-guide.adoc
b/nifi-docs/src/main/asciidoc/python-developer-guide.adoc
index e96ea33867..0bfd4368bd 100644
--- a/nifi-docs/src/main/asciidoc/python-developer-guide.adoc
+++ b/nifi-docs/src/main/asciidoc/python-developer-guide.adoc
@@ -323,6 +323,8 @@ Each processor based on the `FlowFileSource` API has a
`success` relationship an
created in the Processor's Python code. `attributes` and `contents` are both
optional. If `attributes` is not provided,
the FlowFile will still have the usual `filename`, `path` and `uuid`
attributes, but no additional ones.
If `contents` is not provided, a FlowFile with no contents (only attributes)
will be created.
+In case there is no useful information to return from the `create` method,
`return None` can be used instead of returning an
+empty `FlowFileSourceResult`. When `create` returns with `None`, the processor
does not produce any output.
diff --git
a/nifi-extension-bundles/nifi-py4j-bundle/nifi-py4j-bridge/src/main/java/org/apache/nifi/python/processor/FlowFileSourceProxy.java
b/nifi-extension-bundles/nifi-py4j-bundle/nifi-py4j-bridge/src/main/java/org/apache/nifi/python/processor/FlowFileSourceProxy.java
index f21c5c69b2..30b86e4408 100644
---
a/nifi-extension-bundles/nifi-py4j-bundle/nifi-py4j-bridge/src/main/java/org/apache/nifi/python/processor/FlowFileSourceProxy.java
+++
b/nifi-extension-bundles/nifi-py4j-bundle/nifi-py4j-bridge/src/main/java/org/apache/nifi/python/processor/FlowFileSourceProxy.java
@@ -49,6 +49,9 @@ public class FlowFileSourceProxy extends
PythonProcessorProxy<FlowFileSource> {
final FlowFileSourceResult result;
try {
result = getTransform().createFlowFile();
+ if (result == null) {
+ return;
+ }
} catch (final Py4JNetworkException e) {
throw new ProcessException("Failed to communicate with Python
Process", e);
} catch (final Exception e) {
diff --git
a/nifi-extension-bundles/nifi-py4j-bundle/nifi-py4j-integration-tests/src/test/java/org.apache.nifi.py4j/PythonControllerInteractionIT.java
b/nifi-extension-bundles/nifi-py4j-bundle/nifi-py4j-integration-tests/src/test/java/org.apache.nifi.py4j/PythonControllerInteractionIT.java
index adebe92a7f..39a1bb91eb 100644
---
a/nifi-extension-bundles/nifi-py4j-bundle/nifi-py4j-integration-tests/src/test/java/org.apache.nifi.py4j/PythonControllerInteractionIT.java
+++
b/nifi-extension-bundles/nifi-py4j-bundle/nifi-py4j-integration-tests/src/test/java/org.apache.nifi.py4j/PythonControllerInteractionIT.java
@@ -595,6 +595,16 @@ public class PythonControllerInteractionIT {
multiLineContent.getBytes(StandardCharsets.UTF_8));
}
+ @Test
+ public void testCreateNothing() {
+ // Test the use-case where the source processor returns with None.
+ final TestRunner runner = createProcessor("CreateNothing");
+ waitForValid(runner);
+ runner.run();
+
+ runner.assertTransferCount("success", 0);
+ }
+
public interface StringLookupService extends ControllerService {
Optional<String> lookup(Map<String, String> coordinates);
}
diff --git
a/nifi-extension-bundles/nifi-py4j-bundle/nifi-python-test-extensions/src/main/resources/extensions/CreateNothing.py
b/nifi-extension-bundles/nifi-py4j-bundle/nifi-python-test-extensions/src/main/resources/extensions/CreateNothing.py
new file mode 100644
index 0000000000..2ea3125ad2
--- /dev/null
+++
b/nifi-extension-bundles/nifi-py4j-bundle/nifi-python-test-extensions/src/main/resources/extensions/CreateNothing.py
@@ -0,0 +1,32 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from nifiapi.flowfilesource import FlowFileSource
+
+class CreateNothing(FlowFileSource):
+ class Java:
+ implements = ['org.apache.nifi.python.processor.FlowFileSource']
+
+ class ProcessorDetails:
+ version = '0.0.1-SNAPSHOT'
+ description = '''A Python processor for testing a use-case where the
Source processor
+ does not create any output.'''
+ tags = ['test', 'python', 'source']
+
+ def __init__(self, **kwargs):
+ pass
+
+ def create(self, context):
+ return None