-
-
Notifications
You must be signed in to change notification settings - Fork 8
docs: Add docs on how use custom Python processors #753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
647eca0
docs: Add docs on how use custom Python processors
sbernauer 366fc3f
remove sentence
sbernauer 0b76ecd
linter
sbernauer a1dcd60
Apply suggestions from code review
sbernauer e7d289f
Update docs/modules/nifi/pages/usage_guide/custom-components/custom-p…
sbernauer d92f4da
Update YAML comments
sbernauer a404661
Update docs/modules/nifi/pages/usage_guide/custom-components/custom-p…
sbernauer 110a26f
Switch from HelloWorldProcessor to CreateFlowFileProcessor
sbernauer ebb0a5b
Set content type to python
sbernauer 9a7e5be
Merge branch 'main' into docs/python-processors
sbernauer e8bf2b2
Update docs/modules/nifi/pages/usage_guide/custom-components/custom-p…
sbernauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
.../modules/nifi/pages/usage_guide/custom-components/custom-python-processors.adoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| = Custom Python processors | ||
|
|
||
| In NiFi 2.0 support for custom processors written in Python have been added. | ||
sbernauer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| The Stackable images already contain the needed tools, such as - obviously - a supported Python version. | ||
sbernauer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| == General configuration | ||
|
|
||
| [source,yaml] | ||
| ---- | ||
| spec: | ||
| nodes: | ||
| configOverrides: | ||
| nifi.properties: | ||
| nifi.python.command: python3 | ||
| # This property needs to be specified (otherwise a NullPointerException occurs) | ||
| nifi.python.working.directory: /nifi-python-working-directory | ||
| # This is needed to detect the Controller.py location (internally used by NiFi) | ||
| nifi.python.framework.source.directory: /stackable/nifi/python/framework/ | ||
| # This is the folder where the Python scripts are sourced from | ||
| # We need to get the Python files in here | ||
| nifi.python.extensions.source.directory.custom: /nifi-python-extensions | ||
siegfriedweber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ---- | ||
|
|
||
| == Getting Python scripts into NiFi | ||
|
|
||
| TIP: NiFi should hot-reload the Python scripts. You might need to refresh your browser window to see the new processor. | ||
|
|
||
| [#configmap] | ||
| === 1. Mount as ConfigMap | ||
|
|
||
| The easiest way is defining a ConfigMap as follows and mount that. | ||
sbernauer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
sbernauer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| This way the Python processors are stored and versioned alongside your NiFiCluster itself. | ||
sbernauer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| [source,yaml] | ||
| ---- | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: nifi-python-extensions | ||
| data: | ||
| HelloWorldProcessor.py: | | ||
| from nifiapi.flowfiletransform import FlowFileTransform, FlowFileTransformResult | ||
|
|
||
| class WriteHelloWorld(FlowFileTransform): | ||
| class Java: | ||
| implements = ['org.apache.nifi.python.processor.FlowFileTransform'] | ||
| class ProcessorDetails: | ||
| version = '0.0.1-SNAPSHOT' | ||
|
|
||
| def __init__(self, **kwargs): | ||
| pass | ||
|
|
||
| def transform(self, context, flowfile): | ||
| return FlowFileTransformResult(relationship = "success", contents = "Hello World", attributes = {"greeting": "hello"}) | ||
siegfriedweber marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ---- | ||
|
|
||
| You can add multiple Python scripts in the ConfigMap. | ||
| Afterwards we need to mount the Python scripts into `/nifi-python-extensions`: | ||
|
|
||
| [source,yaml] | ||
| ---- | ||
| spec: | ||
| nodes: | ||
| podOverrides: | ||
| spec: | ||
| containers: | ||
| - name: nifi | ||
| volumeMounts: | ||
| - name: nifi-python-extensions | ||
| mountPath: /nifi-python-extensions | ||
| - name: nifi-python-working-directory | ||
| mountPath: /nifi-python-working-directory | ||
| volumes: | ||
| - name: nifi-python-extensions | ||
| configMap: | ||
| name: nifi-python-extensions | ||
| - name: nifi-python-working-directory | ||
| emptyDir: {} | ||
| ---- | ||
|
|
||
| [#git-sync] | ||
| === 2. Use git-sync | ||
siegfriedweber marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| As an alternative you can use `git-sync` to keep your Python processors up to date. | ||
| You need to add a sidecar using podOverrides that syncs into a shared volume between the `nifi` and `git-sync` container. | ||
|
|
||
| The following snippet can serve as a starting point (the Git repo has the folder `processors` with the Python scripts inside). | ||
|
|
||
| [source,yaml] | ||
| ---- | ||
| spec: | ||
| nodes: | ||
| podOverrides: | ||
| spec: | ||
| containers: | ||
| - name: nifi | ||
| volumeMounts: | ||
| - name: nifi-python-extensions | ||
| mountPath: /nifi-python-extensions | ||
| - name: nifi-python-working-directory | ||
| mountPath: /nifi-python-working-directory | ||
| - name: git-sync | ||
| image: registry.k8s.io/git-sync/git-sync:v4.2.3 | ||
| args: | ||
| - --repo=https://github.com/stackabletech/nifi-talk | ||
| - --root=/nifi-python-extensions | ||
| - --period=10s | ||
| volumeMounts: | ||
| - name: nifi-python-extensions | ||
| mountPath: /nifi-python-extensions | ||
| volumes: | ||
| - name: nifi-python-extensions | ||
| emptyDir: {} | ||
| - name: nifi-python-working-directory | ||
| emptyDir: {} | ||
| ---- | ||
|
|
||
| Afterwards you need to update your source directory (you added previously) accordingly to point into the Git subfolder you have. | ||
sbernauer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| [source,yaml] | ||
| ---- | ||
| spec: | ||
| nodes: | ||
| configOverrides: | ||
| nifi.properties: | ||
| # Replace the property from the previous step | ||
| # Format is /nifi-python-extensions/<git-repo-name>/<git-folder>/ | ||
| nifi.python.extensions.source.directory.custom: /nifi-python-extensions/nifi-talk/processors/ | ||
sbernauer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ---- | ||
|
|
||
| === 3. Use PersistentVolume | ||
|
|
||
| You can also mount a PVC below `/nifi-python-extensions` using podOverrides and shell into the NiFi Pod to make changes. | ||
| However, the <<configmap>> or <<git-sync>> approach is recommended. | ||
|
|
||
| == Check processors have been loaded | ||
|
|
||
| NiFi logs every Python processor it found. | ||
| You can use that to check if the processors have been loaded. | ||
|
|
||
| [source,console] | ||
| ---- | ||
| $ kubectl logs nifi-2-0-0-node-default-0 -c nifi | grep -P 'Discovered Python Processor|Discovered or updated [0-9]+ Python Processors' | ||
| 2025-02-14 14:40:20,694 INFO [main] o.a.n.n.StandardExtensionDiscoveringManager Discovered Python Processor PythonZgrepProcessor | ||
| 2025-02-14 14:40:20,697 INFO [main] o.a.n.n.StandardExtensionDiscoveringManager Discovered Python Processor TransformOpenskyStates | ||
| 2025-02-14 14:40:20,700 INFO [main] o.a.n.n.StandardExtensionDiscoveringManager Discovered Python Processor UpdateAttributeFileLookup | ||
| 2025-02-14 14:40:20,700 INFO [main] o.a.n.n.StandardExtensionDiscoveringManager Discovered or updated 3 Python Processors in 60 millis | ||
sbernauer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ---- | ||
9 changes: 9 additions & 0 deletions
9
docs/modules/nifi/pages/usage_guide/custom-components/index.adoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| = Loading custom components | ||
| :description: Load custom NiFi components for enhanced functionality. | ||
|
|
||
| You can develop or use custom components for Apache NiFi, typically custom processors, to extend its functionality. | ||
|
|
||
| There are currently two types of custom components: | ||
|
|
||
| 1. xref:nifi:usage_guide/custom-components/custom-nars.adoc[] | ||
| 2. Starting with NiFi 2.0 you can also use xref:nifi:usage_guide/custom-components/custom-python-processors.adoc[] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.