-
Notifications
You must be signed in to change notification settings - Fork 2.9k
NIFI-7307 Adding support for setting and retrieving Azure Blob Storag… #10939
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
Open
pkelly-nifi
wants to merge
3
commits into
apache:main
Choose a base branch
from
pkelly-nifi:nifi-7307
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
122 changes: 122 additions & 0 deletions
122
...che/nifi/processors/azure/storage/AbstractGetAzureBlobStoragePropertiesProcessor_v12.java
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,122 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package org.apache.nifi.processors.azure.storage; | ||
|
|
||
| import com.azure.storage.blob.BlobClient; | ||
| import com.azure.storage.blob.BlobContainerClient; | ||
| import com.azure.storage.blob.BlobServiceClient; | ||
| import com.azure.storage.blob.models.BlobErrorCode; | ||
| import com.azure.storage.blob.models.BlobStorageException; | ||
| import org.apache.nifi.components.PropertyDescriptor; | ||
| import org.apache.nifi.flowfile.FlowFile; | ||
| import org.apache.nifi.processor.ProcessContext; | ||
| import org.apache.nifi.processor.ProcessSession; | ||
| import org.apache.nifi.processor.Relationship; | ||
| import org.apache.nifi.processor.exception.ProcessException; | ||
| import org.apache.nifi.processors.azure.AbstractAzureBlobProcessor_v12; | ||
| import org.apache.nifi.processors.azure.storage.utils.AzureStorageUtils; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| import static org.apache.nifi.processors.azure.storage.utils.AzureStorageUtils.BLOB_STORAGE_CREDENTIALS_SERVICE; | ||
| import static org.apache.nifi.processors.azure.storage.utils.BlobAttributes.ATTR_NAME_BLOBNAME; | ||
| import static org.apache.nifi.processors.azure.storage.utils.BlobAttributes.ATTR_NAME_CONTAINER; | ||
|
|
||
| public abstract class AbstractGetAzureBlobStoragePropertiesProcessor_v12 extends AbstractAzureBlobProcessor_v12 { | ||
|
|
||
| public static final PropertyDescriptor CONTAINER = new PropertyDescriptor.Builder() | ||
| .fromPropertyDescriptor(AzureStorageUtils.CONTAINER) | ||
| .defaultValue(String.format("${%s}", ATTR_NAME_CONTAINER)) | ||
| .build(); | ||
|
|
||
| public static final PropertyDescriptor BLOB_NAME = new PropertyDescriptor.Builder() | ||
| .fromPropertyDescriptor(AbstractAzureBlobProcessor_v12.BLOB_NAME) | ||
| .defaultValue(String.format("${%s}", ATTR_NAME_BLOBNAME)) | ||
| .build(); | ||
|
|
||
| private static final List<PropertyDescriptor> PROPERTIES = List.of( | ||
| BLOB_STORAGE_CREDENTIALS_SERVICE, | ||
| CONTAINER, | ||
| BLOB_NAME, | ||
| AzureStorageUtils.PROXY_CONFIGURATION_SERVICE | ||
| ); | ||
|
|
||
| static final Relationship REL_FOUND = new Relationship.Builder() | ||
| .name("found") | ||
| .description("A blob with the supplied name was found in the container") | ||
| .build(); | ||
|
|
||
| static final Relationship REL_NOT_FOUND = new Relationship.Builder() | ||
| .name("not found") | ||
| .description("No blob was found with the supplied name in the container") | ||
| .build(); | ||
|
|
||
| private static final Set<Relationship> RELATIONSHIPS = Set.of(REL_FOUND, REL_NOT_FOUND, REL_FAILURE); | ||
|
|
||
| @Override | ||
| public Set<Relationship> getRelationships() { | ||
| return RELATIONSHIPS; | ||
| } | ||
|
|
||
| @Override | ||
| protected List<PropertyDescriptor> getSupportedPropertyDescriptors() { | ||
| return PROPERTIES; | ||
| } | ||
|
|
||
| protected abstract String getAttributePrefix(); | ||
|
|
||
| protected abstract Map<String, String> fetchProperties(BlobClient blobClient); | ||
|
|
||
| @Override | ||
| public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { | ||
| FlowFile flowFile = session.get(); | ||
| if (flowFile == null) { | ||
| return; | ||
| } | ||
|
|
||
| final String containerName = context.getProperty(CONTAINER).evaluateAttributeExpressions(flowFile).getValue(); | ||
| final String blobName = context.getProperty(BLOB_NAME).evaluateAttributeExpressions(flowFile).getValue(); | ||
|
|
||
| try { | ||
| final BlobServiceClient storageClient = getStorageClient(context, flowFile); | ||
| final BlobContainerClient containerClient = storageClient.getBlobContainerClient(containerName); | ||
| final BlobClient blobClient = containerClient.getBlobClient(blobName); | ||
|
|
||
| final Map<String, String> newAttributes = new HashMap<>(); | ||
| fetchProperties(blobClient).forEach((key, value) -> | ||
| newAttributes.put(getAttributePrefix().formatted(key), value) | ||
| ); | ||
|
|
||
| flowFile = session.putAllAttributes(flowFile, newAttributes); | ||
| final String eventDetails = String.format("Attributes added [%s]", String.join(", ", newAttributes.keySet())); | ||
| session.getProvenanceReporter().modifyAttributes(flowFile, eventDetails); | ||
| session.transfer(flowFile, REL_FOUND); | ||
| } catch (final BlobStorageException e) { | ||
| if (e.getErrorCode() == BlobErrorCode.BLOB_NOT_FOUND) { | ||
| getLogger().warn("Specified blob ({}) does not exist, routing to not found.", blobName); | ||
| session.transfer(flowFile, REL_NOT_FOUND); | ||
| } else { | ||
| getLogger().error("Failed to retrieve properties for the specified blob ({}) from Azure Blob Storage. Routing to failure", blobName, e); | ||
| flowFile = session.penalize(flowFile); | ||
| session.transfer(flowFile, REL_FAILURE); | ||
| } | ||
| } | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
...c/main/java/org/apache/nifi/processors/azure/storage/GetAzureBlobStorageMetadata_v12.java
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,49 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package org.apache.nifi.processors.azure.storage; | ||
|
|
||
| import com.azure.storage.blob.BlobClient; | ||
| import org.apache.nifi.annotation.behavior.InputRequirement; | ||
| import org.apache.nifi.annotation.behavior.InputRequirement.Requirement; | ||
| import org.apache.nifi.annotation.behavior.WritesAttribute; | ||
| import org.apache.nifi.annotation.behavior.WritesAttributes; | ||
| import org.apache.nifi.annotation.documentation.CapabilityDescription; | ||
| import org.apache.nifi.annotation.documentation.SeeAlso; | ||
| import org.apache.nifi.annotation.documentation.Tags; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| @Tags({"azure", "microsoft", "cloud", "storage", "blob"}) | ||
| @SeeAlso({ListAzureBlobStorage_v12.class, FetchAzureBlobStorage_v12.class, PutAzureBlobStorage_v12.class, | ||
| CopyAzureBlobStorage_v12.class, DeleteAzureBlobStorage_v12.class, GetAzureBlobStorageTags_v12.class}) | ||
| @CapabilityDescription("Retrieves user metadata from the specified blob from Azure Blob Storage. The processor uses Azure Blob Storage client library v12.") | ||
| @InputRequirement(Requirement.INPUT_REQUIRED) | ||
| @WritesAttributes({@WritesAttribute(attribute = "azure.user.metadata.<metadata-key>", description = "The value of the retrieved metadata")}) | ||
| public class GetAzureBlobStorageMetadata_v12 extends AbstractGetAzureBlobStoragePropertiesProcessor_v12 { | ||
|
|
||
| private static final String ATTRIBUTE_PREFIX = "azure.user.metadata.%s"; | ||
|
|
||
| @Override | ||
| protected String getAttributePrefix() { | ||
| return ATTRIBUTE_PREFIX; | ||
| } | ||
|
|
||
| @Override | ||
| protected Map<String, String> fetchProperties(final BlobClient blobClient) { | ||
| return blobClient.getProperties().getMetadata(); | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
...s/src/main/java/org/apache/nifi/processors/azure/storage/GetAzureBlobStorageTags_v12.java
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,49 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package org.apache.nifi.processors.azure.storage; | ||
|
|
||
| import com.azure.storage.blob.BlobClient; | ||
| import org.apache.nifi.annotation.behavior.InputRequirement; | ||
| import org.apache.nifi.annotation.behavior.InputRequirement.Requirement; | ||
| import org.apache.nifi.annotation.behavior.WritesAttribute; | ||
| import org.apache.nifi.annotation.behavior.WritesAttributes; | ||
| import org.apache.nifi.annotation.documentation.CapabilityDescription; | ||
| import org.apache.nifi.annotation.documentation.SeeAlso; | ||
| import org.apache.nifi.annotation.documentation.Tags; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| @Tags({"azure", "microsoft", "cloud", "storage", "blob"}) | ||
| @SeeAlso({ListAzureBlobStorage_v12.class, FetchAzureBlobStorage_v12.class, PutAzureBlobStorage_v12.class, | ||
| CopyAzureBlobStorage_v12.class, DeleteAzureBlobStorage_v12.class, GetAzureBlobStorageMetadata_v12.class}) | ||
| @CapabilityDescription("Retrieves tags from the specified blob from Azure Blob Storage. The processor uses Azure Blob Storage client library v12.") | ||
| @InputRequirement(Requirement.INPUT_REQUIRED) | ||
| @WritesAttributes({@WritesAttribute(attribute = "azure.tag.<tag-key>", description = "The value of the retrieved tag")}) | ||
| public class GetAzureBlobStorageTags_v12 extends AbstractGetAzureBlobStoragePropertiesProcessor_v12 { | ||
|
|
||
| private static final String ATTRIBUTE_PREFIX = "azure.tag.%s"; | ||
|
|
||
| @Override | ||
| protected String getAttributePrefix() { | ||
| return ATTRIBUTE_PREFIX; | ||
| } | ||
|
|
||
| @Override | ||
| protected Map<String, String> fetchProperties(final BlobClient blobClient) { | ||
| return blobClient.getTags(); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write attributes annotation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added. Please let me know if you have a better suggestion for annotating these dynamic attributes.