Java Code Examples for com.datatorrent.api.Context.OperatorContext#getId()

The following examples show how to use com.datatorrent.api.Context.OperatorContext#getId() . 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: AbstractRabbitMQOutputOperator.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Override
public void setup(OperatorContext context)
{
  // Needed to setup idempotency storage manager in setter
  this.context = context;
  this.operatorContextId = context.getId();

  try {
    connFactory.setHost("localhost");
    connection = connFactory.newConnection();
    channel = connection.createChannel();
    channel.exchangeDeclare(exchange, "fanout");

    this.windowDataManager.setup(context);

  } catch (IOException ex) {
    logger.debug(ex.toString());
    DTThrowable.rethrow(ex);
  }
}
 
Example 2
Source File: MongoDBOutputOperator.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
/**
 * At setup time, init last completed windowId from maxWindowTable
 *
 * @param context
 */
@Override
public void setup(OperatorContext context)
{
  operatorId = context.getId();
  try {
    mongoClient = new MongoClient(hostName);
    db = mongoClient.getDB(dataBase);
    if (userName != null && passWord != null) {
      db.authenticate(userName, passWord.toCharArray());
    }
    initLastWindowInfo();
    for (String table : tableList) {
      tableToDocumentList.put(table, new ArrayList<DBObject>());
      tableToDocument.put(table, new BasicDBObject());
    }
  } catch (UnknownHostException ex) {
    logger.debug(ex.toString());
  }
}
 
Example 3
Source File: AbstractKafkaInputOperator.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Override
public void setup(OperatorContext context)
{
  logger.debug("consumer {} topic {} cacheSize {}", consumer, consumer.getTopic(), consumer.getCacheSize());
  consumer.create();
  // reset the offsets to checkpointed one
  if (consumer instanceof SimpleKafkaConsumer && !offsetStats.isEmpty()) {
    Map<KafkaPartition, Long> currentOffsets = new HashMap<>();
    // Increment the offsets and set it to consumer
    for (Map.Entry<KafkaPartition, Long> e: offsetStats.entrySet()) {
      currentOffsets.put(e.getKey(), e.getValue() + 1);
    }
    ((SimpleKafkaConsumer)consumer).resetOffset(currentOffsets);
  }
  this.context = context;
  operatorId = context.getId();
  if (consumer instanceof HighlevelKafkaConsumer && !(windowDataManager instanceof WindowDataManager.NoopWindowDataManager)) {
    throw new RuntimeException("Idempotency is not supported for High Level Kafka Consumer");
  }
  windowDataManager.setup(context);
}
 
Example 4
Source File: SequenceGenerator.java    From examples with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(OperatorContext context)
{
  super.setup(context);

  id = context.getId();
  sleepTime = context.getValue(OperatorContext.SPIN_MILLIS);
  LOG.debug("Leaving setup, id = {}, sleepTime = {}, divisor = {}",
            id, sleepTime, divisor);
}
 
Example 5
Source File: AbstractFSRollingOutputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(OperatorContext context)
{
  String appId = context.getValue(DAG.APPLICATION_ID);
  operatorId = context.getId();
  outputFilePath = File.separator + appId + File.separator + operatorId;
  super.setup(context);
}
 
Example 6
Source File: WidgetOutputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(OperatorContext context)
{
  if (PubSubHelper.isGatewayConfigured(context)) {
    wsoo.setUri(PubSubHelper.getURI(context));
    wsoo.setup(context);
  } else {
    isWebSocketConnected = false;
    coo.setup(context);
  }
  appId = context.getValue(DAG.APPLICATION_ID);
  operId = context.getId();

}
 
Example 7
Source File: ReduceOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(OperatorContext context)
{
  reporter = new ReporterImpl(ReporterImpl.ReporterType.Reducer, new Counters());
  if (context != null) {
    operatorId = context.getId();
  }
  cacheObject = new HashMap<K1, List<V1>>();
  outputCollector = new OutputCollectorImpl<K2, V2>();
  if (reduceClass != null) {
    try {
      reduceObj = reduceClass.newInstance();
    } catch (Exception e) {
      logger.info("can't instantiate object {}", e.getMessage());
      throw new RuntimeException(e);
    }
    Configuration conf = new Configuration();
    InputStream stream = null;
    if (configFile != null && configFile.length() > 0) {
      logger.info("system /{}", configFile);
      stream = ClassLoader.getSystemResourceAsStream("/" + configFile);
      if (stream == null) {
        logger.info("system {}", configFile);
        stream = ClassLoader.getSystemResourceAsStream(configFile);
      }
    }
    if (stream != null) {
      logger.info("found our stream... so adding it");
      conf.addResource(stream);
    }
    reduceObj.configure(new JobConf(conf));
  }

}
 
Example 8
Source File: AbstractFlumeInputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(OperatorContext context)
{
  long windowDurationMillis = context.getValue(OperatorContext.APPLICATION_WINDOW_COUNT) *
      context.getValue(Context.DAGContext.STREAMING_WINDOW_SIZE_MILLIS);
  maxEventsPerWindow = (long)(windowDurationMillis / 1000.0 * maxEventsPerSecond);
  logger.debug("max-events per-second {} per-window {}", maxEventsPerSecond, maxEventsPerWindow);

  try {
    eventloop = new DefaultEventLoop("EventLoop-" + context.getId());
    eventloop.start();
  } catch (IOException ex) {
    throw new RuntimeException(ex);
  }
}
 
Example 9
Source File: AbstractKinesisInputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * Implement Component Interface.
 *
 * @param context
 */
@Override
public void setup(OperatorContext context)
{
  this.context = context;
  try {
    KinesisUtil.getInstance().createKinesisClient(accessKey, secretKey, endPoint);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
  consumer.create();
  operatorId = context.getId();
  windowDataManager.setup(context);
  shardPosition.clear();
}
 
Example 10
Source File: AbstractRabbitMQInputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(OperatorContext context)
{
  this.operatorContextId = context.getId();
  holdingBuffer = new ArrayBlockingQueue<KeyValPair<Long, byte[]>>(bufferSize);
  this.windowDataManager.setup(context);
}
 
Example 11
Source File: AbstractJdbcNonTransactionableBatchOutputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(OperatorContext context)
{
  super.setup(context);

  mode = context.getValue(OperatorContext.PROCESSING_MODE);

  if (mode == ProcessingMode.AT_MOST_ONCE) {
    //Batch must be cleared to avoid writing same data twice
    tuples.clear();
  }

  try {
    for (T tempTuple: tuples) {
      setStatementParameters(updateCommand, tempTuple);
      updateCommand.addBatch();
    }
  } catch (SQLException e) {
    throw new RuntimeException(e);
  }

  appId = context.getValue(DAG.APPLICATION_ID);
  operatorId = context.getId();
  //Get the last completed window.
  committedWindowId = store.getCommittedWindowId(appId, operatorId);
  LOG.debug("AppId {} OperatorId {}", appId, operatorId);
  LOG.debug("Committed window id {}", committedWindowId);
}
 
Example 12
Source File: AbstractTransactionableStoreOutputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(OperatorContext context)
{
  try {
    store.connect();
    appId = context.getValue(DAG.APPLICATION_ID);
    operatorId = context.getId();
    committedWindowId = store.getCommittedWindowId(appId, operatorId);
  } catch (IOException ex) {
    throw new RuntimeException(ex);
  }
}
 
Example 13
Source File: AbstractKeyValueStoreOutputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(OperatorContext ctxt)
{
  operatorId = ctxt.getId();
  appId = ctxt.getValue(DAGContext.APPLICATION_ID);
  String v = get(getEndWindowKey());
  if (v != null) {
    committedWindowId = Long.valueOf(v);
  }
}
 
Example 14
Source File: AbstractFileInputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(OperatorContext context)
{
  operatorId = context.getId();
  globalProcessedFileCount.setValue(processedFiles.size());
  LOG.debug("Setup processed file count: {}", globalProcessedFileCount);
  this.context = context;

  try {
    filePath = new Path(directory);
    configuration = new Configuration();
    fs = getFSInstance();
  } catch (IOException ex) {
    failureHandling(ex);
  }

  fileCounters.setCounter(FileCounters.GLOBAL_PROCESSED_FILES, globalProcessedFileCount);
  fileCounters.setCounter(FileCounters.LOCAL_PROCESSED_FILES, localProcessedFileCount);
  fileCounters.setCounter(FileCounters.GLOBAL_NUMBER_OF_FAILURES, globalNumberOfFailures);
  fileCounters.setCounter(FileCounters.LOCAL_NUMBER_OF_FAILURES, localNumberOfFailures);
  fileCounters.setCounter(FileCounters.GLOBAL_NUMBER_OF_RETRIES, globalNumberOfRetries);
  fileCounters.setCounter(FileCounters.LOCAL_NUMBER_OF_RETRIES, localNumberOfRetries);
  fileCounters.setCounter(FileCounters.PENDING_FILES, pendingFileCount);

  windowDataManager.setup(context);
  if (context.getValue(OperatorContext.ACTIVATION_WINDOW_ID) < windowDataManager.getLargestCompletedWindow()) {
    //reset current file and offset in case of replay
    currentFile = null;
    offset = 0;
  }
}
 
Example 15
Source File: AbstractSingleFileOutputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * Initializing current partition id, partitionedFileName etc. {@inheritDoc}
 */
@Override
public void setup(OperatorContext context)
{
  super.setup(context);
  physicalPartitionId = context.getId();
  if (StringUtils.isEmpty(partitionedFileNameformat)) {
    partitionedFileName = outputFileName;
  } else {
    partitionedFileName = String.format(partitionedFileNameformat, outputFileName, physicalPartitionId);
  }
}
 
Example 16
Source File: DeduperPartitioningTest.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
public void setup(OperatorContext context)
{
  super.setup(context);
  operatorId = context.getId();
}
 
Example 17
Source File: HDFSOutputOperator.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
public void setup(OperatorContext context)
{
  super.setup(context);
  id = context.getId();
}
 
Example 18
Source File: PartitioningTest.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
@Override
public void setup(OperatorContext context)
{
  this.operatorId = context.getId();
}