Search in sources :

Example 1 with Stellar

use of org.apache.metron.stellar.dsl.Stellar 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;
}
Also used : StellarFunctionInfo(org.apache.metron.stellar.dsl.StellarFunctionInfo) StellarFunction(org.apache.metron.stellar.dsl.StellarFunction) Stellar(org.apache.metron.stellar.dsl.Stellar)

Example 2 with Stellar

use of org.apache.metron.stellar.dsl.Stellar in project metron by apache.

the class BasicStellarTest method ensureDocumentation.

@Test
public void ensureDocumentation() {
    ClassLoader classLoader = getClass().getClassLoader();
    int numFound = 0;
    for (Class<?> clazz : new ClasspathFunctionResolver().resolvables()) {
        if (clazz.isAnnotationPresent(Stellar.class)) {
            numFound++;
            Stellar annotation = clazz.getAnnotation(Stellar.class);
            Assert.assertFalse("Must specify a name for " + clazz.getName(), StringUtils.isEmpty(annotation.name()));
            Assert.assertFalse("Must specify a description annotation for " + clazz.getName(), StringUtils.isEmpty(annotation.description()));
            Assert.assertFalse("Must specify a returns annotation for " + clazz.getName(), StringUtils.isEmpty(annotation.returns()));
        }
    }
    Assert.assertTrue(numFound > 0);
}
Also used : ClasspathFunctionResolver(org.apache.metron.stellar.dsl.functions.resolver.ClasspathFunctionResolver) Stellar(org.apache.metron.stellar.dsl.Stellar) Test(org.junit.Test)

Aggregations

Stellar (org.apache.metron.stellar.dsl.Stellar)2 StellarFunction (org.apache.metron.stellar.dsl.StellarFunction)1 StellarFunctionInfo (org.apache.metron.stellar.dsl.StellarFunctionInfo)1 ClasspathFunctionResolver (org.apache.metron.stellar.dsl.functions.resolver.ClasspathFunctionResolver)1 Test (org.junit.Test)1