Browse Source

[DSIP-57][Audit] Revert PR 14981 code (#16370)

dev
xiangzihao 4 months ago committed by GitHub
parent
commit
d9244ca22f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 19
      dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/plugin/AlertPluginManager.java
  2. 15
      dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/service/AlertBootstrapService.java
  3. 51
      dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/service/ListenerEventFetcher.java
  4. 40
      dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/service/ListenerEventLoop.java
  5. 32
      dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/service/ListenerEventPendingQueue.java
  6. 146
      dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/service/ListenerEventSender.java
  7. 143
      dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/runner/ListenerEventSenderTest.java
  8. 16
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java
  9. 9
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java
  10. 8
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java
  11. 5
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceService.java
  12. 18
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java
  13. 55
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertPluginInstanceServiceImpl.java
  14. 15
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
  15. 46
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertGroupControllerTest.java
  16. 4
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceControllerTest.java
  17. 56
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java
  18. 57
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java
  19. 4
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java
  20. 3
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/WarningType.java
  21. 2
      dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/CodeGenerateUtilsTest.java
  22. 2
      dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HttpUtilsTest.java
  23. 18
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/AlertPluginInstance.java
  24. 7
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapper.java
  25. 43
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ListenerEventMapper.java
  26. 31
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ListenerEventDao.java
  27. 51
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/impl/ListenerEventDaoImpl.java
  28. 10
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapper.xml
  29. 67
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ListenerEventMapper.xml
  30. 31
      dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql
  31. 22
      dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql
  32. 25
      dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql
  33. 23
      dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.1_schema/mysql/dolphinscheduler_ddl.sql
  34. 3
      dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.1_schema/mysql/dolphinscheduler_dml.sql
  35. 12
      dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.1_schema/postgresql/dolphinscheduler_ddl.sql
  36. 2
      dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.1_schema/postgresql/dolphinscheduler_dml.sql
  37. 42
      dolphinscheduler-dao/src/main/resources/sql/upgrade/3.3.0_schema/mysql/dolphinscheduler_ddl.sql
  38. 43
      dolphinscheduler-dao/src/main/resources/sql/upgrade/3.3.0_schema/postgresql/dolphinscheduler_ddl.sql
  39. 26
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapperTest.java
  40. 136
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ListenerEventMapperTest.java
  41. 79
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/repository/impl/ListenerEventDaoImplTest.java
  42. 6
      dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/ClusterStateMonitors.java
  43. 4
      dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/event/TaskStateEventHandler.java
  44. 26
      dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkflowExecuteRunnable.java
  45. 5
      dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkflowExecuteRunnableFactory.java
  46. 5
      dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/runner/WorkflowExecuteRunnableTest.java
  47. 283
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/ListenerEventAlertManager.java
  48. 150
      dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/ListenerEventAlertManagerTest.java
  49. 2
      dolphinscheduler-ui/src/locales/en_US/security.ts
  50. 2
      dolphinscheduler-ui/src/locales/zh_CN/security.ts
  51. 7
      dolphinscheduler-ui/src/service/modules/alert-group/index.ts
  52. 3
      dolphinscheduler-ui/src/service/modules/alert-plugin/types.ts
  53. 4
      dolphinscheduler-ui/src/views/projects/preference/components/use-alert-group.ts
  54. 4
      dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-sql-type.ts
  55. 4
      dolphinscheduler-ui/src/views/projects/task/definition/components/use-start.tsx
  56. 4
      dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag-startup-param.tsx
  57. 4
      dolphinscheduler-ui/src/views/projects/workflow/definition/components/use-modal.ts
  58. 16
      dolphinscheduler-ui/src/views/security/alarm-group-manage/components/alarm-group-modal.tsx
  59. 45
      dolphinscheduler-ui/src/views/security/alarm-instance-manage/detail.tsx
  60. 2
      dolphinscheduler-ui/src/views/security/alarm-instance-manage/types.ts
  61. 4
      dolphinscheduler-ui/src/views/security/alarm-instance-manage/use-columns.ts
  62. 3
      dolphinscheduler-ui/src/views/security/alarm-instance-manage/use-detail.ts
  63. 8
      dolphinscheduler-ui/src/views/security/alarm-instance-manage/use-form.ts

19
dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/plugin/AlertPluginManager.java

@ -19,11 +19,16 @@ package org.apache.dolphinscheduler.alert.plugin;
import org.apache.dolphinscheduler.alert.api.AlertChannel;
import org.apache.dolphinscheduler.alert.api.AlertChannelFactory;
import org.apache.dolphinscheduler.alert.api.AlertConstants;
import org.apache.dolphinscheduler.common.enums.PluginType;
import org.apache.dolphinscheduler.common.enums.WarningType;
import org.apache.dolphinscheduler.dao.PluginDao;
import org.apache.dolphinscheduler.dao.entity.PluginDefine;
import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer;
import org.apache.dolphinscheduler.spi.params.base.ParamsOptions;
import org.apache.dolphinscheduler.spi.params.base.PluginParams;
import org.apache.dolphinscheduler.spi.params.base.Validate;
import org.apache.dolphinscheduler.spi.params.radio.RadioParam;
import org.apache.dolphinscheduler.spi.plugin.PrioritySPIFactory;
import java.util.ArrayList;
@ -71,6 +76,8 @@ public final class AlertPluginManager {
}
private void installAlertPlugin() {
final PluginParams warningTypeParams = getWarningTypeParams();
PrioritySPIFactory<AlertChannelFactory> prioritySPIFactory =
new PrioritySPIFactory<>(AlertChannelFactory.class);
for (Map.Entry<String, AlertChannelFactory> entry : prioritySPIFactory.getSPIMap().entrySet()) {
@ -86,6 +93,7 @@ public final class AlertPluginManager {
final List<PluginParams> params = new ArrayList<>(factory.params());
final String paramsJson = PluginParamsTransfer.transferParamsToJson(params);
params.add(0, warningTypeParams);
final PluginDefine pluginDefine = new PluginDefine(name, PluginType.ALERT.getDesc(), paramsJson);
final int id = pluginDao.addOrUpdatePluginDefine(pluginDefine);
@ -94,4 +102,15 @@ public final class AlertPluginManager {
}
}
private PluginParams getWarningTypeParams() {
return RadioParam.newBuilder(AlertConstants.NAME_WARNING_TYPE, AlertConstants.WARNING_TYPE)
.addParamsOptions(
new ParamsOptions(WarningType.SUCCESS.getDescp(), WarningType.SUCCESS.getDescp(), false))
.addParamsOptions(
new ParamsOptions(WarningType.FAILURE.getDescp(), WarningType.FAILURE.getDescp(), false))
.addParamsOptions(new ParamsOptions(WarningType.ALL.getDescp(), WarningType.ALL.getDescp(), false))
.setValue(WarningType.ALL.getDescp())
.addValidate(Validate.newBuilder().setRequired(true).build())
.build();
}
}

15
dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/service/AlertBootstrapService.java

@ -44,26 +44,18 @@ public final class AlertBootstrapService implements AutoCloseable {
private final AlertEventLoop alertEventLoop;
private final ListenerEventLoop listenerEventLoop;
private final ListenerEventFetcher listenerEventFetcher;
public AlertBootstrapService(AlertRpcServer alertRpcServer,
AlertRegistryClient alertRegistryClient,
AlertPluginManager alertPluginManager,
AlertHAServer alertHAServer,
AlertEventFetcher alertEventFetcher,
AlertEventLoop alertEventLoop,
ListenerEventLoop listenerEventLoop,
ListenerEventFetcher listenerEventFetcher) {
AlertEventLoop alertEventLoop) {
this.alertRpcServer = alertRpcServer;
this.alertRegistryClient = alertRegistryClient;
this.alertPluginManager = alertPluginManager;
this.alertHAServer = alertHAServer;
this.alertEventFetcher = alertEventFetcher;
this.alertEventLoop = alertEventLoop;
this.listenerEventLoop = listenerEventLoop;
this.listenerEventFetcher = listenerEventFetcher;
}
public void start() {
@ -73,10 +65,7 @@ public final class AlertBootstrapService implements AutoCloseable {
alertRegistryClient.start();
alertHAServer.start();
listenerEventFetcher.start();
alertEventFetcher.start();
listenerEventLoop.start();
alertEventLoop.start();
log.info("AlertBootstrapService started...");
}
@ -88,10 +77,8 @@ public final class AlertBootstrapService implements AutoCloseable {
AlertRpcServer closedAlertRpcServer = alertRpcServer;
AlertRegistryClient closedAlertRegistryClient = alertRegistryClient) {
// close resource
listenerEventFetcher.shutdown();
alertEventFetcher.shutdown();
listenerEventLoop.shutdown();
alertEventLoop.shutdown();
alertHAServer.shutdown();
}

51
dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/service/ListenerEventFetcher.java

@ -1,51 +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.alert.service;
import org.apache.dolphinscheduler.dao.entity.ListenerEvent;
import org.apache.dolphinscheduler.dao.repository.ListenerEventDao;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class ListenerEventFetcher extends AbstractEventFetcher<ListenerEvent> {
private final ListenerEventDao listenerEventDao;
protected ListenerEventFetcher(AlertHAServer alertHAServer,
ListenerEventDao listenerEventDao,
ListenerEventPendingQueue listenerEventPendingQueue) {
super("ListenerEventFetcher", alertHAServer, listenerEventPendingQueue);
this.listenerEventDao = listenerEventDao;
}
@Override
protected int getEventOffset(ListenerEvent event) {
return event.getId();
}
@Override
public List<ListenerEvent> fetchPendingEvent(int eventOffset) {
return listenerEventDao.listingPendingEvents(eventOffset, FETCH_SIZE);
}
}

40
dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/service/ListenerEventLoop.java

@ -1,40 +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.alert.service;
import org.apache.dolphinscheduler.dao.entity.ListenerEvent;
import org.springframework.stereotype.Component;
@Component
public class ListenerEventLoop extends AbstractEventLoop<ListenerEvent> {
private final ListenerEventSender listenerEventSender;
protected ListenerEventLoop(AlertSenderThreadPoolFactory alertSenderThreadPoolFactory,
ListenerEventSender listenerEventSender,
ListenerEventPendingQueue listenerEventPendingQueue) {
super("ListenerEventLoop", alertSenderThreadPoolFactory.getThreadPool(), listenerEventPendingQueue);
this.listenerEventSender = listenerEventSender;
}
@Override
public void handleEvent(ListenerEvent event) {
listenerEventSender.sendEvent(event);
}
}

32
dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/service/ListenerEventPendingQueue.java

@ -1,32 +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.alert.service;
import org.apache.dolphinscheduler.alert.config.AlertConfig;
import org.apache.dolphinscheduler.dao.entity.ListenerEvent;
import org.springframework.stereotype.Component;
@Component
public class ListenerEventPendingQueue extends AbstractEventPendingQueue<ListenerEvent> {
public ListenerEventPendingQueue(AlertConfig alertConfig) {
super(alertConfig.getSenderParallelism() * 3 + 1);
}
}

146
dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/service/ListenerEventSender.java

@ -1,146 +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.alert.service;
import org.apache.dolphinscheduler.alert.api.AlertData;
import org.apache.dolphinscheduler.alert.config.AlertConfig;
import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager;
import org.apache.dolphinscheduler.common.enums.AlertStatus;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
import org.apache.dolphinscheduler.dao.entity.ListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.AbstractListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.ProcessDefinitionCreatedListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.ProcessDefinitionDeletedListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.ProcessDefinitionUpdatedListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.ProcessEndListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.ProcessFailListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.ProcessStartListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.ServerDownListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.TaskEndListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.TaskFailListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.TaskStartListenerEvent;
import org.apache.dolphinscheduler.dao.mapper.AlertPluginInstanceMapper;
import org.apache.dolphinscheduler.dao.repository.ListenerEventDao;
import org.apache.curator.shaded.com.google.common.collect.Lists;
import java.util.Date;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class ListenerEventSender extends AbstractEventSender<ListenerEvent> {
private final ListenerEventDao listenerEventDao;
private final AlertPluginInstanceMapper alertPluginInstanceMapper;
public ListenerEventSender(ListenerEventDao listenerEventDao,
AlertPluginInstanceMapper alertPluginInstanceMapper,
AlertPluginManager alertPluginManager,
AlertConfig alertConfig) {
super(alertPluginManager, alertConfig.getWaitTimeout());
this.listenerEventDao = listenerEventDao;
this.alertPluginInstanceMapper = alertPluginInstanceMapper;
}
private AbstractListenerEvent generateEventFromContent(ListenerEvent listenerEvent) {
String content = listenerEvent.getContent();
AbstractListenerEvent event = null;
switch (listenerEvent.getEventType()) {
case SERVER_DOWN:
event = JSONUtils.parseObject(content, ServerDownListenerEvent.class);
break;
case PROCESS_DEFINITION_CREATED:
event = JSONUtils.parseObject(content, ProcessDefinitionCreatedListenerEvent.class);
break;
case PROCESS_DEFINITION_UPDATED:
event = JSONUtils.parseObject(content, ProcessDefinitionUpdatedListenerEvent.class);
break;
case PROCESS_DEFINITION_DELETED:
event = JSONUtils.parseObject(content, ProcessDefinitionDeletedListenerEvent.class);
break;
case PROCESS_START:
event = JSONUtils.parseObject(content, ProcessStartListenerEvent.class);
break;
case PROCESS_END:
event = JSONUtils.parseObject(content, ProcessEndListenerEvent.class);
break;
case PROCESS_FAIL:
event = JSONUtils.parseObject(content, ProcessFailListenerEvent.class);
break;
case TASK_START:
event = JSONUtils.parseObject(content, TaskStartListenerEvent.class);
break;
case TASK_END:
event = JSONUtils.parseObject(content, TaskEndListenerEvent.class);
break;
case TASK_FAIL:
event = JSONUtils.parseObject(content, TaskFailListenerEvent.class);
break;
default:
throw new IllegalArgumentException("Unsupported event type: " + listenerEvent.getEventType());
}
if (event == null) {
throw new IllegalArgumentException("Failed to parse event from content: " + content);
}
return event;
}
@Override
public List<AlertPluginInstance> getAlertPluginInstanceList(ListenerEvent event) {
return alertPluginInstanceMapper.queryAllGlobalAlertPluginInstanceList();
}
@Override
public AlertData getAlertData(ListenerEvent listenerEvent) {
AbstractListenerEvent event = generateEventFromContent(listenerEvent);
return AlertData.builder()
.id(listenerEvent.getId())
.content(JSONUtils.toJsonString(Lists.newArrayList(event)))
.log(listenerEvent.getLog())
.title(event.getTitle())
.alertType(event.getEventType().getCode())
.build();
}
@Override
public Integer getEventId(ListenerEvent event) {
return event.getId();
}
@Override
public void onError(ListenerEvent event, String log) {
listenerEventDao.updateListenerEvent(event.getId(), AlertStatus.EXECUTION_FAILURE, log, new Date());
}
@Override
public void onPartialSuccess(ListenerEvent event, String log) {
listenerEventDao.updateListenerEvent(event.getId(), AlertStatus.EXECUTION_PARTIAL_SUCCESS, log, new Date());
}
@Override
public void onSuccess(ListenerEvent event, String log) {
listenerEventDao.updateListenerEvent(event.getId(), AlertStatus.EXECUTION_FAILURE, log, new Date());
}
}

143
dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/runner/ListenerEventSenderTest.java

@ -1,143 +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.alert.runner;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.apache.dolphinscheduler.alert.api.AlertChannel;
import org.apache.dolphinscheduler.alert.api.AlertResult;
import org.apache.dolphinscheduler.alert.config.AlertConfig;
import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager;
import org.apache.dolphinscheduler.alert.service.ListenerEventSender;
import org.apache.dolphinscheduler.common.enums.AlertPluginInstanceType;
import org.apache.dolphinscheduler.common.enums.AlertStatus;
import org.apache.dolphinscheduler.common.enums.ListenerEventType;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
import org.apache.dolphinscheduler.dao.entity.ListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.ServerDownListenerEvent;
import org.apache.dolphinscheduler.dao.mapper.AlertPluginInstanceMapper;
import org.apache.dolphinscheduler.dao.repository.ListenerEventDao;
import org.apache.commons.codec.digest.DigestUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
class ListenerEventSenderTest {
@Mock
private ListenerEventDao listenerEventDao;
@Mock
private AlertPluginInstanceMapper alertPluginInstanceMapper;
@Mock
private AlertPluginManager alertPluginManager;
@Mock
private AlertConfig alertConfig;
@InjectMocks
private ListenerEventSender listenerEventSender;
@Test
void testSendServerDownEventSuccess() {
ServerDownListenerEvent serverDownListenerEvent = new ServerDownListenerEvent();
serverDownListenerEvent.setEventTime(new Date());
serverDownListenerEvent.setType("WORKER");
serverDownListenerEvent.setHost("192.168.*.*");
ListenerEvent successEvent = new ListenerEvent();
successEvent.setId(1);
successEvent.setPostStatus(AlertStatus.WAIT_EXECUTION);
successEvent.setContent(JSONUtils.toJsonString(serverDownListenerEvent));
successEvent.setSign(DigestUtils.sha256Hex(successEvent.getContent()));
successEvent.setEventType(ListenerEventType.SERVER_DOWN);
successEvent.setCreateTime(new Date());
successEvent.setUpdateTime(new Date());
int pluginDefineId = 1;
String pluginInstanceParams =
"{\"User\":\"xx\",\"receivers\":\"xx\",\"sender\":\"xx\",\"smtpSslTrust\":\"*\",\"enableSmtpAuth\":\"true\",\"receiverCcs\":null,\"showType\":\"table\",\"starttlsEnable\":\"false\",\"serverPort\":\"25\",\"serverHost\":\"xx\",\"Password\":\"xx\",\"sslEnable\":\"false\"}";
String pluginInstanceName = "alert-instance-mail";
List<AlertPluginInstance> alertInstanceList = new ArrayList<>();
AlertPluginInstance alertPluginInstance = new AlertPluginInstance(
pluginDefineId, pluginInstanceParams, pluginInstanceName);
alertPluginInstance.setInstanceType(AlertPluginInstanceType.GLOBAL);
alertPluginInstance.setId(1);
alertInstanceList.add(alertPluginInstance);
when(alertPluginInstanceMapper.queryAllGlobalAlertPluginInstanceList()).thenReturn(alertInstanceList);
AlertResult sendResult = new AlertResult();
sendResult.setSuccess(true);
sendResult.setMessage(String.format("Alert Plugin %s send success", pluginInstanceName));
AlertChannel alertChannelMock = mock(AlertChannel.class);
when(alertChannelMock.process(Mockito.any())).thenReturn(sendResult);
when(alertPluginManager.getAlertChannel(1)).thenReturn(Optional.of(alertChannelMock));
Assertions.assertTrue(sendResult.isSuccess());
listenerEventSender.sendEvent(successEvent);
}
@Test
void testSendServerDownEventFailed() {
ServerDownListenerEvent serverDownListenerEvent = new ServerDownListenerEvent();
serverDownListenerEvent.setEventTime(new Date());
serverDownListenerEvent.setType("WORKER");
serverDownListenerEvent.setHost("192.168.*.*");
ListenerEvent successEvent = new ListenerEvent();
successEvent.setId(1);
successEvent.setPostStatus(AlertStatus.WAIT_EXECUTION);
successEvent.setContent(JSONUtils.toJsonString(serverDownListenerEvent));
successEvent.setSign(DigestUtils.sha1Hex(successEvent.getContent()));
successEvent.setEventType(ListenerEventType.SERVER_DOWN);
successEvent.setCreateTime(new Date());
successEvent.setUpdateTime(new Date());
int pluginDefineId = 1;
String pluginInstanceParams =
"{\"User\":\"xx\",\"receivers\":\"xx\",\"sender\":\"xx\",\"smtpSslTrust\":\"*\",\"enableSmtpAuth\":\"true\",\"receiverCcs\":null,\"showType\":\"table\",\"starttlsEnable\":\"false\",\"serverPort\":\"25\",\"serverHost\":\"xx\",\"Password\":\"xx\",\"sslEnable\":\"false\"}";
String pluginInstanceName = "alert-instance-mail";
List<AlertPluginInstance> alertInstanceList = new ArrayList<>();
AlertPluginInstance alertPluginInstance = new AlertPluginInstance(
pluginDefineId, pluginInstanceParams, pluginInstanceName);
alertPluginInstance.setInstanceType(AlertPluginInstanceType.GLOBAL);
alertPluginInstance.setId(1);
alertInstanceList.add(alertPluginInstance);
when(alertPluginInstanceMapper.queryAllGlobalAlertPluginInstanceList()).thenReturn(alertInstanceList);
AlertResult sendResult = new AlertResult();
sendResult.setSuccess(false);
sendResult.setMessage(String.format("Alert Plugin %s send failed", pluginInstanceName));
AlertChannel alertChannelMock = mock(AlertChannel.class);
when(alertChannelMock.process(Mockito.any())).thenReturn(sendResult);
when(alertPluginManager.getAlertChannel(1)).thenReturn(Optional.of(alertChannelMock));
Assertions.assertFalse(sendResult.isSuccess());
listenerEventSender.sendEvent(successEvent);
}
}

16
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java

@ -113,22 +113,6 @@ public class AlertGroupController extends BaseController {
return Result.success(alertGroups);
}
/**
* normal alert group list
*
* @param loginUser login user
* @return normal alert group list
*/
@Operation(summary = "listNormalAlertGroupById", description = "QUERY_ALERT_GROUP_LIST_NOTES")
@GetMapping(value = "/normal-list")
@ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_ALL_ALERTGROUP_ERROR)
public Result<List<AlertGroup>> normalAlertGroupList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
List<AlertGroup> alertGroups = alertGroupService.queryNormalAlertGroups(loginUser);
return Result.success(alertGroups);
}
/**
* paging query alarm group list
*

9
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java

@ -34,8 +34,6 @@ import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.api.vo.AlertPluginInstanceVO;
import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.common.enums.AlertPluginInstanceType;
import org.apache.dolphinscheduler.common.enums.WarningType;
import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils;
@ -97,11 +95,9 @@ public class AlertPluginInstanceController extends BaseController {
public Result<AlertPluginInstance> createAlertPluginInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "pluginDefineId") int pluginDefineId,
@RequestParam(value = "instanceName") String instanceName,
@RequestParam(value = "instanceType") AlertPluginInstanceType instanceType,
@RequestParam(value = "warningType") WarningType warningType,
@RequestParam(value = "pluginInstanceParams") String pluginInstanceParams) {
AlertPluginInstance alertPluginInstance = alertPluginInstanceService.create(loginUser, pluginDefineId,
instanceName, instanceType, warningType, pluginInstanceParams);
instanceName, pluginInstanceParams);
return Result.success(alertPluginInstance);
}
@ -141,10 +137,9 @@ public class AlertPluginInstanceController extends BaseController {
public Result<AlertPluginInstance> updateAlertPluginInstanceById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable(value = "id") int id,
@RequestParam(value = "instanceName") String instanceName,
@RequestParam(value = "warningType") WarningType warningType,
@RequestParam(value = "pluginInstanceParams") String pluginInstanceParams) {
AlertPluginInstance alertPluginInstance =
alertPluginInstanceService.updateById(loginUser, id, instanceName, warningType, pluginInstanceParams);
alertPluginInstanceService.updateById(loginUser, id, instanceName, pluginInstanceParams);
return Result.success(alertPluginInstance);
}

8
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java

@ -36,14 +36,6 @@ public interface AlertGroupService {
*/
List<AlertGroup> queryAllAlertGroup(User loginUser);
/**
* query normal alert group list
*
* @param loginUser
* @return alert group list which is is not 2
*/
List<AlertGroup> queryNormalAlertGroups(User loginUser);
/**
* query alert group by id
*

5
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceService.java

@ -19,8 +19,6 @@ package org.apache.dolphinscheduler.api.service;
import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.api.vo.AlertPluginInstanceVO;
import org.apache.dolphinscheduler.common.enums.AlertPluginInstanceType;
import org.apache.dolphinscheduler.common.enums.WarningType;
import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
import org.apache.dolphinscheduler.dao.entity.User;
@ -43,8 +41,6 @@ public interface AlertPluginInstanceService {
AlertPluginInstance create(User loginUser,
int pluginDefineId,
String instanceName,
AlertPluginInstanceType instanceType,
WarningType warningType,
String pluginInstanceParams);
/**
@ -58,7 +54,6 @@ public interface AlertPluginInstanceService {
AlertPluginInstance updateById(User loginUser,
int alertPluginInstanceId,
String instanceName,
WarningType warningType,
String pluginInstanceParams);
/**

18
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java

@ -41,7 +41,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
@ -82,15 +81,6 @@ public class AlertGroupServiceImpl extends BaseServiceImpl implements AlertGroup
return alertGroupMapper.selectBatchIds(ids);
}
@Override
public List<AlertGroup> queryNormalAlertGroups(User loginUser) {
return queryAllAlertGroup(loginUser)
.stream()
// todo: remove the hardcode
.filter(alertGroup -> alertGroup.getId() != 2)
.collect(Collectors.toList());
}
/**
* query alert group by id
*
@ -200,12 +190,6 @@ public class AlertGroupServiceImpl extends BaseServiceImpl implements AlertGroup
@Override
public AlertGroup updateAlertGroupById(User loginUser, int id, String groupName, String desc,
String alertInstanceIds) {
// don't allow to update global alert group
// todo: remove hardcode
if (id == 2) {
throw new ServiceException(Status.NOT_ALLOW_TO_UPDATE_GLOBAL_ALARM_GROUP);
}
if (!canOperatorPermissions(loginUser, new Object[]{id}, AuthorizationType.ALERT_GROUP, ALERT_GROUP_UPDATE)) {
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
}
@ -253,7 +237,7 @@ public class AlertGroupServiceImpl extends BaseServiceImpl implements AlertGroup
}
// Not allow to delete the default alarm group ,because the module of service need to use it.
if (id == 1 || id == 2) {
if (id == 1) {
log.warn("Not allow to delete the default alarm group.");
throw new ServiceException(Status.NOT_ALLOW_TO_DELETE_DEFAULT_ALARM_GROUP);
}

55
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertPluginInstanceServiceImpl.java

@ -27,12 +27,9 @@ import org.apache.dolphinscheduler.api.exceptions.ServiceException;
import org.apache.dolphinscheduler.api.service.AlertPluginInstanceService;
import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.api.vo.AlertPluginInstanceVO;
import org.apache.dolphinscheduler.common.enums.AlertPluginInstanceType;
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
import org.apache.dolphinscheduler.common.enums.WarningType;
import org.apache.dolphinscheduler.common.model.Server;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.dao.entity.AlertGroup;
import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
import org.apache.dolphinscheduler.dao.entity.PluginDefine;
import org.apache.dolphinscheduler.dao.entity.User;
@ -49,7 +46,6 @@ import org.apache.dolphinscheduler.registry.api.enums.RegistryNodeType;
import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
@ -87,8 +83,6 @@ public class AlertPluginInstanceServiceImpl extends BaseServiceImpl implements A
@Autowired
private AlertGroupMapper alertGroupMapper;
private final Integer GLOBAL_ALERT_GROUP_ID = 2;
@Autowired
private RegistryClient registryClient;
@ -104,8 +98,6 @@ public class AlertPluginInstanceServiceImpl extends BaseServiceImpl implements A
public AlertPluginInstance create(User loginUser,
int pluginDefineId,
String instanceName,
AlertPluginInstanceType instanceType,
WarningType warningType,
String pluginInstanceParams) {
if (!canOperatorPermissions(loginUser, null, AuthorizationType.ALERT_PLUGIN_INSTANCE, ALERT_INSTANCE_CREATE)) {
@ -117,8 +109,6 @@ public class AlertPluginInstanceServiceImpl extends BaseServiceImpl implements A
alertPluginInstance.setPluginInstanceParams(paramsMapJson);
alertPluginInstance.setInstanceName(instanceName);
alertPluginInstance.setPluginDefineId(pluginDefineId);
alertPluginInstance.setInstanceType(instanceType);
alertPluginInstance.setWarningType(warningType);
if (alertPluginInstanceMapper.existInstanceName(alertPluginInstance.getInstanceName()) == Boolean.TRUE) {
throw new ServiceException(Status.PLUGIN_INSTANCE_ALREADY_EXISTS);
@ -127,20 +117,6 @@ public class AlertPluginInstanceServiceImpl extends BaseServiceImpl implements A
int i = alertPluginInstanceMapper.insert(alertPluginInstance);
if (i > 0) {
log.info("Create alert plugin instance complete, name:{}", alertPluginInstance.getInstanceName());
// global instance will be added into global alert group automatically
if (instanceType == AlertPluginInstanceType.GLOBAL) {
AlertGroup globalAlertGroup = alertGroupMapper.selectById(GLOBAL_ALERT_GROUP_ID);
if (StringUtils.isEmpty(globalAlertGroup.getAlertInstanceIds())) {
globalAlertGroup.setAlertInstanceIds(String.valueOf(alertPluginInstance.getId()));
} else {
List<Integer> ids = Arrays.stream(globalAlertGroup.getAlertInstanceIds().split(","))
.map(s -> Integer.parseInt(s.trim()))
.collect(Collectors.toList());
ids.add(alertPluginInstance.getId());
globalAlertGroup.setAlertInstanceIds(StringUtils.join(ids, ","));
}
alertGroupMapper.updateById(globalAlertGroup);
}
return alertPluginInstance;
}
throw new ServiceException(Status.SAVE_ERROR);
@ -156,7 +132,7 @@ public class AlertPluginInstanceServiceImpl extends BaseServiceImpl implements A
*/
@Override
public AlertPluginInstance updateById(User loginUser, int pluginInstanceId, String instanceName,
WarningType warningType, String pluginInstanceParams) {
String pluginInstanceParams) {
if (!canOperatorPermissions(loginUser, null, AuthorizationType.ALERT_PLUGIN_INSTANCE, ALERT_PLUGIN_UPDATE)) {
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
@ -164,7 +140,7 @@ public class AlertPluginInstanceServiceImpl extends BaseServiceImpl implements A
String paramsMapJson = parsePluginParamsMap(pluginInstanceParams);
AlertPluginInstance alertPluginInstance =
new AlertPluginInstance(pluginInstanceId, paramsMapJson, instanceName, warningType, new Date());
new AlertPluginInstance(pluginInstanceId, paramsMapJson, instanceName, new Date());
int i = alertPluginInstanceMapper.updateById(alertPluginInstance);
@ -190,25 +166,10 @@ public class AlertPluginInstanceServiceImpl extends BaseServiceImpl implements A
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
}
AlertPluginInstance alertPluginInstance = alertPluginInstanceMapper.selectById(alertPluginInstanceId);
if (alertPluginInstance.getInstanceType() == AlertPluginInstanceType.GLOBAL) {
// global instance will be removed from global alert group automatically
AlertGroup globalAlertGroup = alertGroupMapper.selectById(GLOBAL_ALERT_GROUP_ID);
List<Integer> ids = Arrays.stream(globalAlertGroup.getAlertInstanceIds().split(","))
.map(s -> Integer.parseInt(s.trim()))
.collect(Collectors.toList());
ids = ids.stream().filter(x -> x != alertPluginInstanceId).collect(Collectors.toList());
globalAlertGroup.setAlertInstanceIds(StringUtils.join(ids, ","));
alertGroupMapper.updateById(globalAlertGroup);
log.info("Remove global alert plugin instance from global alert group automatically, name:{}",
alertPluginInstance.getInstanceName());
} else {
// check if there is an associated alert group
boolean hasAssociatedAlertGroup = checkHasAssociatedAlertGroup(String.valueOf(alertPluginInstanceId));
if (hasAssociatedAlertGroup) {
throw new ServiceException(Status.DELETE_ALERT_PLUGIN_INSTANCE_ERROR_HAS_ALERT_GROUP_ASSOCIATED);
}
// check if there is an associated alert group
boolean hasAssociatedAlertGroup = checkHasAssociatedAlertGroup(String.valueOf(alertPluginInstanceId));
if (hasAssociatedAlertGroup) {
throw new ServiceException(Status.DELETE_ALERT_PLUGIN_INSTANCE_ERROR_HAS_ALERT_GROUP_ASSOCIATED);
}
alertPluginInstanceMapper.deleteById(alertPluginInstanceId);
@ -271,10 +232,6 @@ public class AlertPluginInstanceServiceImpl extends BaseServiceImpl implements A
alertPluginInstanceVO.setPluginDefineId(alertPluginInstance.getPluginDefineId());
alertPluginInstanceVO.setInstanceName(alertPluginInstance.getInstanceName());
alertPluginInstanceVO.setId(alertPluginInstance.getId());
alertPluginInstanceVO.setInstanceType(alertPluginInstance.getInstanceType().getDescp());
if (alertPluginInstance.getWarningType() != null) {
alertPluginInstanceVO.setWarningType(alertPluginInstance.getWarningType().getDescp().toUpperCase());
}
PluginDefine pluginDefine = pluginDefineMap.get(alertPluginInstance.getPluginDefineId());
// FIXME When the user removes the plug-in, this will happen. At this time, maybe we should add a new field
// to indicate that the plug-in has expired?

15
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java

@ -119,7 +119,6 @@ import org.apache.dolphinscheduler.plugin.task.api.parameters.DependentParameter
import org.apache.dolphinscheduler.plugin.task.api.parameters.SqlParameters;
import org.apache.dolphinscheduler.plugin.task.api.utils.TaskTypeUtils;
import org.apache.dolphinscheduler.plugin.task.sql.SqlTaskChannelFactory;
import org.apache.dolphinscheduler.service.alert.ListenerEventAlertManager;
import org.apache.dolphinscheduler.service.model.TaskNode;
import org.apache.dolphinscheduler.service.process.ProcessService;
@ -250,9 +249,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
@Autowired
private MetricsCleanUpService metricsCleanUpService;
@Autowired
private ListenerEventAlertManager listenerEventAlertManager;
/**
* create process definition
*
@ -309,11 +305,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
processDefinition.setExecutionType(executionType);
result = createDagDefine(loginUser, taskRelationList, processDefinition, taskDefinitionLogs);
if (result.get(Constants.STATUS) == Status.SUCCESS) {
listenerEventAlertManager.publishProcessDefinitionCreatedListenerEvent(loginUser, processDefinition,
taskDefinitionLogs,
taskRelationList);
}
return result;
}
@ -862,11 +853,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
processDefinition.setExecutionType(executionType);
result = updateDagDefine(loginUser, taskRelationList, processDefinition, processDefinitionDeepCopy,
taskDefinitionLogs);
if (result.get(Constants.STATUS) == Status.SUCCESS) {
listenerEventAlertManager.publishProcessDefinitionUpdatedListenerEvent(loginUser, processDefinition,
taskDefinitionLogs,
taskRelationList);
}
return result;
}
@ -1131,7 +1117,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
processDefinitionDao.deleteByWorkflowDefinitionCode(processDefinition.getCode());
metricsCleanUpService.cleanUpWorkflowMetricsByDefinitionCode(code);
log.info("Success delete workflow definition workflowDefinitionCode: {}", code);
listenerEventAlertManager.publishProcessDefinitionDeletedListenerEvent(loginUser, project, processDefinition);
}
/**

46
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertGroupControllerTest.java

@ -217,50 +217,4 @@ public class AlertGroupControllerTest extends AbstractControllerTest {
Assertions.assertEquals(Status.NOT_ALLOW_TO_DELETE_DEFAULT_ALARM_GROUP.getCode(), result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
}
@Test
public void test100DelAlertGroupById() throws Exception {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
MvcResult mvcResult = mockMvc.perform(delete("/alert-groups/2")
.header("sessionId", sessionId)
.params(paramsMap))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assertions.assertEquals(Status.NOT_ALLOW_TO_DELETE_DEFAULT_ALARM_GROUP.getCode(), result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
}
@Test
public void test110UpdateAlertGroupById() throws Exception {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("groupName", defaultTestAlertGroupName);
paramsMap.add("groupType", "email");
paramsMap.add("description", "update alter group");
paramsMap.add("alertInstanceIds", "");
MvcResult mvcResult = mockMvc.perform(put("/alert-groups/2")
.header("sessionId", sessionId)
.params(paramsMap))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assertions.assertEquals(Status.NOT_ALLOW_TO_UPDATE_GLOBAL_ALARM_GROUP.getCode(), result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
}
@Test
public void test120QueryNormalAlertGroupList() throws Exception {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
MvcResult mvcResult = mockMvc.perform(get("/alert-groups/normal-list")
.header("sessionId", sessionId)
.params(paramsMap))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
}
}

4
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceControllerTest.java

@ -80,7 +80,7 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
paramsMap.add("pluginInstanceParams", pluginInstanceParams);
when(alertPluginInstanceService.create(any(User.class), eq(pluginDefineId), eq(instanceName),
eq(pluginInstanceType), eq(warningType), eq(pluginInstanceParams))).thenReturn(alertPluginInstance);
eq(pluginInstanceParams))).thenReturn(alertPluginInstance);
// When
final MvcResult mvcResult = mockMvc.perform(post("/alert-plugin-instances")
@ -131,7 +131,7 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
paramsMap.add("pluginInstanceParams", pluginInstanceParams);
when(alertPluginInstanceService.updateById(any(User.class), eq(pluginDefineId), eq(instanceName),
eq(warningType), eq(pluginInstanceParams))).thenReturn(alertPluginInstance);
eq(pluginInstanceParams))).thenReturn(alertPluginInstance);
// When
final MvcResult mvcResult = mockMvc.perform(put("/alert-plugin-instances/{id}", pluginDefineId)

56
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java

@ -93,7 +93,7 @@ public class AlertGroupServiceTest {
when(alertGroupMapper.queryAllGroupList()).thenReturn(getList());
List<AlertGroup> alertGroups = alertGroupService.queryAllAlertGroup(user);
Assertions.assertEquals(2, alertGroups.size());
Assertions.assertEquals(1, alertGroups.size());
user.setUserType(UserType.GENERAL_USER);
user.setId(2);
@ -110,14 +110,6 @@ public class AlertGroupServiceTest {
assertDoesNotThrow(() -> alertGroupService.queryAllAlertGroup(user));
}
@Test
public void testQueryNormalAlertGroup() {
when(alertGroupMapper.queryAllGroupList()).thenReturn(getList());
List<AlertGroup> alertGroups = alertGroupService.queryNormalAlertGroups(getLoginUser());
Assertions.assertEquals(1, alertGroups.size());
}
@Test
public void testQueryAlertGroupById() {
User user = getLoginUser();
@ -150,7 +142,7 @@ public class AlertGroupServiceTest {
@Test
public void testListPaging() {
IPage<AlertGroup> page = new Page<>(1, 10);
page.setTotal(2L);
page.setTotal(1L);
page.setRecords(getList());
when(alertGroupMapper.queryAlertGroupPage(any(Page.class), eq(groupName))).thenReturn(page);
User user = new User();
@ -183,7 +175,7 @@ public class AlertGroupServiceTest {
@Test
public void testCreateAlertgroup() {
when(alertGroupMapper.insert(any(AlertGroup.class))).thenReturn(3);
when(alertGroupMapper.insert(any(AlertGroup.class))).thenReturn(2);
User user = new User();
user.setId(0);
// no operate
@ -251,10 +243,10 @@ public class AlertGroupServiceTest {
() -> alertGroupService.updateAlertGroupById(user, 1, groupName, tooLongDescription, null));
// success
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, new Object[]{3},
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, new Object[]{2},
user.getId(), baseServiceLogger)).thenReturn(true);
when(alertGroupMapper.selectById(3)).thenReturn(getEntity());
assertDoesNotThrow(() -> alertGroupService.updateAlertGroupById(user, 3, groupName, groupName, null));
when(alertGroupMapper.selectById(2)).thenReturn(getEntity());
assertDoesNotThrow(() -> alertGroupService.updateAlertGroupById(user, 2, groupName, groupName, null));
}
@Test
@ -265,23 +257,11 @@ public class AlertGroupServiceTest {
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP,
user.getId(), ALERT_GROUP_UPDATE, baseServiceLogger)).thenReturn(true);
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP,
new Object[]{3}, user.getId(), baseServiceLogger)).thenReturn(true);
when(alertGroupMapper.selectById(3)).thenReturn(getEntity());
new Object[]{2}, user.getId(), baseServiceLogger)).thenReturn(true);
when(alertGroupMapper.selectById(2)).thenReturn(getEntity());
when(alertGroupMapper.updateById(Mockito.any()))
.thenThrow(new DuplicateKeyException("group name exist"));
assertThrowsServiceException(Status.ALERT_GROUP_EXIST,
() -> alertGroupService.updateAlertGroupById(user, 3, groupName, groupName, null));
}
@Test
public void testUpdateGlobalAlertgroup() {
User user = new User();
user.setId(0);
user.setUserType(UserType.ADMIN_USER);
AlertGroup globalAlertGroup = new AlertGroup();
globalAlertGroup.setId(2);
globalAlertGroup.setGroupName("global alert group");
assertThrowsServiceException(Status.NOT_ALLOW_TO_UPDATE_GLOBAL_ALARM_GROUP,
() -> alertGroupService.updateAlertGroupById(user, 2, groupName, groupName, null));
}
@ -302,20 +282,15 @@ public class AlertGroupServiceTest {
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP,
user.getId(), ALERT_GROUP_DELETE, baseServiceLogger)).thenReturn(true);
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP,
new Object[]{3}, 0, baseServiceLogger)).thenReturn(true);
new Object[]{2}, 0, baseServiceLogger)).thenReturn(true);
assertThrowsServiceException(Status.ALERT_GROUP_NOT_EXIST,
() -> alertGroupService.deleteAlertGroupById(user, 3));
() -> alertGroupService.deleteAlertGroupById(user, 2));
// not allowed1
// not allowed
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, new Object[]{1}, 0,
baseServiceLogger)).thenReturn(true);
assertThrowsServiceException(Status.NOT_ALLOW_TO_DELETE_DEFAULT_ALARM_GROUP,
() -> alertGroupService.deleteAlertGroupById(user, 1));
// not allowed2
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP,
new Object[]{2}, 0, baseServiceLogger)).thenReturn(true);
assertThrowsServiceException(Status.NOT_ALLOW_TO_DELETE_DEFAULT_ALARM_GROUP,
() -> alertGroupService.deleteAlertGroupById(user, 2));
// success
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, new Object[]{4}, 0,
baseServiceLogger)).thenReturn(true);
@ -351,14 +326,7 @@ public class AlertGroupServiceTest {
*/
private List<AlertGroup> getList() {
List<AlertGroup> alertGroups = new ArrayList<>();
AlertGroup defaultAdminWarningGroup = new AlertGroup();
defaultAdminWarningGroup.setId(1);
defaultAdminWarningGroup.setGroupName("default admin warning group");
alertGroups.add(defaultAdminWarningGroup);
AlertGroup globalAlertGroup = new AlertGroup();
globalAlertGroup.setId(2);
globalAlertGroup.setGroupName("global alert group");
alertGroups.add(globalAlertGroup);
alertGroups.add(getEntity());
return alertGroups;
}

57
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java

@ -30,7 +30,6 @@ import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService;
import org.apache.dolphinscheduler.api.service.impl.AlertPluginInstanceServiceImpl;
import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl;
import org.apache.dolphinscheduler.common.enums.AlertPluginInstanceType;
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
import org.apache.dolphinscheduler.common.enums.UserType;
import org.apache.dolphinscheduler.common.enums.WarningType;
@ -96,14 +95,10 @@ public class AlertPluginInstanceServiceTest {
private User noPermUser;
private final AlertPluginInstanceType normalInstanceType = AlertPluginInstanceType.NORMAL;
private final AlertPluginInstanceType globalInstanceType = AlertPluginInstanceType.GLOBAL;
private final WarningType warningType = WarningType.ALL;
private final Integer GLOBAL_ALERT_GROUP_ID = 2;
private static final WarningType warningType = WarningType.ALL;
private String uiParams = "[\n"
+ " {\n"
+ " \"field\":\"userParams\",\n"
@ -192,7 +187,7 @@ public class AlertPluginInstanceServiceTest {
noPermUser.setUserType(UserType.GENERAL_USER);
noPermUser.setId(2);
alertPluginInstance = getAlertPluginInstance(1, normalInstanceType, "test");
alertPluginInstance = getAlertPluginInstance(1, "test");
alertPluginInstances = new ArrayList<>();
alertPluginInstances.add(alertPluginInstance);
}
@ -202,7 +197,7 @@ public class AlertPluginInstanceServiceTest {
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
noPermUser.getId(), ALERT_INSTANCE_CREATE, baseServiceLogger)).thenReturn(false);
assertThrowsServiceException(Status.USER_NO_OPERATION_PERM, () -> alertPluginInstanceService.create(noPermUser,
1, "test", normalInstanceType, warningType, uiParams));
1, "test", uiParams));
when(alertPluginInstanceMapper.existInstanceName("test")).thenReturn(true);
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
@ -210,23 +205,15 @@ public class AlertPluginInstanceServiceTest {
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
null, 0, baseServiceLogger)).thenReturn(true);
assertThrowsServiceException(Status.PLUGIN_INSTANCE_ALREADY_EXISTS,
() -> alertPluginInstanceService.create(user, 1, "test", normalInstanceType, warningType, uiParams));
() -> alertPluginInstanceService.create(user, 1, "test", uiParams));
when(alertPluginInstanceMapper.insert(Mockito.any())).thenReturn(1);
AlertPluginInstance alertPluginInstance =
alertPluginInstanceService.create(user, 1, "test1", normalInstanceType, warningType, uiParams);
alertPluginInstanceService.create(user, 1, "test1", uiParams);
assertNotNull(alertPluginInstance);
when(alertGroupMapper.selectById(GLOBAL_ALERT_GROUP_ID)).thenReturn(getGlobalAlertGroup());
assertDoesNotThrow(() -> alertPluginInstanceService.create(user, 1, "global_plugin_instance",
AlertPluginInstanceType.GLOBAL, warningType, uiParams));
when(alertGroupMapper.selectById(GLOBAL_ALERT_GROUP_ID)).thenReturn(getGlobalAlertGroup("1"));
assertDoesNotThrow(() -> alertPluginInstanceService.create(user, 1, "global_plugin_instance",
AlertPluginInstanceType.GLOBAL, warningType, uiParams));
when(alertPluginInstanceMapper.insert(Mockito.any())).thenReturn(-1);
assertThrowsServiceException(Status.SAVE_ERROR,
() -> alertPluginInstanceService.create(user, 1, "test_insert_error", normalInstanceType, warningType,
() -> alertPluginInstanceService.create(user, 1, "test_insert_error",
uiParams));
}
@ -258,17 +245,6 @@ public class AlertPluginInstanceServiceTest {
1, ALERT_PLUGIN_DELETE, baseServiceLogger)).thenReturn(true);
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
null, 0, baseServiceLogger)).thenReturn(true);
AlertPluginInstance normalInstanceWithId1 = getAlertPluginInstance(1, normalInstanceType, "test1");
AlertPluginInstance normalInstanceWithId9 = getAlertPluginInstance(9, normalInstanceType, "test9");
AlertPluginInstance globalInstanceWithId5 = getAlertPluginInstance(5, globalInstanceType, "test5");
when(alertPluginInstanceMapper.selectById(1)).thenReturn(normalInstanceWithId1);
when(alertPluginInstanceMapper.selectById(9)).thenReturn(normalInstanceWithId9);
when(alertPluginInstanceMapper.selectById(5)).thenReturn(globalInstanceWithId5);
AlertGroup globalAlertGroup = new AlertGroup();
globalAlertGroup.setId(2);
globalAlertGroup.setAlertInstanceIds("5,96");
when(alertGroupMapper.selectById(2)).thenReturn(globalAlertGroup);
when(alertGroupMapper.updateById(Mockito.any())).thenReturn(1);
assertThrowsServiceException(Status.DELETE_ALERT_PLUGIN_INSTANCE_ERROR_HAS_ALERT_GROUP_ASSOCIATED,
() -> alertPluginInstanceService.deleteById(user, 1));
@ -276,8 +252,8 @@ public class AlertPluginInstanceServiceTest {
when(alertPluginInstanceMapper.deleteById(9)).thenReturn(1);
Assertions.assertDoesNotThrow(() -> alertPluginInstanceService.deleteById(user, 9));
when(alertPluginInstanceMapper.deleteById(5)).thenReturn(1);
Assertions.assertDoesNotThrow(() -> alertPluginInstanceService.deleteById(user, 5));
assertThrowsServiceException(Status.DELETE_ALERT_PLUGIN_INSTANCE_ERROR_HAS_ALERT_GROUP_ASSOCIATED,
() -> alertPluginInstanceService.deleteById(user, 5));
when(alertGroupMapper.queryInstanceIdsList()).thenReturn(Collections.emptyList());
Assertions.assertDoesNotThrow(() -> alertPluginInstanceService.deleteById(user, 9));
@ -288,7 +264,7 @@ public class AlertPluginInstanceServiceTest {
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
noPermUser.getId(), ALERT_PLUGIN_UPDATE, baseServiceLogger)).thenReturn(false);
assertThrowsServiceException(Status.USER_NO_OPERATION_PERM,
() -> alertPluginInstanceService.updateById(noPermUser, 1, "test", warningType, uiParams));
() -> alertPluginInstanceService.updateById(noPermUser, 1, "test", uiParams));
when(alertPluginInstanceMapper.updateById(Mockito.any())).thenReturn(0);
when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE, 1,
@ -296,11 +272,11 @@ public class AlertPluginInstanceServiceTest {
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE, null, 0,
baseServiceLogger)).thenReturn(true);
assertThrowsServiceException(Status.SAVE_ERROR,
() -> alertPluginInstanceService.updateById(user, 1, "testUpdate", warningType, uiParams));
() -> alertPluginInstanceService.updateById(user, 1, "testUpdate", uiParams));
when(alertPluginInstanceMapper.updateById(Mockito.any())).thenReturn(1);
AlertPluginInstance alertPluginInstance =
alertPluginInstanceService.updateById(user, 1, "testUpdate", warningType, uiParams);
alertPluginInstanceService.updateById(user, 1, "testUpdate", uiParams);
Assertions.assertNotNull(alertPluginInstance);
}
@ -316,7 +292,7 @@ public class AlertPluginInstanceServiceTest {
when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE, null, 0,
baseServiceLogger)).thenReturn(true);
when(alertPluginInstanceMapper.selectById(1))
.thenReturn(getAlertPluginInstance(1, AlertPluginInstanceType.NORMAL, "test_get_instance"));
.thenReturn(getAlertPluginInstance(1, "test_get_instance"));
Assertions.assertEquals(alertPluginInstanceService.getById(user, 1).getId(), 1);
}
@ -349,7 +325,7 @@ public class AlertPluginInstanceServiceTest {
when(pluginDefineMapper.queryAllPluginDefineList()).thenReturn(Collections.emptyList());
Assertions.assertEquals(0, alertPluginInstanceService.queryAll().size());
AlertPluginInstance alertPluginInstance = getAlertPluginInstance(1, normalInstanceType, "test");
AlertPluginInstance alertPluginInstance = getAlertPluginInstance(1, "test");
PluginDefine pluginDefine = new PluginDefine("script", "script", uiParams);
pluginDefine.setId(1);
List<PluginDefine> pluginDefines = Collections.singletonList(pluginDefine);
@ -359,13 +335,10 @@ public class AlertPluginInstanceServiceTest {
Assertions.assertDoesNotThrow(() -> alertPluginInstanceService.queryAll());
}
private AlertPluginInstance getAlertPluginInstance(int id, AlertPluginInstanceType instanceType,
String instanceName) {
private AlertPluginInstance getAlertPluginInstance(int id, String instanceName) {
AlertPluginInstance alertPluginInstance = new AlertPluginInstance();
alertPluginInstance.setId(id);
alertPluginInstance.setPluginDefineId(1);
alertPluginInstance.setInstanceType(instanceType);
alertPluginInstance.setWarningType(warningType);
alertPluginInstance.setPluginInstanceParams(paramsMap);
alertPluginInstance.setInstanceName(instanceName);
return alertPluginInstance;

4
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java

@ -73,7 +73,6 @@ import org.apache.dolphinscheduler.dao.repository.ProcessDefinitionDao;
import org.apache.dolphinscheduler.dao.repository.ProcessDefinitionLogDao;
import org.apache.dolphinscheduler.dao.repository.TaskDefinitionLogDao;
import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
import org.apache.dolphinscheduler.service.alert.ListenerEventAlertManager;
import org.apache.dolphinscheduler.service.process.ProcessService;
import org.apache.dolphinscheduler.spi.enums.DbType;
@ -186,9 +185,6 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
@Mock
private UserMapper userMapper;
@Mock
private ListenerEventAlertManager listenerEventAlertManager;
protected User user;
protected Exception exception;
protected final static long projectCode = 1L;

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

@ -40,8 +40,7 @@ public enum WarningType {
NONE(0, "none"),
SUCCESS(1, "success"),
FAILURE(2, "failure"),
ALL(3, "all"),
GLOBAL(4, "global");
ALL(3, "all");
WarningType(int code, String descp) {
this.code = code;

2
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/CodeGenerateUtilsTest.java

@ -49,7 +49,7 @@ class CodeGenerateUtilsTest {
@Test
void testNoGenerateDuplicateCodeWithDifferentAppName() throws UnknownHostException, InterruptedException {
int threadNum = 10;
int codeNum = 1000000;
int codeNum = 100000;
final String hostName = InetAddress.getLocalHost().getHostName();
Map<String, List<Long>> machineCodes = new ConcurrentHashMap<>();

2
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HttpUtilsTest.java

@ -46,7 +46,7 @@ public class HttpUtilsTest {
*/
@Test
void testGetValidRequest() {
String response3 = HttpUtils.get("https://www.google.com/");
String response3 = HttpUtils.get("https://www.bing.com/");
assertNotNull(response3, "Response should not be null for a valid certification https URL");
}

18
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/AlertPluginInstance.java

@ -17,9 +17,6 @@
package org.apache.dolphinscheduler.dao.entity;
import org.apache.dolphinscheduler.common.enums.AlertPluginInstanceType;
import org.apache.dolphinscheduler.common.enums.WarningType;
import java.util.Date;
import lombok.Data;
@ -58,18 +55,6 @@ public class AlertPluginInstance {
@TableField("plugin_instance_params")
private String pluginInstanceParams;
/**
* instance_type. 0 normal, 1 global
*/
@TableField("instance_type")
private AlertPluginInstanceType instanceType;
/**
* warning_type
*/
@TableField("warning_type")
private WarningType warningType;
/**
* create_time
*/
@ -95,11 +80,10 @@ public class AlertPluginInstance {
this.instanceName = instanceName;
}
public AlertPluginInstance(int id, String pluginInstanceParams, String instanceName, WarningType warningType,
public AlertPluginInstance(int id, String pluginInstanceParams, String instanceName,
Date updateDate) {
this.id = id;
this.pluginInstanceParams = pluginInstanceParams;
this.warningType = warningType;
this.updateTime = updateDate;
this.instanceName = instanceName;
}

7
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapper.java

@ -36,13 +36,6 @@ public interface AlertPluginInstanceMapper extends BaseMapper<AlertPluginInstanc
*/
List<AlertPluginInstance> queryAllAlertPluginInstanceList();
/**
* query all global alert plugin instance
*
* @return global AlertPluginInstance list
*/
List<AlertPluginInstance> queryAllGlobalAlertPluginInstanceList();
/**
* query by alert group id
*

43
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ListenerEventMapper.java

@ -1,43 +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.dao.mapper;
import org.apache.dolphinscheduler.common.enums.AlertStatus;
import org.apache.dolphinscheduler.dao.entity.ListenerEvent;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface ListenerEventMapper extends BaseMapper<ListenerEvent> {
int batchInsert(@Param("events") List<ListenerEvent> events);
void insertServerDownEvent(@Param("event") ListenerEvent event,
@Param("crashAlarmSuppressionStartTime") Date crashAlarmSuppressionStartTime);
List<ListenerEvent> listingListenerEventByStatus(@Param("minId") int minId,
@Param("postStatus") int postStatus,
@Param("limit") int limit);
void updateListenerEvent(@Param("eventId") int eventId, @Param("postStatus") AlertStatus postStatus,
@Param("log") String log, @Param("updateTime") Date updateTime);
}

31
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ListenerEventDao.java

@ -1,31 +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.dao.repository;
import org.apache.dolphinscheduler.common.enums.AlertStatus;
import org.apache.dolphinscheduler.dao.entity.ListenerEvent;
import java.util.Date;
import java.util.List;
public interface ListenerEventDao extends IDao<ListenerEvent> {
List<ListenerEvent> listingPendingEvents(int minId, int limit);
void updateListenerEvent(int eventId, AlertStatus alertStatus, String message, Date date);
}

51
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/impl/ListenerEventDaoImpl.java

@ -1,51 +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.dao.repository.impl;
import org.apache.dolphinscheduler.common.enums.AlertStatus;
import org.apache.dolphinscheduler.dao.entity.ListenerEvent;
import org.apache.dolphinscheduler.dao.mapper.ListenerEventMapper;
import org.apache.dolphinscheduler.dao.repository.BaseDao;
import org.apache.dolphinscheduler.dao.repository.ListenerEventDao;
import java.util.Date;
import java.util.List;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
@Slf4j
@Repository
public class ListenerEventDaoImpl extends BaseDao<ListenerEvent, ListenerEventMapper> implements ListenerEventDao {
public ListenerEventDaoImpl(@NonNull ListenerEventMapper listenerEventMapper) {
super(listenerEventMapper);
}
@Override
public List<ListenerEvent> listingPendingEvents(int minId, int limit) {
return mybatisMapper.listingListenerEventByStatus(minId, AlertStatus.WAIT_EXECUTION.getCode(), limit);
}
@Override
public void updateListenerEvent(int eventId, AlertStatus alertStatus, String message, Date date) {
mybatisMapper.updateListenerEvent(eventId, alertStatus, message, date);
}
}

10
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapper.xml

@ -20,7 +20,7 @@
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.AlertPluginInstanceMapper">
<sql id="baseSql">
id, plugin_define_id, plugin_instance_params, instance_type, warning_type, create_time, update_time, instance_name
id, plugin_define_id, plugin_instance_params, create_time, update_time, instance_name
</sql>
@ -32,14 +32,6 @@
where 1 = 1 order by update_time desc
</select>
<select id="queryAllGlobalAlertPluginInstanceList"
resultType="org.apache.dolphinscheduler.dao.entity.AlertPluginInstance">
select
<include refid="baseSql"/>
from t_ds_alert_plugin_instance
where instance_type = 1 order by update_time desc
</select>
<select id="queryByIds" resultType="org.apache.dolphinscheduler.dao.entity.AlertPluginInstance">
select
<include refid="baseSql"/>

67
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ListenerEventMapper.xml

@ -1,67 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
~ 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.
-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.ListenerEventMapper">
<sql id="baseSql">
id
, content, sign, event_type, post_status, log, create_time, update_time
</sql>
<insert id="batchInsert">
insert into t_ds_listener_event ( content, sign, post_status, event_type, create_time, update_time)
values
<foreach collection='events' item='event' separator=','>
(#{event.content},#{event.sign},#{event.postStatus.code},
#{event.eventType.code},#{event.createTime},#{event.updateTime})
</foreach>
</insert>
<insert id="insertServerDownEvent">
insert into t_ds_listener_event (content, sign, post_status, event_type, create_time, update_time)
SELECT #{event.sign},
#{event.content},
#{event.postStatus.code},
#{event.eventType.code},
#{event.createTime},
#{event.updateTime}
from t_ds_listener_event
where create_time >= #{crashAlarmSuppressionStartTime}
and sign = #{event.sign}
and post_status = #{event.postStatus.code}
having count(*) = 0
</insert>
<update id="updateListenerEvent">
update t_ds_listener_event
set log = #{log},
post_status = #{postStatus.code},
update_time = #{updateTime}
where id = #{eventId}
</update>
<select id="listingListenerEventByStatus" resultType="org.apache.dolphinscheduler.dao.entity.ListenerEvent">
select
<include refid="baseSql"/>
from t_ds_listener_event
where id > #{minId} and post_status = #{postStatus}
order by id asc
limit #{limit}
</select>
</mapper>

31
dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql

@ -309,10 +309,6 @@ CREATE TABLE t_ds_alertgroup
UNIQUE KEY t_ds_alertgroup_name_un (group_name)
);
-- ----------------------------
-- Records of t_ds_alertgroup
-- ----------------------------
-- ----------------------------
-- Table structure for t_ds_command
-- ----------------------------
@ -1081,10 +1077,6 @@ INSERT INTO t_ds_alertgroup(alert_instance_ids, create_user_id, group_name, desc
VALUES (NULL, 1, 'default admin warning group', 'default admin warning group', '2018-11-29 10:20:39',
'2018-11-29 10:20:39');
INSERT INTO t_ds_alertgroup(alert_instance_ids, create_user_id, group_name, description, create_time, update_time)
VALUES (NULL, 1, 'global alert group', 'global alert group', '2018-11-29 10:20:39',
'2018-11-29 10:20:39');
-- ----------------------------
-- Records of t_ds_user
-- ----------------------------
@ -1120,8 +1112,6 @@ CREATE TABLE t_ds_alert_plugin_instance
create_time timestamp NULL DEFAULT CURRENT_TIMESTAMP,
update_time timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
instance_name varchar(200) DEFAULT NULL,
instance_type int NOT NULL default '0',
warning_type int NOT NULL default '3',
PRIMARY KEY (id)
);
@ -2014,7 +2004,7 @@ CREATE TABLE t_ds_task_group
);
-- ----------------------------
-- Table structure for t_ds_alert_plugin_instance
-- Table structure for t_ds_audit_log
-- ----------------------------
DROP TABLE IF EXISTS t_ds_audit_log;
CREATE TABLE t_ds_audit_log
@ -2167,25 +2157,6 @@ CREATE TABLE t_ds_relation_sub_workflow (
INDEX idx_sub_workflow_instance_id (sub_workflow_instance_id)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for t_ds_listener_event
-- ----------------------------
DROP TABLE IF EXISTS t_ds_listener_event;
CREATE TABLE t_ds_listener_event
(
id int NOT NULL AUTO_INCREMENT,
content text,
sign char(64) NOT NULL DEFAULT '',
post_status tinyint(4) NOT NULL DEFAULT '0',
event_type int(11),
log text,
create_time datetime DEFAULT NULL,
update_time datetime DEFAULT NULL,
PRIMARY KEY (id),
KEY idx_status (post_status),
KEY idx_event_sign (sign)
);
-- ----------------------------
-- Table structure for t_ds_process_task_lineage
-- ----------------------------

22
dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql

@ -1053,8 +1053,6 @@ INSERT IGNORE INTO `t_ds_version` VALUES ('1', '3.3.0');
-- ----------------------------
INSERT IGNORE INTO `t_ds_alertgroup`(alert_instance_ids, create_user_id, group_name, description, create_time, update_time)
VALUES (NULL, 1, 'default admin warning group', 'default admin warning group', current_timestamp, current_timestamp);
INSERT IGNORE INTO `t_ds_alertgroup`(alert_instance_ids, create_user_id, group_name, description, create_time, update_time)
VALUES (NULL, 1, 'global alert group', 'global alert group', current_timestamp, current_timestamp);
-- ----------------------------
-- Records of t_ds_user
@ -1088,8 +1086,6 @@ CREATE TABLE `t_ds_alert_plugin_instance` (
`create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`instance_name` varchar(255) DEFAULT NULL COMMENT 'alert instance name',
`instance_type` int NOT NULL default '0',
`warning_type` int NOT NULL default '3',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE = utf8_bin;
@ -2140,24 +2136,6 @@ CREATE TABLE `t_ds_relation_sub_workflow` (
KEY `idx_sub_workflow_instance_id` (`sub_workflow_instance_id`)
);
-- ----------------------------
-- Table structure for t_ds_listener_event
-- ----------------------------
DROP TABLE IF EXISTS `t_ds_listener_event`;
CREATE TABLE `t_ds_listener_event` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'key',
`content` text COMMENT 'listener event json content',
`sign` char(64) NOT NULL DEFAULT '' COMMENT 'sign=sha1(content)',
`post_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0:wait running,1:success,2:failed,3:partial success',
`event_type` int(11) NOT NULL COMMENT 'listener event type',
`log` text COMMENT 'log',
`create_time` datetime DEFAULT NULL COMMENT 'create time',
`update_time` datetime DEFAULT NULL COMMENT 'update time',
PRIMARY KEY (`id`),
KEY `idx_status` (`post_status`) USING BTREE,
KEY `idx_sign` (`sign`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE = utf8_bin;
-- ----------------------------
-- Table structure for t_ds_process_task_lineage
-- ----------------------------

25
dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql

@ -1056,8 +1056,6 @@ VALUES (-1, 'default', 'default tenant', '1', '2018-03-27 15:48:50', '2018-10-24
-- Records of t_ds_alertgroup, default admin warning group
INSERT INTO t_ds_alertgroup(alert_instance_ids, create_user_id, group_name, description, create_time, update_time)
VALUES (NULL, 1, 'default admin warning group', 'default admin warning group', '2018-11-29 10:20:39', '2018-11-29 10:20:39');
INSERT INTO t_ds_alertgroup(alert_instance_ids, create_user_id, group_name, description, create_time, update_time)
VALUES (NULL, 1, 'global alert group', 'global alert group', '2018-11-29 10:20:39', '2018-11-29 10:20:39');
-- Records of t_ds_queue,default queue name : default
INSERT INTO t_ds_queue(queue_name, queue, create_time, update_time)
@ -1094,8 +1092,6 @@ CREATE TABLE t_ds_alert_plugin_instance (
create_time timestamp NULL,
update_time timestamp NULL,
instance_name varchar(255) NULL,
instance_type int NOT NULL default '0',
warning_type int NOT NULL default '3',
CONSTRAINT t_ds_alert_plugin_instance_pk PRIMARY KEY (id)
);
@ -2129,27 +2125,6 @@ CREATE INDEX idx_parent_workflow_instance_id ON t_ds_relation_sub_workflow (pare
CREATE INDEX idx_parent_task_code ON t_ds_relation_sub_workflow (parent_task_code);
CREATE INDEX idx_sub_workflow_instance_id ON t_ds_relation_sub_workflow (sub_workflow_instance_id);
--
-- Table structure for table t_ds_alert
--
DROP TABLE IF EXISTS t_ds_listener_event;
CREATE TABLE t_ds_listener_event(
id int NOT NULL,
content text,
sign varchar(64) NOT NULL DEFAULT '',
post_status int NOT NULL DEFAULT '0',
event_type int NOT NULL,
log text,
create_time timestamp DEFAULT NULL,
update_time timestamp DEFAULT NULL,
PRIMARY KEY (id)
);
comment on column t_ds_listener_event.sign is 'sign=sha1(content)';
create index idx_listener_event_post_status on t_ds_listener_event (post_status);
create index idx_listener_event_sign on t_ds_listener_event (sign);
-- ----------------------------
-- Table structure for t_ds_process_task_lineage
-- ----------------------------

23
dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.1_schema/mysql/dolphinscheduler_ddl.sql

@ -15,27 +15,6 @@
* limitations under the License.
*/
-- Modify "t_ds_alertgroup" table
ALTER TABLE `t_ds_alertgroup` AUTO_INCREMENT 3;
-- Modify "t_ds_alert_plugin_instance" table
ALTER TABLE `t_ds_alert_plugin_instance`
ADD COLUMN `instance_type` int NOT NULL DEFAULT 0, ADD COLUMN `warning_type` int NOT NULL DEFAULT 3;
-- Create "t_ds_listener_event" table
CREATE TABLE `t_ds_listener_event`
(
`id` int NOT NULL AUTO_INCREMENT COMMENT "key",
`content` text NULL COMMENT "listener event json content",
`sign` char(64) NOT NULL DEFAULT "" COMMENT "sign=sha1(content)",
`post_status` tinyint NOT NULL DEFAULT 0 COMMENT "0:wait running,1:success,2:failed,3:partial success",
`event_type` int NOT NULL COMMENT "listener event type",
`log` text NULL COMMENT "log",
`create_time` datetime NULL COMMENT "create time",
`update_time` datetime NULL COMMENT "update time",
PRIMARY KEY (`id`),
INDEX `idx_sign` (`sign`),
INDEX `idx_status` (`post_status`)
) CHARSET utf8 COLLATE utf8_bin;
-- modify_data_t_ds_dq_rule_input_entry behavior change
--DROP PROCEDURE if EXISTS modify_data_t_ds_dq_rule_input_entry;
DROP PROCEDURE if EXISTS modify_data_t_ds_dq_rule_input_entry;
@ -192,4 +171,4 @@ END;
d//
delimiter ;
CALL create_idx_t_ds_task_group_queue_in_queue;
DROP PROCEDURE create_idx_t_ds_task_group_queue_in_queue;
DROP PROCEDURE create_idx_t_ds_task_group_queue_in_queue;

3
dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.1_schema/mysql/dolphinscheduler_dml.sql

@ -14,6 +14,3 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
INSERT IGNORE INTO `t_ds_alertgroup`(alert_instance_ids, create_user_id, group_name, description, create_time, update_time)
VALUES (NULL, 1, 'global alert group', 'global alert group', current_timestamp, current_timestamp);

12
dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.1_schema/postgresql/dolphinscheduler_ddl.sql

@ -14,16 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-- Modify "t_ds_alert_plugin_instance" table
ALTER TABLE "t_ds_alert_plugin_instance" ADD COLUMN "instance_type" integer NOT NULL DEFAULT 0, ADD COLUMN "warning_type" integer NOT NULL DEFAULT 3;
-- Create "t_ds_listener_event" table
CREATE TABLE "t_ds_listener_event" ("id" integer NOT NULL, "content" text NULL, "sign" character varying(64) NOT NULL DEFAULT '', "post_status" integer NOT NULL DEFAULT 0, "event_type" integer NOT NULL, "log" text NULL, "create_time" timestamp NULL, "update_time" timestamp NULL, PRIMARY KEY ("id"));
-- Create index "idx_listener_event_post_status" to table: "t_ds_listener_event"
CREATE INDEX "idx_listener_event_post_status" ON "t_ds_listener_event" ("post_status");
-- Create index "idx_listener_event_sign" to table: "t_ds_listener_event"
CREATE INDEX "idx_listener_event_sign" ON "t_ds_listener_event" ("sign");
-- Set comment to column: "sign" on table: "t_ds_listener_event"
COMMENT ON COLUMN "t_ds_listener_event" ."sign" IS 'sign=sha1(content)';
-- modify_data_t_ds_dq_rule_input_entry
delimiter d//
@ -79,4 +69,4 @@ ALTER TABLE "t_ds_task_definition_log" ALTER COLUMN "version" SET DEFAULT 1;
ALTER TABLE "t_ds_process_instance" ALTER COLUMN "process_definition_version" SET NOT NULL, ALTER COLUMN "process_definition_version" SET DEFAULT 1;
ALTER TABLE "t_ds_task_instance" ALTER COLUMN "task_definition_version" SET NOT NULL, ALTER COLUMN "task_definition_version" SET DEFAULT 1;
CREATE INDEX IF NOT EXISTS idx_t_ds_task_group_queue_in_queue ON t_ds_task_group_queue(in_queue);
CREATE INDEX IF NOT EXISTS idx_t_ds_task_group_queue_in_queue ON t_ds_task_group_queue(in_queue);

2
dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.1_schema/postgresql/dolphinscheduler_dml.sql

@ -14,5 +14,3 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
INSERT INTO t_ds_alertgroup(alert_instance_ids, create_user_id, group_name, description, create_time, update_time)
VALUES (NULL, 1, 'global alert group', 'global alert group', '2018-11-29 10:20:39', '2018-11-29 10:20:39');

42
dolphinscheduler-dao/src/main/resources/sql/upgrade/3.3.0_schema/mysql/dolphinscheduler_ddl.sql

@ -84,4 +84,44 @@ CREATE TABLE `t_ds_jdbc_registry_data_change_event`
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time',
PRIMARY KEY (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8;
DEFAULT CHARSET = utf8;
DROP TABLE IF EXISTS `t_ds_listener_event`;
-- drop_column_t_ds_alert_plugin_instance behavior change
DROP PROCEDURE if EXISTS drop_column_t_ds_alert_plugin_instance;
delimiter d//
CREATE PROCEDURE drop_column_t_ds_alert_plugin_instance()
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.COLUMNS
WHERE TABLE_NAME='t_ds_alert_plugin_instance'
AND TABLE_SCHEMA=(SELECT DATABASE())
AND COLUMN_NAME ='instance_type')
THEN
ALTER TABLE `t_ds_alert_plugin_instance`
DROP COLUMN `instance_type`;
END IF;
END;
d//
delimiter ;
CALL drop_column_t_ds_alert_plugin_instance;
DROP PROCEDURE drop_column_t_ds_alert_plugin_instance;
-- drop_column_t_ds_alert_plugin_instance behavior change
DROP PROCEDURE if EXISTS drop_column_t_ds_alert_plugin_instance;
delimiter d//
CREATE PROCEDURE drop_column_t_ds_alert_plugin_instance()
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.COLUMNS
WHERE TABLE_NAME='t_ds_alert_plugin_instance'
AND TABLE_SCHEMA=(SELECT DATABASE())
AND COLUMN_NAME ='warning_type')
THEN
ALTER TABLE `t_ds_alert_plugin_instance`
DROP COLUMN `warning_type`;
END IF;
END;
d//
delimiter ;
CALL drop_column_t_ds_alert_plugin_instance;
DROP PROCEDURE drop_column_t_ds_alert_plugin_instance;

43
dolphinscheduler-dao/src/main/resources/sql/upgrade/3.3.0_schema/postgresql/dolphinscheduler_ddl.sql

@ -81,4 +81,45 @@ create table t_ds_jdbc_registry_data_change_event
jdbc_registry_data text not null,
create_time timestamp not null default current_timestamp,
primary key (id)
);
);
DROP TABLE IF EXISTS t_ds_listener_event;
-- drop_column_t_ds_alert_plugin_instance
delimiter d//
CREATE OR REPLACE FUNCTION drop_column_t_ds_alert_plugin_instance() RETURNS void AS $$
BEGIN
IF EXISTS (SELECT 1
FROM information_schema.columns
WHERE table_name = 't_ds_alert_plugin_instance'
AND column_name = 'instance_type')
THEN
ALTER TABLE t_ds_alert_plugin_instance
DROP COLUMN "instance_type";
END IF;
END;
$$ LANGUAGE plpgsql;
d//
select drop_column_t_ds_alert_plugin_instance();
DROP FUNCTION IF EXISTS drop_column_t_ds_alert_plugin_instance();
-- drop_column_t_ds_alert_plugin_instance
delimiter d//
CREATE OR REPLACE FUNCTION drop_column_t_ds_alert_plugin_instance() RETURNS void AS $$
BEGIN
IF EXISTS (SELECT 1
FROM information_schema.columns
WHERE table_name = 't_ds_alert_plugin_instance'
AND column_name = 'warning_type')
THEN
ALTER TABLE t_ds_alert_plugin_instance
DROP COLUMN "warning_type";
END IF;
END;
$$ LANGUAGE plpgsql;
d//
select drop_column_t_ds_alert_plugin_instance();
DROP FUNCTION IF EXISTS drop_column_t_ds_alert_plugin_instance();

26
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapperTest.java

@ -17,7 +17,6 @@
package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.common.enums.AlertPluginInstanceType;
import org.apache.dolphinscheduler.dao.BaseDaoTest;
import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
import org.apache.dolphinscheduler.dao.entity.PluginDefine;
@ -42,9 +41,6 @@ public class AlertPluginInstanceMapperTest extends BaseDaoTest {
@Autowired
private PluginDefineMapper pluginDefineMapper;
@Autowired
private AlertGroupMapper alertGroupMapper;
/**
* Test function queryAllAlertPluginInstanceList behavior with different size.
*/
@ -95,27 +91,6 @@ public class AlertPluginInstanceMapperTest extends BaseDaoTest {
Assertions.assertEquals(1, matchOneRecord.getTotal());
}
/**
* Test function queryAllGlobalAlertPluginInstanceList returning with different search variables.
*/
@Test
public void testQueryAllGlobalAlertPluginInstanceList() {
List<AlertPluginInstance> withoutSingleOne = alertPluginInstanceMapper.queryAllGlobalAlertPluginInstanceList();
Assertions.assertEquals(0, withoutSingleOne.size());
createNormalAlertPluginInstance("test_normal_instance");
List<AlertPluginInstance> withExactlyOne = alertPluginInstanceMapper.queryAllGlobalAlertPluginInstanceList();
Assertions.assertEquals(0, withExactlyOne.size());
createGlobalAlertPluginInstance("test_global_instance_1");
List<AlertPluginInstance> withExactlyTwo = alertPluginInstanceMapper.queryAllGlobalAlertPluginInstanceList();
Assertions.assertEquals(1, withExactlyTwo.size());
createGlobalAlertPluginInstance("test_global_instance_2");
List<AlertPluginInstance> withExactlyThree = alertPluginInstanceMapper.queryAllGlobalAlertPluginInstanceList();
Assertions.assertEquals(2, withExactlyThree.size());
}
/**
* Create normal alert plugin instance according to given alter plugin name.
*/
@ -131,7 +106,6 @@ public class AlertPluginInstanceMapperTest extends BaseDaoTest {
private void createGlobalAlertPluginInstance(String alterPluginInsName) {
PluginDefine pluginDefine = makeSurePluginDefineExists();
AlertPluginInstance alertPluginInstance = new AlertPluginInstance(pluginDefine.getId(), "", alterPluginInsName);
alertPluginInstance.setInstanceType(AlertPluginInstanceType.GLOBAL);
alertPluginInstanceMapper.insert(alertPluginInstance);
}

136
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ListenerEventMapperTest.java

@ -1,136 +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.dao.mapper;
import org.apache.dolphinscheduler.common.enums.AlertStatus;
import org.apache.dolphinscheduler.common.enums.ListenerEventType;
import org.apache.dolphinscheduler.common.utils.DateUtils;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.dao.BaseDaoTest;
import org.apache.dolphinscheduler.dao.entity.ListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.ServerDownListenerEvent;
import org.apache.commons.codec.digest.DigestUtils;
import java.util.Date;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
/**
* AlertPluginInstanceMapper mapper test
*/
public class ListenerEventMapperTest extends BaseDaoTest {
@Autowired
private ListenerEventMapper listenerEventMapper;
/**
* test insert
*
* @return
*/
@Test
public void testInsert() {
ListenerEvent serverDownListenerEvent = generateServerDownListenerEvent("192.168.x.x");
listenerEventMapper.insert(serverDownListenerEvent);
Assertions.assertTrue(serverDownListenerEvent.getId() > 0);
}
/**
* test batch insert
*
* @return
*/
@Test
public void testBatchInsert() {
ListenerEvent event1 = generateServerDownListenerEvent("192.168.x.1");
ListenerEvent event2 = generateServerDownListenerEvent("192.168.x.2");
listenerEventMapper.batchInsert(Lists.newArrayList(event1, event2));
Assertions.assertEquals(listenerEventMapper.selectCount(new QueryWrapper<>()), 2L);
}
/**
* test list listener event by status
*
* @return
*/
@Test
public void testListingListenerEventByStatus() {
ListenerEvent event1 = generateServerDownListenerEvent("192.168.x.1");
ListenerEvent event2 = generateServerDownListenerEvent("192.168.x.2");
listenerEventMapper.batchInsert(Lists.newArrayList(event1, event2));
List<ListenerEvent> listenerEvents =
listenerEventMapper.listingListenerEventByStatus(-1, AlertStatus.WAIT_EXECUTION.getCode(), 50);
Assertions.assertEquals(listenerEvents.size(), 2);
}
/**
* test update server down event
*
* @return
*/
@Test
public void testUpdateListenerEvent() {
ListenerEvent event = generateServerDownListenerEvent("192.168.x.1");
listenerEventMapper.insert(event);
listenerEventMapper.updateListenerEvent(event.getId(), AlertStatus.EXECUTION_FAILURE, "fail", new Date());
ListenerEvent updatedEvent = listenerEventMapper.selectById(event.getId());
Assertions.assertEquals(updatedEvent.getPostStatus(), AlertStatus.EXECUTION_FAILURE);
Assertions.assertEquals(updatedEvent.getLog(), "fail");
}
/**
* test delete listener event
*/
@Test
public void testDeleteListenerEvent() {
ListenerEvent event = generateServerDownListenerEvent("192.168.x.1");
listenerEventMapper.insert(event);
listenerEventMapper.deleteById(event);
ListenerEvent actualAlert = listenerEventMapper.selectById(event.getId());
Assertions.assertNull(actualAlert);
}
/**
* create server down event
*
* @param host worker host
* @return listener event
*/
private ListenerEvent generateServerDownListenerEvent(String host) {
ServerDownListenerEvent event = new ServerDownListenerEvent();
event.setEventTime(new Date());
event.setHost(host);
event.setType("WORKER");
ListenerEvent listenerEvent = new ListenerEvent();
listenerEvent.setEventType(ListenerEventType.SERVER_DOWN);
listenerEvent.setContent(JSONUtils.toJsonString(event));
listenerEvent.setSign(DigestUtils.sha1Hex(listenerEvent.getContent()));
listenerEvent.setLog("success");
listenerEvent.setCreateTime(DateUtils.getCurrentDate());
listenerEvent.setUpdateTime(DateUtils.getCurrentDate());
listenerEvent.setPostStatus(AlertStatus.WAIT_EXECUTION);
return listenerEvent;
}
}

79
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/repository/impl/ListenerEventDaoImplTest.java

@ -1,79 +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.dao.repository.impl;
import static com.google.common.truth.Truth.assertThat;
import org.apache.dolphinscheduler.common.enums.AlertStatus;
import org.apache.dolphinscheduler.common.enums.ListenerEventType;
import org.apache.dolphinscheduler.dao.BaseDaoTest;
import org.apache.dolphinscheduler.dao.entity.ListenerEvent;
import org.apache.dolphinscheduler.dao.repository.ListenerEventDao;
import java.util.Date;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
class ListenerEventDaoImplTest extends BaseDaoTest {
@Autowired
private ListenerEventDao listenerEventDao;
@Test
void listingPendingEvents() {
int minId = -1;
int limit = 10;
assertThat(listenerEventDao.listingPendingEvents(minId, limit)).isEmpty();
ListenerEvent listenerEvent = ListenerEvent.builder()
.eventType(ListenerEventType.SERVER_DOWN)
.sign("test")
.createTime(new Date())
.updateTime(new Date())
.postStatus(AlertStatus.WAIT_EXECUTION)
.build();
listenerEventDao.insert(listenerEvent);
listenerEvent = ListenerEvent.builder()
.eventType(ListenerEventType.SERVER_DOWN)
.sign("test")
.createTime(new Date())
.updateTime(new Date())
.postStatus(AlertStatus.EXECUTION_SUCCESS)
.build();
listenerEventDao.insert(listenerEvent);
assertThat(listenerEventDao.listingPendingEvents(minId, limit)).hasSize(1);
}
@Test
void updateListenerEvent() {
ListenerEvent listenerEvent = ListenerEvent.builder()
.eventType(ListenerEventType.SERVER_DOWN)
.sign("test")
.createTime(new Date())
.updateTime(new Date())
.postStatus(AlertStatus.WAIT_EXECUTION)
.build();
listenerEventDao.insert(listenerEvent);
listenerEventDao.updateListenerEvent(listenerEvent.getId(), AlertStatus.EXECUTION_SUCCESS, "test", new Date());
assertThat(listenerEventDao.queryById(listenerEvent.getId()).getPostStatus())
.isEqualTo(AlertStatus.EXECUTION_SUCCESS);
}
}

6
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/ClusterStateMonitors.java

@ -18,7 +18,6 @@
package org.apache.dolphinscheduler.server.master.cluster;
import org.apache.dolphinscheduler.dao.AlertDao;
import org.apache.dolphinscheduler.service.alert.ListenerEventAlertManager;
import lombok.extern.slf4j.Slf4j;
@ -32,9 +31,6 @@ public class ClusterStateMonitors {
@Autowired
private ClusterManager clusterManager;
@Autowired
private ListenerEventAlertManager listenerEventAlertManager;
@Autowired
private AlertDao alertDao;
@ -49,12 +45,10 @@ public class ClusterStateMonitors {
void masterRemoved(MasterServerMetadata masterServer) {
// todo: unify the alert message
alertDao.sendServerStoppedAlert(masterServer.getAddress(), "MASTER");
listenerEventAlertManager.publishServerDownListenerEvent(masterServer.getAddress(), "MASTER");
}
void workerRemoved(WorkerServerMetadata workerServer) {
alertDao.sendServerStoppedAlert(workerServer.getAddress(), "WORKER");
listenerEventAlertManager.publishServerDownListenerEvent(workerServer.getAddress(), "WORKER");
}
}

4
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/event/TaskStateEventHandler.java

@ -54,10 +54,6 @@ public class TaskStateEventHandler implements StateEventHandler {
"Handle task instance state event, the current task instance state {} will be changed to {}",
task.getState().name(), taskStateEvent.getStatus().name());
if (taskStateEvent.getStatus().isRunning()) {
workflowExecuteRunnable.taskStart(task);
}
Set<Long> completeTaskSet = workflowExecuteRunnable.getCompleteTaskCodes();
if (task.getState().isFinished()
&& (taskStateEvent.getStatus() != null && taskStateEvent.getStatus().isRunning())) {

26
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkflowExecuteRunnable.java

@ -76,7 +76,6 @@ import org.apache.dolphinscheduler.server.master.metrics.TaskMetrics;
import org.apache.dolphinscheduler.server.master.runner.execute.DefaultTaskExecuteRunnableFactory;
import org.apache.dolphinscheduler.server.master.runner.taskgroup.TaskGroupCoordinator;
import org.apache.dolphinscheduler.server.master.utils.WorkflowInstanceUtils;
import org.apache.dolphinscheduler.service.alert.ListenerEventAlertManager;
import org.apache.dolphinscheduler.service.alert.ProcessAlertManager;
import org.apache.dolphinscheduler.service.command.CommandService;
import org.apache.dolphinscheduler.service.cron.CronUtils;
@ -218,8 +217,6 @@ public class WorkflowExecuteRunnable implements IWorkflowExecuteRunnable {
private final MasterConfig masterConfig;
private final ListenerEventAlertManager listenerEventAlertManager;
private final TaskGroupCoordinator taskGroupCoordinator;
public WorkflowExecuteRunnable(
@ -233,7 +230,6 @@ public class WorkflowExecuteRunnable implements IWorkflowExecuteRunnable {
@NonNull CuringParamsService curingParamsService,
@NonNull TaskInstanceDao taskInstanceDao,
@NonNull DefaultTaskExecuteRunnableFactory defaultTaskExecuteRunnableFactory,
@NonNull ListenerEventAlertManager listenerEventAlertManager,
@NonNull TaskGroupCoordinator taskGroupCoordinator) {
this.processService = processService;
this.commandService = commandService;
@ -245,7 +241,6 @@ public class WorkflowExecuteRunnable implements IWorkflowExecuteRunnable {
this.curingParamsService = curingParamsService;
this.taskInstanceDao = taskInstanceDao;
this.defaultTaskExecuteRunnableFactory = defaultTaskExecuteRunnableFactory;
this.listenerEventAlertManager = listenerEventAlertManager;
this.taskGroupCoordinator = taskGroupCoordinator;
TaskMetrics.registerTaskPrepared(standByTaskInstancePriorityQueue::size);
}
@ -329,18 +324,6 @@ public class WorkflowExecuteRunnable implements IWorkflowExecuteRunnable {
return this.stateEvents.size();
}
public void processStart() {
ProcessInstance workflowInstance = workflowExecuteContext.getWorkflowInstance();
ProjectUser projectUser = processService.queryProjectWithUserByProcessInstanceId(workflowInstance.getId());
this.listenerEventAlertManager.publishProcessStartListenerEvent(workflowInstance, projectUser);
}
public void taskStart(TaskInstance taskInstance) {
ProcessInstance workflowInstance = workflowExecuteContext.getWorkflowInstance();
ProjectUser projectUser = processService.queryProjectWithUserByProcessInstanceId(workflowInstance.getId());
this.listenerEventAlertManager.publishTaskStartListenerEvent(workflowInstance, taskInstance, projectUser);
}
public void processTimeout() {
ProcessInstance workflowInstance = workflowExecuteContext.getWorkflowInstance();
ProjectUser projectUser = processService.queryProjectWithUserByProcessInstanceId(workflowInstance.getId());
@ -372,9 +355,7 @@ public class WorkflowExecuteRunnable implements IWorkflowExecuteRunnable {
workflowInstance.setVarPool(VarPoolUtils.mergeVarPoolJsonString(
Lists.newArrayList(workflowInstance.getVarPool(), taskInstance.getVarPool())));
processInstanceDao.upsertProcessInstance(workflowInstance);
ProjectUser projectUser =
processService.queryProjectWithUserByProcessInstanceId(workflowInstance.getId());
listenerEventAlertManager.publishTaskEndListenerEvent(workflowInstance, taskInstance, projectUser);
// save the cacheKey only if the task is defined as cache task and the task is success
if (taskInstance.getIsCache().equals(Flag.YES)) {
saveCacheTaskInstance(taskInstance);
@ -387,7 +368,6 @@ public class WorkflowExecuteRunnable implements IWorkflowExecuteRunnable {
} else if (taskInstance.getState().isFailure() || taskInstance.getState().isKill()
|| taskInstance.getState().isStop()) {
completeTaskSet.add(taskInstance.getTaskCode());
listenerEventAlertManager.publishTaskFailListenerEvent(workflowInstance, taskInstance);
if (isTaskNeedPutIntoErrorMap(taskInstance)) {
errorTaskMap.put(taskInstance.getTaskCode(), taskInstance.getId());
}
@ -670,7 +650,6 @@ public class WorkflowExecuteRunnable implements IWorkflowExecuteRunnable {
log.info("workflowStatue changed to :{}", workflowRunnableStatus);
}
if (workflowRunnableStatus == WorkflowRunnableStatus.INITIALIZE_QUEUE) {
processStart();
submitPostNode(null);
workflowRunnableStatus = WorkflowRunnableStatus.STARTED;
log.info("workflowStatue changed to :{}", workflowRunnableStatus);
@ -699,9 +678,6 @@ public class WorkflowExecuteRunnable implements IWorkflowExecuteRunnable {
processAlertManager.sendAlertProcessInstance(workflowInstance, getValidTaskList(), projectUser);
if (workflowInstance.getState().isSuccess()) {
processAlertManager.closeAlert(workflowInstance);
listenerEventAlertManager.publishProcessEndListenerEvent(workflowInstance, projectUser);
} else {
listenerEventAlertManager.publishProcessFailListenerEvent(workflowInstance, projectUser);
}
taskInstanceMap.forEach((id, taskInstance) -> {
if (taskInstance != null && taskInstance.getTaskGroupId() > 0) {

5
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkflowExecuteRunnableFactory.java

@ -24,7 +24,6 @@ import org.apache.dolphinscheduler.server.master.config.MasterConfig;
import org.apache.dolphinscheduler.server.master.exception.WorkflowCreateException;
import org.apache.dolphinscheduler.server.master.runner.execute.DefaultTaskExecuteRunnableFactory;
import org.apache.dolphinscheduler.server.master.runner.taskgroup.TaskGroupCoordinator;
import org.apache.dolphinscheduler.service.alert.ListenerEventAlertManager;
import org.apache.dolphinscheduler.service.alert.ProcessAlertManager;
import org.apache.dolphinscheduler.service.command.CommandService;
import org.apache.dolphinscheduler.service.expand.CuringParamsService;
@ -71,9 +70,6 @@ public class WorkflowExecuteRunnableFactory {
@Autowired
private WorkflowExecuteContextFactory workflowExecuteContextFactory;
@Autowired
private ListenerEventAlertManager listenerEventAlertManager;
@Autowired
private TaskGroupCoordinator taskGroupCoordinator;
@ -92,7 +88,6 @@ public class WorkflowExecuteRunnableFactory {
curingGlobalParamsService,
taskInstanceDao,
defaultTaskExecuteRunnableFactory,
listenerEventAlertManager,
taskGroupCoordinator));
} catch (Exception ex) {
throw new WorkflowCreateException("Create WorkflowExecuteRunnable failed", ex);

5
dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/runner/WorkflowExecuteRunnableTest.java

@ -40,7 +40,6 @@ import org.apache.dolphinscheduler.server.master.config.MasterConfig;
import org.apache.dolphinscheduler.server.master.graph.IWorkflowGraph;
import org.apache.dolphinscheduler.server.master.runner.execute.DefaultTaskExecuteRunnableFactory;
import org.apache.dolphinscheduler.server.master.runner.taskgroup.TaskGroupCoordinator;
import org.apache.dolphinscheduler.service.alert.ListenerEventAlertManager;
import org.apache.dolphinscheduler.service.alert.ProcessAlertManager;
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext;
import org.apache.dolphinscheduler.service.command.CommandService;
@ -103,8 +102,6 @@ public class WorkflowExecuteRunnableTest {
private WorkflowExecuteContextFactory workflowExecuteContextFactory;
private ListenerEventAlertManager listenerEventAlertManager;
private TaskGroupCoordinator taskGroupCoordinator;
private WorkflowExecuteContext workflowExecuteContext;
@ -124,7 +121,6 @@ public class WorkflowExecuteRunnableTest {
taskDefinitionLogDao = Mockito.mock(TaskDefinitionLogDao.class);
defaultTaskExecuteRunnableFactory = Mockito.mock(DefaultTaskExecuteRunnableFactory.class);
workflowExecuteContextFactory = Mockito.mock(WorkflowExecuteContextFactory.class);
listenerEventAlertManager = Mockito.mock(ListenerEventAlertManager.class);
Map<String, String> cmdParam = new HashMap<>();
cmdParam.put(CMD_PARAM_COMPLEMENT_DATA_START_DATE, "2020-01-01 00:00:00");
@ -157,7 +153,6 @@ public class WorkflowExecuteRunnableTest {
curingGlobalParamsService,
taskInstanceDao,
defaultTaskExecuteRunnableFactory,
listenerEventAlertManager,
taskGroupCoordinator));
}

283
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/ListenerEventAlertManager.java

@ -1,283 +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.service.alert;
import org.apache.dolphinscheduler.common.enums.AlertStatus;
import org.apache.dolphinscheduler.common.enums.ListenerEventType;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
import org.apache.dolphinscheduler.dao.entity.ListenerEvent;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog;
import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.entity.ProjectUser;
import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog;
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.entity.event.AbstractListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.ProcessDefinitionCreatedListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.ProcessDefinitionDeletedListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.ProcessDefinitionUpdatedListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.ProcessEndListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.ProcessFailListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.ProcessStartListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.ServerDownListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.TaskEndListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.TaskFailListenerEvent;
import org.apache.dolphinscheduler.dao.entity.event.TaskStartListenerEvent;
import org.apache.dolphinscheduler.dao.mapper.AlertPluginInstanceMapper;
import org.apache.dolphinscheduler.dao.mapper.ListenerEventMapper;
import org.apache.dolphinscheduler.service.process.ProcessService;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections4.CollectionUtils;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class ListenerEventAlertManager {
@Value("${alert.alarm-suppression.crash:60}")
private int crashAlarmSuppression;
@Autowired
private ListenerEventMapper listenerEventMapper;
@Autowired
private AlertPluginInstanceMapper alertPluginInstanceMapper;
@Autowired
private ProcessService processService;
public void publishServerDownListenerEvent(String host, String type) {
ServerDownListenerEvent event = new ServerDownListenerEvent();
event.setEventTime(new Date());
event.setHost(host);
event.setType(type);
this.saveEvent(event);
}
public void publishProcessDefinitionCreatedListenerEvent(User user,
ProcessDefinition processDefinition,
List<TaskDefinitionLog> taskDefinitionLogs,
List<ProcessTaskRelationLog> processTaskRelationLogs) {
ProcessDefinitionCreatedListenerEvent event = new ProcessDefinitionCreatedListenerEvent(processDefinition);
event.setUserName(user.getUserName());
event.setModifyBy(user.getUserName());
event.setTaskDefinitionLogs(taskDefinitionLogs);
event.setTaskRelationList(processTaskRelationLogs);
this.saveEvent(event);
}
public void publishProcessDefinitionUpdatedListenerEvent(User user, ProcessDefinition processDefinition,
List<TaskDefinitionLog> taskDefinitionLogs,
List<ProcessTaskRelationLog> processTaskRelationLogs) {
ProcessDefinitionUpdatedListenerEvent event = new ProcessDefinitionUpdatedListenerEvent(processDefinition);
event.setTaskDefinitionLogs(taskDefinitionLogs);
event.setTaskRelationList(processTaskRelationLogs);
event.setUserName(user.getUserName());
event.setModifyBy(user.getUserName());
this.saveEvent(event);
}
public void publishProcessDefinitionDeletedListenerEvent(User user, Project project,
ProcessDefinition processDefinition) {
ProcessDefinitionDeletedListenerEvent event = new ProcessDefinitionDeletedListenerEvent();
event.setProjectId(project.getId());
event.setProjectCode(project.getCode());
event.setProjectName(project.getName());
event.setOwner(processDefinition.getUserName());
event.setId(processDefinition.getId());
event.setCode(processDefinition.getCode());
event.setName(processDefinition.getName());
event.setEventTime(new Date());
event.setUserId(user.getId());
event.setModifiedBy(user.getUserName());
this.saveEvent(event);
}
public void publishProcessStartListenerEvent(ProcessInstance processInstance, ProjectUser projectUser) {
ProcessStartListenerEvent event = new ProcessStartListenerEvent();
event.setProjectCode(projectUser.getProjectCode());
event.setProjectName(projectUser.getProjectName());
event.setOwner(projectUser.getUserName());
event.setProcessId(processInstance.getId());
event.setProcessDefinitionCode(processInstance.getProcessDefinitionCode());
event.setProcessName(processInstance.getName());
event.setProcessType(processInstance.getCommandType());
event.setProcessState(processInstance.getState());
event.setRunTimes(processInstance.getRunTimes());
event.setRecovery(processInstance.getRecovery());
event.setProcessStartTime(processInstance.getStartTime());
this.saveEvent(event);
}
public void publishProcessEndListenerEvent(ProcessInstance processInstance, ProjectUser projectUser) {
ProcessEndListenerEvent event = new ProcessEndListenerEvent();
event.setProjectCode(projectUser.getProjectCode());
event.setProjectName(projectUser.getProjectName());
event.setOwner(projectUser.getUserName());
event.setProcessId(processInstance.getId());
event.setProcessDefinitionCode(processInstance.getProcessDefinitionCode());
event.setProcessName(processInstance.getName());
event.setProcessType(processInstance.getCommandType());
event.setProcessState(processInstance.getState());
event.setRecovery(processInstance.getRecovery());
event.setRunTimes(processInstance.getRunTimes());
event.setProcessStartTime(processInstance.getStartTime());
event.setProcessEndTime(processInstance.getEndTime());
event.setProcessHost(processInstance.getHost());
this.saveEvent(event);
}
public void publishProcessFailListenerEvent(ProcessInstance processInstance,
ProjectUser projectUser) {
ProcessFailListenerEvent event = new ProcessFailListenerEvent();
event.setProjectCode(projectUser.getProjectCode());
event.setProjectName(projectUser.getProjectName());
event.setOwner(projectUser.getUserName());
event.setProcessId(processInstance.getId());
event.setProcessDefinitionCode(processInstance.getProcessDefinitionCode());
event.setProcessName(processInstance.getName());
event.setProcessType(processInstance.getCommandType());
event.setProcessState(processInstance.getState());
event.setRecovery(processInstance.getRecovery());
event.setRunTimes(processInstance.getRunTimes());
event.setProcessStartTime(processInstance.getStartTime());
event.setProcessEndTime(processInstance.getEndTime());
event.setProcessHost(processInstance.getHost());
this.saveEvent(event);
}
public void publishTaskStartListenerEvent(ProcessInstance processInstance,
TaskInstance taskInstance,
ProjectUser projectUser) {
TaskStartListenerEvent event = new TaskStartListenerEvent();
event.setProjectCode(projectUser.getProjectCode());
event.setProjectName(projectUser.getProjectName());
event.setOwner(projectUser.getUserName());
event.setProcessId(processInstance.getId());
event.setProcessDefinitionCode(processInstance.getProcessDefinitionCode());
event.setProcessName(processInstance.getName());
event.setTaskCode(taskInstance.getTaskCode());
event.setTaskName(taskInstance.getName());
event.setTaskType(taskInstance.getTaskType());
event.setTaskState(taskInstance.getState());
event.setTaskStartTime(taskInstance.getStartTime());
event.setTaskEndTime(taskInstance.getEndTime());
event.setTaskHost(taskInstance.getHost());
event.setLogPath(taskInstance.getLogPath());
this.saveEvent(event);
}
public void publishTaskEndListenerEvent(ProcessInstance processInstance,
TaskInstance taskInstance,
ProjectUser projectUser) {
TaskEndListenerEvent event = new TaskEndListenerEvent();
event.setProjectCode(projectUser.getProjectCode());
event.setProjectName(projectUser.getProjectName());
event.setOwner(projectUser.getUserName());
event.setProcessId(processInstance.getId());
event.setProcessDefinitionCode(processInstance.getProcessDefinitionCode());
event.setProcessName(processInstance.getName());
event.setTaskCode(taskInstance.getTaskCode());
event.setTaskName(taskInstance.getName());
event.setTaskType(taskInstance.getTaskType());
event.setTaskState(taskInstance.getState());
event.setTaskStartTime(taskInstance.getStartTime());
event.setTaskEndTime(taskInstance.getEndTime());
event.setTaskHost(taskInstance.getHost());
event.setLogPath(taskInstance.getLogPath());
this.saveEvent(event);
}
public void publishTaskFailListenerEvent(ProcessInstance processInstance,
TaskInstance taskInstance) {
ProjectUser projectUser = processService.queryProjectWithUserByProcessInstanceId(processInstance.getId());
TaskFailListenerEvent event = new TaskFailListenerEvent();
event.setProjectCode(projectUser.getProjectCode());
event.setProjectName(projectUser.getProjectName());
event.setOwner(projectUser.getUserName());
event.setProcessId(processInstance.getId());
event.setProcessDefinitionCode(processInstance.getProcessDefinitionCode());
event.setProcessName(processInstance.getName());
event.setTaskCode(taskInstance.getTaskCode());
event.setTaskName(taskInstance.getName());
event.setTaskType(taskInstance.getTaskType());
event.setTaskState(taskInstance.getState());
event.setTaskStartTime(taskInstance.getStartTime());
event.setTaskEndTime(taskInstance.getEndTime());
event.setTaskHost(taskInstance.getHost());
event.setLogPath(taskInstance.getLogPath());
this.saveEvent(event);
}
private void saveEvent(AbstractListenerEvent event) {
if (!needSendGlobalListenerEvent()) {
return;
}
ListenerEvent listenerEvent = new ListenerEvent();
String content = JSONUtils.toJsonString(event);
listenerEvent.setContent(content);
listenerEvent.setPostStatus(AlertStatus.WAIT_EXECUTION);
listenerEvent.setSign(generateSign(content));
listenerEvent.setCreateTime(new Date());
listenerEvent.setUpdateTime(new Date());
listenerEvent.setEventType(event.getEventType());
if (event.getEventType() == ListenerEventType.SERVER_DOWN) {
saveServerDownEvent(listenerEvent);
} else {
saveNormalEvent(listenerEvent);
}
}
private void saveNormalEvent(ListenerEvent listenerEvent) {
int insert = listenerEventMapper.insert(listenerEvent);
if (insert < 1) {
log.error("insert listener event failed: {}", listenerEvent);
}
}
private void saveServerDownEvent(ListenerEvent listenerEvent) {
Date crashAlarmSuppressionStartTime = Date.from(
LocalDateTime.now().plusMinutes(-crashAlarmSuppression).atZone(ZoneId.systemDefault()).toInstant());
listenerEventMapper.insertServerDownEvent(listenerEvent, crashAlarmSuppressionStartTime);
}
private String generateSign(String content) {
return DigestUtils.sha256Hex(content).toLowerCase();
}
private boolean needSendGlobalListenerEvent() {
List<AlertPluginInstance> globalPluginInstanceList =
alertPluginInstanceMapper.queryAllGlobalAlertPluginInstanceList();
return CollectionUtils.isNotEmpty(globalPluginInstanceList);
}
}

150
dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/ListenerEventAlertManagerTest.java

@ -1,150 +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.service.alert;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog;
import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.entity.ProjectUser;
import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog;
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.AlertPluginInstanceMapper;
import org.apache.dolphinscheduler.dao.mapper.ListenerEventMapper;
import org.apache.dolphinscheduler.service.process.ProcessService;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
/**
* ProcessAlertManager Test
*/
@ExtendWith(MockitoExtension.class)
public class ListenerEventAlertManagerTest {
@InjectMocks
ListenerEventAlertManager listenerEventAlertManager;
@Mock
AlertPluginInstanceMapper alertPluginInstanceMapper;
@Mock
ListenerEventMapper listenerEventMapper;
@Mock
ProcessService processService;
@Test
public void sendServerDownListenerEventTest() {
String host = "127.0.0.1";
String type = "WORKER";
List<AlertPluginInstance> globalPluginInstanceList = new ArrayList<>();
AlertPluginInstance instance = new AlertPluginInstance(1, "instanceParams", "instanceName");
globalPluginInstanceList.add(instance);
when(alertPluginInstanceMapper.queryAllGlobalAlertPluginInstanceList())
.thenReturn(globalPluginInstanceList);
Mockito.doNothing().when(listenerEventMapper).insertServerDownEvent(any(), any());
listenerEventAlertManager.publishServerDownListenerEvent(host, type);
}
@Test
public void sendProcessDefinitionCreatedListenerEvent() {
User user = Mockito.mock(User.class);
ProcessDefinition processDefinition = Mockito.mock(ProcessDefinition.class);
List<TaskDefinitionLog> taskDefinitionLogs = new ArrayList<>();
List<ProcessTaskRelationLog> processTaskRelationLogs = new ArrayList<>();
AlertPluginInstance instance = new AlertPluginInstance(1, "instanceParams", "instanceName");
List<AlertPluginInstance> globalPluginInstanceList = new ArrayList<>();
globalPluginInstanceList.add(instance);
when(alertPluginInstanceMapper.queryAllGlobalAlertPluginInstanceList())
.thenReturn(globalPluginInstanceList);
when(listenerEventMapper.insert(any())).thenReturn(1);
listenerEventAlertManager.publishProcessDefinitionCreatedListenerEvent(user, processDefinition,
taskDefinitionLogs, processTaskRelationLogs);
}
@Test
public void sendProcessDefinitionUpdatedListenerEvent() {
User user = new User();
ProcessDefinition processDefinition = new ProcessDefinition();
List<TaskDefinitionLog> taskDefinitionLogs = new ArrayList<>();
List<ProcessTaskRelationLog> processTaskRelationLogs = new ArrayList<>();
listenerEventAlertManager.publishProcessDefinitionUpdatedListenerEvent(user, processDefinition,
taskDefinitionLogs, processTaskRelationLogs);
}
@Test
public void sendProcessDefinitionDeletedListenerEvent() {
User user = new User();
Project project = new Project();
ProcessDefinition processDefinition = new ProcessDefinition();
listenerEventAlertManager.publishProcessDefinitionDeletedListenerEvent(user, project, processDefinition);
}
@Test
public void sendProcessStartListenerEvent() {
ProcessInstance processInstance = new ProcessInstance();
ProjectUser projectUser = new ProjectUser();
listenerEventAlertManager.publishProcessStartListenerEvent(processInstance, projectUser);
}
@Test
public void sendProcessEndListenerEvent() {
ProcessInstance processInstance = new ProcessInstance();
ProjectUser projectUser = new ProjectUser();
listenerEventAlertManager.publishProcessEndListenerEvent(processInstance, projectUser);
}
@Test
public void sendProcessFailListenerEvent() {
ProcessInstance processInstance = new ProcessInstance();
ProjectUser projectUser = new ProjectUser();
listenerEventAlertManager.publishProcessFailListenerEvent(processInstance, projectUser);
}
@Test
public void sendTaskStartListenerEvent() {
ProcessInstance processInstance = Mockito.mock(ProcessInstance.class);
TaskInstance taskInstance = Mockito.mock(TaskInstance.class);
ProjectUser projectUser = Mockito.mock(ProjectUser.class);
listenerEventAlertManager.publishTaskStartListenerEvent(processInstance, taskInstance, projectUser);
}
@Test
public void sendTaskEndListenerEvent() {
ProcessInstance processInstance = Mockito.mock(ProcessInstance.class);
TaskInstance taskInstance = Mockito.mock(TaskInstance.class);
ProjectUser projectUser = Mockito.mock(ProjectUser.class);
listenerEventAlertManager.publishTaskEndListenerEvent(processInstance, taskInstance, projectUser);
}
@Test
public void sendTaskFailListenerEvent() {
ProcessInstance processInstance = Mockito.mock(ProcessInstance.class);
TaskInstance taskInstance = Mockito.mock(TaskInstance.class);
when(processService.queryProjectWithUserByProcessInstanceId(processInstance.getId()))
.thenReturn(new ProjectUser());
listenerEventAlertManager.publishTaskFailListenerEvent(processInstance, taskInstance);
}
}

2
dolphinscheduler-ui/src/locales/en_US/security.ts

@ -201,8 +201,6 @@ export default {
alarm_instance_name: 'Alarm instance name',
alarm_instance_name_tips: 'Please enter alarm plugin instance name',
alarm_plugin_name: 'Alarm plugin name',
alarm_instance_type: 'Alarm instance type',
is_global_instance: 'Is Global Instance',
create_time: 'Create Time',
update_time: 'Update Time',
operation: 'Operation',

2
dolphinscheduler-ui/src/locales/zh_CN/security.ts

@ -197,8 +197,6 @@ export default {
alarm_instance_name: '告警实例名称',
alarm_instance_name_tips: '请输入告警实例名称',
alarm_plugin_name: '告警插件名称',
alarm_instance_type: '告警实例类型',
is_global_instance: '是否全局告警实例',
create_time: '创建时间',
update_time: '更新时间',
operation: '操作',

7
dolphinscheduler-ui/src/service/modules/alert-group/index.ts

@ -41,13 +41,6 @@ export function listAlertGroupById(): any {
})
}
export function listNormalAlertGroupById(): any {
return axios({
url: '/alert-groups/normal-list',
method: 'get'
})
}
export function queryAlertGroupById(data: IdReq): any {
return axios({
url: '/alert-groups/query',

3
dolphinscheduler-ui/src/service/modules/alert-plugin/types.ts

@ -24,8 +24,6 @@ interface ListReq {
interface PluginInstanceReq {
instanceName: string
pluginDefineId: number
instanceType: string
warningType: string
pluginInstanceParams: string
}
@ -41,7 +39,6 @@ interface InstanceNameReq {
interface UpdatePluginInstanceReq {
alertPluginInstanceId: number
instanceName: string
warningType: string
pluginInstanceParams: string
}

4
dolphinscheduler-ui/src/views/projects/preference/components/use-alert-group.ts

@ -18,7 +18,7 @@
import { ref, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import type { IJsonItem } from '../../task/components/node/types'
import { listNormalAlertGroupById } from '@/service/modules/alert-group'
import { listAlertGroupById } from '@/service/modules/alert-group'
export function useAlertGroup(): IJsonItem {
const { t } = useI18n()
@ -26,7 +26,7 @@ export function useAlertGroup(): IJsonItem {
const options = ref([] as { label: string; value: string }[])
const getAlertGroups = async () => {
const res = await listNormalAlertGroupById()
const res = await listAlertGroupById()
options.value = res.map((item: any) => ({
label: item.groupName,
value: item.id

4
dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-sql-type.ts

@ -17,7 +17,7 @@
import { ref, onMounted, computed, h } from 'vue'
import { useI18n } from 'vue-i18n'
import { listNormalAlertGroupById } from '@/service/modules/alert-group'
import { listAlertGroupById } from '@/service/modules/alert-group'
import styles from '../index.module.scss'
import type { IJsonItem } from '../types'
@ -43,7 +43,7 @@ export function useSqlType(model: { [field: string]: any }): IJsonItem[] {
const getGroups = async () => {
if (groupsLoading.value) return
groupsLoading.value = true
const res = await listNormalAlertGroupById()
const res = await listAlertGroupById()
groups.value = res.map((item: { id: number; groupName: string }) => ({
label: item.groupName,
value: item.id

4
dolphinscheduler-ui/src/views/projects/task/definition/components/use-start.tsx

@ -24,7 +24,7 @@ import { queryProcessDefinitionByCode } from '@/service/modules/process-definiti
import { queryAllWorkerGroups } from '@/service/modules/worker-groups'
import { queryTenantList } from '@/service/modules/tenants'
import { queryAllEnvironmentList } from '@/service/modules/environment'
import { listNormalAlertGroupById } from '@/service/modules/alert-group'
import { listAlertGroupById } from '@/service/modules/alert-group'
import type { EnvironmentItem } from '@/service/modules/environment/types'
import type { IStartState } from '../types'
@ -90,7 +90,7 @@ export const useStart = (
}
const getAlertGroups = () => {
listNormalAlertGroupById().then((res: any) => {
listAlertGroupById().then((res: any) => {
variables.startState.alertGroups = res.map((item: any) => ({
label: item.groupName,
value: item.id

4
dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag-startup-param.tsx

@ -18,7 +18,7 @@
import _ from 'lodash'
import { defineComponent, onMounted, PropType, ref, computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { listNormalAlertGroupById } from '@/service/modules/alert-group'
import { listAlertGroupById } from '@/service/modules/alert-group'
import { queryAllWorkerGroups } from '@/service/modules/worker-groups'
import { runningType, warningTypeList } from '@/common/common'
import { IStartupParam } from './types'
@ -42,7 +42,7 @@ export default defineComponent({
const commandParam = JSON.parse(props.startupParam?.commandParam || '{}')
const getAlertGroupList = () => {
listNormalAlertGroupById().then((res: any) => {
listAlertGroupById().then((res: any) => {
alertGroupListRef.value = res
})
}

4
dolphinscheduler-ui/src/views/projects/workflow/definition/components/use-modal.ts

@ -27,7 +27,7 @@ import {
queryProcessDefinitionByCode
} from '@/service/modules/process-definition'
import { queryAllEnvironmentList } from '@/service/modules/environment'
import { listNormalAlertGroupById } from '@/service/modules/alert-group'
import { listAlertGroupById } from '@/service/modules/alert-group'
import { startProcessInstance } from '@/service/modules/executors'
import {
createSchedule,
@ -250,7 +250,7 @@ export function useModal(
}
const getAlertGroups = () => {
listNormalAlertGroupById().then((res: any) => {
listAlertGroupById().then((res: any) => {
variables.alertGroups = res.map((item: any) => ({
label: item.groupName,
value: item.id

16
dolphinscheduler-ui/src/views/security/alarm-group-manage/components/alarm-group-modal.tsx

@ -80,9 +80,11 @@ const AlarmGroupModal = defineComponent({
} else {
variables.model.id = props.row.id
variables.model.groupName = props.row.groupName
variables.model.alertInstanceIds = props.row.alertInstanceIds
.split(',')
.map((item: string) => Number(item))
if (props.row.alertInstanceIds != null) {
variables.model.alertInstanceIds = props.row.alertInstanceIds
.split(',')
.map((item: string) => Number(item))
}
variables.model.description = props.row.description
}
}
@ -93,9 +95,11 @@ const AlarmGroupModal = defineComponent({
() => {
variables.model.id = props.row.id
variables.model.groupName = props.row.groupName
variables.model.alertInstanceIds = props.row.alertInstanceIds
.split(',')
.map((item: string) => Number(item))
if (props.row.alertInstanceIds != null) {
variables.model.alertInstanceIds = props.row.alertInstanceIds
.split(',')
.map((item: string) => Number(item))
}
variables.model.description = props.row.description
}
)

45
dolphinscheduler-ui/src/views/security/alarm-instance-manage/detail.tsx

@ -23,15 +23,7 @@ import {
ref,
getCurrentInstance
} from 'vue'
import {
NSelect,
NInput,
NSwitch,
NRadioGroup,
NSpace,
NRadio,
NButton
} from 'naive-ui'
import { NSelect, NInput, NButton } from 'naive-ui'
import { isFunction } from 'lodash'
import { useI18n } from 'vue-i18n'
import { useForm } from './use-form'
@ -65,7 +57,6 @@ const DetailModal = defineComponent({
const rules = ref<IFormRules>({})
const elements = ref<IFormItem[]>([]) as IElements
const warningTypeSpan = ref(24)
const {
meta,
@ -109,12 +100,6 @@ const DetailModal = defineComponent({
props.show && props.currentRecord && setDetail(props.currentRecord)
}
)
watch(
() => state.detailForm.instanceType,
() =>
(warningTypeSpan.value =
state.detailForm.instanceType === 'GLOBAL' ? 0 : 24)
)
watch(
() => state.json,
() => {
@ -141,7 +126,6 @@ const DetailModal = defineComponent({
...toRefs(state),
...toRefs(status),
meta,
warningTypeSpan,
rules,
elements,
onChangePlugin,
@ -156,7 +140,6 @@ const DetailModal = defineComponent({
show,
t,
meta,
warningTypeSpan,
rules,
elements,
detailForm,
@ -208,32 +191,6 @@ const DetailModal = defineComponent({
/>
)
},
{
path: 'instanceType',
label: t('security.alarm_instance.is_global_instance'),
widget: (
<NSwitch
checkedValue={'GLOBAL'}
uncheckedValue={'NORMAL'}
disabled={!!currentRecord?.id}
v-model:value={detailForm.instanceType}
/>
)
},
{
path: 'warningType',
label: t('security.alarm_instance.WarningType'),
span: warningTypeSpan,
widget: (
<NRadioGroup v-model:value={detailForm.warningType}>
<NSpace>
<NRadio value={'SUCCESS'}>{'success'}</NRadio>
<NRadio value={'FAILURE'}>{'failure'}</NRadio>
<NRadio value={'ALL'}>{'all'}</NRadio>
</NSpace>
</NRadioGroup>
)
},
{
path: 'pluginDefineId',
label: t('security.alarm_instance.select_plugin'),

2
dolphinscheduler-ui/src/views/security/alarm-instance-manage/types.ts

@ -29,8 +29,6 @@ interface IRecord {
createTime?: string
id: number
instanceName: string
instanceType: string
warningType: string
pluginDefineId: number
pluginInstanceParams?: string
updateTime?: string

4
dolphinscheduler-ui/src/views/security/alarm-instance-manage/use-columns.ts

@ -35,10 +35,6 @@ export function useColumns(onCallback: Function) {
title: t('security.alarm_instance.alarm_instance_name'),
key: 'instanceName'
},
{
title: t('security.alarm_instance.alarm_instance_type'),
key: 'instanceType'
},
{
title: t('security.alarm_instance.alarm_plugin_name'),
key: 'alertPluginName'

3
dolphinscheduler-ui/src/views/security/alarm-instance-manage/use-detail.ts

@ -83,7 +83,6 @@ export function useDetail(getFormValues: Function) {
{
alertPluginInstanceId: values.pluginDefineId,
instanceName: values.instanceName,
warningType: values.warningType,
pluginInstanceParams: formatParams(json, values)
},
currentRecord.id
@ -91,8 +90,6 @@ export function useDetail(getFormValues: Function) {
: await createAlertPluginInstance({
instanceName: values.instanceName,
pluginDefineId: values.pluginDefineId,
instanceType: values.instanceType,
warningType: values.warningType,
pluginInstanceParams: formatParams(json, values)
})

8
dolphinscheduler-ui/src/views/security/alarm-instance-manage/use-form.ts

@ -35,9 +35,7 @@ export function useForm() {
const initialValues = {
instanceName: '',
pluginDefineId: null,
instanceType: 'NORMAL',
warningType: 'ALL'
pluginDefineId: null
}
const state = reactive({
@ -46,7 +44,7 @@ export function useForm() {
uiPlugins: [],
pluginsLoading: false,
json: []
} as { detailFormRef: Ref; json: IJsonItem[]; detailForm: { instanceName: string; pluginDefineId: number | null; instanceType: string; warningType: string }; pluginsLoading: boolean; uiPlugins: [] })
} as { detailFormRef: Ref; json: IJsonItem[]; detailForm: { instanceName: string; pluginDefineId: number | null }; pluginsLoading: boolean; uiPlugins: [] })
const meta = {
model: state.detailForm,
@ -111,8 +109,6 @@ export function useForm() {
const setDetail = (record: IRecord) => {
state.detailForm.instanceName = record.instanceName
state.detailForm.pluginDefineId = record.pluginDefineId
state.detailForm.instanceType = record.instanceType
state.detailForm.warningType = record.warningType
if (record.pluginInstanceParams)
state.json = JSON.parse(record.pluginInstanceParams)
// ensure number type field has number type value

Loading…
Cancel
Save