Search in sources :

Example 1 with UpdateConfigEvent

use of com.alibaba.jstorm.task.master.ctrlevent.UpdateConfigEvent in project jstorm by alibaba.

the class TopologyMaster method update.

@Override
public void update(Map conf) {
    LOG.info("Topology master received new conf:" + conf);
    TMHandler handler = handlers.get(UPDATE_CONFIG_NAME);
    if (handler == null) {
        LOG.error("No handler to handle update config event");
        return;
    }
    TMEvent event = new TMEvent(handler, new UpdateConfigEvent(conf));
    threadPools.submit(event);
}
Also used : UpdateConfigEvent(com.alibaba.jstorm.task.master.ctrlevent.UpdateConfigEvent)

Example 2 with UpdateConfigEvent

use of com.alibaba.jstorm.task.master.ctrlevent.UpdateConfigEvent in project jstorm by alibaba.

the class TaskHeartbeatUpdater method process.

@Override
public void process(Object event) throws Exception {
    synchronized (_lock) {
        if (event instanceof UpdateConfigEvent) {
            update(((UpdateConfigEvent) event).getConf());
            return;
        }
        Tuple input = (Tuple) event;
        int sourceTask = input.getSourceTask();
        int uptime = (Integer) input.getValue(0);
        TaskStatus executorStatus = new TaskStatus();
        if (input.getValues().size() < 2) {
            // for compatibility
            executorStatus.setStatus(TaskStatus.RUN);
        } else {
            executorStatus.setStatus((byte) input.getValue(1));
        }
        boolean isSendSpoutTaskFinishStream = false;
        if (spoutsExecutorStatusMap.containsKey(sourceTask)) {
            spoutsExecutorStatusMap.put(sourceTask, executorStatus);
        } else if (boltsExecutorStatusMap.containsKey(sourceTask)) {
            boltsExecutorStatusMap.put(sourceTask, executorStatus);
        } else if (sourceTask != taskId) {
            LOG.warn("received invalid task heartbeat {}", input);
        }
        if (executorStatus.getStatus() == TaskStatus.INIT && spoutsExecutorStatusMap.get(sourceTask) != null) {
            boolean existInitStatusBolt = false;
            for (TaskStatus status : boltsExecutorStatusMap.values()) {
                if (status.getStatus() == TaskStatus.INIT || status.getStatus() == TaskStatus.SHUTDOWN) {
                    existInitStatusBolt = true;
                    break;
                }
            }
            if (!existInitStatusBolt)
                isSendSpoutTaskFinishStream = true;
        }
        if (client == null) {
            client = new NimbusClientWrapper();
            client.init(stormConf);
        }
        // Update the heartbeat for source task, but don't update it if task is initial status
        if (executorStatus.getStatus() != TaskStatus.INIT && uptime > 0) {
            TaskHeartbeat taskHb = taskHbMap.get().get(sourceTask);
            if (taskHb == null) {
                taskHb = new TaskHeartbeat(TimeUtils.current_time_secs(), uptime);
                TaskHeartbeat tmpTaskHb = taskHbMap.get().putIfAbsent(sourceTask, taskHb);
                if (tmpTaskHb != null) {
                    taskHb = tmpTaskHb;
                }
            }
            taskHb.set_time(TimeUtils.current_time_secs());
            taskHb.set_uptime(uptime);
        } else if (isSendSpoutTaskFinishStream) {
            TopoMasterCtrlEvent finishInitEvent = new TopoMasterCtrlEvent(TopoMasterCtrlEvent.EventType.topologyFinishInit);
            ((BoltCollector) (collector.getDelegate())).emitDirectCtrl(sourceTask, Common.TOPOLOGY_MASTER_CONTROL_STREAM_ID, null, new Values(finishInitEvent));
            LOG.info("all bolts' task finish init operation, so tm will notify the spout task-{}", sourceTask);
        }
        // Send heartbeat info of all tasks to nimbus
        if (sourceTask == taskId) {
            uploadHB();
        }
    }
}
Also used : TopoMasterCtrlEvent(com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent) NimbusClientWrapper(backtype.storm.utils.NimbusClientWrapper) Values(backtype.storm.tuple.Values) UpdateConfigEvent(com.alibaba.jstorm.task.master.ctrlevent.UpdateConfigEvent) TaskStatus(com.alibaba.jstorm.task.TaskStatus) Tuple(backtype.storm.tuple.Tuple)

Aggregations

UpdateConfigEvent (com.alibaba.jstorm.task.master.ctrlevent.UpdateConfigEvent)2 Tuple (backtype.storm.tuple.Tuple)1 Values (backtype.storm.tuple.Values)1 NimbusClientWrapper (backtype.storm.utils.NimbusClientWrapper)1 TaskStatus (com.alibaba.jstorm.task.TaskStatus)1 TopoMasterCtrlEvent (com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent)1