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

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

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

    https://github.com/apache/metron/pull/740#discussion_r137926435
  
    --- Diff: 
metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/shell/StellarShell.java
 ---
    @@ -287,39 +294,131 @@ private void handleStellar(String expression) {
        * Executes a magic expression.
        * @param rawExpression The expression to execute.
        */
    -  private void handleMagic( String rawExpression) {
    -    String[] expression = rawExpression.trim().split(" ");
    +  private void handleMagic(String rawExpression) {
     
    +    String[] expression = rawExpression.trim().split("\\s+");
         String command = expression[0];
    -    if(MAGIC_FUNCTIONS.equals(command)) {
     
    -      // if '%functions FOO' then show only functions that contain 'FOO'
    -      Predicate<String> nameFilter = (name -> true);
    -      if(expression.length > 1) {
    -        nameFilter = (name -> name.contains(expression[1]));
    -      }
    +    if (MAGIC_FUNCTIONS.equals(command)) {
    +      handleMagicFunctions(expression);
    +
    +    } else if (MAGIC_VARS.equals(command)) {
    +      handleMagicVars();
     
    -      // list available functions
    -      String functions = StreamSupport
    -              
.stream(executor.getFunctionResolver().getFunctionInfo().spliterator(), false)
    -              .map(info -> String.format("%s", info.getName()))
    -              .filter(nameFilter)
    -              .sorted()
    -              .collect(Collectors.joining(", "));
    -      writeLine(functions);
    +    } else if (MAGIC_GLOBALS.equals(command)) {
    +      handleMagicGlobals();
     
    -    } else if(MAGIC_VARS.equals(command)) {
    +    } else if (MAGIC_DEFINE.equals(command)) {
    +      handleMagicDefine(rawExpression);
     
    -      // list all variables
    -      executor.getVariables()
    -              .forEach((k,v) -> writeLine(String.format("%s = %s", k, v)));
    +    } else if(MAGIC_UNDEFINE.equals(command)) {
    +      handleMagicUndefine(expression);
     
         } else {
           writeLine(ERROR_PROMPT + "undefined magic command: " + 
rawExpression);
         }
       }
     
       /**
    +   * Handle a magic '%functions'.  Lists all of the variables in-scope.
    +   * @param expression
    +   */
    +  private void handleMagicFunctions(String[] expression) {
    +
    +    // if '%functions FOO' then show only functions that contain 'FOO'
    +    Predicate<String> nameFilter = (name -> true);
    +    if (expression.length > 1) {
    +      nameFilter = (name -> name.contains(expression[1]));
    +    }
    +
    +    // '%functions' -> list all functions in scope
    +    String functions = StreamSupport
    +            
.stream(executor.getFunctionResolver().getFunctionInfo().spliterator(), false)
    +            .map(info -> String.format("%s", info.getName()))
    +            .filter(nameFilter)
    +            .sorted()
    +            .collect(Collectors.joining(", "));
    +    writeLine(functions);
    +  }
    +
    +  /**
    +   * Handle a magic '%vars'.  Lists all of the variables in-scope.
    +   */
    +  private void handleMagicVars() {
    +    executor.getVariables()
    +            .forEach((k, v) -> writeLine(String.format("%s = %s", k, v)));
    +  }
    +
    +  /**
    +   * Handle a magic '%globals'.  List all of the global configuration 
values.
    +   */
    +  private void handleMagicGlobals() {
    +    Map<String, Object> globals = getOrCreateGlobalConfig(executor);
    +    writeLine(globals.toString());
    +  }
    +
    +  /**
    +   * Handle a magic '%define var=value'.  Alter the global configuration.
    +   * @param expression The expression passed to %define
    +   */
    +  public void handleMagicDefine(String expression) {
    +
    +    // grab the expression in '%define <assign-expression>'
    +    String assignExpr = 
StringUtils.trimToEmpty(expression.substring(MAGIC_DEFINE.length()));
    +    if (assignExpr.length() > 0) {
    +
    +      // the expression must be an assignment
    +      if(StellarAssignment.isAssignment(assignExpr)) {
    +        StellarAssignment expr = StellarAssignment.from(assignExpr);
    --- End diff --
    
    Here I leveraged the same assignment code that is used elsewhere in the 
REPL.


> Define Session Specific Global Configuration Values in the REPL
> ---------------------------------------------------------------
>
>                 Key: METRON-1167
>                 URL: https://issues.apache.org/jira/browse/METRON-1167
>             Project: Metron
>          Issue Type: Improvement
>    Affects Versions: 0.4.0
>            Reporter: Nick Allen
>            Assignee: Nick Allen
>             Fix For: Next + 1
>
>
> Many Stellar functions accept configuration values from the Global 
> configuration.  When using the REPL you can load the global configuration 
> values by launching the REPL with the -z option, which loads the global 
> configuration stored in Zookeeper.
> The only way to modify the global configuration within the REPL currently is 
> to do the following steps.
> 1. Retrieve the global configuration with conf := CONFIG_GET("global")
> 2. Alter that global configuration by modifying the JSON contained in the 
> `conf` variable.
> 3. Push the new global configuration using CONFIG_PUT("global", conf)
> 4. Close and then reopen the REPL.  Without restarting the REPL the new 
> global configuration is not loaded.
> I want a way to do this directly in the REPL, without restarting it, and also 
> in a way that does not modify the persisted global configuration in 
> Zookeeper.  I may be monkeying with something the REPL, but I don't want to 
> break one of my live Metron topologies.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to