Browse Source

Remove unused closeAlert (#16877)

dev
Wenjun Ruan 3 weeks ago committed by GitHub
parent
commit
271fa23faf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertChannel.java
  2. 14
      dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/service/AbstractEventSender.java
  3. 143
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/Constants.java
  4. 3
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/AlertType.java
  5. 44
      dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/ConstantsTest.java
  6. 30
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/WorkflowAlertManager.java

5
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertChannel.java

@ -17,8 +17,6 @@
package org.apache.dolphinscheduler.alert.api;
import lombok.NonNull;
/**
* alert channel for sending alerts
*/
@ -32,7 +30,4 @@ public interface AlertChannel {
*/
AlertResult process(AlertInfo info);
default @NonNull AlertResult closeAlert(AlertInfo info) {
return new AlertResult(true, "no need to close alert");
}
}

14
dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/service/AbstractEventSender.java

@ -26,7 +26,6 @@ import org.apache.dolphinscheduler.alert.api.AlertInfo;
import org.apache.dolphinscheduler.alert.api.AlertResult;
import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager;
import org.apache.dolphinscheduler.common.enums.AlertStatus;
import org.apache.dolphinscheduler.common.enums.AlertType;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
import org.apache.dolphinscheduler.dao.entity.AlertSendStatus;
@ -128,19 +127,10 @@ public abstract class AbstractEventSender<T> implements EventSender<T> {
try {
AlertResult alertResult;
if (sendEventTimeout <= 0) {
if (alertData.getAlertType() == AlertType.CLOSE_ALERT.getCode()) {
alertResult = alertChannel.closeAlert(alertInfo);
} else {
alertResult = alertChannel.process(alertInfo);
}
} else {
CompletableFuture<AlertResult> future;
if (alertData.getAlertType() == AlertType.CLOSE_ALERT.getCode()) {
future = CompletableFuture.supplyAsync(() -> alertChannel.closeAlert(alertInfo));
} else {
future = CompletableFuture.supplyAsync(() -> alertChannel.process(alertInfo));
}
alertResult = future.get(sendEventTimeout, TimeUnit.MILLISECONDS);
alertResult = CompletableFuture.supplyAsync(() -> alertChannel.process(alertInfo)).get(sendEventTimeout,
TimeUnit.MILLISECONDS);
}
checkNotNull(alertResult, "AlertResult cannot be null");
return alertResult;

143
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/Constants.java

@ -17,8 +17,6 @@
package org.apache.dolphinscheduler.common.constants;
import org.apache.commons.lang3.SystemUtils;
import java.time.Duration;
import java.util.regex.Pattern;
@ -27,8 +25,6 @@ import lombok.experimental.UtilityClass;
@UtilityClass
public final class Constants {
public static final String AUTO_CLOSE_ALERT = "alert.auto-close";
/**
* common properties path
*/
@ -38,7 +34,6 @@ public final class Constants {
public static final String AWS_YAML_PATH = "/aws.yaml";
public static final String RESOURCE_CENTER_YAML_PATH = "/resource-center.yaml";
public static final String FORMAT_SS = "%s%s";
public static final String FORMAT_S_S = "%s/%s";
public static final String FORMAT_S_S_COLON = "%s:%s";
public static final String FOLDER_SEPARATOR = "/";
@ -50,17 +45,6 @@ public final class Constants {
*/
public static final String FS_DEFAULT_FS = "resource.hdfs.fs.defaultFS";
/**
* hdfs defaultFS property name. Should be consistent with the property name in hdfs-site.xml
*/
public static final String HDFS_DEFAULT_FS = "fs.defaultFS";
/**
* hdfs configuration
* resource.hdfs.root.user
*/
public static final String HDFS_ROOT_USER = "resource.hdfs.root.user";
/**
* hdfs/s3 configuration
* resource.storage.upload.base.path
@ -72,16 +56,6 @@ public final class Constants {
*/
public static final String DATA_BASEDIR_PATH = "data.basedir.path";
/**
* dolphinscheduler.env.path
*/
public static final String DOLPHINSCHEDULER_ENV_PATH = "dolphinscheduler.env.path";
/**
* environment properties default path
*/
public static final String ENV_PATH = "dolphinscheduler_env.sh";
/**
* resource.view.suffixs
*/
@ -107,28 +81,6 @@ public final class Constants {
public static final String AWS_S3_BUCKET_NAME = "aws.s3.bucket.name";
public static final String ALIBABA_CLOUD_OSS_BUCKET_NAME = "resource.alibaba.cloud.oss.bucket.name";
public static final String ALIBABA_CLOUD_OSS_END_POINT = "resource.alibaba.cloud.oss.endpoint";
public static final String GOOGLE_CLOUD_STORAGE_BUCKET_NAME = "resource.google.cloud.storage.bucket.name";
public static final String GOOGLE_CLOUD_STORAGE_CREDENTIAL = "resource.google.cloud.storage.credential";
public static final String AZURE_BLOB_STORAGE_CONNECTION_STRING = "resource.azure.blob.storage.connection.string";
public static final String AZURE_BLOB_STORAGE_CONTAINER_NAME = "resource.azure.blob.storage.container.name";
public static final String AZURE_BLOB_STORAGE_ACCOUNT_NAME = "resource.azure.blob.storage.account.name";
public static final String HUAWEI_CLOUD_OBS_BUCKET_NAME = "resource.huawei.cloud.obs.bucket.name";
public static final String HUAWEI_CLOUD_OBS_END_POINT = "resource.huawei.cloud.obs.endpoint";
/**
* fetch applicationId way
*/
public static final String APPID_COLLECT = "appId.collect";
public static final String DEFAULT_COLLECT_WAY = "log";
/**
* comma ,
*/
@ -139,16 +91,6 @@ public final class Constants {
*/
public static final String COLON = ":";
/**
* period .
*/
public static final String PERIOD = ".";
/**
* QUESTION ?
*/
public static final String QUESTION = "?";
/**
* SPACE " "
*/
@ -253,11 +195,6 @@ public final class Constants {
*/
public static final int ALL_PERMISSIONS = READ_PERMISSION | WRITE_PERMISSION | EXECUTE_PERMISSION;
/**
* max task timeout
*/
public static final int MAX_TASK_TIMEOUT = 24 * 3600;
/**
* forbid running task
*/
@ -289,11 +226,6 @@ public final class Constants {
*/
public static final long SLEEP_TIME_MILLIS = 1_000L;
/**
* short sleep 100ms
*/
public static final long SLEEP_TIME_MILLIS_SHORT = 100L;
public static final Duration SERVER_CLOSE_WAIT_TIME = Duration.ofSeconds(3);
/**
@ -346,24 +278,16 @@ public final class Constants {
*/
public static final String UNDERLINE = "_";
public static final String PID = SystemUtils.IS_OS_WINDOWS ? "handle" : "pid";
public static final String STAR = "*";
public static final char N = 'N';
public static final String GLOBAL_PARAMS = "globalParams";
public static final String LOCAL_PARAMS = "localParams";
public static final String SUBWORKFLOW_INSTANCE_ID = "subWorkflowInstanceId";
public static final String WORKFLOW_INSTANCE_STATE = "workflowInstanceState";
public static final String PARENT_WORKFLOW_INSTANCE = "parentWorkflowInstance";
public static final String CONDITION_RESULT = "conditionResult";
public static final String SWITCH_RESULT = "switchResult";
public static final String WAIT_START_TIMEOUT = "waitStartTimeout";
public static final String DEPENDENCE = "dependence";
public static final String TASK_LIST = "taskList";
public static final String QUEUE = "queue";
public static final String QUEUE_NAME = "queueName";
public static final int LOG_QUERY_SKIP_LINE_NUMBER = 0;
public static final int LOG_QUERY_LIMIT = 4096;
public static final String DEPENDENT_SPLIT = ":||";
public static final long DEPENDENT_ALL_TASK_CODE = -1;
public static final long DEPENDENT_WORKFLOW_CODE = 0;
@ -378,11 +302,6 @@ public final class Constants {
*/
public static final String KERBEROS = "kerberos";
/**
* kerberos expire time
*/
public static final String KERBEROS_EXPIRE_TIME = "kerberos.expire.time";
/**
* java.security.krb5.conf
*/
@ -419,29 +338,8 @@ public final class Constants {
*/
public static final String SSO_LOGIN_USER_STATE = "sso.login.user.state";
public static final String WORKFLOW_INSTANCE_ID_MDC_KEY = "workflowInstanceId";
public static final String TASK_INSTANCE_ID_MDC_KEY = "taskInstanceId";
/**
* double brackets left
*/
public static final String DOUBLE_BRACKETS_LEFT = "{{";
/**
* double brackets left
*/
public static final String DOUBLE_BRACKETS_RIGHT = "}}";
/**
* double brackets left
*/
public static final String DOUBLE_BRACKETS_LEFT_SPACE = "{ {";
/**
* double brackets left
*/
public static final String DOUBLE_BRACKETS_RIGHT_SPACE = "} }";
/**
* status
*/
@ -452,11 +350,6 @@ public final class Constants {
*/
public static final String MSG = "msg";
/**
* data total
*/
public static final String COUNT = "count";
/**
* page size
*/
@ -501,8 +394,6 @@ public final class Constants {
*/
public static final int SESSION_TIME_OUT = 7200;
public static final int MAX_FILE_SIZE = 1024 * 1024 * 1024;
public static final String CLASS = "class";
/**
@ -524,17 +415,6 @@ public final class Constants {
*/
public static final String SH = "sh";
/**
* pstree, get pud and sub pid
*/
public static final String PSTREE = "pstree";
/**
* dry run flag
*/
public static final int DRY_RUN_FLAG_NO = 0;
public static final int DRY_RUN_FLAG_YES = 1;
/**
* use for k8s
*/
@ -546,18 +426,12 @@ public final class Constants {
* schedule timezone
*/
public static final String SCHEDULE_TIMEZONE = "schedule_timezone";
public static final int RESOURCE_FULL_NAME_MAX_LENGTH = 128;
/**
* tenant
*/
public static final int TENANT_FULL_NAME_MAX_LENGTH = 30;
/**
* schedule time the amount of date data is too large, affecting the memory, so set 100
*/
public static final int SCHEDULE_TIME_MAX_LENGTH = 100;
/**
* password max and min LENGTH
*/
@ -578,12 +452,6 @@ public final class Constants {
public static final String SECURITY_CONFIG_TYPE_LDAP = "LDAP";
/**
* test flag
*/
public static final int TEST_FLAG_NO = 0;
public static final int TEST_FLAG_YES = 1;
/**
* Task Types
*/
@ -625,15 +493,6 @@ public final class Constants {
/** string no */
public static final String STRING_NO = "NO";
public static final String SMALL = "small";
public static final String CHANGE = "change";
/**
* support hive datasource in one session
*/
public static final String SUPPORT_HIVE_ONE_SESSION = "support.hive.oneSession";
public static final Integer QUERY_ALL_ON_SYSTEM = 0;
public static final Integer QUERY_ALL_ON_PROJECT = 1;
public static final Integer QUERY_ALL_ON_WORKFLOW = 2;
@ -658,8 +517,6 @@ public final class Constants {
public static final String REMOTE_LOGGING_OSS_ENDPOINT = "remote.logging.oss.endpoint";
public static final String REMOTE_LOGGING_S3_BUCKET_NAME = "remote.logging.s3.bucket.name";
/**
* remote logging for GCS
*/

3
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/AlertType.java

@ -39,8 +39,7 @@ public enum AlertType {
TASK_FAILURE(5, "task failure"),
TASK_SUCCESS(6, "task success"),
TASK_TIMEOUT(7, "task timeout"),
CLOSE_ALERT(8, "the workflow instance success, can close the before alert");
;
AlertType(int code, String descp) {
this.code = code;

44
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/ConstantsTest.java

@ -1,44 +0,0 @@
/*
* 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.common;
import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.commons.lang3.SystemUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* Constants Test
*/
public class ConstantsTest {
/**
* Test PID via env
*/
@Test
public void testPID() {
if (SystemUtils.IS_OS_WINDOWS) {
Assertions.assertEquals(Constants.PID, "handle");
} else {
Assertions.assertEquals(Constants.PID, "pid");
}
}
}

30
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/WorkflowAlertManager.java

@ -17,13 +17,11 @@
package org.apache.dolphinscheduler.service.alert;
import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.common.enums.AlertType;
import org.apache.dolphinscheduler.common.enums.CommandType;
import org.apache.dolphinscheduler.common.enums.Flag;
import org.apache.dolphinscheduler.common.enums.WarningType;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.common.utils.PropertyUtils;
import org.apache.dolphinscheduler.dao.AlertDao;
import org.apache.dolphinscheduler.dao.entity.Alert;
import org.apache.dolphinscheduler.dao.entity.ProjectUser;
@ -35,8 +33,6 @@ import org.apache.dolphinscheduler.dao.entity.WorkflowInstance;
import org.apache.dolphinscheduler.dao.mapper.UserMapper;
import org.apache.dolphinscheduler.dao.mapper.WorkflowDefinitionLogMapper;
import org.apache.commons.collections4.CollectionUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -294,32 +290,6 @@ public class WorkflowAlertManager {
return sendWarning;
}
/**
* Send a close alert event, if the workflowInstance has sent alert before, then will insert a closed event.
*
* @param workflowInstance success workflow instance
*/
public void closeAlert(WorkflowInstance workflowInstance) {
if (!PropertyUtils.getBoolean(Constants.AUTO_CLOSE_ALERT, false)) {
return;
}
List<Alert> alerts = alertDao.listAlerts(workflowInstance.getId());
if (CollectionUtils.isEmpty(alerts)) {
// no need to close alert
return;
}
Alert alert = new Alert();
alert.setAlertGroupId(workflowInstance.getWarningGroupId());
alert.setUpdateTime(new Date());
alert.setCreateTime(new Date());
alert.setProjectCode(workflowInstance.getWorkflowDefinition().getProjectCode());
alert.setWorkflowDefinitionCode(workflowInstance.getWorkflowDefinitionCode());
alert.setWorkflowInstanceId(workflowInstance.getId());
alert.setAlertType(AlertType.CLOSE_ALERT);
alertDao.addAlert(alert);
}
public void sendTaskTimeoutAlert(WorkflowInstance workflowInstance,
TaskInstance taskInstance,
ProjectUser projectUser) {

Loading…
Cancel
Save