Skip to content

Commit

Permalink
NIFI-12271 Fix PutAzureBlobStorage_v12 rollback on failure with FileR…
Browse files Browse the repository at this point in the history
…esourceService

This closes apache#7930

Signed-off-by: David Handermann <[email protected]>
  • Loading branch information
Lehel44 authored and exceptionfactory committed Oct 26, 2023
1 parent c4ff8de commit a3e4f89
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
final String blobName = context.getProperty(BLOB_NAME).evaluateAttributeExpressions(flowFile).getValue();
final AzureStorageConflictResolutionStrategy conflictResolution = AzureStorageConflictResolutionStrategy.valueOf(context.getProperty(CONFLICT_RESOLUTION).getValue());
final ResourceTransferSource resourceTransferSource = ResourceTransferSource.valueOf(context.getProperty(RESOURCE_TRANSFER_SOURCE).getValue());
final Optional<FileResource> fileResourceFound = getFileResource(resourceTransferSource, context, flowFile.getAttributes());

long startNanos = System.nanoTime();
try {
final Optional<FileResource> fileResourceFound = getFileResource(resourceTransferSource, context, flowFile.getAttributes());
BlobServiceClient storageClient = getStorageClient(context, flowFile);
BlobContainerClient containerClient = storageClient.getBlobContainerClient(containerName);
if (createContainer && !containerClient.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,31 @@ public void testPutBlobFromLocalFile() throws Exception {
assertProvenanceEvents();
}

@Test
public void testPutBlobFromNonExistentLocalFile() throws Exception {
String attributeName = "file.path";

String serviceId = FileResourceService.class.getSimpleName();
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);

String filePath = "nonexistent.txt";

Map<String, String> attributes = new HashMap<>();
attributes.put(attributeName, filePath);

runProcessor(EMPTY_CONTENT, attributes);

runner.assertAllFlowFilesTransferred(PutAzureBlobStorage_v12.REL_FAILURE, 1);

assertProvenanceEvents();
}


private void runProcessor(byte[] data) {
runProcessor(data, Collections.emptyMap());
Expand Down

0 comments on commit a3e4f89

Please sign in to comment.