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

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

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

    https://github.com/apache/incubator-metron/pull/262#discussion_r79652181
  
    --- Diff: 
metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/shell/StellarExecutor.java
 ---
    @@ -0,0 +1,130 @@
    +/*
    + *
    + *  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.
    + *
    + */
    +
    +package org.apache.metron.common.stellar.shell;
    +
    +import com.fasterxml.jackson.core.type.TypeReference;
    +import org.apache.commons.lang.StringUtils;
    +import org.apache.curator.framework.CuratorFramework;
    +import org.apache.metron.common.configuration.ConfigurationsUtils;
    +import org.apache.metron.common.dsl.Context;
    +import org.apache.metron.common.dsl.FunctionResolver;
    +import org.apache.metron.common.dsl.MapVariableResolver;
    +import org.apache.metron.common.dsl.StellarFunctions;
    +import org.apache.metron.common.dsl.VariableResolver;
    +import org.apache.metron.common.stellar.StellarProcessor;
    +import org.apache.metron.common.utils.JSONUtils;
    +
    +import java.io.ByteArrayInputStream;
    +import java.util.Collections;
    +import java.util.HashMap;
    +import java.util.Map;
    +
    +import static 
org.apache.metron.common.configuration.ConfigurationsUtils.readGlobalConfigBytesFromZookeeper;
    +
    +/**
    + * Executes Stellar expressions and maintains state across multiple 
invocations.
    + */
    +public class StellarExecutor {
    +
    +  /**
    +   * The variables known by Stellar.
    +   */
    +  private Map<String, Object> variables;
    +
    +  /**
    +   * The function resolver.
    +   */
    +  private FunctionResolver functionResolver ;
    +
    +  /**
    +   * The context
    +   */
    +  private Context context;
    +
    +  public StellarExecutor() throws Exception {
    +    this(null);
    +  }
    +
    +  public StellarExecutor(String zookeeperUrl) throws Exception {
    +    this.variables = new HashMap<>();
    +    this.functionResolver = new StellarFunctions().FUNCTION_RESOLVER();
    +    this.context = getContext(zookeeperUrl);
    +  }
    +
    +  /**
    +   * Creates a Context initialized with configuration stored in Zookeeper.
    +   * @param zookeeperUrl The Zookeeper URL.
    +   */
    +  private Context getContext(String zookeeperUrl) throws Exception {
    +    Context context = Context.EMPTY_CONTEXT();
    +
    +    // load global configuration from zookeeper
    +    if(StringUtils.isNotBlank(zookeeperUrl)) {
    +      try (CuratorFramework client = 
ConfigurationsUtils.getClient(zookeeperUrl)) {
    +        client.start();
    +
    +        Map<String, Object> global = JSONUtils.INSTANCE.load(
    +                new 
ByteArrayInputStream(readGlobalConfigBytesFromZookeeper(client)),
    +                new TypeReference<Map<String, Object>>() {
    +                });
    +
    +        context = new Context.Builder()
    +                .with(Context.Capabilities.GLOBAL_CONFIG, () -> global)
    --- End diff --
    
    Can we add the `Context.Capabilities.ZOOKEEPER_CLIENT` as well?  Looks like 
we have it right there on line 81.


> Make Stellar Profiler Client API Accessible in Parser and Enrichment 
> Topologies
> -------------------------------------------------------------------------------
>
>                 Key: METRON-421
>                 URL: https://issues.apache.org/jira/browse/METRON-421
>             Project: Metron
>          Issue Type: Improvement
>            Reporter: Nick Allen
>            Assignee: Nick Allen
>
> A user should be able to use the Stellar Profiler Client API from the Parser 
> and Enrichment topologies.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to