Search in sources :

Example 11 with UDF

use of com.hortonworks.streamline.streams.catalog.UDF in project streamline by hortonworks.

the class StormTopologyDependenciesHandler method visit.

@Override
public void visit(RulesProcessor rulesProcessor) {
    Set<UDF> udfsToShip = new HashSet<>();
    for (Rule rule : rulesProcessor.getRules()) {
        for (Udf udf : rule.getReferredUdfs()) {
            List<QueryParam> qps = QueryParam.params(UDF.NAME, udf.getName());
            // The null check for backward compatibility
            if (udf.getClassName() != null) {
                qps.add(new QueryParam(UDF.CLASSNAME, udf.getClassName()));
            }
            // The null check for backward compatibility
            if (udf.getType() != null) {
                qps.add(new QueryParam(UDF.TYPE, udf.getType().toString()));
            }
            Collection<UDF> udfs = catalogService.listUDFs(qps);
            if (udfs.size() > 1) {
                throw new IllegalStateException("Multiple UDF definitions for :" + udf);
            } else if (udfs.size() == 1) {
                udfsToShip.add(udfs.iterator().next());
            } else {
                throw new IllegalStateException("No catalog entity for udf: '" + udf + "'. " + "May be the UDF information is not bootstrapped or got deleted.");
            }
        }
        for (UDF udf : udfsToShip) {
            extraJars.add(udf.getJarStoragePath());
        }
    }
    resourceNames.addAll(rulesProcessor.getExtraResources());
    handleBundleForStreamlineComponent(rulesProcessor);
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) UDF(com.hortonworks.streamline.streams.catalog.UDF) Udf(com.hortonworks.streamline.streams.layout.component.rule.expression.Udf) Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule) HashSet(java.util.HashSet)

Example 12 with UDF

use of com.hortonworks.streamline.streams.catalog.UDF in project streamline by hortonworks.

the class UDFCatalogResourceTest method newTestUDF.

private UDF newTestUDF(String fnName, String className) {
    // provide the same info the user would give the UI for a UDF upload
    UDF udf = new UDF();
    udf.setName(fnName);
    udf.setDisplayName(fnName);
    udf.setDescription("Test Function named " + fnName);
    udf.setType(FUNCTION);
    udf.setClassName(className);
    udf.setJarStoragePath(CUSTOM_UDF_MICROTEST_PATH + File.separator + MICROTEST_JAR_NAME);
    udf.setBuiltin(false);
    return udf;
}
Also used : UDF(com.hortonworks.streamline.streams.catalog.UDF)

Example 13 with UDF

use of com.hortonworks.streamline.streams.catalog.UDF in project streamline by hortonworks.

the class UDFCatalogResourceTest method testProcessUdfWithSimpleClass.

@Test
public void testProcessUdfWithSimpleClass() throws Exception {
    String fnName = "FooTriMultiplierUDF";
    String className = getFullClassName(fnName);
    UDF udf = newTestUDF(fnName, className);
    InputStream inputStream = new FileInputStream(udf.getJarStoragePath());
    catalogResource.processUdf(inputStream, udf, true, false);
}
Also used : UDF(com.hortonworks.streamline.streams.catalog.UDF) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 14 with UDF

use of com.hortonworks.streamline.streams.catalog.UDF in project streamline by hortonworks.

the class UDFCatalogResourceTest method testProcessUdfWithInnerClassFqdnName.

@Test
public void testProcessUdfWithInnerClassFqdnName() throws Exception {
    String fnName = "FooPredicateGTZ";
    String fqdnName = "FooInnerclassTestUDFs$FooPredicateGTZ";
    String canonicalName = "FooInnerclassTestUDFs.FooPredicateGTZ.FooAdder";
    String className = getFullClassName(fqdnName);
    UDF udf = newTestUDF(fnName, className);
    InputStream inputStream = new FileInputStream(udf.getJarStoragePath());
    catalogResource.processUdf(inputStream, udf, true, false);
    Assert.assertEquals(getFullClassName(fqdnName), udf.getClassName());
}
Also used : UDF(com.hortonworks.streamline.streams.catalog.UDF) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 15 with UDF

use of com.hortonworks.streamline.streams.catalog.UDF in project streamline by hortonworks.

the class UDFCatalogResourceTest method testProcessUdfWithInnerClassCanonicalName.

@Test
public void testProcessUdfWithInnerClassCanonicalName() throws Exception {
    String fnName = "FooAdder";
    String fqdnName = "FooInnerclassTestUDFs$FooAdder";
    String canonicalName = "FooInnerclassTestUDFs.FooAdder";
    String className = getFullClassName(canonicalName);
    UDF udf = newTestUDF(fnName, className);
    InputStream inputStream = new FileInputStream(udf.getJarStoragePath());
    catalogResource.processUdf(inputStream, udf, true, false);
    Assert.assertEquals(getFullClassName(fqdnName), udf.getClassName());
}
Also used : UDF(com.hortonworks.streamline.streams.catalog.UDF) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

UDF (com.hortonworks.streamline.streams.catalog.UDF)15 Test (org.junit.Test)6 Timed (com.codahale.metrics.annotation.Timed)5 Path (javax.ws.rs.Path)5 TopologyRule (com.hortonworks.streamline.streams.catalog.TopologyRule)3 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 Expectations (mockit.Expectations)3 StorableKey (com.hortonworks.registries.storage.StorableKey)2 UnsupportedMediaTypeException (com.hortonworks.streamline.common.exception.service.exception.request.UnsupportedMediaTypeException)2 TopologyStream (com.hortonworks.streamline.streams.catalog.TopologyStream)2 Stream (com.hortonworks.streamline.streams.layout.component.Stream)2 Random (java.util.Random)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 MediaType (javax.ws.rs.core.MediaType)2 QueryParam (com.hortonworks.registries.common.QueryParam)1 Rule (com.hortonworks.streamline.streams.layout.component.rule.Rule)1 Udf (com.hortonworks.streamline.streams.layout.component.rule.expression.Udf)1