Search in sources :

Example 1 with StellarShellExecutor

use of org.apache.metron.stellar.common.shell.StellarShellExecutor 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 2 with StellarShellExecutor

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

the class DocCommand method execute.

@Override
public StellarResult execute(String command, StellarShellExecutor executor) {
    StellarResult result;
    // expect ?functionName
    String functionName = StringUtils.substring(command, 1);
    // grab any docs for the given function
    Spliterator<StellarFunctionInfo> fnIterator = executor.getFunctionResolver().getFunctionInfo().spliterator();
    Optional<StellarFunctionInfo> functionInfo = StreamSupport.stream(fnIterator, false).filter(info -> StringUtils.equals(functionName, info.getName())).findFirst();
    if (functionInfo.isPresent()) {
        result = success(docFormat(functionInfo.get()));
    } else {
        result = error(String.format("No docs available for function '%s'", functionName));
    }
    return result;
}
Also used : StellarFunctionInfo(org.apache.metron.stellar.dsl.StellarFunctionInfo) StellarResult.error(org.apache.metron.stellar.common.shell.StellarResult.error) StellarResult(org.apache.metron.stellar.common.shell.StellarResult) Optional(java.util.Optional) StreamSupport(java.util.stream.StreamSupport) StringUtils(org.apache.commons.lang3.StringUtils) Spliterator(java.util.Spliterator) Function(java.util.function.Function) StellarResult.success(org.apache.metron.stellar.common.shell.StellarResult.success) StellarShellExecutor(org.apache.metron.stellar.common.shell.StellarShellExecutor) StellarFunctionInfo(org.apache.metron.stellar.dsl.StellarFunctionInfo) StellarResult(org.apache.metron.stellar.common.shell.StellarResult)

Example 3 with StellarShellExecutor

use of org.apache.metron.stellar.common.shell.StellarShellExecutor 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

StellarShellExecutor (org.apache.metron.stellar.common.shell.StellarShellExecutor)3 DefaultStellarShellExecutor (org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor)2 Optional (java.util.Optional)1 Properties (java.util.Properties)1 Spliterator (java.util.Spliterator)1 Function (java.util.function.Function)1 StreamSupport (java.util.stream.StreamSupport)1 StringUtils (org.apache.commons.lang3.StringUtils)1 StellarResult (org.apache.metron.stellar.common.shell.StellarResult)1 StellarResult.error (org.apache.metron.stellar.common.shell.StellarResult.error)1 StellarResult.success (org.apache.metron.stellar.common.shell.StellarResult.success)1 StellarFunctionInfo (org.apache.metron.stellar.dsl.StellarFunctionInfo)1