Skip to content

Commit

Permalink
NIFI-7794 Adding a property to PutAzureStorageBlob to determine wheth…
Browse files Browse the repository at this point in the history
…er to check the existence of a container and create it if necessary.

This closes #4535.

Signed-off-by: Joey Frazee <jfrazee@apache.org>
  • Loading branch information
pkelly-nifi authored and joewitt committed Sep 22, 2020
1 parent 52f219b commit 1fb8bc3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,25 @@ public class PutAzureBlobStorage extends AbstractAzureBlobProcessor {
.required(true)
.build();

public static final PropertyDescriptor CREATE_CONTAINER = new PropertyDescriptor.Builder()
.name("azure-create-container")
.displayName("Create Container")
.expressionLanguageSupported(ExpressionLanguageScope.NONE)
.required(true)
.addValidator(StandardValidators.BOOLEAN_VALIDATOR)
.allowableValues("true", "false")
.defaultValue("false")
.description("Specifies whether to check if the container exists and to automatically create it if it does not. " +
"Permission to list containers is required. If false, this check is not made, but the Put operation " +
"will fail if the container does not exist.")
.build();

@Override
public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
List<PropertyDescriptor> properties = new ArrayList<>(super.getSupportedPropertyDescriptors());
properties.remove(BLOB);
properties.add(BLOB_NAME);
properties.add(CREATE_CONTAINER);
return properties;
}

Expand All @@ -93,11 +107,15 @@ public void onTrigger(final ProcessContext context, final ProcessSession session

String blobPath = context.getProperty(BLOB_NAME).evaluateAttributeExpressions(flowFile).getValue();

final boolean createContainer = context.getProperty(CREATE_CONTAINER).asBoolean();

AtomicReference<Exception> storedException = new AtomicReference<>();
try {
CloudBlobClient blobClient = AzureStorageUtils.createCloudBlobClient(context, getLogger(), flowFile);
CloudBlobContainer container = blobClient.getContainerReference(containerName);
container.createIfNotExists();

if (createContainer)
container.createIfNotExists();

CloudBlob blob = container.getBlockBlobReference(blobPath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public final class AzureStorageUtils {
public static final PropertyDescriptor CONTAINER = new PropertyDescriptor.Builder()
.name("container-name")
.displayName("Container Name")
.description("Name of the Azure storage container. In case of PutAzureBlobStorage processor, container will be created if it does not exist.")
.description("Name of the Azure storage container. In case of PutAzureBlobStorage processor, container can be created if it does not exist.")
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
.required(true)
Expand Down

0 comments on commit 1fb8bc3

Please sign in to comment.