[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-27 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r738041008



##
File path: extensions/standard-processors/processors/TailFile.cpp
##
@@ -797,11 +799,13 @@ void TailFile::updateFlowFileAttributes(const std::string 
_file_name, const
 const std::string ,
 std::shared_ptr 
_file) const {
   logger_->log_info("TailFile %s for %" PRIu64 " bytes", fileName, 
flow_file->getSize());
-  std::string logName = baseName + "." + std::to_string(state.position_) + "-" 
+
-std::to_string(state.position_ + flow_file->getSize() 
- 1) + "." + extension;
+  std::string logName = textfragmentutils::createFileName(baseName, extension, 
state.position_, flow_file->getSize());
   flow_file->setAttribute(core::SpecialFlowAttribute::PATH, state.path_);
   flow_file->addAttribute(core::SpecialFlowAttribute::ABSOLUTE_PATH, 
full_file_name);
   flow_file->setAttribute(core::SpecialFlowAttribute::FILENAME, logName);
+  flow_file->setAttribute(textfragmentutils::BASE_NAME_ATTRIBUTE, baseName);
+  flow_file->setAttribute(textfragmentutils::POST_NAME_ATTRIBUTE, extension);
+  flow_file->setAttribute(textfragmentutils::OFFSET_ATTRIBUTE, 
std::to_string(state.position_));

Review comment:
   No, it works without these. (e.g. DefragmentationTextTests dont use 
these attributes)
   
   If these are not set in the input files then these and the filename 
attribute wont be updated in the output file, but the defragmentation process 
will work.
   If these are set and they match in the incoming fragments then these and the 
filename attribute will be updated accordingly.
   On mixed inputs (not matching attributes in different inputs or not alligned 
offsets) it will fail.




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




[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-26 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r736700410



##
File path: extensions/standard-processors/processors/DefragmentText.cpp
##
@@ -0,0 +1,340 @@
+/**
+ * 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 "DefragmentText.h"
+
+#include 
+
+#include "core/Resource.h"
+#include "serialization/PayloadSerializer.h"
+#include "TextFragmentUtils.h"
+#include "utils/gsl.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+const core::Relationship DefragmentText::Success("success", "Flowfiles that 
have no fragmented messages in them");
+const core::Relationship DefragmentText::Failure("failure", "Flowfiles that 
failed the defragmentation process");
+const core::Relationship DefragmentText::Self("__self__", "Marks the FlowFile 
to be owned by this processor");
+
+const core::Property DefragmentText::Pattern(
+core::PropertyBuilder::createProperty("Pattern")
+->withDescription("A regular expression to match at the start or end 
of messages.")
+->isRequired(true)->build());
+
+const core::Property DefragmentText::PatternLoc(
+core::PropertyBuilder::createProperty("Pattern 
Location")->withDescription("Whether the pattern is located at the start or at 
the end of the messages.")
+->withAllowableValues(PatternLocation::values())
+
->withDefaultValue(toString(PatternLocation::START_OF_MESSAGE))->build());
+
+
+const core::Property DefragmentText::MaxBufferSize(
+core::PropertyBuilder::createProperty("Max Buffer Size")
+->withDescription("The maximum buffer size, if the buffer exceeds 
this, it will be transferred to failure. Expected format is  ")
+
->withType(core::StandardValidators::get().DATA_SIZE_VALIDATOR)->build());
+
+const core::Property DefragmentText::MaxBufferAge(
+core::PropertyBuilder::createProperty("Max Buffer Age")->
+withDescription("The maximum age of a buffer after which the buffer 
will be transferred to failure. Expected format is  ")->build());
+
+void DefragmentText::initialize() {
+  setSupportedRelationships({Success, Failure});
+  setSupportedProperties({Pattern, PatternLoc, MaxBufferAge, MaxBufferSize});
+}
+
+void DefragmentText::onSchedule(core::ProcessContext* context, 
core::ProcessSessionFactory*) {
+  gsl_Expects(context);
+
+  std::string max_buffer_age_str;
+  if (context->getProperty(MaxBufferAge.getName(), max_buffer_age_str)) {
+core::TimeUnit unit;
+uint64_t max_buffer_age;
+if (core::Property::StringToTime(max_buffer_age_str, max_buffer_age, unit) 
&& core::Property::ConvertTimeUnitToMS(max_buffer_age, unit, max_buffer_age)) {
+  buffer_.setMaxAge(std::chrono::milliseconds(max_buffer_age));
+  logger_->log_trace("The Buffer maximum age is configured to be %" PRIu64 
" ms", max_buffer_age);
+}
+  }
+
+  std::string max_buffer_size_str;
+  if (context->getProperty(MaxBufferSize.getName(), max_buffer_size_str)) {
+uint64_t max_buffer_size = 
core::DataSizeValue(max_buffer_size_str).getValue();
+if (max_buffer_size > 0) {
+  buffer_.setMaxSize(max_buffer_size);
+  logger_->log_trace("The Buffer maximum size is configured to be %" 
PRIu64 " B", max_buffer_size);
+}
+  }
+
+  context->getProperty(PatternLoc.getName(), pattern_location_);
+
+  std::string pattern_str;
+  if (context->getProperty(Pattern.getName(), pattern_str) && 
!pattern_str.empty()) {
+pattern_ = std::regex(pattern_str);
+logger_->log_trace("The Pattern is configured to be %s", pattern_str);
+  } else {
+throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Pattern property missing or 
invalid");
+  }
+}
+
+void DefragmentText::onTrigger(core::ProcessContext*, core::ProcessSession* 
session) {
+  gsl_Expects(session);
+  auto flowFiles = flow_file_store_.getNewFlowFiles();
+  for (auto& file : flowFiles) {
+processNextFragment(session, file);
+  }
+  std::shared_ptr original_flow_file = session->get();
+  processNextFragment(session, original_flow_file);
+  if (buffer_.maxAgeReached() || buffer_.maxSizeReached()) {
+buffer_.flushAndReplace(session, Failure, nullptr);
+  }
+}
+
+void 

[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-26 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r736699005



##
File path: PROCESSORS.md
##
@@ -295,6 +296,29 @@ In the list below, the names of required properties appear 
in bold. Any other pr
 | - | - |
 |success|FlowFiles that are sent successfully to the destination are 
transferred to this relationship|
 
+## DefragmentText
+
+### Description
+
+DefragmentText splits and merges incoming flowfiles so cohesive messages are 
not split between them
+### Properties
+
+In the list below, the names of required properties appear in bold. Any other 
properties (not in bold) are considered optional. The table also indicates any 
default values, and whether a property supports the NiFi Expression Language.
+
+| Name | Default Value | Allowable Values | Description |
+| - | - | - | - |
+|**Pattern**|||A regular expression to match at the start or end of messages.|
+|Pattern Location|Start of Message|Start of MessageEnd of Message|Whether 
the pattern is located at the start or at the end of the messages.|
+|MaxBufferAge||duration time unit|The maximum age of a buffer 
after which the buffer will be transferred to failure.|
+|MaxBufferSize||size size unit|The maximum buffer size, if the 
buffer exceed this, it will be transferred to failure.|
+
+### Relationships
+
+| Name | Description |
+| - | - |
+|success|Flowfiles that have no fragmented messages in them|

Review comment:
   sounds better, changed in 
https://github.com/apache/nifi-minifi-cpp/pull/1188/commits/db507183aabe984accb113f7b626150be93ece6b




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




[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-25 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r735583036



##
File path: extensions/standard-processors/processors/DefragmentText.cpp
##
@@ -0,0 +1,340 @@
+/**
+ * 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 "DefragmentText.h"
+
+#include 
+
+#include "core/Resource.h"
+#include "serialization/PayloadSerializer.h"
+#include "TextFragmentUtils.h"
+#include "utils/gsl.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+const core::Relationship DefragmentText::Success("success", "Flowfiles that 
have no fragmented messages in them");
+const core::Relationship DefragmentText::Failure("failure", "Flowfiles that 
failed the defragmentation process");
+const core::Relationship DefragmentText::Self("__self__", "Marks the FlowFile 
to be owned by this processor");
+
+const core::Property DefragmentText::Pattern(
+core::PropertyBuilder::createProperty("Pattern")
+->withDescription("A regular expression to match at the start or end 
of messages.")
+->isRequired(true)->build());
+
+const core::Property DefragmentText::PatternLoc(
+core::PropertyBuilder::createProperty("Pattern 
Location")->withDescription("Whether the pattern is located at the start or at 
the end of the messages.")
+->withAllowableValues(PatternLocation::values())
+
->withDefaultValue(toString(PatternLocation::START_OF_MESSAGE))->build());
+
+
+const core::Property DefragmentText::MaxBufferSize(
+core::PropertyBuilder::createProperty("Max Buffer Size")
+->withDescription("The maximum buffer size, if the buffer exceeds 
this, it will be transferred to failure. Expected format is  ")
+
->withType(core::StandardValidators::get().DATA_SIZE_VALIDATOR)->build());
+
+const core::Property DefragmentText::MaxBufferAge(
+core::PropertyBuilder::createProperty("Max Buffer Age")->
+withDescription("The maximum age of a buffer after which the buffer 
will be transferred to failure. Expected format is  ")->build());
+
+void DefragmentText::initialize() {
+  setSupportedRelationships({Success, Failure});
+  setSupportedProperties({Pattern, PatternLoc, MaxBufferAge, MaxBufferSize});
+}
+
+void DefragmentText::onSchedule(core::ProcessContext* context, 
core::ProcessSessionFactory*) {
+  gsl_Expects(context);
+
+  std::string max_buffer_age_str;
+  if (context->getProperty(MaxBufferAge.getName(), max_buffer_age_str)) {
+core::TimeUnit unit;
+uint64_t max_buffer_age;
+if (core::Property::StringToTime(max_buffer_age_str, max_buffer_age, unit) 
&& core::Property::ConvertTimeUnitToMS(max_buffer_age, unit, max_buffer_age)) {
+  buffer_.setMaxAge(std::chrono::milliseconds(max_buffer_age));
+  logger_->log_trace("The Buffer maximum age is configured to be %" PRIu64 
" ms", max_buffer_age);
+}
+  }
+
+  std::string max_buffer_size_str;
+  if (context->getProperty(MaxBufferSize.getName(), max_buffer_size_str)) {
+uint64_t max_buffer_size = 
core::DataSizeValue(max_buffer_size_str).getValue();
+if (max_buffer_size > 0) {
+  buffer_.setMaxSize(max_buffer_size);
+  logger_->log_trace("The Buffer maximum size is configured to be %" 
PRIu64 " B", max_buffer_size);
+}
+  }
+
+  context->getProperty(PatternLoc.getName(), pattern_location_);
+
+  std::string pattern_str;
+  if (context->getProperty(Pattern.getName(), pattern_str) && 
!pattern_str.empty()) {
+pattern_ = std::regex(pattern_str);
+logger_->log_trace("The Pattern is configured to be %s", pattern_str);
+  } else {
+throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Pattern property missing or 
invalid");
+  }
+}
+
+void DefragmentText::onTrigger(core::ProcessContext*, core::ProcessSession* 
session) {
+  gsl_Expects(session);
+  auto flowFiles = flow_file_store_.getNewFlowFiles();
+  for (auto& file : flowFiles) {
+processNextFragment(session, file);
+  }
+  std::shared_ptr original_flow_file = session->get();
+  processNextFragment(session, original_flow_file);
+  if (buffer_.maxAgeReached() || buffer_.maxSizeReached()) {
+buffer_.flushAndReplace(session, Failure, nullptr);
+  }
+}
+
+void 

[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-25 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r735430824



##
File path: extensions/standard-processors/processors/DefragmentText.h
##
@@ -0,0 +1,104 @@
+/**
+ * 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 
+#include 
+#include 
+#include 
+
+#include "core/Processor.h"
+#include "core/FlowFileStore.h"
+#include "core/logging/Logger.h"
+#include "core/logging/LoggerConfiguration.h"
+#include "utils/Enum.h"
+#include "serialization/PayloadSerializer.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+class DefragmentText : public core::Processor {
+ public:
+  explicit DefragmentText(const std::string& name,  const utils::Identifier& 
uuid = {})
+  : Processor(name, uuid) {
+  }
+  EXTENSIONAPI static const core::Relationship Self;
+  EXTENSIONAPI static const core::Relationship Success;
+  EXTENSIONAPI static const core::Relationship Failure;
+
+  EXTENSIONAPI static const core::Property Pattern;
+  EXTENSIONAPI static const core::Property PatternLoc;
+  EXTENSIONAPI static const core::Property MaxBufferAge;
+  EXTENSIONAPI static const core::Property MaxBufferSize;
+
+  void initialize() override;
+  void onSchedule(core::ProcessContext* context, core::ProcessSessionFactory* 
sessionFactory) override;
+  void onTrigger(core::ProcessContext* context, core::ProcessSession* session) 
override;
+  void restore(const std::shared_ptr& flowFile) override;
+  std::set> getOutGoingConnections(const 
std::string ) const override;
+
+  SMART_ENUM(PatternLocation,
+ (END_OF_MESSAGE, "End of Message"),
+ (START_OF_MESSAGE, "Start of Message")
+  )
+
+ protected:
+  class Buffer {
+   public:
+bool isCompatible(const std::shared_ptr& 
flow_file_to_append) const;
+void append(core::ProcessSession* session, const 
std::shared_ptr& flow_file_to_append);
+bool maxSizeReached() const;
+bool maxAgeReached() const;
+void setMaxAge(uint64_t max_age);
+void setMaxSize(size_t max_size);
+void flushAndReplace(core::ProcessSession* session, const 
core::Relationship& relationship,
+ const std::shared_ptr& 
new_buffered_flow_file);
+
+bool empty() const { return buffered_flow_file_ == nullptr; }
+
+   private:
+void store(core::ProcessSession* session, const 
std::shared_ptr& new_buffered_flow_file);
+
+std::shared_ptr buffered_flow_file_;
+std::chrono::time_point creation_time_;
+std::optional max_age_;
+std::optional max_size_;
+  };
+
+  std::mutex defrag_mutex_;

Review comment:
   awesome, rebased removed the mutex and added the the isSingleThreaded in 
https://github.com/apache/nifi-minifi-cpp/pull/1188/commits/b01973d54c61708b44422c7c24db5c611a7d89be

##
File path: extensions/standard-processors/processors/DefragmentText.cpp
##
@@ -0,0 +1,337 @@
+/**
+ * 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 "DefragmentText.h"
+
+#include 
+
+#include "core/Resource.h"
+#include "serialization/PayloadSerializer.h"
+#include "TextFragmentUtils.h"
+#include "utils/gsl.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+const core::Relationship DefragmentText::Success("success", "Flowfiles that 
have no fragmented messages in them");
+const core::Relationship DefragmentText::Failure("failure", "Flowfiles that 
failed the defragmentation process");
+const 

[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-25 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r735430824



##
File path: extensions/standard-processors/processors/DefragmentText.h
##
@@ -0,0 +1,104 @@
+/**
+ * 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 
+#include 
+#include 
+#include 
+
+#include "core/Processor.h"
+#include "core/FlowFileStore.h"
+#include "core/logging/Logger.h"
+#include "core/logging/LoggerConfiguration.h"
+#include "utils/Enum.h"
+#include "serialization/PayloadSerializer.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+class DefragmentText : public core::Processor {
+ public:
+  explicit DefragmentText(const std::string& name,  const utils::Identifier& 
uuid = {})
+  : Processor(name, uuid) {
+  }
+  EXTENSIONAPI static const core::Relationship Self;
+  EXTENSIONAPI static const core::Relationship Success;
+  EXTENSIONAPI static const core::Relationship Failure;
+
+  EXTENSIONAPI static const core::Property Pattern;
+  EXTENSIONAPI static const core::Property PatternLoc;
+  EXTENSIONAPI static const core::Property MaxBufferAge;
+  EXTENSIONAPI static const core::Property MaxBufferSize;
+
+  void initialize() override;
+  void onSchedule(core::ProcessContext* context, core::ProcessSessionFactory* 
sessionFactory) override;
+  void onTrigger(core::ProcessContext* context, core::ProcessSession* session) 
override;
+  void restore(const std::shared_ptr& flowFile) override;
+  std::set> getOutGoingConnections(const 
std::string ) const override;
+
+  SMART_ENUM(PatternLocation,
+ (END_OF_MESSAGE, "End of Message"),
+ (START_OF_MESSAGE, "Start of Message")
+  )
+
+ protected:
+  class Buffer {
+   public:
+bool isCompatible(const std::shared_ptr& 
flow_file_to_append) const;
+void append(core::ProcessSession* session, const 
std::shared_ptr& flow_file_to_append);
+bool maxSizeReached() const;
+bool maxAgeReached() const;
+void setMaxAge(uint64_t max_age);
+void setMaxSize(size_t max_size);
+void flushAndReplace(core::ProcessSession* session, const 
core::Relationship& relationship,
+ const std::shared_ptr& 
new_buffered_flow_file);
+
+bool empty() const { return buffered_flow_file_ == nullptr; }
+
+   private:
+void store(core::ProcessSession* session, const 
std::shared_ptr& new_buffered_flow_file);
+
+std::shared_ptr buffered_flow_file_;
+std::chrono::time_point creation_time_;
+std::optional max_age_;
+std::optional max_size_;
+  };
+
+  std::mutex defrag_mutex_;

Review comment:
   rebased removed the mutex and added the the isSingleThreaded in 
https://github.com/apache/nifi-minifi-cpp/pull/1188/commits/b01973d54c61708b44422c7c24db5c611a7d89be




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




[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-21 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r733584660



##
File path: extensions/standard-processors/processors/DefragmentText.cpp
##
@@ -0,0 +1,337 @@
+/**
+ * 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 "DefragmentText.h"
+
+#include 
+
+#include "core/Resource.h"
+#include "serialization/PayloadSerializer.h"
+#include "TextFragmentUtils.h"
+#include "utils/gsl.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+const core::Relationship DefragmentText::Success("success", "Flowfiles that 
have no fragmented messages in them");
+const core::Relationship DefragmentText::Failure("failure", "Flowfiles that 
failed the defragmentation process");
+const core::Relationship DefragmentText::Self("__self__", "Marks the FlowFile 
to be owned by this processor");
+
+const core::Property DefragmentText::Pattern(
+core::PropertyBuilder::createProperty("Pattern")
+->withDescription("A regular expression to match at the start or end 
of messages.")
+->isRequired(true)->build());
+
+const core::Property DefragmentText::PatternLoc(
+core::PropertyBuilder::createProperty("Pattern 
Location")->withDescription("Where to look for the pattern.")

Review comment:
   Changed the description in 
https://github.com/apache/nifi-minifi-cpp/pull/1188/commits/d064266734f9ff1cbd4e66734a5dffee2176046a
   `Whether the pattern is located at the start or at the end of the messages.` 
is this better? or should I list them exactly how they are accepted? e.g. 
"Where to look for the Pattern? Start of Message/End of Message"




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




[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-21 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r733581417



##
File path: extensions/standard-processors/processors/DefragmentText.cpp
##
@@ -0,0 +1,337 @@
+/**
+ * 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 "DefragmentText.h"
+
+#include 
+
+#include "core/Resource.h"
+#include "serialization/PayloadSerializer.h"
+#include "TextFragmentUtils.h"
+#include "utils/gsl.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+const core::Relationship DefragmentText::Success("success", "Flowfiles that 
have no fragmented messages in them");
+const core::Relationship DefragmentText::Failure("failure", "Flowfiles that 
failed the defragmentation process");
+const core::Relationship DefragmentText::Self("__self__", "Marks the FlowFile 
to be owned by this processor");
+
+const core::Property DefragmentText::Pattern(
+core::PropertyBuilder::createProperty("Pattern")
+->withDescription("A regular expression to match at the start or end 
of messages.")
+->isRequired(true)->build());
+
+const core::Property DefragmentText::PatternLoc(
+core::PropertyBuilder::createProperty("Pattern 
Location")->withDescription("Where to look for the pattern.")
+->withAllowableValues(PatternLocation::values())
+
->withDefaultValue(toString(PatternLocation::START_OF_MESSAGE))->build());
+
+
+const core::Property DefragmentText::MaxBufferSize(
+core::PropertyBuilder::createProperty("Max Buffer Size")
+->withDescription("The maximum buffer size, if the buffer exceeds 
this, it will be transferred to failure. Expected format is  ")
+
->withType(core::StandardValidators::get().DATA_SIZE_VALIDATOR)->build());
+
+const core::Property DefragmentText::MaxBufferAge(
+core::PropertyBuilder::createProperty("Max Buffer Age")->
+withDescription("The maximum age of a buffer after which the buffer 
will be transferred to failure. Expected format is  ")->build());
+
+void DefragmentText::initialize() {
+  setSupportedRelationships({Success, Failure});
+  setSupportedProperties({Pattern, PatternLoc, MaxBufferAge, MaxBufferSize});
+}
+
+void DefragmentText::onSchedule(core::ProcessContext* context, 
core::ProcessSessionFactory*) {
+  gsl_Expects(context);
+
+  std::string max_buffer_age_str;
+  if (context->getProperty(MaxBufferAge.getName(), max_buffer_age_str)) {
+core::TimeUnit unit;
+uint64_t max_buffer_age;
+if (core::Property::StringToTime(max_buffer_age_str, max_buffer_age, unit) 
&& core::Property::ConvertTimeUnitToMS(max_buffer_age, unit, max_buffer_age)) {
+  buffer_.setMaxAge(max_buffer_age);
+  logger_->log_trace("The Buffer maximum age is configured to be %" PRIu64 
" ms", max_buffer_age);
+}
+  }
+
+  std::string max_buffer_size_str;
+  if (context->getProperty(MaxBufferSize.getName(), max_buffer_size_str)) {
+uint64_t max_buffer_size = 
core::DataSizeValue(max_buffer_size_str).getValue();
+if (max_buffer_size > 0) {
+  buffer_.setMaxSize(max_buffer_size);
+  logger_->log_trace("The Buffer maximum size is configured to be %" 
PRIu64 " B", max_buffer_size);
+}
+  }
+
+  context->getProperty(PatternLoc.getName(), pattern_location_);
+
+  std::string pattern_str;
+  if (context->getProperty(Pattern.getName(), pattern_str) && pattern_str != 
"") {
+pattern_ = std::regex(pattern_str);
+logger_->log_trace("The Pattern is configured to be %s", pattern_str);
+  } else {
+throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Pattern property missing or 
invalid");
+  }
+}
+
+void DefragmentText::onTrigger(core::ProcessContext*, core::ProcessSession* 
session) {
+  gsl_Expects(session);
+  std::lock_guard defrag_lock(defrag_mutex_);
+  auto flowFiles = flow_file_store_.getNewFlowFiles();
+  for (auto& file : flowFiles) {
+processNextFragment(session, file);
+  }
+  std::shared_ptr original_flow_file = session->get();
+  processNextFragment(session, original_flow_file);
+  if (buffer_.maxAgeReached() || buffer_.maxSizeReached()) {
+buffer_.flushAndReplace(session, Failure, nullptr);
+  }
+}
+
+void DefragmentText::processNextFragment(core::ProcessSession *session, 

[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-21 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r733581195



##
File path: libminifi/test/ReadFromFlowFileTestProcessor.cpp
##
@@ -0,0 +1,69 @@
+/**
+ * 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 "ReadFromFlowFileTestProcessor.h"
+
+#include 
+#include 
+#include 
+
+#include "utils/gsl.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+const core::Relationship ReadFromFlowFileTestProcessor::Success("success", 
"success operational on the flow record");
+
+void ReadFromFlowFileTestProcessor::initialize() {
+  setSupportedRelationships({ Success });
+}
+
+void ReadFromFlowFileTestProcessor::onSchedule(core::ProcessContext*, 
core::ProcessSessionFactory*) {
+  logger_->log_info("%s", ON_SCHEDULE_LOG_STR);
+}
+
+namespace {
+struct ReadFlowFileIntoBuffer : public InputStreamCallback {
+  std::vector buffer_;
+
+  int64_t process(const std::shared_ptr ) override {
+size_t bytes_read = stream->read(buffer_, stream->size());
+return io::isError(bytes_read) ? -1 : gsl::narrow(bytes_read);
+  }
+};
+}
+
+void ReadFromFlowFileTestProcessor::onTrigger(core::ProcessContext* context, 
core::ProcessSession* session) {
+  gsl_Expects(context && session);
+  logger_->log_info("%s", ON_TRIGGER_LOG_STR);
+  flow_file_contents_.clear();
+
+  std::shared_ptr flow_file = session->get();
+  while (flow_file) {

Review comment:
   didnt know that one thanks, 
https://github.com/apache/nifi-minifi-cpp/pull/1188/commits/d064266734f9ff1cbd4e66734a5dffee2176046a




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




[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-21 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r733578580



##
File path: extensions/standard-processors/processors/DefragmentText.cpp
##
@@ -0,0 +1,337 @@
+/**
+ * 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 "DefragmentText.h"
+
+#include 
+
+#include "core/Resource.h"
+#include "serialization/PayloadSerializer.h"
+#include "TextFragmentUtils.h"
+#include "utils/gsl.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+const core::Relationship DefragmentText::Success("success", "Flowfiles that 
have no fragmented messages in them");
+const core::Relationship DefragmentText::Failure("failure", "Flowfiles that 
failed the defragmentation process");
+const core::Relationship DefragmentText::Self("__self__", "Marks the FlowFile 
to be owned by this processor");
+
+const core::Property DefragmentText::Pattern(
+core::PropertyBuilder::createProperty("Pattern")
+->withDescription("A regular expression to match at the start or end 
of messages.")
+->isRequired(true)->build());
+
+const core::Property DefragmentText::PatternLoc(
+core::PropertyBuilder::createProperty("Pattern 
Location")->withDescription("Where to look for the pattern.")
+->withAllowableValues(PatternLocation::values())
+
->withDefaultValue(toString(PatternLocation::START_OF_MESSAGE))->build());
+
+
+const core::Property DefragmentText::MaxBufferSize(
+core::PropertyBuilder::createProperty("Max Buffer Size")
+->withDescription("The maximum buffer size, if the buffer exceeds 
this, it will be transferred to failure. Expected format is  ")
+
->withType(core::StandardValidators::get().DATA_SIZE_VALIDATOR)->build());
+
+const core::Property DefragmentText::MaxBufferAge(
+core::PropertyBuilder::createProperty("Max Buffer Age")->
+withDescription("The maximum age of a buffer after which the buffer 
will be transferred to failure. Expected format is  ")->build());
+
+void DefragmentText::initialize() {
+  setSupportedRelationships({Success, Failure});
+  setSupportedProperties({Pattern, PatternLoc, MaxBufferAge, MaxBufferSize});
+}
+
+void DefragmentText::onSchedule(core::ProcessContext* context, 
core::ProcessSessionFactory*) {
+  gsl_Expects(context);
+
+  std::string max_buffer_age_str;
+  if (context->getProperty(MaxBufferAge.getName(), max_buffer_age_str)) {
+core::TimeUnit unit;
+uint64_t max_buffer_age;
+if (core::Property::StringToTime(max_buffer_age_str, max_buffer_age, unit) 
&& core::Property::ConvertTimeUnitToMS(max_buffer_age, unit, max_buffer_age)) {
+  buffer_.setMaxAge(max_buffer_age);
+  logger_->log_trace("The Buffer maximum age is configured to be %" PRIu64 
" ms", max_buffer_age);
+}
+  }
+
+  std::string max_buffer_size_str;
+  if (context->getProperty(MaxBufferSize.getName(), max_buffer_size_str)) {
+uint64_t max_buffer_size = 
core::DataSizeValue(max_buffer_size_str).getValue();
+if (max_buffer_size > 0) {
+  buffer_.setMaxSize(max_buffer_size);
+  logger_->log_trace("The Buffer maximum size is configured to be %" 
PRIu64 " B", max_buffer_size);
+}
+  }
+
+  context->getProperty(PatternLoc.getName(), pattern_location_);
+
+  std::string pattern_str;
+  if (context->getProperty(Pattern.getName(), pattern_str) && pattern_str != 
"") {
+pattern_ = std::regex(pattern_str);
+logger_->log_trace("The Pattern is configured to be %s", pattern_str);
+  } else {
+throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Pattern property missing or 
invalid");
+  }
+}
+
+void DefragmentText::onTrigger(core::ProcessContext*, core::ProcessSession* 
session) {
+  gsl_Expects(session);
+  std::lock_guard defrag_lock(defrag_mutex_);
+  auto flowFiles = flow_file_store_.getNewFlowFiles();
+  for (auto& file : flowFiles) {
+processNextFragment(session, file);
+  }
+  std::shared_ptr original_flow_file = session->get();
+  processNextFragment(session, original_flow_file);
+  if (buffer_.maxAgeReached() || buffer_.maxSizeReached()) {
+buffer_.flushAndReplace(session, Failure, nullptr);
+  }
+}
+
+void DefragmentText::processNextFragment(core::ProcessSession *session, 

[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-21 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r733473306



##
File path: extensions/standard-processors/processors/DefragmentText.cpp
##
@@ -0,0 +1,337 @@
+/**
+ * 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 "DefragmentText.h"
+
+#include 
+
+#include "core/Resource.h"
+#include "serialization/PayloadSerializer.h"
+#include "TextFragmentUtils.h"
+#include "utils/gsl.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+const core::Relationship DefragmentText::Success("success", "Flowfiles that 
have no fragmented messages in them");
+const core::Relationship DefragmentText::Failure("failure", "Flowfiles that 
failed the defragmentation process");
+const core::Relationship DefragmentText::Self("__self__", "Marks the FlowFile 
to be owned by this processor");
+
+const core::Property DefragmentText::Pattern(
+core::PropertyBuilder::createProperty("Pattern")
+->withDescription("A regular expression to match at the start or end 
of messages.")
+->isRequired(true)->build());
+
+const core::Property DefragmentText::PatternLoc(
+core::PropertyBuilder::createProperty("Pattern 
Location")->withDescription("Where to look for the pattern.")
+->withAllowableValues(PatternLocation::values())
+
->withDefaultValue(toString(PatternLocation::START_OF_MESSAGE))->build());
+
+
+const core::Property DefragmentText::MaxBufferSize(
+core::PropertyBuilder::createProperty("Max Buffer Size")
+->withDescription("The maximum buffer size, if the buffer exceeds 
this, it will be transferred to failure. Expected format is  ")
+
->withType(core::StandardValidators::get().DATA_SIZE_VALIDATOR)->build());
+
+const core::Property DefragmentText::MaxBufferAge(
+core::PropertyBuilder::createProperty("Max Buffer Age")->
+withDescription("The maximum age of a buffer after which the buffer 
will be transferred to failure. Expected format is  ")->build());
+
+void DefragmentText::initialize() {
+  setSupportedRelationships({Success, Failure});
+  setSupportedProperties({Pattern, PatternLoc, MaxBufferAge, MaxBufferSize});
+}
+
+void DefragmentText::onSchedule(core::ProcessContext* context, 
core::ProcessSessionFactory*) {
+  gsl_Expects(context);
+
+  std::string max_buffer_age_str;
+  if (context->getProperty(MaxBufferAge.getName(), max_buffer_age_str)) {
+core::TimeUnit unit;
+uint64_t max_buffer_age;
+if (core::Property::StringToTime(max_buffer_age_str, max_buffer_age, unit) 
&& core::Property::ConvertTimeUnitToMS(max_buffer_age, unit, max_buffer_age)) {
+  buffer_.setMaxAge(max_buffer_age);
+  logger_->log_trace("The Buffer maximum age is configured to be %" PRIu64 
" ms", max_buffer_age);
+}
+  }
+
+  std::string max_buffer_size_str;
+  if (context->getProperty(MaxBufferSize.getName(), max_buffer_size_str)) {
+uint64_t max_buffer_size = 
core::DataSizeValue(max_buffer_size_str).getValue();
+if (max_buffer_size > 0) {
+  buffer_.setMaxSize(max_buffer_size);
+  logger_->log_trace("The Buffer maximum size is configured to be %" 
PRIu64 " B", max_buffer_size);
+}
+  }
+
+  context->getProperty(PatternLoc.getName(), pattern_location_);
+
+  std::string pattern_str;
+  if (context->getProperty(Pattern.getName(), pattern_str) && pattern_str != 
"") {

Review comment:
   I am not sure if having an empty string as a required property is 
invalid in every case.
   I dont wanna break other processors in this PR. Maybe a separate PR where we 
can discuss this further?




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




[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-20 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r732905550



##
File path: docker/test/integration/features/defragtextflowfiles.feature
##
@@ -0,0 +1,30 @@
+Feature: DefragmentText can defragment fragmented data from TailFile
+  Background:
+Given the content of "/tmp/output" is monitored
+
+  Scenario Outline: DefragmentText merges split messages from TailFile

Review comment:
   This shows the most common usecase TailFile+DefragmentText so this acts 
as documentation, and also this depends on tailfile not just DefragmentText.




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




[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-19 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r732049205



##
File path: extensions/standard-processors/processors/DefragmentText.cpp
##
@@ -0,0 +1,346 @@
+/**
+ * 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 "DefragmentText.h"
+
+#include 
+
+#include "core/Resource.h"
+#include "serialization/PayloadSerializer.h"
+#include "TextFragmentUtils.h"
+#include "utils/gsl.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+const core::Relationship DefragmentText::Success("success", "Flowfiles that 
have no fragmented messages in them");
+const core::Relationship DefragmentText::Failure("failure", "Flowfiles that 
failed the defragmentation process");
+const core::Relationship DefragmentText::Self("__self__", "Marks the FlowFile 
to be owned by this processor");
+
+const core::Property DefragmentText::Pattern(
+core::PropertyBuilder::createProperty("Pattern")
+->withDescription("A regular expression to match at the start or end 
of messages.")
+->isRequired(true)->build());
+
+const core::Property DefragmentText::PatternLoc(
+core::PropertyBuilder::createProperty("Pattern 
Location")->withDescription("Where to look for the pattern.")
+->withAllowableValues(PatternLocation::values())
+
->withDefaultValue(toString(PatternLocation::START_OF_MESSAGE))->build());
+
+
+const core::Property DefragmentText::MaxBufferSize(
+core::PropertyBuilder::createProperty("Max Buffer Size")
+->withDescription("The maximum buffer size, if the buffer exceeds 
this, it will be transferred to failure. Expected format is  ")
+
->withType(core::StandardValidators::get().DATA_SIZE_VALIDATOR)->build());
+
+const core::Property DefragmentText::MaxBufferAge(
+core::PropertyBuilder::createProperty("Max Buffer Age")->
+withDescription("The maximum age of a buffer after which the buffer 
will be transferred to failure. Expected format is  ")->build());
+
+void DefragmentText::initialize() {
+  setSupportedRelationships({Success, Failure});
+  setSupportedProperties({Pattern, PatternLoc, MaxBufferAge, MaxBufferSize});
+}
+
+void DefragmentText::onSchedule(core::ProcessContext* context, 
core::ProcessSessionFactory*) {
+  gsl_Expects(context);
+
+  std::string max_buffer_age_str;
+  if (context->getProperty(MaxBufferAge.getName(), max_buffer_age_str)) {
+core::TimeUnit unit;
+uint64_t max_buffer_age;
+if (core::Property::StringToTime(max_buffer_age_str, max_buffer_age, unit) 
&& core::Property::ConvertTimeUnitToMS(max_buffer_age, unit, max_buffer_age)) {
+  buffer_.setMaxAge(max_buffer_age);
+  logger_->log_trace("The Buffer maximum age is configured to be %" PRIu64 
" ms", max_buffer_age);
+}
+  }
+
+  std::string max_buffer_size_str;
+  if (context->getProperty(MaxBufferSize.getName(), max_buffer_size_str)) {
+uint64_t max_buffer_size = 
core::DataSizeValue(max_buffer_size_str).getValue();
+if (max_buffer_size > 0) {
+  buffer_.setMaxSize(max_buffer_size);
+  logger_->log_trace("The Buffer maximum size is configured to be %" 
PRIu64 " B", max_buffer_size);
+}
+  }
+
+  context->getProperty(PatternLoc.getName(), pattern_location_);
+
+  std::string pattern_str;
+  if (context->getProperty(Pattern.getName(), pattern_str) && pattern_str != 
"") {
+pattern_ = std::regex(pattern_str);
+logger_->log_trace("The Pattern is configured to be %s", pattern_str);
+  } else {
+throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Pattern property missing or 
invalid");
+  }
+}
+
+void DefragmentText::onTrigger(core::ProcessContext*, core::ProcessSession* 
session) {
+  gsl_Expects(session);
+  std::lock_guard defrag_lock(defrag_mutex_);
+  auto flowFiles = flow_file_store_.getNewFlowFiles();
+  for (auto& file : flowFiles) {
+processNextFragment(session, file);
+  }
+  std::shared_ptr original_flow_file = session->get();
+  processNextFragment(session, original_flow_file);
+  if (buffer_.maxAgeReached() || buffer_.maxSizeReached()) {
+buffer_.flushAndReplace(session, Failure, nullptr);
+  }
+}
+
+void DefragmentText::processNextFragment(core::ProcessSession *session, 

[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-19 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r731921747



##
File path: extensions/standard-processors/processors/DefragmentText.cpp
##
@@ -0,0 +1,346 @@
+/**
+ * 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 "DefragmentText.h"
+
+#include 
+
+#include "core/Resource.h"
+#include "serialization/PayloadSerializer.h"
+#include "TextFragmentUtils.h"
+#include "utils/gsl.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+const core::Relationship DefragmentText::Success("success", "Flowfiles that 
have no fragmented messages in them");
+const core::Relationship DefragmentText::Failure("failure", "Flowfiles that 
failed the defragmentation process");
+const core::Relationship DefragmentText::Self("__self__", "Marks the FlowFile 
to be owned by this processor");
+
+const core::Property DefragmentText::Pattern(
+core::PropertyBuilder::createProperty("Pattern")
+->withDescription("A regular expression to match at the start or end 
of messages.")
+->isRequired(true)->build());
+
+const core::Property DefragmentText::PatternLoc(
+core::PropertyBuilder::createProperty("Pattern 
Location")->withDescription("Where to look for the pattern.")
+->withAllowableValues(PatternLocation::values())
+
->withDefaultValue(toString(PatternLocation::START_OF_MESSAGE))->build());
+
+
+const core::Property DefragmentText::MaxBufferSize(
+core::PropertyBuilder::createProperty("Max Buffer Size")
+->withDescription("The maximum buffer size, if the buffer exceeds 
this, it will be transferred to failure. Expected format is  ")
+
->withType(core::StandardValidators::get().DATA_SIZE_VALIDATOR)->build());
+
+const core::Property DefragmentText::MaxBufferAge(
+core::PropertyBuilder::createProperty("Max Buffer Age")->
+withDescription("The maximum age of a buffer after which the buffer 
will be transferred to failure. Expected format is  ")->build());
+
+void DefragmentText::initialize() {
+  setSupportedRelationships({Success, Failure});
+  setSupportedProperties({Pattern, PatternLoc, MaxBufferAge, MaxBufferSize});
+}
+
+void DefragmentText::onSchedule(core::ProcessContext* context, 
core::ProcessSessionFactory*) {
+  gsl_Expects(context);
+
+  std::string max_buffer_age_str;
+  if (context->getProperty(MaxBufferAge.getName(), max_buffer_age_str)) {
+core::TimeUnit unit;
+uint64_t max_buffer_age;
+if (core::Property::StringToTime(max_buffer_age_str, max_buffer_age, unit) 
&& core::Property::ConvertTimeUnitToMS(max_buffer_age, unit, max_buffer_age)) {
+  buffer_.setMaxAge(max_buffer_age);
+  logger_->log_trace("The Buffer maximum age is configured to be %" PRIu64 
" ms", max_buffer_age);
+}
+  }
+
+  std::string max_buffer_size_str;
+  if (context->getProperty(MaxBufferSize.getName(), max_buffer_size_str)) {
+uint64_t max_buffer_size = 
core::DataSizeValue(max_buffer_size_str).getValue();
+if (max_buffer_size > 0) {
+  buffer_.setMaxSize(max_buffer_size);
+  logger_->log_trace("The Buffer maximum size is configured to be %" 
PRIu64 " B", max_buffer_size);
+}
+  }
+
+  context->getProperty(PatternLoc.getName(), pattern_location_);
+
+  std::string pattern_str;
+  if (context->getProperty(Pattern.getName(), pattern_str) && pattern_str != 
"") {
+pattern_ = std::regex(pattern_str);
+logger_->log_trace("The Pattern is configured to be %s", pattern_str);
+  } else {
+throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Pattern property missing or 
invalid");
+  }
+}
+
+void DefragmentText::onTrigger(core::ProcessContext*, core::ProcessSession* 
session) {
+  gsl_Expects(session);
+  std::lock_guard defrag_lock(defrag_mutex_);
+  auto flowFiles = flow_file_store_.getNewFlowFiles();
+  for (auto& file : flowFiles) {
+processNextFragment(session, file);
+  }
+  std::shared_ptr original_flow_file = session->get();
+  processNextFragment(session, original_flow_file);
+  if (buffer_.maxAgeReached() || buffer_.maxSizeReached()) {
+buffer_.flushAndReplace(session, Failure, nullptr);
+  }
+}
+
+void DefragmentText::processNextFragment(core::ProcessSession *session, 

[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-19 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r731860607



##
File path: PROCESSORS.md
##
@@ -295,6 +296,30 @@ In the list below, the names of required properties appear 
in bold. Any other pr
 | - | - |
 |success|FlowFiles that are sent successfully to the destination are 
transferred to this relationship|
 
+## DefragmentText
+
+### Description
+
+DefragmentText splits and merges incoming flowfiles so cohesive messages are 
not split between them
+### Properties
+
+In the list below, the names of required properties appear in bold. Any other 
properties (not in bold) are considered optional. The table also indicates any 
default values, and whether a property supports the NiFi Expression Language.
+
+| Name | Default Value | Allowable Values | Description |
+| - | - | - | - |
+|**Pattern**|||A regular expression to match at the start or end of messages.|
+|Pattern Location|Start of Message|Start of MessageEnd of Message|Where to 
look for the pattern.|
+|MaxBufferAge|||The maximum age of a buffer after which the buffer will be 
transferred to failure.|
+|MaxBufferSize|||The maximum buffer size, if the buffer exceed this, it will 
be transferred to failure.|
+
+### Relationships
+
+| Name | Description |
+| - | - |
+|success|Flowfiles that have no fragmented messages in them|
+|original|The FlowFiles that were used to create the defragmented flowfiles|

Review comment:
   yeah, it was deleted as part of this review this seems a leftover, 
removed it in 
https://github.com/apache/nifi-minifi-cpp/pull/1188/commits/6bdfd7e37c9a16c977b6c785d661a9326383b113




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




[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-19 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r731859938



##
File path: extensions/standard-processors/processors/DefragmentText.cpp
##
@@ -0,0 +1,346 @@
+/**
+ * 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 "DefragmentText.h"
+
+#include 
+
+#include "core/Resource.h"
+#include "serialization/PayloadSerializer.h"
+#include "TextFragmentUtils.h"
+#include "utils/gsl.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+const core::Relationship DefragmentText::Success("success", "Flowfiles that 
have no fragmented messages in them");
+const core::Relationship DefragmentText::Failure("failure", "Flowfiles that 
failed the defragmentation process");
+const core::Relationship DefragmentText::Self("__self__", "Marks the FlowFile 
to be owned by this processor");
+
+const core::Property DefragmentText::Pattern(
+core::PropertyBuilder::createProperty("Pattern")
+->withDescription("A regular expression to match at the start or end 
of messages.")
+->isRequired(true)->build());
+
+const core::Property DefragmentText::PatternLoc(
+core::PropertyBuilder::createProperty("Pattern 
Location")->withDescription("Where to look for the pattern.")
+->withAllowableValues(PatternLocation::values())
+
->withDefaultValue(toString(PatternLocation::START_OF_MESSAGE))->build());
+
+
+const core::Property DefragmentText::MaxBufferSize(
+core::PropertyBuilder::createProperty("Max Buffer Size")
+->withDescription("The maximum buffer size, if the buffer exceeds 
this, it will be transferred to failure. Expected format is  ")
+
->withType(core::StandardValidators::get().DATA_SIZE_VALIDATOR)->build());
+
+const core::Property DefragmentText::MaxBufferAge(
+core::PropertyBuilder::createProperty("Max Buffer Age")->
+withDescription("The maximum age of a buffer after which the buffer 
will be transferred to failure. Expected format is  ")->build());
+
+void DefragmentText::initialize() {
+  setSupportedRelationships({Success, Failure});
+  setSupportedProperties({Pattern, PatternLoc, MaxBufferAge, MaxBufferSize});
+}
+
+void DefragmentText::onSchedule(core::ProcessContext* context, 
core::ProcessSessionFactory*) {
+  gsl_Expects(context);
+
+  std::string max_buffer_age_str;
+  if (context->getProperty(MaxBufferAge.getName(), max_buffer_age_str)) {
+core::TimeUnit unit;
+uint64_t max_buffer_age;
+if (core::Property::StringToTime(max_buffer_age_str, max_buffer_age, unit) 
&& core::Property::ConvertTimeUnitToMS(max_buffer_age, unit, max_buffer_age)) {
+  buffer_.setMaxAge(max_buffer_age);
+  logger_->log_trace("The Buffer maximum age is configured to be %" PRIu64 
" ms", max_buffer_age);
+}
+  }
+
+  std::string max_buffer_size_str;
+  if (context->getProperty(MaxBufferSize.getName(), max_buffer_size_str)) {
+uint64_t max_buffer_size = 
core::DataSizeValue(max_buffer_size_str).getValue();
+if (max_buffer_size > 0) {
+  buffer_.setMaxSize(max_buffer_size);
+  logger_->log_trace("The Buffer maximum size is configured to be %" 
PRIu64 " B", max_buffer_size);
+}
+  }
+
+  context->getProperty(PatternLoc.getName(), pattern_location_);
+
+  std::string pattern_str;
+  if (context->getProperty(Pattern.getName(), pattern_str) && pattern_str != 
"") {
+pattern_ = std::regex(pattern_str);
+logger_->log_trace("The Pattern is configured to be %s", pattern_str);
+  } else {
+throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Pattern property missing or 
invalid");
+  }
+}
+
+void DefragmentText::onTrigger(core::ProcessContext*, core::ProcessSession* 
session) {
+  gsl_Expects(session);
+  std::lock_guard defrag_lock(defrag_mutex_);
+  auto flowFiles = flow_file_store_.getNewFlowFiles();
+  for (auto& file : flowFiles) {
+processNextFragment(session, file);
+  }
+  std::shared_ptr original_flow_file = session->get();
+  processNextFragment(session, original_flow_file);
+  if (buffer_.maxAgeReached() || buffer_.maxSizeReached()) {
+buffer_.flushAndReplace(session, Failure, nullptr);
+  }
+}
+
+void DefragmentText::processNextFragment(core::ProcessSession *session, 

[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-19 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r731858057



##
File path: extensions/standard-processors/processors/DefragmentText.cpp
##
@@ -0,0 +1,346 @@
+/**
+ * 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 "DefragmentText.h"
+
+#include 
+
+#include "core/Resource.h"
+#include "serialization/PayloadSerializer.h"
+#include "TextFragmentUtils.h"
+#include "utils/gsl.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+const core::Relationship DefragmentText::Success("success", "Flowfiles that 
have no fragmented messages in them");
+const core::Relationship DefragmentText::Failure("failure", "Flowfiles that 
failed the defragmentation process");
+const core::Relationship DefragmentText::Self("__self__", "Marks the FlowFile 
to be owned by this processor");
+
+const core::Property DefragmentText::Pattern(
+core::PropertyBuilder::createProperty("Pattern")
+->withDescription("A regular expression to match at the start or end 
of messages.")
+->isRequired(true)->build());
+
+const core::Property DefragmentText::PatternLoc(
+core::PropertyBuilder::createProperty("Pattern 
Location")->withDescription("Where to look for the pattern.")
+->withAllowableValues(PatternLocation::values())
+
->withDefaultValue(toString(PatternLocation::START_OF_MESSAGE))->build());
+
+
+const core::Property DefragmentText::MaxBufferSize(
+core::PropertyBuilder::createProperty("Max Buffer Size")
+->withDescription("The maximum buffer size, if the buffer exceeds 
this, it will be transferred to failure. Expected format is  ")
+
->withType(core::StandardValidators::get().DATA_SIZE_VALIDATOR)->build());
+
+const core::Property DefragmentText::MaxBufferAge(
+core::PropertyBuilder::createProperty("Max Buffer Age")->
+withDescription("The maximum age of a buffer after which the buffer 
will be transferred to failure. Expected format is  ")->build());
+
+void DefragmentText::initialize() {
+  setSupportedRelationships({Success, Failure});
+  setSupportedProperties({Pattern, PatternLoc, MaxBufferAge, MaxBufferSize});
+}
+
+void DefragmentText::onSchedule(core::ProcessContext* context, 
core::ProcessSessionFactory*) {
+  gsl_Expects(context);
+
+  std::string max_buffer_age_str;
+  if (context->getProperty(MaxBufferAge.getName(), max_buffer_age_str)) {
+core::TimeUnit unit;
+uint64_t max_buffer_age;
+if (core::Property::StringToTime(max_buffer_age_str, max_buffer_age, unit) 
&& core::Property::ConvertTimeUnitToMS(max_buffer_age, unit, max_buffer_age)) {
+  buffer_.setMaxAge(max_buffer_age);
+  logger_->log_trace("The Buffer maximum age is configured to be %" PRIu64 
" ms", max_buffer_age);
+}
+  }
+
+  std::string max_buffer_size_str;
+  if (context->getProperty(MaxBufferSize.getName(), max_buffer_size_str)) {
+uint64_t max_buffer_size = 
core::DataSizeValue(max_buffer_size_str).getValue();
+if (max_buffer_size > 0) {
+  buffer_.setMaxSize(max_buffer_size);
+  logger_->log_trace("The Buffer maximum size is configured to be %" 
PRIu64 " B", max_buffer_size);
+}
+  }
+
+  context->getProperty(PatternLoc.getName(), pattern_location_);
+
+  std::string pattern_str;
+  if (context->getProperty(Pattern.getName(), pattern_str) && pattern_str != 
"") {
+pattern_ = std::regex(pattern_str);
+logger_->log_trace("The Pattern is configured to be %s", pattern_str);
+  } else {
+throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Pattern property missing or 
invalid");
+  }
+}
+
+void DefragmentText::onTrigger(core::ProcessContext*, core::ProcessSession* 
session) {
+  gsl_Expects(session);
+  std::lock_guard defrag_lock(defrag_mutex_);
+  auto flowFiles = flow_file_store_.getNewFlowFiles();
+  for (auto& file : flowFiles) {
+processNextFragment(session, file);
+  }
+  std::shared_ptr original_flow_file = session->get();
+  processNextFragment(session, original_flow_file);
+  if (buffer_.maxAgeReached() || buffer_.maxSizeReached()) {
+buffer_.flushAndReplace(session, Failure, nullptr);
+  }
+}
+
+void DefragmentText::processNextFragment(core::ProcessSession *session, 

[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-19 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r731857399



##
File path: extensions/standard-processors/processors/DefragmentText.cpp
##
@@ -0,0 +1,346 @@
+/**
+ * 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 "DefragmentText.h"
+
+#include 
+
+#include "core/Resource.h"
+#include "serialization/PayloadSerializer.h"
+#include "TextFragmentUtils.h"
+#include "utils/gsl.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+const core::Relationship DefragmentText::Success("success", "Flowfiles that 
have no fragmented messages in them");
+const core::Relationship DefragmentText::Failure("failure", "Flowfiles that 
failed the defragmentation process");
+const core::Relationship DefragmentText::Self("__self__", "Marks the FlowFile 
to be owned by this processor");
+
+const core::Property DefragmentText::Pattern(
+core::PropertyBuilder::createProperty("Pattern")
+->withDescription("A regular expression to match at the start or end 
of messages.")
+->isRequired(true)->build());
+
+const core::Property DefragmentText::PatternLoc(
+core::PropertyBuilder::createProperty("Pattern 
Location")->withDescription("Where to look for the pattern.")
+->withAllowableValues(PatternLocation::values())
+
->withDefaultValue(toString(PatternLocation::START_OF_MESSAGE))->build());
+
+
+const core::Property DefragmentText::MaxBufferSize(
+core::PropertyBuilder::createProperty("Max Buffer Size")
+->withDescription("The maximum buffer size, if the buffer exceeds 
this, it will be transferred to failure. Expected format is  ")
+
->withType(core::StandardValidators::get().DATA_SIZE_VALIDATOR)->build());
+
+const core::Property DefragmentText::MaxBufferAge(
+core::PropertyBuilder::createProperty("Max Buffer Age")->
+withDescription("The maximum age of a buffer after which the buffer 
will be transferred to failure. Expected format is  ")->build());
+
+void DefragmentText::initialize() {
+  setSupportedRelationships({Success, Failure});
+  setSupportedProperties({Pattern, PatternLoc, MaxBufferAge, MaxBufferSize});
+}
+
+void DefragmentText::onSchedule(core::ProcessContext* context, 
core::ProcessSessionFactory*) {
+  gsl_Expects(context);
+
+  std::string max_buffer_age_str;
+  if (context->getProperty(MaxBufferAge.getName(), max_buffer_age_str)) {
+core::TimeUnit unit;
+uint64_t max_buffer_age;
+if (core::Property::StringToTime(max_buffer_age_str, max_buffer_age, unit) 
&& core::Property::ConvertTimeUnitToMS(max_buffer_age, unit, max_buffer_age)) {
+  buffer_.setMaxAge(max_buffer_age);
+  logger_->log_trace("The Buffer maximum age is configured to be %" PRIu64 
" ms", max_buffer_age);
+}
+  }
+
+  std::string max_buffer_size_str;
+  if (context->getProperty(MaxBufferSize.getName(), max_buffer_size_str)) {
+uint64_t max_buffer_size = 
core::DataSizeValue(max_buffer_size_str).getValue();
+if (max_buffer_size > 0) {
+  buffer_.setMaxSize(max_buffer_size);
+  logger_->log_trace("The Buffer maximum size is configured to be %" 
PRIu64 " B", max_buffer_size);
+}
+  }
+
+  context->getProperty(PatternLoc.getName(), pattern_location_);
+
+  std::string pattern_str;
+  if (context->getProperty(Pattern.getName(), pattern_str) && pattern_str != 
"") {
+pattern_ = std::regex(pattern_str);
+logger_->log_trace("The Pattern is configured to be %s", pattern_str);
+  } else {
+throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Pattern property missing or 
invalid");
+  }
+}
+
+void DefragmentText::onTrigger(core::ProcessContext*, core::ProcessSession* 
session) {
+  gsl_Expects(session);
+  std::lock_guard defrag_lock(defrag_mutex_);
+  auto flowFiles = flow_file_store_.getNewFlowFiles();
+  for (auto& file : flowFiles) {
+processNextFragment(session, file);
+  }
+  std::shared_ptr original_flow_file = session->get();
+  processNextFragment(session, original_flow_file);
+  if (buffer_.maxAgeReached() || buffer_.maxSizeReached()) {
+buffer_.flushAndReplace(session, Failure, nullptr);
+  }
+}
+
+void DefragmentText::processNextFragment(core::ProcessSession *session, 

[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-19 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r731823945



##
File path: extensions/standard-processors/processors/DefragmentText.cpp
##
@@ -0,0 +1,346 @@
+/**
+ * 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 "DefragmentText.h"
+
+#include 
+
+#include "core/Resource.h"
+#include "serialization/PayloadSerializer.h"
+#include "TextFragmentUtils.h"
+#include "utils/gsl.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+const core::Relationship DefragmentText::Success("success", "Flowfiles that 
have no fragmented messages in them");
+const core::Relationship DefragmentText::Failure("failure", "Flowfiles that 
failed the defragmentation process");
+const core::Relationship DefragmentText::Self("__self__", "Marks the FlowFile 
to be owned by this processor");
+
+const core::Property DefragmentText::Pattern(
+core::PropertyBuilder::createProperty("Pattern")
+->withDescription("A regular expression to match at the start or end 
of messages.")
+->isRequired(true)->build());
+
+const core::Property DefragmentText::PatternLoc(
+core::PropertyBuilder::createProperty("Pattern 
Location")->withDescription("Where to look for the pattern.")
+->withAllowableValues(PatternLocation::values())
+
->withDefaultValue(toString(PatternLocation::START_OF_MESSAGE))->build());
+
+
+const core::Property DefragmentText::MaxBufferSize(
+core::PropertyBuilder::createProperty("Max Buffer Size")
+->withDescription("The maximum buffer size, if the buffer exceeds 
this, it will be transferred to failure. Expected format is  ")
+
->withType(core::StandardValidators::get().DATA_SIZE_VALIDATOR)->build());
+
+const core::Property DefragmentText::MaxBufferAge(
+core::PropertyBuilder::createProperty("Max Buffer Age")->
+withDescription("The maximum age of a buffer after which the buffer 
will be transferred to failure. Expected format is  ")->build());
+
+void DefragmentText::initialize() {
+  setSupportedRelationships({Success, Failure});
+  setSupportedProperties({Pattern, PatternLoc, MaxBufferAge, MaxBufferSize});
+}
+
+void DefragmentText::onSchedule(core::ProcessContext* context, 
core::ProcessSessionFactory*) {
+  gsl_Expects(context);
+
+  std::string max_buffer_age_str;
+  if (context->getProperty(MaxBufferAge.getName(), max_buffer_age_str)) {
+core::TimeUnit unit;
+uint64_t max_buffer_age;
+if (core::Property::StringToTime(max_buffer_age_str, max_buffer_age, unit) 
&& core::Property::ConvertTimeUnitToMS(max_buffer_age, unit, max_buffer_age)) {
+  buffer_.setMaxAge(max_buffer_age);
+  logger_->log_trace("The Buffer maximum age is configured to be %" PRIu64 
" ms", max_buffer_age);
+}
+  }
+
+  std::string max_buffer_size_str;
+  if (context->getProperty(MaxBufferSize.getName(), max_buffer_size_str)) {
+uint64_t max_buffer_size = 
core::DataSizeValue(max_buffer_size_str).getValue();
+if (max_buffer_size > 0) {
+  buffer_.setMaxSize(max_buffer_size);
+  logger_->log_trace("The Buffer maximum size is configured to be %" 
PRIu64 " B", max_buffer_size);
+}
+  }
+
+  context->getProperty(PatternLoc.getName(), pattern_location_);
+
+  std::string pattern_str;
+  if (context->getProperty(Pattern.getName(), pattern_str) && pattern_str != 
"") {
+pattern_ = std::regex(pattern_str);
+logger_->log_trace("The Pattern is configured to be %s", pattern_str);
+  } else {
+throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Pattern property missing or 
invalid");
+  }
+}
+
+void DefragmentText::onTrigger(core::ProcessContext*, core::ProcessSession* 
session) {
+  gsl_Expects(session);
+  std::lock_guard defrag_lock(defrag_mutex_);
+  auto flowFiles = flow_file_store_.getNewFlowFiles();
+  for (auto& file : flowFiles) {
+processNextFragment(session, file);
+  }
+  std::shared_ptr original_flow_file = session->get();
+  processNextFragment(session, original_flow_file);
+  if (buffer_.maxAgeReached() || buffer_.maxSizeReached()) {
+buffer_.flushAndReplace(session, Failure, nullptr);
+  }
+}
+
+void DefragmentText::processNextFragment(core::ProcessSession *session, 

[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragmentText processor

2021-10-18 Thread GitBox


martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r731091666



##
File path: extensions/standard-processors/processors/DefragmentText.cpp
##
@@ -26,38 +26,38 @@
 
 namespace org::apache::nifi::minifi::processors {
 
-const core::Relationship DefragTextFlowFiles::Success("success", "Flowfiles 
that have no fragmented messages in them");
-const core::Relationship DefragTextFlowFiles::Failure("failure", "Flowfiles 
that failed the defragmentation process");
-const core::Relationship DefragTextFlowFiles::Self("__self__", "Marks the 
FlowFile to be owned by this processor");
+const core::Relationship DefragmentText::Success("success", "Flowfiles that 
have no fragmented messages in them");
+const core::Relationship DefragmentText::Failure("failure", "Flowfiles that 
failed the defragmentation process");
+const core::Relationship DefragmentText::Self("__self__", "Marks the FlowFile 
to be owned by this processor");
 
-const core::Property DefragTextFlowFiles::Pattern(
+const core::Property DefragmentText::Pattern(
 core::PropertyBuilder::createProperty("Pattern")
 ->withDescription("A regular expression to match at the start or end 
of messages.")
 ->withDefaultValue("")->isRequired(true)->build());
 
-const core::Property DefragTextFlowFiles::PatternLoc(
+const core::Property DefragmentText::PatternLoc(
 core::PropertyBuilder::createProperty("Pattern 
Location")->withDescription("Where to look for the pattern.")
 ->withAllowableValues(PatternLocation::values())
 
->withDefaultValue(toString(PatternLocation::START_OF_MESSAGE))->build());
 
 
-const core::Property DefragTextFlowFiles::MaxBufferSize(
+const core::Property DefragmentText::MaxBufferSize(
 core::PropertyBuilder::createProperty("Max Buffer Size")
 ->withDescription("The maximum buffer size, if the buffer exceeds 
this, it will be transferred to failure. Expected format is  ")
 
->withType(core::StandardValidators::get().DATA_SIZE_VALIDATOR)->build());
 
-const core::Property DefragTextFlowFiles::MaxBufferAge(
+const core::Property DefragmentText::MaxBufferAge(
 core::PropertyBuilder::createProperty("Max Buffer Age")->
 withDescription("The maximum age of a buffer after which the buffer 
will be transferred to failure. Expected format is  ")->build());
 
-void DefragTextFlowFiles::initialize() {
+void DefragmentText::initialize() {
   std::lock_guard defrag_lock(defrag_mutex_);
 
   setSupportedRelationships({Success, Failure});
   setSupportedProperties({Pattern, PatternLoc, MaxBufferAge, MaxBufferSize});
 }
 
-void DefragTextFlowFiles::onSchedule(core::ProcessContext* context, 
core::ProcessSessionFactory*) {
+void DefragmentText::onSchedule(core::ProcessContext* context, 
core::ProcessSessionFactory*) {
   gsl_Expects(context);
   std::lock_guard defrag_lock(defrag_mutex_);

Review comment:
   Since these functions are on the public interface, I felt that they 
should be defended againts multithreaded usage (onSchedule especially since it 
writes the class members, while onTrigger uses these)
   But since it is not the case in other processors, I removed them to be more 
readable. 
https://github.com/apache/nifi-minifi-cpp/commit/ed5c9672a4d451cea91998ea9a72dda78121ef02
   This was also discussed in a previous PR 
https://github.com/apache/nifi-minifi-cpp/pull/1178#discussion_r719358796

##
File path: PROCESSORS.md
##
@@ -295,6 +296,30 @@ In the list below, the names of required properties appear 
in bold. Any other pr
 | - | - |
 |success|FlowFiles that are sent successfully to the destination are 
transferred to this relationship|
 
+## DefragmentText
+
+### Description
+
+DefragmentText splits and merges incoming flowfiles so cohesive messages are 
not split between them
+### Properties
+
+In the list below, the names of required properties appear in bold. Any other 
properties (not in bold) are considered optional. The table also indicates any 
default values, and whether a property supports the NiFi Expression Language.
+
+| Name | Default Value | Allowable Values | Description |
+| - | - | - | - |
+|**Pattern**|||A regular expression to match at the start or end of messages.|
+|Pattern Location|||Where to look for the pattern.|

Review comment:
   good catch changed it in 
https://github.com/apache/nifi-minifi-cpp/commit/ed5c9672a4d451cea91998ea9a72dda78121ef02

##
File path: extensions/standard-processors/processors/DefragmentText.cpp
##
@@ -0,0 +1,347 @@
+/**
+ * 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