Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> taskParamsMap = definition.getTaskParamMap();
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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");
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<String, Object> 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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public enum TaskExecutorLifecycleEventType {

FAILED,

RESULT_ALERT,

FINALIZE,
;

Expand Down
Loading