Search in sources :

Example 6 with DefaultStellarShellExecutor

use of org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor in project metron by apache.

the class MagicListVariablesTest method setup.

@Before
public void setup() throws Exception {
    // setup the %magic
    magic = new MagicListVariables();
    // setup the executor
    Properties props = new Properties();
    executor = new DefaultStellarShellExecutor(props, Optional.empty());
    executor.init();
}
Also used : Properties(java.util.Properties) DefaultStellarShellExecutor(org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor) Before(org.junit.Before)

Example 7 with DefaultStellarShellExecutor

use of org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor in project metron by apache.

the class MagicUndefineGlobalTest method setup.

@Before
public void setup() throws Exception {
    // setup the %magic
    magic = new MagicUndefineGlobal();
    // setup the executor
    Properties props = new Properties();
    executor = new DefaultStellarShellExecutor(props, Optional.empty());
    executor.init();
}
Also used : Properties(java.util.Properties) DefaultStellarShellExecutor(org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor) Before(org.junit.Before)

Example 8 with DefaultStellarShellExecutor

use of org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor in project metron by apache.

the class StellarShell method createExecutor.

/**
 * Creates the Stellar execution environment.
 * @param commandLine The command line arguments.
 * @param console The console which drives the REPL.
 * @param properties Stellar properties.
 */
private StellarShellExecutor createExecutor(CommandLine commandLine, Console console, Properties properties, StellarAutoCompleter autoCompleter) throws Exception {
    // setup zookeeper client
    Optional<String> zookeeperUrl = Optional.empty();
    if (commandLine.hasOption("z")) {
        zookeeperUrl = Optional.of(commandLine.getOptionValue("z"));
    }
    StellarShellExecutor executor = new DefaultStellarShellExecutor(properties, zookeeperUrl);
    // the 'CONSOLE' capability is only available with the CLI REPL
    executor.getContext().addCapability(CONSOLE, () -> console);
    // allows some Stellar functions to access Stellar internals; should probably use %magics instead
    executor.getContext().addCapability(SHELL_VARIABLES, () -> executor.getState());
    // register the auto-completer to be notified when needed
    executor.addSpecialListener((special) -> autoCompleter.addCandidateFunction(special.getCommand()));
    executor.addFunctionListener((function) -> autoCompleter.addCandidateFunction(function.getName()));
    executor.addVariableListener((name, val) -> autoCompleter.addCandidateVariable(name));
    executor.init();
    return executor;
}
Also used : DefaultStellarShellExecutor(org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor) DefaultStellarShellExecutor(org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor) StellarShellExecutor(org.apache.metron.stellar.common.shell.StellarShellExecutor)

Example 9 with DefaultStellarShellExecutor

use of org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor in project metron by apache.

the class DocCommandTest method setup.

@Before
public void setup() throws Exception {
    // setup the command
    command = new DocCommand();
    // setup a function resolver - only 3 functions have been defined
    SimpleFunctionResolver functionResolver = new SimpleFunctionResolver().withClass(StringFunctions.ToString.class).withClass(StringFunctions.ToLower.class).withClass(StringFunctions.ToUpper.class);
    // setup the executor
    Properties props = new Properties();
    executor = new DefaultStellarShellExecutor(functionResolver, props, Optional.empty());
    executor.init();
}
Also used : StringFunctions(org.apache.metron.stellar.dsl.functions.StringFunctions) SimpleFunctionResolver(org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver) Properties(java.util.Properties) DefaultStellarShellExecutor(org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor) Before(org.junit.Before)

Example 10 with DefaultStellarShellExecutor

use of org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor in project metron by apache.

the class StellarInterpreter method createExecutor.

/**
 * Create an executor that will run the Stellar code for the Zeppelin Notebook.
 * @return The stellar executor.
 */
private StellarShellExecutor createExecutor() throws Exception {
    Properties props = getProperty();
    StellarShellExecutor executor = new DefaultStellarShellExecutor(props, Optional.empty());
    // register the auto-completer to be notified
    executor.addSpecialListener((magic) -> autoCompleter.addCandidateFunction(magic.getCommand()));
    executor.addFunctionListener((fn) -> autoCompleter.addCandidateFunction(fn.getName()));
    executor.addVariableListener((name, val) -> autoCompleter.addCandidateVariable(name));
    executor.init();
    return executor;
}
Also used : Properties(java.util.Properties) DefaultStellarShellExecutor(org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor) DefaultStellarShellExecutor(org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor) StellarShellExecutor(org.apache.metron.stellar.common.shell.StellarShellExecutor)

Aggregations

DefaultStellarShellExecutor (org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor)10 Properties (java.util.Properties)9 Before (org.junit.Before)8 StellarShellExecutor (org.apache.metron.stellar.common.shell.StellarShellExecutor)2 StringFunctions (org.apache.metron.stellar.dsl.functions.StringFunctions)2 SimpleFunctionResolver (org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver)2