You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2021/12/02 08:50:51 UTC

[GitHub] [nifi-minifi-cpp] lordgamez opened a new pull request #1221: MINIFICPP-1630 Create FetchAzureDataLakeStorage processor

lordgamez opened a new pull request #1221:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1221


   https://issues.apache.org/jira/browse/MINIFICPP-1630
   
   --------------------------------------------------------------------------------------
   Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced
        in the commit message?
   
   - [ ] Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically main)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   ### For code changes:
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   - [ ] If applicable, have you updated the LICENSE file?
   - [ ] If applicable, have you updated the NOTICE file?
   
   ### For documentation related changes:
   - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
   
   ### Note:
   Please ensure that once the PR is submitted, you check GitHub Actions CI results for build issues and submit an update to your PR as soon as possible.
   


-- 
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-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] lordgamez commented on a change in pull request #1221: MINIFICPP-1630 Create FetchAzureDataLakeStorage processor

Posted by GitBox <gi...@apache.org>.
lordgamez commented on a change in pull request #1221:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1221#discussion_r783120357



##########
File path: extensions/azure/storage/AzureDataLakeStorageClient.cpp
##########
@@ -30,30 +34,35 @@ 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) {
     logger_->log_debug("Azure Data Lake Storge client credentials have not changed, no need to reset client");
     return;
   }
 
+  Azure::Storage::Files::DataLake::DataLakeClientOptions options;
+  if (number_of_retries) {
+    options.Retry.MaxRetries = *number_of_retries;
+  }
+
   if (credentials.getUseManagedIdentityCredentials()) {
     auto datalake_service_client = Azure::Storage::Files::DataLake::DataLakeServiceClient(
-      "https://" + credentials.getStorageAccountName() + ".dfs." + credentials.getEndpointSuffix(), std::make_shared<Azure::Identity::ManagedIdentityCredential>());
-
+      "https://" + credentials.getStorageAccountName() + ".dfs." + credentials.getEndpointSuffix(), std::make_shared<Azure::Identity::ManagedIdentityCredential>(), options);
     client_ = std::make_unique<Azure::Storage::Files::DataLake::DataLakeFileSystemClient>(datalake_service_client.GetFileSystemClient(file_system_name));
     logger_->log_debug("Azure Data Lake Storge client has been reset with new managed identity credentials.");
   } else {
     client_ = std::make_unique<Azure::Storage::Files::DataLake::DataLakeFileSystemClient>(
-    Azure::Storage::Files::DataLake::DataLakeFileSystemClient::CreateFromConnectionString(credentials.buildConnectionString(), file_system_name));
+      Azure::Storage::Files::DataLake::DataLakeFileSystemClient::CreateFromConnectionString(credentials.buildConnectionString(), file_system_name, options));

Review comment:
       Fixed in eb6a6e6fa9f875efae2b720956a25392a5ce7383

##########
File path: extensions/azure/storage/AzureDataLakeStorageClient.cpp
##########
@@ -30,30 +34,35 @@ 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) {
     logger_->log_debug("Azure Data Lake Storge client credentials have not changed, no need to reset client");
     return;
   }
 
+  Azure::Storage::Files::DataLake::DataLakeClientOptions options;
+  if (number_of_retries) {
+    options.Retry.MaxRetries = *number_of_retries;
+  }
+
   if (credentials.getUseManagedIdentityCredentials()) {
     auto datalake_service_client = Azure::Storage::Files::DataLake::DataLakeServiceClient(
-      "https://" + credentials.getStorageAccountName() + ".dfs." + credentials.getEndpointSuffix(), std::make_shared<Azure::Identity::ManagedIdentityCredential>());
-
+      "https://" + credentials.getStorageAccountName() + ".dfs." + credentials.getEndpointSuffix(), std::make_shared<Azure::Identity::ManagedIdentityCredential>(), options);

Review comment:
       Fixed in eb6a6e6fa9f875efae2b720956a25392a5ce7383




-- 
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-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] lordgamez commented on a change in pull request #1221: MINIFICPP-1630 Create FetchAzureDataLakeStorage processor

Posted by GitBox <gi...@apache.org>.
lordgamez commented on a change in pull request #1221:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1221#discussion_r783035680



##########
File path: extensions/azure/storage/AzureDataLakeStorage.cpp
##########
@@ -61,4 +61,29 @@ bool AzureDataLakeStorage::deleteFile(const storage::DeleteAzureDataLakeStorageP
   }
 }
 
+std::optional<uint64_t> AzureDataLakeStorage::fetchFile(const FetchAzureDataLakeStorageParameters& params, io::BaseStream& stream) {
+  try {
+    auto fetch_res = data_lake_storage_client_->fetchFile(params);
+
+    std::array<uint8_t, 4096> buffer;
+    size_t write_size = 0;
+    if (fetch_res.FileSize < 0) return 0;
+    while (write_size < gsl::narrow<uint64_t>(fetch_res.FileSize)) {
+      const auto next_write_size = (std::min)(gsl::narrow<size_t>(fetch_res.FileSize) - write_size, buffer.size());
+      if (!fetch_res.Body->Read(buffer.data(), gsl::narrow<std::streamsize>(next_write_size))) {
+        return -1;
+      }
+      const auto ret = stream.write(buffer.data(), next_write_size);
+      if (io::isError(ret)) {
+        return -1;
+      }
+      write_size += next_write_size;
+    }

Review comment:
       Good idea, saves us some code duplication, updated in 714793593b09ed8b33ac7db2547c74258467e748




-- 
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-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] lordgamez commented on a change in pull request #1221: MINIFICPP-1630 Create FetchAzureDataLakeStorage processor

Posted by GitBox <gi...@apache.org>.
lordgamez commented on a change in pull request #1221:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1221#discussion_r783034523



##########
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 714793593b09ed8b33ac7db2547c74258467e748




-- 
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-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] lordgamez commented on a change in pull request #1221: MINIFICPP-1630 Create FetchAzureDataLakeStorage processor

Posted by GitBox <gi...@apache.org>.
lordgamez commented on a change in pull request #1221:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1221#discussion_r783034723



##########
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 714793593b09ed8b33ac7db2547c74258467e748

##########
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 714793593b09ed8b33ac7db2547c74258467e748




-- 
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-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] lordgamez commented on a change in pull request #1221: MINIFICPP-1630 Create FetchAzureDataLakeStorage processor

Posted by GitBox <gi...@apache.org>.
lordgamez commented on a change in pull request #1221:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1221#discussion_r783034341



##########
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 714793593b09ed8b33ac7db2547c74258467e748




-- 
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-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1221: MINIFICPP-1630 Create FetchAzureDataLakeStorage processor

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1221:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1221#discussion_r782222859



##########
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:
       It would be nice to declare the preconditions that `context` and `session` must be valid.
   ```suggestion
   void FetchAzureDataLakeStorage::onTrigger(const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::ProcessSession>& session) {
     gsl_Expects(context && session);
   ```

##########
File path: extensions/azure/storage/AzureDataLakeStorage.cpp
##########
@@ -61,4 +61,29 @@ bool AzureDataLakeStorage::deleteFile(const storage::DeleteAzureDataLakeStorageP
   }
 }
 
+std::optional<uint64_t> AzureDataLakeStorage::fetchFile(const FetchAzureDataLakeStorageParameters& params, io::BaseStream& stream) {
+  try {
+    auto fetch_res = data_lake_storage_client_->fetchFile(params);
+
+    std::array<uint8_t, 4096> buffer;
+    size_t write_size = 0;
+    if (fetch_res.FileSize < 0) return 0;
+    while (write_size < gsl::narrow<uint64_t>(fetch_res.FileSize)) {
+      const auto next_write_size = (std::min)(gsl::narrow<size_t>(fetch_res.FileSize) - write_size, buffer.size());
+      if (!fetch_res.Body->Read(buffer.data(), gsl::narrow<std::streamsize>(next_write_size))) {
+        return -1;
+      }
+      const auto ret = stream.write(buffer.data(), next_write_size);
+      if (io::isError(ret)) {
+        return -1;
+      }
+      write_size += next_write_size;
+    }

Review comment:
       Not sure if it's worth the extra effort, but if you could wrap the download result in an `InputStream`, then you could reuse `internal::pipe` (which has similar code to this function) or just return the stream directly.]
   It would also probably be easier to mock `fetchFile`.

##########
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:
       There is no reason for this function to necessitate shared ownership. The first parameter should preferably be of type `const core::ProcessContext&`. The second one needs to be a `shared_ptr` due to `getProperty` (also unnecessarily) requiring a `shared_ptr` parameter.




-- 
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-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] lordgamez commented on a change in pull request #1221: MINIFICPP-1630 Create FetchAzureDataLakeStorage processor

Posted by GitBox <gi...@apache.org>.
lordgamez commented on a change in pull request #1221:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1221#discussion_r768808670



##########
File path: extensions/azure/storage/AzureDataLakeStorage.cpp
##########
@@ -61,4 +61,29 @@ bool AzureDataLakeStorage::deleteFile(const storage::DeleteAzureDataLakeStorageP
   }
 }
 
+std::optional<uint64_t> AzureDataLakeStorage::fetchFile(const FetchAzureDataLakeStorageParameters& params, io::BaseStream& stream) {
+  try {
+    auto fetch_res = data_lake_storage_client_->fetchFile(params);
+
+    std::vector<uint8_t> buffer(4096);

Review comment:
       Updated in 172d2a4f893238d7a9818b812cc0b7b671c3cd0b

##########
File path: extensions/azure/storage/AzureDataLakeStorage.cpp
##########
@@ -61,4 +61,29 @@ bool AzureDataLakeStorage::deleteFile(const storage::DeleteAzureDataLakeStorageP
   }
 }
 
+std::optional<uint64_t> AzureDataLakeStorage::fetchFile(const FetchAzureDataLakeStorageParameters& params, io::BaseStream& stream) {
+  try {
+    auto fetch_res = data_lake_storage_client_->fetchFile(params);
+
+    std::vector<uint8_t> buffer(4096);
+    size_t write_size = 0;
+    if (fetch_res.FileSize < 0) return 0;
+    while (write_size < gsl::narrow<uint64_t>(fetch_res.FileSize)) {
+      const auto next_write_size = (std::min)(gsl::narrow<size_t>(fetch_res.FileSize) - write_size, size_t{4096});

Review comment:
       Updated in 172d2a4f893238d7a9818b812cc0b7b671c3cd0b

##########
File path: extensions/azure/processors/FetchAzureDataLakeStorage.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ * @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) {
+  logger_->log_debug("FetchAzureDataLakeStorage onTrigger");
+  std::shared_ptr<core::FlowFile> flow_file = session->get();
+  if (!flow_file) {
+    context->yield();
+    return;
+  }
+
+  const auto params = buildFetchParameters(context, flow_file);
+  if (!params) {
+    session->transfer(flow_file, Failure);
+    return;
+  }
+
+  WriteCallback callback(azure_data_lake_storage_, *params, logger_);
+  session->write(flow_file, &callback);
+
+  if (callback.getResult() == std::nullopt) {
+    logger_->log_error("Failed to fetch file '%s' from Azure Data Lake storage", params->filename);
+    session->transfer(flow_file, Failure);

Review comment:
       Good point, I think it's better to have the original flowfile forwarded to the failure relationship and as I checked it works that way in NiFi too. I updated the processor to create a new flowfile for the success case and forward the original in failure cases in 172d2a4f893238d7a9818b812cc0b7b671c3cd0b




-- 
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-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1221: MINIFICPP-1630 Create FetchAzureDataLakeStorage processor

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1221:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1221#discussion_r767853016



##########
File path: extensions/azure/processors/FetchAzureDataLakeStorage.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ * @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) {
+  logger_->log_debug("FetchAzureDataLakeStorage onTrigger");
+  std::shared_ptr<core::FlowFile> flow_file = session->get();
+  if (!flow_file) {
+    context->yield();
+    return;
+  }
+
+  const auto params = buildFetchParameters(context, flow_file);
+  if (!params) {
+    session->transfer(flow_file, Failure);
+    return;
+  }
+
+  WriteCallback callback(azure_data_lake_storage_, *params, logger_);
+  session->write(flow_file, &callback);
+
+  if (callback.getResult() == std::nullopt) {
+    logger_->log_error("Failed to fetch file '%s' from Azure Data Lake storage", params->filename);
+    session->transfer(flow_file, Failure);

Review comment:
       when the fetch fails, we return 0 in the `WriteCallback` which sets the flowfile's size to 0, then we send this flowfile to Failure, do we want this, or do we want to forward the original flowfile to failure (and maybe create a new one for the fetched content)?




-- 
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-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] lordgamez commented on a change in pull request #1221: MINIFICPP-1630 Create FetchAzureDataLakeStorage processor

Posted by GitBox <gi...@apache.org>.
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-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] fgerlits closed pull request #1221: MINIFICPP-1630 Create FetchAzureDataLakeStorage processor

Posted by GitBox <gi...@apache.org>.
fgerlits closed pull request #1221:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1221


   


-- 
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-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] adam-markovics commented on a change in pull request #1221: MINIFICPP-1630 Create FetchAzureDataLakeStorage processor

Posted by GitBox <gi...@apache.org>.
adam-markovics commented on a change in pull request #1221:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1221#discussion_r782221327



##########
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:
       Field number_of_retries_ is never set.

##########
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:
       I think success_contents is a wrong name here




-- 
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-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1221: MINIFICPP-1630 Create FetchAzureDataLakeStorage processor

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1221:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1221#discussion_r767837675



##########
File path: extensions/azure/storage/AzureDataLakeStorage.cpp
##########
@@ -61,4 +61,29 @@ bool AzureDataLakeStorage::deleteFile(const storage::DeleteAzureDataLakeStorageP
   }
 }
 
+std::optional<uint64_t> AzureDataLakeStorage::fetchFile(const FetchAzureDataLakeStorageParameters& params, io::BaseStream& stream) {
+  try {
+    auto fetch_res = data_lake_storage_client_->fetchFile(params);
+
+    std::vector<uint8_t> buffer(4096);
+    size_t write_size = 0;
+    if (fetch_res.FileSize < 0) return 0;
+    while (write_size < gsl::narrow<uint64_t>(fetch_res.FileSize)) {
+      const auto next_write_size = (std::min)(gsl::narrow<size_t>(fetch_res.FileSize) - write_size, size_t{4096});

Review comment:
       `buffer.size()` could be used here




-- 
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-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1221: MINIFICPP-1630 Create FetchAzureDataLakeStorage processor

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1221:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1221#discussion_r767837072



##########
File path: extensions/azure/storage/AzureDataLakeStorage.cpp
##########
@@ -61,4 +61,29 @@ bool AzureDataLakeStorage::deleteFile(const storage::DeleteAzureDataLakeStorageP
   }
 }
 
+std::optional<uint64_t> AzureDataLakeStorage::fetchFile(const FetchAzureDataLakeStorageParameters& params, io::BaseStream& stream) {
+  try {
+    auto fetch_res = data_lake_storage_client_->fetchFile(params);
+
+    std::vector<uint8_t> buffer(4096);

Review comment:
       we could use an `std::array` here




-- 
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-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] lordgamez commented on a change in pull request #1221: MINIFICPP-1630 Create FetchAzureDataLakeStorage processor

Posted by GitBox <gi...@apache.org>.
lordgamez commented on a change in pull request #1221:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1221#discussion_r783098509



##########
File path: extensions/azure/storage/AzureDataLakeStorage.cpp
##########
@@ -61,4 +61,29 @@ bool AzureDataLakeStorage::deleteFile(const storage::DeleteAzureDataLakeStorageP
   }
 }
 
+std::optional<uint64_t> AzureDataLakeStorage::fetchFile(const FetchAzureDataLakeStorageParameters& params, io::BaseStream& stream) {
+  try {
+    auto fetch_res = data_lake_storage_client_->fetchFile(params);
+
+    std::array<uint8_t, 4096> buffer;
+    size_t write_size = 0;
+    if (fetch_res.FileSize < 0) return 0;
+    while (write_size < gsl::narrow<uint64_t>(fetch_res.FileSize)) {
+      const auto next_write_size = (std::min)(gsl::narrow<size_t>(fetch_res.FileSize) - write_size, buffer.size());
+      if (!fetch_res.Body->Read(buffer.data(), gsl::narrow<std::streamsize>(next_write_size))) {
+        return -1;
+      }
+      const auto ret = stream.write(buffer.data(), next_write_size);
+      if (io::isError(ret)) {
+        return -1;
+      }
+      write_size += next_write_size;
+    }

Review comment:
       I see your point, updated in 0f01db34bb1cc4576c7ed709dd1b9ef71801b43d




-- 
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-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1221: MINIFICPP-1630 Create FetchAzureDataLakeStorage processor

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1221:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1221#discussion_r783107526



##########
File path: extensions/azure/storage/AzureDataLakeStorageClient.cpp
##########
@@ -30,30 +34,35 @@ 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) {
     logger_->log_debug("Azure Data Lake Storge client credentials have not changed, no need to reset client");
     return;
   }
 
+  Azure::Storage::Files::DataLake::DataLakeClientOptions options;
+  if (number_of_retries) {
+    options.Retry.MaxRetries = *number_of_retries;
+  }
+
   if (credentials.getUseManagedIdentityCredentials()) {
     auto datalake_service_client = Azure::Storage::Files::DataLake::DataLakeServiceClient(
-      "https://" + credentials.getStorageAccountName() + ".dfs." + credentials.getEndpointSuffix(), std::make_shared<Azure::Identity::ManagedIdentityCredential>());
-
+      "https://" + credentials.getStorageAccountName() + ".dfs." + credentials.getEndpointSuffix(), std::make_shared<Azure::Identity::ManagedIdentityCredential>(), options);
     client_ = std::make_unique<Azure::Storage::Files::DataLake::DataLakeFileSystemClient>(datalake_service_client.GetFileSystemClient(file_system_name));
     logger_->log_debug("Azure Data Lake Storge client has been reset with new managed identity credentials.");
   } else {
     client_ = std::make_unique<Azure::Storage::Files::DataLake::DataLakeFileSystemClient>(
-    Azure::Storage::Files::DataLake::DataLakeFileSystemClient::CreateFromConnectionString(credentials.buildConnectionString(), file_system_name));
+      Azure::Storage::Files::DataLake::DataLakeFileSystemClient::CreateFromConnectionString(credentials.buildConnectionString(), file_system_name, options));

Review comment:
       Continuation indentation should be 4 spaces.
   ```suggestion
           Azure::Storage::Files::DataLake::DataLakeFileSystemClient::CreateFromConnectionString(credentials.buildConnectionString(), file_system_name, options));
   ```

##########
File path: extensions/azure/storage/AzureDataLakeStorageClient.cpp
##########
@@ -30,30 +34,35 @@ 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) {
     logger_->log_debug("Azure Data Lake Storge client credentials have not changed, no need to reset client");
     return;
   }
 
+  Azure::Storage::Files::DataLake::DataLakeClientOptions options;
+  if (number_of_retries) {
+    options.Retry.MaxRetries = *number_of_retries;
+  }
+
   if (credentials.getUseManagedIdentityCredentials()) {
     auto datalake_service_client = Azure::Storage::Files::DataLake::DataLakeServiceClient(
-      "https://" + credentials.getStorageAccountName() + ".dfs." + credentials.getEndpointSuffix(), std::make_shared<Azure::Identity::ManagedIdentityCredential>());
-
+      "https://" + credentials.getStorageAccountName() + ".dfs." + credentials.getEndpointSuffix(), std::make_shared<Azure::Identity::ManagedIdentityCredential>(), options);

Review comment:
       same here




-- 
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-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1221: MINIFICPP-1630 Create FetchAzureDataLakeStorage processor

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1221:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1221#discussion_r783049664



##########
File path: extensions/azure/storage/AzureDataLakeStorage.cpp
##########
@@ -61,4 +61,29 @@ bool AzureDataLakeStorage::deleteFile(const storage::DeleteAzureDataLakeStorageP
   }
 }
 
+std::optional<uint64_t> AzureDataLakeStorage::fetchFile(const FetchAzureDataLakeStorageParameters& params, io::BaseStream& stream) {
+  try {
+    auto fetch_res = data_lake_storage_client_->fetchFile(params);
+
+    std::array<uint8_t, 4096> buffer;
+    size_t write_size = 0;
+    if (fetch_res.FileSize < 0) return 0;
+    while (write_size < gsl::narrow<uint64_t>(fetch_res.FileSize)) {
+      const auto next_write_size = (std::min)(gsl::narrow<size_t>(fetch_res.FileSize) - write_size, buffer.size());
+      if (!fetch_res.Body->Read(buffer.data(), gsl::narrow<std::streamsize>(next_write_size))) {
+        return -1;
+      }
+      const auto ret = stream.write(buffer.data(), next_write_size);
+      if (io::isError(ret)) {
+        return -1;
+      }
+      write_size += next_write_size;
+    }

Review comment:
       I think it would be better if `fetchFile` itself returned an `InputStream`. This way mocking it would be as easy as returning some data in a `BufferStream`.




-- 
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-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org