In DolphinScheduler for YARN tasks such as MapReduce (MR), Spark, Flink, and even Shell tasks, the initial approach was to determine the task status based on the application ID when a YARN task was detected. This means that instead of relying solely on the client process status, DolphinScheduler would also consider the YARN status to decide on the task state.
\ Later, the community refactored this process (which was a step in the right direction but is still incomplete), leading to some issues.
\ For instance, in the Flink Stream Application mode, where the client is detached, the client Shell exits immediately, causing DolphinScheduler to mark the task as successful. However, the task on YARN is still running, and DolphinScheduler can no longer track its status on YARN.
\ So, how can we implement tracking for YARN task status in DolphinScheduler?
\
Note: This example is based on version 3.2.1.
Worker Task Relationship DiagramFirst, let’s look at the relationship principle of Worker Tasks in DolphinScheduler.
\
\
\
The AbstractYarnTask can implement YARN status tracking. Refer to the full code in org.apache.dolphinscheduler.plugin.task.api.AbstractYarnTask:
public abstract class AbstractYarnTask extends AbstractRemoteTask { private static final int MAX_RETRY_ATTEMPTS = 3; private ShellCommandExecutor shellCommandExecutor; public AbstractYarnTask(TaskExecutionContext taskRequest) { super(taskRequest); this.shellCommandExecutor = new ShellCommandExecutor(this::logHandle, taskRequest); } @Override public void submitApplication() throws TaskException { try { IShellInterceptorBuilder shellActuatorBuilder = ShellInterceptorBuilderFactory.newBuilder() .properties(getProperties()) .appendScript(getScript().replaceAll("\\r\\n", System.lineSeparator())); TaskResponse response = shellCommandExecutor.run(shellActuatorBuilder, null); setExitStatusCode(response.getExitStatusCode()); setAppIds(String.join(TaskConstants.COMMA, getApplicationIds())); setProcessId(response.getProcessId()); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); log.info("The current yarn task has been interrupted", ex); setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE); throw new TaskException("The current yarn task has been interrupted", ex); } catch (Exception e) { log.error("yarn process failure", e); exitStatusCode = -1; throw new TaskException("Execute task failed", e); } } @Override public void trackApplicationStatus() throws TaskException { if (StringUtils.isEmpty(appIds)) { return; } ListHere, the core logic is that instead of overriding the handle method directly, YARN tasks only need to implement two core interfaces: submitApplicationand trackApplicationStatus. The cancelApplication method ideally should be delegated to YarnApplicationManager (this integration is currently missing but does not impact functionality).
Displaying ApplicationId for Streaming Tasks on the FrontendFile: dolphinscheduler-ui/src/views/projects/task/instance/use-stream-table.ts
Wrapping ApplicationId as YARN URL on the BackendFile: dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java
\
File: dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/Constants.java
\
File: dolphinscheduler-common/src/main/resources/common.properties
\
File: dolphinscheduler-storage-plugin/dolphinscheduler-storage-hdfs/src/main/java/org/apache/dolphinscheduler/plugin/storage/hdfs/HdfsStorageOperator.java
\
File: dolphinscheduler-storage-plugin/dolphinscheduler-storage-hdfs/src/main/java/org/apache/dolphinscheduler/plugin/storage/hdfs/HdfsStorageProperties.java
\
Final UI display:
\
Note: You will need to manually paste the URL; the above code does not include this functionality.
Problem TrackingThere is an issue here regarding the state. There are three states: FINISHED, FAILED, and KILLED. However, within the FINISHED state, there is also a FinalStatus, and being “finished” doesn’t necessarily mean success. Under FINISHED, there are actually SUCCEEDED, FAILED, and KILLED statuses. Essentially, FINISHED cannot be treated as the final state in DolphinScheduler, and further evaluation is needed.
\ In the code for org.apache.dolphinscheduler.plugin.task.api.AbstractYarnTask#handleFinalState:
private void handleFinalState(YarnState yarnState) { switch (yarnState) { case FINISHED: setExitStatusCode(EXIT_CODE_SUCCESS); break; case KILLED: setExitStatusCode(EXIT_CODE_KILL); break; default: setExitStatusCode(EXIT_CODE_FAILURE); break; } } Using HTTP to Kill a Task curl -X PUT -d '{"state":"KILLED"}' \ -H "Content-Type: application/json" \ http://xx.xx.xx.xx:8088/ws/v1/cluster/apps/application_1694766249884_1098/state?user.name=hdfsNote: You must specifyuser.name, otherwise, the task might not be killed successfully.
All Rights Reserved. Copyright , Central Coast Communications, Inc.