ruanwenjun commented on code in PR #13948: URL: https://github.com/apache/dolphinscheduler/pull/13948#discussion_r1174401666
########## dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/BaseTaskDispatcher.java: ########## @@ -0,0 +1,133 @@ +/* + * 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.runner; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.apache.dolphinscheduler.common.enums.TaskEventType; +import org.apache.dolphinscheduler.common.utils.DateUtils; +import org.apache.dolphinscheduler.common.utils.JSONUtils; +import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; +import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; +import org.apache.dolphinscheduler.remote.command.Message; +import org.apache.dolphinscheduler.remote.command.task.TaskDispatchRequest; +import org.apache.dolphinscheduler.remote.command.task.TaskDispatchResponse; +import org.apache.dolphinscheduler.remote.exceptions.RemotingException; +import org.apache.dolphinscheduler.remote.utils.Host; +import org.apache.dolphinscheduler.server.master.config.MasterConfig; +import org.apache.dolphinscheduler.server.master.dispatch.exceptions.WorkerGroupNotFoundException; +import org.apache.dolphinscheduler.server.master.exception.TaskDispatchException; +import org.apache.dolphinscheduler.server.master.processor.queue.TaskEvent; +import org.apache.dolphinscheduler.server.master.processor.queue.TaskEventService; +import org.apache.dolphinscheduler.server.master.rpc.MasterRpcClient; +import org.apache.dolphinscheduler.server.master.runner.dispatcher.TaskDispatcher; +import org.apache.dolphinscheduler.server.master.runner.execute.TaskExecuteRunnable; + +import java.util.Date; +import java.util.Optional; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public abstract class BaseTaskDispatcher implements TaskDispatcher { + + protected final TaskEventService taskEventService; + protected final MasterConfig masterConfig; + protected final MasterRpcClient masterRpcClient; + + protected BaseTaskDispatcher(TaskEventService taskEventService, + MasterConfig masterConfig, + MasterRpcClient masterRpcClient) { + this.taskEventService = checkNotNull(taskEventService); + this.masterConfig = checkNotNull(masterConfig); + this.masterRpcClient = checkNotNull(masterRpcClient); + } + + @Override + public void dispatchTask(TaskExecuteRunnable taskExecuteRunnable) throws TaskDispatchException { + Host taskInstanceDispatchHost; + try { + taskInstanceDispatchHost = getTaskInstanceDispatchHost(taskExecuteRunnable) + .orElseThrow(() -> new TaskDispatchException("Cannot find the host to execute task.")); + } catch (WorkerGroupNotFoundException workerGroupNotFoundException) { + log.error("Dispatch task: {} failed, worker group not found.", + taskExecuteRunnable.getTaskExecutionContext().getTaskName(), workerGroupNotFoundException); + addDispatchFailedEvent(taskExecuteRunnable); + return; + } + // todo: why we need to add field host to taskExecutionContext? + // it's better to make the dispatch in sync, then we can get the host from dispatch response. Review Comment: This is done. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
