lordgamez commented on a change in pull request #1158:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1158#discussion_r710240996



##########
File path: extensions/azure/storage/AzureDataLakeStorage.h
##########
@@ -0,0 +1,57 @@
+/**
+ * @file AzureDataLakeStorage.h
+ * AzureDataLakeStorage class declaration
+ *
+ * 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.
+ */
+#pragma once
+
+#include <string>
+#include <vector>
+#include <memory>
+#include <optional>
+#include <utility>
+
+#include "core/logging/Logger.h"
+#include "core/logging/LoggerConfiguration.h"
+#include "AzureDataLakeStorageClient.h"
+
+namespace org::apache::nifi::minifi::azure::storage {
+
+enum class UploadResultCode {
+  SUCCESS,
+  FILE_ALREADY_EXISTS,
+  FAILURE
+};
+
+struct UploadDataLakeStorageResult {
+  UploadResultCode result_code = UploadResultCode::SUCCESS;
+  std::string primary_uri;
+};
+
+class AzureDataLakeStorage {
+ public:
+  AzureDataLakeStorage();
+  explicit AzureDataLakeStorage(std::unique_ptr<DataLakeStorageClient> 
data_lake_storage_client);
+
+  storage::UploadDataLakeStorageResult uploadFile(const 
storage::PutAzureDataLakeStorageParameters& params, const uint8_t* buffer, 
std::size_t buffer_size);
+
+ private:
+  std::shared_ptr<logging::Logger> 
logger_{logging::LoggerFactory<AzureDataLakeStorage>::getLogger()};
+  std::unique_ptr<DataLakeStorageClient> data_lake_storage_client_;

Review comment:
       Updated in f02f86cd63fd4d08e8a125d469ada637bd7635fe

##########
File path: extensions/azure/processors/PutAzureDataLakeStorage.cpp
##########
@@ -0,0 +1,167 @@
+/**
+ * @file PutAzureDataLakeStorage.cpp
+ * PutAzureDataLakeStorage 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 "PutAzureDataLakeStorage.h"
+
+#include "utils/ProcessorConfigUtils.h"
+#include "utils/gsl.h"
+#include "controllerservices/AzureStorageCredentialsService.h"
+
+namespace org::apache::nifi::minifi::azure::processors {
+
+const core::Property PutAzureDataLakeStorage::FilesystemName(
+    core::PropertyBuilder::createProperty("Filesystem Name")
+      ->withDescription("Name of the Azure Storage File System. It is assumed 
to be already existing.")
+      ->supportsExpressionLanguage(true)
+      ->isRequired(true)
+      ->build());
+const core::Property PutAzureDataLakeStorage::DirectoryName(
+    core::PropertyBuilder::createProperty("Directory Name")
+      ->withDescription("Name of the Azure Storage Directory. The Directory 
Name cannot contain a leading '/'. "
+                        "If left empty it designates the root directory. The 
directory will be created if not already existing.")
+      ->supportsExpressionLanguage(true)
+      ->build());
+const core::Property PutAzureDataLakeStorage::FileName(
+    core::PropertyBuilder::createProperty("File Name")
+      ->withDescription("The filename to be uploaded. If left empty the 
filename attribute will be used by default.")
+      ->supportsExpressionLanguage(true)
+      ->build());
+const core::Property PutAzureDataLakeStorage::ConflictResolutionStrategy(
+    core::PropertyBuilder::createProperty("Conflict Resolution Strategy")
+      ->withDescription("Indicates what should happen when a file with the 
same name already exists in the output directory.")
+      ->isRequired(true)
+      
->withDefaultValue<std::string>(toString(FileExistsResolutionStrategy::FAIL_FLOW))
+      
->withAllowableValues<std::string>(FileExistsResolutionStrategy::values())
+      ->build());
+
+const core::Relationship PutAzureDataLakeStorage::Success("success", "Files 
that have been successfully written to Azure storage are transferred to this 
relationship");
+const core::Relationship PutAzureDataLakeStorage::Failure("failure", "Files 
that could not be written to Azure storage for some reason are transferred to 
this relationship");
+
+void PutAzureDataLakeStorage::initialize() {
+  // Set the supported properties
+  updateSupportedProperties({
+    FilesystemName,
+    DirectoryName,
+    FileName,
+    ConflictResolutionStrategy
+  });
+  // Set the supported relationships
+  setSupportedRelationships({
+    Success,
+    Failure
+  });
+}
+
+void PutAzureDataLakeStorage::onSchedule(const 
std::shared_ptr<core::ProcessContext>& context, const 
std::shared_ptr<core::ProcessSessionFactory>& /*sessionFactory*/) {
+  connection_string_ = getConnectionStringFromControllerService(context);
+  if (connection_string_.empty()) {
+    throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Azure Storage Credentials 
Service property missing or invalid");
+  }
+
+  conflict_resolution_strategy_ = FileExistsResolutionStrategy::parse(
+    utils::parsePropertyWithAllowableValuesOrThrow(*context, 
ConflictResolutionStrategy.getName(), 
FileExistsResolutionStrategy::values()).c_str());
+}
+
+std::optional<storage::PutAzureDataLakeStorageParameters> 
PutAzureDataLakeStorage::buildUploadParameters(
+    const std::shared_ptr<core::ProcessContext>& context, const 
std::shared_ptr<core::FlowFile>& flow_file) {
+  storage::PutAzureDataLakeStorageParameters params;
+  params.connection_string = connection_string_;
+  params.replace_file = conflict_resolution_strategy_ == 
FileExistsResolutionStrategy::REPLACE_FILE;
+
+  if (!context->getProperty(FilesystemName, params.file_system_name, 
flow_file) || params.file_system_name.empty()) {
+    logger_->log_error("Filesystem Name '%s' is invalid or empty!", 
params.file_system_name);
+    return std::nullopt;
+  }
+
+  context->getProperty(DirectoryName, params.directory_name, flow_file);
+
+  context->getProperty(FileName, params.filename, flow_file);
+  if (params.filename.empty() && (!flow_file->getAttribute("filename", 
params.filename) || params.filename.empty())) {
+    logger_->log_error("No File Name is set and default object key 'filename' 
attribute could not be found!");
+    return std::nullopt;
+  }
+
+  return params;
+}
+
+void PutAzureDataLakeStorage::onTrigger(const 
std::shared_ptr<core::ProcessContext>& context, const 
std::shared_ptr<core::ProcessSession>& session) {
+  logger_->log_debug("PutAzureDataLakeStorage onTrigger");
+  std::shared_ptr<core::FlowFile> flow_file = session->get();
+  if (!flow_file) {
+    context->yield();
+    return;
+  }
+
+  const auto params = buildUploadParameters(context, flow_file);
+  if (!params) {
+    session->transfer(flow_file, Failure);
+    return;
+  }
+
+  PutAzureDataLakeStorage::ReadCallback callback(flow_file->getSize(), 
azure_data_lake_storage_, *params, logger_);
+  session->read(flow_file, &callback);
+  auto result = callback.getResult();
+  if (result.result_code == storage::UploadResultCode::FILE_ALREADY_EXISTS) {
+    gsl_Expects(conflict_resolution_strategy_ != 
FileExistsResolutionStrategy::REPLACE_FILE);
+    if (conflict_resolution_strategy_ == 
FileExistsResolutionStrategy::FAIL_FLOW) {
+      logger_->log_error("Failed to upload file '%s/%s' to filesystem '%s' on 
Azure Data Lake storage because file already exists",
+        params->directory_name, params->filename, params->file_system_name);
+      session->transfer(flow_file, Failure);
+      return;
+    } else if (conflict_resolution_strategy_ == 
FileExistsResolutionStrategy::IGNORE_REQUEST) {
+      logger_->log_debug("Upload of file '%s/%s' was ignored because it 
already exits in filesystem '%s' on Azure Data Lake Storage",
+        params->directory_name, params->filename, params->file_system_name);
+      session->transfer(flow_file, Success);
+      return;
+    }
+  } else if (result.result_code == storage::UploadResultCode::FAILURE) {
+    logger_->log_error("Failed to upload file '%s/%s' to filesystem '%s' on 
Azure Data Lake storage", params->directory_name, params->filename, 
params->file_system_name);
+    session->transfer(flow_file, Failure);
+  } else {
+    session->putAttribute(flow_file, "azure.filesystem", 
params->file_system_name);
+    session->putAttribute(flow_file, "azure.directory", 
params->directory_name);
+    session->putAttribute(flow_file, "azure.filename", params->filename);
+    session->putAttribute(flow_file, "azure.primaryUri", result.primary_uri);
+    session->putAttribute(flow_file, "azure.length", 
std::to_string(flow_file->getSize()));
+    logger_->log_debug("Successfully uploaded file '%s/%s' to filesystem '%s' 
on Azure Data Lake storage", params->directory_name, params->filename, 
params->file_system_name);
+    session->transfer(flow_file, Success);
+  }
+}
+
+PutAzureDataLakeStorage::ReadCallback::ReadCallback(
+      uint64_t flow_size, storage::AzureDataLakeStorage& 
azure_data_lake_storage, const storage::PutAzureDataLakeStorageParameters& 
params, std::shared_ptr<logging::Logger> logger)
+  : flow_size_(flow_size),
+    azure_data_lake_storage_(azure_data_lake_storage),
+    params_(params),
+    logger_(std::move(logger)) {
+}
+
+int64_t PutAzureDataLakeStorage::ReadCallback::process(const 
std::shared_ptr<io::BaseStream>& stream) {
+  std::vector<uint8_t> buffer;
+  int read_ret = stream->read(buffer, flow_size_);
+  if (io::isError(read_ret)) {
+    return -1;
+  }

Review comment:
       Updated in f02f86cd63fd4d08e8a125d469ada637bd7635fe

##########
File path: extensions/azure/processors/AzureStorageProcessorBase.cpp
##########
@@ -0,0 +1,56 @@
+/**
+ * @file AzureStorageProcessorBase.cpp
+ * AzureStorageProcessorBase 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 "AzureStorageProcessorBase.h"
+
+#include <memory>
+#include <string>
+
+#include "controllerservices/AzureStorageCredentialsService.h"
+
+namespace org::apache::nifi::minifi::azure::processors {
+
+const core::Property AzureStorageProcessorBase::AzureStorageCredentialsService(
+  core::PropertyBuilder::createProperty("Azure Storage Credentials Service")
+    ->withDescription("Name of the Azure Storage Credentials Service used to 
retrieve the connection string from.")
+    ->build());
+
+std::string 
AzureStorageProcessorBase::getConnectionStringFromControllerService(const 
std::shared_ptr<core::ProcessContext> &context) const {
+  std::string service_name;
+  if (!context->getProperty(AzureStorageCredentialsService.getName(), 
service_name) || service_name.empty()) {
+    return "";
+  }
+
+  std::shared_ptr<core::controller::ControllerService> service = 
context->getControllerService(service_name);
+  if (nullptr == service) {
+    logger_->log_error("Azure Storage credentials service with name: '%s' 
could not be found", service_name.c_str());

Review comment:
       Updated in f02f86cd63fd4d08e8a125d469ada637bd7635fe

##########
File path: extensions/azure/processors/PutAzureBlobStorage.cpp
##########
@@ -90,14 +81,13 @@ const core::Relationship 
PutAzureBlobStorage::Failure("failure", "Unsuccessful o
 
 void PutAzureBlobStorage::initialize() {
   // Set the supported properties
-  setSupportedProperties({
+  updateSupportedProperties({

Review comment:
       Updated in f02f86cd63fd4d08e8a125d469ada637bd7635fe

##########
File path: cmake/BundledAzureSdkCpp.cmake
##########
@@ -54,7 +53,7 @@ function(use_bundled_libazure SOURCE_DIR BINARY_DIR)
     ExternalProject_Add(
             azure-sdk-cpp-external
             GIT_REPOSITORY "https://github.com/Azure/azure-sdk-for-cpp.git";
-            GIT_TAG "azure-storage-blobs_12.0.0-beta.7"
+            GIT_TAG "azure-storage-files-datalake_12.2.0"

Review comment:
       Updated in f02f86cd63fd4d08e8a125d469ada637bd7635fe




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org

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


Reply via email to