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;
}
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;
}
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;
}
Aggregations