arpadboda commented on a change in pull request #931: URL: https://github.com/apache/nifi-minifi-cpp/pull/931#discussion_r521445242
########## File path: extensions/aws/processors/DeleteS3Object.cpp ########## @@ -0,0 +1,92 @@ +/** + * @file DeleteS3Object.cpp + * DeleteS3Object 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 "DeleteS3Object.h" + +#include <set> +#include <memory> + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace aws { +namespace processors { + +const core::Property DeleteS3Object::Version( + core::PropertyBuilder::createProperty("Version") + ->withDescription("The Version of the Object to delete") + ->supportsExpressionLanguage(true) + ->build()); + +const core::Relationship DeleteS3Object::Success("success", "FlowFiles are routed to success relationship"); +const core::Relationship DeleteS3Object::Failure("failure", "FlowFiles are routed to failure relationship"); + +void DeleteS3Object::initialize() { + // Set the supported properties + std::set<core::Property> properties(S3Processor::getSupportedProperties()); + properties.insert(Version); + setSupportedProperties(properties); + // Set the supported relationships + std::set<core::Relationship> relationships; + relationships.insert(Failure); + relationships.insert(Success); + setSupportedRelationships(relationships); Review comment: Just fancy, you can do it using init list: ``` setSupportedRelationships({Failure, Success}); ``` ########## File path: extensions/aws/processors/DeleteS3Object.cpp ########## @@ -0,0 +1,92 @@ +/** + * @file DeleteS3Object.cpp + * DeleteS3Object 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 "DeleteS3Object.h" + +#include <set> +#include <memory> + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace aws { +namespace processors { + +const core::Property DeleteS3Object::Version( + core::PropertyBuilder::createProperty("Version") + ->withDescription("The Version of the Object to delete") + ->supportsExpressionLanguage(true) + ->build()); + +const core::Relationship DeleteS3Object::Success("success", "FlowFiles are routed to success relationship"); +const core::Relationship DeleteS3Object::Failure("failure", "FlowFiles are routed to failure relationship"); + +void DeleteS3Object::initialize() { + // Set the supported properties + std::set<core::Property> properties(S3Processor::getSupportedProperties()); + properties.insert(Version); + setSupportedProperties(properties); + // Set the supported relationships + std::set<core::Relationship> relationships; + relationships.insert(Failure); + relationships.insert(Success); + setSupportedRelationships(relationships); +} + +bool DeleteS3Object::getExpressionLanguageSupportedProperties( + const std::shared_ptr<core::ProcessContext> &context, + const std::shared_ptr<core::FlowFile> &flow_file) { + if (!S3Processor::getExpressionLanguageSupportedProperties(context, flow_file)) { + return false; + } + + context->getProperty(Version, version_, flow_file); + logger_->log_debug("DeleteS3Object: Version [%s]", version_); + return true; +} + +void DeleteS3Object::onTrigger(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSession> &session) { + logger_->log_debug("DeleteS3Object onTrigger"); + std::shared_ptr<core::FlowFile> flow_file = session->get(); + if (!flow_file) { + return; Review comment: yield can be applied in this case as well ########## File path: extensions/aws/processors/DeleteS3Object.cpp ########## @@ -0,0 +1,92 @@ +/** + * @file DeleteS3Object.cpp + * DeleteS3Object 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 "DeleteS3Object.h" + +#include <set> +#include <memory> + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace aws { +namespace processors { + +const core::Property DeleteS3Object::Version( + core::PropertyBuilder::createProperty("Version") + ->withDescription("The Version of the Object to delete") + ->supportsExpressionLanguage(true) + ->build()); + +const core::Relationship DeleteS3Object::Success("success", "FlowFiles are routed to success relationship"); +const core::Relationship DeleteS3Object::Failure("failure", "FlowFiles are routed to failure relationship"); + +void DeleteS3Object::initialize() { + // Set the supported properties + std::set<core::Property> properties(S3Processor::getSupportedProperties()); + properties.insert(Version); + setSupportedProperties(properties); + // Set the supported relationships + std::set<core::Relationship> relationships; + relationships.insert(Failure); + relationships.insert(Success); + setSupportedRelationships(relationships); +} + +bool DeleteS3Object::getExpressionLanguageSupportedProperties( + const std::shared_ptr<core::ProcessContext> &context, + const std::shared_ptr<core::FlowFile> &flow_file) { + if (!S3Processor::getExpressionLanguageSupportedProperties(context, flow_file)) { + return false; + } + + context->getProperty(Version, version_, flow_file); + logger_->log_debug("DeleteS3Object: Version [%s]", version_); + return true; +} + +void DeleteS3Object::onTrigger(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSession> &session) { + logger_->log_debug("DeleteS3Object onTrigger"); + std::shared_ptr<core::FlowFile> flow_file = session->get(); + if (!flow_file) { + return; + } + + if (!getExpressionLanguageSupportedProperties(context, flow_file)) { + context->yield(); + return; + } + + if (s3_wrapper_->deleteObject(bucket_, object_key_, version_)) { + logger_->log_debug("Successfully deleted S3 object %s from bucket %s", object_key_, bucket_); + session->transfer(flow_file, Success); + } else { + logger_->log_debug("Failed to delete S3 object %s from bucket %s", object_key_, bucket_); Review comment: I think this should be a bit more verbose than debug. Info at least, but I would consider warning as well. ########## File path: extensions/aws/s3/S3Wrapper.cpp ########## @@ -38,8 +38,24 @@ minifi::utils::optional<Aws::S3::Model::PutObjectResult> S3Wrapper::sendPutObjec logger_->log_info("Added S3 object %s to bucket %s", request.GetKey(), request.GetBucket()); return outcome.GetResultWithOwnership(); } else { - logger_->log_error("PutS3Object failed with the following: '%s'", outcome.GetError().GetMessage()); - return minifi::utils::nullopt; + logger_->log_error("PutS3Object failed with the following: '%s'", outcome.GetError().GetMessage()); + return minifi::utils::nullopt; + } +} + +bool S3Wrapper::sendDeleteObjectRequest(const Aws::S3::Model::DeleteObjectRequest& request) { + Aws::S3::S3Client s3_client(credentials_, client_config_); + Aws::S3::Model::DeleteObjectOutcome outcome = s3_client.DeleteObject(request); + + if (outcome.IsSuccess()) { + logger_->log_info("Deleted S3 object %s from bucket %s", request.GetKey(), request.GetBucket()); + return true; + } else if (outcome.GetError().GetErrorType() == Aws::S3::S3Errors::NO_SUCH_KEY) { + logger_->log_info("S3 object %s was not found in bucket %s", request.GetKey(), request.GetBucket()); Review comment: This case is strange. Can be a result of a misconfiguration, too. Not sure if we should handle it as success. ---------------------------------------------------------------- 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: [email protected]
