Search in sources :

Example 96 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class RuleProcessorRuntime method createGroovyScript.

private Script createGroovyScript(Rule rule) {
    LOG.info("Creating groovy execution script for rule {} ", rule);
    GroovyExpression groovyExpression = new GroovyExpression(rule.getCondition());
    GroovyScriptEngine groovyScriptEngine = new GroovyScriptEngine();
    GroovyScript<Boolean> groovyScript = createHelperGroovyScript(groovyExpression, groovyScriptEngine);
    GroovyScript<Collection<StreamlineEvent>> wrapper = new GroovyScript<Collection<StreamlineEvent>>(groovyExpression.asString(), groovyScriptEngine) {

        @Override
        public Collection<StreamlineEvent> evaluate(StreamlineEvent event) throws ScriptException {
            if (groovyScript.evaluate(event)) {
                return Collections.singletonList(event);
            } else {
                return Collections.emptyList();
            }
        }
    };
    return wrapper;
}
Also used : GroovyScript(com.hortonworks.streamline.streams.runtime.script.GroovyScript) GroovyScriptEngine(com.hortonworks.streamline.streams.runtime.script.engine.GroovyScriptEngine) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Collection(java.util.Collection) GroovyExpression(com.hortonworks.streamline.streams.runtime.rule.condition.expression.GroovyExpression)

Example 97 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class MergeTransformRuntimeTest method testExecute.

@Test
public void testExecute() throws Exception {
    Map<String, Object> fieldsAndValues = new HashMap<>();
    fieldsAndValues.put("1", "one");
    fieldsAndValues.put("2", "two");
    Map<String, String> defaults = new HashMap<>();
    defaults.put("2", "TWO");
    defaults.put("3", "THREE");
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("dsrcid").build();
    TransformRuntime transformRuntime = new MergeTransformRuntime(new MergeTransform(defaults));
    List<StreamlineEvent> result = transformRuntime.execute(event);
    System.out.println(result);
    assertEquals(1, result.size());
    assertEquals("two", result.get(0).get("2"));
    assertEquals("THREE", result.get(0).get("3"));
}
Also used : MergeTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.MergeTransform) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) TransformRuntime(com.hortonworks.streamline.streams.runtime.TransformRuntime) Test(org.junit.Test)

Aggregations

StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)97 Test (org.junit.Test)47 HashMap (java.util.HashMap)41 Values (org.apache.storm.tuple.Values)25 ArrayList (java.util.ArrayList)19 Tuple (org.apache.storm.tuple.Tuple)14 Result (com.hortonworks.streamline.streams.Result)13 Expectations (mockit.Expectations)9 TupleImpl (org.apache.storm.tuple.TupleImpl)9 Map (java.util.Map)8 Verifications (mockit.Verifications)8 TransformRuntime (com.hortonworks.streamline.streams.runtime.TransformRuntime)7 ProcessingException (com.hortonworks.streamline.streams.exception.ProcessingException)6 StormSqlExpression (com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression)6 List (java.util.List)5 IdPreservedStreamlineEvent (com.hortonworks.streamline.streams.common.IdPreservedStreamlineEvent)4 StreamlineEventImpl (com.hortonworks.streamline.streams.common.StreamlineEventImpl)4 Fields (org.apache.storm.tuple.Fields)4 EventCorrelationInjector (com.hortonworks.streamline.streams.common.event.correlation.EventCorrelationInjector)3 MergeTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.MergeTransform)3