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);
}
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();
}
}
}
Aggregations