metron-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cestella <...@git.apache.org>
Subject [GitHub] metron pull request #705: METRON-1118 Ignore Profile with Bad 'onlyif' or 'f...
Date Wed, 23 Aug 2017 13:59:32 GMT
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/705#discussion_r134758177
  
    --- Diff: metron-analytics/metron-profiler-common/src/main/java/org/apache/metron/profiler/DefaultMessageRouter.java
---
    @@ -62,21 +68,45 @@ public DefaultMessageRouter(Context context) {
       @Override
       public List<MessageRoute> route(JSONObject message, ProfilerConfig config, Context
context) {
         List<MessageRoute> routes = new ArrayList<>();
    -    @SuppressWarnings("unchecked")
    -    final Map<String, Object> state = (Map<String, Object>) message;
     
         // attempt to route the message to each of the profiles
         for (ProfileConfig profile: config.getProfiles()) {
    +      Optional<MessageRoute> route = routeToProfile(message, profile);
    +      route.ifPresent(routes::add);
    +    }
     
    +    return routes;
    +  }
    +
    +  /**
    +   * Creates a route if a message is needed by a profile.
    +   * @param message The message that needs routed.
    +   * @param profile The profile that may need the message.
    +   * @return A MessageRoute if the message is needed by the profile.
    +   */
    +  private Optional<MessageRoute> routeToProfile(JSONObject message, ProfileConfig
profile) {
    +    Optional<MessageRoute> route = Optional.empty();
    +
    +    // allow the profile to access the fields defined within the message
    +    @SuppressWarnings("unchecked")
    +    final Map<String, Object> state = (Map<String, Object>) message;
    +
    +    try {
           // is this message needed by this profile?
           if (executor.execute(profile.getOnlyif(), state, Boolean.class)) {
     
             // what is the name of the entity in this message?
             String entity = executor.execute(profile.getForeach(), state, String.class);
    -        routes.add(new MessageRoute(profile, entity));
    +        route = Optional.of(new MessageRoute(profile, entity));
           }
    +
    +    } catch(Exception e) {
    --- End diff --
    
    What do you think about catching Throwable there?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message