lordgamez commented on a change in pull request #1221: URL: https://github.com/apache/nifi-minifi-cpp/pull/1221#discussion_r783034838
########## File path: extensions/azure/processors/FetchAzureDataLakeStorage.cpp ########## @@ -0,0 +1,125 @@ +/** + * @file FetchAzureDataLakeStorage.cpp + * FetchAzureDataLakeStorage class implementation + * + * 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. + */ + +#include "FetchAzureDataLakeStorage.h" + +#include "core/Resource.h" + +namespace org::apache::nifi::minifi::azure::processors { + +const core::Property FetchAzureDataLakeStorage::RangeStart( + core::PropertyBuilder::createProperty("Range Start") + ->withDescription("The byte position at which to start reading from the object. An empty value or a value of zero will start reading at the beginning of the object.") + ->supportsExpressionLanguage(true) + ->build()); + +const core::Property FetchAzureDataLakeStorage::RangeLength( + core::PropertyBuilder::createProperty("Range Length") + ->withDescription("The number of bytes to download from the object, starting from the Range Start. " + "An empty value or a value that extends beyond the end of the object will read to the end of the object.") + ->supportsExpressionLanguage(true) + ->build()); + +const core::Property FetchAzureDataLakeStorage::NumberOfRetries( + core::PropertyBuilder::createProperty("Number of Retries") + ->withDescription("The number of automatic retries to perform if the download fails.") + ->withDefaultValue<uint64_t>(0) + ->supportsExpressionLanguage(true) + ->build()); + +const core::Relationship FetchAzureDataLakeStorage::Success("success", "Files that have been successfully fetched from Azure storage are transferred to this relationship"); +const core::Relationship FetchAzureDataLakeStorage::Failure("failure", "In case of fetch failure flowfiles are transferred to this relationship"); + +void FetchAzureDataLakeStorage::initialize() { + // Add new supported properties + setSupportedProperties({ + AzureStorageCredentialsService, + FilesystemName, + DirectoryName, + FileName, + RangeStart, + RangeLength, + NumberOfRetries + }); + // Set the supported relationships + setSupportedRelationships({ + Success, + Failure + }); +} + +std::optional<storage::FetchAzureDataLakeStorageParameters> FetchAzureDataLakeStorage::buildFetchParameters( + const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::FlowFile>& flow_file) { + storage::FetchAzureDataLakeStorageParameters params; Review comment: Updated in 5bc55b3ad7361bb333a55d87421ab6c3ccc1676b ########## File path: extensions/azure/processors/FetchAzureDataLakeStorage.cpp ########## @@ -0,0 +1,125 @@ +/** + * @file FetchAzureDataLakeStorage.cpp + * FetchAzureDataLakeStorage class implementation + * + * 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. + */ + +#include "FetchAzureDataLakeStorage.h" + +#include "core/Resource.h" + +namespace org::apache::nifi::minifi::azure::processors { + +const core::Property FetchAzureDataLakeStorage::RangeStart( + core::PropertyBuilder::createProperty("Range Start") + ->withDescription("The byte position at which to start reading from the object. An empty value or a value of zero will start reading at the beginning of the object.") + ->supportsExpressionLanguage(true) + ->build()); + +const core::Property FetchAzureDataLakeStorage::RangeLength( + core::PropertyBuilder::createProperty("Range Length") + ->withDescription("The number of bytes to download from the object, starting from the Range Start. " + "An empty value or a value that extends beyond the end of the object will read to the end of the object.") + ->supportsExpressionLanguage(true) + ->build()); + +const core::Property FetchAzureDataLakeStorage::NumberOfRetries( + core::PropertyBuilder::createProperty("Number of Retries") + ->withDescription("The number of automatic retries to perform if the download fails.") + ->withDefaultValue<uint64_t>(0) + ->supportsExpressionLanguage(true) + ->build()); + +const core::Relationship FetchAzureDataLakeStorage::Success("success", "Files that have been successfully fetched from Azure storage are transferred to this relationship"); +const core::Relationship FetchAzureDataLakeStorage::Failure("failure", "In case of fetch failure flowfiles are transferred to this relationship"); + +void FetchAzureDataLakeStorage::initialize() { + // Add new supported properties + setSupportedProperties({ + AzureStorageCredentialsService, + FilesystemName, + DirectoryName, + FileName, + RangeStart, + RangeLength, + NumberOfRetries + }); + // Set the supported relationships + setSupportedRelationships({ + Success, + Failure + }); +} + +std::optional<storage::FetchAzureDataLakeStorageParameters> FetchAzureDataLakeStorage::buildFetchParameters( + const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::FlowFile>& flow_file) { + storage::FetchAzureDataLakeStorageParameters params; + if (!setCommonParameters(params, *context, flow_file)) { + return std::nullopt; + } + + std::string value; + if (context->getProperty(RangeStart, value, flow_file)) { + params.range_start = std::stoull(value); + logger_->log_debug("Range Start property set to %llu", *params.range_start); + } + + if (context->getProperty(RangeLength, value, flow_file)) { + params.range_length = std::stoull(value); + logger_->log_debug("Range Length property set to %llu", *params.range_length); + } + + if (context->getProperty(NumberOfRetries, value, flow_file)) { + params.number_of_retries = std::stoull(value); + logger_->log_debug("Number Of Retries property set to %llu", *params.number_of_retries); + } + + return params; +} + +void FetchAzureDataLakeStorage::onTrigger(const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::ProcessSession>& session) { Review comment: Updated in 5bc55b3ad7361bb333a55d87421ab6c3ccc1676b ########## File path: libminifi/test/azure-tests/FetchAzureDataLakeStorageTests.cpp ########## @@ -0,0 +1,133 @@ +/** + * + * 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. + */ + +#include "AzureDataLakeStorageTestsFixture.h" +#include "processors/FetchAzureDataLakeStorage.h" +#include "controllerservices/AzureStorageCredentialsService.h" + +namespace { + +using namespace std::chrono_literals; + +using FetchAzureDataLakeStorageTestsFixture = AzureDataLakeStorageTestsFixture<minifi::azure::processors::FetchAzureDataLakeStorage>; + +TEST_CASE_METHOD(FetchAzureDataLakeStorageTestsFixture, "Azure storage credentials service is empty", "[azureDataLakeStorageParameters]") { + plan_->setProperty(azure_data_lake_storage_, minifi::azure::processors::FetchAzureDataLakeStorage::AzureStorageCredentialsService.getName(), ""); + REQUIRE_THROWS_AS(test_controller_.runSession(plan_, true), minifi::Exception); + REQUIRE(getFailedFlowFileContents().size() == 0); +} + +TEST_CASE_METHOD(FetchAzureDataLakeStorageTestsFixture, "Test Azure credentials with account name and SAS token set", "[azureDataLakeStorageParameters]") { + setDefaultProperties(); + plan_->setProperty(azure_storage_cred_service_, minifi::azure::controllers::AzureStorageCredentialsService::SASToken.getName(), "token"); + plan_->setProperty(azure_storage_cred_service_, minifi::azure::controllers::AzureStorageCredentialsService::StorageAccountName.getName(), "TEST_ACCOUNT"); + plan_->setProperty(azure_storage_cred_service_, minifi::azure::controllers::AzureStorageCredentialsService::ConnectionString.getName(), ""); + test_controller_.runSession(plan_, true); + auto passed_params = mock_data_lake_storage_client_ptr_->getPassedFetchParams(); + CHECK(passed_params.credentials.buildConnectionString() == "AccountName=TEST_ACCOUNT;SharedAccessSignature=token"); + CHECK(getFailedFlowFileContents().size() == 0); +} + +TEST_CASE_METHOD(FetchAzureDataLakeStorageTestsFixture, "Test Azure credentials with connection string override", "[azureDataLakeStorageParameters]") { + setDefaultProperties(); + plan_->setProperty(azure_storage_cred_service_, minifi::azure::controllers::AzureStorageCredentialsService::ConnectionString.getName(), CONNECTION_STRING); + plan_->setProperty(azure_storage_cred_service_, minifi::azure::controllers::AzureStorageCredentialsService::SASToken.getName(), "token"); + plan_->setProperty(azure_storage_cred_service_, minifi::azure::controllers::AzureStorageCredentialsService::StorageAccountName.getName(), "TEST_ACCOUNT"); + test_controller_.runSession(plan_, true); + auto passed_params = mock_data_lake_storage_client_ptr_->getPassedFetchParams(); + CHECK(passed_params.credentials.buildConnectionString() == CONNECTION_STRING); + CHECK(getFailedFlowFileContents().size() == 0); +} + +TEST_CASE_METHOD(FetchAzureDataLakeStorageTestsFixture, "Test Azure credentials with managed identity use", "[azureDataLakeStorageParameters]") { + setDefaultProperties(); + plan_->setProperty(azure_storage_cred_service_, minifi::azure::controllers::AzureStorageCredentialsService::ConnectionString.getName(), "test"); + plan_->setProperty(azure_storage_cred_service_, minifi::azure::controllers::AzureStorageCredentialsService::UseManagedIdentityCredentials.getName(), "true"); + plan_->setProperty(azure_storage_cred_service_, minifi::azure::controllers::AzureStorageCredentialsService::StorageAccountName.getName(), "TEST_ACCOUNT"); + test_controller_.runSession(plan_, true); + auto passed_params = mock_data_lake_storage_client_ptr_->getPassedFetchParams(); + CHECK(passed_params.credentials.buildConnectionString().empty()); + CHECK(passed_params.credentials.getStorageAccountName() == "TEST_ACCOUNT"); + CHECK(passed_params.credentials.getEndpointSuffix() == "core.windows.net"); + CHECK(getFailedFlowFileContents().size() == 0); +} + +TEST_CASE_METHOD(FetchAzureDataLakeStorageTestsFixture, "Filesystem name is not set", "[azureDataLakeStorageParameters]") { + plan_->setProperty(update_attribute_, "test.filesystemname", "", true); + test_controller_.runSession(plan_, true); + using org::apache::nifi::minifi::utils::verifyLogLinePresenceInPollTime; + CHECK(verifyLogLinePresenceInPollTime(1s, "Filesystem Name '' is invalid or empty!")); + auto failed_flowfiles = getFailedFlowFileContents(); + REQUIRE(failed_flowfiles.size() == 1); + REQUIRE(failed_flowfiles[0] == TEST_DATA); +} + +TEST_CASE_METHOD(FetchAzureDataLakeStorageTestsFixture, "Connection String is empty", "[azureDataLakeStorageParameters]") { + plan_->setProperty(azure_storage_cred_service_, minifi::azure::controllers::AzureStorageCredentialsService::ConnectionString.getName(), ""); + REQUIRE_THROWS_AS(test_controller_.runSession(plan_, true), minifi::Exception); + REQUIRE(getFailedFlowFileContents().size() == 0); +} + +TEST_CASE_METHOD(FetchAzureDataLakeStorageTestsFixture, "Fetch full file succeeds", "[azureDataLakeStorageFetch]") { + test_controller_.runSession(plan_, true); + REQUIRE(getFailedFlowFileContents().size() == 0); + auto passed_params = mock_data_lake_storage_client_ptr_->getPassedFetchParams(); + CHECK(passed_params.credentials.buildConnectionString() == CONNECTION_STRING); + CHECK(passed_params.file_system_name == FILESYSTEM_NAME); + CHECK(passed_params.directory_name == DIRECTORY_NAME); + CHECK(passed_params.filename == GETFILE_FILE_NAME); + CHECK(passed_params.range_start == std::nullopt); + CHECK(passed_params.range_length == std::nullopt); + auto success_contents = getSuccessfulFlowFileContents(); + REQUIRE(success_contents.size() == 1); + REQUIRE(success_contents[0] == mock_data_lake_storage_client_ptr_->FETCHED_DATA); +} + +TEST_CASE_METHOD(FetchAzureDataLakeStorageTestsFixture, "Fetch a range of the file succeeds", "[azureDataLakeStorageFetch]") { + plan_->setProperty(azure_data_lake_storage_, minifi::azure::processors::FetchAzureDataLakeStorage::RangeStart.getName(), "5"); + plan_->setProperty(azure_data_lake_storage_, minifi::azure::processors::FetchAzureDataLakeStorage::RangeLength.getName(), "10"); + test_controller_.runSession(plan_, true); + REQUIRE(getFailedFlowFileContents().size() == 0); + auto passed_params = mock_data_lake_storage_client_ptr_->getPassedFetchParams(); + CHECK(passed_params.credentials.buildConnectionString() == CONNECTION_STRING); + CHECK(passed_params.file_system_name == FILESYSTEM_NAME); + CHECK(passed_params.directory_name == DIRECTORY_NAME); + CHECK(passed_params.filename == GETFILE_FILE_NAME); + CHECK(*passed_params.range_start == 5); + CHECK(*passed_params.range_length == 10); + auto success_contents = getSuccessfulFlowFileContents(); + REQUIRE(success_contents.size() == 1); + REQUIRE(success_contents[0] == mock_data_lake_storage_client_ptr_->FETCHED_DATA.substr(5, 10)); +} + +TEST_CASE_METHOD(FetchAzureDataLakeStorageTestsFixture, "Number of Retries is set", "[azureDataLakeStorageFetch]") { + plan_->setProperty(azure_data_lake_storage_, minifi::azure::processors::FetchAzureDataLakeStorage::NumberOfRetries.getName(), "1"); + test_controller_.runSession(plan_, true); + REQUIRE(mock_data_lake_storage_client_ptr_->getPassedFetchParams().number_of_retries == 1); +} + +TEST_CASE_METHOD(FetchAzureDataLakeStorageTestsFixture, "Fetch full file fails", "[azureDataLakeStorageFetch]") { + mock_data_lake_storage_client_ptr_->setFetchFailure(true); + test_controller_.runSession(plan_, true); + REQUIRE(getSuccessfulFlowFileContents().size() == 0); + auto success_contents = getFailedFlowFileContents(); Review comment: Fixed in 5bc55b3ad7361bb333a55d87421ab6c3ccc1676b ########## File path: extensions/azure/storage/AzureDataLakeStorageClient.cpp ########## @@ -30,21 +34,25 @@ AzureDataLakeStorageClient::AzureDataLakeStorageClient() { utils::AzureSdkLogger::initialize(); } -void AzureDataLakeStorageClient::resetClientIfNeeded(const AzureStorageCredentials& credentials, const std::string& file_system_name) { - if (client_ && credentials_ == credentials && file_system_name_ == file_system_name) { +void AzureDataLakeStorageClient::resetClientIfNeeded(const AzureStorageCredentials& credentials, const std::string& file_system_name, std::optional<uint64_t> number_of_retries) { + if (client_ && credentials_ == credentials && file_system_name_ == file_system_name && number_of_retries_ == number_of_retries) { Review comment: Great catch! Fixed in 5bc55b3ad7361bb333a55d87421ab6c3ccc1676b -- 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