Search in sources :

Example 1 with IBolt

use of org.apache.storm.task.IBolt in project storm by apache.

the class BoltExecutor method init.

public void init(ArrayList<Task> idToTask, int idToTaskBase) throws InterruptedException {
    executorTransfer.initLocalRecvQueues();
    workerReady.await();
    while (!stormActive.get()) {
        // Topology may be deployed in deactivated mode, wait for activation
        Utils.sleepNoSimulation(100);
    }
    LOG.info("Preparing bolt {}:{}", componentId, getTaskIds());
    for (Task taskData : idToTask) {
        if (taskData == null) {
            // This happens if the min id is too small
            continue;
        }
        IBolt boltObject = (IBolt) taskData.getTaskObject();
        TopologyContext userContext = taskData.getUserContext();
        if (boltObject instanceof ICredentialsListener) {
            ((ICredentialsListener) boltObject).setCredentials(credentials);
        }
        if (Constants.SYSTEM_COMPONENT_ID.equals(componentId)) {
            BuiltinMetricsUtil.registerIconnectionServerMetric(workerData.getReceiver(), topoConf, userContext);
            // add any autocredential expiry metrics from the worker
            if (workerData.getAutoCredentials() != null) {
                for (IAutoCredentials autoCredential : workerData.getAutoCredentials()) {
                    if (autoCredential instanceof IMetricsRegistrant) {
                        IMetricsRegistrant registrant = (IMetricsRegistrant) autoCredential;
                        registrant.registerMetrics(userContext, topoConf);
                    }
                }
            }
        }
        this.outputCollector = new BoltOutputCollectorImpl(this, taskData, rand, hasEventLoggers, ackingEnabled, isDebug);
        boltObject.prepare(topoConf, userContext, new OutputCollector(outputCollector));
    }
    openOrPrepareWasCalled.set(true);
    LOG.info("Prepared bolt {}:{}", componentId, taskIds);
    setupTicks(false);
    setupMetrics();
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector) Task(org.apache.storm.daemon.Task) ICredentialsListener(org.apache.storm.ICredentialsListener) IAutoCredentials(org.apache.storm.security.auth.IAutoCredentials) IMetricsRegistrant(org.apache.storm.metric.api.IMetricsRegistrant) IBolt(org.apache.storm.task.IBolt) TopologyContext(org.apache.storm.task.TopologyContext)

Example 2 with IBolt

use of org.apache.storm.task.IBolt in project storm by apache.

the class BoltExecutor method init.

public void init(Map<Integer, Task> idToTask) {
    while (!stormActive.get()) {
        Utils.sleep(100);
    }
    LOG.info("Preparing bolt {}:{}", componentId, idToTask.keySet());
    for (Map.Entry<Integer, Task> entry : idToTask.entrySet()) {
        Task taskData = entry.getValue();
        IBolt boltObject = (IBolt) taskData.getTaskObject();
        TopologyContext userContext = taskData.getUserContext();
        taskData.getBuiltInMetrics().registerAll(stormConf, userContext);
        if (boltObject instanceof ICredentialsListener) {
            ((ICredentialsListener) boltObject).setCredentials(credentials);
        }
        if (Constants.SYSTEM_COMPONENT_ID.equals(componentId)) {
            Map<String, DisruptorQueue> map = ImmutableMap.of("sendqueue", transferQueue, "receive", receiveQueue, "transfer", workerData.getTransferQueue());
            BuiltinMetricsUtil.registerQueueMetrics(map, stormConf, userContext);
            Map cachedNodePortToSocket = (Map) workerData.getCachedNodeToPortSocket().get();
            BuiltinMetricsUtil.registerIconnectionClientMetrics(cachedNodePortToSocket, stormConf, userContext);
            BuiltinMetricsUtil.registerIconnectionServerMetric(workerData.getReceiver(), stormConf, userContext);
        } else {
            Map<String, DisruptorQueue> map = ImmutableMap.of("sendqueue", transferQueue, "receive", receiveQueue);
            BuiltinMetricsUtil.registerQueueMetrics(map, stormConf, userContext);
        }
        IOutputCollector outputCollector = new BoltOutputCollectorImpl(this, taskData, entry.getKey(), rand, hasEventLoggers, isDebug);
        boltObject.prepare(stormConf, userContext, new OutputCollector(outputCollector));
    }
    openOrPrepareWasCalled.set(true);
    LOG.info("Prepared bolt {}:{}", componentId, idToTask.keySet());
    setupMetrics();
}
Also used : IOutputCollector(org.apache.storm.task.IOutputCollector) OutputCollector(org.apache.storm.task.OutputCollector) Task(org.apache.storm.daemon.Task) ICredentialsListener(org.apache.storm.ICredentialsListener) IOutputCollector(org.apache.storm.task.IOutputCollector) DisruptorQueue(org.apache.storm.utils.DisruptorQueue) IBolt(org.apache.storm.task.IBolt) TopologyContext(org.apache.storm.task.TopologyContext) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 3 with IBolt

use of org.apache.storm.task.IBolt in project storm by apache.

the class ExecutorShutdown method shutdown.

@Override
public void shutdown() {
    try {
        LOG.info("Shutting down executor " + executor.getComponentId() + ":" + executor.getExecutorId());
        executor.getReceiveQueue().close();
        for (Utils.SmartThread t : threads) {
            t.interrupt();
        }
        for (Utils.SmartThread t : threads) {
            LOG.debug("Executor " + executor.getComponentId() + ":" + executor.getExecutorId() + " joining thread " + t.getName());
            // Don't wait forever.
            // This is to avoid the deadlock between the executor thread (t) and the shutdown hook (which invokes Worker::shutdown)
            // when it is the executor thread (t) who invokes the shutdown hook. See STORM-3658.
            long waitMs = 100;
            t.join(waitMs);
            if (t.isAlive()) {
                LOG.warn("Thread {} is still alive ({} ms after interruption). Stop waiting for it.", t.getName(), waitMs);
            }
        }
        executor.getStats().cleanupStats();
        for (Task task : taskDatas) {
            if (task == null) {
                continue;
            }
            TopologyContext userContext = task.getUserContext();
            for (ITaskHook hook : userContext.getHooks()) {
                hook.cleanup();
            }
        }
        executor.getStormClusterState().disconnect();
        if (executor.getOpenOrPrepareWasCalled().get()) {
            for (Task task : taskDatas) {
                if (task == null) {
                    continue;
                }
                Object object = task.getTaskObject();
                if (object instanceof ISpout) {
                    ((ISpout) object).close();
                } else if (object instanceof IBolt) {
                    ((IBolt) object).cleanup();
                } else {
                    LOG.error("unknown component object");
                }
            }
        }
        LOG.info("Shut down executor " + executor.getComponentId() + ":" + executor.getExecutorId());
    } catch (Exception e) {
        throw Utils.wrapInRuntime(e);
    }
}
Also used : Task(org.apache.storm.daemon.Task) Utils(org.apache.storm.utils.Utils) ITaskHook(org.apache.storm.hooks.ITaskHook) IBolt(org.apache.storm.task.IBolt) TopologyContext(org.apache.storm.task.TopologyContext) ISpout(org.apache.storm.spout.ISpout)

Aggregations

Task (org.apache.storm.daemon.Task)3 IBolt (org.apache.storm.task.IBolt)3 TopologyContext (org.apache.storm.task.TopologyContext)3 ICredentialsListener (org.apache.storm.ICredentialsListener)2 OutputCollector (org.apache.storm.task.OutputCollector)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 ITaskHook (org.apache.storm.hooks.ITaskHook)1 IMetricsRegistrant (org.apache.storm.metric.api.IMetricsRegistrant)1 IAutoCredentials (org.apache.storm.security.auth.IAutoCredentials)1 ISpout (org.apache.storm.spout.ISpout)1 IOutputCollector (org.apache.storm.task.IOutputCollector)1 DisruptorQueue (org.apache.storm.utils.DisruptorQueue)1 Utils (org.apache.storm.utils.Utils)1