Skip to content

MINIFICPP-2928 Add PutOPCFile processor - #2289

Open
lordgamez wants to merge 3 commits into
apache:MINIFICPP-2927from
lordgamez:MINIFICPP-2928
Open

lordgamez wants to merge 3 commits into
apache:MINIFICPP-2927from
lordgamez:MINIFICPP-2928

Conversation

@lordgamez

@lordgamez lordgamez commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/MINIFICPP-2928

Depends on #2287


Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.

In order to streamline the review of the contribution we ask you to ensure the following steps have been taken:

For all changes:

  • Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?

  • Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.

  • Has your PR been rebased against the latest commit within the target branch (typically main)?

  • Is your initial contribution a single, squashed commit?

For code changes:

  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE file?
  • If applicable, have you updated the NOTICE file?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

Note:

Please ensure that once the PR is submitted, you check GitHub Actions CI results for build issues and submit an update to your PR as soon as possible.

@lordgamez
lordgamez requested a balanced review from Copilot November 9, 2026 14:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

4 open issues
What changed in this PR

Adds OPC UA file upload support by introducing the new PutOPCFile processor and extending the existing OPC UA file transfer/test infrastructure to support writing, file creation, and improved browse/path resolution.

Changes:

  • Introduces PutOPCFile processor (overwrite/append, optional create-under-parent behavior) and documents it.
  • Extends OPC UA file transfer support (RemoteFile::write, CreateFile support) and improves browse/path resolution helpers.
  • Expands test coverage: new PutOPCFile unit tests, updated integration feature scenarios, and enhanced test servers.
File Description
extensions/​opc/​src/​PutOPCFile.cpp Implements the new PutOPCFile processor logic (resolve/create target file, write via OPC UA file methods).
extensions/​opc/​include/​PutOPCFile.h Declares processor properties/relationships/output attributes for PutOPCFile.
extensions/​opc/​tests/​PutOPCFileTests.cpp Adds comprehensive unit tests for PutOPCFile behavior (overwrite/append/create/error cases).
extensions/​opc/​src/​OPCFileTransfer.cpp Adds RemoteFile write support and CreateFile invocation helper; centralizes chunk sizing.
extensions/​opc/​include/​OPCFileTransfer.h Extends RemoteFile API with write() and adds createFileInDirectory() declaration.
extensions/​opc/​src/​OPCCommon.cpp Adds browse-with-pagination helper (findObjectChildByName) and renames child lookup to qualified-name variant.
extensions/​opc/​include/​OPCCommon.h Exposes new/renamed client browse helper APIs.
extensions/​opc/​src/​BaseOPCProcessor.cpp Centralizes path resolution and “target node” resolution logic for reuse across processors.
extensions/​opc/​include/​BaseOPCProcessor.h Adds shared resolvePathNode()/resolveTargetNode() helpers and supporting structs.
extensions/​opc/​src/​FetchOPCFile.cpp Refactors to use shared path resolution and new RemoteFile chunk sizing API.
extensions/​opc/​include/​FetchOPCFile.h Updates cached file state to align with RemoteFile-managed chunk sizing.
extensions/​opc/​src/​PutOPCProcessor.cpp Refactors target-node resolution to use new BaseOPCProcessor helper and updates logging.
extensions/​opc/​include/​PutOPCProcessor.h Removes now-redundant private resolution helpers (moved to BaseOPCProcessor).
extensions/​opc/​src/​FetchOPCHistory.cpp Refactors to use shared path resolution and updated error logging.
extensions/​opc/​src/​FetchOPCEvents.cpp Refactors to use shared path resolution and updated error logging.
extensions/​opc/​tests/​PutOPCProcessorTests.cpp Updates assertions to match revised/standardized error messages.
extensions/​opc/​tests/​FetchOPCFileTests.cpp Updates assertion to match revised file-node path resolution error message.
extensions/​opc/​tests/​FetchOPCEventsTests.cpp Updates assertions to match revised path translation/multi-node error messages.
extensions/​opc/​tests/​OpcUaTestServer.h Extends test server with FileType Write support, CreateFile support, paging controls, and file content accessors.
extensions/​opc/​tests/​features/​opcua_file_transfer.feature Adds BDD scenarios for creating/overwriting/appending files via PutOPCFile.
extensions/​opc/​tests/​features/​steps/​steps.py Adds new step to assert file server file content within a timeout.
extensions/​opc/​tests/​features/​containers/​opc_ua_file_server_container.py Adds helper to validate server-side file content.
extensions/​opc/​tests/​features/​resources/​opcua-file-server/​file_server.cpp Extends OPC UA file server for writable files and CreateFile/Write methods.
PROCESSORS.md Documents PutOPCFile properties/relationships/output attributes.
.github/​references/​docker_manifest.json Registers PutOPCFile in the processor manifest for tooling/docs.

Review effort: Lite

Comment thread extensions/opc/src/PutOPCFile.cpp Resolved
Comment thread extensions/opc/src/BaseOPCProcessor.cpp Resolved
@szaszm
szaszm self-requested a review November 12, 2026 14:44

@szaszm szaszm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if we could use RAII wrappers for all OPC-UA library types. During a manual review, I didn't spot any leaks, but having the compiler prove it would be more reassuring. On the other hand, the RAII wrapper types may introduce a lot of boilerplate, so it's up to you if you think it's worth it.

if (std::filesystem::exists(path, error)) {
return UA_STATUSCODE_BADBROWSENAMEDUPLICATED;
}
if (!std::ofstream(path, std::ios::binary)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change this to clarify the meaning. {} makes it clear that this is indended to be a temporary object, not a function call, and the comment further clarifies the purpose.

Suggested change
if (!std::ofstream(path, std::ios::binary)) {
// create empty file
if (!std::ofstream{path, std::ios::binary}) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 9346f9d

UA_NODEID_NUMERIC(0, UA_NS0ID_FILEDIRECTORYTYPE),
attr,
nullptr,
const_cast<std::filesystem::path*>(&data_dir),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment explaining why this const_cast is safe in practice?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment in 9346f9d

Comment thread extensions/opc/src/OPCCommon.cpp Outdated
std::swap(continuation_point, result.continuationPoint);
for (size_t i = 0; i < result.referencesSize; ++i) {
const auto& ref = result.references[i];
if (std::string_view(reinterpret_cast<const char*>(ref.browseName.name.data), ref.browseName.name.length) == browse_name) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd extract ref.browseName.name too, with a type if possible, to make future changes less error-prone. (the two long distance references shouldn't be able to drift from each other)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, updated in 9346f9d

Comment thread extensions/opc/src/OPCCommon.cpp Outdated
Comment on lines +550 to +553
const auto guard = gsl::finally([&browse_request, &browse_response]() {
UA_BrowseRequest_clear(&browse_request);
UA_BrowseResponse_clear(&browse_response);
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we separate the two cleanup guards, to avoid possible future cases where an error between the two initializations cause the resources of one to be leaked?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good idea, updated in 9346f9d

@lordgamez

Copy link
Copy Markdown
Contributor Author

It would be nice if we could use RAII wrappers for all OPC-UA library types. During a manual review, I didn't spot any leaks, but having the compiler prove it would be more reassuring. On the other hand, the RAII wrapper types may introduce a lot of boilerplate, so it's up to you if you think it's worth it.

I think it's a good idea and worth the the effort, we can investigate how much boilerplate would it add, but if it's manageable it's worth implementing. I would handle this improvement separately, so I added a jira ticket for this: https://issues.apache.org/jira/browse/MINIFICPP-2950

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants