Search in sources :

Example 1 with TaskStatus

use of com.alibaba.jstorm.task.TaskStatus 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)

Example 2 with TaskStatus

use of com.alibaba.jstorm.task.TaskStatus in project jstorm by alibaba.

the class TaskHeartbeatUpdater method checkAllTasksShutdown.

private boolean checkAllTasksShutdown() {
    boolean ret = true;
    List<TaskStatus> taskStatuses = new ArrayList<>();
    taskStatuses.addAll(spoutsExecutorStatusMap.values());
    taskStatuses.addAll(boltsExecutorStatusMap.values());
    for (TaskStatus status : taskStatuses) {
        if (status.getStatus() == TaskStatus.RUN) {
            ret = false;
            break;
        }
    }
    return ret;
}
Also used : TaskStatus(com.alibaba.jstorm.task.TaskStatus)

Example 3 with TaskStatus

use of com.alibaba.jstorm.task.TaskStatus in project jstorm by alibaba.

the class TaskHeartbeatUpdater method initExecutorsStatus.

private void initExecutorsStatus() {
    this.boltsExecutorStatusMap = new ConcurrentHashMap<>();
    this.spoutsExecutorStatusMap = new ConcurrentHashMap<>();
    try {
        StormTopology sysTopology = Common.system_topology(stormConf, context.getRawTopology());
        Map<String, Bolt> bolts = sysTopology.get_bolts();
        if (bolts != null) {
            List<Integer> boltTasks = this.context.getComponentsTasks(bolts.keySet());
            for (Integer task : boltTasks) {
                boltsExecutorStatusMap.put(task, new TaskStatus());
            }
            //exception of topolgy master task
            boltsExecutorStatusMap.remove(taskId);
        }
        Map<String, SpoutSpec> spouts = sysTopology.get_spouts();
        if (bolts != null) {
            List<Integer> spoutTasks = this.context.getComponentsTasks(spouts.keySet());
            for (Integer task : spoutTasks) {
                spoutsExecutorStatusMap.put(task, new TaskStatus());
            }
        }
    } catch (InvalidTopologyException e) {
        LOG.error("Failed to build system topology", e);
        throw new RuntimeException(e);
    }
}
Also used : TaskStatus(com.alibaba.jstorm.task.TaskStatus)

Aggregations

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