You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "shubhluck (via GitHub)" <gi...@apache.org> on 2026/07/30 20:07:51 UTC
[PR] NIFI-16159 Add support for FileResourceService in PutFile [nifi]
shubhluck opened a new pull request, #11495:
URL: https://github.com/apache/nifi/pull/11495
<!-- 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. -->
# Summary
[NIFI-16159](https://issues.apache.org/jira/browse/NIFI-16159)
Add support for `FileResourceService` in `PutFile`, matching the `Resource Transfer Source` / `File Resource Service` pattern already available in `PutS3Object` (NIFI-12642), `PutGCSObject` (NIFI-12643), and `PutHDFS` (NIFI-12801).
`PutFile` currently writes only the incoming FlowFile's content to the destination directory. Users who want to stage a file already on the local filesystem (or reachable via a custom `FileResourceService` implementation) have to first pull it into a FlowFile with `FetchFile`/`GetFile`, which is wasteful for large local files.
**Changes**
- Add `Resource Transfer Source` and `File Resource Service` property descriptors to `PutFile`, reusing `ResourceTransferProperties` from `nifi-resource-transfer`.
- When `Resource Transfer Source = File Resource Service`, obtain a `FileResource` via `ResourceTransferUtils.getFileResource(...)` and stream its `InputStream` to the `.<filename>` temp file with `StandardCopyOption.REPLACE_EXISTING` (preserving the overwrite semantics of the original `session.exportTo(...)` call), then proceed with the existing rename / permissions / owner / group / lastModified logic.
- When `Resource Transfer Source = FlowFile Content` (default) the behavior is byte-identical to today.
- Add `nifi-resource-transfer` and `nifi-file-resource-service-api` (compile) and `nifi-file-resource-service` (test) to `nifi-standard-processors/pom.xml`.
- Add `TestPutFile#testPutFileFromLocalFile` covering the `FileResourceService` path using `StandardFileResourceService`.
**Backward compatibility**
`Resource Transfer Source` defaults to `FlowFile Content`, so existing flows are unaffected. `File Resource Service` only appears in the UI when the source is set to `File Resource Service` (declared via `dependsOn`).
# Tracking
Please complete the following tracking steps prior to pull request creation.
### Issue Tracking
- [x] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
### Pull Request Tracking
- [x] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
- [x] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
- [x] Pull request contains [commits signed](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits) with a registered key indicating `Verified` status
### Pull Request Formatting
- [x] Pull Request based on current revision of the `main` branch
- [x] Pull Request refers to a feature branch with one commit containing changes
# Verification
Please indicate the verification steps performed prior to pull request creation.
### Build
- [ ] Build completed using `./mvnw clean install -P contrib-check`
- [ ] JDK 21
- [ ] JDK 25
### Licensing
- [x] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
- [x] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
### Documentation
- [x] Documentation formatting appears as expected in rendered files
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-16159 Add support for FileResourceService in PutFile [nifi]
Posted by "shubhluck (via GitHub)" <gi...@apache.org>.
shubhluck commented on code in PR #11495:
URL: https://github.com/apache/nifi/pull/11495#discussion_r3888037360
##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml:
##########
@@ -38,6 +38,21 @@
<artifactId>nifi-standard-record-utils</artifactId>
<version>2.11.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-resource-transfer</artifactId>
+ <version>2.11.0-SNAPSHOT</version>
Review Comment:
Bumped to 2.12.0-SNAPSHOT.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-16159 Add support for FileResourceService in PutFile [nifi]
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on code in PR #11495:
URL: https://github.com/apache/nifi/pull/11495#discussion_r3887802221
##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml:
##########
@@ -38,6 +38,21 @@
<artifactId>nifi-standard-record-utils</artifactId>
<version>2.11.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-resource-transfer</artifactId>
+ <version>2.11.0-SNAPSHOT</version>
Review Comment:
The versions should be updated to `2.12.0-SNAPSHOT`.
##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutFile.java:
##########
@@ -244,6 +249,42 @@ public void testReplaceAndMaxFileLimitReach() throws IOException {
assertEquals("Another file", new String(content));
}
+ @Test
+ public void testPutFileFromLocalFile() throws Exception {
+ final TestRunner runner = TestRunners.newTestRunner(new PutFile());
+ runner.setProperty(PutFile.DIRECTORY, targetDir.getAbsolutePath());
+ runner.setProperty(PutFile.CONFLICT_RESOLUTION, PutFile.REPLACE_RESOLUTION);
+
+ final String attributeName = "file.path";
+ final String serviceId = FileResourceService.class.getSimpleName();
+ final FileResourceService service = new StandardFileResourceService();
+ runner.addControllerService(serviceId, service);
+ runner.setProperty(service, StandardFileResourceService.FILE_PATH, String.format("${%s}", attributeName));
+ runner.enableControllerService(service);
+
+ runner.setProperty(ResourceTransferProperties.RESOURCE_TRANSFER_SOURCE, ResourceTransferSource.FILE_RESOURCE_SERVICE.getValue());
+ runner.setProperty(ResourceTransferProperties.FILE_RESOURCE_SERVICE, serviceId);
+
+ final byte[] fileData = "0123456789".getBytes(StandardCharsets.UTF_8);
+ final Path tempFilePath = Files.createTempFile("PutFile_testPutFileFromLocalFile_", "");
Review Comment:
This approach can leave files in the temporary directory. The JUnit TempDir annotation should be used to wire in a directory to the test method instead.
##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutFile.java:
##########
@@ -304,7 +315,16 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
}
}
- session.exportTo(flowFile, dotCopyFile, false);
+ final ResourceTransferSource resourceTransferSource = ResourceTransferSource.valueOf(
+ context.getProperty(RESOURCE_TRANSFER_SOURCE).getValue());
+ final Optional<FileResource> fileResource = getFileResource(resourceTransferSource, context, flowFile.getAttributes());
Review Comment:
This should use `asAllowableValue()` instead of `ResourceTransferSource.valueOf()`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-16159 Add support for FileResourceService in PutFile [nifi]
Posted by "shubhluck (via GitHub)" <gi...@apache.org>.
shubhluck commented on code in PR #11495:
URL: https://github.com/apache/nifi/pull/11495#discussion_r3888036175
##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutFile.java:
##########
@@ -304,7 +315,16 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
}
}
- session.exportTo(flowFile, dotCopyFile, false);
+ final ResourceTransferSource resourceTransferSource = ResourceTransferSource.valueOf(
+ context.getProperty(RESOURCE_TRANSFER_SOURCE).getValue());
+ final Optional<FileResource> fileResource = getFileResource(resourceTransferSource, context, flowFile.getAttributes());
Review Comment:
Fixed as suggested switched to asAllowableValue
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-16159 Add support for FileResourceService in PutFile [nifi]
Posted by "shubhluck (via GitHub)" <gi...@apache.org>.
shubhluck commented on code in PR #11495:
URL: https://github.com/apache/nifi/pull/11495#discussion_r3888037982
##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutFile.java:
##########
@@ -244,6 +249,42 @@ public void testReplaceAndMaxFileLimitReach() throws IOException {
assertEquals("Another file", new String(content));
}
+ @Test
+ public void testPutFileFromLocalFile() throws Exception {
+ final TestRunner runner = TestRunners.newTestRunner(new PutFile());
+ runner.setProperty(PutFile.DIRECTORY, targetDir.getAbsolutePath());
+ runner.setProperty(PutFile.CONFLICT_RESOLUTION, PutFile.REPLACE_RESOLUTION);
+
+ final String attributeName = "file.path";
+ final String serviceId = FileResourceService.class.getSimpleName();
+ final FileResourceService service = new StandardFileResourceService();
+ runner.addControllerService(serviceId, service);
+ runner.setProperty(service, StandardFileResourceService.FILE_PATH, String.format("${%s}", attributeName));
+ runner.enableControllerService(service);
+
+ runner.setProperty(ResourceTransferProperties.RESOURCE_TRANSFER_SOURCE, ResourceTransferSource.FILE_RESOURCE_SERVICE.getValue());
+ runner.setProperty(ResourceTransferProperties.FILE_RESOURCE_SERVICE, serviceId);
+
+ final byte[] fileData = "0123456789".getBytes(StandardCharsets.UTF_8);
+ final Path tempFilePath = Files.createTempFile("PutFile_testPutFileFromLocalFile_", "");
Review Comment:
Switched to a @TempDir Path sourceDir method parameter and dropped the try/finally cleanup
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-16159 Add support for FileResourceService in PutFile [nifi]
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory merged PR #11495:
URL: https://github.com/apache/nifi/pull/11495
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-16159 Add support for FileResourceService in PutFile [nifi]
Posted by "shubhluck (via GitHub)" <gi...@apache.org>.
shubhluck commented on PR #11495:
URL: https://github.com/apache/nifi/pull/11495#issuecomment-5164733631
The `TestSocketLoadBalancedFlowFileQueue.testGetQueueSnapshotIncludesRebalancingPartition` failure on the JDK 21 EN leg is unrelated to this change (which only touches nifi-standard-processors/PutFile). The other three matrix legs passed. Looks like a flaky test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org