-
Notifications
You must be signed in to change notification settings - Fork 5k
[Fix-17758][Master] Mark task as failed if TaskExecutionContext initialization fails #17821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event; | ||
|
|
||
| import org.apache.dolphinscheduler.server.master.engine.ILifecycleEventType; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.AbstractTaskLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.TaskLifecycleEventType; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable; | ||
|
|
||
| import java.util.Date; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
|
|
||
| @Data | ||
| @Builder | ||
| @AllArgsConstructor | ||
| public class TaskFatalLifecycleEvent extends AbstractTaskLifecycleEvent { | ||
|
|
||
| private final ITaskExecutionRunnable taskExecutionRunnable; | ||
Check noticeCode scanning / CodeQL Missing Override annotation Note
This method overrides
AbstractTaskLifecycleEvent.getTaskExecutionRunnable Error loading related location Loading
|
||
|
|
||
| private final Date endTime; | ||
|
|
||
| @Override | ||
| public ILifecycleEventType getEventType() { | ||
| return TaskLifecycleEventType.FATAL; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "TaskFatalLifecycleEvent{" + | ||
| "task=" + taskExecutionRunnable.getName() + | ||
| ", endTime=" + endTime + | ||
| '}'; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.dolphinscheduler.server.master.engine.task.lifecycle.handler; | ||
|
|
||
| import org.apache.dolphinscheduler.server.master.engine.ILifecycleEventType; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.TaskLifecycleEventType; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskFatalLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.statemachine.ITaskStateAction; | ||
| import org.apache.dolphinscheduler.server.master.engine.workflow.runnable.IWorkflowExecutionRunnable; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class TaskFatalLifecycleEventHandler extends AbstractTaskLifecycleEventHandler<TaskFatalLifecycleEvent> { | ||
|
|
||
| @Override | ||
| public void handle(final ITaskStateAction taskStateAction, | ||
| final IWorkflowExecutionRunnable workflowExecutionRunnable, | ||
| final ITaskExecutionRunnable taskExecutionRunnable, | ||
| final TaskFatalLifecycleEvent taskFatalEvent) { | ||
| taskStateAction.onFatalEvent(workflowExecutionRunnable, taskExecutionRunnable, taskFatalEvent); | ||
| } | ||
|
|
||
| @Override | ||
| public ILifecycleEventType matchEventType() { | ||
| return TaskLifecycleEventType.FATAL; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -36,6 +36,7 @@ | |||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskSuccessLifecycleEvent; | ||||
| import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable; | ||||
| import org.apache.dolphinscheduler.server.master.engine.workflow.runnable.IWorkflowExecutionRunnable; | ||||
| import org.apache.dolphinscheduler.server.master.exception.TaskExecutionContextCreateException; | ||||
|
|
||||
| import java.util.concurrent.TimeUnit; | ||||
|
|
||||
|
|
@@ -109,7 +110,14 @@ public void onDispatchEvent(final IWorkflowExecutionRunnable workflowExecutionRu | |||
| taskInstance.getDelayTime(), | ||||
| remainTimeMills); | ||||
| } | ||||
| taskExecutionRunnable.initializeTaskExecutionContext(); | ||||
|
|
||||
| try { | ||||
| taskExecutionRunnable.initializeTaskExecutionContext(); | ||||
| } catch (Exception ex) { | ||||
| log.error("Failed to initialize task execution context, taskName: {}", taskInstance.getName(), ex); | ||||
| throw new TaskExecutionContextCreateException(ex.getMessage()); | ||||
|
|
||||
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsafe type casting without verification. While the TaskExecutionContextCreateException is currently only thrown when handling TaskDispatchLifecycleEvent (which extends AbstractTaskLifecycleEvent), it would be safer to check the type before casting to prevent potential ClassCastException if the code structure changes. Consider adding an instanceof check before the cast.