arpadboda commented on a change in pull request #580: MINIFICPP-30: Add support
for regex with Multiple file mode
URL: https://github.com/apache/nifi-minifi-cpp/pull/580#discussion_r296629133
##########
File path: extensions/standard-processors/processors/TailFile.cpp
##########
@@ -61,34 +66,101 @@ namespace nifi {
namespace minifi {
namespace processors {
-core::Property TailFile::FileName("File to Tail", "Fully-qualified filename of
the file that should be tailed", "");
+core::Property TailFile::FileName("File to Tail", "Fully-qualified filename of
the file that should be tailed when using single file mode, or a file regex
when using multifile mode", "");
core::Property TailFile::StateFile("State File", "Specifies the file that
should be used for storing state about"
" what data has been ingested so that upon
restart NiFi can resume from where it left off",
"TailFileState");
core::Property TailFile::Delimiter("Input Delimiter", "Specifies the character
that should be used for delimiting the data being tailed"
"from the incoming file.",
"");
+
+core::Property TailFile::TailMode(
+ core::PropertyBuilder::createProperty("tail-mode", "Tailing
Mode")->withDescription("Specifies the tail file mode. In 'Single file' mode
only a single file will be watched. "
+ "In 'Multiple file' mode a regex may be used. Note that in
multiple file mode we will still continue to watch for rollover on the initial
set of watched files. "
+ "The Regex used to locate multiple files will be run during
the schedule phrase. Note that if rotated files are matched by the regex, those
files will be
tailed.")->isRequired(true)->withAllowableValue<std::string>("Single
file")->withAllowableValue("Multiple file")->withDefaultValue(
+ "Single file")->build());
+
+core::Property
TailFile::BaseDirectory(core::PropertyBuilder::createProperty("tail-base-directory",
"Base Directory")->isRequired(false)->build());
+
core::Relationship TailFile::Success("success", "All files are routed to
success");
+const char *TailFile::CURRENT_STR = "CURRENT.";
+const char *TailFile::POSITION_STR = "POSITION.";
+
void TailFile::initialize() {
// Set the supported properties
std::set<core::Property> properties;
properties.insert(FileName);
properties.insert(StateFile);
properties.insert(Delimiter);
+ properties.insert(TailMode);
+ properties.insert(BaseDirectory);
setSupportedProperties(properties);
// Set the supported relationships
std::set<core::Relationship> relationships;
relationships.insert(Success);
setSupportedRelationships(relationships);
}
-void TailFile::onSchedule(core::ProcessContext *context,
core::ProcessSessionFactory *sessionFactory) {
+void TailFile::onSchedule(const std::shared_ptr<core::ProcessContext>
&context, const std::shared_ptr<core::ProcessSessionFactory> &sessionFactory) {
+ std::lock_guard<std::mutex> tail_lock(tail_file_mutex_);
+
std::string value;
if (context->getProperty(Delimiter.getName(), value)) {
delimiter_ = value;
}
+
+ std::string mode;
+ context->getProperty(TailMode.getName(), mode);
+
+ std::string file = "";
+ if (!context->getProperty(FileName.getName(), file)) {
+ throw minifi::Exception(ExceptionType::PROCESSOR_EXCEPTION, "File to Tail
is a required property");
+ }
+ if (mode == "Multiple file") {
+ // file is a regex
+ std::string base_dir;
+ if (!context->getProperty(BaseDirectory.getName(), base_dir)) {
+ throw minifi::Exception(ExceptionType::PROCESSOR_EXCEPTION, "Base
directory is required for multiple tail mode.");
+ }
+
+ auto fileRegexSelect = [&](const std::string& path, const std::string&
filename) -> bool {
+ struct stat sb;
+ std::string fileFullName = path +
utils::file::FileUtils::get_separator() + filename;
Review comment:
This and "stat" seem to be unreferenced.
----------------------------------------------------------------
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]
With regards,
Apache Git Services