Search in sources :

Example 1 with AppDataSnapshotServerMap

use of org.apache.apex.malhar.lib.appdata.snapshot.AppDataSnapshotServerMap in project apex-malhar by apache.

the class ApplicationWithQuerySupport method populateDAG.

/**
 * Populates the DAG with operators and connecting streams
 *
 * @param dag The directed acyclic graph of operators to populate
 * @param conf The configuration
 */
@Override
public void populateDAG(DAG dag, Configuration conf) {
    // create operators
    LineReader lineReader = dag.addOperator("lineReader", new LineReader());
    WordReader wordReader = dag.addOperator("wordReader", new WordReader());
    WindowWordCount windowWordCount = dag.addOperator("windowWordCount", new WindowWordCount());
    FileWordCount fileWordCount = dag.addOperator("fileWordCount", new FileWordCount());
    WordCountWriter wcWriter = dag.addOperator("wcWriter", new WordCountWriter());
    ConsoleOutputOperator console = dag.addOperator("console", new ConsoleOutputOperator());
    console.setStringFormat("wordCount: %s");
    // create streams
    dag.addStream("lines", lineReader.output, wordReader.input);
    dag.addStream("control", lineReader.control, fileWordCount.control);
    dag.addStream("words", wordReader.output, windowWordCount.input);
    dag.addStream("windowWordCounts", windowWordCount.output, fileWordCount.input);
    dag.addStream("fileWordCounts", fileWordCount.fileOutput, wcWriter.input);
    if (PubSubHelper.isGatewayConfigured(dag)) {
        // add query support
        URI uri = PubSubHelper.getURI(dag);
        AppDataSnapshotServerMap snapshotServerFile = dag.addOperator("snapshotServerFile", new AppDataSnapshotServerMap());
        AppDataSnapshotServerMap snapshotServerGlobal = dag.addOperator("snapshotServerGlobal", new AppDataSnapshotServerMap());
        String snapshotServerJSON = SchemaUtils.jarResourceFileToString(SNAPSHOT_SCHEMA);
        snapshotServerFile.setSnapshotSchemaJSON(snapshotServerJSON);
        snapshotServerGlobal.setSnapshotSchemaJSON(snapshotServerJSON);
        PubSubWebSocketAppDataQuery wsQueryFile = new PubSubWebSocketAppDataQuery();
        PubSubWebSocketAppDataQuery wsQueryGlobal = new PubSubWebSocketAppDataQuery();
        wsQueryFile.setUri(uri);
        wsQueryGlobal.setUri(uri);
        snapshotServerFile.setEmbeddableQueryInfoProvider(wsQueryFile);
        snapshotServerGlobal.setEmbeddableQueryInfoProvider(wsQueryGlobal);
        PubSubWebSocketAppDataResult wsResultFile = dag.addOperator("wsResultFile", new PubSubWebSocketAppDataResult());
        PubSubWebSocketAppDataResult wsResultGlobal = dag.addOperator("wsResultGlobal", new PubSubWebSocketAppDataResult());
        wsResultFile.setUri(uri);
        wsResultGlobal.setUri(uri);
        Operator.InputPort<String> queryResultFilePort = wsResultFile.input;
        Operator.InputPort<String> queryResultGlobalPort = wsResultGlobal.input;
        dag.addStream("WordCountsFile", fileWordCount.outputPerFile, snapshotServerFile.input, console.input);
        dag.addStream("WordCountsGlobal", fileWordCount.outputGlobal, snapshotServerGlobal.input);
        dag.addStream("ResultFile", snapshotServerFile.queryResult, queryResultFilePort);
        dag.addStream("ResultGlobal", snapshotServerGlobal.queryResult, queryResultGlobalPort);
    } else {
        // throw new RuntimeException("Error: No GATEWAY_CONNECT_ADDRESS");
        dag.addStream("WordCounts", fileWordCount.outputPerFile, console.input);
    }
    LOG.info("done with populateDAG, isDebugEnabled = " + LOG.isDebugEnabled());
    LOG.info("Returning from populateDAG");
}
Also used : Operator(com.datatorrent.api.Operator) ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) URI(java.net.URI) ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) PubSubWebSocketAppDataResult(org.apache.apex.malhar.lib.io.PubSubWebSocketAppDataResult) AppDataSnapshotServerMap(org.apache.apex.malhar.lib.appdata.snapshot.AppDataSnapshotServerMap) PubSubWebSocketAppDataQuery(org.apache.apex.malhar.lib.io.PubSubWebSocketAppDataQuery)

Example 2 with AppDataSnapshotServerMap

use of org.apache.apex.malhar.lib.appdata.snapshot.AppDataSnapshotServerMap in project apex-malhar by apache.

the class TwitterTopCounterApplication method consoleOutput.

public static void consoleOutput(DAG dag, String operatorName, OutputPort<List<Map<String, Object>>> topCount, String schemaFile, String alias) {
    if (PubSubHelper.isGatewayConfigured(dag)) {
        URI uri = PubSubHelper.getURI(dag);
        AppDataSnapshotServerMap snapshotServer = dag.addOperator("SnapshotServer", new AppDataSnapshotServerMap());
        Map<String, String> conversionMap = Maps.newHashMap();
        conversionMap.put(alias, WindowedTopCounter.FIELD_TYPE);
        String snapshotServerJSON = SchemaUtils.jarResourceFileToString(schemaFile);
        snapshotServer.setSnapshotSchemaJSON(snapshotServerJSON);
        snapshotServer.setTableFieldToMapField(conversionMap);
        PubSubWebSocketAppDataQuery wsQuery = new PubSubWebSocketAppDataQuery();
        wsQuery.setUri(uri);
        snapshotServer.setEmbeddableQueryInfoProvider(wsQuery);
        PubSubWebSocketAppDataResult wsResult = dag.addOperator("QueryResult", new PubSubWebSocketAppDataResult());
        wsResult.setUri(uri);
        Operator.InputPort<String> queryResultPort = wsResult.input;
        dag.addStream("MapProvider", topCount, snapshotServer.input);
        dag.addStream("Result", snapshotServer.queryResult, queryResultPort);
    } else {
        ConsoleOutputOperator operator = dag.addOperator(operatorName, new ConsoleOutputOperator());
        operator.setStringFormat(operatorName + ": %s");
        dag.addStream("MapProvider", topCount, operator.input);
    }
}
Also used : Operator(com.datatorrent.api.Operator) ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) PubSubWebSocketAppDataResult(org.apache.apex.malhar.lib.io.PubSubWebSocketAppDataResult) AppDataSnapshotServerMap(org.apache.apex.malhar.lib.appdata.snapshot.AppDataSnapshotServerMap) PubSubWebSocketAppDataQuery(org.apache.apex.malhar.lib.io.PubSubWebSocketAppDataQuery) URI(java.net.URI)

Example 3 with AppDataSnapshotServerMap

use of org.apache.apex.malhar.lib.appdata.snapshot.AppDataSnapshotServerMap in project apex-malhar by apache.

the class ApplicationAppData method populateDAG.

@Override
public void populateDAG(DAG dag, Configuration conf) {
    RandomEventGenerator rand = dag.addOperator("rand", new RandomEventGenerator());
    PiCalculateOperator calc = dag.addOperator("picalc", new PiCalculateOperator());
    dag.addStream("rand_calc", rand.integer_data, calc.input).setLocality(locality);
    AppDataSnapshotServerMap snapshotServer = dag.addOperator("SnapshotServer", new AppDataSnapshotServerMap());
    String snapshotServerJSON = SchemaUtils.jarResourceFileToString(SNAPSHOT_SCHEMA);
    snapshotServer.setSnapshotSchemaJSON(snapshotServerJSON);
    PubSubWebSocketAppDataQuery wsQuery = new PubSubWebSocketAppDataQuery();
    wsQuery.enableEmbeddedMode();
    snapshotServer.setEmbeddableQueryInfoProvider(wsQuery);
    PubSubWebSocketAppDataResult wsResult = dag.addOperator("QueryResult", new PubSubWebSocketAppDataResult());
    Operator.InputPort<String> queryResultPort = wsResult.input;
    NamedValueList<Object> adaptor = dag.addOperator("adaptor", new NamedValueList<Object>());
    ConsoleOutputOperator console = dag.addOperator("console", new ConsoleOutputOperator());
    dag.addStream("PiValues", calc.output, adaptor.inPort, console.input).setLocality(locality);
    ;
    dag.addStream("NamedPiValues", adaptor.outPort, snapshotServer.input);
    dag.addStream("Result", snapshotServer.queryResult, queryResultPort);
}
Also used : Operator(com.datatorrent.api.Operator) ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) PubSubWebSocketAppDataResult(org.apache.apex.malhar.lib.io.PubSubWebSocketAppDataResult) AppDataSnapshotServerMap(org.apache.apex.malhar.lib.appdata.snapshot.AppDataSnapshotServerMap) PubSubWebSocketAppDataQuery(org.apache.apex.malhar.lib.io.PubSubWebSocketAppDataQuery) RandomEventGenerator(org.apache.apex.malhar.lib.testbench.RandomEventGenerator)

Aggregations

Operator (com.datatorrent.api.Operator)3 AppDataSnapshotServerMap (org.apache.apex.malhar.lib.appdata.snapshot.AppDataSnapshotServerMap)3 ConsoleOutputOperator (org.apache.apex.malhar.lib.io.ConsoleOutputOperator)3 PubSubWebSocketAppDataQuery (org.apache.apex.malhar.lib.io.PubSubWebSocketAppDataQuery)3 PubSubWebSocketAppDataResult (org.apache.apex.malhar.lib.io.PubSubWebSocketAppDataResult)3 URI (java.net.URI)2 RandomEventGenerator (org.apache.apex.malhar.lib.testbench.RandomEventGenerator)1