Java Code Examples for backtype.storm.task.TopologyContext#getThisComponentId()

The following examples show how to use backtype.storm.task.TopologyContext#getThisComponentId() . 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: StreamFrameFetcher.java    From StormCV with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes" })
@Override
public void prepare(Map conf, TopologyContext context) throws Exception {
	this.id = context.getThisComponentId();
	int nrTasks = context.getComponentTasks(id).size();
	int taskIndex = context.getThisTaskIndex();
	
	if(conf.containsKey(StormCVConfig.STORMCV_FRAME_ENCODING)){
		imageType = (String)conf.get(StormCVConfig.STORMCV_FRAME_ENCODING);
	}
	
	// change the list based on the number of tasks working on it
	if(this.locations != null && this.locations.size() > 0){
		int batchSize = (int) Math.floor(locations.size() / nrTasks);
		int start = batchSize * taskIndex;
		locations = locations.subList(start, Math.min(start + batchSize, locations.size()));
	}
}
 
Example 2
Source File: CVParticleBolt.java    From StormCV with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void prepare(Map conf, TopologyContext context, OutputCollector collector) {
	this.collector = collector;
	this.boltName = context.getThisComponentId();
	
	try{
		PersistentArrayMap map = (PersistentArrayMap)conf.get(Config.TOPOLOGY_KRYO_REGISTER);
		for(Object className : map.keySet()){
			serializers.put((String)className, (CVParticleSerializer<? extends CVParticle>)Class.forName((String)map.get(className)).newInstance());
		}
	}catch(Exception e){
		logger.error("Unable to prepare CVParticleBolt due to ",e);
	}
	
	this.prepare(conf, context);
}
 
Example 3
Source File: CoordinatedBolt.java    From jstorm with Apache License 2.0 6 votes vote down vote up
public void prepare(Map conf, TopologyContext context, OutputCollector collector) {

        taskId = String.valueOf(context.getThisTaskId());
        taskName = context.getThisComponentId() + "_" + context.getThisTaskId();

        this.basicCollector = new BasicOutputCollector(collector);
        this.collector = collector;

        if (delegate instanceof ICommitter) {
            isCommiter = true;
            commited = new TimeCacheMap<>(context.maxTopologyMessageTimeout());
            mkCommitDir(conf);
        }

        delegate.prepare(conf, context);

    }
 
Example 4
Source File: BatchSpoutTrigger.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    batchQueue = new LinkedBlockingQueue<>();
    this.collector = collector;
    this.conf = conf;
    taskName = context.getThisComponentId() + "_" + context.getThisTaskId();

    intervalCheck = new IntervalCheck();
    try {
        zkClient = BatchCommon.getZkClient(conf);
        initMsgId();
    } catch (Exception e) {
        LOG.error("", e);
        throw new RuntimeException("Failed to init");
    }
    LOG.info("Successfully open " + taskName);
}
 
Example 5
Source File: SimpleFileNameFormat.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void prepare(Map conf, TopologyContext topologyContext) {
    this.componentId = topologyContext.getThisComponentId();
    this.taskId = topologyContext.getThisTaskId();
    try {
        this.host = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        throw new RuntimeException(e);
    }
}
 
Example 6
Source File: AckTransactionSpout.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    SpoutOutputCollectorCb ackOutput = new AckSpoutOutputCollector(collector.getDelegate());
    spoutExecutor.open(conf, context, new SpoutOutputCollector(ackOutput));
    tracker = new AckPendingBatchTracker<>();
    taskStats = new TaskBaseMetric(context.getTopologyId(), context.getThisComponentId(), context.getThisTaskId());
    random = new Random(Utils.secureRandomLong());
}
 
Example 7
Source File: AckTransactionBolt.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    this.batchXorTracker = new AckPendingBatchTracker<>();
    this.ackOutputCollector = new AckOutputCollector(collector.getDelegate(), batchXorTracker);
    this.bolt.prepare(stormConf, context, new OutputCollector(ackOutputCollector));

    this.componentId = context.getThisComponentId();
    this.taskId = context.getThisTaskId();
    this.taskStats = new TaskBaseMetric(context.getTopologyId(), componentId, taskId);
    this.batchTimeout = ConfigExtension.getTransactionBatchSnapshotTimeout(stormConf) * 1000;
    this.random = new Random(Utils.secureRandomLong());

    LOG.info("batchTimeout: {}", batchTimeout);
}
 
Example 8
Source File: AbstractDataEnrichBolt.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    this.collector = collector;
    // start external data retrieval
    try {
        ExternalDataJoiner joiner = new ExternalDataJoiner(
                lcm, config, context.getThisComponentId() + "." + context.getThisTaskIndex());
        joiner.start();
    } catch(Exception ex){
        LOG.error("Fail bringing up quartz scheduler.", ex);
        throw new IllegalStateException(ex);
    }
}
 
Example 9
Source File: CheckpointSpout.java    From jstorm with Apache License 2.0 5 votes vote down vote up
/**
 * Loads the last saved checkpoint state the from persistent storage.
 */
private KeyValueState<String, CheckPointState> loadCheckpointState(Map conf, TopologyContext ctx) {
    String namespace = ctx.getThisComponentId() + "-" + ctx.getThisTaskId();
    KeyValueState<String, CheckPointState> state =
            (KeyValueState<String, CheckPointState>) StateFactory.getState(namespace, conf, ctx);
    if (state.get(TX_STATE_KEY) == null) {
        CheckPointState txState = new CheckPointState(-1, CheckPointState.State.COMMITTED);
        state.put(TX_STATE_KEY, txState);
        state.commit();
        LOG.debug("Initialized checkpoint spout state with txState {}", txState);
    } else {
        LOG.debug("Got checkpoint spout state {}", state.get(TX_STATE_KEY));
    }
    return state;
}
 
Example 10
Source File: SequenceSpout.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    this.collector = collector;
    
    if (conf.get("spout.max.sending.num") == null) {
        isLimited = false;
    } else {
        isLimited = true;
        SPOUT_MAX_SEND_NUM = JStormUtils.parseLong(conf.get("spout.max.sending.num"));
    }
    
    Boolean btrue = JStormUtils.parseBoolean(conf.get("spout.send.contrl.message"));
    if (btrue != null && btrue) {
        isSendCtrlMsg = true;
    } else {
        isSendCtrlMsg = false;
    }
    
    isFinished = false;
    
    tpsCounter = new TpsCounter(context.getThisComponentId() + ":" + context.getThisTaskId());
    MetricClient metricClient = new MetricClient(context);
    this.tpCounter = metricClient.registerTopologyCounter("TpCounter");

    MAX_PENDING_COUNTER = getMaxPending(conf);
    
    bufferLen = JStormUtils.parseInt(conf.get("byte.buffer.len"), 0);
    
    random = new Random();
    random.setSeed(System.currentTimeMillis());

    idGenerate = new Random(Utils.secureRandomLong());

    JStormUtils.sleepMs(20 * 1000);
    
    LOG.info("Finish open, buffer Len:" + bufferLen);
}
 
Example 11
Source File: MergeRecord.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    this.collector = collector;
    
    tpsCounter = new TpsCounter(context.getThisComponentId() + ":" + context.getThisTaskId());
    
    LOG.info("Finished preparation");
}
 
Example 12
Source File: TotalCount.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    this.collector = collector;
    this.context = context;
    
    tpsCounter = new TpsCounter(context.getThisComponentId() + ":" + context.getThisTaskId());

    checkTupleId = JStormUtils.parseBoolean(stormConf.get("bolt.check.tupleId"), false);
    slowDonw = JStormUtils.parseBoolean(stormConf.get("bolt.slow.down"), false);
    
    metricClient = new MetricClient(context);
    
    Gauge<Double> gauge = new Gauge<Double>() {
        private Random random = new Random();
        
        @Override
        public Double getValue() {
            return random.nextDouble();
        }
        
    };
    myGauge = metricClient.registerGauge("myGauge", gauge);
    myCounter = metricClient.registerCounter("myCounter");
    tpCounter = metricClient.registerTopologyCounter("TpCounter");
    myMeter = metricClient.registerMeter("myMeter");
    myJStormHistogram = metricClient.registerHistogram("myHistogram");
    
    LOG.info("Finished preparation " + stormConf);
}
 
Example 13
Source File: PairCount.java    From jstorm with Apache License 2.0 4 votes vote down vote up
public void prepare(Map conf, TopologyContext context) {
    tpsCounter = new TpsCounter(context.getThisComponentId() + ":" + context.getThisTaskId());
    LOG.info("Successfully do parepare " + context.getThisComponentId());
}
 
Example 14
Source File: DefaultFileNameFormat.java    From jstorm with Apache License 2.0 4 votes vote down vote up
public void prepare(Map conf, TopologyContext topologyContext) {
    this.componentId = topologyContext.getThisComponentId();
    this.taskId = topologyContext.getThisTaskId();
}
 
Example 15
Source File: MetricClient.java    From jstorm with Apache License 2.0 4 votes vote down vote up
public MetricClient(TopologyContext context) {
    taskId = context.getThisTaskId();
    this.topologyId = context.getTopologyId();
    this.componentId = context.getThisComponentId();
}
 
Example 16
Source File: DefaultFileNameFormat.java    From storm-hdfs with Apache License 2.0 4 votes vote down vote up
@Override
public void prepare(Map conf, TopologyContext topologyContext) {
    this.componentId = topologyContext.getThisComponentId();
    this.taskId = topologyContext.getThisTaskId();
}
 
Example 17
Source File: TaskReceiver.java    From jstorm with Apache License 2.0 4 votes vote down vote up
public TaskReceiver(Task task, int taskId, Map stormConf, TopologyContext topologyContext,
                    Map<Integer, DisruptorQueue> innerTaskTransfer,
                    TaskStatus taskStatus, String taskName) {
    this.stormConf = stormConf;
    this.task = task;
    this.bolt = (task.getTaskObj() instanceof IBolt ? (IBolt) task.getTaskObj() : null);
    this.taskId = taskId;
    this.idStr = taskName;

    this.topologyContext = topologyContext;
    this.innerTaskTransfer = innerTaskTransfer;

    this.taskStatus = taskStatus;

    int queueSize = JStormUtils.parseInt(stormConf.get(Config.TOPOLOGY_EXECUTOR_RECEIVE_BUFFER_SIZE), 256);

    long timeout = JStormUtils.parseLong(stormConf.get(Config.TOPOLOGY_DISRUPTOR_WAIT_TIMEOUT), 10);
    WaitStrategy waitStrategy = new TimeoutBlockingWaitStrategy(timeout, TimeUnit.MILLISECONDS);
    boolean isDisruptorBatchMode = ConfigExtension.isDisruptorQueueBatchMode(stormConf);
    int disruptorBatch = ConfigExtension.getDisruptorBufferSize(stormConf);
    long flushMs = ConfigExtension.getDisruptorBufferFlushMs(stormConf);
    this.deserializeQueue = DisruptorQueue.mkInstance("TaskDeserialize", ProducerType.MULTI, queueSize, waitStrategy,
            isDisruptorBatchMode, disruptorBatch, flushMs);
    dserializeThreadNum = ConfigExtension.getTaskDeserializeThreadNum(stormConf);
    deserializeThreads = new ArrayList<>();
    setDeserializeThread();
    //this.deserializer = new KryoTupleDeserializer(stormConf, topologyContext);

    String topologyId = topologyContext.getTopologyId();
    String component = topologyContext.getThisComponentId();

    AsmHistogram deserializeTimerHistogram = new AsmHistogram();
    deserializeTimerHistogram.setAggregate(false);
    deserializeTimer = (AsmHistogram) JStormMetrics.registerTaskMetric(MetricUtils.taskMetricName(
            topologyId, component, taskId, MetricDef.DESERIALIZE_TIME, MetricType.HISTOGRAM), deserializeTimerHistogram);

    QueueGauge deserializeQueueGauge = new QueueGauge(deserializeQueue, idStr, MetricDef.DESERIALIZE_QUEUE);
    JStormMetrics.registerTaskMetric(MetricUtils.taskMetricName(
                    topologyId, component, taskId, MetricDef.DESERIALIZE_QUEUE, MetricType.GAUGE),
            new AsmGauge(deserializeQueueGauge));
    JStormHealthCheck.registerTaskHealthCheck(taskId, MetricDef.DESERIALIZE_QUEUE, deserializeQueueGauge);

    this.isBackpressureEnable = ConfigExtension.isBackpressureEnable(stormConf);
    this.highMark = (float) ConfigExtension.getBackpressureWaterMarkHigh(stormConf);
    this.lowMark = (float) ConfigExtension.getBackpressureWaterMarkLow(stormConf);
    this.backpressureStatus = false;

    LOG.info("Successfully started TaskReceiver thread for {}, thread num: {}", idStr, dserializeThreadNum);
}
 
Example 18
Source File: StatefulBoltExecutor.java    From jstorm with Apache License 2.0 4 votes vote down vote up
@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    // get the last successfully committed state from state store
    String namespace = context.getThisComponentId() + "-" + context.getThisTaskId();
    prepare(stormConf, context, collector, StateFactory.getState(namespace, stormConf, context));
}
 
Example 19
Source File: StatefulWindowedBoltExecutor.java    From jstorm with Apache License 2.0 4 votes vote down vote up
private KeyValueState<TaskStream, WindowState> getWindowState(Map stormConf, TopologyContext context) {
    String namespace = context.getThisComponentId() + "-" + context.getThisTaskId() + "-window";
    return (KeyValueState<TaskStream, WindowState>) StateFactory.getState(namespace, stormConf, context);
}
 
Example 20
Source File: SplitRecord.java    From jstorm with Apache License 2.0 2 votes vote down vote up
public void prepare(Map conf, TopologyContext context) {
    
    tpsCounter = new TpsCounter(context.getThisComponentId() + ":" + context.getThisTaskId());
    
    LOG.info("Successfully do prepare");
}