[ 
https://issues.apache.org/jira/browse/METRON-1820?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16646912#comment-16646912
 ] 

ASF GitHub Bot commented on METRON-1820:
----------------------------------------

Github user mmiklavc commented on a diff in the pull request:

    https://github.com/apache/metron/pull/1234#discussion_r224566471
  
    --- Diff: 
metron-platform/metron-parsers/src/main/java/org/apache/metron/parsers/syslog/Syslog5424Parser.java
 ---
    @@ -61,16 +67,37 @@ public void configure(Map<String, Object> config) {
       public void init() {
       }
     
    -  @Override
       @SuppressWarnings("unchecked")
    +  @Override
       public List<JSONObject> parse(byte[] rawMessage) {
    +    Optional<MessageParserResult<JSONObject>> resultOptional = 
parseOptionalResult(rawMessage);
    --- End diff --
    
    Just spitballing here, but maybe an option here is to create a decorator 
interface around the older implementation and provide defaults when someone 
implements the new interface? Old api doesn't change and we handle new 
implementations gracefully.
    
    ```java
    public interface MessageParser<T> extends Configurable {
      List<T> parse(byte[] rawMessage);
      Optional<List<T>> parseOptional(byte[] parseMessage);
    }
    public interface MultilineMessageParser<T> extends MessageParser {
      default List<T> parse(byte[] rawMessage) {
        throw new NotImplementedException();
      }
      default Optional<MessageParserResult<T>> parseOptionalResult(byte[] 
parseMessage) {
        List<T> list = new ArrayList<>();
          try {
            Optional<List<T>> optionalMessages = parseOptional(parseMessage);
            optionalMessages.ifPresent(list::addAll);
          } catch (Throwable t) {
            return Optional.of(new DefaultMessageParserResult<>(t));
          }
          return Optional.of(new DefaultMessageParserResult<T>(list));
      }
    }
    ```
    
    **ParserBolt:**
    ```java
    MultilineMessageParser mmp = null;
    if (!(parser instanceof MultilineMessageParser)) {
      mmp = new MultilineMessageParser<JSONObject>() {
    
        @Override
        public void configure(Map<String, Object> config) {
          parser.configure(config);
        }
    
        @Override
        public void init() {
          parser.init();
        }
    
        @Override
        public boolean validate(JSONObject message) {
          return parser.validate(message);
        }
      };
    } else {
      mmp = (MultilineMessageParser) parser;
    }
    
    Optional<MessageParserResult<JSONObject>> results = 
mmp.parseOptionalResult(rawMessage.getMessage());
    ```



> Update to new Simple-Syslog-5424 version to support error handling
> ------------------------------------------------------------------
>
>                 Key: METRON-1820
>                 URL: https://issues.apache.org/jira/browse/METRON-1820
>             Project: Metron
>          Issue Type: Sub-task
>            Reporter: Otto Fowler
>            Assignee: Otto Fowler
>            Priority: Major
>
> Now that we have an api to support handling per line errors in metron, 
> upgrade to the newest version of the simple-syslog5424 library which also 
> supports this



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to