You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@metron.apache.org by nickwallen <gi...@git.apache.org> on 2016/09/20 16:17:59 UTC

[GitHub] incubator-metron pull request #262: METRON-421 Create Stellar REPL

GitHub user nickwallen opened a pull request:

    https://github.com/apache/incubator-metron/pull/262

    METRON-421 Create Stellar REPL

    Created this for debugging some issues I was having in running Stellar functions are on a live cluster.  Thought this would be generally useful on its own.
    
    METRON-435
    
    Create a REPL (Read Eval Print Loop) for the Stellar language that helps in debugging, troubleshooting and learning Stellar. The Stellar DSL (domain specific language) is used to act upon streaming data within Apache Storm. It is difficult to troubleshoot Stellar when it can only be executed within a Storm topology. This REPL is intended to help mitigate that problem by allowing a user to replicate data encountered in production, isolate initialization errors, or understand function resolution problems.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/nickwallen/incubator-metron METRON-435

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-metron/pull/262.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #262
    
----

----


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

[GitHub] incubator-metron pull request #262: METRON-421 Create Stellar REPL

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/incubator-metron/pull/262#discussion_r79652429
  
    --- Diff: metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/shell/StellarShell.java ---
    @@ -0,0 +1,215 @@
    +/*
    + *
    + *  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 org.apache.commons.cli.CommandLine;
    +import org.apache.commons.cli.CommandLineParser;
    +import org.apache.commons.cli.HelpFormatter;
    +import org.apache.commons.cli.Options;
    +import org.apache.commons.cli.PosixParser;
    +import org.apache.commons.lang3.StringUtils;
    +import org.apache.metron.common.dsl.Context;
    +
    +import java.util.Scanner;
    +import java.util.stream.Collectors;
    +import java.util.stream.StreamSupport;
    +
    +import static java.lang.String.format;
    +
    +/**
    + * A REPL environment for Stellar.
    + *
    + * Useful for debugging Stellar expressions.
    + */
    +public class StellarShell {
    +
    +  private static final String WELCOME = "Stellar, Go!";
    --- End diff --
    
    I LOL'd


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

[GitHub] incubator-metron issue #262: METRON-435 Create Stellar REPL

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:

    https://github.com/apache/incubator-metron/pull/262
  
    What, no autocomplete? ;)


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

[GitHub] incubator-metron issue #262: METRON-435 Create Stellar REPL

Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on the issue:

    https://github.com/apache/incubator-metron/pull/262
  
    Also, added a doc string type functionality.  I couldn't help myself.
    
    ```
    >>> ?PROTOCOL_TO_NAME
    PROTOCOL_TO_NAME
     desc: Convert the IANA protocol number to the protocol name       
     args: IANA Number                                                 
      ret: The protocol name associated with the IANA number.  
    ```


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

[GitHub] incubator-metron issue #262: METRON-435 Create Stellar REPL

Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on the issue:

    https://github.com/apache/incubator-metron/pull/262
  
    Ha, trust me, I wanted to do it.


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

[GitHub] incubator-metron pull request #262: METRON-435 Create Stellar REPL

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-metron/pull/262


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

[GitHub] incubator-metron issue #262: METRON-421 Create Stellar REPL

Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on the issue:

    https://github.com/apache/incubator-metron/pull/262
  
    Oops, yes.  Let me fix.


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

[GitHub] incubator-metron issue #262: METRON-421 Create Stellar REPL

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:

    https://github.com/apache/incubator-metron/pull/262
  
    did you mean to title this METRON-435?


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

[GitHub] incubator-metron pull request #262: METRON-421 Create Stellar REPL

Posted by cestella <gi...@git.apache.org>.
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.


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

[GitHub] incubator-metron issue #262: METRON-435 Create Stellar REPL

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:

    https://github.com/apache/incubator-metron/pull/262
  
    Bonus points if you had used https://github.com/qmx/jreadline and given us emacs and vi mode as well as a hook for autocomplete :)


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

[GitHub] incubator-metron issue #262: METRON-435 Create Stellar REPL

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:

    https://github.com/apache/incubator-metron/pull/262
  
    +1, we can iterate from here.  I think this is going to be super useful.


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

[GitHub] incubator-metron pull request #262: METRON-435 Create Stellar REPL

Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on a diff in the pull request:

    https://github.com/apache/incubator-metron/pull/262#discussion_r79681676
  
    --- 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 --
    
    Added zookeeper client to the Context.


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