use of org.apache.metron.stellar.dsl.StellarFunctionInfo in project metron by apache.
the class StellarServiceImpl method getStellarFunctions.
@Override
public List<StellarFunctionDescription> getStellarFunctions() {
List<StellarFunctionDescription> stellarFunctionDescriptions = new ArrayList<>();
Iterable<StellarFunctionInfo> stellarFunctionsInfo = StellarFunctions.FUNCTION_RESOLVER().getFunctionInfo();
stellarFunctionsInfo.forEach(stellarFunctionInfo -> {
stellarFunctionDescriptions.add(new StellarFunctionDescription(stellarFunctionInfo.getName(), stellarFunctionInfo.getDescription(), stellarFunctionInfo.getParams(), stellarFunctionInfo.getReturns()));
});
return stellarFunctionDescriptions;
}
use of org.apache.metron.stellar.dsl.StellarFunctionInfo in project metron by apache.
the class BaseFunctionResolver method resolveFunctions.
/**
* Performs the core process of function resolution.
*/
protected Map<String, StellarFunctionInfo> resolveFunctions() {
// maps a function name to its definition
Map<String, StellarFunctionInfo> functions = new HashMap<>();
for (Class<? extends StellarFunction> clazz : resolvables()) {
StellarFunctionInfo fn = resolveFunction(clazz);
if (fn != null) {
// check for duplicate function names
StellarFunctionInfo fnSameName = functions.get(fn.getName());
if (fnSameName != null && ObjectUtils.notEqual(fnSameName, fn)) {
LOG.warn("Namespace conflict: duplicate function names; `{}` implemented by [{}, {}]", fn.getName(), fnSameName.getFunction(), fn.getFunction());
}
functions.put(fn.getName(), fn);
}
}
return functions;
}
use of org.apache.metron.stellar.dsl.StellarFunctionInfo in project metron by apache.
the class DocumentationGenerator method main.
public static void main(String... argv) {
List<StellarFunctionInfo> functions = Lists.newArrayList(SingletonFunctionResolver.getInstance().getFunctionInfo());
Collections.sort(functions, (o1, o2) -> o1.getName().compareTo(o2.getName()));
for (StellarFunctionInfo info : functions) {
System.out.println("### `" + info.getName() + "`");
System.out.println(" * Description: " + info.getDescription());
System.out.println(" * Input:");
for (String param : info.getParams()) {
System.out.println(" * " + param);
}
System.out.println(" * Returns: " + info.getReturns());
System.out.println("");
}
}
use of org.apache.metron.stellar.dsl.StellarFunctionInfo 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.dsl.StellarFunctionInfo in project metron by apache.
the class BaseFunctionResolver method resolveFunction.
/**
* Resolves a Stellar function from a given class.
* @param clazz The class.
*/
public static StellarFunctionInfo resolveFunction(Class<? extends StellarFunction> clazz) {
StellarFunctionInfo info = null;
// the class must be annotated
if (clazz.isAnnotationPresent(Stellar.class)) {
Stellar annotation = clazz.getAnnotation(Stellar.class);
String fullyQualifiedName = getNameFromAnnotation(annotation);
StellarFunction function = createFunction(clazz);
if (fullyQualifiedName != null && function != null) {
info = new StellarFunctionInfo(annotation.description(), fullyQualifiedName, annotation.params(), annotation.returns(), function);
}
}
return info;
}
Aggregations