Search in sources :

Example 6 with ConsoleOutputOperator

use of org.apache.apex.malhar.lib.io.ConsoleOutputOperator in project apex-malhar by apache.

the class ExactlyOnceFileOutputApp method populateDAG.

@Override
public void populateDAG(DAG dag, Configuration configuration) {
    KafkaSinglePortStringInputOperator kafkaInput = dag.addOperator("kafkaInput", new KafkaSinglePortStringInputOperator());
    kafkaInput.setWindowDataManager(new FSWindowDataManager());
    ExactlyOnceJdbcOutputApp.UniqueCounterFlat count = dag.addOperator("count", new ExactlyOnceJdbcOutputApp.UniqueCounterFlat());
    FileWriter fileWriter = dag.addOperator("fileWriter", new FileWriter());
    ConsoleOutputOperator cons = dag.addOperator("console", new ConsoleOutputOperator());
    dag.addStream("words", kafkaInput.outputPort, count.data);
    dag.addStream("counts", count.counts, fileWriter.input, cons.input);
}
Also used : ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) KafkaSinglePortStringInputOperator(org.apache.apex.examples.exactlyonce.ExactlyOnceJdbcOutputApp.KafkaSinglePortStringInputOperator) FSWindowDataManager(org.apache.apex.malhar.lib.wal.FSWindowDataManager)

Example 7 with ConsoleOutputOperator

use of org.apache.apex.malhar.lib.io.ConsoleOutputOperator in project apex-malhar by apache.

the class YahooFinanceApplication method getConsole.

/**
 * Get console for output operator.
 * @param name  Operator name
 * @param dag   Application DAG graph.
 * @return input port for console output.
 */
public InputPort<Object> getConsole(String name, /*String nodeName,*/
DAG dag, String prefix) {
    // hack to output to HTTP based on actual environment
    /*
     String serverAddr = System.getenv("MALHAR_AJAXSERVER_ADDRESS");
     if (serverAddr != null) {
     HttpOutputOperator<Object> oper = dag.addOperator(name, new HttpOutputOperator<Object>());
     oper.setResourceURL(URI.create("http://" + serverAddr + "/channel/" + nodeName));
     return oper.input;
     }
     */
    ConsoleOutputOperator oper = dag.addOperator(name, ConsoleOutputOperator.class);
    oper.setStringFormat(prefix + ": %s");
    return oper.input;
}
Also used : ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator)

Example 8 with ConsoleOutputOperator

use of org.apache.apex.malhar.lib.io.ConsoleOutputOperator in project apex-malhar by apache.

the class Application method populateDAG.

@Override
public void populateDAG(DAG dag, Configuration entries) {
    /* Generate random key-value pairs */
    RandomKeysGenerator randGen = dag.addOperator("randomgen", new RandomKeysGenerator());
    /* Initialize with three partition to start with */
    // UniqueCount1 uniqCount = dag.addOperator("uniqevalue", new UniqueCount1());
    UniqueCounter<Integer> uniqCount = dag.addOperator("uniqevalue", new UniqueCounter<Integer>());
    MapToKeyHashValuePairConverter<Integer, Integer> converter = dag.addOperator("converter", new MapToKeyHashValuePairConverter());
    uniqCount.setCumulative(false);
    dag.setAttribute(uniqCount, Context.OperatorContext.PARTITIONER, new StatelessPartitioner<UniqueCounter<Integer>>(3));
    CountVerifier<Integer> verifier = dag.addOperator("verifier", new CountVerifier<Integer>());
    StreamDuplicater<KeyHashValPair<Integer, Integer>> dup = dag.addOperator("dup", new StreamDuplicater<KeyHashValPair<Integer, Integer>>());
    ConsoleOutputOperator output = dag.addOperator("output", new ConsoleOutputOperator());
    ConsoleOutputOperator successOutput = dag.addOperator("successoutput", new ConsoleOutputOperator());
    successOutput.setStringFormat("Success %d");
    ConsoleOutputOperator failureOutput = dag.addOperator("failureoutput", new ConsoleOutputOperator());
    failureOutput.setStringFormat("Failure %d");
    // success and failure counters.
    Counter successcounter = dag.addOperator("successcounter", new Counter());
    Counter failurecounter = dag.addOperator("failurecounter", new Counter());
    dag.addStream("datain", randGen.outPort, uniqCount.data);
    dag.addStream("dataverification0", randGen.verificationPort, verifier.in1);
    dag.addStream("convert", uniqCount.count, converter.input).setLocality(Locality.THREAD_LOCAL);
    dag.addStream("split", converter.output, dup.data);
    dag.addStream("consoutput", dup.out1, output.input);
    dag.addStream("dataverification1", dup.out2, verifier.in2);
    dag.addStream("successc", verifier.successPort, successcounter.input);
    dag.addStream("failurec", verifier.failurePort, failurecounter.input);
    dag.addStream("succconsoutput", successcounter.output, successOutput.input);
    dag.addStream("failconsoutput", failurecounter.output, failureOutput.input);
}
Also used : UniqueCounter(org.apache.apex.malhar.lib.algo.UniqueCounter) ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) Counter(org.apache.apex.malhar.lib.stream.Counter) UniqueCounter(org.apache.apex.malhar.lib.algo.UniqueCounter) MapToKeyHashValuePairConverter(org.apache.apex.malhar.lib.converter.MapToKeyHashValuePairConverter) KeyHashValPair(org.apache.apex.malhar.lib.util.KeyHashValPair)

Example 9 with ConsoleOutputOperator

use of org.apache.apex.malhar.lib.io.ConsoleOutputOperator in project apex-malhar by apache.

the class XmlParserApplicationTest method testApplication.

@Test
public void testApplication() {
    try {
        LocalMode lma = LocalMode.newInstance();
        DAG dag = lma.getDAG();
        XmlDataEmitterOperator input = dag.addOperator("data", new XmlDataEmitterOperator());
        XmlParser parser = dag.addOperator("xmlparser", new XmlParser());
        ResultCollector rc = dag.addOperator("rc", new ResultCollector());
        dag.getMeta(parser).getMeta(parser.out).getAttributes().put(Context.PortContext.TUPLE_CLASS, org.apache.apex.malhar.lib.parser.XmlParserTest.EmployeeBean.class);
        ConsoleOutputOperator xmlObjectOp = dag.addOperator("xmlObjectOp", new ConsoleOutputOperator());
        xmlObjectOp.setDebug(true);
        dag.addStream("input", input.output, parser.in);
        dag.addStream("output", parser.parsedOutput, xmlObjectOp.input);
        dag.addStream("pojo", parser.out, rc.input);
        LocalMode.Controller lc = lma.getController();
        lc.setHeartbeatMonitoringEnabled(false);
        ((StramLocalCluster) lc).setExitCondition(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                return TupleCount == 1;
            }
        });
        // runs for 10 seconds and quits
        lc.run(10000);
        Assert.assertEquals(1, TupleCount);
        Assert.assertEquals("john", obj.getName());
    } catch (ConstraintViolationException e) {
        Assert.fail("constraint violations: " + e.getConstraintViolations());
    }
}
Also used : DAG(com.datatorrent.api.DAG) StramLocalCluster(com.datatorrent.stram.StramLocalCluster) ConstraintViolationException(javax.validation.ConstraintViolationException) ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) LocalMode(com.datatorrent.api.LocalMode) ConstraintViolationException(javax.validation.ConstraintViolationException) Test(org.junit.Test)

Example 10 with ConsoleOutputOperator

use of org.apache.apex.malhar.lib.io.ConsoleOutputOperator in project apex-malhar by apache.

the class RubyOperatorBenchmarkApplication method populateDAG.

@Override
public void populateDAG(DAG dag, Configuration conf) {
    RandomEventGenerator rand = dag.addOperator("rand", new RandomEventGenerator());
    rand.setMaxvalue(3000);
    rand.setTuplesBlast(120);
    RandomMapOutput randMap = dag.addOperator("randMap", new RandomMapOutput());
    randMap.setKey("val");
    RubyOperator ruby = dag.addOperator("ruby", new RubyOperator());
    String setupScript = "def square(val)\n";
    setupScript += "  return val*val\nend\n";
    ruby.addSetupScript(setupScript);
    ruby.setInvoke("square");
    ruby.setPassThru(true);
    ConsoleOutputOperator console = dag.addOperator("console", new ConsoleOutputOperator());
    dag.getMeta(console).getMeta(console.input).getAttributes().put(PortContext.QUEUE_CAPACITY, QUEUE_CAPACITY);
    dag.getMeta(ruby).getMeta(ruby.result).getAttributes().put(PortContext.QUEUE_CAPACITY, QUEUE_CAPACITY);
    dag.addStream("rand_randMap", rand.integer_data, randMap.input).setLocality(Locality.THREAD_LOCAL);
    dag.addStream("randMap_ruby", randMap.map_data, ruby.inBindings).setLocality(locality);
    dag.addStream("ruby_console", ruby.result, console.input).setLocality(locality);
}
Also used : ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) RandomMapOutput(org.apache.apex.benchmark.RandomMapOutput) RubyOperator(org.apache.apex.malhar.contrib.ruby.RubyOperator) RandomEventGenerator(org.apache.apex.malhar.lib.testbench.RandomEventGenerator)

Aggregations

ConsoleOutputOperator (org.apache.apex.malhar.lib.io.ConsoleOutputOperator)36 RandomEventGenerator (org.apache.apex.malhar.lib.testbench.RandomEventGenerator)6 Operator (com.datatorrent.api.Operator)5 Counter (org.apache.apex.malhar.lib.stream.Counter)5 PubSubWebSocketAppDataQuery (org.apache.apex.malhar.lib.io.PubSubWebSocketAppDataQuery)4 PubSubWebSocketAppDataResult (org.apache.apex.malhar.lib.io.PubSubWebSocketAppDataResult)4 WindowOption (org.apache.apex.malhar.lib.window.WindowOption)4 URI (java.net.URI)3 UniqueCounter (org.apache.apex.malhar.lib.algo.UniqueCounter)3 AppDataSnapshotServerMap (org.apache.apex.malhar.lib.appdata.snapshot.AppDataSnapshotServerMap)3 MapToKeyHashValuePairConverter (org.apache.apex.malhar.lib.converter.MapToKeyHashValuePairConverter)3 WindowState (org.apache.apex.malhar.lib.window.WindowState)3 List (java.util.List)2 FunctionOperator (org.apache.apex.malhar.lib.function.FunctionOperator)2 ApacheLogParseMapOutputOperator (org.apache.apex.malhar.lib.logs.ApacheLogParseMapOutputOperator)2 DimensionObject (org.apache.apex.malhar.lib.logs.DimensionObject)2 JsonByteArrayOperator (org.apache.apex.malhar.lib.stream.JsonByteArrayOperator)2 KeyValPair (org.apache.apex.malhar.lib.util.KeyValPair)2 FSWindowDataManager (org.apache.apex.malhar.lib.wal.FSWindowDataManager)2 TriggerOption (org.apache.apex.malhar.lib.window.TriggerOption)2