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



##########
File path: extensions/aws/processors/FetchS3Object.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ * @file FetchS3Object.cpp
+ * FetchS3Object 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 "FetchS3Object.h"
+
+#include <set>
+#include <memory>
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace aws {
+namespace processors {
+
+const core::Property FetchS3Object::Version(
+  core::PropertyBuilder::createProperty("Version")
+    ->withDescription("The Version of the Object to download")
+    ->supportsExpressionLanguage(true)
+    ->build());
+const core::Property FetchS3Object::RequesterPays(
+  core::PropertyBuilder::createProperty("Requester Pays")
+    ->isRequired(true)
+    ->withDefaultValue<bool>(false)
+    ->withDescription("If true, indicates that the requester consents to pay 
any charges associated with retrieving "
+                      "objects from the S3 bucket. This sets the 
'x-amz-request-payer' header to 'requester'.")
+    ->build());
+
+const core::Relationship FetchS3Object::Success("success", "FlowFiles are 
routed to success relationship");
+const core::Relationship FetchS3Object::Failure("failure", "FlowFiles are 
routed to failure relationship");
+
+void FetchS3Object::initialize() {
+  // Add new supported properties
+  updateSupportedProperties({Version, RequesterPays});
+  // Set the supported relationships
+  setSupportedRelationships({Failure, Success});
+}
+
+void FetchS3Object::onSchedule(const std::shared_ptr<core::ProcessContext> 
&context, const std::shared_ptr<core::ProcessSessionFactory> &sessionFactory) {
+  S3Processor::onSchedule(context, sessionFactory);
+
+  context->getProperty(RequesterPays.getName(), 
get_object_params_.requester_pays);
+  logger_->log_debug("FetchS3Object: RequesterPays [%s]", 
get_object_params_.requester_pays ? "true" : "false");
+}
+
+bool FetchS3Object::getExpressionLanguageSupportedProperties(
+    const std::shared_ptr<core::ProcessContext> &context,
+    const std::shared_ptr<core::FlowFile> &flow_file) {
+  if (!S3Processor::getExpressionLanguageSupportedProperties(context, 
flow_file)) {
+    return false;
+  }
+  get_object_params_.bucket = std::move(bucket_);
+  get_object_params_.object_key = std::move(object_key_);
+
+  context->getProperty(Version, get_object_params_.version, flow_file);
+  logger_->log_debug("FetchS3Object: Version [%s]", 
get_object_params_.version);
+  return true;
+}
+
+void FetchS3Object::onTrigger(const std::shared_ptr<core::ProcessContext> 
&context, const std::shared_ptr<core::ProcessSession> &session) {
+  logger_->log_debug("FetchS3Object onTrigger");
+  std::shared_ptr<core::FlowFile> flow_file = session->get();
+  if (!flow_file) {
+    context->yield();
+    return;
+  }
+
+  if (!getExpressionLanguageSupportedProperties(context, flow_file)) {
+    session->transfer(flow_file, Failure);
+    return;
+  }
+
+  WriteCallback callback(flow_file->getSize(), get_object_params_, 
s3_wrapper_.get());
+  session->write(flow_file, &callback);

Review comment:
       After checking the code there seems to be no way for this to throw. The 
callback can only fail and return 0 if failure happens. The write may throw an 
exception only if the return value of the callback is less than 0.




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

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


Reply via email to