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/14 15:57:20 UTC

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

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