turcsanyip commented on a change in pull request #5486: URL: https://github.com/apache/nifi/pull/5486#discussion_r739545995
########## File path: nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/processors/azure/AbstractAzureBlobProcessor_v12.java ########## @@ -0,0 +1,163 @@ +/* + * 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; + +import com.azure.core.credential.AzureSasCredential; +import com.azure.identity.ClientSecretCredentialBuilder; +import com.azure.identity.ManagedIdentityCredentialBuilder; +import com.azure.storage.blob.BlobClient; +import com.azure.storage.blob.BlobServiceClient; +import com.azure.storage.blob.BlobServiceClientBuilder; +import com.azure.storage.blob.models.BlobProperties; +import com.azure.storage.common.StorageSharedKeyCredential; +import org.apache.nifi.annotation.lifecycle.OnScheduled; +import org.apache.nifi.annotation.lifecycle.OnStopped; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.context.PropertyContext; +import org.apache.nifi.expression.ExpressionLanguageScope; +import org.apache.nifi.processor.AbstractProcessor; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.Relationship; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.services.azure.storage.AzureStorageCredentialsDetails_v12; +import org.apache.nifi.services.azure.storage.AzureStorageCredentialsService_v12; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +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_BLOBTYPE; +import static org.apache.nifi.processors.azure.storage.utils.BlobAttributes.ATTR_NAME_CONTAINER; +import static org.apache.nifi.processors.azure.storage.utils.BlobAttributes.ATTR_NAME_ETAG; +import static org.apache.nifi.processors.azure.storage.utils.BlobAttributes.ATTR_NAME_LANG; +import static org.apache.nifi.processors.azure.storage.utils.BlobAttributes.ATTR_NAME_LENGTH; +import static org.apache.nifi.processors.azure.storage.utils.BlobAttributes.ATTR_NAME_MIME_TYPE; +import static org.apache.nifi.processors.azure.storage.utils.BlobAttributes.ATTR_NAME_PRIMARY_URI; +import static org.apache.nifi.processors.azure.storage.utils.BlobAttributes.ATTR_NAME_TIMESTAMP; + +public abstract class AbstractAzureBlobProcessor_v12 extends AbstractProcessor { + + public static final PropertyDescriptor STORAGE_CREDENTIALS_SERVICE = new PropertyDescriptor.Builder() + .name("storage-credentials-service") + .displayName("Storage Credentials") + .description("Controller Service used to obtain Azure Blob Storage Credentials.") + .identifiesControllerService(AzureStorageCredentialsService_v12.class) + .required(true) + .build(); + + public static final PropertyDescriptor BLOB_NAME = new PropertyDescriptor.Builder() + .name("blob-name") + .displayName("Blob Name") + .description("The full name of the blob") + .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) + .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES) + .required(true) + .build(); + + public static final Relationship REL_SUCCESS = new Relationship.Builder() + .name("success") + .description("All successfully processed FlowFiles are routed to this relationship") + .build(); + public static final Relationship REL_FAILURE = new Relationship.Builder() + .name("failure") + .description("Unsuccessful operations will be transferred to the failure relationship.") + .build(); + + private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( + REL_SUCCESS, + REL_FAILURE + ))); + + private BlobServiceClient storageClient; + + @Override + public Set<Relationship> getRelationships() { + return RELATIONSHIPS; + } + + @OnScheduled + public void onScheduled(ProcessContext context) { + storageClient = createStorageClient(context); + } + + @OnStopped + public void onStopped() { + storageClient = null; + } + + protected BlobServiceClient getStorageClient() { + return storageClient; + } + + public static BlobServiceClient createStorageClient(PropertyContext context) { Review comment: I'm afraid we cannot not hide it totally. Even if it was `protected`, someone could use this abstract class as a parent class for their custom processors. Unfortunately, we will not be able to change it due to backward compatibility. Furthermore, it is `public` and `static` because of the Listen processor. Put, Fetch and Delete processors are subclasses of this abstract class (so `protected` would be fine) but Listen should come from `AbstractListProcessor`. For this reason, it accesses this method in static way. I know it is weird but the existing blob/adls List processors use the same and I have no better idea. I tried to subclass the List processor from the blob abstract class and define an `AbstractListProcessor` sublcass in the List processor (as an inner class) and use it as a delegate but it is not straightforward because all the processor lifecycle method callbacks should be delegated as well. So I gave up this approach. Any idea would be appreciated! -- 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-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org