Java Code Examples for com.datatorrent.api.DAG#getValue()

The following examples show how to use com.datatorrent.api.DAG#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigUtil.java    From examples with Apache License 2.0 5 votes vote down vote up
public static String getGatewayAddress(DAG dag, Configuration conf)
{
  String gatewayAddress = dag.getValue(DAGContext.GATEWAY_CONNECT_ADDRESS);
  if (gatewayAddress == null) {
    gatewayAddress = conf.get(PROP_GATEWAY_ADDRESS);
  }
  return gatewayAddress;
}
 
Example 2
Source File: ConfigUtil.java    From streaming-benchmarks with Apache License 2.0 5 votes vote down vote up
public static String getGatewayAddress(DAG dag, Configuration conf)
{
  String gatewayAddress = dag.getValue(DAGContext.GATEWAY_CONNECT_ADDRESS);
  if (gatewayAddress == null) {
    gatewayAddress = conf.get(PROP_GATEWAY_ADDRESS);
  }
  return gatewayAddress;
}
 
Example 3
Source File: ApplicationWithQuerySupport.java    From examples with Apache License 2.0 4 votes vote down vote up
@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);

  String gatewayAddress = dag.getValue(DAG.GATEWAY_CONNECT_ADDRESS);

  if ( ! StringUtils.isEmpty(gatewayAddress)) {        // add query support
    URI uri = URI.create("ws://" + gatewayAddress + "/pubsub");

    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);

    dag.addOperator("QueryFile", wsQueryFile);
    dag.addOperator("QueryGlobal", 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("QueryFileStream", wsQueryFile.outputPort, snapshotServerFile.query);
    dag.addStream("QueryGlobalStream", wsQueryGlobal.outputPort, snapshotServerGlobal.query);

    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);
  }

  System.out.println("done with populateDAG, isDebugEnabled = " + LOG.isDebugEnabled());
  LOG.info("Returning from populateDAG");
}