use of com.alibaba.jstorm.daemon.nimbus.StatusType in project jstorm by alibaba.
the class RefreshActive method run.
@Override
public void run() {
try {
StatusType newTopologyStatus;
// /ZK-DIR/topology
StormBase base = zkCluster.storm_base(topologyId, this);
if (base == null) {
// normally the topology has been removed
LOG.warn("Failed to get StormBase from ZK of " + topologyId);
newTopologyStatus = StatusType.killed;
} else {
newTopologyStatus = base.getStatus().getStatusType();
}
// Process the topology status change
StatusType oldTopologyStatus = workerData.getTopologyStatus();
List<TaskShutdownDameon> tasks = workerData.getShutdownTasks();
if (tasks == null) {
LOG.info("Tasks aren't ready or are beginning to shutdown");
return;
}
// If all connections were done, start to update topology status. Otherwise, just return.
if (oldTopologyStatus == null) {
if (!workerData.getWorkeInitConnectionStatus().get()) {
return;
}
}
if (oldTopologyStatus == null || !newTopologyStatus.equals(oldTopologyStatus)) {
LOG.info("Old TopologyStatus:" + oldTopologyStatus + ", new TopologyStatus:" + newTopologyStatus);
if (newTopologyStatus.equals(StatusType.active)) {
for (TaskShutdownDameon task : tasks) {
if (task.getTask().getTaskStatus().isInit()) {
task.getTask().getTaskStatus().setStatus(TaskStatus.RUN);
} else {
task.active();
}
}
} else if (oldTopologyStatus == null || !oldTopologyStatus.equals(StatusType.inactive)) {
for (TaskShutdownDameon task : tasks) {
if (task.getTask().getTaskStatus().isInit()) {
task.getTask().getTaskStatus().setStatus(TaskStatus.PAUSE);
} else {
task.deactive();
}
}
}
workerData.setTopologyStatus(newTopologyStatus);
if (base != null) {
boolean newMonitorEnable = base.isEnableMonitor();
boolean oldMonitorEnable = monitorEnable.get();
if (newMonitorEnable != oldMonitorEnable) {
LOG.info("Change MonitorEnable from " + oldMonitorEnable + " to " + newMonitorEnable);
monitorEnable.set(newMonitorEnable);
}
}
}
} catch (Exception e) {
LOG.error("Failed to get topology from ZK ", e);
}
}
Aggregations