From 3581578d37c668768d0a2411fbedc6e6270d005b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E4=B9=89=E8=B6=85?= Date: Tue, 6 Jan 2026 20:30:55 +0800 Subject: [PATCH] add task result alert from worker to master by rpc --- .../common/enums/AlertType.java | 3 +- .../dao/mapper/TaskDefinitionMapperTest.java | 4 +- .../master/ITaskResultAlertService.java | 30 ++++++++ ...TaskExecutorEventRemoteReporterClient.java | 37 ++++++++++ .../transportor/TaskResultAlertRequest.java | 42 +++++++++++ .../transportor/TaskResultAlertResponse.java | 40 +++++++++++ .../rpc/TaskResultAlertServiceImpl.java | 72 +++++++++++++++++++ .../TaskExecutorEventBusCoordinator.java | 5 ++ .../TaskExecutorLifecycleEventType.java | 2 + ...TaskExecutorResultAlertLifecycleEvent.java | 59 +++++++++++++++ .../ITaskExecutorLifecycleEventListener.java | 2 + .../TaskExecutorLifecycleEventListener.java | 6 ++ .../plugin/task/api/AbstractTask.java | 12 ++-- .../plugin/task/api/TaskCallBack.java | 3 + ...lertInfo.java => TaskResultAlertInfo.java} | 28 ++------ .../task/api/parameters/SqlParameters.java | 14 ++-- .../api/parameters/SqlParametersTest.java | 6 +- .../plugin/task/datax/DataxTaskTest.java | 6 ++ .../plugin/task/emr/EmrAddStepsTaskTest.java | 6 ++ .../plugin/task/emr/EmrJobFlowTaskTest.java | 6 ++ .../plugin/task/sql/SqlTask.java | 22 ++++-- .../task/zeppelin/ZeppelinTaskTest.java | 6 ++ .../components/node/fields/use-sql-type.ts | 14 ++-- .../task/components/node/format-data.ts | 4 +- .../projects/task/components/node/types.ts | 2 +- .../worker/executor/PhysicalTaskExecutor.java | 8 +++ 26 files changed, 382 insertions(+), 57 deletions(-) create mode 100644 dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/ITaskResultAlertService.java create mode 100644 dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/transportor/TaskResultAlertRequest.java create mode 100644 dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/transportor/TaskResultAlertResponse.java create mode 100644 dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/rpc/TaskResultAlertServiceImpl.java create mode 100644 dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/events/TaskExecutorResultAlertLifecycleEvent.java rename dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/model/{TaskAlertInfo.java => TaskResultAlertInfo.java} (66%) diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/AlertType.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/AlertType.java index f7a5ba0d3906..096f4e3c7918 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/AlertType.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/AlertType.java @@ -29,7 +29,7 @@ public enum AlertType { /** * 0 workflow instance failure, 1 workflow instance success, 2 workflow instance blocked, 3 workflow instance timeout, 4 fault tolerance warning, - * 5 task failure, 6 task success, 7 task timeout, 8 close alert + * 5 task failure, 6 task success, 7 task timeout, 8 task result */ WORKFLOW_INSTANCE_FAILURE(0, "workflow instance failure"), WORKFLOW_INSTANCE_SUCCESS(1, "workflow instance success"), @@ -39,6 +39,7 @@ public enum AlertType { TASK_FAILURE(5, "task failure"), TASK_SUCCESS(6, "task success"), TASK_TIMEOUT(7, "task timeout"), + TASK_RESULT(8, "task result"); ; AlertType(int code, String descp) { diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapperTest.java index da3cc1d27481..83fc14e5fec7 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapperTest.java @@ -140,7 +140,7 @@ public void testDeleteByCode() { @Test public void testNullPropertyValueOfLocalParams() { String definitionJson = - "{\"failRetryTimes\":\"0\",\"timeoutNotifyStrategy\":\"\",\"code\":\"5195043558720\",\"flag\":\"YES\",\"environmentCode\":\"-1\",\"taskDefinitionIndex\":2,\"taskPriority\":\"MEDIUM\",\"taskParams\":\"{\\\"preStatements\\\":null,\\\"postStatements\\\":null,\\\"type\\\":\\\"ADB_MYSQL\\\",\\\"database\\\":\\\"lijia\\\",\\\"sql\\\":\\\"create table nation_${random_serial_number} as select * from nation\\\",\\\"localParams\\\":[{\\\"direct\\\":2,\\\"type\\\":3,\\\"prop\\\":\\\"key\\\"}],\\\"Name\\\":\\\"create_table_as_select_nation\\\",\\\"FailRetryTimes\\\":0,\\\"dbClusterId\\\":\\\"amv-bp10o45925jpx959\\\",\\\"sendEmail\\\":false,\\\"displayRows\\\":10,\\\"limit\\\":10000,\\\"agentSource\\\":\\\"Workflow\\\",\\\"agentVersion\\\":\\\"Unkown\\\"}\",\"timeout\":\"0\",\"taskType\":\"ADB_MYSQL\",\"timeoutFlag\":\"CLOSE\",\"projectCode\":\"5191800302720\",\"name\":\"create_table_as_select_nation\",\"delayTime\":\"0\",\"workerGroup\":\"default\"}"; + "{\"failRetryTimes\":\"0\",\"timeoutNotifyStrategy\":\"\",\"code\":\"5195043558720\",\"flag\":\"YES\",\"environmentCode\":\"-1\",\"taskDefinitionIndex\":2,\"taskPriority\":\"MEDIUM\",\"taskParams\":\"{\\\"preStatements\\\":null,\\\"postStatements\\\":null,\\\"type\\\":\\\"ADB_MYSQL\\\",\\\"database\\\":\\\"lijia\\\",\\\"sql\\\":\\\"create table nation_${random_serial_number} as select * from nation\\\",\\\"localParams\\\":[{\\\"direct\\\":2,\\\"type\\\":3,\\\"prop\\\":\\\"key\\\"}],\\\"Name\\\":\\\"create_table_as_select_nation\\\",\\\"FailRetryTimes\\\":0,\\\"dbClusterId\\\":\\\"amv-bp10o45925jpx959\\\",\\\"sendAlert\\\":false,\\\"displayRows\\\":10,\\\"limit\\\":10000,\\\"agentSource\\\":\\\"Workflow\\\",\\\"agentVersion\\\":\\\"Unkown\\\"}\",\"timeout\":\"0\",\"taskType\":\"ADB_MYSQL\",\"timeoutFlag\":\"CLOSE\",\"projectCode\":\"5191800302720\",\"name\":\"create_table_as_select_nation\",\"delayTime\":\"0\",\"workerGroup\":\"default\"}"; TaskDefinition definition = JSONUtils.parseObject(definitionJson, TaskDefinition.class); Map taskParamsMap = definition.getTaskParamMap(); @@ -157,7 +157,7 @@ public void testNullPropertyValueOfLocalParams() { @Test public void testNullLocalParamsOfTaskParams() { String definitionJson = - "{\"failRetryTimes\":\"0\",\"timeoutNotifyStrategy\":\"\",\"code\":\"5195043558720\",\"flag\":\"YES\",\"environmentCode\":\"-1\",\"taskDefinitionIndex\":2,\"taskPriority\":\"MEDIUM\",\"taskParams\":\"{\\\"preStatements\\\":null,\\\"postStatements\\\":null,\\\"type\\\":\\\"ADB_MYSQL\\\",\\\"database\\\":\\\"lijia\\\",\\\"sql\\\":\\\"create table nation_${random_serial_number} as select * from nation\\\",\\\"localParams\\\":null,\\\"Name\\\":\\\"create_table_as_select_nation\\\",\\\"FailRetryTimes\\\":0,\\\"dbClusterId\\\":\\\"amv-bp10o45925jpx959\\\",\\\"sendEmail\\\":false,\\\"displayRows\\\":10,\\\"limit\\\":10000,\\\"agentSource\\\":\\\"Workflow\\\",\\\"agentVersion\\\":\\\"Unkown\\\"}\",\"timeout\":\"0\",\"taskType\":\"ADB_MYSQL\",\"timeoutFlag\":\"CLOSE\",\"projectCode\":\"5191800302720\",\"name\":\"create_table_as_select_nation\",\"delayTime\":\"0\",\"workerGroup\":\"default\"}"; + "{\"failRetryTimes\":\"0\",\"timeoutNotifyStrategy\":\"\",\"code\":\"5195043558720\",\"flag\":\"YES\",\"environmentCode\":\"-1\",\"taskDefinitionIndex\":2,\"taskPriority\":\"MEDIUM\",\"taskParams\":\"{\\\"preStatements\\\":null,\\\"postStatements\\\":null,\\\"type\\\":\\\"ADB_MYSQL\\\",\\\"database\\\":\\\"lijia\\\",\\\"sql\\\":\\\"create table nation_${random_serial_number} as select * from nation\\\",\\\"localParams\\\":null,\\\"Name\\\":\\\"create_table_as_select_nation\\\",\\\"FailRetryTimes\\\":0,\\\"dbClusterId\\\":\\\"amv-bp10o45925jpx959\\\",\\\"sendAlert\\\":false,\\\"displayRows\\\":10,\\\"limit\\\":10000,\\\"agentSource\\\":\\\"Workflow\\\",\\\"agentVersion\\\":\\\"Unkown\\\"}\",\"timeout\":\"0\",\"taskType\":\"ADB_MYSQL\",\"timeoutFlag\":\"CLOSE\",\"projectCode\":\"5191800302720\",\"name\":\"create_table_as_select_nation\",\"delayTime\":\"0\",\"workerGroup\":\"default\"}"; TaskDefinition definition = JSONUtils.parseObject(definitionJson, TaskDefinition.class); Assertions.assertNull(definition.getTaskParamMap(), "Serialize the task definition success"); diff --git a/dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/ITaskResultAlertService.java b/dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/ITaskResultAlertService.java new file mode 100644 index 000000000000..32eeb9e3c160 --- /dev/null +++ b/dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/ITaskResultAlertService.java @@ -0,0 +1,30 @@ +/* + * 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.extract.master; + +import org.apache.dolphinscheduler.extract.base.RpcMethod; +import org.apache.dolphinscheduler.extract.base.RpcService; +import org.apache.dolphinscheduler.extract.master.transportor.TaskResultAlertRequest; +import org.apache.dolphinscheduler.extract.master.transportor.TaskResultAlertResponse; + +@RpcService +public interface ITaskResultAlertService { + + @RpcMethod + TaskResultAlertResponse reportTaskResultAlertToMaster(TaskResultAlertRequest taskResultAlertRequest); +} diff --git a/dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/TaskExecutorEventRemoteReporterClient.java b/dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/TaskExecutorEventRemoteReporterClient.java index cec9f8eab781..58229a576539 100644 --- a/dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/TaskExecutorEventRemoteReporterClient.java +++ b/dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/TaskExecutorEventRemoteReporterClient.java @@ -18,12 +18,16 @@ package org.apache.dolphinscheduler.extract.master; import org.apache.dolphinscheduler.extract.base.client.Clients; +import org.apache.dolphinscheduler.extract.master.transportor.TaskResultAlertRequest; +import org.apache.dolphinscheduler.extract.master.transportor.TaskResultAlertResponse; +import org.apache.dolphinscheduler.plugin.task.api.model.TaskResultAlertInfo; import org.apache.dolphinscheduler.task.executor.eventbus.ITaskExecutorEventRemoteReporterClient; import org.apache.dolphinscheduler.task.executor.events.IReportableTaskExecutorLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorDispatchedLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorFailedLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorKilledLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorPausedLifecycleEvent; +import org.apache.dolphinscheduler.task.executor.events.TaskExecutorResultAlertLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorRuntimeContextChangedLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorStartedLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorSuccessLifecycleEvent; @@ -67,6 +71,10 @@ public void reportTaskExecutionEventToMaster(final String masterAddress, reportTaskSuccessEventToMaster(masterAddress, (TaskExecutorSuccessLifecycleEvent) taskExecutorLifecycleEvent); break; + case RESULT_ALERT: + reportTaskResultAlertEventToMaster(masterAddress, + (TaskExecutorResultAlertLifecycleEvent) taskExecutorLifecycleEvent); + break; default: log.warn("Unsupported TaskExecutionEvent: {}", taskExecutorLifecycleEvent); } @@ -131,4 +139,33 @@ private static void reportTaskSuccessEventToMaster(final String masterAddress, .withHost(masterAddress) .onTaskExecutorSuccess(taskExecutionSuccessEvent); } + + private static void reportTaskResultAlertEventToMaster(final String masterAddress, + final TaskExecutorResultAlertLifecycleEvent taskExecutionResultAlertEvent) { + TaskResultAlertInfo taskResultAlertInfo = taskExecutionResultAlertEvent.getTaskResultAlertInfo(); + TaskResultAlertRequest taskResultAlertRequest = + TaskResultAlertRequest.builder() + .alertGroupId(taskResultAlertInfo.getAlertGroupId()) + .title(taskResultAlertInfo.getTitle()) + .content(taskResultAlertInfo.getContent()) + .workflowDefinitionCode(taskResultAlertInfo.getWorkflowDefinitionCode()) + .workflowInstanceId(taskResultAlertInfo.getWorkflowInstanceId()) + .taskInstanceId(taskResultAlertInfo.getTaskInstanceId()) + .build(); + + TaskResultAlertResponse taskResultAlertResponse = Clients.withService(ITaskResultAlertService.class) + .withHost(masterAddress) + .reportTaskResultAlertToMaster(taskResultAlertRequest); + + if (taskResultAlertResponse != null && taskResultAlertResponse.isSuccess()) { + log.info( + "Successfully reported task result alert to master. TaskInstanceId: {}, Title: '{}', MasterAddress: {}", + taskResultAlertInfo.getTaskInstanceId(), taskResultAlertInfo.getTitle(), masterAddress); + } else { + log.warn( + "Failed to report task result alert to master. TaskInstanceId: {}, Title: '{}', MasterAddress: {}, Reason: {}", + taskResultAlertInfo.getTaskInstanceId(), taskResultAlertInfo.getTitle(), masterAddress, + taskResultAlertResponse != null ? taskResultAlertResponse.getMessage() : "response is null"); + } + } } diff --git a/dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/transportor/TaskResultAlertRequest.java b/dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/transportor/TaskResultAlertRequest.java new file mode 100644 index 000000000000..54ea1e52d9d1 --- /dev/null +++ b/dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/transportor/TaskResultAlertRequest.java @@ -0,0 +1,42 @@ +/* + * 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.extract.master.transportor; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class TaskResultAlertRequest { + + private String title; + + private String content; + + private Integer alertGroupId; + + private Long workflowDefinitionCode; + + private Integer workflowInstanceId; + + private int taskInstanceId; +} diff --git a/dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/transportor/TaskResultAlertResponse.java b/dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/transportor/TaskResultAlertResponse.java new file mode 100644 index 000000000000..7915e64836bb --- /dev/null +++ b/dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/transportor/TaskResultAlertResponse.java @@ -0,0 +1,40 @@ +/* + * 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.extract.master.transportor; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TaskResultAlertResponse { + + private boolean success; + + private String message; + + public static TaskResultAlertResponse success() { + return new TaskResultAlertResponse(true, null); + } + + public static TaskResultAlertResponse failed(String message) { + return new TaskResultAlertResponse(false, message); + } +} diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/rpc/TaskResultAlertServiceImpl.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/rpc/TaskResultAlertServiceImpl.java new file mode 100644 index 000000000000..1b41a2aa9f1f --- /dev/null +++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/rpc/TaskResultAlertServiceImpl.java @@ -0,0 +1,72 @@ +/* + * 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.rpc; + +import org.apache.dolphinscheduler.common.enums.AlertType; +import org.apache.dolphinscheduler.common.enums.WarningType; +import org.apache.dolphinscheduler.dao.AlertDao; +import org.apache.dolphinscheduler.dao.entity.Alert; +import org.apache.dolphinscheduler.extract.master.ITaskResultAlertService; +import org.apache.dolphinscheduler.extract.master.transportor.TaskResultAlertRequest; +import org.apache.dolphinscheduler.extract.master.transportor.TaskResultAlertResponse; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import lombok.extern.slf4j.Slf4j; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class TaskResultAlertServiceImpl implements ITaskResultAlertService { + + @Autowired + private AlertDao alertDao; + + @Override + public TaskResultAlertResponse reportTaskResultAlertToMaster(TaskResultAlertRequest taskResultAlertRequest) { + log.info("Received TaskResultAlertRequest request{}", taskResultAlertRequest); + + try { + Alert alert = new Alert(); + alert.setTitle(taskResultAlertRequest.getTitle()); + alert.setContent(taskResultAlertRequest.getContent()); + alert.setWarningType(WarningType.NONE); + alert.setCreateTime(new Date()); + alert.setUpdateTime(new Date()); + alert.setAlertGroupId(taskResultAlertRequest.getAlertGroupId()); + alert.setWorkflowDefinitionCode(taskResultAlertRequest.getWorkflowDefinitionCode()); + alert.setWorkflowInstanceId(taskResultAlertRequest.getWorkflowInstanceId()); + Map info = new HashMap<>(); + info.put("taskInstanceId", taskResultAlertRequest.getTaskInstanceId()); + alert.setInfo(info); + + alert.setAlertType(AlertType.TASK_RESULT); + alertDao.addAlert(alert); + + log.info("add alert success"); + return TaskResultAlertResponse.success(); + } catch (Exception ex) { + log.error("add alert failed:{} ", ex.getMessage()); + return TaskResultAlertResponse.failed(ex.getMessage()); + } + } +} diff --git a/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/eventbus/TaskExecutorEventBusCoordinator.java b/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/eventbus/TaskExecutorEventBusCoordinator.java index 1ced554bc7a8..905d0690b2f6 100644 --- a/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/eventbus/TaskExecutorEventBusCoordinator.java +++ b/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/eventbus/TaskExecutorEventBusCoordinator.java @@ -33,6 +33,7 @@ import org.apache.dolphinscheduler.task.executor.events.TaskExecutorKilledLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorPauseLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorPausedLifecycleEvent; +import org.apache.dolphinscheduler.task.executor.events.TaskExecutorResultAlertLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorRuntimeContextChangedLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorStartedLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorSuccessLifecycleEvent; @@ -183,6 +184,10 @@ private void doFireTaskExecutorEventBus(final ITaskExecutor taskExecutor) { taskExecutorLifecycleEventListener.onTaskExecutorFinalizeLifecycleEvent( ((TaskExecutorFinalizeLifecycleEvent) taskExecutorLifecycleEvent)); break; + case RESULT_ALERT: + taskExecutorLifecycleEventListener.onTaskExecutorResultAlertLifecycleEvent( + ((TaskExecutorResultAlertLifecycleEvent) taskExecutorLifecycleEvent)); + break; default: throw new IllegalArgumentException( "Unsupported TaskExecutorLifecycleEvent: " + taskExecutorLifecycleEvent); diff --git a/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/events/TaskExecutorLifecycleEventType.java b/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/events/TaskExecutorLifecycleEventType.java index aa0aa2cd4e56..88e973beb578 100644 --- a/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/events/TaskExecutorLifecycleEventType.java +++ b/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/events/TaskExecutorLifecycleEventType.java @@ -37,6 +37,8 @@ public enum TaskExecutorLifecycleEventType { FAILED, + RESULT_ALERT, + FINALIZE, ; diff --git a/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/events/TaskExecutorResultAlertLifecycleEvent.java b/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/events/TaskExecutorResultAlertLifecycleEvent.java new file mode 100644 index 000000000000..e9a2ad158ef0 --- /dev/null +++ b/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/events/TaskExecutorResultAlertLifecycleEvent.java @@ -0,0 +1,59 @@ +/* + * 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.task.executor.events; + +import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; +import org.apache.dolphinscheduler.plugin.task.api.model.TaskResultAlertInfo; +import org.apache.dolphinscheduler.task.executor.ITaskExecutor; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.ToString; +import lombok.experimental.SuperBuilder; + +@Data +@ToString(callSuper = true) +@SuperBuilder +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor +public class TaskExecutorResultAlertLifecycleEvent extends AbstractTaskExecutorLifecycleEvent + implements + IReportableTaskExecutorLifecycleEvent { + + private int workflowInstanceId; + + private String taskInstanceHost; + + private Long latestReportTime; + + private TaskResultAlertInfo taskResultAlertInfo; + + public static TaskExecutorResultAlertLifecycleEvent of(final ITaskExecutor taskExecutor, + TaskResultAlertInfo taskResultAlertInfo) { + final TaskExecutionContext taskExecutionContext = taskExecutor.getTaskExecutionContext(); + return TaskExecutorResultAlertLifecycleEvent.builder() + .workflowInstanceId(taskExecutionContext.getWorkflowInstanceId()) + .taskInstanceId(taskExecutionContext.getTaskInstanceId()) + .taskInstanceHost(taskExecutionContext.getHost()) + .taskResultAlertInfo(taskResultAlertInfo) + .type(TaskExecutorLifecycleEventType.RESULT_ALERT) + .build(); + } + +} diff --git a/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/listener/ITaskExecutorLifecycleEventListener.java b/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/listener/ITaskExecutorLifecycleEventListener.java index 07da199cb5e4..0755a87288bb 100644 --- a/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/listener/ITaskExecutorLifecycleEventListener.java +++ b/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/listener/ITaskExecutorLifecycleEventListener.java @@ -24,6 +24,7 @@ import org.apache.dolphinscheduler.task.executor.events.TaskExecutorKilledLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorPauseLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorPausedLifecycleEvent; +import org.apache.dolphinscheduler.task.executor.events.TaskExecutorResultAlertLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorRuntimeContextChangedLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorStartedLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorSuccessLifecycleEvent; @@ -50,4 +51,5 @@ public interface ITaskExecutorLifecycleEventListener { void onTaskExecutorFinalizeLifecycleEvent(final TaskExecutorFinalizeLifecycleEvent event); + void onTaskExecutorResultAlertLifecycleEvent(final TaskExecutorResultAlertLifecycleEvent event); } diff --git a/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/listener/TaskExecutorLifecycleEventListener.java b/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/listener/TaskExecutorLifecycleEventListener.java index c17afaca636b..5d2df2846967 100644 --- a/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/listener/TaskExecutorLifecycleEventListener.java +++ b/dolphinscheduler-task-executor/src/main/java/org/apache/dolphinscheduler/task/executor/listener/TaskExecutorLifecycleEventListener.java @@ -32,6 +32,7 @@ import org.apache.dolphinscheduler.task.executor.events.TaskExecutorKilledLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorPauseLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorPausedLifecycleEvent; +import org.apache.dolphinscheduler.task.executor.events.TaskExecutorResultAlertLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorRuntimeContextChangedLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorStartedLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorSuccessLifecycleEvent; @@ -114,6 +115,11 @@ public void onTaskExecutorFinalizeLifecycleEvent(final TaskExecutorFinalizeLifec executorContainer.finalize(taskExecutor); } + @Override + public void onTaskExecutorResultAlertLifecycleEvent(TaskExecutorResultAlertLifecycleEvent event) { + reportTaskExecutorLifecycleEventToMaster(event); + } + private void reportTaskExecutorLifecycleEventToMaster(IReportableTaskExecutorLifecycleEvent taskExecutorLifecycleEvent) { taskExecutorLifecycleEventReporter.reportTaskExecutorLifecycleEvent(taskExecutorLifecycleEvent); } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractTask.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractTask.java index 006f40aa1416..249f9e69860c 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractTask.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractTask.java @@ -19,7 +19,7 @@ import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; import org.apache.dolphinscheduler.plugin.task.api.model.Property; -import org.apache.dolphinscheduler.plugin.task.api.model.TaskAlertInfo; +import org.apache.dolphinscheduler.plugin.task.api.model.TaskResultAlertInfo; import org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters; import java.util.Map; @@ -58,7 +58,7 @@ public abstract class AbstractTask { protected boolean needAlert = false; - protected TaskAlertInfo taskAlertInfo; + protected TaskResultAlertInfo taskResultAlertInfo; /** * constructor @@ -117,12 +117,12 @@ public void setNeedAlert(boolean needAlert) { this.needAlert = needAlert; } - public TaskAlertInfo getTaskAlertInfo() { - return taskAlertInfo; + public TaskResultAlertInfo getTaskResultAlertInfo() { + return taskResultAlertInfo; } - public void setTaskAlertInfo(TaskAlertInfo taskAlertInfo) { - this.taskAlertInfo = taskAlertInfo; + public void setTaskResultAlertInfo(TaskResultAlertInfo taskResultAlertInfo) { + this.taskResultAlertInfo = taskResultAlertInfo; } /** diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/TaskCallBack.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/TaskCallBack.java index 010e328c35d9..f3a5095243d3 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/TaskCallBack.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/TaskCallBack.java @@ -18,6 +18,7 @@ package org.apache.dolphinscheduler.plugin.task.api; import org.apache.dolphinscheduler.plugin.task.api.model.ApplicationInfo; +import org.apache.dolphinscheduler.plugin.task.api.model.TaskResultAlertInfo; public interface TaskCallBack { @@ -26,4 +27,6 @@ public interface TaskCallBack { // todo:The pid should put into runtime context @Deprecated void updateTaskInstanceInfo(int taskInstanceId); + + void reportTaskResultAlertInfo(TaskResultAlertInfo taskResultAlertInfo); } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/model/TaskAlertInfo.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/model/TaskResultAlertInfo.java similarity index 66% rename from dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/model/TaskAlertInfo.java rename to dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/model/TaskResultAlertInfo.java index dc83af276134..2e768b0cf60f 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/model/TaskAlertInfo.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/model/TaskResultAlertInfo.java @@ -17,7 +17,10 @@ package org.apache.dolphinscheduler.plugin.task.api.model; -public class TaskAlertInfo { +import lombok.Data; + +@Data +public class TaskResultAlertInfo { private String title; @@ -25,27 +28,10 @@ public class TaskAlertInfo { private Integer alertGroupId; - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getContent() { - return content; - } + private Long workflowDefinitionCode; - public void setContent(String content) { - this.content = content; - } + private Integer workflowInstanceId; - public Integer getAlertGroupId() { - return alertGroupId; - } + private int taskInstanceId; - public void setAlertGroupId(Integer alertGroupId) { - this.alertGroupId = alertGroupId; - } } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parameters/SqlParameters.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parameters/SqlParameters.java index 8864943bac43..d6ef15973152 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parameters/SqlParameters.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parameters/SqlParameters.java @@ -66,9 +66,9 @@ public class SqlParameters extends AbstractParameters { private int sqlType; /** - * send email + * send alert */ - private Boolean sendEmail; + private Boolean sendAlert; /** * display rows @@ -147,12 +147,12 @@ public void setSqlType(int sqlType) { this.sqlType = sqlType; } - public Boolean getSendEmail() { - return sendEmail; + public Boolean getSendAlert() { + return sendAlert; } - public void setSendEmail(Boolean sendEmail) { - this.sendEmail = sendEmail; + public void setSendAlert(Boolean sendAlert) { + this.sendAlert = sendAlert; } public int getDisplayRows() { @@ -273,7 +273,7 @@ public String toString() { + ", datasource=" + datasource + ", sql='" + sql + '\'' + ", sqlType=" + sqlType - + ", sendEmail=" + sendEmail + + ", sendAlert=" + sendAlert + ", displayRows=" + displayRows + ", limit=" + limit + ", showType='" + showType + '\'' diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/SqlParametersTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/SqlParametersTest.java index 8f1ee7656000..bfa8ba6416cf 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/SqlParametersTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/SqlParametersTest.java @@ -35,7 +35,7 @@ public class SqlParametersTest { private final String sql = "select * from t_ds_user"; private final int datasource = 1; private final int sqlType = 0; - private final Boolean sendEmail = true; + private final Boolean sendAlert = true; private final int displayRows = 10; private final String showType = "TABLE"; private final String title = "sql test"; @@ -58,7 +58,7 @@ public void testSqlParameters() { sqlParameters.setSql(sql); sqlParameters.setDatasource(datasource); sqlParameters.setSqlType(sqlType); - sqlParameters.setSendEmail(sendEmail); + sqlParameters.setSendAlert(sendAlert); sqlParameters.setDisplayRows(displayRows); sqlParameters.setShowType(showType); sqlParameters.setTitle(title); @@ -68,7 +68,7 @@ public void testSqlParameters() { Assertions.assertEquals(sql, sqlParameters.getSql()); Assertions.assertEquals(datasource, sqlParameters.getDatasource()); Assertions.assertEquals(sqlType, sqlParameters.getSqlType()); - Assertions.assertEquals(sendEmail, sqlParameters.getSendEmail()); + Assertions.assertEquals(sendAlert, sqlParameters.getSendAlert()); Assertions.assertEquals(displayRows, sqlParameters.getDisplayRows()); Assertions.assertEquals(showType, sqlParameters.getShowType()); Assertions.assertEquals(title, sqlParameters.getTitle()); diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/test/java/org/apache/dolphinscheduler/plugin/task/datax/DataxTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/test/java/org/apache/dolphinscheduler/plugin/task/datax/DataxTaskTest.java index 3b1dd82c9283..48264c076ae4 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/test/java/org/apache/dolphinscheduler/plugin/task/datax/DataxTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/test/java/org/apache/dolphinscheduler/plugin/task/datax/DataxTaskTest.java @@ -37,6 +37,7 @@ import org.apache.dolphinscheduler.plugin.task.api.model.ApplicationInfo; import org.apache.dolphinscheduler.plugin.task.api.model.Property; import org.apache.dolphinscheduler.plugin.task.api.model.TaskResponse; +import org.apache.dolphinscheduler.plugin.task.api.model.TaskResultAlertInfo; import org.apache.dolphinscheduler.plugin.task.api.parameters.resource.ResourceParametersHelper; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; @@ -78,6 +79,11 @@ public void updateRemoteApplicationInfo(int taskInstanceId, ApplicationInfo appl public void updateTaskInstanceInfo(int taskInstanceId) { } + + @Override + public void reportTaskResultAlertInfo(TaskResultAlertInfo taskResultAlertInfo) { + + } }; @BeforeEach diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrAddStepsTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrAddStepsTaskTest.java index b1fab4d436d1..a24f5b97e790 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrAddStepsTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrAddStepsTaskTest.java @@ -27,6 +27,7 @@ import org.apache.dolphinscheduler.plugin.task.api.TaskException; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; import org.apache.dolphinscheduler.plugin.task.api.model.ApplicationInfo; +import org.apache.dolphinscheduler.plugin.task.api.model.TaskResultAlertInfo; import org.apache.commons.io.IOUtils; @@ -86,6 +87,11 @@ public void updateRemoteApplicationInfo(int taskInstanceId, ApplicationInfo appl public void updateTaskInstanceInfo(int taskInstanceId) { } + + @Override + public void reportTaskResultAlertInfo(TaskResultAlertInfo taskResultAlertInfo) { + + } }; @BeforeEach diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrJobFlowTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrJobFlowTaskTest.java index fc50f7ed97b8..2a9a920fea7b 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrJobFlowTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrJobFlowTaskTest.java @@ -27,6 +27,7 @@ import org.apache.dolphinscheduler.plugin.task.api.TaskException; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; import org.apache.dolphinscheduler.plugin.task.api.model.ApplicationInfo; +import org.apache.dolphinscheduler.plugin.task.api.model.TaskResultAlertInfo; import org.apache.commons.io.IOUtils; @@ -108,6 +109,11 @@ public void updateRemoteApplicationInfo(int taskInstanceId, ApplicationInfo appl public void updateTaskInstanceInfo(int taskInstanceId) { } + + @Override + public void reportTaskResultAlertInfo(TaskResultAlertInfo taskResultAlertInfo) { + + } }; @BeforeEach diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java index 44296bc3313b..c58695c63710 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java @@ -32,7 +32,7 @@ import org.apache.dolphinscheduler.plugin.task.api.enums.SqlType; import org.apache.dolphinscheduler.plugin.task.api.enums.TaskTimeoutStrategy; import org.apache.dolphinscheduler.plugin.task.api.model.Property; -import org.apache.dolphinscheduler.plugin.task.api.model.TaskAlertInfo; +import org.apache.dolphinscheduler.plugin.task.api.model.TaskResultAlertInfo; import org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters; import org.apache.dolphinscheduler.plugin.task.api.parameters.SqlParameters; import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils; @@ -156,6 +156,11 @@ public void handle(TaskCallBack taskCallBack) throws TaskException { setExitStatusCode(TaskConstants.EXIT_CODE_SUCCESS); + if (this.getNeedAlert()) { + // callback to report taskResult alert + taskCallBack.reportTaskResultAlertInfo(this.getTaskResultAlertInfo()); + } + } catch (Exception e) { if (exitStatusCode == TaskConstants.EXIT_CODE_KILL) { log.info("sql task has been killed"); @@ -282,8 +287,8 @@ private String resultProcess(ResultSet resultSet) throws Exception { String result = resultJSONArray.isEmpty() ? JSONUtils.toJsonString(generateEmptyRow(resultSet)) : JSONUtils.toJsonString(resultJSONArray); - if (Boolean.TRUE.equals(sqlParameters.getSendEmail())) { - sendAttachment(sqlParameters.getGroupId(), StringUtils.isNotEmpty(sqlParameters.getTitle()) + if (Boolean.TRUE.equals(sqlParameters.getSendAlert())) { + sendTaskResultAlert(sqlParameters.getGroupId(), StringUtils.isNotEmpty(sqlParameters.getTitle()) ? sqlParameters.getTitle() : taskExecutionContext.getTaskName() + " query result sets", result); } @@ -312,18 +317,21 @@ private ArrayNode generateEmptyRow(ResultSet resultSet) throws SQLException { } /** - * send alert as an attachment + * send alert * * @param title title * @param content content */ - private void sendAttachment(int groupId, String title, String content) { + private void sendTaskResultAlert(int groupId, String title, String content) { setNeedAlert(Boolean.TRUE); - TaskAlertInfo taskAlertInfo = new TaskAlertInfo(); + TaskResultAlertInfo taskAlertInfo = new TaskResultAlertInfo(); taskAlertInfo.setAlertGroupId(groupId); taskAlertInfo.setContent(content); taskAlertInfo.setTitle(title); - setTaskAlertInfo(taskAlertInfo); + taskAlertInfo.setWorkflowDefinitionCode(this.taskExecutionContext.getWorkflowDefinitionCode()); + taskAlertInfo.setWorkflowInstanceId(this.taskExecutionContext.getWorkflowInstanceId()); + taskAlertInfo.setTaskInstanceId(this.taskExecutionContext.getTaskInstanceId()); + setTaskResultAlertInfo(taskAlertInfo); } private String executeQuery(Connection connection, SqlBinds sqlBinds, String handlerType) throws Exception { diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/test/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/test/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTaskTest.java index ffaf85b207b0..55ae6baf93e3 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/test/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/test/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTaskTest.java @@ -34,6 +34,7 @@ import org.apache.dolphinscheduler.plugin.task.api.TaskException; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; import org.apache.dolphinscheduler.plugin.task.api.model.ApplicationInfo; +import org.apache.dolphinscheduler.plugin.task.api.model.TaskResultAlertInfo; import org.apache.dolphinscheduler.plugin.task.api.parameters.resource.ResourceParametersHelper; import org.apache.zeppelin.client.NoteResult; @@ -82,6 +83,11 @@ public void updateRemoteApplicationInfo(int taskInstanceId, ApplicationInfo appl public void updateTaskInstanceInfo(int taskInstanceId) { } + + @Override + public void reportTaskResultAlertInfo(TaskResultAlertInfo taskResultAlertInfo) { + + } }; @BeforeEach diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-sql-type.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-sql-type.ts index d30ef9ef3221..b9ac314ff3d4 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-sql-type.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-sql-type.ts @@ -24,8 +24,8 @@ import type { IJsonItem } from '../types' export function useSqlType(model: { [field: string]: any }): IJsonItem[] { const { t } = useI18n() const querySpan = computed(() => (model.sqlType === '0' ? 6 : 0)) - const emailSpan = computed(() => - model.sqlType === '0' && model.sendEmail ? 24 : 0 + const alertSpan = computed(() => + model.sqlType === '0' && model.sendAlert ? 24 : 0 ) const groups = ref([]) const groupsLoading = ref(false) @@ -69,7 +69,7 @@ export function useSqlType(model: { [field: string]: any }): IJsonItem[] { }, { type: 'switch', - field: 'sendEmail', + field: 'sendAlert', span: querySpan, name: t('project.node.send_alarm') }, @@ -109,12 +109,12 @@ export function useSqlType(model: { [field: string]: any }): IJsonItem[] { props: { placeholder: t('project.node.title_tips') }, - span: emailSpan, + span: alertSpan, validate: { trigger: ['input', 'blur'], required: true, validator(unuse, value) { - if (model.sendEmail && !value) + if (model.sendAlert && !value) return new Error(t('project.node.title_tips')) } } @@ -124,7 +124,7 @@ export function useSqlType(model: { [field: string]: any }): IJsonItem[] { field: 'groupId', name: t('project.node.alarm_group'), options: groups, - span: emailSpan, + span: alertSpan, props: { loading: groupsLoading, placeholder: t('project.node.alarm_group_tips') @@ -133,7 +133,7 @@ export function useSqlType(model: { [field: string]: any }): IJsonItem[] { trigger: ['input', 'blur'], required: true, validator(unuse, value) { - if (model.sendEmail && !value) + if (model.sendAlert && !value) return new Error(t('project.node.alarm_group_tips')) } } diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/format-data.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/format-data.ts index 8fc67906775c..cd7fec72a85b 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/format-data.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/format-data.ts @@ -208,9 +208,9 @@ export function formatParams(data: INodeData): { taskParams.sqlType = data.sqlType taskParams.preStatements = data.preStatements taskParams.postStatements = data.postStatements - taskParams.sendEmail = data.sendEmail + taskParams.sendAlert = data.sendAlert taskParams.displayRows = data.displayRows - if (data.sqlType === '0' && data.sendEmail) { + if (data.sqlType === '0' && data.sendAlert) { taskParams.title = data.title taskParams.groupId = data.groupId } diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/types.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/types.ts index 76dcde23ee2d..570073cebe35 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/types.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/types.ts @@ -305,7 +305,7 @@ interface ITaskParams { datasource?: string sql?: string sqlType?: string - sendEmail?: boolean + sendAlert?: boolean displayRows?: number title?: string groupId?: string diff --git a/dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/executor/PhysicalTaskExecutor.java b/dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/executor/PhysicalTaskExecutor.java index 7118a099d5f9..f25c63a75e2b 100644 --- a/dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/executor/PhysicalTaskExecutor.java +++ b/dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/executor/PhysicalTaskExecutor.java @@ -25,6 +25,7 @@ import org.apache.dolphinscheduler.plugin.task.api.TaskCallBack; import org.apache.dolphinscheduler.plugin.task.api.log.TaskLogMarkers; import org.apache.dolphinscheduler.plugin.task.api.model.ApplicationInfo; +import org.apache.dolphinscheduler.plugin.task.api.model.TaskResultAlertInfo; import org.apache.dolphinscheduler.plugin.task.api.resource.ResourceContext; import org.apache.dolphinscheduler.server.worker.config.WorkerConfig; import org.apache.dolphinscheduler.server.worker.utils.TaskExecutionContextUtils; @@ -33,6 +34,7 @@ import org.apache.dolphinscheduler.task.executor.ITaskExecutor; import org.apache.dolphinscheduler.task.executor.TaskExecutorState; import org.apache.dolphinscheduler.task.executor.TaskExecutorStateMappings; +import org.apache.dolphinscheduler.task.executor.events.TaskExecutorResultAlertLifecycleEvent; import org.apache.dolphinscheduler.task.executor.events.TaskExecutorRuntimeContextChangedLifecycleEvent; import java.util.ArrayList; @@ -86,6 +88,12 @@ public void updateRemoteApplicationInfo(final int taskInstanceId, final Applicat public void updateTaskInstanceInfo(final int taskInstanceId) { taskExecutorEventBus.publish(TaskExecutorRuntimeContextChangedLifecycleEvent.of(taskExecutor)); } + + @Override + public void reportTaskResultAlertInfo(TaskResultAlertInfo taskResultAlertInfo) { + taskExecutorEventBus + .publish(TaskExecutorResultAlertLifecycleEvent.of(taskExecutor, taskResultAlertInfo)); + } }); }