mark-bathori commented on code in PR #8359:
URL: https://github.com/apache/nifi/pull/8359#discussion_r1484035099


##########
nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/services/azure/storage/AzureBlobStorageFileResourceService.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.services.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.BlobStorageException;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.documentation.UseCase;
+import org.apache.nifi.annotation.lifecycle.OnDisabled;
+import org.apache.nifi.annotation.lifecycle.OnEnabled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.fileresource.service.api.FileResource;
+import org.apache.nifi.fileresource.service.api.FileResourceService;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processors.azure.AbstractAzureBlobProcessor_v12;
+import org.apache.nifi.processors.azure.storage.FetchAzureBlobStorage_v12;
+import org.apache.nifi.processors.azure.storage.utils.AzureStorageUtils;
+import org.apache.nifi.processors.azure.storage.utils.BlobServiceClientFactory;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.nifi.processors.azure.storage.utils.AzureStorageUtils.getProxyOptions;
+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;
+import static org.apache.nifi.util.StringUtils.isBlank;
+
+@Tags({"azure", "microsoft", "cloud", "storage", "file", "resource", "blob"})
+@SeeAlso({FetchAzureBlobStorage_v12.class})
+@CapabilityDescription("Provides an Azure Blob Storage file resource for other 
components.")
+@UseCase(
+        description = "Fetch a specific file from Azure Blob Storage." +
+                " The service provides higher performance compared to fetch 
processors when the data should be moved between different storages without any 
transformation.",
+        configuration = """
+                "Container Name" = "${azure.container}"
+                "Blob Name" = "${azure.blobname}"
+
+                The "Storage Credentials" property should specify an instance 
of the AzureStorageCredentialsService_v12 in order to provide credentials for 
accessing the storage container.
+                """
+)
+public class AzureBlobStorageFileResourceService extends 
AbstractControllerService implements FileResourceService {
+
+    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();
+
+    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();
+
+    private static final List<PropertyDescriptor> PROPERTIES = List.of(
+            CONTAINER,
+            BLOB_NAME,
+            STORAGE_CREDENTIALS_SERVICE
+    );
+
+    private volatile BlobServiceClientFactory clientFactory;
+    private volatile ConfigurationContext context;
+
+    @Override
+    protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return PROPERTIES;
+    }
+
+    @OnEnabled
+    public void onEnabled(final ConfigurationContext context) {
+        this.clientFactory = new BlobServiceClientFactory(getLogger(), 
getProxyOptions(context));
+        this.context = context;
+    }
+
+    @OnDisabled
+    public void onDisabled() {
+        this.clientFactory = null;
+        this.context = null;
+    }
+
+    @Override
+    public FileResource getFileResource(Map<String, String> attributes) {
+        BlobServiceClient client = getStorageClient(attributes);

Review Comment:
   This can be `final`.



##########
nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/services/azure/storage/AzureDataLakeStorageFileResourceService.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.services.azure.storage;
+
+import com.azure.storage.file.datalake.DataLakeDirectoryClient;
+import com.azure.storage.file.datalake.DataLakeFileClient;
+import com.azure.storage.file.datalake.DataLakeFileSystemClient;
+import com.azure.storage.file.datalake.DataLakeServiceClient;
+import com.azure.storage.file.datalake.models.DataLakeStorageException;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.documentation.UseCase;
+import org.apache.nifi.annotation.lifecycle.OnDisabled;
+import org.apache.nifi.annotation.lifecycle.OnEnabled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.fileresource.service.api.FileResource;
+import org.apache.nifi.fileresource.service.api.FileResourceService;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processors.azure.storage.FetchAzureDataLakeStorage;
+import 
org.apache.nifi.processors.azure.storage.utils.DataLakeServiceClientFactory;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProcessor.ADLS_CREDENTIALS_SERVICE;
+import static 
org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProcessor.DIRECTORY;
+import static 
org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProcessor.FILE;
+import static 
org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProcessor.FILESYSTEM;
+import static 
org.apache.nifi.processors.azure.storage.utils.AzureStorageUtils.getProxyOptions;
+import static org.apache.nifi.util.StringUtils.isBlank;
+
+@Tags({"azure", "microsoft", "cloud", "storage", "adlsgen2", "file", 
"resource", "datalake"})
+@SeeAlso({FetchAzureDataLakeStorage.class})
+@CapabilityDescription("Provides an Azure Data Lake Storage (ADLS) file 
resource for other components.")
+@UseCase(
+        description = "Fetch the specified file from Azure Data Lake Storage." 
+
+                " The service provides higher performance compared to fetch 
processors when the data should be moved between different storages without any 
transformation.",
+        configuration = """
+                "Filesystem Name" = "${azure.filesystem}"
+                "Directory Name" = "${azure.directory}"
+                "File Name" = "${azure.filename}"
+
+                The "ADLS Credentials" property should specify an instance of 
the ADLSCredentialsService in order to provide credentials for accessing the 
filesystem.
+                """
+)
+public class AzureDataLakeStorageFileResourceService extends 
AbstractControllerService implements FileResourceService {
+
+    private static final List<PropertyDescriptor> PROPERTIES = List.of(
+            ADLS_CREDENTIALS_SERVICE,
+            FILESYSTEM,
+            DIRECTORY,
+            FILE
+    );
+
+    private volatile DataLakeServiceClientFactory clientFactory;
+    private volatile ConfigurationContext context;
+
+    @Override
+    protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return PROPERTIES;
+    }
+
+    @OnEnabled
+    public void onEnabled(final ConfigurationContext context) {
+        this.clientFactory = new DataLakeServiceClientFactory(getLogger(), 
getProxyOptions(context));
+        this.context = context;
+    }
+
+    @OnDisabled
+    public void onDisabled() {
+        this.clientFactory = null;
+        this.context = null;
+    }
+
+    @Override
+    public FileResource getFileResource(Map<String, String> attributes) {
+        DataLakeServiceClient client = getStorageClient(attributes);
+        try {
+            return fetchBlob(client, attributes);
+        } catch (final DataLakeStorageException | IOException e) {
+            throw new ProcessException("Failed to fetch file from ADLS 
Storage", e);
+        }
+    }
+
+    protected DataLakeServiceClient getStorageClient(Map<String, String> 
attributes) {
+        final ADLSCredentialsService credentialsService = 
context.getProperty(ADLS_CREDENTIALS_SERVICE)
+                .asControllerService(ADLSCredentialsService.class);
+        return 
clientFactory.getStorageClient(credentialsService.getCredentialsDetails(attributes));
+    }
+
+    /**
+     * Fetching file from the provided filesystem and directory in ADLS.
+     *
+     * @param storageClient azure data lake service client
+     * @param attributes configuration attributes
+     * @return fetched file as FileResource
+     * @throws IOException exception caused by missing parameters or blob not 
found
+     */
+    private FileResource fetchBlob(final DataLakeServiceClient storageClient, 
final Map<String, String> attributes) throws IOException {
+        final String fileSystem = 
context.getProperty(FILESYSTEM).evaluateAttributeExpressions(attributes).getValue();
+        final String directory = 
context.getProperty(DIRECTORY).evaluateAttributeExpressions(attributes).getValue();
+        final String file = 
context.getProperty(FILE).evaluateAttributeExpressions(attributes).getValue();
+
+        if (isBlank(fileSystem) || isBlank(file)) {
+            throw new ProcessException("Filesystem and file name cannot be 
empty");
+        }
+        validateDirectoryProperty(directory);
+
+        final DataLakeFileSystemClient fileSystemClient = 
storageClient.getFileSystemClient(fileSystem);
+        final DataLakeDirectoryClient directoryClient = 
fileSystemClient.getDirectoryClient(directory);
+        final DataLakeFileClient fileClient = 
directoryClient.getFileClient(file);
+
+        if (fileClient.getProperties().isDirectory()) {
+            throw new ProcessException(FILE.getDisplayName() + " (" + file + 
") points to a directory. Full path: " + fileClient.getFilePath());
+        }
+
+        if (!fileClient.exists()) {
+            throw new ProcessException(String.format("File %s/%s not found in 
file system: %s", directory, file, fileSystem));
+        }
+
+        return new FileResource(fileClient.openInputStream().getInputStream(),
+                fileClient.getProperties().getFileSize());
+    }
+
+    private static void validateDirectoryProperty(String directoryName) {

Review Comment:
   This method can be found in `AbstractAzureDataLakeStorageProcessor`, so it 
doesn't need to be duplicated.



##########
nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/services/azure/storage/AzureDataLakeStorageFileResourceService.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.services.azure.storage;
+
+import com.azure.storage.file.datalake.DataLakeDirectoryClient;
+import com.azure.storage.file.datalake.DataLakeFileClient;
+import com.azure.storage.file.datalake.DataLakeFileSystemClient;
+import com.azure.storage.file.datalake.DataLakeServiceClient;
+import com.azure.storage.file.datalake.models.DataLakeStorageException;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.documentation.UseCase;
+import org.apache.nifi.annotation.lifecycle.OnDisabled;
+import org.apache.nifi.annotation.lifecycle.OnEnabled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.fileresource.service.api.FileResource;
+import org.apache.nifi.fileresource.service.api.FileResourceService;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processors.azure.storage.FetchAzureDataLakeStorage;
+import 
org.apache.nifi.processors.azure.storage.utils.DataLakeServiceClientFactory;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProcessor.ADLS_CREDENTIALS_SERVICE;
+import static 
org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProcessor.DIRECTORY;
+import static 
org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProcessor.FILE;
+import static 
org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProcessor.FILESYSTEM;
+import static 
org.apache.nifi.processors.azure.storage.utils.AzureStorageUtils.getProxyOptions;
+import static org.apache.nifi.util.StringUtils.isBlank;
+
+@Tags({"azure", "microsoft", "cloud", "storage", "adlsgen2", "file", 
"resource", "datalake"})
+@SeeAlso({FetchAzureDataLakeStorage.class})
+@CapabilityDescription("Provides an Azure Data Lake Storage (ADLS) file 
resource for other components.")
+@UseCase(
+        description = "Fetch the specified file from Azure Data Lake Storage." 
+
+                " The service provides higher performance compared to fetch 
processors when the data should be moved between different storages without any 
transformation.",
+        configuration = """
+                "Filesystem Name" = "${azure.filesystem}"
+                "Directory Name" = "${azure.directory}"
+                "File Name" = "${azure.filename}"
+
+                The "ADLS Credentials" property should specify an instance of 
the ADLSCredentialsService in order to provide credentials for accessing the 
filesystem.
+                """
+)
+public class AzureDataLakeStorageFileResourceService extends 
AbstractControllerService implements FileResourceService {
+
+    private static final List<PropertyDescriptor> PROPERTIES = List.of(
+            ADLS_CREDENTIALS_SERVICE,
+            FILESYSTEM,
+            DIRECTORY,
+            FILE
+    );
+
+    private volatile DataLakeServiceClientFactory clientFactory;
+    private volatile ConfigurationContext context;
+
+    @Override
+    protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return PROPERTIES;
+    }
+
+    @OnEnabled
+    public void onEnabled(final ConfigurationContext context) {
+        this.clientFactory = new DataLakeServiceClientFactory(getLogger(), 
getProxyOptions(context));
+        this.context = context;
+    }
+
+    @OnDisabled
+    public void onDisabled() {
+        this.clientFactory = null;
+        this.context = null;
+    }
+
+    @Override
+    public FileResource getFileResource(Map<String, String> attributes) {
+        DataLakeServiceClient client = getStorageClient(attributes);

Review Comment:
   This can be `final`.



##########
nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/services/azure/storage/AzureDataLakeStorageFileResourceService.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.services.azure.storage;
+
+import com.azure.storage.file.datalake.DataLakeDirectoryClient;
+import com.azure.storage.file.datalake.DataLakeFileClient;
+import com.azure.storage.file.datalake.DataLakeFileSystemClient;
+import com.azure.storage.file.datalake.DataLakeServiceClient;
+import com.azure.storage.file.datalake.models.DataLakeStorageException;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.documentation.UseCase;
+import org.apache.nifi.annotation.lifecycle.OnDisabled;
+import org.apache.nifi.annotation.lifecycle.OnEnabled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.fileresource.service.api.FileResource;
+import org.apache.nifi.fileresource.service.api.FileResourceService;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processors.azure.storage.FetchAzureDataLakeStorage;
+import 
org.apache.nifi.processors.azure.storage.utils.DataLakeServiceClientFactory;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProcessor.ADLS_CREDENTIALS_SERVICE;

Review Comment:
   I think it's not a best practice to use these properties from an 
AbstractProcessor class. These properties should be used only in the 
implementing classes and since this ControllerService is not a direct 
implementation, it would be better to extract these into a common util class.



##########
nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/services/azure/storage/AzureDataLakeStorageFileResourceService.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.services.azure.storage;
+
+import com.azure.storage.file.datalake.DataLakeDirectoryClient;
+import com.azure.storage.file.datalake.DataLakeFileClient;
+import com.azure.storage.file.datalake.DataLakeFileSystemClient;
+import com.azure.storage.file.datalake.DataLakeServiceClient;
+import com.azure.storage.file.datalake.models.DataLakeStorageException;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.documentation.UseCase;
+import org.apache.nifi.annotation.lifecycle.OnDisabled;
+import org.apache.nifi.annotation.lifecycle.OnEnabled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.fileresource.service.api.FileResource;
+import org.apache.nifi.fileresource.service.api.FileResourceService;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processors.azure.storage.FetchAzureDataLakeStorage;
+import 
org.apache.nifi.processors.azure.storage.utils.DataLakeServiceClientFactory;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProcessor.ADLS_CREDENTIALS_SERVICE;
+import static 
org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProcessor.DIRECTORY;
+import static 
org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProcessor.FILE;
+import static 
org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProcessor.FILESYSTEM;
+import static 
org.apache.nifi.processors.azure.storage.utils.AzureStorageUtils.getProxyOptions;
+import static org.apache.nifi.util.StringUtils.isBlank;
+
+@Tags({"azure", "microsoft", "cloud", "storage", "adlsgen2", "file", 
"resource", "datalake"})
+@SeeAlso({FetchAzureDataLakeStorage.class})
+@CapabilityDescription("Provides an Azure Data Lake Storage (ADLS) file 
resource for other components.")
+@UseCase(
+        description = "Fetch the specified file from Azure Data Lake Storage." 
+
+                " The service provides higher performance compared to fetch 
processors when the data should be moved between different storages without any 
transformation.",
+        configuration = """
+                "Filesystem Name" = "${azure.filesystem}"
+                "Directory Name" = "${azure.directory}"
+                "File Name" = "${azure.filename}"
+
+                The "ADLS Credentials" property should specify an instance of 
the ADLSCredentialsService in order to provide credentials for accessing the 
filesystem.
+                """
+)
+public class AzureDataLakeStorageFileResourceService extends 
AbstractControllerService implements FileResourceService {
+
+    private static final List<PropertyDescriptor> PROPERTIES = List.of(
+            ADLS_CREDENTIALS_SERVICE,
+            FILESYSTEM,
+            DIRECTORY,
+            FILE
+    );
+
+    private volatile DataLakeServiceClientFactory clientFactory;
+    private volatile ConfigurationContext context;
+
+    @Override
+    protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return PROPERTIES;
+    }
+
+    @OnEnabled
+    public void onEnabled(final ConfigurationContext context) {
+        this.clientFactory = new DataLakeServiceClientFactory(getLogger(), 
getProxyOptions(context));
+        this.context = context;
+    }
+
+    @OnDisabled
+    public void onDisabled() {
+        this.clientFactory = null;
+        this.context = null;
+    }
+
+    @Override
+    public FileResource getFileResource(Map<String, String> attributes) {
+        DataLakeServiceClient client = getStorageClient(attributes);
+        try {
+            return fetchBlob(client, attributes);
+        } catch (final DataLakeStorageException | IOException e) {
+            throw new ProcessException("Failed to fetch file from ADLS 
Storage", e);
+        }
+    }
+
+    protected DataLakeServiceClient getStorageClient(Map<String, String> 
attributes) {
+        final ADLSCredentialsService credentialsService = 
context.getProperty(ADLS_CREDENTIALS_SERVICE)
+                .asControllerService(ADLSCredentialsService.class);
+        return 
clientFactory.getStorageClient(credentialsService.getCredentialsDetails(attributes));
+    }
+
+    /**
+     * Fetching file from the provided filesystem and directory in ADLS.
+     *
+     * @param storageClient azure data lake service client
+     * @param attributes configuration attributes
+     * @return fetched file as FileResource
+     * @throws IOException exception caused by missing parameters or blob not 
found
+     */
+    private FileResource fetchBlob(final DataLakeServiceClient storageClient, 
final Map<String, String> attributes) throws IOException {
+        final String fileSystem = 
context.getProperty(FILESYSTEM).evaluateAttributeExpressions(attributes).getValue();
+        final String directory = 
context.getProperty(DIRECTORY).evaluateAttributeExpressions(attributes).getValue();
+        final String file = 
context.getProperty(FILE).evaluateAttributeExpressions(attributes).getValue();
+
+        if (isBlank(fileSystem) || isBlank(file)) {

Review Comment:
   There are already methods provided in 
`AbstractAzureDataLakeStorageProcessor` to check the `fileSystem` and `file` 
properties, so these could be used here too. These are 
`evaluateFileSystemProperty` and `evaluateFileNameProperty` methods.



-- 
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

Reply via email to