-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MINIFICPP-2146 Add support for SMB networking protocol
MINIFICPP-2147 PutSmb MINIFICPP-2148 FetchSmb MINIFICPP-2150 ListSmb
- Loading branch information
1 parent
fbe2176
commit 8dc4bb2
Showing
55 changed files
with
2,532 additions
and
764 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
if (NOT (WIN32 AND ENABLE_SMB)) | ||
return() | ||
endif() | ||
|
||
include(${CMAKE_SOURCE_DIR}/extensions/ExtensionHeader.txt) | ||
|
||
file(GLOB SOURCES "*.cpp") | ||
|
||
add_library(minifi-smb SHARED ${SOURCES}) | ||
target_link_libraries(minifi-smb ${LIBMINIFI} Mpr) | ||
target_include_directories(minifi-smb PRIVATE BEFORE "${CMAKE_SOURCE_DIR}/extensions/standard-processors") | ||
|
||
register_extension(minifi-smb "SMB EXTENSIONS" SMB-EXTENSIONS "This enables SMB support" "extensions/smb/tests") | ||
|
||
register_extension_linter(minifi-smb-extensions-linter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* 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 "FetchSmb.h" | ||
#include "core/Resource.h" | ||
#include "utils/file/FileReaderCallback.h" | ||
|
||
namespace org::apache::nifi::minifi::extensions::smb { | ||
|
||
void FetchSmb::initialize() { | ||
setSupportedProperties(Properties); | ||
setSupportedRelationships(Relationships); | ||
} | ||
|
||
void FetchSmb::onSchedule(const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::ProcessSessionFactory>&) { | ||
gsl_Expects(context); | ||
if (auto connection_controller_name = context->getProperty(FetchSmb::ConnectionControllerService)) { | ||
smb_connection_controller_service_ = std::dynamic_pointer_cast<SmbConnectionControllerService>(context->getControllerService(*connection_controller_name)); | ||
} | ||
if (!smb_connection_controller_service_) { | ||
throw minifi::Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Missing SMB Connection Controller Service"); | ||
} | ||
} | ||
|
||
namespace { | ||
std::filesystem::path getPath(core::ProcessContext& context, const std::shared_ptr<core::FlowFile>& flow_file) { | ||
auto remote_file = context.getProperty(FetchSmb::RemoteFile, flow_file); | ||
if (remote_file && !remote_file->empty()) { | ||
if (remote_file->starts_with('/')) | ||
remote_file->erase(remote_file->begin()); | ||
return *remote_file; | ||
} | ||
std::filesystem::path path = flow_file->getAttribute(core::SpecialFlowAttribute::PATH).value_or(""); | ||
std::filesystem::path filename = flow_file->getAttribute(core::SpecialFlowAttribute::FILENAME).value_or(""); | ||
return path / filename; | ||
} | ||
} // namespace | ||
|
||
void FetchSmb::onTrigger(const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::ProcessSession>& session) { | ||
gsl_Expects(context && session && smb_connection_controller_service_); | ||
|
||
auto connection_error = smb_connection_controller_service_->validateConnection(); | ||
if (connection_error) { | ||
logger_->log_error("Couldn't establish connection to the specified network location due to %s", connection_error.message()); | ||
context->yield(); | ||
return; | ||
} | ||
|
||
auto flow_file = session->get(); | ||
if (!flow_file) { | ||
context->yield(); | ||
return; | ||
} | ||
|
||
auto path = getPath(*context, flow_file); | ||
|
||
try { | ||
session->write(flow_file, utils::FileReaderCallback{smb_connection_controller_service_->getPath() / path}); | ||
session->transfer(flow_file, Success); | ||
} catch (const utils::FileReaderCallbackIOError& io_error) { | ||
flow_file->addAttribute(ErrorCode.name, fmt::format("{}", io_error.error_code)); | ||
flow_file->addAttribute(ErrorMessage.name, io_error.what()); | ||
session->transfer(flow_file, Failure); | ||
return; | ||
} | ||
} | ||
|
||
REGISTER_RESOURCE(FetchSmb, Processor); | ||
|
||
} // namespace org::apache::nifi::minifi::extensions::smb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* 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 <memory> | ||
#include <optional> | ||
#include <regex> | ||
#include <string> | ||
#include <utility> | ||
|
||
#include "SmbConnectionControllerService.h" | ||
#include "core/Processor.h" | ||
#include "core/ProcessSession.h" | ||
#include "core/Property.h" | ||
#include "core/PropertyDefinition.h" | ||
#include "core/PropertyDefinitionBuilder.h" | ||
#include "core/OutputAttributeDefinition.h" | ||
#include "core/logging/LoggerConfiguration.h" | ||
#include "utils/Enum.h" | ||
#include "utils/ListingStateManager.h" | ||
#include "utils/file/ListedFile.h" | ||
#include "utils/file/FileUtils.h" | ||
|
||
namespace org::apache::nifi::minifi::extensions::smb { | ||
|
||
class FetchSmb : public core::Processor { | ||
public: | ||
explicit FetchSmb(std::string name, const utils::Identifier& uuid = {}) | ||
: core::Processor(std::move(name), uuid) { | ||
} | ||
|
||
EXTENSIONAPI static constexpr const char* Description = "Fetches files from a SMB Share. Designed to be used in tandem with ListSmb."; | ||
|
||
EXTENSIONAPI static constexpr auto ConnectionControllerService = core::PropertyDefinitionBuilder<>::createProperty("SMB Connection Controller Service") | ||
.withDescription("Specifies the SMB connection controller service to use for connecting to the SMB server.") | ||
.isRequired(true) | ||
.withAllowedTypes<SmbConnectionControllerService>() | ||
.build(); | ||
EXTENSIONAPI static constexpr auto RemoteFile = core::PropertyDefinitionBuilder<>::createProperty("Input Directory") | ||
.withDescription("The full path of the file to be retrieved from the remote server. Expression language supported. If left empty the path and filename attributes will be used.") | ||
.isRequired(false) | ||
.supportsExpressionLanguage(true) | ||
.build(); | ||
EXTENSIONAPI static constexpr auto Properties = std::array<core::PropertyReference, 2>{ | ||
ConnectionControllerService, | ||
RemoteFile | ||
}; | ||
|
||
EXTENSIONAPI static constexpr auto Success = core::RelationshipDefinition{"success", "A flowfile will be routed here for each successfully fetched file."}; | ||
EXTENSIONAPI static constexpr auto Failure = core::RelationshipDefinition{"failure", "A flowfile will be routed here when failed to fetch its content."}; | ||
EXTENSIONAPI static constexpr auto Relationships = std::array{Success, Failure}; | ||
|
||
EXTENSIONAPI static constexpr auto ErrorCode = core::OutputAttributeDefinition<>{"error.code", { Failure }, "The error code returned by SMB when the fetch of a file fails."}; | ||
EXTENSIONAPI static constexpr auto ErrorMessage = core::OutputAttributeDefinition<>{"error.message", { Failure }, "The error message returned by SMB when the fetch of a file fails."}; | ||
|
||
EXTENSIONAPI static constexpr auto OutputAttributes = std::array<core::OutputAttributeReference, 2>{ FetchSmb::ErrorCode, ErrorMessage }; | ||
|
||
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false; | ||
EXTENSIONAPI static constexpr bool SupportsDynamicRelationships = false; | ||
EXTENSIONAPI static constexpr core::annotation::Input InputRequirement = core::annotation::Input::INPUT_REQUIRED; | ||
EXTENSIONAPI static constexpr bool IsSingleThreaded = false; | ||
|
||
ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS | ||
|
||
void initialize() override; | ||
void onSchedule(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSessionFactory> &session_factory) override; | ||
void onTrigger(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSession> &session) override; | ||
|
||
private: | ||
std::shared_ptr<SmbConnectionControllerService> smb_connection_controller_service_; | ||
std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<FetchSmb>::getLogger(uuid_); | ||
}; | ||
|
||
} // namespace org::apache::nifi::minifi::extensions::smb |
Oops, something went wrong.