|
18 | 18 | package org.apache.dolphinscheduler.server.master.rpc; |
19 | 19 |
|
20 | 20 | import org.apache.dolphinscheduler.extract.master.ITaskExecutorEventListener; |
| 21 | +import org.apache.dolphinscheduler.plugin.task.api.utils.LogUtils; |
21 | 22 | import org.apache.dolphinscheduler.server.master.engine.IWorkflowRepository; |
22 | 23 | import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskDispatchedLifecycleEvent; |
23 | 24 | import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskFailedLifecycleEvent; |
@@ -53,79 +54,118 @@ public class TaskExecutorEventListenerImpl implements ITaskExecutorEventListener |
53 | 54 |
|
54 | 55 | @Override |
55 | 56 | public void onTaskExecutorDispatched(final TaskExecutorDispatchedLifecycleEvent taskExecutorDispatchedLifecycleEvent) { |
56 | | - final ITaskExecutionRunnable taskExecutionRunnable = |
57 | | - getTaskExecutionRunnable(taskExecutorDispatchedLifecycleEvent); |
58 | | - final TaskDispatchedLifecycleEvent taskDispatchedLifecycleEvent = TaskDispatchedLifecycleEvent.builder() |
59 | | - .taskExecutionRunnable(taskExecutionRunnable) |
60 | | - .executorHost(taskExecutorDispatchedLifecycleEvent.getTaskInstanceHost()) |
61 | | - .build(); |
62 | | - |
63 | | - taskExecutionRunnable.getWorkflowEventBus().publish(taskDispatchedLifecycleEvent); |
| 57 | + LogUtils.setWorkflowInstanceIdMDC(taskExecutorDispatchedLifecycleEvent.getWorkflowInstanceId()); |
| 58 | + try { |
| 59 | + final ITaskExecutionRunnable taskExecutionRunnable = |
| 60 | + getTaskExecutionRunnable(taskExecutorDispatchedLifecycleEvent); |
| 61 | + final TaskDispatchedLifecycleEvent taskDispatchedLifecycleEvent = TaskDispatchedLifecycleEvent.builder() |
| 62 | + .taskExecutionRunnable(taskExecutionRunnable) |
| 63 | + .executorHost(taskExecutorDispatchedLifecycleEvent.getTaskInstanceHost()) |
| 64 | + .build(); |
| 65 | + |
| 66 | + taskExecutionRunnable.getWorkflowEventBus().publish(taskDispatchedLifecycleEvent); |
| 67 | + } finally { |
| 68 | + LogUtils.removeWorkflowInstanceIdMDC(); |
| 69 | + } |
64 | 70 | } |
65 | 71 |
|
66 | 72 | @Override |
67 | 73 | public void onTaskExecutorRunning(final TaskExecutorStartedLifecycleEvent taskExecutorStartedLifecycleEvent) { |
68 | | - final ITaskExecutionRunnable taskExecutionRunnable = |
69 | | - getTaskExecutionRunnable(taskExecutorStartedLifecycleEvent); |
70 | | - final TaskRunningLifecycleEvent taskRunningEvent = TaskRunningLifecycleEvent.builder() |
71 | | - .taskExecutionRunnable(taskExecutionRunnable) |
72 | | - .startTime(new Date(taskExecutorStartedLifecycleEvent.getStartTime())) |
73 | | - .logPath(taskExecutorStartedLifecycleEvent.getLogPath()) |
74 | | - .build(); |
75 | | - |
76 | | - taskExecutionRunnable.getWorkflowEventBus().publish(taskRunningEvent); |
| 74 | + LogUtils.setWorkflowInstanceIdMDC(taskExecutorStartedLifecycleEvent.getWorkflowInstanceId()); |
| 75 | + try { |
| 76 | + final ITaskExecutionRunnable taskExecutionRunnable = |
| 77 | + getTaskExecutionRunnable(taskExecutorStartedLifecycleEvent); |
| 78 | + final TaskRunningLifecycleEvent taskRunningEvent = TaskRunningLifecycleEvent.builder() |
| 79 | + .taskExecutionRunnable(taskExecutionRunnable) |
| 80 | + .startTime(new Date(taskExecutorStartedLifecycleEvent.getStartTime())) |
| 81 | + .logPath(taskExecutorStartedLifecycleEvent.getLogPath()) |
| 82 | + .build(); |
| 83 | + |
| 84 | + taskExecutionRunnable.getWorkflowEventBus().publish(taskRunningEvent); |
| 85 | + } finally { |
| 86 | + LogUtils.removeWorkflowInstanceIdMDC(); |
| 87 | + } |
77 | 88 | } |
78 | 89 |
|
79 | 90 | @Override |
80 | 91 | public void onTaskExecutorRuntimeContextChanged(final TaskExecutorRuntimeContextChangedLifecycleEvent taskExecutorRuntimeContextChangedLifecycleEventr) { |
81 | | - final ITaskExecutionRunnable taskExecutionRunnable = |
82 | | - getTaskExecutionRunnable(taskExecutorRuntimeContextChangedLifecycleEventr); |
83 | | - |
84 | | - final TaskRuntimeContextChangedEvent taskRuntimeContextChangedEvent = TaskRuntimeContextChangedEvent.builder() |
85 | | - .taskExecutionRunnable(taskExecutionRunnable) |
86 | | - .runtimeContext(taskExecutorRuntimeContextChangedLifecycleEventr.getAppIds()) |
87 | | - .build(); |
88 | | - |
89 | | - taskExecutionRunnable.getWorkflowEventBus().publish(taskRuntimeContextChangedEvent); |
| 92 | + LogUtils.setWorkflowInstanceIdMDC(taskExecutorRuntimeContextChangedLifecycleEventr.getWorkflowInstanceId()); |
| 93 | + try { |
| 94 | + final ITaskExecutionRunnable taskExecutionRunnable = |
| 95 | + getTaskExecutionRunnable(taskExecutorRuntimeContextChangedLifecycleEventr); |
| 96 | + |
| 97 | + final TaskRuntimeContextChangedEvent taskRuntimeContextChangedEvent = |
| 98 | + TaskRuntimeContextChangedEvent.builder() |
| 99 | + .taskExecutionRunnable(taskExecutionRunnable) |
| 100 | + .runtimeContext(taskExecutorRuntimeContextChangedLifecycleEventr.getAppIds()) |
| 101 | + .build(); |
| 102 | + |
| 103 | + taskExecutionRunnable.getWorkflowEventBus().publish(taskRuntimeContextChangedEvent); |
| 104 | + } finally { |
| 105 | + LogUtils.removeWorkflowInstanceIdMDC(); |
| 106 | + } |
90 | 107 | } |
91 | 108 |
|
92 | 109 | @Override |
93 | 110 | public void onTaskExecutorSuccess(final TaskExecutorSuccessLifecycleEvent taskExecutorSuccessLifecycleEvent) { |
94 | | - final ITaskExecutionRunnable taskExecutionRunnable = |
95 | | - getTaskExecutionRunnable(taskExecutorSuccessLifecycleEvent); |
96 | | - final TaskSuccessLifecycleEvent taskSuccessEvent = TaskSuccessLifecycleEvent.builder() |
97 | | - .taskExecutionRunnable(taskExecutionRunnable) |
98 | | - .endTime(new Date(taskExecutorSuccessLifecycleEvent.getEndTime())) |
99 | | - .varPool(taskExecutorSuccessLifecycleEvent.getVarPool()) |
100 | | - .build(); |
101 | | - taskExecutionRunnable.getWorkflowEventBus().publish(taskSuccessEvent); |
| 111 | + LogUtils.setWorkflowInstanceIdMDC(taskExecutorSuccessLifecycleEvent.getWorkflowInstanceId()); |
| 112 | + try { |
| 113 | + final ITaskExecutionRunnable taskExecutionRunnable = |
| 114 | + getTaskExecutionRunnable(taskExecutorSuccessLifecycleEvent); |
| 115 | + final TaskSuccessLifecycleEvent taskSuccessEvent = TaskSuccessLifecycleEvent.builder() |
| 116 | + .taskExecutionRunnable(taskExecutionRunnable) |
| 117 | + .endTime(new Date(taskExecutorSuccessLifecycleEvent.getEndTime())) |
| 118 | + .varPool(taskExecutorSuccessLifecycleEvent.getVarPool()) |
| 119 | + .build(); |
| 120 | + taskExecutionRunnable.getWorkflowEventBus().publish(taskSuccessEvent); |
| 121 | + } finally { |
| 122 | + LogUtils.removeWorkflowInstanceIdMDC(); |
| 123 | + } |
102 | 124 | } |
103 | 125 |
|
104 | 126 | @Override |
105 | 127 | public void onTaskExecutorFailed(final TaskExecutorFailedLifecycleEvent taskExecutorFailedLifecycleEvent) { |
106 | | - final ITaskExecutionRunnable taskExecutionRunnable = getTaskExecutionRunnable(taskExecutorFailedLifecycleEvent); |
107 | | - final TaskFailedLifecycleEvent taskFailedEvent = TaskFailedLifecycleEvent.builder() |
108 | | - .taskExecutionRunnable(taskExecutionRunnable) |
109 | | - .endTime(new Date(taskExecutorFailedLifecycleEvent.getEndTime())) |
110 | | - .build(); |
111 | | - taskExecutionRunnable.getWorkflowEventBus().publish(taskFailedEvent); |
| 128 | + LogUtils.setWorkflowInstanceIdMDC(taskExecutorFailedLifecycleEvent.getWorkflowInstanceId()); |
| 129 | + try { |
| 130 | + final ITaskExecutionRunnable taskExecutionRunnable = |
| 131 | + getTaskExecutionRunnable(taskExecutorFailedLifecycleEvent); |
| 132 | + final TaskFailedLifecycleEvent taskFailedEvent = TaskFailedLifecycleEvent.builder() |
| 133 | + .taskExecutionRunnable(taskExecutionRunnable) |
| 134 | + .endTime(new Date(taskExecutorFailedLifecycleEvent.getEndTime())) |
| 135 | + .build(); |
| 136 | + taskExecutionRunnable.getWorkflowEventBus().publish(taskFailedEvent); |
| 137 | + } finally { |
| 138 | + LogUtils.removeWorkflowInstanceIdMDC(); |
| 139 | + } |
112 | 140 | } |
113 | 141 |
|
114 | 142 | @Override |
115 | 143 | public void onTaskExecutorKilled(final TaskExecutorKilledLifecycleEvent taskExecutorKilledLifecycleEvent) { |
116 | | - final ITaskExecutionRunnable taskExecutionRunnable = getTaskExecutionRunnable(taskExecutorKilledLifecycleEvent); |
117 | | - final TaskKilledLifecycleEvent taskKilledEvent = TaskKilledLifecycleEvent.builder() |
118 | | - .taskExecutionRunnable(taskExecutionRunnable) |
119 | | - .endTime(new Date(taskExecutorKilledLifecycleEvent.getEndTime())) |
120 | | - .build(); |
121 | | - taskExecutionRunnable.getWorkflowEventBus().publish(taskKilledEvent); |
| 144 | + LogUtils.setWorkflowInstanceIdMDC(taskExecutorKilledLifecycleEvent.getWorkflowInstanceId()); |
| 145 | + try { |
| 146 | + final ITaskExecutionRunnable taskExecutionRunnable = |
| 147 | + getTaskExecutionRunnable(taskExecutorKilledLifecycleEvent); |
| 148 | + final TaskKilledLifecycleEvent taskKilledEvent = TaskKilledLifecycleEvent.builder() |
| 149 | + .taskExecutionRunnable(taskExecutionRunnable) |
| 150 | + .endTime(new Date(taskExecutorKilledLifecycleEvent.getEndTime())) |
| 151 | + .build(); |
| 152 | + taskExecutionRunnable.getWorkflowEventBus().publish(taskKilledEvent); |
| 153 | + } finally { |
| 154 | + LogUtils.removeWorkflowInstanceIdMDC(); |
| 155 | + } |
122 | 156 | } |
123 | 157 |
|
124 | 158 | @Override |
125 | 159 | public void onTaskExecutorPaused(final TaskExecutorPausedLifecycleEvent taskExecutorPausedLifecycleEvent) { |
126 | | - final ITaskExecutionRunnable taskExecutionRunnable = getTaskExecutionRunnable(taskExecutorPausedLifecycleEvent); |
127 | | - final TaskPausedLifecycleEvent taskPausedEvent = TaskPausedLifecycleEvent.of(taskExecutionRunnable); |
128 | | - taskExecutionRunnable.getWorkflowEventBus().publish(taskPausedEvent); |
| 160 | + LogUtils.setWorkflowInstanceIdMDC(taskExecutorPausedLifecycleEvent.getWorkflowInstanceId()); |
| 161 | + try { |
| 162 | + final ITaskExecutionRunnable taskExecutionRunnable = |
| 163 | + getTaskExecutionRunnable(taskExecutorPausedLifecycleEvent); |
| 164 | + final TaskPausedLifecycleEvent taskPausedEvent = TaskPausedLifecycleEvent.of(taskExecutionRunnable); |
| 165 | + taskExecutionRunnable.getWorkflowEventBus().publish(taskPausedEvent); |
| 166 | + } finally { |
| 167 | + LogUtils.removeWorkflowInstanceIdMDC(); |
| 168 | + } |
129 | 169 | } |
130 | 170 |
|
131 | 171 | private ITaskExecutionRunnable getTaskExecutionRunnable(final IReportableTaskExecutorLifecycleEvent reportableTaskExecutorLifecycleEvent) { |
|
0 commit comments