Browse Source

[Feature-#3828][server] Delete recipients and CCs in the process defi… (#4303)

* [Feature-#3828][server] Delete recipients and CCs in the process definition and select the associated alert group instead

* The specific alarm instance associated with the alert group
* The process definition only associates the alert group, and does not care about the specific alarm instance.

this closes #3828

* remove test cc

* remove test cc

* fix test error

* add sql upgrade script
delete alert column(show_type、alert_type、re、cc)

* code style

* update test
Note the statement to delete the column, and provide related instructions

* delete AlertGroup field(alert_type)

* fix ut error

* fix ut error

* fix ut error

* code style

* delete api-doc receiverCC

* delete UserAlertGroupMapper

* delete UserAlertGroup

* delete UserAlertGroupApi

* alert group add coulmn user_id

* alter user_id to create_user_id

* userinfo remove alert group info
pull/3/MERGE
Kirs 4 years ago committed by GitHub
parent
commit
14785f4e39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java
  2. 91
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java
  3. 116
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java
  4. 94
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java
  5. 47
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java
  6. 3
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java
  7. 7
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java
  8. 38
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UserAlertGroupService.java
  9. 178
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java
  10. 32
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
  11. 23
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionVersionServiceImpl.java
  12. 100
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ExecutorControllerTest.java
  13. 129
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java
  14. 126
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorService2Test.java
  15. 23
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionVersionServiceTest.java
  16. 53
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UserAlertGroupServiceTest.java
  17. 85
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/AlertDao.java
  18. 85
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Alert.java
  19. 58
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/AlertGroup.java
  20. 93
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java
  21. 88
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinitionVersion.java
  22. 142
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/UserAlertGroup.java
  23. 8
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.java
  24. 45
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/UserAlertGroupMapper.java
  25. 8
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.xml
  26. 12
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml
  27. 31
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserAlertGroupMapper.xml
  28. 7
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/AlertDaoTest.java
  29. 189
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapperTest.java
  30. 5
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertMapperTest.java
  31. 2
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapperTest.java
  32. 4
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java
  33. 4
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionVersionMapperTest.java
  34. 196
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UserAlertGroupMapperTest.java
  35. 122
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UserMapperTest.java
  36. 77
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterTaskExecThread.java
  37. 12
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/AlertManager.java
  38. 7
      dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/registry/DependencyConfig.java
  39. 8
      dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/processor/TaskCallbackServiceTestConfig.java
  40. 766
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java
  41. 1
      pom.xml
  42. 63
      sql/dolphinscheduler-postgre.sql
  43. 66
      sql/dolphinscheduler_mysql.sql
  44. 42
      sql/upgrade/1.4.0_schema/mysql/dolphinscheduler_ddl.sql
  45. 40
      sql/upgrade/1.4.0_schema/postgresql/dolphinscheduler_ddl.sql

3
dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java

@ -22,7 +22,6 @@ import org.apache.dolphinscheduler.alert.runner.AlertSender;
import org.apache.dolphinscheduler.alert.utils.Constants; import org.apache.dolphinscheduler.alert.utils.Constants;
import org.apache.dolphinscheduler.alert.utils.PropertyUtils; import org.apache.dolphinscheduler.alert.utils.PropertyUtils;
import org.apache.dolphinscheduler.common.enums.AlertStatus; import org.apache.dolphinscheduler.common.enums.AlertStatus;
import org.apache.dolphinscheduler.common.enums.AlertType;
import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.dao.AlertDao; import org.apache.dolphinscheduler.dao.AlertDao;
import org.apache.dolphinscheduler.dao.DaoFactory; import org.apache.dolphinscheduler.dao.DaoFactory;
@ -70,8 +69,6 @@ public class EmailAlertPluginTest {
AlertGroup alertGroup = new AlertGroup(); AlertGroup alertGroup = new AlertGroup();
alertGroup.setDescription("test alert group 1"); alertGroup.setDescription("test alert group 1");
alertGroup.setGroupName("testalertg1"); alertGroup.setGroupName("testalertg1");
//TODO AlertType is neet delete from AlertGroup
alertGroup.setGroupType(AlertType.EMAIL);
alertDao.getAlertGroupMapper().insert(alertGroup); alertDao.getAlertGroupMapper().insert(alertGroup);
//add alert //add alert

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

@ -14,8 +14,16 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.dolphinscheduler.api.controller; package org.apache.dolphinscheduler.api.controller;
import static org.apache.dolphinscheduler.api.enums.Status.CREATE_ALERT_GROUP_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.DELETE_ALERT_GROUP_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.LIST_PAGING_ALERT_GROUP_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_ALERTGROUP_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_ALERT_GROUP_ERROR;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.AlertGroupService; import org.apache.dolphinscheduler.api.service.AlertGroupService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
@ -23,22 +31,27 @@ import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.AlertType; import org.apache.dolphinscheduler.common.enums.AlertType;
import org.apache.dolphinscheduler.common.utils.ParameterUtils; import org.apache.dolphinscheduler.common.utils.ParameterUtils;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import java.util.HashMap;
import io.swagger.annotations.ApiImplicitParams; import java.util.Map;
import io.swagger.annotations.ApiOperation;
import org.apache.dolphinscheduler.api.enums.Status;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.GetMapping;
import springfox.documentation.annotations.ApiIgnore; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import java.util.HashMap; import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Map; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import static org.apache.dolphinscheduler.api.enums.Status.*; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;
/** /**
* alert group controller * alert group controller
@ -65,9 +78,9 @@ public class AlertGroupController extends BaseController {
*/ */
@ApiOperation(value = "createAlertgroup", notes = "CREATE_ALERT_GROUP_NOTES") @ApiOperation(value = "createAlertgroup", notes = "CREATE_ALERT_GROUP_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"), @ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "groupType", value = "GROUP_TYPE", required = true, dataType = "AlertType"), @ApiImplicitParam(name = "groupType", value = "GROUP_TYPE", required = true, dataType = "AlertType"),
@ApiImplicitParam(name = "description", value = "DESC", dataType = "String") @ApiImplicitParam(name = "description", value = "DESC", dataType = "String")
}) })
@PostMapping(value = "/create") @PostMapping(value = "/create")
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
@ -77,7 +90,7 @@ public class AlertGroupController extends BaseController {
@RequestParam(value = "groupType") AlertType groupType, @RequestParam(value = "groupType") AlertType groupType,
@RequestParam(value = "description", required = false) String description) { @RequestParam(value = "description", required = false) String description) {
logger.info("loginUser user {}, create alertgroup, groupName: {}, groupType: {}, desc: {}", logger.info("loginUser user {}, create alertgroup, groupName: {}, groupType: {}, desc: {}",
loginUser.getUserName(), groupName, groupType, description); loginUser.getUserName(), groupName, groupType, description);
Map<String, Object> result = alertGroupService.createAlertgroup(loginUser, groupName, groupType, description); Map<String, Object> result = alertGroupService.createAlertgroup(loginUser, groupName, groupType, description);
return returnDataList(result); return returnDataList(result);
} }
@ -94,7 +107,7 @@ public class AlertGroupController extends BaseController {
@ApiException(QUERY_ALL_ALERTGROUP_ERROR) @ApiException(QUERY_ALL_ALERTGROUP_ERROR)
public Result list(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { public Result list(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
logger.info("login user {}, query all alertGroup", logger.info("login user {}, query all alertGroup",
loginUser.getUserName()); loginUser.getUserName());
HashMap<String, Object> result = alertGroupService.queryAlertgroup(); HashMap<String, Object> result = alertGroupService.queryAlertgroup();
return returnDataList(result); return returnDataList(result);
} }
@ -110,9 +123,9 @@ public class AlertGroupController extends BaseController {
*/ */
@ApiOperation(value = "queryAlertGroupListPaging", notes = "QUERY_ALERT_GROUP_LIST_PAGING_NOTES") @ApiOperation(value = "queryAlertGroupListPaging", notes = "QUERY_ALERT_GROUP_LIST_PAGING_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"), @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"),
@ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"), @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"),
@ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20") @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20")
}) })
@GetMapping(value = "/list-paging") @GetMapping(value = "/list-paging")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ -122,7 +135,7 @@ public class AlertGroupController extends BaseController {
@RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageSize") Integer pageSize) { @RequestParam("pageSize") Integer pageSize) {
logger.info("login user {}, list paging, pageNo: {}, searchVal: {}, pageSize: {}", logger.info("login user {}, list paging, pageNo: {}, searchVal: {}, pageSize: {}",
loginUser.getUserName(), pageNo, searchVal, pageSize); loginUser.getUserName(), pageNo, searchVal, pageSize);
Map<String, Object> result = checkPageParams(pageNo, pageSize); Map<String, Object> result = checkPageParams(pageNo, pageSize);
if (result.get(Constants.STATUS) != Status.SUCCESS) { if (result.get(Constants.STATUS) != Status.SUCCESS) {
return returnDataListPaging(result); return returnDataListPaging(result);
@ -145,10 +158,10 @@ public class AlertGroupController extends BaseController {
*/ */
@ApiOperation(value = "updateAlertgroup", notes = "UPDATE_ALERT_GROUP_NOTES") @ApiOperation(value = "updateAlertgroup", notes = "UPDATE_ALERT_GROUP_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "ALERT_GROUP_ID", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "id", value = "ALERT_GROUP_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"), @ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"),
@ApiImplicitParam(name = "groupType", value = "GROUP_TYPE", required = true, dataType = "AlertType"), @ApiImplicitParam(name = "groupType", value = "GROUP_TYPE", required = true, dataType = "AlertType"),
@ApiImplicitParam(name = "description", value = "DESC", dataType = "String") @ApiImplicitParam(name = "description", value = "DESC", dataType = "String")
}) })
@PostMapping(value = "/update") @PostMapping(value = "/update")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ -159,7 +172,7 @@ public class AlertGroupController extends BaseController {
@RequestParam(value = "groupType") AlertType groupType, @RequestParam(value = "groupType") AlertType groupType,
@RequestParam(value = "description", required = false) String description) { @RequestParam(value = "description", required = false) String description) {
logger.info("login user {}, updateProcessInstance alertgroup, groupName: {}, groupType: {}, desc: {}", logger.info("login user {}, updateProcessInstance alertgroup, groupName: {}, groupType: {}, desc: {}",
loginUser.getUserName(), groupName, groupType, description); loginUser.getUserName(), groupName, groupType, description);
Map<String, Object> result = alertGroupService.updateAlertgroup(loginUser, id, groupName, groupType, description); Map<String, Object> result = alertGroupService.updateAlertgroup(loginUser, id, groupName, groupType, description);
return returnDataList(result); return returnDataList(result);
} }
@ -173,7 +186,7 @@ public class AlertGroupController extends BaseController {
*/ */
@ApiOperation(value = "delAlertgroupById", notes = "DELETE_ALERT_GROUP_BY_ID_NOTES") @ApiOperation(value = "delAlertgroupById", notes = "DELETE_ALERT_GROUP_BY_ID_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "ALERT_GROUP_ID", required = true, dataType = "Int", example = "100") @ApiImplicitParam(name = "id", value = "ALERT_GROUP_ID", required = true, dataType = "Int", example = "100")
}) })
@PostMapping(value = "/delete") @PostMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ -195,7 +208,7 @@ public class AlertGroupController extends BaseController {
*/ */
@ApiOperation(value = "verifyGroupName", notes = "VERIFY_ALERT_GROUP_NAME_NOTES") @ApiOperation(value = "verifyGroupName", notes = "VERIFY_ALERT_GROUP_NAME_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"), @ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"),
}) })
@GetMapping(value = "/verify-group-name") @GetMapping(value = "/verify-group-name")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ -215,28 +228,4 @@ public class AlertGroupController extends BaseController {
} }
return result; return result;
} }
/**
* grant user
*
* @param loginUser login user
* @param userIds user ids in the group
* @param alertgroupId alert group id
* @return grant result code
*/
@ApiOperation(value = "grantUser", notes = "GRANT_ALERT_GROUP_NOTES")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "ALERT_GROUP_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "userIds", value = "USER_IDS", required = true, dataType = "String")
})
@PostMapping(value = "/grant-user")
@ResponseStatus(HttpStatus.OK)
@ApiException(ALERT_GROUP_GRANT_USER_ERROR)
public Result grantUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "alertgroupId") int alertgroupId,
@RequestParam(value = "userIds") String userIds) {
logger.info("login user {}, grant user, alertGroupId: {},userIds : {}", loginUser.getUserName(), alertgroupId, userIds);
Map<String, Object> result = alertGroupService.grantUser(loginUser, alertgroupId, userIds);
return returnDataList(result);
}
} }

116
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java

@ -14,30 +14,48 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.dolphinscheduler.api.controller; package org.apache.dolphinscheduler.api.controller;
import static org.apache.dolphinscheduler.api.enums.Status.CHECK_PROCESS_DEFINITION_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.EXECUTE_PROCESS_INSTANCE_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.START_PROCESS_INSTANCE_ERROR;
import org.apache.dolphinscheduler.api.enums.ExecuteType; import org.apache.dolphinscheduler.api.enums.ExecuteType;
import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.ExecutorService; import org.apache.dolphinscheduler.api.service.ExecutorService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.CommandType;
import org.apache.dolphinscheduler.common.enums.FailureStrategy;
import org.apache.dolphinscheduler.common.enums.Priority;
import org.apache.dolphinscheduler.common.enums.RunMode;
import org.apache.dolphinscheduler.common.enums.TaskDependType;
import org.apache.dolphinscheduler.common.enums.WarningType;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
import io.swagger.annotations.*;
import org.apache.dolphinscheduler.common.enums.*; import java.text.ParseException;
import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import java.text.ParseException;
import java.util.Map;
import static org.apache.dolphinscheduler.api.enums.Status.*;
/** /**
* execute process controller * execute process controller
*/ */
@ -64,8 +82,6 @@ public class ExecutorController extends BaseController {
* @param execType execute type * @param execType execute type
* @param warningType warning type * @param warningType warning type
* @param warningGroupId warning group id * @param warningGroupId warning group id
* @param receivers receivers
* @param receiversCc receivers cc
* @param runMode run mode * @param runMode run mode
* @param processInstancePriority process instance priority * @param processInstancePriority process instance priority
* @param workerGroup worker group * @param workerGroup worker group
@ -74,20 +90,18 @@ public class ExecutorController extends BaseController {
*/ */
@ApiOperation(value = "startProcessInstance", notes = "RUN_PROCESS_INSTANCE_NOTES") @ApiOperation(value = "startProcessInstance", notes = "RUN_PROCESS_INSTANCE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "scheduleTime", value = "SCHEDULE_TIME", required = true, dataType = "String"), @ApiImplicitParam(name = "scheduleTime", value = "SCHEDULE_TIME", required = true, dataType = "String"),
@ApiImplicitParam(name = "failureStrategy", value = "FAILURE_STRATEGY", required = true, dataType = "FailureStrategy"), @ApiImplicitParam(name = "failureStrategy", value = "FAILURE_STRATEGY", required = true, dataType = "FailureStrategy"),
@ApiImplicitParam(name = "startNodeList", value = "START_NODE_LIST", dataType = "String"), @ApiImplicitParam(name = "startNodeList", value = "START_NODE_LIST", dataType = "String"),
@ApiImplicitParam(name = "taskDependType", value = "TASK_DEPEND_TYPE", dataType = "TaskDependType"), @ApiImplicitParam(name = "taskDependType", value = "TASK_DEPEND_TYPE", dataType = "TaskDependType"),
@ApiImplicitParam(name = "execType", value = "COMMAND_TYPE", dataType = "CommandType"), @ApiImplicitParam(name = "execType", value = "COMMAND_TYPE", dataType = "CommandType"),
@ApiImplicitParam(name = "warningType", value = "WARNING_TYPE", required = true, dataType = "WarningType"), @ApiImplicitParam(name = "warningType", value = "WARNING_TYPE", required = true, dataType = "WarningType"),
@ApiImplicitParam(name = "warningGroupId", value = "WARNING_GROUP_ID", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "warningGroupId", value = "WARNING_GROUP_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "receivers", value = "RECEIVERS", dataType = "String"), @ApiImplicitParam(name = "runMode", value = "RUN_MODE", dataType = "RunMode"),
@ApiImplicitParam(name = "receiversCc", value = "RECEIVERS_CC", dataType = "String"), @ApiImplicitParam(name = "processInstancePriority", value = "PROCESS_INSTANCE_PRIORITY", required = true, dataType = "Priority"),
@ApiImplicitParam(name = "runMode", value = "RUN_MODE", dataType = "RunMode"), @ApiImplicitParam(name = "workerGroup", value = "WORKER_GROUP", dataType = "String", example = "default"),
@ApiImplicitParam(name = "processInstancePriority", value = "PROCESS_INSTANCE_PRIORITY", required = true, dataType = "Priority"), @ApiImplicitParam(name = "timeout", value = "TIMEOUT", dataType = "Int", example = "100"),
@ApiImplicitParam(name = "workerGroup", value = "WORKER_GROUP", dataType = "String", example = "default"),
@ApiImplicitParam(name = "timeout", value = "TIMEOUT", dataType = "Int", example = "100"),
}) })
@PostMapping(value = "start-process-instance") @PostMapping(value = "start-process-instance")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ -102,26 +116,24 @@ public class ExecutorController extends BaseController {
@RequestParam(value = "execType", required = false) CommandType execType, @RequestParam(value = "execType", required = false) CommandType execType,
@RequestParam(value = "warningType", required = true) WarningType warningType, @RequestParam(value = "warningType", required = true) WarningType warningType,
@RequestParam(value = "warningGroupId", required = false) int warningGroupId, @RequestParam(value = "warningGroupId", required = false) int warningGroupId,
@RequestParam(value = "receivers", required = false) String receivers,
@RequestParam(value = "receiversCc", required = false) String receiversCc,
@RequestParam(value = "runMode", required = false) RunMode runMode, @RequestParam(value = "runMode", required = false) RunMode runMode,
@RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority, @RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority,
@RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, @RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup,
@RequestParam(value = "timeout", required = false) Integer timeout) throws ParseException { @RequestParam(value = "timeout", required = false) Integer timeout) throws ParseException {
logger.info("login user {}, start process instance, project name: {}, process definition id: {}, schedule time: {}, " logger.info("login user {}, start process instance, project name: {}, process definition id: {}, schedule time: {}, "
+ "failure policy: {}, node name: {}, node dep: {}, notify type: {}, " + "failure policy: {}, node name: {}, node dep: {}, notify type: {}, "
+ "notify group id: {},receivers:{},receiversCc:{}, run mode: {},process instance priority:{}, workerGroup: {}, timeout: {}", + "notify group id: {}, run mode: {},process instance priority:{}, workerGroup: {}, timeout: {}",
loginUser.getUserName(), projectName, processDefinitionId, scheduleTime, loginUser.getUserName(), projectName, processDefinitionId, scheduleTime,
failureStrategy, startNodeList, taskDependType, warningType, workerGroup, receivers, receiversCc, runMode, processInstancePriority, failureStrategy, startNodeList, taskDependType, warningType, workerGroup, runMode, processInstancePriority,
workerGroup, timeout); workerGroup, timeout);
if (timeout == null) { if (timeout == null) {
timeout = Constants.MAX_TASK_TIMEOUT; timeout = Constants.MAX_TASK_TIMEOUT;
} }
Map<String, Object> result = execService.execProcessInstance(loginUser, projectName, processDefinitionId, scheduleTime, execType, failureStrategy, Map<String, Object> result = execService.execProcessInstance(loginUser, projectName, processDefinitionId, scheduleTime, execType, failureStrategy,
startNodeList, taskDependType, warningType, startNodeList, taskDependType, warningType,
warningGroupId, receivers, receiversCc, runMode, processInstancePriority, workerGroup, timeout); warningGroupId, runMode, processInstancePriority, workerGroup, timeout);
return returnDataList(result); return returnDataList(result);
} }
@ -137,8 +149,8 @@ public class ExecutorController extends BaseController {
*/ */
@ApiOperation(value = "execute", notes = "EXECUTE_ACTION_TO_PROCESS_INSTANCE_NOTES") @ApiOperation(value = "execute", notes = "EXECUTE_ACTION_TO_PROCESS_INSTANCE_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "executeType", value = "EXECUTE_TYPE", required = true, dataType = "ExecuteType") @ApiImplicitParam(name = "executeType", value = "EXECUTE_TYPE", required = true, dataType = "ExecuteType")
}) })
@PostMapping(value = "/execute") @PostMapping(value = "/execute")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ -149,7 +161,7 @@ public class ExecutorController extends BaseController {
@RequestParam("executeType") ExecuteType executeType @RequestParam("executeType") ExecuteType executeType
) { ) {
logger.info("execute command, login user: {}, project:{}, process instance id:{}, execute type:{}", logger.info("execute command, login user: {}, project:{}, process instance id:{}, execute type:{}",
loginUser.getUserName(), projectName, processInstanceId, executeType); loginUser.getUserName(), projectName, processInstanceId, executeType);
Map<String, Object> result = execService.execute(loginUser, projectName, processInstanceId, executeType); Map<String, Object> result = execService.execute(loginUser, projectName, processInstanceId, executeType);
return returnDataList(result); return returnDataList(result);
} }
@ -163,7 +175,7 @@ public class ExecutorController extends BaseController {
*/ */
@ApiOperation(value = "startCheckProcessDefinition", notes = "START_CHECK_PROCESS_DEFINITION_NOTES") @ApiOperation(value = "startCheckProcessDefinition", notes = "START_CHECK_PROCESS_DEFINITION_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100") @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100")
}) })
@PostMapping(value = "/start-check") @PostMapping(value = "/start-check")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ -174,32 +186,4 @@ public class ExecutorController extends BaseController {
Map<String, Object> result = execService.startCheckByProcessDefinedId(processDefinitionId); Map<String, Object> result = execService.startCheckByProcessDefinedId(processDefinitionId);
return returnDataList(result); return returnDataList(result);
} }
/**
* query recipients and copyers by process definition ID
*
* @param loginUser login user
* @param processDefinitionId process definition id
* @param processInstanceId process instance id
* @return receivers cc list
*/
@ApiIgnore
@ApiOperation(value = "getReceiverCc", notes = "GET_RECEIVER_CC_NOTES")
@ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100")
})
@GetMapping(value = "/get-receiver-cc")
@ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_RECIPIENTS_AND_COPYERS_BY_PROCESS_DEFINITION_ERROR)
public Result getReceiverCc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "processDefinitionId", required = false) Integer processDefinitionId,
@RequestParam(value = "processInstanceId", required = false) Integer processInstanceId) {
logger.info("login user {}, get process definition receiver and cc", loginUser.getUserName());
Map<String, Object> result = execService.getReceiverCc(processDefinitionId, processInstanceId);
return returnDataList(result);
}
} }

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

@ -14,9 +14,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.dolphinscheduler.api.service; package org.apache.dolphinscheduler.api.service;
import java.util.*;
import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
@ -25,29 +25,33 @@ import org.apache.dolphinscheduler.common.utils.CollectionUtils;
import org.apache.dolphinscheduler.common.utils.StringUtils; import org.apache.dolphinscheduler.common.utils.StringUtils;
import org.apache.dolphinscheduler.dao.entity.AlertGroup; import org.apache.dolphinscheduler.dao.entity.AlertGroup;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.entity.UserAlertGroup;
import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper; import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
/** /**
* alert group service * alert group service
*/ */
@Service @Service
public class AlertGroupService extends BaseService{ public class AlertGroupService extends BaseService {
private static final Logger logger = LoggerFactory.getLogger(AlertGroupService.class); private static final Logger logger = LoggerFactory.getLogger(AlertGroupService.class);
@Autowired @Autowired
private AlertGroupMapper alertGroupMapper; private AlertGroupMapper alertGroupMapper;
@Autowired
private UserAlertGroupService userAlertGroupService;
/** /**
* query alert group list * query alert group list
* *
@ -68,8 +72,8 @@ public class AlertGroupService extends BaseService{
* *
* @param loginUser login user * @param loginUser login user
* @param searchVal search value * @param searchVal search value
* @param pageNo page number * @param pageNo page number
* @param pageSize page size * @param pageSize page size
* @return alert group list page * @return alert group list page
*/ */
public Map<String, Object> listPaging(User loginUser, String searchVal, Integer pageNo, Integer pageSize) { public Map<String, Object> listPaging(User loginUser, String searchVal, Integer pageNo, Integer pageSize) {
@ -81,9 +85,9 @@ public class AlertGroupService extends BaseService{
Page<AlertGroup> page = new Page(pageNo, pageSize); Page<AlertGroup> page = new Page(pageNo, pageSize);
IPage<AlertGroup> alertGroupIPage = alertGroupMapper.queryAlertGroupPage( IPage<AlertGroup> alertGroupIPage = alertGroupMapper.queryAlertGroupPage(
page, searchVal); page, searchVal);
PageInfo<AlertGroup> pageInfo = new PageInfo<>(pageNo, pageSize); PageInfo<AlertGroup> pageInfo = new PageInfo<>(pageNo, pageSize);
pageInfo.setTotalCount((int)alertGroupIPage.getTotal()); pageInfo.setTotalCount((int) alertGroupIPage.getTotal());
pageInfo.setLists(alertGroupIPage.getRecords()); pageInfo.setLists(alertGroupIPage.getRecords());
result.put(Constants.DATA_LIST, pageInfo); result.put(Constants.DATA_LIST, pageInfo);
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
@ -97,13 +101,13 @@ public class AlertGroupService extends BaseService{
* @param loginUser login user * @param loginUser login user
* @param groupName group name * @param groupName group name
* @param groupType group type * @param groupType group type
* @param desc description * @param desc description
* @return create result code * @return create result code
*/ */
public Map<String, Object> createAlertgroup(User loginUser, String groupName, AlertType groupType, String desc) { public Map<String, Object> createAlertgroup(User loginUser, String groupName, AlertType groupType, String desc) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
//only admin can operate //only admin can operate
if (checkAdmin(loginUser, result)){ if (checkAdmin(loginUser, result)) {
return result; return result;
} }
@ -111,10 +115,10 @@ public class AlertGroupService extends BaseService{
Date now = new Date(); Date now = new Date();
alertGroup.setGroupName(groupName); alertGroup.setGroupName(groupName);
alertGroup.setGroupType(groupType);
alertGroup.setDescription(desc); alertGroup.setDescription(desc);
alertGroup.setCreateTime(now); alertGroup.setCreateTime(now);
alertGroup.setUpdateTime(now); alertGroup.setUpdateTime(now);
alertGroup.setCreateUserId(loginUser.getId());
// insert // insert
int insert = alertGroupMapper.insert(alertGroup); int insert = alertGroupMapper.insert(alertGroup);
@ -131,20 +135,19 @@ public class AlertGroupService extends BaseService{
* updateProcessInstance alert group * updateProcessInstance alert group
* *
* @param loginUser login user * @param loginUser login user
* @param id alert group id * @param id alert group id
* @param groupName group name * @param groupName group name
* @param groupType group type * @param groupType group type
* @param desc description * @param desc description
* @return update result code * @return update result code
*/ */
public Map<String, Object> updateAlertgroup(User loginUser, int id, String groupName, AlertType groupType, String desc) { public Map<String, Object> updateAlertgroup(User loginUser, int id, String groupName, AlertType groupType, String desc) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
if (checkAdmin(loginUser, result)){ if (checkAdmin(loginUser, result)) {
return result; return result;
} }
AlertGroup alertGroup = alertGroupMapper.selectById(id); AlertGroup alertGroup = alertGroupMapper.selectById(id);
if (alertGroup == null) { if (alertGroup == null) {
@ -158,12 +161,9 @@ public class AlertGroupService extends BaseService{
if (StringUtils.isNotEmpty(groupName)) { if (StringUtils.isNotEmpty(groupName)) {
alertGroup.setGroupName(groupName); alertGroup.setGroupName(groupName);
} }
if (groupType != null) {
alertGroup.setGroupType(groupType);
}
alertGroup.setDescription(desc); alertGroup.setDescription(desc);
alertGroup.setUpdateTime(now); alertGroup.setUpdateTime(now);
alertGroup.setCreateUserId(loginUser.getId());
// updateProcessInstance // updateProcessInstance
alertGroupMapper.updateById(alertGroup); alertGroupMapper.updateById(alertGroup);
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
@ -174,7 +174,7 @@ public class AlertGroupService extends BaseService{
* delete alert group by id * delete alert group by id
* *
* @param loginUser login user * @param loginUser login user
* @param id alert group id * @param id alert group id
* @return delete result code * @return delete result code
*/ */
@Transactional(rollbackFor = RuntimeException.class) @Transactional(rollbackFor = RuntimeException.class)
@ -183,7 +183,7 @@ public class AlertGroupService extends BaseService{
result.put(Constants.STATUS, false); result.put(Constants.STATUS, false);
//only admin can operate //only admin can operate
if (checkAdmin(loginUser, result)){ if (checkAdmin(loginUser, result)) {
return result; return result;
} }
//check exist //check exist
@ -192,57 +192,11 @@ public class AlertGroupService extends BaseService{
putMsg(result, Status.ALERT_GROUP_NOT_EXIST); putMsg(result, Status.ALERT_GROUP_NOT_EXIST);
return result; return result;
} }
userAlertGroupService.deleteByAlertGroupId(id);
alertGroupMapper.deleteById(id); alertGroupMapper.deleteById(id);
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
return result; return result;
} }
/**
* grant user
*
* @param loginUser login user
* @param alertgroupId alert group id
* @param userIds user id list
* @return grant result code
*/
public Map<String, Object> grantUser(User loginUser, int alertgroupId, String userIds) {
Map<String, Object> result = new HashMap<>();
result.put(Constants.STATUS, false);
//only admin can operate
if (checkAdmin(loginUser, result)){
return result;
}
userAlertGroupService.deleteByAlertGroupId(alertgroupId);
if (StringUtils.isEmpty(userIds)) {
putMsg(result, Status.SUCCESS);
return result;
}
String[] userIdsArr = userIds.split(",");
Date now = new Date();
List<UserAlertGroup> alertGroups = new ArrayList<>(userIds.length());
for (String userId : userIdsArr) {
UserAlertGroup userAlertGroup = new UserAlertGroup();
userAlertGroup.setAlertgroupId(alertgroupId);
userAlertGroup.setUserId(Integer.parseInt(userId));
userAlertGroup.setCreateTime(now);
userAlertGroup.setUpdateTime(now);
alertGroups.add(userAlertGroup);
}
if (CollectionUtils.isNotEmpty(alertGroups)) {
userAlertGroupService.saveBatch(alertGroups);
}
putMsg(result, Status.SUCCESS);
return result;
}
/** /**
* verify group name exists * verify group name exists
* *

47
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java

@ -83,8 +83,6 @@ public class ExecutorService extends BaseService{
* @param taskDependType node dependency type * @param taskDependType node dependency type
* @param warningType warning type * @param warningType warning type
* @param warningGroupId notify group id * @param warningGroupId notify group id
* @param receivers receivers
* @param receiversCc receivers cc
* @param processInstancePriority process instance priority * @param processInstancePriority process instance priority
* @param workerGroup worker group name * @param workerGroup worker group name
* @param runMode run mode * @param runMode run mode
@ -96,7 +94,7 @@ public class ExecutorService extends BaseService{
int processDefinitionId, String cronTime, CommandType commandType, int processDefinitionId, String cronTime, CommandType commandType,
FailureStrategy failureStrategy, String startNodeList, FailureStrategy failureStrategy, String startNodeList,
TaskDependType taskDependType, WarningType warningType, int warningGroupId, TaskDependType taskDependType, WarningType warningType, int warningGroupId,
String receivers, String receiversCc, RunMode runMode, RunMode runMode,
Priority processInstancePriority, String workerGroup, Integer timeout) throws ParseException { Priority processInstancePriority, String workerGroup, Integer timeout) throws ParseException {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
// timeout is invalid // timeout is invalid
@ -137,11 +135,7 @@ public class ExecutorService extends BaseService{
taskDependType, failureStrategy, startNodeList, cronTime, warningType, loginUser.getId(), taskDependType, failureStrategy, startNodeList, cronTime, warningType, loginUser.getId(),
warningGroupId, runMode,processInstancePriority, workerGroup); warningGroupId, runMode,processInstancePriority, workerGroup);
if(create > 0 ){ if(create > 0 ){
/** processDefinition.setWarningGroupId(warningGroupId);
* according to the process definition ID updateProcessInstance and CC recipient
*/
processDefinition.setReceivers(receivers);
processDefinition.setReceiversCc(receiversCc);
processDefinitionMapper.updateById(processDefinition); processDefinitionMapper.updateById(processDefinition);
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
} else { } else {
@ -424,43 +418,6 @@ public class ExecutorService extends BaseService{
return result; return result;
} }
/**
* query recipients and copyers by process definition id or processInstanceId
*
* @param processDefineId process definition id
* @param processInstanceId process instance id
* @return receivers cc list
*/
public Map<String, Object> getReceiverCc(Integer processDefineId,Integer processInstanceId) {
Map<String, Object> result = new HashMap<>();
logger.info("processInstanceId {}",processInstanceId);
if(processDefineId == null && processInstanceId == null){
throw new RuntimeException("You must set values for parameters processDefineId or processInstanceId");
}
if(processDefineId == null && processInstanceId != null) {
ProcessInstance processInstance = processInstanceMapper.selectById(processInstanceId);
if (processInstance == null) {
throw new RuntimeException("processInstanceId is not exists");
}
processDefineId = processInstance.getProcessDefinitionId();
}
ProcessDefinition processDefinition = processDefinitionMapper.selectById(processDefineId);
if (processDefinition == null){
throw new RuntimeException(String.format("processDefineId %d is not exists",processDefineId));
}
String receivers = processDefinition.getReceivers();
String receiversCc = processDefinition.getReceiversCc();
Map<String,String> dataMap = new HashMap<>();
dataMap.put(Constants.RECEIVERS,receivers);
dataMap.put(Constants.RECEIVERS_CC,receiversCc);
result.put(Constants.DATA_LIST, dataMap);
putMsg(result, Status.SUCCESS);
return result;
}
/** /**
* create command * create command
* @param commandType commandType * @param commandType commandType

3
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java

@ -187,8 +187,7 @@ public class ProcessInstanceService extends BaseService {
ProcessInstance processInstance = processService.findProcessInstanceDetailById(processId); ProcessInstance processInstance = processService.findProcessInstanceDetailById(processId);
ProcessDefinition processDefinition = processService.findProcessDefineById(processInstance.getProcessDefinitionId()); ProcessDefinition processDefinition = processService.findProcessDefineById(processInstance.getProcessDefinitionId());
processInstance.setReceivers(processDefinition.getReceivers()); processInstance.setWarningGroupId(processDefinition.getWarningGroupId());
processInstance.setReceiversCc(processDefinition.getReceiversCc());
result.put(DATA_LIST, processInstance); result.put(DATA_LIST, processInstance);
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);

7
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java

@ -161,8 +161,7 @@ public class SchedulerService extends BaseService {
/** /**
* updateProcessInstance receivers and cc by process definition id * updateProcessInstance receivers and cc by process definition id
*/ */
processDefinition.setReceivers(receivers); processDefinition.setWarningGroupId(warningGroupId);
processDefinition.setReceiversCc(receiversCc);
processDefinitionMapper.updateById(processDefinition); processDefinitionMapper.updateById(processDefinition);
// return scheduler object with ID // return scheduler object with ID
@ -275,8 +274,8 @@ public class SchedulerService extends BaseService {
/** /**
* updateProcessInstance recipients and cc by process definition ID * updateProcessInstance recipients and cc by process definition ID
*/ */
processDefinition.setReceivers(receivers); processDefinition.setWarningGroupId(warningGroupId);
processDefinition.setReceiversCc(receiversCc);
processDefinitionMapper.updateById(processDefinition); processDefinitionMapper.updateById(processDefinition);
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);

38
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UserAlertGroupService.java

@ -1,38 +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.api.service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.dolphinscheduler.dao.entity.UserAlertGroup;
import org.apache.dolphinscheduler.dao.mapper.UserAlertGroupMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
*
*/
@Service
public class UserAlertGroupService extends ServiceImpl<UserAlertGroupMapper, UserAlertGroup> {
@Autowired
private UserAlertGroupMapper userAlertGroupMapper;
boolean deleteByAlertGroupId(Integer groupId) {
return userAlertGroupMapper.deleteByAlertgroupId(groupId) >= 1;
}
}

178
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java

@ -14,10 +14,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.dolphinscheduler.api.service; package org.apache.dolphinscheduler.api.service;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.dolphinscheduler.api.dto.resources.ResourceComponent; import org.apache.dolphinscheduler.api.dto.resources.ResourceComponent;
import org.apache.dolphinscheduler.api.dto.resources.visitor.ResourceTreeVisitor; import org.apache.dolphinscheduler.api.dto.resources.visitor.ResourceTreeVisitor;
import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.enums.Status;
@ -33,6 +35,7 @@ import org.apache.dolphinscheduler.common.utils.*;
import org.apache.dolphinscheduler.dao.entity.*; import org.apache.dolphinscheduler.dao.entity.*;
import org.apache.dolphinscheduler.dao.mapper.*; import org.apache.dolphinscheduler.dao.mapper.*;
import org.apache.dolphinscheduler.dao.utils.ResourceProcessDefinitionUtils; import org.apache.dolphinscheduler.dao.utils.ResourceProcessDefinitionUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -83,13 +86,13 @@ public class UsersService extends BaseService {
/** /**
* create user, only system admin have permission * create user, only system admin have permission
* *
* @param loginUser login user * @param loginUser login user
* @param userName user name * @param userName user name
* @param userPassword user password * @param userPassword user password
* @param email email * @param email email
* @param tenantId tenant id * @param tenantId tenant id
* @param phone phone * @param phone phone
* @param queue queue * @param queue queue
* @return create result code * @return create result code
* @throws Exception exception * @throws Exception exception
*/ */
@ -109,7 +112,7 @@ public class UsersService extends BaseService {
String msg = this.checkUserParams(userName, userPassword, email, phone); String msg = this.checkUserParams(userName, userPassword, email, phone);
if (!StringUtils.isEmpty(msg)) { if (!StringUtils.isEmpty(msg)) {
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR,msg); putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, msg);
return result; return result;
} }
if (!isAdmin(loginUser)) { if (!isAdmin(loginUser)) {
@ -126,12 +129,12 @@ public class UsersService extends BaseService {
Tenant tenant = tenantMapper.queryById(tenantId); Tenant tenant = tenantMapper.queryById(tenantId);
// resource upload startup // resource upload startup
if (PropertyUtils.getResUploadStartupState()){ if (PropertyUtils.getResUploadStartupState()) {
// if tenant not exists // if tenant not exists
if (!HadoopUtils.getInstance().exists(HadoopUtils.getHdfsTenantDir(tenant.getTenantCode()))){ if (!HadoopUtils.getInstance().exists(HadoopUtils.getHdfsTenantDir(tenant.getTenantCode()))) {
createTenantDirIfNotExists(tenant.getTenantCode()); createTenantDirIfNotExists(tenant.getTenantCode());
} }
String userPath = HadoopUtils.getHdfsUserDir(tenant.getTenantCode(),user.getId()); String userPath = HadoopUtils.getHdfsUserDir(tenant.getTenantCode(), user.getId());
HadoopUtils.getInstance().mkdir(userPath); HadoopUtils.getInstance().mkdir(userPath);
} }
@ -142,12 +145,12 @@ public class UsersService extends BaseService {
@Transactional(rollbackFor = RuntimeException.class) @Transactional(rollbackFor = RuntimeException.class)
public User createUser(String userName, public User createUser(String userName,
String userPassword, String userPassword,
String email, String email,
int tenantId, int tenantId,
String phone, String phone,
String queue, String queue,
int state) { int state) {
User user = new User(); User user = new User();
Date now = new Date(); Date now = new Date();
@ -161,7 +164,7 @@ public class UsersService extends BaseService {
user.setUserType(UserType.GENERAL_USER); user.setUserType(UserType.GENERAL_USER);
user.setCreateTime(now); user.setCreateTime(now);
user.setUpdateTime(now); user.setUpdateTime(now);
if (StringUtils.isEmpty(queue)){ if (StringUtils.isEmpty(queue)) {
queue = ""; queue = "";
} }
user.setQueue(queue); user.setQueue(queue);
@ -173,6 +176,7 @@ public class UsersService extends BaseService {
/** /**
* query user by id * query user by id
*
* @param id id * @param id id
* @return user info * @return user info
*/ */
@ -182,6 +186,7 @@ public class UsersService extends BaseService {
/** /**
* query user * query user
*
* @param name name * @param name name
* @return user info * @return user info
*/ */
@ -192,7 +197,7 @@ public class UsersService extends BaseService {
/** /**
* query user * query user
* *
* @param name name * @param name name
* @param password password * @param password password
* @return user info * @return user info
*/ */
@ -203,6 +208,7 @@ public class UsersService extends BaseService {
/** /**
* get user id by user name * get user id by user name
*
* @param name user name * @param name user name
* @return if name empty 0, user not exists -1, user exist user id * @return if name empty 0, user not exists -1, user exist user id
*/ */
@ -225,9 +231,9 @@ public class UsersService extends BaseService {
* query user list * query user list
* *
* @param loginUser login user * @param loginUser login user
* @param pageNo page number * @param pageNo page number
* @param searchVal search avlue * @param searchVal search avlue
* @param pageSize page size * @param pageSize page size
* @return user list page * @return user list page
*/ */
public Map<String, Object> queryUserList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) { public Map<String, Object> queryUserList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) {
@ -242,7 +248,7 @@ public class UsersService extends BaseService {
IPage<User> scheduleList = userMapper.queryUserPaging(page, searchVal); IPage<User> scheduleList = userMapper.queryUserPaging(page, searchVal);
PageInfo<User> pageInfo = new PageInfo<>(pageNo, pageSize); PageInfo<User> pageInfo = new PageInfo<>(pageNo, pageSize);
pageInfo.setTotalCount((int)scheduleList.getTotal()); pageInfo.setTotalCount((int) scheduleList.getTotal());
pageInfo.setLists(scheduleList.getRecords()); pageInfo.setLists(scheduleList.getRecords());
result.put(Constants.DATA_LIST, pageInfo); result.put(Constants.DATA_LIST, pageInfo);
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
@ -253,13 +259,13 @@ public class UsersService extends BaseService {
/** /**
* updateProcessInstance user * updateProcessInstance user
* *
* @param userId user id * @param userId user id
* @param userName user name * @param userName user name
* @param userPassword user password * @param userPassword user password
* @param email email * @param email email
* @param tenantId tennat id * @param tenantId tennat id
* @param phone phone * @param phone phone
* @param queue queue * @param queue queue
* @return update result code * @return update result code
* @throws Exception exception * @throws Exception exception
*/ */
@ -283,8 +289,8 @@ public class UsersService extends BaseService {
if (StringUtils.isNotEmpty(userName)) { if (StringUtils.isNotEmpty(userName)) {
if (!CheckUtils.checkUserName(userName)){ if (!CheckUtils.checkUserName(userName)) {
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR,userName); putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, userName);
return result; return result;
} }
@ -297,23 +303,23 @@ public class UsersService extends BaseService {
} }
if (StringUtils.isNotEmpty(userPassword)) { if (StringUtils.isNotEmpty(userPassword)) {
if (!CheckUtils.checkPassword(userPassword)){ if (!CheckUtils.checkPassword(userPassword)) {
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR,userPassword); putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, userPassword);
return result; return result;
} }
user.setUserPassword(EncryptionUtils.getMd5(userPassword)); user.setUserPassword(EncryptionUtils.getMd5(userPassword));
} }
if (StringUtils.isNotEmpty(email)) { if (StringUtils.isNotEmpty(email)) {
if (!CheckUtils.checkEmail(email)){ if (!CheckUtils.checkEmail(email)) {
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR,email); putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, email);
return result; return result;
} }
user.setEmail(email); user.setEmail(email);
} }
if (StringUtils.isNotEmpty(phone) && !CheckUtils.checkPhone(phone)) { if (StringUtils.isNotEmpty(phone) && !CheckUtils.checkPhone(phone)) {
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR,phone); putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, phone);
return result; return result;
} }
user.setPhone(phone); user.setPhone(phone);
@ -329,19 +335,19 @@ public class UsersService extends BaseService {
Tenant newTenant = tenantMapper.queryById(tenantId); Tenant newTenant = tenantMapper.queryById(tenantId);
if (newTenant != null) { if (newTenant != null) {
// if hdfs startup // if hdfs startup
if (PropertyUtils.getResUploadStartupState() && oldTenant != null){ if (PropertyUtils.getResUploadStartupState() && oldTenant != null) {
String newTenantCode = newTenant.getTenantCode(); String newTenantCode = newTenant.getTenantCode();
String oldResourcePath = HadoopUtils.getHdfsResDir(oldTenant.getTenantCode()); String oldResourcePath = HadoopUtils.getHdfsResDir(oldTenant.getTenantCode());
String oldUdfsPath = HadoopUtils.getHdfsUdfDir(oldTenant.getTenantCode()); String oldUdfsPath = HadoopUtils.getHdfsUdfDir(oldTenant.getTenantCode());
// if old tenant dir exists // if old tenant dir exists
if (HadoopUtils.getInstance().exists(oldResourcePath)){ if (HadoopUtils.getInstance().exists(oldResourcePath)) {
String newResourcePath = HadoopUtils.getHdfsResDir(newTenantCode); String newResourcePath = HadoopUtils.getHdfsResDir(newTenantCode);
String newUdfsPath = HadoopUtils.getHdfsUdfDir(newTenantCode); String newUdfsPath = HadoopUtils.getHdfsUdfDir(newTenantCode);
//file resources list //file resources list
List<Resource> fileResourcesList = resourceMapper.queryResourceList( List<Resource> fileResourcesList = resourceMapper.queryResourceList(
null, userId, ResourceType.FILE.ordinal()); null, userId, ResourceType.FILE.ordinal());
if (CollectionUtils.isNotEmpty(fileResourcesList)) { if (CollectionUtils.isNotEmpty(fileResourcesList)) {
ResourceTreeVisitor resourceTreeVisitor = new ResourceTreeVisitor(fileResourcesList); ResourceTreeVisitor resourceTreeVisitor = new ResourceTreeVisitor(fileResourcesList);
ResourceComponent resourceComponent = resourceTreeVisitor.visit(); ResourceComponent resourceComponent = resourceTreeVisitor.visit();
@ -350,7 +356,7 @@ public class UsersService extends BaseService {
//udf resources //udf resources
List<Resource> udfResourceList = resourceMapper.queryResourceList( List<Resource> udfResourceList = resourceMapper.queryResourceList(
null, userId, ResourceType.UDF.ordinal()); null, userId, ResourceType.UDF.ordinal());
if (CollectionUtils.isNotEmpty(udfResourceList)) { if (CollectionUtils.isNotEmpty(udfResourceList)) {
ResourceTreeVisitor resourceTreeVisitor = new ResourceTreeVisitor(udfResourceList); ResourceTreeVisitor resourceTreeVisitor = new ResourceTreeVisitor(udfResourceList);
ResourceComponent resourceComponent = resourceTreeVisitor.visit(); ResourceComponent resourceComponent = resourceTreeVisitor.visit();
@ -358,18 +364,18 @@ public class UsersService extends BaseService {
} }
//Delete the user from the old tenant directory //Delete the user from the old tenant directory
String oldUserPath = HadoopUtils.getHdfsUserDir(oldTenant.getTenantCode(),userId); String oldUserPath = HadoopUtils.getHdfsUserDir(oldTenant.getTenantCode(), userId);
HadoopUtils.getInstance().delete(oldUserPath, true); HadoopUtils.getInstance().delete(oldUserPath, true);
}else { } else {
// if old tenant dir not exists , create // if old tenant dir not exists , create
createTenantDirIfNotExists(oldTenant.getTenantCode()); createTenantDirIfNotExists(oldTenant.getTenantCode());
} }
if (HadoopUtils.getInstance().exists(HadoopUtils.getHdfsTenantDir(newTenant.getTenantCode()))){ if (HadoopUtils.getInstance().exists(HadoopUtils.getHdfsTenantDir(newTenant.getTenantCode()))) {
//create user in the new tenant directory //create user in the new tenant directory
String newUserPath = HadoopUtils.getHdfsUserDir(newTenant.getTenantCode(),user.getId()); String newUserPath = HadoopUtils.getHdfsUserDir(newTenant.getTenantCode(), user.getId());
HadoopUtils.getInstance().mkdir(newUserPath); HadoopUtils.getInstance().mkdir(newUserPath);
}else { } else {
// if new tenant dir not exists , create // if new tenant dir not exists , create
createTenantDirIfNotExists(newTenant.getTenantCode()); createTenantDirIfNotExists(newTenant.getTenantCode());
} }
@ -389,7 +395,7 @@ public class UsersService extends BaseService {
* delete user * delete user
* *
* @param loginUser login user * @param loginUser login user
* @param id user id * @param id user id
* @return delete result code * @return delete result code
* @throws Exception exception when operate hdfs * @throws Exception exception when operate hdfs
*/ */
@ -411,7 +417,7 @@ public class UsersService extends BaseService {
if (user != null) { if (user != null) {
if (PropertyUtils.getResUploadStartupState()) { if (PropertyUtils.getResUploadStartupState()) {
String userPath = HadoopUtils.getHdfsUserDir(user.getTenantCode(),id); String userPath = HadoopUtils.getHdfsUserDir(user.getTenantCode(), id);
if (HadoopUtils.getInstance().exists(userPath)) { if (HadoopUtils.getInstance().exists(userPath)) {
HadoopUtils.getInstance().delete(userPath, true); HadoopUtils.getInstance().delete(userPath, true);
} }
@ -427,8 +433,8 @@ public class UsersService extends BaseService {
/** /**
* grant project * grant project
* *
* @param loginUser login user * @param loginUser login user
* @param userId user id * @param userId user id
* @param projectIds project id array * @param projectIds project id array
* @return grant result code * @return grant result code
*/ */
@ -477,8 +483,8 @@ public class UsersService extends BaseService {
/** /**
* grant resource * grant resource
* *
* @param loginUser login user * @param loginUser login user
* @param userId user id * @param userId user id
* @param resourceIds resource id array * @param resourceIds resource id array
* @return grant result code * @return grant result code
*/ */
@ -490,7 +496,7 @@ public class UsersService extends BaseService {
return result; return result;
} }
User user = userMapper.selectById(userId); User user = userMapper.selectById(userId);
if(user == null){ if (user == null) {
putMsg(result, Status.USER_NOT_EXIST, userId); putMsg(result, Status.USER_NOT_EXIST, userId);
return result; return result;
} }
@ -501,7 +507,7 @@ public class UsersService extends BaseService {
// need authorize resource id set // need authorize resource id set
for (String resourceFullId : resourceFullIdArr) { for (String resourceFullId : resourceFullIdArr) {
String[] resourceIdArr = resourceFullId.split("-"); String[] resourceIdArr = resourceFullId.split("-");
for (int i=0;i<=resourceIdArr.length-1;i++) { for (int i = 0; i <= resourceIdArr.length - 1; i++) {
int resourceIdValue = Integer.parseInt(resourceIdArr[i]); int resourceIdValue = Integer.parseInt(resourceIdArr[i]);
needAuthorizeResIds.add(resourceIdValue); needAuthorizeResIds.add(resourceIdValue);
} }
@ -528,7 +534,7 @@ public class UsersService extends BaseService {
if (CollectionUtils.isNotEmpty(resourceIdSet)) { if (CollectionUtils.isNotEmpty(resourceIdSet)) {
logger.error("can't be deleted,because it is used of process definition"); logger.error("can't be deleted,because it is used of process definition");
for (Integer resId : resourceIdSet) { for (Integer resId : resourceIdSet) {
logger.error("resource id:{} is used of process definition {}",resId,resourceProcessMap.get(resId)); logger.error("resource id:{} is used of process definition {}", resId, resourceProcessMap.get(resId));
} }
putMsg(result, Status.RESOURCE_IS_USED); putMsg(result, Status.RESOURCE_IS_USED);
return result; return result;
@ -555,7 +561,7 @@ public class UsersService extends BaseService {
resourcesUser.setResourcesId(resourceIdValue); resourcesUser.setResourcesId(resourceIdValue);
if (resource.isDirectory()) { if (resource.isDirectory()) {
resourcesUser.setPerm(Constants.AUTHORIZE_READABLE_PERM); resourcesUser.setPerm(Constants.AUTHORIZE_READABLE_PERM);
}else{ } else {
resourcesUser.setPerm(Constants.AUTHORIZE_WRITABLE_PERM); resourcesUser.setPerm(Constants.AUTHORIZE_WRITABLE_PERM);
} }
@ -575,8 +581,8 @@ public class UsersService extends BaseService {
* grant udf function * grant udf function
* *
* @param loginUser login user * @param loginUser login user
* @param userId user id * @param userId user id
* @param udfIds udf id array * @param udfIds udf id array
* @return grant result code * @return grant result code
*/ */
@Transactional(rollbackFor = RuntimeException.class) @Transactional(rollbackFor = RuntimeException.class)
@ -588,7 +594,7 @@ public class UsersService extends BaseService {
return result; return result;
} }
User user = userMapper.selectById(userId); User user = userMapper.selectById(userId);
if(user == null){ if (user == null) {
putMsg(result, Status.USER_NOT_EXIST, userId); putMsg(result, Status.USER_NOT_EXIST, userId);
return result; return result;
} }
@ -621,9 +627,9 @@ public class UsersService extends BaseService {
/** /**
* grant datasource * grant datasource
* *
* @param loginUser login user * @param loginUser login user
* @param userId user id * @param userId user id
* @param datasourceIds data source id array * @param datasourceIds data source id array
* @return grant result code * @return grant result code
*/ */
@Transactional(rollbackFor = RuntimeException.class) @Transactional(rollbackFor = RuntimeException.class)
@ -636,7 +642,7 @@ public class UsersService extends BaseService {
return result; return result;
} }
User user = userMapper.selectById(userId); User user = userMapper.selectById(userId);
if(user == null){ if (user == null) {
putMsg(result, Status.USER_NOT_EXIST, userId); putMsg(result, Status.USER_NOT_EXIST, userId);
return result; return result;
} }
@ -676,23 +682,11 @@ public class UsersService extends BaseService {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
User user = null; User user;
if (loginUser.getUserType() == UserType.ADMIN_USER) { if (loginUser.getUserType() == UserType.ADMIN_USER) {
user = loginUser; user = loginUser;
} else { } else {
user = userMapper.queryDetailsById(loginUser.getId()); user = userMapper.queryDetailsById(loginUser.getId());
List<AlertGroup> alertGroups = alertGroupMapper.queryByUserId(loginUser.getId());
StringBuilder sb = new StringBuilder();
if (alertGroups != null && alertGroups.size() > 0) {
for (int i = 0; i < alertGroups.size() - 1; i++) {
sb.append(alertGroups.get(i).getGroupName() + ",");
}
sb.append(alertGroups.get(alertGroups.size() - 1));
user.setAlertGroup(sb.toString());
}
} }
result.put(Constants.DATA_LIST, user); result.put(Constants.DATA_LIST, user);
@ -735,7 +729,7 @@ public class UsersService extends BaseService {
return result; return result;
} }
List<User> userList = userMapper.selectList(null ); List<User> userList = userMapper.selectList(null);
result.put(Constants.DATA_LIST, userList); result.put(Constants.DATA_LIST, userList);
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
@ -767,7 +761,7 @@ public class UsersService extends BaseService {
/** /**
* unauthorized user * unauthorized user
* *
* @param loginUser login user * @param loginUser login user
* @param alertgroupId alert group id * @param alertgroupId alert group id
* @return unauthorize result code * @return unauthorize result code
*/ */
@ -779,7 +773,7 @@ public class UsersService extends BaseService {
return result; return result;
} }
List<User> userList = userMapper.selectList(null ); List<User> userList = userMapper.selectList(null);
List<User> resultUsers = new ArrayList<>(); List<User> resultUsers = new ArrayList<>();
Set<User> userSet = null; Set<User> userSet = null;
if (userList != null && userList.size() > 0) { if (userList != null && userList.size() > 0) {
@ -804,7 +798,7 @@ public class UsersService extends BaseService {
/** /**
* authorized user * authorized user
* *
* @param loginUser login user * @param loginUser login user
* @param alertgroupId alert group id * @param alertgroupId alert group id
* @return authorized result code * @return authorized result code
*/ */
@ -824,8 +818,8 @@ public class UsersService extends BaseService {
/** /**
* check * check
* *
* @param result result * @param result result
* @param bool bool * @param bool bool
* @param userNoOperationPerm status * @param userNoOperationPerm status
* @return check result * @return check result
*/ */
@ -848,7 +842,6 @@ public class UsersService extends BaseService {
} }
/** /**
*
* @param userName * @param userName
* @param password * @param password
* @param email * @param email
@ -877,35 +870,36 @@ public class UsersService extends BaseService {
/** /**
* copy resource files * copy resource files
*
* @param resourceComponent resource component * @param resourceComponent resource component
* @param srcBasePath src base path * @param srcBasePath src base path
* @param dstBasePath dst base path * @param dstBasePath dst base path
* @throws IOException io exception * @throws IOException io exception
*/ */
private void copyResourceFiles(ResourceComponent resourceComponent, String srcBasePath, String dstBasePath) throws IOException { private void copyResourceFiles(ResourceComponent resourceComponent, String srcBasePath, String dstBasePath) throws IOException {
List<ResourceComponent> components = resourceComponent.getChildren(); List<ResourceComponent> components = resourceComponent.getChildren();
if (CollectionUtils.isNotEmpty(components)) { if (CollectionUtils.isNotEmpty(components)) {
for (ResourceComponent component:components) { for (ResourceComponent component : components) {
// verify whether exist // verify whether exist
if (!HadoopUtils.getInstance().exists(String.format("%s/%s",srcBasePath,component.getFullName()))){ if (!HadoopUtils.getInstance().exists(String.format("%s/%s", srcBasePath, component.getFullName()))) {
logger.error("resource file: {} not exist,copy error",component.getFullName()); logger.error("resource file: {} not exist,copy error", component.getFullName());
throw new ServiceException(Status.RESOURCE_NOT_EXIST); throw new ServiceException(Status.RESOURCE_NOT_EXIST);
} }
if (!component.isDirctory()) { if (!component.isDirctory()) {
// copy it to dst // copy it to dst
HadoopUtils.getInstance().copy(String.format("%s/%s",srcBasePath,component.getFullName()),String.format("%s/%s",dstBasePath,component.getFullName()),false,true); HadoopUtils.getInstance().copy(String.format("%s/%s", srcBasePath, component.getFullName()), String.format("%s/%s", dstBasePath, component.getFullName()), false, true);
continue; continue;
} }
if(CollectionUtils.isEmpty(component.getChildren())) { if (CollectionUtils.isEmpty(component.getChildren())) {
// if not exist,need create it // if not exist,need create it
if (!HadoopUtils.getInstance().exists(String.format("%s/%s",dstBasePath,component.getFullName()))) { if (!HadoopUtils.getInstance().exists(String.format("%s/%s", dstBasePath, component.getFullName()))) {
HadoopUtils.getInstance().mkdir(String.format("%s/%s",dstBasePath,component.getFullName())); HadoopUtils.getInstance().mkdir(String.format("%s/%s", dstBasePath, component.getFullName()));
} }
}else{ } else {
copyResourceFiles(component,srcBasePath,dstBasePath); copyResourceFiles(component, srcBasePath, dstBasePath);
} }
} }
} }
@ -929,7 +923,7 @@ public class UsersService extends BaseService {
String msg = this.checkUserParams(userName, userPassword, email, ""); String msg = this.checkUserParams(userName, userPassword, email, "");
if (!StringUtils.isEmpty(msg)) { if (!StringUtils.isEmpty(msg)) {
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR,msg); putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, msg);
return result; return result;
} }
@ -959,7 +953,7 @@ public class UsersService extends BaseService {
return result; return result;
} }
if (!CheckUtils.checkUserName(userName)){ if (!CheckUtils.checkUserName(userName)) {
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, userName); putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, userName);
return result; return result;
} }

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

@ -158,7 +158,6 @@ public class ProcessDefinitionServiceImpl extends BaseService implements
* @param locations locations for nodes * @param locations locations for nodes
* @param connects connects for nodes * @param connects connects for nodes
* @return create result code * @return create result code
* @throws JsonProcessingException JsonProcessingException
*/ */
public Map<String, Object> createProcessDefinition(User loginUser, public Map<String, Object> createProcessDefinition(User loginUser,
String projectName, String projectName,
@ -166,7 +165,7 @@ public class ProcessDefinitionServiceImpl extends BaseService implements
String processDefinitionJson, String processDefinitionJson,
String desc, String desc,
String locations, String locations,
String connects) throws JsonProcessingException { String connects) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
Project project = projectMapper.queryByName(projectName); Project project = projectMapper.queryByName(projectName);
@ -836,19 +835,14 @@ public class ProcessDefinitionServiceImpl extends BaseService implements
String processDefinitionName, String processDefinitionName,
String importProcessParam) { String importProcessParam) {
Map<String, Object> createProcessResult = null; Map<String, Object> createProcessResult = null;
try { createProcessResult = createProcessDefinition(loginUser
createProcessResult = createProcessDefinition(loginUser , currentProjectName,
, currentProjectName, processDefinitionName + "_import_" + DateUtils.getCurrentTimeStamp(),
processDefinitionName + "_import_" + DateUtils.getCurrentTimeStamp(), importProcessParam,
importProcessParam, processMeta.getProcessDefinitionDescription(),
processMeta.getProcessDefinitionDescription(), processMeta.getProcessDefinitionLocations(),
processMeta.getProcessDefinitionLocations(), processMeta.getProcessDefinitionConnects());
processMeta.getProcessDefinitionConnects()); putMsg(result, Status.SUCCESS);
putMsg(result, Status.SUCCESS);
} catch (JsonProcessingException e) {
logger.error("import process meta json data: {}", e.getMessage(), e);
putMsg(result, Status.IMPORT_PROCESS_DEFINE_ERROR);
}
return createProcessResult; return createProcessResult;
} }
@ -1056,8 +1050,7 @@ public class ProcessDefinitionServiceImpl extends BaseService implements
processDefine.setCreateTime(now); processDefine.setCreateTime(now);
processDefine.setUpdateTime(now); processDefine.setUpdateTime(now);
processDefine.setFlag(subProcess.getFlag()); processDefine.setFlag(subProcess.getFlag());
processDefine.setReceivers(subProcess.getReceivers()); processDefine.setWarningGroupId(subProcess.getWarningGroupId());
processDefine.setReceiversCc(subProcess.getReceiversCc());
processDefineMapper.insert(processDefine); processDefineMapper.insert(processDefine);
logger.info("create sub process, project: {}, process name: {}", targetProject.getName(), processDefine.getName()); logger.info("create sub process, project: {}, process name: {}", targetProject.getName(), processDefine.getName());
@ -1330,7 +1323,7 @@ public class ProcessDefinitionServiceImpl extends BaseService implements
} }
runningNodeMap.remove(nodeName); runningNodeMap.remove(nodeName);
} }
if (waitingRunningNodeMap == null || waitingRunningNodeMap.size() == 0) { if (waitingRunningNodeMap.size() == 0) {
break; break;
} else { } else {
runningNodeMap.putAll(waitingRunningNodeMap); runningNodeMap.putAll(waitingRunningNodeMap);
@ -1580,8 +1573,7 @@ public class ProcessDefinitionServiceImpl extends BaseService implements
processDefinition.setTimeout(processDefinitionVersion.getTimeout()); processDefinition.setTimeout(processDefinitionVersion.getTimeout());
processDefinition.setGlobalParams(processDefinitionVersion.getGlobalParams()); processDefinition.setGlobalParams(processDefinitionVersion.getGlobalParams());
processDefinition.setUpdateTime(new Date()); processDefinition.setUpdateTime(new Date());
processDefinition.setReceivers(processDefinitionVersion.getReceivers()); processDefinition.setWarningGroupId(processDefinitionVersion.getWarningGroupId());
processDefinition.setReceiversCc(processDefinitionVersion.getReceiversCc());
processDefinition.setResourceIds(processDefinitionVersion.getResourceIds()); processDefinition.setResourceIds(processDefinitionVersion.getResourceIds());
if (processDefineMapper.updateById(processDefinition) > 0) { if (processDefineMapper.updateById(processDefinition) > 0) {

23
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionVersionServiceImpl.java

@ -66,18 +66,17 @@ public class ProcessDefinitionVersionServiceImpl extends BaseService implements
long version = this.queryMaxVersionByProcessDefinitionId(processDefinition.getId()) + 1; long version = this.queryMaxVersionByProcessDefinitionId(processDefinition.getId()) + 1;
ProcessDefinitionVersion processDefinitionVersion = ProcessDefinitionVersion ProcessDefinitionVersion processDefinitionVersion = ProcessDefinitionVersion
.newBuilder() .newBuilder()
.processDefinitionId(processDefinition.getId()) .processDefinitionId(processDefinition.getId())
.version(version) .version(version)
.processDefinitionJson(processDefinition.getProcessDefinitionJson()) .processDefinitionJson(processDefinition.getProcessDefinitionJson())
.description(processDefinition.getDescription()) .description(processDefinition.getDescription())
.locations(processDefinition.getLocations()) .locations(processDefinition.getLocations())
.connects(processDefinition.getConnects()) .connects(processDefinition.getConnects())
.timeout(processDefinition.getTimeout()) .timeout(processDefinition.getTimeout())
.globalParams(processDefinition.getGlobalParams()) .globalParams(processDefinition.getGlobalParams())
.createTime(processDefinition.getUpdateTime()) .createTime(processDefinition.getUpdateTime())
.receivers(processDefinition.getReceivers()) .warningGroupId(processDefinition.getWarningGroupId())
.receiversCc(processDefinition.getReceiversCc())
.resourceIds(processDefinition.getResourceIds()) .resourceIds(processDefinition.getResourceIds())
.build(); .build();

100
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ExecutorControllerTest.java

@ -14,14 +14,20 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.dolphinscheduler.api.controller; package org.apache.dolphinscheduler.api.controller;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.apache.dolphinscheduler.api.enums.ExecuteType; import org.apache.dolphinscheduler.api.enums.ExecuteType;
import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.enums.FailureStrategy; import org.apache.dolphinscheduler.common.enums.FailureStrategy;
import org.apache.dolphinscheduler.common.enums.WarningType; import org.apache.dolphinscheduler.common.enums.WarningType;
import org.apache.dolphinscheduler.common.utils.*; import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -32,44 +38,39 @@ import org.springframework.test.web.servlet.MvcResult;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/** /**
* executor controller test * executor controller test
*/ */
public class ExecutorControllerTest extends AbstractControllerTest{ public class ExecutorControllerTest extends AbstractControllerTest {
private static Logger logger = LoggerFactory.getLogger(ExecutorControllerTest.class); private static Logger logger = LoggerFactory.getLogger(ExecutorControllerTest.class);
@Ignore @Ignore
@Test @Test
public void testStartProcessInstance() throws Exception { public void testStartProcessInstance() throws Exception {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("processDefinitionId","40"); paramsMap.add("processDefinitionId", "40");
paramsMap.add("scheduleTime",""); paramsMap.add("scheduleTime", "");
paramsMap.add("failureStrategy", String.valueOf(FailureStrategy.CONTINUE)); paramsMap.add("failureStrategy", String.valueOf(FailureStrategy.CONTINUE));
paramsMap.add("startNodeList",""); paramsMap.add("startNodeList", "");
paramsMap.add("taskDependType",""); paramsMap.add("taskDependType", "");
paramsMap.add("execType",""); paramsMap.add("execType", "");
paramsMap.add("warningType", String.valueOf(WarningType.NONE)); paramsMap.add("warningType", String.valueOf(WarningType.NONE));
paramsMap.add("warningGroupId",""); paramsMap.add("warningGroupId", "");
paramsMap.add("receivers",""); paramsMap.add("receivers", "");
paramsMap.add("receiversCc",""); paramsMap.add("receiversCc", "");
paramsMap.add("runMode",""); paramsMap.add("runMode", "");
paramsMap.add("processInstancePriority",""); paramsMap.add("processInstancePriority", "");
paramsMap.add("workerGroupId",""); paramsMap.add("workerGroupId", "");
paramsMap.add("timeout",""); paramsMap.add("timeout", "");
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/executors/start-process-instance","cxc_1113") MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/executors/start-process-instance", "cxc_1113")
.header("sessionId", sessionId) .header("sessionId", sessionId)
.params(paramsMap)) .params(paramsMap))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andReturn(); .andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString()); logger.info(mvcResult.getResponse().getContentAsString());
} }
@ -77,47 +78,32 @@ public class ExecutorControllerTest extends AbstractControllerTest{
@Test @Test
public void testExecute() throws Exception { public void testExecute() throws Exception {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("processInstanceId","40"); paramsMap.add("processInstanceId", "40");
paramsMap.add("executeType",String.valueOf(ExecuteType.NONE)); paramsMap.add("executeType", String.valueOf(ExecuteType.NONE));
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/executors/execute","cxc_1113") MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/executors/execute", "cxc_1113")
.header("sessionId", sessionId) .header("sessionId", sessionId)
.params(paramsMap)) .params(paramsMap))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andReturn(); .andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString()); logger.info(mvcResult.getResponse().getContentAsString());
} }
@Test @Test
public void testStartCheckProcessDefinition() throws Exception { public void testStartCheckProcessDefinition() throws Exception {
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/executors/start-check","cxc_1113") MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/executors/start-check", "cxc_1113")
.header(SESSION_ID, sessionId) .header(SESSION_ID, sessionId)
.param("processDefinitionId","40")) .param("processDefinitionId", "40"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andReturn(); .andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString()); logger.info(mvcResult.getResponse().getContentAsString());
} }
@Test
public void testGetReceiverCc() throws Exception {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("processInstanceId","13");
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/executors/get-receiver-cc","cxc_1113")
.header(SESSION_ID, sessionId)
.params(paramsMap))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
}
} }

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

@ -14,14 +14,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.dolphinscheduler.api.service; package org.apache.dolphinscheduler.api.service;
import com.baomidou.mybatisplus.core.metadata.IPage; import static org.mockito.ArgumentMatchers.any;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import static org.mockito.ArgumentMatchers.eq;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
@ -31,15 +29,15 @@ import org.apache.dolphinscheduler.common.utils.CollectionUtils;
import org.apache.dolphinscheduler.dao.entity.AlertGroup; import org.apache.dolphinscheduler.dao.entity.AlertGroup;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper; import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper;
import org.apache.dolphinscheduler.dao.mapper.UserAlertGroupMapper;
import org.junit.After; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Assert; import org.junit.Assert;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import static org.mockito.ArgumentMatchers.*;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
@ -47,6 +45,9 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class AlertGroupServiceTest { public class AlertGroupServiceTest {
@ -56,128 +57,97 @@ public class AlertGroupServiceTest {
private AlertGroupService alertGroupService; private AlertGroupService alertGroupService;
@Mock @Mock
private AlertGroupMapper alertGroupMapper; private AlertGroupMapper alertGroupMapper;
@Mock
private UserAlertGroupMapper userAlertGroupMapper;
@Mock
UserAlertGroupService userAlertGroupService;
private String groupName = "AlertGroupServiceTest"; private String groupName = "AlertGroupServiceTest";
@Before
public void setUp() {
}
@After
public void after(){
}
@Test @Test
public void testQueryAlertGroup(){ public void testQueryAlertGroup() {
Mockito.when(alertGroupMapper.queryAllGroupList()).thenReturn(getList()); Mockito.when(alertGroupMapper.queryAllGroupList()).thenReturn(getList());
HashMap<String, Object> result= alertGroupService.queryAlertgroup(); HashMap<String, Object> result = alertGroupService.queryAlertgroup();
logger.info(result.toString()); logger.info(result.toString());
List<AlertGroup> alertGroups = (List<AlertGroup>) result.get(Constants.DATA_LIST); List<AlertGroup> alertGroups = (List<AlertGroup>) result.get(Constants.DATA_LIST);
Assert.assertTrue(CollectionUtils.isNotEmpty(alertGroups)); Assert.assertTrue(CollectionUtils.isNotEmpty(alertGroups));
} }
@Test @Test
public void testListPaging(){ public void testListPaging() {
IPage<AlertGroup> page = new Page<>(1,10); IPage<AlertGroup> page = new Page<>(1, 10);
page.setTotal(1L); page.setTotal(1L);
page.setRecords(getList()); page.setRecords(getList());
Mockito.when(alertGroupMapper.queryAlertGroupPage(any(Page.class),eq(groupName))).thenReturn(page); Mockito.when(alertGroupMapper.queryAlertGroupPage(any(Page.class), eq(groupName))).thenReturn(page);
User user = new User(); User user = new User();
// no operate // no operate
Map<String, Object> result = alertGroupService.listPaging(user,groupName,1,10); Map<String, Object> result = alertGroupService.listPaging(user, groupName, 1, 10);
logger.info(result.toString()); logger.info(result.toString());
Assert.assertEquals(Status.USER_NO_OPERATION_PERM,result.get(Constants.STATUS)); Assert.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS));
//success //success
user.setUserType(UserType.ADMIN_USER); user.setUserType(UserType.ADMIN_USER);
result = alertGroupService.listPaging(user,groupName,1,10); result = alertGroupService.listPaging(user, groupName, 1, 10);
logger.info(result.toString()); logger.info(result.toString());
PageInfo<AlertGroup> pageInfo = (PageInfo<AlertGroup>) result.get(Constants.DATA_LIST); PageInfo<AlertGroup> pageInfo = (PageInfo<AlertGroup>) result.get(Constants.DATA_LIST);
Assert.assertTrue(CollectionUtils.isNotEmpty(pageInfo.getLists())); Assert.assertTrue(CollectionUtils.isNotEmpty(pageInfo.getLists()));
} }
@Test
public void testCreateAlertgroup(){
@Test
public void testCreateAlertgroup() {
Mockito.when(alertGroupMapper.insert(any(AlertGroup.class))).thenReturn(2); Mockito.when(alertGroupMapper.insert(any(AlertGroup.class))).thenReturn(2);
User user = new User(); User user = new User();
//no operate //no operate
Map<String, Object> result = alertGroupService.createAlertgroup(user,groupName, AlertType.EMAIL,groupName); Map<String, Object> result = alertGroupService.createAlertgroup(user, groupName, AlertType.EMAIL, groupName);
logger.info(result.toString()); logger.info(result.toString());
Assert.assertEquals(Status.USER_NO_OPERATION_PERM,result.get(Constants.STATUS)); Assert.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS));
user.setUserType(UserType.ADMIN_USER); user.setUserType(UserType.ADMIN_USER);
//success //success
result = alertGroupService.createAlertgroup(user,groupName, AlertType.EMAIL,groupName); result = alertGroupService.createAlertgroup(user, groupName, AlertType.EMAIL, groupName);
logger.info(result.toString()); logger.info(result.toString());
Assert.assertEquals(Status.SUCCESS,result.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
} }
@Test @Test
public void testUpdateAlertgroup(){ public void testUpdateAlertgroup() {
User user = new User(); User user = new User();
// no operate // no operate
Map<String, Object> result = alertGroupService.updateAlertgroup(user,1,groupName, AlertType.SMS,groupName); Map<String, Object> result = alertGroupService.updateAlertgroup(user, 1, groupName, AlertType.SMS, groupName);
logger.info(result.toString()); logger.info(result.toString());
Assert.assertEquals(Status.USER_NO_OPERATION_PERM,result.get(Constants.STATUS)); Assert.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS));
user.setUserType(UserType.ADMIN_USER); user.setUserType(UserType.ADMIN_USER);
// not exist // not exist
result = alertGroupService.updateAlertgroup(user,1,groupName, AlertType.SMS,groupName); result = alertGroupService.updateAlertgroup(user, 1, groupName, AlertType.SMS, groupName);
logger.info(result.toString()); logger.info(result.toString());
Assert.assertEquals(Status.ALERT_GROUP_NOT_EXIST,result.get(Constants.STATUS)); Assert.assertEquals(Status.ALERT_GROUP_NOT_EXIST, result.get(Constants.STATUS));
//success //success
Mockito.when(alertGroupMapper.selectById(2)).thenReturn(getEntity()); Mockito.when(alertGroupMapper.selectById(2)).thenReturn(getEntity());
result = alertGroupService.updateAlertgroup(user,2,groupName, AlertType.SMS,groupName); result = alertGroupService.updateAlertgroup(user, 2, groupName, AlertType.SMS, groupName);
logger.info(result.toString()); logger.info(result.toString());
Assert.assertEquals(Status.SUCCESS,result.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
} }
@Test @Test
public void testDelAlertgroupById(){ public void testDelAlertgroupById() {
User user = new User(); User user = new User();
// no operate // no operate
Map<String, Object> result = alertGroupService.delAlertgroupById(user,1); Map<String, Object> result = alertGroupService.delAlertgroupById(user, 1);
logger.info(result.toString()); logger.info(result.toString());
Assert.assertEquals(Status.USER_NO_OPERATION_PERM,result.get(Constants.STATUS)); Assert.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS));
user.setUserType(UserType.ADMIN_USER); user.setUserType(UserType.ADMIN_USER);
// not exist // not exist
result = alertGroupService.delAlertgroupById(user,2); result = alertGroupService.delAlertgroupById(user, 2);
logger.info(result.toString()); logger.info(result.toString());
Assert.assertEquals(Status.ALERT_GROUP_NOT_EXIST,result.get(Constants.STATUS)); Assert.assertEquals(Status.ALERT_GROUP_NOT_EXIST, result.get(Constants.STATUS));
//success //success
Mockito.when(alertGroupMapper.selectById(2)).thenReturn(getEntity()); Mockito.when(alertGroupMapper.selectById(2)).thenReturn(getEntity());
result = alertGroupService.delAlertgroupById(user,2); result = alertGroupService.delAlertgroupById(user, 2);
logger.info(result.toString()); logger.info(result.toString());
Assert.assertEquals(Status.SUCCESS,result.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
} }
@Test
public void testGrantUser() {
Integer groupId = 1;
ArgumentCaptor<Integer> groupArgument = ArgumentCaptor.forClass(Integer.class);
Mockito.when(userAlertGroupService.deleteByAlertGroupId(anyInt())).thenReturn(true);
Map<String, Object> result = alertGroupService.grantUser(getLoginUser(), groupId, "123,321");
Mockito.verify(userAlertGroupService).deleteByAlertGroupId(groupArgument.capture());
logger.info(result.toString());
assertEquals(groupArgument.getValue(), groupId);
assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
}
@Test @Test
public void testVerifyGroupName() { public void testVerifyGroupName() {
//group name not exist //group name not exist
@ -190,12 +160,12 @@ public class AlertGroupServiceTest {
Assert.assertTrue(result); Assert.assertTrue(result);
} }
/** /**
* create admin user * create admin user
*
* @return * @return
*/ */
private User getLoginUser(){ private User getLoginUser() {
User loginUser = new User(); User loginUser = new User();
loginUser.setUserType(UserType.ADMIN_USER); loginUser.setUserType(UserType.ADMIN_USER);
@ -205,9 +175,10 @@ public class AlertGroupServiceTest {
/** /**
* get list * get list
*
* @return * @return
*/ */
private List<AlertGroup> getList(){ private List<AlertGroup> getList() {
List<AlertGroup> alertGroups = new ArrayList<>(); List<AlertGroup> alertGroups = new ArrayList<>();
alertGroups.add(getEntity()); alertGroups.add(getEntity());
return alertGroups; return alertGroups;
@ -215,13 +186,13 @@ public class AlertGroupServiceTest {
/** /**
* get entity * get entity
*
* @return * @return
*/ */
private AlertGroup getEntity(){ private AlertGroup getEntity() {
AlertGroup alertGroup = new AlertGroup(); AlertGroup alertGroup = new AlertGroup();
alertGroup.setId(1); alertGroup.setId(1);
alertGroup.setGroupName(groupName); alertGroup.setGroupName(groupName);
alertGroup.setGroupType(AlertType.EMAIL);
return alertGroup; return alertGroup;
} }

126
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorService2Test.java

@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.dolphinscheduler.api.service; package org.apache.dolphinscheduler.api.service;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
@ -126,18 +127,17 @@ public class ExecutorService2Test {
*/ */
@Test @Test
public void testNoComplement() throws ParseException { public void testNoComplement() throws ParseException {
try {
Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList()); Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList());
Map<String, Object> result = executorService.execProcessInstance(loginUser, projectName, Map<String, Object> result = executorService.execProcessInstance(loginUser, projectName,
processDefinitionId, cronTime, CommandType.START_PROCESS, processDefinitionId, cronTime, CommandType.START_PROCESS,
null, null, null, null,
null, null, 0, null, null, 0,
"", "", RunMode.RUN_MODE_SERIAL, RunMode.RUN_MODE_SERIAL,
Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110); Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110);
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
verify(processService, times(1)).createCommand(any(Command.class)); verify(processService, times(1)).createCommand(any(Command.class));
} catch (Exception e) {
}
} }
/** /**
@ -145,18 +145,16 @@ public class ExecutorService2Test {
*/ */
@Test @Test
public void testDateError() throws ParseException { public void testDateError() throws ParseException {
try {
Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList()); Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList());
Map<String, Object> result = executorService.execProcessInstance(loginUser, projectName, Map<String, Object> result = executorService.execProcessInstance(loginUser, projectName,
processDefinitionId, "2020-01-31 23:00:00,2020-01-01 00:00:00", CommandType.COMPLEMENT_DATA, processDefinitionId, "2020-01-31 23:00:00,2020-01-01 00:00:00", CommandType.COMPLEMENT_DATA,
null, null, null, null,
null, null, 0, null, null, 0,
"", "", RunMode.RUN_MODE_SERIAL, RunMode.RUN_MODE_SERIAL,
Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110); Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110);
Assert.assertEquals(Status.START_PROCESS_INSTANCE_ERROR, result.get(Constants.STATUS)); Assert.assertEquals(Status.START_PROCESS_INSTANCE_ERROR, result.get(Constants.STATUS));
verify(processService, times(0)).createCommand(any(Command.class)); verify(processService, times(0)).createCommand(any(Command.class));
} catch (Exception e) {
}
} }
/** /**
@ -164,18 +162,16 @@ public class ExecutorService2Test {
*/ */
@Test @Test
public void testSerial() throws ParseException { public void testSerial() throws ParseException {
try {
Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList()); Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList());
Map<String, Object> result = executorService.execProcessInstance(loginUser, projectName, Map<String, Object> result = executorService.execProcessInstance(loginUser, projectName,
processDefinitionId, cronTime, CommandType.COMPLEMENT_DATA, processDefinitionId, cronTime, CommandType.COMPLEMENT_DATA,
null, null, null, null,
null, null, 0, null, null, 0,
"", "", RunMode.RUN_MODE_SERIAL, RunMode.RUN_MODE_SERIAL,
Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110); Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110);
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
verify(processService, times(1)).createCommand(any(Command.class)); verify(processService, times(1)).createCommand(any(Command.class));
} catch (Exception e) {
}
} }
/** /**
@ -183,18 +179,17 @@ public class ExecutorService2Test {
*/ */
@Test @Test
public void testParallelWithOutSchedule() throws ParseException { public void testParallelWithOutSchedule() throws ParseException {
try {
Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList()); Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList());
Map<String, Object> result = executorService.execProcessInstance(loginUser, projectName, Map<String, Object> result = executorService.execProcessInstance(loginUser, projectName,
processDefinitionId, cronTime, CommandType.COMPLEMENT_DATA, processDefinitionId, cronTime, CommandType.COMPLEMENT_DATA,
null, null, null, null,
null, null, 0, null, null, 0,
"", "", RunMode.RUN_MODE_PARALLEL, RunMode.RUN_MODE_PARALLEL,
Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110); Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110);
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
verify(processService, times(31)).createCommand(any(Command.class)); verify(processService, times(31)).createCommand(any(Command.class));
} catch (Exception e) {
}
} }
/** /**
@ -202,31 +197,28 @@ public class ExecutorService2Test {
*/ */
@Test @Test
public void testParallelWithSchedule() throws ParseException { public void testParallelWithSchedule() throws ParseException {
try {
Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(oneSchedulerList());
Map<String, Object> result = executorService.execProcessInstance(loginUser, projectName,
processDefinitionId, cronTime, CommandType.COMPLEMENT_DATA,
null, null,
null, null, 0,
"", "", RunMode.RUN_MODE_PARALLEL,
Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110);
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
verify(processService, times(15)).createCommand(any(Command.class));
} catch (Exception e) {
}
}
Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(oneSchedulerList());
Map<String, Object> result = executorService.execProcessInstance(loginUser, projectName,
processDefinitionId, cronTime, CommandType.COMPLEMENT_DATA,
null, null,
null, null, 0,
RunMode.RUN_MODE_PARALLEL,
Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110);
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
verify(processService, times(15)).createCommand(any(Command.class));
}
@Test @Test
public void testNoMsterServers() throws ParseException { public void testNoMasterServers() throws ParseException {
Mockito.when(monitorService.getServerListFromZK(true)).thenReturn(new ArrayList<Server>()); Mockito.when(monitorService.getServerListFromZK(true)).thenReturn(new ArrayList<Server>());
Map<String, Object> result = executorService.execProcessInstance(loginUser, projectName, Map<String, Object> result = executorService.execProcessInstance(loginUser, projectName,
processDefinitionId, cronTime, CommandType.COMPLEMENT_DATA, processDefinitionId, cronTime, CommandType.COMPLEMENT_DATA,
null, null, null, null,
null, null, 0, null, null, 0,
"", "", RunMode.RUN_MODE_PARALLEL, RunMode.RUN_MODE_PARALLEL,
Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110); Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110);
Assert.assertEquals(result.get(Constants.STATUS), Status.MASTER_NOT_EXISTS); Assert.assertEquals(result.get(Constants.STATUS), Status.MASTER_NOT_EXISTS);
} }

23
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionVersionServiceTest.java

@ -216,18 +216,17 @@ public class ProcessDefinitionVersionServiceTest {
*/ */
private ProcessDefinitionVersion getProcessDefinitionVersion(ProcessDefinition processDefinition) { private ProcessDefinitionVersion getProcessDefinitionVersion(ProcessDefinition processDefinition) {
return ProcessDefinitionVersion return ProcessDefinitionVersion
.newBuilder() .newBuilder()
.processDefinitionId(processDefinition.getId()) .processDefinitionId(processDefinition.getId())
.version(1) .version(1)
.processDefinitionJson(processDefinition.getProcessDefinitionJson()) .processDefinitionJson(processDefinition.getProcessDefinitionJson())
.description(processDefinition.getDescription()) .description(processDefinition.getDescription())
.locations(processDefinition.getLocations()) .locations(processDefinition.getLocations())
.connects(processDefinition.getConnects()) .connects(processDefinition.getConnects())
.timeout(processDefinition.getTimeout()) .timeout(processDefinition.getTimeout())
.globalParams(processDefinition.getGlobalParams()) .globalParams(processDefinition.getGlobalParams())
.createTime(processDefinition.getUpdateTime()) .createTime(processDefinition.getUpdateTime())
.receivers(processDefinition.getReceivers()) .warningGroupId(processDefinition.getWarningGroupId())
.receiversCc(processDefinition.getReceiversCc())
.resourceIds(processDefinition.getResourceIds()) .resourceIds(processDefinition.getResourceIds())
.build(); .build();
} }

53
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UserAlertGroupServiceTest.java

@ -1,53 +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.api.service;
import org.apache.dolphinscheduler.dao.mapper.UserAlertGroupMapper;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
/**
*
*/
@RunWith(MockitoJUnitRunner.class)
public class UserAlertGroupServiceTest {
@InjectMocks
UserAlertGroupService userAlertGroupService;
@Mock
UserAlertGroupMapper userAlertGroupMapper;
@Test
public void deleteByAlertGroupId() {
Integer groupId = 1;
userAlertGroupService.deleteByAlertGroupId(groupId);
ArgumentCaptor<Integer> argumentCaptor = ArgumentCaptor.forClass(Integer.class);
Mockito.verify(userAlertGroupMapper).deleteByAlertgroupId(argumentCaptor.capture());
assertEquals(argumentCaptor.getValue(), groupId);
}
}

85
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/AlertDao.java

@ -19,10 +19,8 @@ package org.apache.dolphinscheduler.dao;
import org.apache.dolphinscheduler.common.enums.AlertEvent; import org.apache.dolphinscheduler.common.enums.AlertEvent;
import org.apache.dolphinscheduler.common.enums.AlertStatus; import org.apache.dolphinscheduler.common.enums.AlertStatus;
import org.apache.dolphinscheduler.common.enums.AlertType;
import org.apache.dolphinscheduler.common.enums.AlertWarnLevel; import org.apache.dolphinscheduler.common.enums.AlertWarnLevel;
import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.common.utils.StringUtils;
import org.apache.dolphinscheduler.dao.datasource.ConnectionFactory; import org.apache.dolphinscheduler.dao.datasource.ConnectionFactory;
import org.apache.dolphinscheduler.dao.entity.Alert; import org.apache.dolphinscheduler.dao.entity.Alert;
import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance; import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
@ -30,11 +28,9 @@ import org.apache.dolphinscheduler.dao.entity.ProcessAlertContent;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
import org.apache.dolphinscheduler.dao.entity.ServerAlertContent; import org.apache.dolphinscheduler.dao.entity.ServerAlertContent;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper; import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper;
import org.apache.dolphinscheduler.dao.mapper.AlertMapper; import org.apache.dolphinscheduler.dao.mapper.AlertMapper;
import org.apache.dolphinscheduler.dao.mapper.AlertPluginInstanceMapper; import org.apache.dolphinscheduler.dao.mapper.AlertPluginInstanceMapper;
import org.apache.dolphinscheduler.dao.mapper.UserAlertGroupMapper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -53,9 +49,6 @@ public class AlertDao extends AbstractBaseDao {
@Autowired @Autowired
private AlertMapper alertMapper; private AlertMapper alertMapper;
@Autowired
private UserAlertGroupMapper userAlertGroupMapper;
@Autowired @Autowired
private AlertPluginInstanceMapper alertPluginInstanceMapper; private AlertPluginInstanceMapper alertPluginInstanceMapper;
@ -65,7 +58,6 @@ public class AlertDao extends AbstractBaseDao {
@Override @Override
protected void init() { protected void init() {
alertMapper = ConnectionFactory.getInstance().getMapper(AlertMapper.class); alertMapper = ConnectionFactory.getInstance().getMapper(AlertMapper.class);
userAlertGroupMapper = ConnectionFactory.getInstance().getMapper(UserAlertGroupMapper.class);
alertPluginInstanceMapper = ConnectionFactory.getInstance().getMapper(AlertPluginInstanceMapper.class); alertPluginInstanceMapper = ConnectionFactory.getInstance().getMapper(AlertPluginInstanceMapper.class);
alertGroupMapper = ConnectionFactory.getInstance().getMapper(AlertGroupMapper.class); alertGroupMapper = ConnectionFactory.getInstance().getMapper(AlertGroupMapper.class);
} }
@ -96,34 +88,23 @@ public class AlertDao extends AbstractBaseDao {
return alertMapper.updateById(alert); return alertMapper.updateById(alert);
} }
/**
* query user list by alert group id
*
* @param alerGroupId alerGroupId
* @return user list
*/
public List<User> queryUserByAlertGroupId(int alerGroupId) {
return userAlertGroupMapper.listUserByAlertgroupId(alerGroupId);
}
/** /**
* MasterServer or WorkerServer stoped * MasterServer or WorkerServer stoped
* *
* @param alertgroupId alertgroupId * @param alertGroupId alertGroupId
* @param host host * @param host host
* @param serverType serverType * @param serverType serverType
*/ */
public void sendServerStopedAlert(int alertgroupId, String host, String serverType) { public void sendServerStopedAlert(int alertGroupId, String host, String serverType) {
Alert alert = new Alert(); Alert alert = new Alert();
List<ServerAlertContent> serverAlertContents = new ArrayList<>(1); List<ServerAlertContent> serverAlertContents = new ArrayList<>(1);
ServerAlertContent serverStopAlertContent = ServerAlertContent.newBuilder(). ServerAlertContent serverStopAlertContent = ServerAlertContent.newBuilder().
type(serverType).host(host).event(AlertEvent.SERVER_DOWN).warningLevel(AlertWarnLevel.SERIOUS). type(serverType).host(host).event(AlertEvent.SERVER_DOWN).warningLevel(AlertWarnLevel.SERIOUS).
build(); build();
serverAlertContents.add(serverStopAlertContent); serverAlertContents.add(serverStopAlertContent);
String content = JSONUtils.toJsonString(serverAlertContents); String content = JSONUtils.toJsonString(serverAlertContents);
alert.setTitle("Fault tolerance warning"); alert.setTitle("Fault tolerance warning");
saveTaskTimeoutAlert(alert, content, alertgroupId, null, null); saveTaskTimeoutAlert(alert, content, alertGroupId);
} }
/** /**
@ -133,34 +114,24 @@ public class AlertDao extends AbstractBaseDao {
* @param processDefinition processDefinition * @param processDefinition processDefinition
*/ */
public void sendProcessTimeoutAlert(ProcessInstance processInstance, ProcessDefinition processDefinition) { public void sendProcessTimeoutAlert(ProcessInstance processInstance, ProcessDefinition processDefinition) {
int alertgroupId = processInstance.getWarningGroupId(); int alertGroupId = processInstance.getWarningGroupId();
String receivers = processDefinition.getReceivers();
String receiversCc = processDefinition.getReceiversCc();
Alert alert = new Alert(); Alert alert = new Alert();
List<ProcessAlertContent> processAlertContentList = new ArrayList<>(1); List<ProcessAlertContent> processAlertContentList = new ArrayList<>(1);
ProcessAlertContent processAlertContent = ProcessAlertContent.newBuilder() ProcessAlertContent processAlertContent = ProcessAlertContent.newBuilder()
.processId(processInstance.getId()) .processId(processInstance.getId())
.processName(processInstance.getName()) .processName(processInstance.getName())
.event(AlertEvent.TIME_OUT) .event(AlertEvent.TIME_OUT)
.warningLevel(AlertWarnLevel.MIDDLE) .warningLevel(AlertWarnLevel.MIDDLE)
.build(); .build();
processAlertContentList.add(processAlertContent); processAlertContentList.add(processAlertContent);
String content = JSONUtils.toJsonString(processAlertContentList); String content = JSONUtils.toJsonString(processAlertContentList);
alert.setTitle("Process Timeout Warn"); alert.setTitle("Process Timeout Warn");
saveTaskTimeoutAlert(alert, content, alertgroupId, receivers, receiversCc); saveTaskTimeoutAlert(alert, content, alertGroupId);
} }
private void saveTaskTimeoutAlert(Alert alert, String content, int alertgroupId, String receivers, String receiversCc) { private void saveTaskTimeoutAlert(Alert alert, String content, int alertGroupId) {
//alert.setShowType(ShowType.TABLE); alert.setAlertGroupId(alertGroupId);
alert.setContent(content); alert.setContent(content);
alert.setAlertType(AlertType.EMAIL);
alert.setAlertGroupId(alertgroupId);
if (StringUtils.isNotEmpty(receivers)) {
alert.setReceivers(receivers);
}
if (StringUtils.isNotEmpty(receiversCc)) {
alert.setReceiversCc(receiversCc);
}
alert.setCreateTime(new Date()); alert.setCreateTime(new Date());
alert.setUpdateTime(new Date()); alert.setUpdateTime(new Date());
alertMapper.insert(alert); alertMapper.insert(alert);
@ -169,30 +140,28 @@ public class AlertDao extends AbstractBaseDao {
/** /**
* task timeout warn * task timeout warn
* *
* @param alertgroupId alertgroupId * @param alertGroupId alertGroupId
* @param receivers receivers
* @param receiversCc receiversCc
* @param processInstanceId processInstanceId * @param processInstanceId processInstanceId
* @param processInstanceName processInstanceName * @param processInstanceName processInstanceName
* @param taskId taskId * @param taskId taskId
* @param taskName taskName * @param taskName taskName
*/ */
public void sendTaskTimeoutAlert(int alertgroupId, String receivers, String receiversCc, int processInstanceId, public void sendTaskTimeoutAlert(int alertGroupId, int processInstanceId,
String processInstanceName, int taskId, String taskName) { String processInstanceName, int taskId, String taskName) {
Alert alert = new Alert(); Alert alert = new Alert();
List<ProcessAlertContent> processAlertContentList = new ArrayList<>(1); List<ProcessAlertContent> processAlertContentList = new ArrayList<>(1);
ProcessAlertContent processAlertContent = ProcessAlertContent.newBuilder() ProcessAlertContent processAlertContent = ProcessAlertContent.newBuilder()
.processId(processInstanceId) .processId(processInstanceId)
.processName(processInstanceName) .processName(processInstanceName)
.taskId(taskId) .taskId(taskId)
.taskName(taskName) .taskName(taskName)
.event(AlertEvent.TIME_OUT) .event(AlertEvent.TIME_OUT)
.warningLevel(AlertWarnLevel.MIDDLE) .warningLevel(AlertWarnLevel.MIDDLE)
.build(); .build();
processAlertContentList.add(processAlertContent); processAlertContentList.add(processAlertContent);
String content = JSONUtils.toJsonString(processAlertContentList); String content = JSONUtils.toJsonString(processAlertContentList);
alert.setTitle("Task Timeout Warn"); alert.setTitle("Task Timeout Warn");
saveTaskTimeoutAlert(alert, content, alertgroupId, receivers, receiversCc); saveTaskTimeoutAlert(alert, content, alertGroupId);
} }
/** /**
@ -204,16 +173,6 @@ public class AlertDao extends AbstractBaseDao {
return alertMapper.listAlertByStatus(AlertStatus.WAIT_EXECUTION); return alertMapper.listAlertByStatus(AlertStatus.WAIT_EXECUTION);
} }
/**
* list user information by alert group id
*
* @param alertgroupId alertgroupId
* @return user list
*/
public List<User> listUserByAlertgroupId(int alertgroupId) {
return userAlertGroupMapper.listUserByAlertgroupId(alertgroupId);
}
/** /**
* for test * for test
* *

85
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Alert.java

@ -18,7 +18,6 @@
package org.apache.dolphinscheduler.dao.entity; package org.apache.dolphinscheduler.dao.entity;
import org.apache.dolphinscheduler.common.enums.AlertStatus; import org.apache.dolphinscheduler.common.enums.AlertStatus;
import org.apache.dolphinscheduler.common.enums.AlertType;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@ -41,23 +40,13 @@ public class Alert {
*/ */
@TableField(value = "title") @TableField(value = "title")
private String title; private String title;
/**
* show_type
*/
//TODO ShowType should be delete from Alert, Because showType is move to the plugin params
@TableField(value = "show_type")
private String showType;
/** /**
* content * content
*/ */
@TableField(value = "content") @TableField(value = "content")
private String content; private String content;
/**
* alert_type
*/
//TODO alertType should be delete from Alert, because alert type is decide by the AlertPlugin instance
@TableField(value = "alert_type")
private AlertType alertType;
/** /**
* alert_status * alert_status
*/ */
@ -73,18 +62,7 @@ public class Alert {
*/ */
@TableField("alertgroup_id") @TableField("alertgroup_id")
private int alertGroupId; private int alertGroupId;
/**
* receivers
*/
//TODO receivers should be delete from Alert, because only email alert need receivers . And receivers is move to Email Alert Plugin params.
@TableField("receivers")
private String receivers;
/**
* receivers_cc
*/
//TODO receivers_cc should be delete from Alert, because only email alert need receivers_cc . And receivers_cc is move to Email Alert Plugin params.
@TableField("receivers_cc")
private String receiversCc;
/** /**
* create_time * create_time
*/ */
@ -117,14 +95,6 @@ public class Alert {
this.title = title; this.title = title;
} }
// public String getShowType() {
// return showType;
// }
//
// public void setShowType(String showType) {
// this.showType = showType;
// }
public String getContent() { public String getContent() {
return content; return content;
} }
@ -133,14 +103,6 @@ public class Alert {
this.content = content; this.content = content;
} }
public AlertType getAlertType() {
return alertType;
}
public void setAlertType(AlertType alertType) {
this.alertType = alertType;
}
public AlertStatus getAlertStatus() { public AlertStatus getAlertStatus() {
return alertStatus; return alertStatus;
} }
@ -165,22 +127,6 @@ public class Alert {
this.alertGroupId = alertGroupId; this.alertGroupId = alertGroupId;
} }
public String getReceivers() {
return receivers;
}
public void setReceivers(String receivers) {
this.receivers = receivers;
}
public String getReceiversCc() {
return receiversCc;
}
public void setReceiversCc(String receiversCc) {
this.receiversCc = receiversCc;
}
public Date getCreateTime() { public Date getCreateTime() {
return createTime; return createTime;
} }
@ -225,27 +171,15 @@ public class Alert {
if (!title.equals(alert.title)) { if (!title.equals(alert.title)) {
return false; return false;
} }
if (showType != alert.showType) {
return false;
}
if (!content.equals(alert.content)) { if (!content.equals(alert.content)) {
return false; return false;
} }
if (alertType != alert.alertType) {
return false;
}
if (alertStatus != alert.alertStatus) { if (alertStatus != alert.alertStatus) {
return false; return false;
} }
if (!log.equals(alert.log)) { if (!log.equals(alert.log)) {
return false; return false;
} }
if (!receivers.equals(alert.receivers)) {
return false;
}
if (!receiversCc.equals(alert.receiversCc)) {
return false;
}
if (!createTime.equals(alert.createTime)) { if (!createTime.equals(alert.createTime)) {
return false; return false;
} }
@ -257,14 +191,10 @@ public class Alert {
public int hashCode() { public int hashCode() {
int result = id; int result = id;
result = 31 * result + title.hashCode(); result = 31 * result + title.hashCode();
result = 31 * result + showType.hashCode();
result = 31 * result + content.hashCode(); result = 31 * result + content.hashCode();
result = 31 * result + alertType.hashCode();
result = 31 * result + alertStatus.hashCode(); result = 31 * result + alertStatus.hashCode();
result = 31 * result + log.hashCode(); result = 31 * result + log.hashCode();
result = 31 * result + alertGroupId; result = 31 * result + alertGroupId;
result = 31 * result + receivers.hashCode();
result = 31 * result + receiversCc.hashCode();
result = 31 * result + createTime.hashCode(); result = 31 * result + createTime.hashCode();
result = 31 * result + updateTime.hashCode(); result = 31 * result + updateTime.hashCode();
result = 31 * result + info.hashCode(); result = 31 * result + info.hashCode();
@ -278,13 +208,9 @@ public class Alert {
+ id + id
+ ", title='" + ", title='"
+ title + '\'' + title + '\''
+ ", showType="
+ showType
+ ", content='" + ", content='"
+ content + content
+ '\'' + '\''
+ ", alertType="
+ alertType
+ ", alertStatus=" + ", alertStatus="
+ alertStatus + alertStatus
+ ", log='" + ", log='"
@ -292,11 +218,6 @@ public class Alert {
+ '\'' + '\''
+ ", alertGroupId=" + ", alertGroupId="
+ alertGroupId + alertGroupId
+ ", receivers='"
+ receivers
+ '\''
+ ", receiversCc='"
+ receiversCc
+ '\'' + '\''
+ ", createTime=" + ", createTime="
+ createTime + createTime

58
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/AlertGroup.java

@ -14,16 +14,16 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.dolphinscheduler.dao.entity; package org.apache.dolphinscheduler.dao.entity;
import com.baomidou.mybatisplus.annotation.TableField; import java.util.Date;
import org.apache.dolphinscheduler.common.enums.AlertType;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import java.util.Date;
@TableName("t_ds_alertgroup") @TableName("t_ds_alertgroup")
public class AlertGroup { public class AlertGroup {
/** /**
@ -36,11 +36,7 @@ public class AlertGroup {
*/ */
@TableField(value = "group_name") @TableField(value = "group_name")
private String groupName; private String groupName;
/**
* group_type
*/
@TableField(value = "group_type")
private AlertType groupType;
/** /**
* description * description
*/ */
@ -57,6 +53,12 @@ public class AlertGroup {
@TableField(value = "update_time") @TableField(value = "update_time")
private Date updateTime; private Date updateTime;
/**
* create_user_id
*/
@TableField(value = "create_user_id")
private int createUserId;
public int getId() { public int getId() {
return id; return id;
} }
@ -73,14 +75,6 @@ public class AlertGroup {
this.groupName = groupName; this.groupName = groupName;
} }
public AlertType getGroupType() {
return groupType;
}
public void setGroupType(AlertType groupType) {
this.groupType = groupType;
}
public Date getCreateTime() { public Date getCreateTime() {
return createTime; return createTime;
} }
@ -105,6 +99,14 @@ public class AlertGroup {
this.description = description; this.description = description;
} }
public int getCreateUserId() {
return createUserId;
}
public void setCreateUserId(int createUserId) {
this.createUserId = createUserId;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) { if (this == o) {
@ -119,10 +121,10 @@ public class AlertGroup {
if (id != that.id) { if (id != that.id) {
return false; return false;
} }
if (groupName != null ? !groupName.equals(that.groupName) : that.groupName != null) { if (createUserId != that.createUserId) {
return false; return false;
} }
if (groupType != that.groupType) { if (groupName != null ? !groupName.equals(that.groupName) : that.groupName != null) {
return false; return false;
} }
if (description != null ? !description.equals(that.description) : that.description != null) { if (description != null ? !description.equals(that.description) : that.description != null) {
@ -135,8 +137,8 @@ public class AlertGroup {
@Override @Override
public int hashCode() { public int hashCode() {
int result = id; int result = id;
result = 31 * result + createUserId;
result = 31 * result + (groupName != null ? groupName.hashCode() : 0); result = 31 * result + (groupName != null ? groupName.hashCode() : 0);
result = 31 * result + (groupType != null ? groupType.hashCode() : 0);
result = 31 * result + (description != null ? description.hashCode() : 0); result = 31 * result + (description != null ? description.hashCode() : 0);
result = 31 * result + (createTime != null ? createTime.hashCode() : 0); result = 31 * result + (createTime != null ? createTime.hashCode() : 0);
result = 31 * result + (updateTime != null ? updateTime.hashCode() : 0); result = 31 * result + (updateTime != null ? updateTime.hashCode() : 0);
@ -145,13 +147,13 @@ public class AlertGroup {
@Override @Override
public String toString() { public String toString() {
return "AlertGroup{" + return "AlertGroup{"
"id=" + id + + "id=" + id
", groupName='" + groupName + '\'' + + "createUserId=" + createUserId
", groupType=" + groupType + + ", groupName='" + groupName + '\''
", description='" + description + '\'' + + ", description='" + description + '\''
", createTime=" + createTime + + ", createTime=" + createTime
", updateTime=" + updateTime + + ", updateTime=" + updateTime
'}'; + '}';
} }
} }

93
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java

@ -139,16 +139,6 @@ public class ProcessDefinition {
*/ */
private String connects; private String connects;
/**
* receivers
*/
private String receivers;
/**
* receivers cc
*/
private String receiversCc;
/** /**
* schedule release state : online/offline * schedule release state : online/offline
*/ */
@ -175,6 +165,11 @@ public class ProcessDefinition {
*/ */
private String resourceIds; private String resourceIds;
/**
* warningGroupId
*/
@TableField(exist = false)
private int warningGroupId;
public String getName() { public String getName() {
return name; return name;
@ -272,7 +267,6 @@ public class ProcessDefinition {
this.projectName = projectName; this.projectName = projectName;
} }
public String getGlobalParams() { public String getGlobalParams() {
return globalParams; return globalParams;
} }
@ -324,22 +318,6 @@ public class ProcessDefinition {
this.connects = connects; this.connects = connects;
} }
public String getReceivers() {
return receivers;
}
public void setReceivers(String receivers) {
this.receivers = receivers;
}
public String getReceiversCc() {
return receiversCc;
}
public void setReceiversCc(String receiversCc) {
this.receiversCc = receiversCc;
}
public ReleaseState getScheduleReleaseState() { public ReleaseState getScheduleReleaseState() {
return scheduleReleaseState; return scheduleReleaseState;
} }
@ -388,35 +366,42 @@ public class ProcessDefinition {
this.modifyBy = modifyBy; this.modifyBy = modifyBy;
} }
public int getWarningGroupId() {
return warningGroupId;
}
public void setWarningGroupId(int warningGroupId) {
this.warningGroupId = warningGroupId;
}
@Override @Override
public String toString() { public String toString() {
return "ProcessDefinition{" + return "ProcessDefinition{"
"id=" + id + + "id=" + id
", name='" + name + '\'' + + ", name='" + name + '\''
", version=" + version + + ", version=" + version
", releaseState=" + releaseState + + ", releaseState=" + releaseState
", projectId=" + projectId + + ", projectId=" + projectId
", processDefinitionJson='" + processDefinitionJson + '\'' + + ", processDefinitionJson='" + processDefinitionJson + '\''
", description='" + description + '\'' + + ", description='" + description + '\''
", globalParams='" + globalParams + '\'' + + ", globalParams='" + globalParams + '\''
", globalParamList=" + globalParamList + + ", globalParamList=" + globalParamList
", globalParamMap=" + globalParamMap + + ", globalParamMap=" + globalParamMap
", createTime=" + createTime + + ", createTime=" + createTime
", updateTime=" + updateTime + + ", updateTime=" + updateTime
", flag=" + flag + + ", flag=" + flag
", userId=" + userId + + ", userId=" + userId
", userName='" + userName + '\'' + + ", userName='" + userName + '\''
", projectName='" + projectName + '\'' + + ", projectName='" + projectName + '\''
", locations='" + locations + '\'' + + ", locations='" + locations + '\''
", connects='" + connects + '\'' + + ", connects='" + connects + '\''
", receivers='" + receivers + '\'' + + ", scheduleReleaseState=" + scheduleReleaseState
", receiversCc='" + receiversCc + '\'' + + ", timeout=" + timeout
", scheduleReleaseState=" + scheduleReleaseState + + ", warningGroupId=" + warningGroupId
", timeout=" + timeout + + ", tenantId=" + tenantId
", tenantId=" + tenantId + + ", modifyBy='" + modifyBy + '\''
", modifyBy='" + modifyBy + '\'' + + ", resourceIds='" + resourceIds + '\''
", resourceIds='" + resourceIds + '\'' + + '}';
'}';
} }
} }

88
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinitionVersion.java

@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.dao.entity;
import java.util.Date; import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
@ -57,16 +58,6 @@ public class ProcessDefinitionVersion {
*/ */
private String description; private String description;
/**
* receivers
*/
private String receivers;
/**
* receivers cc
*/
private String receiversCc;
/** /**
* process warning time out. unit: minute * process warning time out. unit: minute
*/ */
@ -98,6 +89,13 @@ public class ProcessDefinitionVersion {
*/ */
private String connects; private String connects;
/**
* warningGroupId
*/
@TableField(exist = false)
private int warningGroupId;
public String getGlobalParams() { public String getGlobalParams() {
return globalParams; return globalParams;
} }
@ -170,22 +168,6 @@ public class ProcessDefinitionVersion {
this.connects = connects; this.connects = connects;
} }
public String getReceivers() {
return receivers;
}
public void setReceivers(String receivers) {
this.receivers = receivers;
}
public String getReceiversCc() {
return receiversCc;
}
public void setReceiversCc(String receiversCc) {
this.receiversCc = receiversCc;
}
public int getTimeout() { public int getTimeout() {
return timeout; return timeout;
} }
@ -202,23 +184,30 @@ public class ProcessDefinitionVersion {
this.resourceIds = resourceIds; this.resourceIds = resourceIds;
} }
public int getWarningGroupId() {
return warningGroupId;
}
public void setWarningGroupId(int warningGroupId) {
this.warningGroupId = warningGroupId;
}
@Override @Override
public String toString() { public String toString() {
return "ProcessDefinitionVersion{" return "ProcessDefinitionVersion{"
+ "id=" + id + "id=" + id
+ ", processDefinitionId=" + processDefinitionId + ", processDefinitionId=" + processDefinitionId
+ ", version=" + version + ", version=" + version
+ ", processDefinitionJson='" + processDefinitionJson + '\'' + ", processDefinitionJson='" + processDefinitionJson + '\''
+ ", description='" + description + '\'' + ", description='" + description + '\''
+ ", globalParams='" + globalParams + '\'' + ", globalParams='" + globalParams + '\''
+ ", createTime=" + createTime + ", createTime=" + createTime
+ ", locations='" + locations + '\'' + ", locations='" + locations + '\''
+ ", connects='" + connects + '\'' + ", connects='" + connects + '\''
+ ", receivers='" + receivers + '\'' + ", timeout=" + timeout
+ ", receiversCc='" + receiversCc + '\'' + ", warningGroupId=" + warningGroupId
+ ", timeout=" + timeout + ", resourceIds='" + resourceIds + '\''
+ ", resourceIds='" + resourceIds + '\'' + '}';
+ '}';
} }
public static Builder newBuilder() { public static Builder newBuilder() {
@ -235,9 +224,8 @@ public class ProcessDefinitionVersion {
private Date createTime; private Date createTime;
private String locations; private String locations;
private String connects; private String connects;
private String receivers;
private String receiversCc;
private int timeout; private int timeout;
private int warningGroupId;
private String resourceIds; private String resourceIds;
private Builder() { private Builder() {
@ -288,18 +276,13 @@ public class ProcessDefinitionVersion {
return this; return this;
} }
public Builder receivers(String receivers) { public Builder timeout(int timeout) {
this.receivers = receivers; this.timeout = timeout;
return this;
}
public Builder receiversCc(String receiversCc) {
this.receiversCc = receiversCc;
return this; return this;
} }
public Builder timeout(int timeout) { public Builder warningGroupId(int warningGroupId) {
this.timeout = timeout; this.warningGroupId = warningGroupId;
return this; return this;
} }
@ -319,9 +302,8 @@ public class ProcessDefinitionVersion {
processDefinitionVersion.setCreateTime(createTime); processDefinitionVersion.setCreateTime(createTime);
processDefinitionVersion.setLocations(locations); processDefinitionVersion.setLocations(locations);
processDefinitionVersion.setConnects(connects); processDefinitionVersion.setConnects(connects);
processDefinitionVersion.setReceivers(receivers);
processDefinitionVersion.setReceiversCc(receiversCc);
processDefinitionVersion.setTimeout(timeout); processDefinitionVersion.setTimeout(timeout);
processDefinitionVersion.setWarningGroupId(warningGroupId);
processDefinitionVersion.setResourceIds(resourceIds); processDefinitionVersion.setResourceIds(resourceIds);
return processDefinitionVersion; return processDefinitionVersion;
} }

142
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/UserAlertGroup.java

@ -1,142 +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.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
/**
* user alert group
*/
@TableName("t_ds_relation_user_alertgroup")
public class UserAlertGroup {
/**
* id
*/
@TableId(value="id", type=IdType.AUTO)
private int id;
/**
* id
*/
@TableField("alertgroup_id")
private int alertgroupId;
/**
* alert group name
*/
@TableField(exist = false)
private String alertgroupName;
/**
* user id
*/
private int userId;
/**
* user name
*/
@TableField(exist = false)
private String userName;
/**
* create time
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
private Date createTime;
/**
* update time
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
private Date updateTime;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAlertgroupId() {
return alertgroupId;
}
public void setAlertgroupId(int alertgroupId) {
this.alertgroupId = alertgroupId;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getAlertgroupName() {
return alertgroupName;
}
public void setAlertgroupName(String alertgroupName) {
this.alertgroupName = alertgroupName;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
@Override
public String toString() {
return "UserAlertGroup{" +
"id=" + id +
", alertgroupId=" + alertgroupId +
", alertgroupName='" + alertgroupName + '\'' +
", userId=" + userId +
", userName='" + userName + '\'' +
", createTime=" + createTime +
", updateTime=" + updateTime +
'}';
}
}

8
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.java

@ -55,14 +55,6 @@ public interface AlertGroupMapper extends BaseMapper<AlertGroup> {
*/ */
List<AlertGroup> queryByUserId(@Param("userId") int userId); List<AlertGroup> queryByUserId(@Param("userId") int userId);
/**
* query by alert type
* @param alertType alertType
* @return alertgroup list
*/
List<AlertGroup> queryByAlertType(@Param("alertType") AlertType alertType);
/** /**
* query all group list * query all group list
* @return alertgroup list * @return alertgroup list

45
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/UserAlertGroupMapper.java

@ -1,45 +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.dao.entity.User;
import org.apache.dolphinscheduler.dao.entity.UserAlertGroup;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* user alertgroup relation mapper interface
*/
public interface UserAlertGroupMapper extends BaseMapper<UserAlertGroup> {
/**
* delete user alertgroup relation by alertgroupId
* @param alertgroupId alertgroupId
* @return delete result
*/
int deleteByAlertgroupId(@Param("alertgroupId") int alertgroupId);
/**
* list user by alertgroupId
* @param alertgroupId alertgroupId
* @return user list
*/
List<User> listUserByAlertgroupId(@Param("alertgroupId") int alertgroupId);
}

8
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.xml

@ -31,14 +31,10 @@
where group_name=#{groupName} where group_name=#{groupName}
</select> </select>
<select id="queryByUserId" resultType="org.apache.dolphinscheduler.dao.entity.AlertGroup"> <select id="queryByUserId" resultType="org.apache.dolphinscheduler.dao.entity.AlertGroup">
select * from t_ds_alertgroup t
left join t_ds_relation_user_alertgroup r on t.id=r.alertgroup_id
where r.user_id=#{userId}
</select>
<select id="queryByAlertType" resultType="org.apache.dolphinscheduler.dao.entity.AlertGroup">
select * from t_ds_alertgroup select * from t_ds_alertgroup
where group_type=#{alertType} where create_user_id = #{userId}
</select> </select>
<select id="queryAllGroupList" resultType="org.apache.dolphinscheduler.dao.entity.AlertGroup"> <select id="queryAllGroupList" resultType="org.apache.dolphinscheduler.dao.entity.AlertGroup">
select * select *
from t_ds_alertgroup from t_ds_alertgroup

12
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml

@ -29,12 +29,14 @@
and pd.name = #{processDefinitionName} and pd.name = #{processDefinitionName}
</select> </select>
<select id="queryDefineListPaging" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinition"> <select id="queryDefineListPaging" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinition">
SELECT td.id, td.name, td.version, td.release_state, td.project_id, td.user_id, td.description, td.global_params, SELECT td.id, td.name, td.version, td.release_state, td.project_id, td.user_id, td.description,
td.flag, td.receivers, td.receivers_cc, td.timeout, td.tenant_id, td.modify_by, td.update_time, td.create_time, td.global_params,
sc.schedule_release_state, tu.user_name td.flag, td.warning_group_id, td.timeout, td.tenant_id, td.modify_by, td.update_time, td.create_time,
sc.schedule_release_state, tu.user_name
FROM t_ds_process_definition td FROM t_ds_process_definition td
left join (select process_definition_id,release_state as schedule_release_state from t_ds_schedules group by process_definition_id,release_state) sc on sc.process_definition_id = td.id left join (select process_definition_id,release_state as schedule_release_state from t_ds_schedules group by
left join t_ds_user tu on td.user_id = tu.id process_definition_id,release_state) sc on sc.process_definition_id = td.id
left join t_ds_user tu on td.user_id = tu.id
where td.project_id = #{projectId} where td.project_id = #{projectId}
<if test=" searchVal != null and searchVal != ''"> <if test=" searchVal != null and searchVal != ''">
and td.name like concat('%', #{searchVal}, '%') and td.name like concat('%', #{searchVal}, '%')

31
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserAlertGroupMapper.xml

@ -1,31 +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.UserAlertGroupMapper">
<delete id="deleteByAlertgroupId">
delete from t_ds_relation_user_alertgroup
where alertgroup_id = #{alertgroupId}
</delete>
<select id="listUserByAlertgroupId" resultType="org.apache.dolphinscheduler.dao.entity.User">
SELECT u.*
FROM t_ds_relation_user_alertgroup g_u
JOIN t_ds_user u on g_u.user_id = u.id
WHERE g_u.alertgroup_id = #{alertgroupId}
</select>
</mapper>

7
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/AlertDaoTest.java

@ -18,7 +18,6 @@
package org.apache.dolphinscheduler.dao; package org.apache.dolphinscheduler.dao;
import org.apache.dolphinscheduler.common.enums.AlertStatus; import org.apache.dolphinscheduler.common.enums.AlertStatus;
import org.apache.dolphinscheduler.common.enums.AlertType;
import org.apache.dolphinscheduler.dao.entity.Alert; import org.apache.dolphinscheduler.dao.entity.Alert;
import java.util.List; import java.util.List;
@ -33,10 +32,8 @@ public class AlertDaoTest {
AlertDao alertDao = DaoFactory.getDaoInstance(AlertDao.class); AlertDao alertDao = DaoFactory.getDaoInstance(AlertDao.class);
Alert alert = new Alert(); Alert alert = new Alert();
alert.setTitle("Mysql Exception"); alert.setTitle("Mysql Exception");
//alert.setShowType(ShowType.TEXT); alert.setContent("[\"alarm time:2018-02-05\", \"service name:MYSQL_ALTER\", \"alarm name:MYSQL_ALTER_DUMP\", "
alert.setContent("[\"alarm time:2018-02-05\", \"service name:MYSQL_ALTER\", \"alarm name:MYSQL_ALTER_DUMP\", " + + "\"get the alarm exception.!,interface error,exception information:timed out\", \"request address:http://blog.csdn.net/dreamInTheWorld/article/details/78539286\"]");
"\"get the alarm exception.!,interface error,exception information:timed out\", \"request address:http://blog.csdn.net/dreamInTheWorld/article/details/78539286\"]");
alert.setAlertType(AlertType.EMAIL);
alert.setAlertGroupId(1); alert.setAlertGroupId(1);
alert.setAlertStatus(AlertStatus.WAIT_EXECUTION); alert.setAlertStatus(AlertStatus.WAIT_EXECUTION);
alertDao.addAlert(alert); alertDao.addAlert(alert);

189
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapperTest.java

@ -14,38 +14,36 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.dolphinscheduler.dao.mapper; package org.apache.dolphinscheduler.dao.mapper;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import org.apache.dolphinscheduler.common.enums.AlertType;
import org.apache.dolphinscheduler.common.utils.DateUtils; import org.apache.dolphinscheduler.common.utils.DateUtils;
import org.apache.dolphinscheduler.dao.entity.AccessToken;
import org.apache.dolphinscheduler.dao.entity.AlertGroup; import org.apache.dolphinscheduler.dao.entity.AlertGroup;
import org.apache.dolphinscheduler.dao.entity.UserAlertGroup;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import static org.hamcrest.Matchers.*; import com.baomidou.mybatisplus.core.metadata.IPage;
import static org.junit.Assert.*; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
/** /**
* AlertGroup mapper test * AlertGroup mapper test
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest @SpringBootTest
@ -53,22 +51,17 @@ import static org.junit.Assert.*;
@Rollback(true) @Rollback(true)
public class AlertGroupMapperTest { public class AlertGroupMapperTest {
@Autowired @Autowired
AlertGroupMapper alertGroupMapper; AlertGroupMapper alertGroupMapper;
@Autowired
UserAlertGroupMapper userAlertGroupMapper;
/** /**
* test insert * test insert
*/ */
@Test @Test
public void testInsert(){ public void testInsert() {
AlertGroup alertGroup = createAlertGroup(); AlertGroup alertGroup = createAlertGroup();
assertNotNull(alertGroup); assertNotNull(alertGroup);
assertThat(alertGroup.getId(),greaterThan(0)); assertThat(alertGroup.getId(), greaterThan(0));
} }
@ -99,7 +92,7 @@ public class AlertGroupMapperTest {
Integer offset = 2; Integer offset = 2;
Integer size = 2; Integer size = 2;
Map<Integer, AlertGroup> alertGroupMap = createAlertGroups(count,groupName); Map<Integer, AlertGroup> alertGroupMap = createAlertGroups(count, groupName);
Page page = new Page(offset, size); Page page = new Page(offset, size);
@ -109,25 +102,23 @@ public class AlertGroupMapperTest {
assertEquals(alertGroupList.size(), size.intValue()); assertEquals(alertGroupList.size(), size.intValue());
for (AlertGroup alertGroup : alertGroupList){ for (AlertGroup alertGroup : alertGroupList) {
AlertGroup resultAlertGroup = alertGroupMap.get(alertGroup.getId()); AlertGroup resultAlertGroup = alertGroupMap.get(alertGroup.getId());
if (resultAlertGroup != null){ if (resultAlertGroup != null) {
assertEquals(alertGroup,resultAlertGroup); assertEquals(alertGroup, resultAlertGroup);
} }
} }
} }
/** /**
* test update * test update
*/ */
@Test @Test
public void testUpdate(){ public void testUpdate() {
AlertGroup alertGroup = createAlertGroup(); AlertGroup alertGroup = createAlertGroup();
alertGroup.setGroupName("modify GroupName"); alertGroup.setGroupName("modify GroupName");
alertGroup.setGroupType(AlertType.SMS);
alertGroup.setDescription("modify GroupName"); alertGroup.setDescription("modify GroupName");
alertGroup.setUpdateTime(DateUtils.getCurrentDate()); alertGroup.setUpdateTime(DateUtils.getCurrentDate());
@ -135,16 +126,15 @@ public class AlertGroupMapperTest {
AlertGroup resultAlertGroup = alertGroupMapper.selectById(alertGroup.getId()); AlertGroup resultAlertGroup = alertGroupMapper.selectById(alertGroup.getId());
assertEquals(alertGroup,resultAlertGroup); assertEquals(alertGroup, resultAlertGroup);
} }
/** /**
* test delete * test delete
*/ */
@Test @Test
public void testDelete(){ public void testDelete() {
AlertGroup alertGroup = createAlertGroup(); AlertGroup alertGroup = createAlertGroup();
@ -156,7 +146,6 @@ public class AlertGroupMapperTest {
} }
/** /**
* test query by groupname * test query by groupname
*/ */
@ -169,42 +158,9 @@ public class AlertGroupMapperTest {
List<AlertGroup> alertGroupList = alertGroupMapper.queryByGroupName("testGroup"); List<AlertGroup> alertGroupList = alertGroupMapper.queryByGroupName("testGroup");
compareAlertGroups(alertGroupMap, alertGroupList); compareAlertGroups(alertGroupMap, alertGroupList);
} }
/**
* test query by userId
*/
@Test
public void testQueryByUserId() {
Integer count = 4;
Integer userId = 1;
Map<Integer, AlertGroup> alertGroupMap =
createAlertGroups(count, userId);
List<AlertGroup> alertGroupList =
alertGroupMapper.queryByUserId(userId);
compareAlertGroups(alertGroupMap,alertGroupList);
}
/**
* test query by alert type
*/
@Test
public void testQueryByAlertType() {
Integer count = 4;
Map<Integer, AlertGroup> alertGroupMap = createAlertGroups(count);
List<AlertGroup> alertGroupList = alertGroupMapper.queryByAlertType(AlertType.EMAIL);
compareAlertGroups(alertGroupMap,alertGroupList);
}
/** /**
* test query all group list * test query all group list
*/ */
@ -215,37 +171,38 @@ public class AlertGroupMapperTest {
List<AlertGroup> alertGroupList = alertGroupMapper.queryAllGroupList(); List<AlertGroup> alertGroupList = alertGroupMapper.queryAllGroupList();
compareAlertGroups(alertGroupMap,alertGroupList); compareAlertGroups(alertGroupMap, alertGroupList);
} }
/** /**
* compare AlertGruops * compare AlertGruops
* @param alertGroupMap alertGroupMap *
* @param alertGroupMap alertGroupMap
* @param alertGroupList alertGroupList * @param alertGroupList alertGroupList
*/ */
private void compareAlertGroups(Map<Integer,AlertGroup> alertGroupMap, private void compareAlertGroups(Map<Integer, AlertGroup> alertGroupMap,
List<AlertGroup> alertGroupList){ List<AlertGroup> alertGroupList) {
// greaterThanOrEqualTo,beacuse maybe db have already exists // greaterThanOrEqualTo,beacuse maybe db have already exists
assertThat(alertGroupList.size(),greaterThanOrEqualTo(alertGroupMap.size())); assertThat(alertGroupList.size(), greaterThanOrEqualTo(alertGroupMap.size()));
for (AlertGroup alertGroup : alertGroupList){ for (AlertGroup alertGroup : alertGroupList) {
AlertGroup resultAlertGroup = alertGroupMap.get(alertGroup.getId()); AlertGroup resultAlertGroup = alertGroupMap.get(alertGroup.getId());
if (resultAlertGroup != null){ if (resultAlertGroup != null) {
assertEquals(alertGroup,resultAlertGroup); assertEquals(alertGroup, resultAlertGroup);
} }
} }
} }
/** /**
* insert * insert
*
* @return AlertGroup * @return AlertGroup
*/ */
private AlertGroup createAlertGroup(String groupName){ private AlertGroup createAlertGroup(String groupName) {
AlertGroup alertGroup = new AlertGroup(); AlertGroup alertGroup = new AlertGroup();
alertGroup.setGroupName(groupName); alertGroup.setGroupName(groupName);
alertGroup.setDescription("alert group 1"); alertGroup.setDescription("alert group 1");
alertGroup.setGroupType(AlertType.EMAIL);
alertGroup.setCreateTime(DateUtils.getCurrentDate()); alertGroup.setCreateTime(DateUtils.getCurrentDate());
alertGroup.setUpdateTime(DateUtils.getCurrentDate()); alertGroup.setUpdateTime(DateUtils.getCurrentDate());
@ -257,13 +214,13 @@ public class AlertGroupMapperTest {
/** /**
* insert * insert
*
* @return AlertGroup * @return AlertGroup
*/ */
private AlertGroup createAlertGroup(){ private AlertGroup createAlertGroup() {
AlertGroup alertGroup = new AlertGroup(); AlertGroup alertGroup = new AlertGroup();
alertGroup.setGroupName("testGroup"); alertGroup.setGroupName("testGroup");
alertGroup.setDescription("testGroup"); alertGroup.setDescription("testGroup");
alertGroup.setGroupType(AlertType.EMAIL);
alertGroup.setCreateTime(DateUtils.getCurrentDate()); alertGroup.setCreateTime(DateUtils.getCurrentDate());
alertGroup.setUpdateTime(DateUtils.getCurrentDate()); alertGroup.setUpdateTime(DateUtils.getCurrentDate());
@ -275,81 +232,41 @@ public class AlertGroupMapperTest {
/** /**
* create AlertGroups * create AlertGroups
* @param count create AlertGroup count *
* @param count create AlertGroup count
* @param groupName groupName * @param groupName groupName
* @return AlertGroup map * @return AlertGroup map
*/ */
private Map<Integer,AlertGroup> createAlertGroups( private Map<Integer, AlertGroup> createAlertGroups(
Integer count,String groupName){ Integer count, String groupName) {
Map<Integer,AlertGroup> alertGroupMap = new HashMap<>(); Map<Integer, AlertGroup> alertGroupMap = new HashMap<>();
AlertGroup alertGroup = null; AlertGroup alertGroup = null;
for (int i = 0 ; i < count; i++){ for (int i = 0; i < count; i++) {
alertGroup = createAlertGroup(groupName); alertGroup = createAlertGroup(groupName);
alertGroupMap.put(alertGroup.getId(),alertGroup); alertGroupMap.put(alertGroup.getId(), alertGroup);
}
return alertGroupMap;
}
/**
* create AlertGroups
* @param count create AlertGroup count
* @return AlertGroup map
*/
private Map<Integer,AlertGroup> createAlertGroups(
Integer count){
Map<Integer,AlertGroup> alertGroupMap = new HashMap<>();
AlertGroup alertGroup = null;
for (int i = 0 ; i < count; i++){
alertGroup = createAlertGroup();
alertGroupMap.put(alertGroup.getId(),alertGroup);
} }
return alertGroupMap; return alertGroupMap;
} }
/** /**
* create AlertGroups * create AlertGroups
*
* @param count create AlertGroup count * @param count create AlertGroup count
* @return AlertGroup map * @return AlertGroup map
*/ */
private Map<Integer,AlertGroup> createAlertGroups( private Map<Integer, AlertGroup> createAlertGroups(
Integer count,Integer userId){ Integer count) {
Map<Integer,AlertGroup> alertGroupMap = new HashMap<>(); Map<Integer, AlertGroup> alertGroupMap = new HashMap<>();
AlertGroup alertGroup = null; AlertGroup alertGroup = null;
for (int i = 0 ; i < count; i++){ for (int i = 0; i < count; i++) {
alertGroup = createAlertGroup(); alertGroup = createAlertGroup();
alertGroupMap.put(alertGroup.getId(), alertGroup);
createUserAlertGroup(userId,alertGroup.getId());
alertGroupMap.put(alertGroup.getId(),alertGroup);
} }
return alertGroupMap; return alertGroupMap;
} }
/**
* create AlertGroup
* @param userId userId
* @param alertgroupId alertgroupId
* @return UserAlertGroup
*/
private UserAlertGroup createUserAlertGroup(
Integer userId,Integer alertgroupId){
UserAlertGroup userAlertGroup = new UserAlertGroup();
userAlertGroup.setAlertgroupId(alertgroupId);
userAlertGroup.setUserId(userId);
userAlertGroup.setCreateTime(DateUtils.getCurrentDate());
userAlertGroup.setUpdateTime(DateUtils.getCurrentDate());
userAlertGroupMapper.insert(userAlertGroup);
return userAlertGroup;
}
} }

5
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertMapperTest.java

@ -23,7 +23,6 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import org.apache.dolphinscheduler.common.enums.AlertStatus; import org.apache.dolphinscheduler.common.enums.AlertStatus;
import org.apache.dolphinscheduler.common.enums.AlertType;
import org.apache.dolphinscheduler.common.utils.DateUtils; import org.apache.dolphinscheduler.common.utils.DateUtils;
import org.apache.dolphinscheduler.dao.entity.Alert; import org.apache.dolphinscheduler.dao.entity.Alert;
@ -162,14 +161,10 @@ public class AlertMapperTest {
*/ */
private Alert createAlert(AlertStatus alertStatus) { private Alert createAlert(AlertStatus alertStatus) {
Alert alert = new Alert(); Alert alert = new Alert();
//alert.setShowType(ShowType.TABLE);
alert.setTitle("test alert"); alert.setTitle("test alert");
alert.setContent("[{'type':'WORKER','host':'192.168.xx.xx','event':'server down','warning level':'serious'}]"); alert.setContent("[{'type':'WORKER','host':'192.168.xx.xx','event':'server down','warning level':'serious'}]");
alert.setAlertType(AlertType.EMAIL);
alert.setAlertStatus(alertStatus); alert.setAlertStatus(alertStatus);
alert.setLog("success"); alert.setLog("success");
alert.setReceivers("aa@aa.com");
alert.setReceiversCc("bb@aa.com");
alert.setCreateTime(DateUtils.getCurrentDate()); alert.setCreateTime(DateUtils.getCurrentDate());
alert.setUpdateTime(DateUtils.getCurrentDate()); alert.setUpdateTime(DateUtils.getCurrentDate());

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

@ -17,7 +17,6 @@
package org.apache.dolphinscheduler.dao.mapper; package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.common.enums.AlertType;
import org.apache.dolphinscheduler.common.utils.DateUtils; import org.apache.dolphinscheduler.common.utils.DateUtils;
import org.apache.dolphinscheduler.dao.entity.AlertGroup; import org.apache.dolphinscheduler.dao.entity.AlertGroup;
import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance; import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
@ -106,7 +105,6 @@ public class AlertPluginInstanceMapperTest {
AlertGroup alertGroup = new AlertGroup(); AlertGroup alertGroup = new AlertGroup();
alertGroup.setGroupName(groupName); alertGroup.setGroupName(groupName);
alertGroup.setDescription("alert group 1"); alertGroup.setDescription("alert group 1");
alertGroup.setGroupType(AlertType.EMAIL);
alertGroup.setCreateTime(DateUtils.getCurrentDate()); alertGroup.setCreateTime(DateUtils.getCurrentDate());
alertGroup.setUpdateTime(DateUtils.getCurrentDate()); alertGroup.setUpdateTime(DateUtils.getCurrentDate());

4
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java

@ -77,8 +77,6 @@ public class ProcessDefinitionMapperTest {
processDefinition.setUserId(101); processDefinition.setUserId(101);
processDefinition.setUpdateTime(new Date()); processDefinition.setUpdateTime(new Date());
processDefinition.setCreateTime(new Date()); processDefinition.setCreateTime(new Date());
// processDefinition.setGlobalParams("[{\"prop\":\"selenium_global_parameters_1\",\"direct\":\"IN\",\"type\":\"VARCHAR\",\"value\":\"selenium_global_parameters_value_1\"}]");
processDefinitionMapper.insert(processDefinition); processDefinitionMapper.insert(processDefinition);
return processDefinition; return processDefinition;
} }
@ -170,8 +168,6 @@ public class ProcessDefinitionMapperTest {
processDefinition.setCreateTime(new Date()); processDefinition.setCreateTime(new Date());
processDefinition.setTenantId(tenant.getId()); processDefinition.setTenantId(tenant.getId());
processDefinition.setUserId(user.getId()); processDefinition.setUserId(user.getId());
// processDefinition.setGlobalParams("[{\"prop\":\"selenium_global_parameters_1\",\"direct\":\"IN\",\"type\":\"VARCHAR\",\"value\":\"selenium_global_parameters_value_1\"}]");
//
processDefinitionMapper.insert(processDefinition); processDefinitionMapper.insert(processDefinition);
ProcessDefinition processDefinition1 = processDefinitionMapper.queryByDefineName(project.getId(), "def 1"); ProcessDefinition processDefinition1 = processDefinitionMapper.queryByDefineName(project.getId(), "def 1");

4
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionVersionMapperTest.java

@ -76,8 +76,6 @@ public class ProcessDefinitionVersionMapperTest {
processDefinitionVersion.setCreateTime(new Date()); processDefinitionVersion.setCreateTime(new Date());
processDefinitionVersion.setLocations(StringUtils.EMPTY); processDefinitionVersion.setLocations(StringUtils.EMPTY);
processDefinitionVersion.setConnects(StringUtils.EMPTY); processDefinitionVersion.setConnects(StringUtils.EMPTY);
processDefinitionVersion.setReceivers(StringUtils.EMPTY);
processDefinitionVersion.setReceiversCc(StringUtils.EMPTY);
processDefinitionVersion.setTimeout(10); processDefinitionVersion.setTimeout(10);
processDefinitionVersion.setResourceIds("1,2"); processDefinitionVersion.setResourceIds("1,2");
processDefinitionVersionMapper.insert(processDefinitionVersion); processDefinitionVersionMapper.insert(processDefinitionVersion);
@ -101,8 +99,6 @@ public class ProcessDefinitionVersionMapperTest {
processDefinitionVersion.setCreateTime(new Date()); processDefinitionVersion.setCreateTime(new Date());
processDefinitionVersion.setLocations(StringUtils.EMPTY); processDefinitionVersion.setLocations(StringUtils.EMPTY);
processDefinitionVersion.setConnects(StringUtils.EMPTY); processDefinitionVersion.setConnects(StringUtils.EMPTY);
processDefinitionVersion.setReceivers(StringUtils.EMPTY);
processDefinitionVersion.setReceiversCc(StringUtils.EMPTY);
processDefinitionVersion.setTimeout(10); processDefinitionVersion.setTimeout(10);
processDefinitionVersion.setResourceIds("1,2"); processDefinitionVersion.setResourceIds("1,2");
processDefinitionVersionMapper.insert(processDefinitionVersion); processDefinitionVersionMapper.insert(processDefinitionVersion);

196
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UserAlertGroupMapperTest.java

@ -1,196 +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.AlertType;
import org.apache.dolphinscheduler.common.enums.UserType;
import org.apache.dolphinscheduler.dao.entity.AlertGroup;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.entity.UserAlertGroup;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
@Rollback(true)
public class UserAlertGroupMapperTest {
@Autowired
private UserMapper userMapper;
@Autowired
AlertGroupMapper alertGroupMapper;
@Autowired
private UserAlertGroupMapper userAlertGroupMapper;
/**
* insert one UserAlertGroup
* @param user user
* @param alertGroup alertGroup
* @return UserAlertGroup
*/
private UserAlertGroup insertOne(User user,AlertGroup alertGroup){
UserAlertGroup userAlertGroup = new UserAlertGroup();
userAlertGroup.setAlertgroupName(alertGroup.getGroupName());
userAlertGroup.setAlertgroupId(alertGroup.getId());
userAlertGroup.setUserId(user.getId());
userAlertGroup.setCreateTime(new Date());
userAlertGroup.setUpdateTime(new Date());
userAlertGroupMapper.insert(userAlertGroup);
return userAlertGroup;
}
/**
* insert one UserAlertGroup
* @return UserAlertGroup
*/
private UserAlertGroup insertOne(){
UserAlertGroup userAlertGroup = new UserAlertGroup();
userAlertGroup.setAlertgroupName("dolphin_alert_group");
userAlertGroup.setAlertgroupId(10);
userAlertGroup.setUserId(4);
userAlertGroup.setCreateTime(new Date());
userAlertGroup.setUpdateTime(new Date());
userAlertGroupMapper.insert(userAlertGroup);
return userAlertGroup;
}
/**
* insert one user
* @return User
*/
private User insertOneUser(){
User user = new User();
user.setUserName("user1");
user.setUserPassword("1");
user.setEmail("xx@123.com");
user.setUserType(UserType.GENERAL_USER);
user.setCreateTime(new Date());
user.setTenantId(1);
user.setQueue("dolphin");
user.setUpdateTime(new Date());
userMapper.insert(user);
return user;
}
/**
* insert one AlertGroup
* @return AlertGroup
*/
private AlertGroup insertOneAlertGroup(){
//insertOne
AlertGroup alertGroup = new AlertGroup();
alertGroup.setGroupName("alert group 1");
alertGroup.setDescription("alert test1");
alertGroup.setGroupType(AlertType.EMAIL);
alertGroup.setCreateTime(new Date());
alertGroup.setUpdateTime(new Date());
alertGroupMapper.insert(alertGroup);
return alertGroup;
}
/**
* test update
*/
@Test
public void testUpdate(){
//insertOneUser
User user = insertOneUser();
//insertOneAlertGroup
AlertGroup alertGroup = insertOneAlertGroup();
//insertOne
UserAlertGroup userAlertGroup = insertOne();
//update
userAlertGroup.setUserId(user.getId());
userAlertGroup.setAlertgroupId(alertGroup.getId());
userAlertGroup.setUpdateTime(new Date());
int update = userAlertGroupMapper.updateById(userAlertGroup);
Assert.assertEquals(update, 1);
}
/**
* test delete
*/
@Test
public void testDelete(){
//insertOne
UserAlertGroup userAlertGroup = insertOne();
//delete
int delete = userAlertGroupMapper.deleteById(userAlertGroup.getId());
Assert.assertEquals(delete, 1);
}
/**
* test query
*/
@Test
public void testQuery() {
//insertOne
UserAlertGroup userAlertGroup = insertOne();
//query
List<UserAlertGroup> userAlertGroupList = userAlertGroupMapper.selectList(null);
Assert.assertNotEquals(userAlertGroupList.size(), 0);
}
/**
* test delete by alertgroupId
*/
@Test
public void testDeleteByAlertgroupId() {
//insertOneUser
User user = insertOneUser();
//insertOneAlertGroup
AlertGroup alertGroup = insertOneAlertGroup();
//insertOne
UserAlertGroup userAlertGroup = insertOne(user,alertGroup);
int delete = userAlertGroupMapper.deleteByAlertgroupId(alertGroup.getId());
Assert.assertEquals(delete, 1);
}
/**
* test list user by alertgroupId
*/
@Test
public void testListUserByAlertgroupId() {
//insertOneUser
User user = insertOneUser();
//insertOneAlertGroup
AlertGroup alertGroup = insertOneAlertGroup();
//insertOne
UserAlertGroup userAlertGroup = insertOne(user,alertGroup);
List<User> userList = userAlertGroupMapper.listUserByAlertgroupId(alertGroup.getId());
Assert.assertNotEquals(userList.size(), 0);
}
}

122
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UserMapperTest.java

@ -14,14 +14,20 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.dolphinscheduler.dao.mapper; package org.apache.dolphinscheduler.dao.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.dolphinscheduler.common.enums.AlertType;
import org.apache.dolphinscheduler.common.enums.UserType; import org.apache.dolphinscheduler.common.enums.UserType;
import org.apache.dolphinscheduler.common.utils.DateUtils; import org.apache.dolphinscheduler.common.utils.DateUtils;
import org.apache.dolphinscheduler.dao.entity.*; import org.apache.dolphinscheduler.dao.entity.AccessToken;
import org.apache.dolphinscheduler.dao.entity.AlertGroup;
import org.apache.dolphinscheduler.dao.entity.Queue;
import org.apache.dolphinscheduler.dao.entity.Tenant;
import org.apache.dolphinscheduler.dao.entity.User;
import java.util.Date;
import java.util.List;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -31,8 +37,8 @@ import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Date; import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.List; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest @SpringBootTest
@ -45,9 +51,6 @@ public class UserMapperTest {
@Autowired @Autowired
AlertGroupMapper alertGroupMapper; AlertGroupMapper alertGroupMapper;
@Autowired
private UserAlertGroupMapper userAlertGroupMapper;
@Autowired @Autowired
AccessTokenMapper accessTokenMapper; AccessTokenMapper accessTokenMapper;
@ -59,9 +62,10 @@ public class UserMapperTest {
/** /**
* insert one user * insert one user
*
* @return User * @return User
*/ */
private User insertOne(){ private User insertOne() {
User user = new User(); User user = new User();
user.setUserName("user1"); user.setUserName("user1");
user.setUserPassword("1"); user.setUserPassword("1");
@ -76,10 +80,11 @@ public class UserMapperTest {
/** /**
* insert one user * insert one user
*
* @param tenant tenant * @param tenant tenant
* @return User * @return User
*/ */
private User insertOne(Tenant tenant){ private User insertOne(Tenant tenant) {
User user = new User(); User user = new User();
user.setUserName("user1"); user.setUserName("user1");
user.setUserPassword("1"); user.setUserPassword("1");
@ -94,11 +99,12 @@ public class UserMapperTest {
/** /**
* insert one user * insert one user
* @param queue queue *
* @param queue queue
* @param tenant tenant * @param tenant tenant
* @return User * @return User
*/ */
private User insertOne(Queue queue,Tenant tenant){ private User insertOne(Queue queue, Tenant tenant) {
User user = new User(); User user = new User();
user.setUserName("user1"); user.setUserName("user1");
user.setUserPassword("1"); user.setUserPassword("1");
@ -114,14 +120,14 @@ public class UserMapperTest {
/** /**
* insert one AlertGroup * insert one AlertGroup
*
* @return AlertGroup * @return AlertGroup
*/ */
private AlertGroup insertOneAlertGroup(){ private AlertGroup insertOneAlertGroup() {
//insertOne //insertOne
AlertGroup alertGroup = new AlertGroup(); AlertGroup alertGroup = new AlertGroup();
alertGroup.setGroupName("alert group 1"); alertGroup.setGroupName("alert group 1");
alertGroup.setDescription("alert test1"); alertGroup.setDescription("alert test1");
alertGroup.setGroupType(AlertType.EMAIL);
alertGroup.setCreateTime(new Date()); alertGroup.setCreateTime(new Date());
alertGroup.setUpdateTime(new Date()); alertGroup.setUpdateTime(new Date());
@ -129,45 +135,30 @@ public class UserMapperTest {
return alertGroup; return alertGroup;
} }
/**
* insert one UserAlertGroup
* @param user user
* @param alertGroup alertGroup
* @return UserAlertGroup
*/
private UserAlertGroup insertOneUserAlertGroup(User user,AlertGroup alertGroup){
UserAlertGroup userAlertGroup = new UserAlertGroup();
userAlertGroup.setAlertgroupName(alertGroup.getGroupName());
userAlertGroup.setAlertgroupId(alertGroup.getId());
userAlertGroup.setUserId(user.getId());
userAlertGroup.setCreateTime(new Date());
userAlertGroup.setUpdateTime(new Date());
userAlertGroupMapper.insert(userAlertGroup);
return userAlertGroup;
}
/** /**
* insert one AccessToken * insert one AccessToken
*
* @param user user * @param user user
* @return AccessToken * @return AccessToken
*/ */
private AccessToken insertOneAccessToken(User user){ private AccessToken insertOneAccessToken(User user) {
//insertOne //insertOne
AccessToken accessToken = new AccessToken(); AccessToken accessToken = new AccessToken();
accessToken.setUserId(user.getId()); accessToken.setUserId(user.getId());
accessToken.setToken("secrettoken"); accessToken.setToken("secrettoken");
accessToken.setCreateTime(new Date()); accessToken.setCreateTime(new Date());
accessToken.setUpdateTime(new Date()); accessToken.setUpdateTime(new Date());
accessToken.setExpireTime(DateUtils.getSomeHourOfDay(new Date(),1)); accessToken.setExpireTime(DateUtils.getSomeHourOfDay(new Date(), 1));
accessTokenMapper.insert(accessToken); accessTokenMapper.insert(accessToken);
return accessToken; return accessToken;
} }
/** /**
* insert one Tenant * insert one Tenant
*
* @return Tenant * @return Tenant
*/ */
private Tenant insertOneTenant(){ private Tenant insertOneTenant() {
Tenant tenant = new Tenant(); Tenant tenant = new Tenant();
tenant.setTenantCode("dolphin"); tenant.setTenantCode("dolphin");
tenant.setTenantName("dolphin test"); tenant.setTenantName("dolphin test");
@ -181,9 +172,10 @@ public class UserMapperTest {
/** /**
* insert one Tenant * insert one Tenant
*
* @return Tenant * @return Tenant
*/ */
private Tenant insertOneTenant(Queue queue){ private Tenant insertOneTenant(Queue queue) {
Tenant tenant = new Tenant(); Tenant tenant = new Tenant();
tenant.setTenantCode("dolphin"); tenant.setTenantCode("dolphin");
tenant.setTenantName("dolphin test"); tenant.setTenantName("dolphin test");
@ -198,9 +190,10 @@ public class UserMapperTest {
/** /**
* insert one Queue * insert one Queue
*
* @return Queue * @return Queue
*/ */
private Queue insertOneQueue(){ private Queue insertOneQueue() {
Queue queue = new Queue(); Queue queue = new Queue();
queue.setQueue("dolphin"); queue.setQueue("dolphin");
queue.setQueueName("dolphin queue"); queue.setQueueName("dolphin queue");
@ -214,7 +207,7 @@ public class UserMapperTest {
* test update * test update
*/ */
@Test @Test
public void testUpdate(){ public void testUpdate() {
//insertOne //insertOne
User user = insertOne(); User user = insertOne();
//update //update
@ -229,7 +222,7 @@ public class UserMapperTest {
* test delete * test delete
*/ */
@Test @Test
public void testDelete(){ public void testDelete() {
//insertOne //insertOne
User user = insertOne(); User user = insertOne();
//delete //delete
@ -261,30 +254,6 @@ public class UserMapperTest {
Assert.assertNotEquals(userList.size(), 0); Assert.assertNotEquals(userList.size(), 0);
} }
// /**
// * test query by username
// */
// @Test
// public void testQueryByUserNameAccurately() {
// //insertOne
// User user = insertOne();
// //queryByUserNameAccurately
// User queryUser = userMapper.queryByUserNameAccurately(user.getUserName());
// Assert.assertEquals(queryUser.getUserName(), user.getUserName());
// }
// /**
// * test query by username and password
// */
// @Test
// public void testQueryUserByNamePassword() {
// //insertOne
// User user = insertOne();
// //queryUserByNamePassword
// User queryUser = userMapper.queryUserByNamePassword(user.getUserName(),user.getUserPassword());
// Assert.assertEquals(queryUser.getUserName(),user.getUserName());
// Assert.assertEquals(queryUser.getUserPassword(), user.getUserPassword());
// }
/** /**
* test page * test page
@ -296,9 +265,9 @@ public class UserMapperTest {
//insertOneTenant //insertOneTenant
Tenant tenant = insertOneTenant(); Tenant tenant = insertOneTenant();
//insertOne //insertOne
User user = insertOne(queue,tenant); User user = insertOne(queue, tenant);
//queryUserPaging //queryUserPaging
Page<User> page = new Page(1,3); Page<User> page = new Page(1, 3);
IPage<User> userIPage = userMapper.queryUserPaging(page, user.getUserName()); IPage<User> userIPage = userMapper.queryUserPaging(page, user.getUserName());
Assert.assertNotEquals(userIPage.getTotal(), 0); Assert.assertNotEquals(userIPage.getTotal(), 0);
} }
@ -311,29 +280,12 @@ public class UserMapperTest {
//insertOneQueue and insertOneTenant //insertOneQueue and insertOneTenant
Queue queue = insertOneQueue(); Queue queue = insertOneQueue();
Tenant tenant = insertOneTenant(queue); Tenant tenant = insertOneTenant(queue);
User user = insertOne(queue,tenant); User user = insertOne(queue, tenant);
//queryDetailsById //queryDetailsById
User queryUser = userMapper.queryDetailsById(user.getId()); User queryUser = userMapper.queryDetailsById(user.getId());
Assert.assertEquals(user.getUserName(), queryUser.getUserName()); Assert.assertEquals(user.getUserName(), queryUser.getUserName());
} }
/**
* test query user list by alertgroupId
*/
@Test
public void testQueryUserListByAlertGroupId() {
//insertOne
User user = insertOne();
//insertOneAlertGroup
AlertGroup alertGroup = insertOneAlertGroup();
//insertOneUserAlertGroup
UserAlertGroup userAlertGroup = insertOneUserAlertGroup(user, alertGroup);
//queryUserListByAlertGroupId
List<User> userList = userMapper.queryUserListByAlertGroupId(userAlertGroup.getAlertgroupId());
Assert.assertNotEquals(userList.size(), 0);
}
/** /**
* test query tenant code by userId * test query tenant code by userId
*/ */
@ -345,7 +297,7 @@ public class UserMapperTest {
User user = insertOne(tenant); User user = insertOne(tenant);
//queryTenantCodeByUserId //queryTenantCodeByUserId
User queryUser = userMapper.queryTenantCodeByUserId(user.getId()); User queryUser = userMapper.queryTenantCodeByUserId(user.getId());
Assert.assertEquals(queryUser,user); Assert.assertEquals(queryUser, user);
} }
/** /**
@ -359,7 +311,7 @@ public class UserMapperTest {
AccessToken accessToken = insertOneAccessToken(user); AccessToken accessToken = insertOneAccessToken(user);
//queryUserByToken //queryUserByToken
User userToken = userMapper.queryUserByToken(accessToken.getToken()); User userToken = userMapper.queryUserByToken(accessToken.getToken());
Assert.assertEquals(userToken,user); Assert.assertEquals(userToken, user);
} }
} }

77
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterTaskExecThread.java

@ -14,8 +14,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.dolphinscheduler.server.master.runner;
package org.apache.dolphinscheduler.server.master.runner;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.ExecutionStatus; import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
@ -42,7 +42,6 @@ import org.apache.dolphinscheduler.service.bean.SpringApplicationContext;
import java.util.Date; import java.util.Date;
import java.util.Set; import java.util.Set;
/** /**
* master task exec thread * master task exec thread
*/ */
@ -64,9 +63,10 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
/** /**
* constructor of MasterTaskExecThread * constructor of MasterTaskExecThread
* @param taskInstance task instance *
* @param taskInstance task instance
*/ */
public MasterTaskExecThread(TaskInstance taskInstance){ public MasterTaskExecThread(TaskInstance taskInstance) {
super(taskInstance); super(taskInstance);
this.taskInstanceCacheManager = SpringApplicationContext.getBean(TaskInstanceCacheManagerImpl.class); this.taskInstanceCacheManager = SpringApplicationContext.getBean(TaskInstanceCacheManagerImpl.class);
this.nettyExecutorManager = SpringApplicationContext.getBean(NettyExecutorManager.class); this.nettyExecutorManager = SpringApplicationContext.getBean(NettyExecutorManager.class);
@ -75,10 +75,11 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
/** /**
* get task instance * get task instance
*
* @return TaskInstance * @return TaskInstance
*/ */
@Override @Override
public TaskInstance getTaskInstance(){ public TaskInstance getTaskInstance() {
return this.taskInstance; return this.taskInstance;
} }
@ -96,70 +97,70 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
public Boolean submitWaitComplete() { public Boolean submitWaitComplete() {
Boolean result = false; Boolean result = false;
this.taskInstance = submit(); this.taskInstance = submit();
if(this.taskInstance == null){ if (this.taskInstance == null) {
logger.error("submit task instance to mysql and queue failed , please check and fix it"); logger.error("submit task instance to mysql and queue failed , please check and fix it");
return result; return result;
} }
if(!this.taskInstance.getState().typeIsFinished()) { if (!this.taskInstance.getState().typeIsFinished()) {
result = waitTaskQuit(); result = waitTaskQuit();
} }
taskInstance.setEndTime(new Date()); taskInstance.setEndTime(new Date());
processService.updateTaskInstance(taskInstance); processService.updateTaskInstance(taskInstance);
logger.info("task :{} id:{}, process id:{}, exec thread completed ", logger.info("task :{} id:{}, process id:{}, exec thread completed ",
this.taskInstance.getName(),taskInstance.getId(), processInstance.getId() ); this.taskInstance.getName(), taskInstance.getId(), processInstance.getId());
return result; return result;
} }
/** /**
* polling db * polling db
* * <p>
* wait task quit * wait task quit
*
* @return true if task quit success * @return true if task quit success
*/ */
public Boolean waitTaskQuit(){ public Boolean waitTaskQuit() {
// query new state // query new state
taskInstance = processService.findTaskInstanceById(taskInstance.getId()); taskInstance = processService.findTaskInstanceById(taskInstance.getId());
logger.info("wait task: process id: {}, task id:{}, task name:{} complete", logger.info("wait task: process id: {}, task id:{}, task name:{} complete",
this.taskInstance.getProcessInstanceId(), this.taskInstance.getId(), this.taskInstance.getName()); this.taskInstance.getProcessInstanceId(), this.taskInstance.getId(), this.taskInstance.getName());
// task time out // task time out
boolean checkTimeout = false; boolean checkTimeout = false;
TaskTimeoutParameter taskTimeoutParameter = getTaskTimeoutParameter(); TaskTimeoutParameter taskTimeoutParameter = getTaskTimeoutParameter();
if(taskTimeoutParameter.getEnable()){ if (taskTimeoutParameter.getEnable()) {
TaskTimeoutStrategy strategy = taskTimeoutParameter.getStrategy(); TaskTimeoutStrategy strategy = taskTimeoutParameter.getStrategy();
if(strategy == TaskTimeoutStrategy.WARN || strategy == TaskTimeoutStrategy.WARNFAILED){ if (strategy == TaskTimeoutStrategy.WARN || strategy == TaskTimeoutStrategy.WARNFAILED) {
checkTimeout = true; checkTimeout = true;
} }
} }
while (Stopper.isRunning()){ while (Stopper.isRunning()) {
try { try {
if(this.processInstance == null){ if (this.processInstance == null) {
logger.error("process instance not exists , master task exec thread exit"); logger.error("process instance not exists , master task exec thread exit");
return true; return true;
} }
// task instance add queue , waiting worker to kill // task instance add queue , waiting worker to kill
if(this.cancel || this.processInstance.getState() == ExecutionStatus.READY_STOP){ if (this.cancel || this.processInstance.getState() == ExecutionStatus.READY_STOP) {
cancelTaskInstance(); cancelTaskInstance();
} }
if(processInstance.getState() == ExecutionStatus.READY_PAUSE){ if (processInstance.getState() == ExecutionStatus.READY_PAUSE) {
pauseTask(); pauseTask();
} }
// task instance finished // task instance finished
if (taskInstance.getState().typeIsFinished()){ if (taskInstance.getState().typeIsFinished()) {
// if task is final result , then remove taskInstance from cache // if task is final result , then remove taskInstance from cache
taskInstanceCacheManager.removeByTaskInstanceId(taskInstance.getId()); taskInstanceCacheManager.removeByTaskInstanceId(taskInstance.getId());
break; break;
} }
if(checkTimeout){ if (checkTimeout) {
long remainTime = DateUtils.getRemainTime(taskInstance.getStartTime(), taskTimeoutParameter.getInterval() * 60L); long remainTime = DateUtils.getRemainTime(taskInstance.getStartTime(), taskTimeoutParameter.getInterval() * 60L);
if (remainTime < 0) { if (remainTime < 0) {
logger.warn("task id: {} execution time out",taskInstance.getId()); logger.warn("task id: {} execution time out", taskInstance.getId());
// process define // process define
ProcessDefinition processDefine = processService.findProcessDefineById(processInstance.getProcessDefinitionId()); ProcessDefinition processDefine = processService.findProcessDefineById(processInstance.getProcessDefinitionId());
// send warn mail // send warn mail
alertDao.sendTaskTimeoutAlert(processInstance.getWarningGroupId(),processDefine.getReceivers(), alertDao.sendTaskTimeoutAlert(processInstance.getWarningGroupId(), processInstance.getId(), processInstance.getName(),
processDefine.getReceiversCc(), processInstance.getId(), processInstance.getName(), taskInstance.getId(), taskInstance.getName());
taskInstance.getId(),taskInstance.getName());
checkTimeout = false; checkTimeout = false;
} }
} }
@ -168,10 +169,10 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
processInstance = processService.findProcessInstanceById(processInstance.getId()); processInstance = processService.findProcessInstanceById(processInstance.getId());
Thread.sleep(Constants.SLEEP_TIME_MILLIS); Thread.sleep(Constants.SLEEP_TIME_MILLIS);
} catch (Exception e) { } catch (Exception e) {
logger.error("exception",e); logger.error("exception", e);
if (processInstance != null) { if (processInstance != null) {
logger.error("wait task quit failed, instance id:{}, task id:{}", logger.error("wait task quit failed, instance id:{}, task id:{}",
processInstance.getId(), taskInstance.getId()); processInstance.getId(), taskInstance.getId());
} }
} }
} }
@ -180,31 +181,29 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
/** /**
* pause task if task have not been dispatched to worker, do not dispatch anymore. * pause task if task have not been dispatched to worker, do not dispatch anymore.
*
*/ */
public void pauseTask() { public void pauseTask() {
taskInstance = processService.findTaskInstanceById(taskInstance.getId()); taskInstance = processService.findTaskInstanceById(taskInstance.getId());
if(taskInstance == null){ if (taskInstance == null) {
return; return;
} }
if(StringUtils.isBlank(taskInstance.getHost())){ if (StringUtils.isBlank(taskInstance.getHost())) {
taskInstance.setState(ExecutionStatus.PAUSE); taskInstance.setState(ExecutionStatus.PAUSE);
taskInstance.setEndTime(new Date()); taskInstance.setEndTime(new Date());
processService.updateTaskInstance(taskInstance); processService.updateTaskInstance(taskInstance);
} }
} }
/** /**
* task instance add queue , waiting worker to kill * task instance add queue , waiting worker to kill
*/ */
private void cancelTaskInstance() throws Exception{ private void cancelTaskInstance() throws Exception {
if(alreadyKilled){ if (alreadyKilled) {
return; return;
} }
alreadyKilled = true; alreadyKilled = true;
taskInstance = processService.findTaskInstanceById(taskInstance.getId()); taskInstance = processService.findTaskInstanceById(taskInstance.getId());
if(StringUtils.isBlank(taskInstance.getHost())){ if (StringUtils.isBlank(taskInstance.getHost())) {
taskInstance.setState(ExecutionStatus.KILL); taskInstance.setState(ExecutionStatus.KILL);
taskInstance.setEndTime(new Date()); taskInstance.setEndTime(new Date());
processService.updateTaskInstance(taskInstance); processService.updateTaskInstance(taskInstance);
@ -222,23 +221,24 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
nettyExecutorManager.executeDirectly(executionContext); nettyExecutorManager.executeDirectly(executionContext);
logger.info("master kill taskInstance name :{} taskInstance id:{}", logger.info("master kill taskInstance name :{} taskInstance id:{}",
taskInstance.getName(), taskInstance.getId() ); taskInstance.getName(), taskInstance.getId());
} }
/** /**
* whether exists valid worker group * whether exists valid worker group
*
* @param taskInstanceWorkerGroup taskInstanceWorkerGroup * @param taskInstanceWorkerGroup taskInstanceWorkerGroup
* @return whether exists * @return whether exists
*/ */
public Boolean existsValidWorkerGroup(String taskInstanceWorkerGroup){ public Boolean existsValidWorkerGroup(String taskInstanceWorkerGroup) {
Set<String> workerGroups = zookeeperRegistryCenter.getWorkerGroupDirectly(); Set<String> workerGroups = zookeeperRegistryCenter.getWorkerGroupDirectly();
// not worker group // not worker group
if (CollectionUtils.isEmpty(workerGroups)){ if (CollectionUtils.isEmpty(workerGroups)) {
return false; return false;
} }
// has worker group , but not taskInstance assigned worker group // has worker group , but not taskInstance assigned worker group
if (!workerGroups.contains(taskInstanceWorkerGroup)){ if (!workerGroups.contains(taskInstanceWorkerGroup)) {
return false; return false;
} }
Set<String> workers = zookeeperRegistryCenter.getWorkerGroupNodesDirectly(taskInstanceWorkerGroup); Set<String> workers = zookeeperRegistryCenter.getWorkerGroupNodesDirectly(taskInstanceWorkerGroup);
@ -250,9 +250,10 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
/** /**
* get task timeout parameter * get task timeout parameter
*
* @return TaskTimeoutParameter * @return TaskTimeoutParameter
*/ */
private TaskTimeoutParameter getTaskTimeoutParameter(){ private TaskTimeoutParameter getTaskTimeoutParameter() {
String taskJson = taskInstance.getTaskJson(); String taskJson = taskInstance.getTaskJson();
TaskNode taskNode = JSONUtils.parseObject(taskJson, TaskNode.class); TaskNode taskNode = JSONUtils.parseObject(taskJson, TaskNode.class);
return taskNode.getTaskTimeoutParameter(); return taskNode.getTaskTimeoutParameter();

12
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/AlertManager.java

@ -17,7 +17,6 @@
package org.apache.dolphinscheduler.server.utils; package org.apache.dolphinscheduler.server.utils;
import org.apache.dolphinscheduler.common.enums.AlertType;
import org.apache.dolphinscheduler.common.enums.CommandType; import org.apache.dolphinscheduler.common.enums.CommandType;
import org.apache.dolphinscheduler.common.enums.WarningType; import org.apache.dolphinscheduler.common.enums.WarningType;
import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.common.utils.JSONUtils;
@ -28,7 +27,6 @@ import org.apache.dolphinscheduler.dao.entity.ProcessAlertContent;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
import org.apache.dolphinscheduler.dao.entity.TaskInstance; import org.apache.dolphinscheduler.dao.entity.TaskInstance;
import org.apache.dolphinscheduler.spi.alert.ShowType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -171,14 +169,10 @@ public class AlertManager {
try { try {
Alert alert = new Alert(); Alert alert = new Alert();
alert.setTitle("worker fault tolerance"); alert.setTitle("worker fault tolerance");
//alert.setShowType(ShowType.TABLE);
String content = getWorkerToleranceContent(processInstance, toleranceTaskList); String content = getWorkerToleranceContent(processInstance, toleranceTaskList);
alert.setContent(content); alert.setContent(content);
alert.setAlertType(AlertType.EMAIL);
alert.setCreateTime(new Date()); alert.setCreateTime(new Date());
alert.setAlertGroupId(processInstance.getWarningGroupId() == null ? 1 : processInstance.getWarningGroupId()); alert.setAlertGroupId(processInstance.getWarningGroupId() == null ? 1 : processInstance.getWarningGroupId());
alert.setReceivers(processInstance.getProcessDefinition().getReceivers());
alert.setReceiversCc(processInstance.getProcessDefinition().getReceiversCc());
alertDao.addAlert(alert); alertDao.addAlert(alert);
logger.info("add alert to db , alert : {}", alert.toString()); logger.info("add alert to db , alert : {}", alert.toString());
@ -225,16 +219,10 @@ public class AlertManager {
String cmdName = getCommandCnName(processInstance.getCommandType()); String cmdName = getCommandCnName(processInstance.getCommandType());
String success = processInstance.getState().typeIsSuccess() ? "success" : "failed"; String success = processInstance.getState().typeIsSuccess() ? "success" : "failed";
alert.setTitle(cmdName + " " + success); alert.setTitle(cmdName + " " + success);
ShowType showType = processInstance.getState().typeIsSuccess() ? ShowType.TEXT : ShowType.TABLE;
//alert.setShowType(showType);
String content = getContentProcessInstance(processInstance, taskInstances); String content = getContentProcessInstance(processInstance, taskInstances);
alert.setContent(content); alert.setContent(content);
alert.setAlertType(AlertType.EMAIL);
alert.setAlertGroupId(processInstance.getWarningGroupId()); alert.setAlertGroupId(processInstance.getWarningGroupId());
alert.setCreateTime(new Date()); alert.setCreateTime(new Date());
alert.setReceivers(processInstance.getProcessDefinition().getReceivers());
alert.setReceiversCc(processInstance.getProcessDefinition().getReceiversCc());
alertDao.addAlert(alert); alertDao.addAlert(alert);
logger.info("add alert to db , alert: {}", alert.toString()); logger.info("add alert to db , alert: {}", alert.toString());
} }

7
dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/registry/DependencyConfig.java

@ -34,7 +34,6 @@ import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper;
import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.TenantMapper;
import org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper; import org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper;
import org.apache.dolphinscheduler.dao.mapper.UserAlertGroupMapper;
import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper;
import org.apache.dolphinscheduler.server.master.cache.impl.TaskInstanceCacheManagerImpl; import org.apache.dolphinscheduler.server.master.cache.impl.TaskInstanceCacheManagerImpl;
import org.apache.dolphinscheduler.server.master.config.MasterConfig; import org.apache.dolphinscheduler.server.master.config.MasterConfig;
@ -66,11 +65,6 @@ public class DependencyConfig {
return Mockito.mock(AlertMapper.class); return Mockito.mock(AlertMapper.class);
} }
@Bean
public UserAlertGroupMapper userAlertGroupMapper() {
return Mockito.mock(UserAlertGroupMapper.class);
}
@Bean @Bean
public TaskInstanceCacheManagerImpl taskInstanceCacheManagerImpl() { public TaskInstanceCacheManagerImpl taskInstanceCacheManagerImpl() {
return Mockito.mock(TaskInstanceCacheManagerImpl.class); return Mockito.mock(TaskInstanceCacheManagerImpl.class);
@ -136,7 +130,6 @@ public class DependencyConfig {
return Mockito.mock(ResourceMapper.class); return Mockito.mock(ResourceMapper.class);
} }
@Bean @Bean
public ErrorCommandMapper errorCommandMapper() { public ErrorCommandMapper errorCommandMapper() {
return Mockito.mock(ErrorCommandMapper.class); return Mockito.mock(ErrorCommandMapper.class);

8
dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/processor/TaskCallbackServiceTestConfig.java

@ -34,7 +34,6 @@ import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper;
import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.TenantMapper;
import org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper; import org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper;
import org.apache.dolphinscheduler.dao.mapper.UserAlertGroupMapper;
import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper;
import org.apache.dolphinscheduler.server.master.cache.impl.TaskInstanceCacheManagerImpl; import org.apache.dolphinscheduler.server.master.cache.impl.TaskInstanceCacheManagerImpl;
import org.apache.dolphinscheduler.service.process.ProcessService; import org.apache.dolphinscheduler.service.process.ProcessService;
@ -49,7 +48,6 @@ import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
public class TaskCallbackServiceTestConfig { public class TaskCallbackServiceTestConfig {
@Bean @Bean
public AlertDao alertDao() { public AlertDao alertDao() {
return new AlertDao(); return new AlertDao();
@ -60,11 +58,6 @@ public class TaskCallbackServiceTestConfig {
return Mockito.mock(AlertMapper.class); return Mockito.mock(AlertMapper.class);
} }
@Bean
public UserAlertGroupMapper userAlertGroupMapper() {
return Mockito.mock(UserAlertGroupMapper.class);
}
@Bean @Bean
public TaskInstanceCacheManagerImpl taskInstanceCacheManagerImpl() { public TaskInstanceCacheManagerImpl taskInstanceCacheManagerImpl() {
return Mockito.mock(TaskInstanceCacheManagerImpl.class); return Mockito.mock(TaskInstanceCacheManagerImpl.class);
@ -125,7 +118,6 @@ public class TaskCallbackServiceTestConfig {
return Mockito.mock(ResourceMapper.class); return Mockito.mock(ResourceMapper.class);
} }
@Bean @Bean
public ErrorCommandMapper errorCommandMapper() { public ErrorCommandMapper errorCommandMapper() {
return Mockito.mock(ErrorCommandMapper.class); return Mockito.mock(ErrorCommandMapper.class);

766
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java

File diff suppressed because it is too large Load Diff

1
pom.xml

@ -940,7 +940,6 @@
<include>**/dao/mapper/TenantMapperTest.java</include> <include>**/dao/mapper/TenantMapperTest.java</include>
<include>**/dao/mapper/UdfFuncMapperTest.java</include> <include>**/dao/mapper/UdfFuncMapperTest.java</include>
<include>**/dao/mapper/UDFUserMapperTest.java</include> <include>**/dao/mapper/UDFUserMapperTest.java</include>
<include>**/dao/mapper/UserAlertGroupMapperTest.java</include>
<include>**/dao/mapper/UserMapperTest.java</include> <include>**/dao/mapper/UserMapperTest.java</include>
<include>**/dao/mapper/AlertPluginInstanceMapperTest.java</include> <include>**/dao/mapper/AlertPluginInstanceMapperTest.java</include>
<include>**/dao/mapper/PluginDefineTest.java</include> <include>**/dao/mapper/PluginDefineTest.java</include>

63
sql/dolphinscheduler-postgre.sql

@ -187,14 +187,10 @@ DROP TABLE IF EXISTS t_ds_alert;
CREATE TABLE t_ds_alert ( CREATE TABLE t_ds_alert (
id int NOT NULL , id int NOT NULL ,
title varchar(64) DEFAULT NULL , title varchar(64) DEFAULT NULL ,
show_type int DEFAULT NULL ,
content text , content text ,
alert_type int DEFAULT NULL ,
alert_status int DEFAULT '0' , alert_status int DEFAULT '0' ,
log text , log text ,
alertgroup_id int DEFAULT NULL , alertgroup_id int DEFAULT NULL ,
receivers text ,
receivers_cc text ,
create_time timestamp DEFAULT NULL , create_time timestamp DEFAULT NULL ,
update_time timestamp DEFAULT NULL , update_time timestamp DEFAULT NULL ,
PRIMARY KEY (id) PRIMARY KEY (id)
@ -204,14 +200,14 @@ CREATE TABLE t_ds_alert (
-- --
DROP TABLE IF EXISTS t_ds_alertgroup; DROP TABLE IF EXISTS t_ds_alertgroup;
CREATE TABLE t_ds_alertgroup ( CREATE TABLE t_ds_alertgroup(
id int NOT NULL , id int NOT NULL,
group_name varchar(255) DEFAULT NULL , create_user_id int4 DEFAULT NULL,
group_type int DEFAULT NULL , group_name varchar(255) DEFAULT NULL,
description varchar(255) DEFAULT NULL , description varchar(255) DEFAULT NULL,
create_time timestamp DEFAULT NULL , create_time timestamp DEFAULT NULL,
update_time timestamp DEFAULT NULL , update_time timestamp DEFAULT NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
) ; ) ;
-- --
@ -301,8 +297,7 @@ CREATE TABLE t_ds_process_definition (
flag int DEFAULT NULL , flag int DEFAULT NULL ,
locations text , locations text ,
connects text , connects text ,
receivers text , warning_group_id int4 DEFAULT NULL ,
receivers_cc text ,
create_time timestamp DEFAULT NULL , create_time timestamp DEFAULT NULL ,
timeout int DEFAULT '0' , timeout int DEFAULT '0' ,
tenant_id int NOT NULL DEFAULT '-1' , tenant_id int NOT NULL DEFAULT '-1' ,
@ -329,8 +324,7 @@ CREATE TABLE t_ds_process_definition_version (
global_params text , global_params text ,
locations text , locations text ,
connects text , connects text ,
receivers text , warning_group_id int4 DEFAULT NULL,
receivers_cc text ,
create_time timestamp DEFAULT NULL , create_time timestamp DEFAULT NULL ,
timeout int DEFAULT '0' , timeout int DEFAULT '0' ,
resource_ids varchar(64), resource_ids varchar(64),
@ -492,20 +486,6 @@ CREATE TABLE t_ds_relation_udfs_user (
) ; ) ;
; ;
--
-- Table structure for table t_ds_relation_user_alertgroup
--
DROP TABLE IF EXISTS t_ds_relation_user_alertgroup;
CREATE TABLE t_ds_relation_user_alertgroup (
id int NOT NULL,
alertgroup_id int DEFAULT NULL,
user_id int DEFAULT NULL,
create_time timestamp DEFAULT NULL,
update_time timestamp DEFAULT NULL,
PRIMARY KEY (id)
);
-- --
-- Table structure for table t_ds_resources -- Table structure for table t_ds_resources
-- --
@ -748,9 +728,6 @@ ALTER TABLE t_ds_relation_resources_user ALTER COLUMN id SET DEFAULT NEXTVAL('t_
DROP SEQUENCE IF EXISTS t_ds_relation_udfs_user_id_sequence; DROP SEQUENCE IF EXISTS t_ds_relation_udfs_user_id_sequence;
CREATE SEQUENCE t_ds_relation_udfs_user_id_sequence; CREATE SEQUENCE t_ds_relation_udfs_user_id_sequence;
ALTER TABLE t_ds_relation_udfs_user ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_relation_udfs_user_id_sequence'); ALTER TABLE t_ds_relation_udfs_user ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_relation_udfs_user_id_sequence');
DROP SEQUENCE IF EXISTS t_ds_relation_user_alertgroup_id_sequence;
CREATE SEQUENCE t_ds_relation_user_alertgroup_id_sequence;
ALTER TABLE t_ds_relation_user_alertgroup ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_relation_user_alertgroup_id_sequence');
DROP SEQUENCE IF EXISTS t_ds_resources_id_sequence; DROP SEQUENCE IF EXISTS t_ds_resources_id_sequence;
CREATE SEQUENCE t_ds_resources_id_sequence; CREATE SEQUENCE t_ds_resources_id_sequence;
@ -777,21 +754,27 @@ ALTER TABLE t_ds_version ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_version_id_se
DROP SEQUENCE IF EXISTS t_ds_worker_group_id_sequence; DROP SEQUENCE IF EXISTS t_ds_worker_group_id_sequence;
CREATE SEQUENCE t_ds_worker_group_id_sequence; CREATE SEQUENCE t_ds_worker_group_id_sequence;
ALTER TABLE t_ds_worker_group ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_worker_group_id_sequence'); ALTER TABLE t_ds_worker_group
ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_worker_group_id_sequence');
DROP SEQUENCE IF EXISTS t_ds_worker_server_id_sequence; DROP SEQUENCE IF EXISTS t_ds_worker_server_id_sequence;
CREATE SEQUENCE t_ds_worker_server_id_sequence; CREATE SEQUENCE t_ds_worker_server_id_sequence;
ALTER TABLE t_ds_worker_server ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_worker_server_id_sequence'); ALTER TABLE t_ds_worker_server
ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_worker_server_id_sequence');
-- Records of t_ds_user?user : admin , password : dolphinscheduler123 -- Records of t_ds_user?user : admin , password : dolphinscheduler123
INSERT INTO t_ds_user(user_name,user_password,user_type,email,phone,tenant_id,state,create_time,update_time) VALUES ('admin', '7ad2410b2f4c074479a8937a28a22b8f', '0', 'xxx@qq.com', '', '0', 1, '2018-03-27 15:48:50', '2018-10-24 17:40:22'); INSERT INTO t_ds_user(user_name, user_password, user_type, email, phone, tenant_id, state, create_time, update_time)
VALUES ('admin', '7ad2410b2f4c074479a8937a28a22b8f', '0', 'xxx@qq.com', '', '0', 1, '2018-03-27 15:48:50',
'2018-10-24 17:40:22');
-- Records of t_ds_alertgroup,dolphinscheduler warning group -- Records of t_ds_alertgroup,dolphinscheduler warning group
INSERT INTO t_ds_alertgroup(group_name,group_type,description,create_time,update_time) VALUES ('dolphinscheduler warning group', '0', 'dolphinscheduler warning group','2018-11-29 10:20:39', '2018-11-29 10:20:39'); INSERT INTO t_ds_alertgroup(id, create_user_id, group_name, description, create_time, update_time)
INSERT INTO t_ds_relation_user_alertgroup(alertgroup_id,user_id,create_time,update_time) VALUES ( '1', '1', '2018-11-29 10:22:33', '2018-11-29 10:22:33'); VALUES (1, 'dolphinscheduler warning group', 'dolphinscheduler warning group', '2018-11-29 10:20:39',
'2018-11-29 10:20:39');
-- Records of t_ds_queue,default queue name : default -- Records of t_ds_queue,default queue name : default
INSERT INTO t_ds_queue(queue_name,queue,create_time,update_time) VALUES ('default', 'default','2018-11-29 10:22:33', '2018-11-29 10:22:33'); INSERT INTO t_ds_queue(queue_name, queue, create_time, update_time)
VALUES ('default', 'default', '2018-11-29 10:22:33', '2018-11-29 10:22:33');
-- Records of t_ds_queue,default queue name : default -- Records of t_ds_queue,default queue name : default
INSERT INTO t_ds_version(version) VALUES ('1.3.0'); INSERT INTO t_ds_version(version) VALUES ('1.3.0');

66
sql/dolphinscheduler_mysql.sql

@ -279,14 +279,10 @@ DROP TABLE IF EXISTS `t_ds_alert`;
CREATE TABLE `t_ds_alert` ( CREATE TABLE `t_ds_alert` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'key', `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'key',
`title` varchar(64) DEFAULT NULL COMMENT 'title', `title` varchar(64) DEFAULT NULL COMMENT 'title',
`show_type` tinyint(4) DEFAULT NULL COMMENT 'send email type,0:TABLE,1:TEXT',
`content` text COMMENT 'Message content (can be email, can be SMS. Mail is stored in JSON map, and SMS is string)', `content` text COMMENT 'Message content (can be email, can be SMS. Mail is stored in JSON map, and SMS is string)',
`alert_type` tinyint(4) DEFAULT NULL COMMENT '0:email,1:sms',
`alert_status` tinyint(4) DEFAULT '0' COMMENT '0:wait running,1:success,2:failed', `alert_status` tinyint(4) DEFAULT '0' COMMENT '0:wait running,1:success,2:failed',
`log` text COMMENT 'log', `log` text COMMENT 'log',
`alertgroup_id` int(11) DEFAULT NULL COMMENT 'alert group id', `alertgroup_id` int(11) DEFAULT NULL COMMENT 'alert group id',
`receivers` text COMMENT 'receivers',
`receivers_cc` text COMMENT 'cc',
`create_time` datetime DEFAULT NULL COMMENT 'create time', `create_time` datetime DEFAULT NULL COMMENT 'create time',
`update_time` datetime DEFAULT NULL COMMENT 'update time', `update_time` datetime DEFAULT NULL COMMENT 'update time',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
@ -300,14 +296,14 @@ CREATE TABLE `t_ds_alert` (
-- Table structure for t_ds_alertgroup -- Table structure for t_ds_alertgroup
-- ---------------------------- -- ----------------------------
DROP TABLE IF EXISTS `t_ds_alertgroup`; DROP TABLE IF EXISTS `t_ds_alertgroup`;
CREATE TABLE `t_ds_alertgroup` ( CREATE TABLE `t_ds_alertgroup`(
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'key', `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'key',
`group_name` varchar(255) DEFAULT NULL COMMENT 'group name', `create_user_id` int(11) DEFAULT NULL COMMENT 'create user id',
`group_type` tinyint(4) DEFAULT NULL COMMENT 'Group type (message 0, SMS 1...)', `group_name` varchar(255) DEFAULT NULL COMMENT 'group name',
`description` varchar(255) DEFAULT NULL, `description` varchar(255) DEFAULT NULL,
`create_time` datetime DEFAULT NULL COMMENT 'create time', `create_time` datetime DEFAULT NULL COMMENT 'create time',
`update_time` datetime DEFAULT NULL COMMENT 'update time', `update_time` datetime DEFAULT NULL COMMENT 'update time',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
-- ---------------------------- -- ----------------------------
@ -406,8 +402,7 @@ CREATE TABLE `t_ds_process_definition` (
`flag` tinyint(4) DEFAULT NULL COMMENT '0 not available, 1 available', `flag` tinyint(4) DEFAULT NULL COMMENT '0 not available, 1 available',
`locations` text COMMENT 'Node location information', `locations` text COMMENT 'Node location information',
`connects` text COMMENT 'Node connection information', `connects` text COMMENT 'Node connection information',
`receivers` text COMMENT 'receivers', `warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id',
`receivers_cc` text COMMENT 'cc',
`create_time` datetime DEFAULT NULL COMMENT 'create time', `create_time` datetime DEFAULT NULL COMMENT 'create time',
`timeout` int(11) DEFAULT '0' COMMENT 'time out', `timeout` int(11) DEFAULT '0' COMMENT 'time out',
`tenant_id` int(11) NOT NULL DEFAULT '-1' COMMENT 'tenant id', `tenant_id` int(11) NOT NULL DEFAULT '-1' COMMENT 'tenant id',
@ -436,8 +431,7 @@ CREATE TABLE `t_ds_process_definition_version` (
`global_params` text COMMENT 'global parameters', `global_params` text COMMENT 'global parameters',
`locations` text COMMENT 'Node location information', `locations` text COMMENT 'Node location information',
`connects` text COMMENT 'Node connection information', `connects` text COMMENT 'Node connection information',
`receivers` text COMMENT 'receivers', `warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id',
`receivers_cc` text COMMENT 'cc',
`create_time` datetime DEFAULT NULL COMMENT 'create time', `create_time` datetime DEFAULT NULL COMMENT 'create time',
`timeout` int(11) DEFAULT '0' COMMENT 'time out', `timeout` int(11) DEFAULT '0' COMMENT 'time out',
`resource_ids` varchar(255) DEFAULT NULL COMMENT 'resource ids', `resource_ids` varchar(255) DEFAULT NULL COMMENT 'resource ids',
@ -620,27 +614,6 @@ CREATE TABLE `t_ds_relation_udfs_user` (
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of t_ds_relation_udfs_user
-- ----------------------------
-- ----------------------------
-- Table structure for t_ds_relation_user_alertgroup
-- ----------------------------
DROP TABLE IF EXISTS `t_ds_relation_user_alertgroup`;
CREATE TABLE `t_ds_relation_user_alertgroup` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'key',
`alertgroup_id` int(11) DEFAULT NULL COMMENT 'alert group id',
`user_id` int(11) DEFAULT NULL COMMENT 'user id',
`create_time` datetime DEFAULT NULL COMMENT 'create time',
`update_time` datetime DEFAULT NULL COMMENT 'update time',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of t_ds_relation_user_alertgroup
-- ----------------------------
-- ---------------------------- -- ----------------------------
-- Table structure for t_ds_resources -- Table structure for t_ds_resources
-- ---------------------------- -- ----------------------------
@ -831,28 +804,29 @@ CREATE TABLE `t_ds_version` (
-- ---------------------------- -- ----------------------------
-- Records of t_ds_version -- Records of t_ds_version
-- ---------------------------- -- ----------------------------
INSERT INTO `t_ds_version` VALUES ('1', '1.3.0'); INSERT INTO `t_ds_version`
VALUES ('1', '1.3.0');
-- ---------------------------- -- ----------------------------
-- Records of t_ds_alertgroup -- Records of t_ds_alertgroup
-- ---------------------------- -- ----------------------------
INSERT INTO `t_ds_alertgroup` VALUES ('1', 'default admin warning group', '0', 'default admin warning group', '2018-11-29 10:20:39', '2018-11-29 10:20:39'); INSERT INTO `t_ds_alertgroup`
VALUES (1, 1, 'default admin warning group', 'default admin warning group', '2018-11-29 10:20:39',
-- ---------------------------- '2018-11-29 10:20:39');
-- Records of t_ds_relation_user_alertgroup
-- ----------------------------
INSERT INTO `t_ds_relation_user_alertgroup` VALUES ('1', '1', '1', '2018-11-29 10:22:33', '2018-11-29 10:22:33');
-- ---------------------------- -- ----------------------------
-- Records of t_ds_user -- Records of t_ds_user
-- ---------------------------- -- ----------------------------
INSERT INTO `t_ds_user` VALUES ('1', 'admin', '7ad2410b2f4c074479a8937a28a22b8f', '0', 'xxx@qq.com', '', '0', '2018-03-27 15:48:50', '2018-10-24 17:40:22', null, 1); INSERT INTO `t_ds_user`
VALUES ('1', 'admin', '7ad2410b2f4c074479a8937a28a22b8f', '0', 'xxx@qq.com', '', '0', '2018-03-27 15:48:50',
'2018-10-24 17:40:22', null, 1);
-- ---------------------------- -- ----------------------------
-- Table structure for t_ds_plugin_define -- Table structure for t_ds_plugin_define
-- ---------------------------- -- ----------------------------
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); SET
sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
DROP TABLE IF EXISTS `t_ds_plugin_define`; DROP TABLE IF EXISTS `t_ds_plugin_define`;
CREATE TABLE `t_ds_plugin_define` ( CREATE TABLE `t_ds_plugin_define` (
`id` int NOT NULL AUTO_INCREMENT, `id` int NOT NULL AUTO_INCREMENT,

42
sql/upgrade/1.4.0_schema/mysql/dolphinscheduler_ddl.sql

@ -30,14 +30,40 @@ CREATE TABLE `t_ds_plugin_define` (
DROP TABLE IF EXISTS `t_ds_alert_plugin_instance`; DROP TABLE IF EXISTS `t_ds_alert_plugin_instance`;
CREATE TABLE `t_ds_alert_plugin_instance` ( CREATE TABLE `t_ds_alert_plugin_instance` (
`id` int NOT NULL AUTO_INCREMENT, `id` int NOT NULL AUTO_INCREMENT,
`plugin_define_id` int NOT NULL, `plugin_define_id` int NOT NULL,
`plugin_instance_params` text COMMENT 'plugin instance params. Also contain the params value which user input in web ui.', `plugin_instance_params` text COMMENT 'plugin instance params. Also contain the params value which user input in web ui.',
`create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`alert_group_id` int DEFAULT NULL, `alert_group_id` int DEFAULT NULL,
`instance_name` varchar(200) DEFAULT NULL COMMENT 'alert instance name', `instance_name` varchar(200) DEFAULT NULL COMMENT 'alert instance name',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE t_ds_process_definition
ADD COLUMN `warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id' AFTER `connects`;
ALTER TABLE t_ds_process_definition_version
ADD COLUMN `warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id' AFTER `connects`;
ALTER TABLE t_ds_alertgroup
ADD COLUMN `create_user_id` int(11) DEFAULT NULL COMMENT 'create user id' AFTER `id`;
-- ----------------------------
-- These columns will not be used in the new version,if you determine that the historical data is useless, you can delete it using the sql below
-- ----------------------------
/*
ALTER TABLE t_ds_process_definition DROP receivers, DROP receivers_cc;
ALTER TABLE t_ds_process_definition_version DROP receivers, DROP receivers_cc;
ALTER TABLE t_ds_alert DROP show_type,DROP alert_type,DROP receivers,DROP receivers_cc;
ALTER TABLE t_ds_alertgroup DROP group_type;
DROP TABLE IF EXISTS t_ds_relation_user_alertgroup;
*/

40
sql/upgrade/1.4.0_schema/postgresql/dolphinscheduler_ddl.sql

@ -29,12 +29,36 @@ CREATE TABLE t_ds_plugin_define (
DROP TABLE IF EXISTS t_ds_alert_plugin_instance; DROP TABLE IF EXISTS t_ds_alert_plugin_instance;
CREATE TABLE t_ds_alert_plugin_instance ( CREATE TABLE t_ds_alert_plugin_instance (
id serial NOT NULL, id serial NOT NULL,
plugin_define_id int4 NOT NULL, plugin_define_id int4 NOT NULL,
plugin_instance_params text NULL, plugin_instance_params text NULL,
create_time timestamp NULL, create_time timestamp NULL,
update_time timestamp NULL, update_time timestamp NULL,
alert_group_id int4 NOT NULL, alert_group_id int4 NOT NULL,
instance_name varchar(200) NULL, instance_name varchar(200) NULL,
CONSTRAINT t_ds_alert_plugin_instance_pk PRIMARY KEY (id) CONSTRAINT t_ds_alert_plugin_instance_pk PRIMARY KEY (id)
); );
ALTER TABLE t_ds_process_definition
ADD COLUMN `warning_group_id` int4 DEFAULT NULL COMMENT 'alert group id' AFTER `connects`;
ALTER TABLE t_ds_process_definition_version
ADD COLUMN `warning_group_id` int4 DEFAULT NULL COMMENT 'alert group id' AFTER `connects`;
ALTER TABLE t_ds_alertgroup
ADD COLUMN `create_user_id` int4 DEFAULT NULL COMMENT 'create user id' AFTER `id`;
-- ----------------------------
-- These columns will not be used in the new version,if you determine that the historical data is useless, you can delete it using the sql below
-- ----------------------------
/*
ALTER TABLE t_ds_process_definition DROP COLUMN "receivers", DROP COLUMN "receivers_cc";
ALTER TABLE t_ds_process_definition_version DROP COLUMN "receivers", DROP COLUMN "receivers_cc";
ALTER TABLE t_ds_alert DROP COLUMN "show_type",DROP COLUMN "alert_type",DROP COLUMN "receivers",DROP COLUMN "receivers_cc";
ALTER TABLE t_ds_alertgroup DROP COLUMN "group_type";
DROP TABLE IF EXISTS t_ds_relation_user_alertgroup;
*/

Loading…
Cancel
Save