diff --git a/.asf.yaml b/.asf.yaml index 2eca3ad1b2..2ed24a40dd 100644 --- a/.asf.yaml +++ b/.asf.yaml @@ -36,7 +36,7 @@ github: - data-schedule enabled_merge_buttons: squash: true - merge: false + merge: true rebase: false protected_branches: dev: diff --git a/.github/actions/translate-on-issue b/.github/actions/translate-on-issue deleted file mode 160000 index 8c4d3b8ead..0000000000 --- a/.github/actions/translate-on-issue +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8c4d3b8ead41812bbe837dc5dfb8fa047cd2b548 diff --git a/.gitignore b/.gitignore index 2e1a6478ed..9011db1479 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ config.gypi test/coverage /docs/zh_CN/介绍 /docs/zh_CN/贡献代码.md +dolphinscheduler-common/src/main/resources/zookeeper.properties dolphinscheduler-dao/src/main/resources/dao/data_source.properties dolphinscheduler-alert/logs/ dolphinscheduler-alert/src/main/resources/alert.properties_bak diff --git a/docker/build/conf/dolphinscheduler/logback/logback-alert.xml b/docker/build/conf/dolphinscheduler/logback/logback-alert.xml index 5f1872969b..1718947dd1 100644 --- a/docker/build/conf/dolphinscheduler/logback/logback-alert.xml +++ b/docker/build/conf/dolphinscheduler/logback/logback-alert.xml @@ -18,13 +18,12 @@ - - + - [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %message%n + [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %msg%n UTF-8 @@ -39,7 +38,7 @@ - [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %message%n + [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %msg%n UTF-8 diff --git a/docker/build/conf/dolphinscheduler/logback/logback-api.xml b/docker/build/conf/dolphinscheduler/logback/logback-api.xml index ead5403bd6..bec3d9aa49 100644 --- a/docker/build/conf/dolphinscheduler/logback/logback-api.xml +++ b/docker/build/conf/dolphinscheduler/logback/logback-api.xml @@ -18,13 +18,12 @@ - - + - [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %message%n + [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %msg%n UTF-8 @@ -43,7 +42,7 @@ - [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %message%n + [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %msg%n UTF-8 diff --git a/docker/build/conf/dolphinscheduler/logback/logback-master.xml b/docker/build/conf/dolphinscheduler/logback/logback-master.xml index c8692b82c5..f0d2c81df2 100644 --- a/docker/build/conf/dolphinscheduler/logback/logback-master.xml +++ b/docker/build/conf/dolphinscheduler/logback/logback-master.xml @@ -18,18 +18,19 @@ - - + - [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %message%n + [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %msg%n UTF-8 + - - + - [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %message%n + [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %msg%n UTF-8 + - - + - [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %message%n + [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %msg%n UTF-8 @@ -39,13 +38,14 @@ - [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %message%n + [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %msg%n UTF-8 + diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AccessTokenController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AccessTokenController.java index e691f88e6d..01bb22d9ae 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AccessTokenController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AccessTokenController.java @@ -35,8 +35,11 @@ import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -49,12 +52,13 @@ import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import springfox.documentation.annotations.ApiIgnore; + /** * access token controller */ @Api(tags = "ACCESS_TOKEN_TAG") @RestController -@RequestMapping("/access-token") +@RequestMapping("/access-tokens") public class AccessTokenController extends BaseController { @Autowired @@ -63,14 +67,14 @@ public class AccessTokenController extends BaseController { /** * create token * - * @param loginUser login user - * @param userId token for user id + * @param loginUser login user + * @param userId token for user id * @param expireTime expire time for the token - * @param token token + * @param token token * @return create result state code */ @ApiIgnore - @PostMapping(value = "/create") + @PostMapping() @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_ACCESS_TOKEN_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -86,8 +90,8 @@ public class AccessTokenController extends BaseController { /** * generate token string * - * @param loginUser login user - * @param userId token for user + * @param loginUser login user + * @param userId token for user * @param expireTime expire time * @return token string */ @@ -107,18 +111,18 @@ public class AccessTokenController extends BaseController { * query access token list paging * * @param loginUser login user - * @param pageNo page number + * @param pageNo page number * @param searchVal search value - * @param pageSize page size + * @param pageSize page size * @return token list of page number and page size */ @ApiOperation(value = "queryAccessTokenList", notes = "QUERY_ACCESS_TOKEN_LIST_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), - @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") }) - @GetMapping(value = "/list-paging") + @GetMapping() @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_ACCESSTOKEN_LIST_PAGING_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -140,16 +144,16 @@ public class AccessTokenController extends BaseController { * delete access token by id * * @param loginUser login user - * @param id token id + * @param id token id * @return delete result code */ @ApiIgnore - @PostMapping(value = "/delete") + @DeleteMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_ACCESS_TOKEN_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result delAccessTokenById(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int id) { + @PathVariable(value = "id") int id) { Map result = accessTokenService.delAccessTokenById(loginUser, id); return returnDataList(result); } @@ -158,20 +162,20 @@ public class AccessTokenController extends BaseController { /** * update token * - * @param loginUser login user - * @param id token id - * @param userId token for user + * @param loginUser login user + * @param id token id + * @param userId token for user * @param expireTime token expire time - * @param token token string + * @param token token string * @return update result code */ @ApiIgnore - @PostMapping(value = "/update") + @PutMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_ACCESS_TOKEN_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateToken(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int id, + @PathVariable(value = "id") int id, @RequestParam(value = "userId") int userId, @RequestParam(value = "expireTime") String expireTime, @RequestParam(value = "token") String token) { diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java index 227775d62c..8bc4c7eba8 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java @@ -39,8 +39,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -58,7 +61,7 @@ import springfox.documentation.annotations.ApiIgnore; */ @Api(tags = "ALERT_GROUP_TAG") @RestController -@RequestMapping("alert-group") +@RequestMapping("/alert-groups") public class AlertGroupController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(AlertGroupController.class); @@ -77,11 +80,11 @@ public class AlertGroupController extends BaseController { */ @ApiOperation(value = "createAlertgroup", notes = "CREATE_ALERT_GROUP_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "description", value = "DESC", dataType = "String"), - @ApiImplicitParam(name = "alertInstanceIds", value = "alertInstanceIds", required = true, dataType = "String") + @ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "description", value = "DESC", dataType = "String"), + @ApiImplicitParam(name = "alertInstanceIds", value = "alertInstanceIds", required = true, dataType = "String") }) - @PostMapping(value = "/create") + @PostMapping() @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_ALERT_GROUP_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -121,11 +124,11 @@ public class AlertGroupController extends BaseController { */ @ApiOperation(value = "queryAlertGroupListPaging", notes = "QUERY_ALERT_GROUP_LIST_PAGING_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"), - @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"), + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") }) - @GetMapping(value = "/list-paging") + @GetMapping() @ResponseStatus(HttpStatus.OK) @ApiException(LIST_PAGING_ALERT_GROUP_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -163,6 +166,7 @@ public class AlertGroupController extends BaseController { } + /** * updateProcessInstance alert group * @@ -174,17 +178,17 @@ public class AlertGroupController extends BaseController { */ @ApiOperation(value = "updateAlertgroup", notes = "UPDATE_ALERT_GROUP_NOTES") @ApiImplicitParams({ - @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 = "description", value = "DESC", dataType = "String"), - @ApiImplicitParam(name = "alertInstanceIds", value = "alertInstanceIds", required = true, dataType = "String") + @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 = "description", value = "DESC", dataType = "String"), + @ApiImplicitParam(name = "alertInstanceIds", value = "alertInstanceIds", required = true, dataType = "String") }) - @PostMapping(value = "/update") + @PutMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_ALERT_GROUP_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateAlertgroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int id, + @PathVariable(value = "id") int id, @RequestParam(value = "groupName") String groupName, @RequestParam(value = "description", required = false) String description, @RequestParam(value = "alertInstanceIds") String alertInstanceIds) { @@ -202,14 +206,14 @@ public class AlertGroupController extends BaseController { */ @ApiOperation(value = "delAlertgroupById", notes = "DELETE_ALERT_GROUP_BY_ID_NOTES") @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") + @DeleteMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_ALERT_GROUP_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result delAlertgroupById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int id) { + @PathVariable(value = "id") int id) { Map result = alertGroupService.delAlertgroupById(loginUser, id); return returnDataList(result); } @@ -224,9 +228,9 @@ public class AlertGroupController extends BaseController { */ @ApiOperation(value = "verifyGroupName", notes = "VERIFY_ALERT_GROUP_NAME_NOTES") @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-name") @ResponseStatus(HttpStatus.OK) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result verifyGroupName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java index 2853e37d54..2e241a50c6 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java @@ -38,8 +38,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -57,7 +60,7 @@ import springfox.documentation.annotations.ApiIgnore; */ @Api(tags = "ALERT_PLUGIN_INSTANCE_TAG") @RestController -@RequestMapping("alert-plugin-instance") +@RequestMapping("alert-plugin-instances") public class AlertPluginInstanceController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(AlertPluginInstanceController.class); @@ -77,11 +80,11 @@ public class AlertPluginInstanceController extends BaseController { */ @ApiOperation(value = "createAlertPluginInstance", notes = "CREATE_ALERT_PLUGIN_INSTANCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "pluginDefineId", value = "ALERT_PLUGIN_DEFINE_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "instanceName", value = "ALERT_PLUGIN_INSTANCE_NAME", required = true, dataType = "String", example = "DING TALK"), - @ApiImplicitParam(name = "pluginInstanceParams", value = "ALERT_PLUGIN_INSTANCE_PARAMS", required = true, dataType = "String", example = "ALERT_PLUGIN_INSTANCE_PARAMS") + @ApiImplicitParam(name = "pluginDefineId", value = "ALERT_PLUGIN_DEFINE_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "instanceName", value = "ALERT_PLUGIN_INSTANCE_NAME", required = true, dataType = "String", example = "DING TALK"), + @ApiImplicitParam(name = "pluginInstanceParams", value = "ALERT_PLUGIN_INSTANCE_PARAMS", required = true, dataType = "String", example = "ALERT_PLUGIN_INSTANCE_PARAMS") }) - @PostMapping(value = "/create") + @PostMapping() @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_ALERT_PLUGIN_INSTANCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -97,26 +100,26 @@ public class AlertPluginInstanceController extends BaseController { * updateAlertPluginInstance * * @param loginUser login user - * @param alertPluginInstanceId alert plugin instance id + * @param id alert plugin instance id * @param instanceName instance name * @param pluginInstanceParams instance params * @return result */ @ApiOperation(value = "updateAlertPluginInstance", notes = "UPDATE_ALERT_PLUGIN_INSTANCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "alertPluginInstanceId", value = "ALERT_PLUGIN_INSTANCE_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "instanceName", value = "ALERT_PLUGIN_INSTANCE_NAME", required = true, dataType = "String", example = "DING TALK"), - @ApiImplicitParam(name = "pluginInstanceParams", value = "ALERT_PLUGIN_INSTANCE_PARAMS", required = true, dataType = "String", example = "ALERT_PLUGIN_INSTANCE_PARAMS") + @ApiImplicitParam(name = "alertPluginInstanceId", value = "ALERT_PLUGIN_INSTANCE_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "instanceName", value = "ALERT_PLUGIN_INSTANCE_NAME", required = true, dataType = "String", example = "DING TALK"), + @ApiImplicitParam(name = "pluginInstanceParams", value = "ALERT_PLUGIN_INSTANCE_PARAMS", required = true, dataType = "String", example = "ALERT_PLUGIN_INSTANCE_PARAMS") }) - @PostMapping(value = "/update") + @PutMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_ALERT_PLUGIN_INSTANCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateAlertPluginInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "alertPluginInstanceId") int alertPluginInstanceId, + @PathVariable(value = "id") int id, @RequestParam(value = "instanceName") String instanceName, @RequestParam(value = "pluginInstanceParams") String pluginInstanceParams) { - Map result = alertPluginInstanceService.update(loginUser, alertPluginInstanceId, instanceName, pluginInstanceParams); + Map result = alertPluginInstanceService.update(loginUser, id, instanceName, pluginInstanceParams); return returnDataList(result); } @@ -129,14 +132,14 @@ public class AlertPluginInstanceController extends BaseController { */ @ApiOperation(value = "deleteAlertPluginInstance", notes = "DELETE_ALERT_PLUGIN_INSTANCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "ALERT_PLUGIN_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "id", value = "ALERT_PLUGIN_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/delete") + @DeleteMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_ALERT_PLUGIN_INSTANCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteAlertPluginInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int id) { + @PathVariable(value = "id") int id) { Map result = alertPluginInstanceService.delete(loginUser, id); return returnDataList(result); @@ -150,12 +153,12 @@ public class AlertPluginInstanceController extends BaseController { * @return result */ @ApiOperation(value = "getAlertPluginInstance", notes = "GET_ALERT_PLUGIN_INSTANCE_NOTES") - @PostMapping(value = "/get") + @GetMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(GET_ALERT_PLUGIN_INSTANCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result getAlertPluginInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int id) { + @PathVariable(value = "id") int id) { Map result = alertPluginInstanceService.get(loginUser, id); return returnDataList(result); } @@ -166,8 +169,8 @@ public class AlertPluginInstanceController extends BaseController { * @param loginUser login user * @return result */ - @ApiOperation(value = "queryAllAlertPluginInstance", notes = "QUERY_ALL_ALERT_PLUGIN_INSTANCE_NOTES") - @PostMapping(value = "/queryAll") + @ApiOperation(value = "queryAlertPluginInstanceList", notes = "QUERY_ALL_ALERT_PLUGIN_INSTANCE_NOTES") + @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_ALL_ALERT_PLUGIN_INSTANCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -185,9 +188,9 @@ public class AlertPluginInstanceController extends BaseController { */ @ApiOperation(value = "verifyAlertInstanceName", notes = "VERIFY_ALERT_INSTANCE_NAME_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "alertInstanceName", value = "ALERT_INSTANCE_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "alertInstanceName", value = "ALERT_INSTANCE_NAME", required = true, dataType = "String"), }) - @GetMapping(value = "/verify-alert-instance-name") + @GetMapping(value = "/verify-name") @ResponseStatus(HttpStatus.OK) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result verifyGroupName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @@ -216,10 +219,10 @@ public class AlertPluginInstanceController extends BaseController { */ @ApiOperation(value = "queryAlertPluginInstanceListPaging", notes = "QUERY_ALERT_PLUGIN_INSTANCE_LIST_PAGING_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") }) - @GetMapping(value = "/list-paging") + @GetMapping() @ResponseStatus(HttpStatus.OK) @ApiException(LIST_PAGING_ALERT_PLUGIN_INSTANCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/BaseController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/BaseController.java index aa2ac00b00..1dec863c6a 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/BaseController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/BaseController.java @@ -172,11 +172,11 @@ public class BaseController { * @param totalList success object list * @param currentPage current page * @param total total - * @param totalPage total page + * @param totalPage total page * @return success result code */ public Result success(Object totalList, Integer currentPage, - Integer total, Integer totalPage) { + Integer total, Integer totalPage) { Result result = new Result(); result.setCode(Status.SUCCESS.getCode()); result.setMsg(Status.SUCCESS.getMsg()); @@ -240,6 +240,7 @@ public class BaseController { /** * get result + * * @param msg message * @param list object list * @return result code diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java index d41fbe1454..326c7f44b4 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java @@ -63,15 +63,15 @@ public class DataAnalysisController extends BaseController { * * @param loginUser login user * @param startDate count start date - * @param endDate count end date - * @param projectId project id + * @param endDate count end date + * @param projectCode project code * @return task instance count data */ @ApiOperation(value = "countTaskState", notes = "COUNT_TASK_STATE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "startDate", value = "START_DATE", dataType = "String"), - @ApiImplicitParam(name = "endDate", value = "END_DATE", dataType = "String"), - @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100") + @ApiImplicitParam(name = "startDate", value = "START_DATE", dataType = "String"), + @ApiImplicitParam(name = "endDate", value = "END_DATE", dataType = "String"), + @ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE", dataType = "Long", example = "100") }) @GetMapping(value = "/task-state-count") @ResponseStatus(HttpStatus.OK) @@ -80,9 +80,9 @@ public class DataAnalysisController extends BaseController { public Result countTaskState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "startDate", required = false) String startDate, @RequestParam(value = "endDate", required = false) String endDate, - @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) { + @RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) { - Map result = dataAnalysisService.countTaskStateByProject(loginUser, projectId, startDate, endDate); + Map result = dataAnalysisService.countTaskStateByProject(loginUser, projectCode, startDate, endDate); return returnDataList(result); } @@ -91,15 +91,15 @@ public class DataAnalysisController extends BaseController { * * @param loginUser login user * @param startDate start date - * @param endDate end date - * @param projectId project id + * @param endDate end date + * @param projectCode project code * @return process instance data */ @ApiOperation(value = "countProcessInstanceState", notes = "COUNT_PROCESS_INSTANCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "startDate", value = "START_DATE", dataType = "String"), - @ApiImplicitParam(name = "endDate", value = "END_DATE", dataType = "String"), - @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100") + @ApiImplicitParam(name = "startDate", value = "START_DATE", dataType = "String"), + @ApiImplicitParam(name = "endDate", value = "END_DATE", dataType = "String"), + @ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE", dataType = "Long", example = "100") }) @GetMapping(value = "/process-state-count") @ResponseStatus(HttpStatus.OK) @@ -108,9 +108,9 @@ public class DataAnalysisController extends BaseController { public Result countProcessInstanceState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "startDate", required = false) String startDate, @RequestParam(value = "endDate", required = false) String endDate, - @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) { + @RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) { - Map result = dataAnalysisService.countProcessInstanceStateByProject(loginUser, projectId, startDate, endDate); + Map result = dataAnalysisService.countProcessInstanceStateByProject(loginUser, projectCode, startDate, endDate); return returnDataList(result); } @@ -118,50 +118,38 @@ public class DataAnalysisController extends BaseController { * statistics the process definition quantities of certain person * * @param loginUser login user - * @param projectId project id - * @return definition count in project id + * @param projectCode project code + * @return definition count in project code */ @ApiOperation(value = "countDefinitionByUser", notes = "COUNT_PROCESS_DEFINITION_BY_USER_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100") + @ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE", dataType = "Long", example = "100") }) @GetMapping(value = "/define-user-count") @ResponseStatus(HttpStatus.OK) @ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result countDefinitionByUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) { + @RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) { - Map result = dataAnalysisService.countDefinitionByUser(loginUser, projectId); + Map result = dataAnalysisService.countDefinitionByUser(loginUser, projectCode); return returnDataList(result); } - /** * statistical command status data * * @param loginUser login user - * @param startDate start date - * @param endDate end date - * @param projectId project id - * @return command state in project id + * @return command state of user projects */ @ApiOperation(value = "countCommandState", notes = "COUNT_COMMAND_STATE_NOTES") - @ApiImplicitParams({ - @ApiImplicitParam(name = "startDate", value = "START_DATE", dataType = "String"), - @ApiImplicitParam(name = "endDate", value = "END_DATE", dataType = "String"), - @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100") - }) @GetMapping(value = "/command-state-count") @ResponseStatus(HttpStatus.OK) @ApiException(COMMAND_STATE_COUNT_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") - public Result countCommandState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "startDate", required = false) String startDate, - @RequestParam(value = "endDate", required = false) String endDate, - @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) { + public Result countCommandState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - Map result = dataAnalysisService.countCommandState(loginUser, projectId, startDate, endDate); + Map result = dataAnalysisService.countCommandState(loginUser); return returnDataList(result); } @@ -169,21 +157,16 @@ public class DataAnalysisController extends BaseController { * queue count * * @param loginUser login user - * @param projectId project id * @return queue state count */ @ApiOperation(value = "countQueueState", notes = "COUNT_QUEUE_STATE_NOTES") - @ApiImplicitParams({ - @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100") - }) @GetMapping(value = "/queue-count") @ResponseStatus(HttpStatus.OK) @ApiException(QUEUE_COUNT_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") - public Result countQueueState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) { + public Result countQueueState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - Map result = dataAnalysisService.countQueueState(loginUser, projectId); + Map result = dataAnalysisService.countQueueState(loginUser); return returnDataList(result); } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataSourceController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataSourceController.java index e4c3a590a9..041af44434 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataSourceController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataSourceController.java @@ -46,8 +46,11 @@ import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -81,7 +84,7 @@ public class DataSourceController extends BaseController { * @return create result code */ @ApiOperation(value = "createDataSource", notes = "CREATE_DATA_SOURCE_NOTES") - @PostMapping(value = "/create") + @PostMapping() @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_DATASOURCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -96,19 +99,23 @@ public class DataSourceController extends BaseController { * updateProcessInstance data source * * @param loginUser login user + * @param id datasource id * @param dataSourceParam datasource param * @return update result code */ @ApiOperation(value = "updateDataSource", notes = "UPDATE_DATA_SOURCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "dataSourceParam", value = "DATA_SOURCE_PARAM", required = true, dataType = "BaseDataSourceParamDTO"), + @ApiImplicitParam(name = "id", value = "DATA_SOURCE_ID", required = true, dataType = "Integer"), + @ApiImplicitParam(name = "dataSourceParam", value = "DATA_SOURCE_PARAM", required = true, dataType = "BaseDataSourceParamDTO") }) - @PostMapping(value = "/update") + @PutMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_DATASOURCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @PathVariable(value = "id") Integer id, @RequestBody BaseDataSourceParamDTO dataSourceParam) { + dataSourceParam.setId(id); return dataSourceService.updateDataSource(dataSourceParam.getId(), loginUser, dataSourceParam); } @@ -116,20 +123,20 @@ public class DataSourceController extends BaseController { * query data source detail * * @param loginUser login user - * @param id datasource id + * @param id datasource id * @return data source detail */ @ApiOperation(value = "queryDataSource", notes = "QUERY_DATA_SOURCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "DATA_SOURCE_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "id", value = "DATA_SOURCE_ID", required = true, dataType = "Int", example = "100") }) - @PostMapping(value = "/update-ui") + @GetMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_DATASOURCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("id") int id) { + @PathVariable("id") int id) { Map result = dataSourceService.queryDataSource(id); return returnDataList(result); @@ -139,12 +146,12 @@ public class DataSourceController extends BaseController { * query datasource by type * * @param loginUser login user - * @param type data source type + * @param type data source type * @return data source list page */ @ApiOperation(value = "queryDataSourceList", notes = "QUERY_DATA_SOURCE_LIST_BY_TYPE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "type", value = "DB_TYPE", required = true, dataType = "DbType") + @ApiImplicitParam(name = "type", value = "DB_TYPE", required = true, dataType = "DbType") }) @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) @@ -161,17 +168,17 @@ public class DataSourceController extends BaseController { * * @param loginUser login user * @param searchVal search value - * @param pageNo page number - * @param pageSize page size + * @param pageNo page number + * @param pageSize page size * @return data source list page */ @ApiOperation(value = "queryDataSourceListPaging", notes = "QUERY_DATA_SOURCE_LIST_PAGING_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), - @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") }) - @GetMapping(value = "/list-paging") + @GetMapping() @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_DATASOURCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -191,12 +198,12 @@ public class DataSourceController extends BaseController { * connect datasource * * @param loginUser login user - * @param dataSourceParam datasource param + * @param dataSourceParam datasource param * @return connect result code */ @ApiOperation(value = "connectDataSource", notes = "CONNECT_DATA_SOURCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "dataSourceParam", value = "DATA_SOURCE_PARAM", required = true, dataType = "BaseDataSourceParamDTO"), + @ApiImplicitParam(name = "dataSourceParam", value = "DATA_SOURCE_PARAM", required = true, dataType = "BaseDataSourceParamDTO") }) @PostMapping(value = "/connect") @ResponseStatus(HttpStatus.OK) @@ -213,19 +220,19 @@ public class DataSourceController extends BaseController { * connection test * * @param loginUser login user - * @param id data source id + * @param id data source id * @return connect result code */ @ApiOperation(value = "connectionTest", notes = "CONNECT_DATA_SOURCE_TEST_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "DATA_SOURCE_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "id", value = "DATA_SOURCE_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/connect-by-id") + @GetMapping(value = "/{id}/connect-test") @ResponseStatus(HttpStatus.OK) @ApiException(CONNECTION_TEST_FAILURE) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result connectionTest(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("id") int id) { + @PathVariable("id") int id) { return dataSourceService.connectionTest(id); } @@ -233,19 +240,19 @@ public class DataSourceController extends BaseController { * delete datasource by id * * @param loginUser login user - * @param id datasource id + * @param id datasource id * @return delete result */ @ApiOperation(value = "deleteDataSource", notes = "DELETE_DATA_SOURCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "DATA_SOURCE_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "id", value = "DATA_SOURCE_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/delete") + @DeleteMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_DATA_SOURCE_FAILURE) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result delete(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("id") int id) { + @PathVariable("id") int id) { return dataSourceService.delete(loginUser, id); } @@ -253,12 +260,12 @@ public class DataSourceController extends BaseController { * verify datasource name * * @param loginUser login user - * @param name data source name + * @param name data source name * @return true if data source name not exists.otherwise return false */ @ApiOperation(value = "verifyDataSourceName", notes = "VERIFY_DATA_SOURCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "name", value = "DATA_SOURCE_NAME", required = true, dataType = "String") + @ApiImplicitParam(name = "name", value = "DATA_SOURCE_NAME", required = true, dataType = "String") }) @GetMapping(value = "/verify-name") @ResponseStatus(HttpStatus.OK) @@ -275,14 +282,14 @@ public class DataSourceController extends BaseController { * unauthorized datasource * * @param loginUser login user - * @param userId user id + * @param userId user id * @return unauthed data source result code */ @ApiOperation(value = "unauthDatasource", notes = "UNAUTHORIZED_DATA_SOURCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/unauth-datasource") + @GetMapping(value = "/unauth") @ResponseStatus(HttpStatus.OK) @ApiException(UNAUTHORIZED_DATASOURCE) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -298,14 +305,14 @@ public class DataSourceController extends BaseController { * authorized datasource * * @param loginUser login user - * @param userId user id + * @param userId user id * @return authorized result code */ @ApiOperation(value = "authedDatasource", notes = "AUTHORIZED_DATA_SOURCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/authed-datasource") + @GetMapping(value = "/authed") @ResponseStatus(HttpStatus.OK) @ApiException(AUTHORIZED_DATA_SOURCE) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java index e6159369e3..93a31f2e8c 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java @@ -60,7 +60,7 @@ import springfox.documentation.annotations.ApiIgnore; */ @Api(tags = "EXECUTOR_TAG") @RestController -@RequestMapping("projects/{projectName}/executors") +@RequestMapping("projects/{projectCode}/executors") public class ExecutorController extends BaseController { @Autowired @@ -70,8 +70,8 @@ public class ExecutorController extends BaseController { * execute process instance * * @param loginUser login user - * @param projectName project name - * @param processDefinitionId process definition id + * @param projectCode project code + * @param processDefinitionCode process definition code * @param scheduleTime schedule time * @param failureStrategy failure strategy * @param startNodeList start nodes list @@ -88,7 +88,7 @@ public class ExecutorController extends BaseController { */ @ApiOperation(value = "startProcessInstance", notes = "RUN_PROCESS_INSTANCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "processDefinitionCode", value = "PROCESS_DEFINITION_CODE", required = true, dataType = "Long", example = "100"), @ApiImplicitParam(name = "scheduleTime", value = "SCHEDULE_TIME", required = true, dataType = "String"), @ApiImplicitParam(name = "failureStrategy", value = "FAILURE_STRATEGY", required = true, dataType = "FailureStrategy"), @ApiImplicitParam(name = "startNodeList", value = "START_NODE_LIST", dataType = "String"), @@ -108,8 +108,8 @@ public class ExecutorController extends BaseController { @ApiException(START_PROCESS_INSTANCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result startProcessInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam(value = "processDefinitionId") int processDefinitionId, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @RequestParam(value = "processDefinitionCode") long processDefinitionCode, @RequestParam(value = "scheduleTime", required = false) String scheduleTime, @RequestParam(value = "failureStrategy", required = true) FailureStrategy failureStrategy, @RequestParam(value = "startNodeList", required = false) String startNodeList, @@ -123,8 +123,7 @@ public class ExecutorController extends BaseController { @RequestParam(value = "environmentCode", required = false, defaultValue = "-1") Long environmentCode, @RequestParam(value = "timeout", required = false) Integer timeout, @RequestParam(value = "startParams", required = false) String startParams, - @RequestParam(value = "expectedParallelismNumber", required = false) Integer expectedParallelismNumber - ) { + @RequestParam(value = "expectedParallelismNumber", required = false) Integer expectedParallelismNumber) { if (timeout == null) { timeout = Constants.MAX_TASK_TIMEOUT; @@ -133,18 +132,16 @@ public class ExecutorController extends BaseController { if (startParams != null) { startParamMap = JSONUtils.toMap(startParams); } - Map result = execService.execProcessInstance(loginUser, projectName, processDefinitionId, scheduleTime, execType, failureStrategy, - startNodeList, taskDependType, warningType, - warningGroupId, runMode, processInstancePriority, workerGroup, environmentCode, timeout, startParamMap, expectedParallelismNumber); + Map result = execService.execProcessInstance(loginUser, projectCode, processDefinitionCode, scheduleTime, execType, failureStrategy, + startNodeList, taskDependType, warningType, warningGroupId, runMode, processInstancePriority, workerGroup, environmentCode,timeout, startParamMap, expectedParallelismNumber); return returnDataList(result); } - /** * do action to process instance:pause, stop, repeat, recover from pause, recover from stop * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param processInstanceId process instance id * @param executeType execute type * @return execute result code @@ -159,32 +156,30 @@ public class ExecutorController extends BaseController { @ApiException(EXECUTE_PROCESS_INSTANCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result execute(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, @RequestParam("processInstanceId") Integer processInstanceId, @RequestParam("executeType") ExecuteType executeType ) { - Map result = execService.execute(loginUser, projectName, processInstanceId, executeType); + Map result = execService.execute(loginUser, projectCode, processInstanceId, executeType); return returnDataList(result); } /** * check process definition and all of the son process definitions is on line. * - * @param loginUser login user - * @param processDefinitionId process definition id + * @param processDefinitionCode process definition code * @return check result code */ @ApiOperation(value = "startCheckProcessDefinition", notes = "START_CHECK_PROCESS_DEFINITION_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "processDefinitionCode", value = "PROCESS_DEFINITION_CODE", required = true, dataType = "Long", example = "100") }) @PostMapping(value = "/start-check") @ResponseStatus(HttpStatus.OK) @ApiException(CHECK_PROCESS_DEFINITION_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") - public Result startCheckProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "processDefinitionId") int processDefinitionId) { - Map result = execService.startCheckByProcessDefinedId(processDefinitionId); + public Result startCheckProcessDefinition(@RequestParam(value = "processDefinitionCode") long processDefinitionCode) { + Map result = execService.startCheckByProcessDefinedCode(processDefinitionCode); return returnDataList(result); } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoggerController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoggerController.java index 4990d34d6f..3800264f6b 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoggerController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoggerController.java @@ -59,26 +59,26 @@ public class LoggerController extends BaseController { /** * query task log * - * @param loginUser login user + * @param loginUser login user * @param taskInstanceId task instance id - * @param skipNum skip number - * @param limit limit + * @param skipNum skip number + * @param limit limit * @return task log content */ @ApiOperation(value = "queryLog", notes = "QUERY_TASK_INSTANCE_LOG_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "taskInstanceId", value = "TASK_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "skipLineNum", value = "SKIP_LINE_NUM", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "limit", value = "LIMIT", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "taskInstanceId", value = "TASK_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "skipLineNum", value = "SKIP_LINE_NUM", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "limit", value = "LIMIT", required = true, dataType = "Int", example = "100") }) @GetMapping(value = "/detail") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_TASK_INSTANCE_LOG_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryLog(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "taskInstanceId") int taskInstanceId, - @RequestParam(value = "skipLineNum") int skipNum, - @RequestParam(value = "limit") int limit) { + @RequestParam(value = "taskInstanceId") int taskInstanceId, + @RequestParam(value = "skipLineNum") int skipNum, + @RequestParam(value = "limit") int limit) { return loggerService.queryLog(taskInstanceId, skipNum, limit); } @@ -86,13 +86,13 @@ public class LoggerController extends BaseController { /** * download log file * - * @param loginUser login user + * @param loginUser login user * @param taskInstanceId task instance id * @return log file content */ @ApiOperation(value = "downloadTaskLog", notes = "DOWNLOAD_TASK_INSTANCE_LOG_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "taskInstanceId", value = "TASK_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "taskInstanceId", value = "TASK_ID", required = true, dataType = "Int", example = "100") }) @GetMapping(value = "/download-log") @ResponseBody @@ -102,9 +102,9 @@ public class LoggerController extends BaseController { @RequestParam(value = "taskInstanceId") int taskInstanceId) { byte[] logBytes = loggerService.getLogBytes(taskInstanceId); return ResponseEntity - .ok() - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + System.currentTimeMillis() + ".log" + "\"") - .body(logBytes); + .ok() + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + System.currentTimeMillis() + ".log" + "\"") + .body(logBytes); } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoginController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoginController.java index c513ae8573..1527408e7b 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoginController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/LoginController.java @@ -70,16 +70,16 @@ public class LoginController extends BaseController { /** * login * - * @param userName user name + * @param userName user name * @param userPassword user password - * @param request request - * @param response response + * @param request request + * @param response response * @return login result */ @ApiOperation(value = "login", notes = "LOGIN_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userName", value = "USER_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", required = true, dataType = "String") + @ApiImplicitParam(name = "userName", value = "USER_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", required = true, dataType = "String") }) @PostMapping(value = "/login") @ApiException(USER_LOGIN_FAILURE) @@ -91,7 +91,7 @@ public class LoginController extends BaseController { //user name check if (StringUtils.isEmpty(userName)) { return error(Status.USER_NAME_NULL.getCode(), - Status.USER_NAME_NULL.getMsg()); + Status.USER_NAME_NULL.getMsg()); } // user ip check @@ -102,7 +102,7 @@ public class LoginController extends BaseController { // verify username and password Result> result = authenticator.authenticate(userName, userPassword, ip); - if (result.isFailed()) { + if (result.getCode() != Status.SUCCESS.getCode()) { return result; } @@ -121,7 +121,7 @@ public class LoginController extends BaseController { * sign out * * @param loginUser login user - * @param request request + * @param request request * @return sign out result */ @ApiOperation(value = "signOut", notes = "SIGNOUT_NOTES") diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/MonitorController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/MonitorController.java index 92c9858fb1..92a9ffa5ad 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/MonitorController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/MonitorController.java @@ -61,7 +61,7 @@ public class MonitorController extends BaseController { * @return master list */ @ApiOperation(value = "listMaster", notes = "MASTER_LIST_NOTES") - @GetMapping(value = "/master/list") + @GetMapping(value = "/masters") @ResponseStatus(HttpStatus.OK) @ApiException(LIST_MASTERS_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -77,7 +77,7 @@ public class MonitorController extends BaseController { * @return worker information list */ @ApiOperation(value = "listWorker", notes = "WORKER_LIST_NOTES") - @GetMapping(value = "/worker/list") + @GetMapping(value = "/workers") @ResponseStatus(HttpStatus.OK) @ApiException(LIST_WORKERS_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -93,7 +93,7 @@ public class MonitorController extends BaseController { * @return data base state */ @ApiOperation(value = "queryDatabaseState", notes = "QUERY_DATABASE_STATE_NOTES") - @GetMapping(value = "/database") + @GetMapping(value = "/databases") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_DATABASE_STATE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -109,7 +109,7 @@ public class MonitorController extends BaseController { * @return zookeeper information list */ @ApiOperation(value = "queryZookeeperState", notes = "QUERY_ZOOKEEPER_STATE_NOTES") - @GetMapping(value = "/zookeeper/list") + @GetMapping(value = "/zookeepers") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_ZOOKEEPER_STATE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java index c948665c33..9a0c63ca7d 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java @@ -18,13 +18,14 @@ package org.apache.dolphinscheduler.api.controller; import static org.apache.dolphinscheduler.api.enums.Status.BATCH_COPY_PROCESS_DEFINITION_ERROR; -import static org.apache.dolphinscheduler.api.enums.Status.BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.BATCH_DELETE_PROCESS_DEFINE_BY_CODES_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.BATCH_MOVE_PROCESS_DEFINITION_ERROR; -import static org.apache.dolphinscheduler.api.enums.Status.CREATE_PROCESS_DEFINITION; -import static org.apache.dolphinscheduler.api.enums.Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.CREATE_PROCESS_DEFINITION_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.DELETE_PROCESS_DEFINE_BY_CODE_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.DELETE_PROCESS_DEFINITION_VERSION_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.ENCAPSULATION_TREEVIEW_STRUCTURE_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.IMPORT_PROCESS_DEFINE_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PROCESS_DEFINITION_LIST; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PROCESS_DEFINITION_LIST_PAGING_ERROR; @@ -57,17 +58,18 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; 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.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; - -import com.fasterxml.jackson.core.JsonProcessingException; +import org.springframework.web.multipart.MultipartFile; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -81,7 +83,7 @@ import springfox.documentation.annotations.ApiIgnore; */ @Api(tags = "PROCESS_DEFINITION_TAG") @RestController -@RequestMapping("projects/{projectName}/process") +@RequestMapping("projects/{projectCode}/process-definition") public class ProcessDefinitionController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(ProcessDefinitionController.class); @@ -93,36 +95,39 @@ public class ProcessDefinitionController extends BaseController { * create process definition * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param name process definition name - * @param json process definition json * @param description description + * @param globalParams globalParams * @param locations locations for nodes - * @param connects connects for nodes + * @param timeout timeout + * @param tenantCode tenantCode + * @param taskRelationJson relation json for nodes + * @param taskDefinitionJson taskDefinitionJson * @return create result code */ @ApiOperation(value = "createProcessDefinition", notes = "CREATE_PROCESS_DEFINITION_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "name", value = "PROCESS_DEFINITION_NAME", required = true, type = "String"), - @ApiImplicitParam(name = "processDefinitionJson", value = "PROCESS_DEFINITION_JSON", required = true, type = "String"), - @ApiImplicitParam(name = "locations", value = "PROCESS_DEFINITION_LOCATIONS", required = true, type = "String"), - @ApiImplicitParam(name = "connects", value = "PROCESS_DEFINITION_CONNECTS", required = true, type = "String"), - @ApiImplicitParam(name = "description", value = "PROCESS_DEFINITION_DESC", required = false, type = "String"), + @ApiImplicitParam(name = "name", value = "PROCESS_DEFINITION_NAME", required = true, type = "String"), + @ApiImplicitParam(name = "locations", value = "PROCESS_DEFINITION_LOCATIONS", required = true, type = "String"), + @ApiImplicitParam(name = "description", value = "PROCESS_DEFINITION_DESC", required = false, type = "String") }) - @PostMapping(value = "/save") + @PostMapping() @ResponseStatus(HttpStatus.CREATED) - @ApiException(CREATE_PROCESS_DEFINITION) + @ApiException(CREATE_PROCESS_DEFINITION_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result createProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, @RequestParam(value = "name", required = true) String name, - @RequestParam(value = "processDefinitionJson", required = true) String json, - @RequestParam(value = "locations", required = true) String locations, - @RequestParam(value = "connects", required = true) String connects, - @RequestParam(value = "description", required = false) String description) throws JsonProcessingException { - - Map result = processDefinitionService.createProcessDefinition(loginUser, projectName, name, json, - description, locations, connects); + @RequestParam(value = "description", required = false) String description, + @RequestParam(value = "globalParams", required = false, defaultValue = "[]") String globalParams, + @RequestParam(value = "locations", required = false) String locations, + @RequestParam(value = "timeout", required = false, defaultValue = "0") int timeout, + @RequestParam(value = "tenantCode", required = true) String tenantCode, + @RequestParam(value = "taskRelationJson", required = true) String taskRelationJson, + @RequestParam(value = "taskDefinitionJson", required = true) String taskDefinitionJson) { + Map result = processDefinitionService.createProcessDefinition(loginUser, projectCode, name, description, globalParams, + locations, timeout, tenantCode, taskRelationJson, taskDefinitionJson); return returnDataList(result); } @@ -130,74 +135,72 @@ public class ProcessDefinitionController extends BaseController { * copy process definition * * @param loginUser login user - * @param projectName project name - * @param processDefinitionIds process definition ids - * @param targetProjectId target project id + * @param projectCode project code + * @param codes process definition codes + * @param targetProjectCode target project code * @return copy result code */ - @ApiOperation(value = "copyProcessDefinition", notes = "COPY_PROCESS_DEFINITION_NOTES") + @ApiOperation(value = "batchCopyByCodes", notes = "COPY_PROCESS_DEFINITION_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processDefinitionIds", value = "PROCESS_DEFINITION_IDS", required = true, dataType = "String", example = "3,4"), - @ApiImplicitParam(name = "targetProjectId", value = "TARGET_PROJECT_ID", required = true, dataType = "Int", example = "10") + @ApiImplicitParam(name = "codes", value = "PROCESS_DEFINITION_CODES", required = true, dataType = "String", example = "3,4"), + @ApiImplicitParam(name = "targetProjectCode", value = "TARGET_PROJECT_CODE", required = true, dataType = "Long", example = "123") }) - @PostMapping(value = "/copy") + @PostMapping(value = "/batch-copy") @ResponseStatus(HttpStatus.OK) @ApiException(BATCH_COPY_PROCESS_DEFINITION_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result copyProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam(value = "processDefinitionIds", required = true) String processDefinitionIds, - @RequestParam(value = "targetProjectId", required = true) int targetProjectId) { - return returnDataList( - processDefinitionService.batchCopyProcessDefinition(loginUser, projectName, processDefinitionIds, targetProjectId)); + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @RequestParam(value = "codes", required = true) String codes, + @RequestParam(value = "targetProjectCode", required = true) long targetProjectCode) { + return returnDataList(processDefinitionService.batchCopyProcessDefinition(loginUser, projectCode, codes, targetProjectCode)); } /** * move process definition * * @param loginUser login user - * @param projectName project name - * @param processDefinitionIds process definition ids - * @param targetProjectId target project id + * @param projectCode project code + * @param codes process definition codes + * @param targetProjectCode target project code * @return move result code */ - @ApiOperation(value = "moveProcessDefinition", notes = "MOVE_PROCESS_DEFINITION_NOTES") + @ApiOperation(value = "batchMoveByCodes", notes = "MOVE_PROCESS_DEFINITION_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processDefinitionIds", value = "PROCESS_DEFINITION_IDS", required = true, dataType = "String", example = "3,4"), - @ApiImplicitParam(name = "targetProjectId", value = "TARGET_PROJECT_ID", required = true, dataType = "Int", example = "10") + @ApiImplicitParam(name = "codes", value = "PROCESS_DEFINITION_CODES", required = true, dataType = "String", example = "3,4"), + @ApiImplicitParam(name = "targetProjectCode", value = "TARGET_PROJECT_CODE", required = true, dataType = "Long", example = "123") }) - @PostMapping(value = "/move") + @PostMapping(value = "/batch-move") @ResponseStatus(HttpStatus.OK) @ApiException(BATCH_MOVE_PROCESS_DEFINITION_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result moveProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam(value = "processDefinitionIds", required = true) String processDefinitionIds, - @RequestParam(value = "targetProjectId", required = true) int targetProjectId) { - return returnDataList( - processDefinitionService.batchMoveProcessDefinition(loginUser, projectName, processDefinitionIds, targetProjectId)); + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @RequestParam(value = "codes", required = true) String codes, + @RequestParam(value = "targetProjectCode", required = true) long targetProjectCode) { + return returnDataList(processDefinitionService.batchMoveProcessDefinition(loginUser, projectCode, codes, targetProjectCode)); } /** * verify process definition name unique * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param name name * @return true if process definition name not exists, otherwise false */ @ApiOperation(value = "verify-name", notes = "VERIFY_PROCESS_DEFINITION_NAME_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "name", value = "PROCESS_DEFINITION_NAME", required = true, type = "String") + @ApiImplicitParam(name = "name", value = "PROCESS_DEFINITION_NAME", required = true, type = "String") }) @GetMapping(value = "/verify-name") @ResponseStatus(HttpStatus.OK) @ApiException(VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result verifyProcessDefinitionName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, @RequestParam(value = "name", required = true) String name) { - Map result = processDefinitionService.verifyProcessDefinitionName(loginUser, projectName, name); + Map result = processDefinitionService.verifyProcessDefinitionName(loginUser, projectCode, name); return returnDataList(result); } @@ -205,42 +208,45 @@ public class ProcessDefinitionController extends BaseController { * update process definition * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param name process definition name - * @param id process definition id - * @param processDefinitionJson process definition json + * @param code process definition code * @param description description + * @param globalParams globalParams * @param locations locations for nodes - * @param connects connects for nodes + * @param timeout timeout + * @param tenantCode tenantCode + * @param taskRelationJson relation json for nodes + * @param taskDefinitionJson taskDefinitionJson * @return update result code */ - - @ApiOperation(value = "updateProcessDefinition", notes = "UPDATE_PROCESS_DEFINITION_NOTES") + @ApiOperation(value = "update", notes = "UPDATE_PROCESS_DEFINITION_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "name", value = "PROCESS_DEFINITION_NAME", required = true, type = "String"), - @ApiImplicitParam(name = "id", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "processDefinitionJson", value = "PROCESS_DEFINITION_JSON", required = true, type = "String"), - @ApiImplicitParam(name = "locations", value = "PROCESS_DEFINITION_LOCATIONS", required = true, type = "String"), - @ApiImplicitParam(name = "connects", value = "PROCESS_DEFINITION_CONNECTS", required = true, type = "String"), - @ApiImplicitParam(name = "description", value = "PROCESS_DEFINITION_DESC", required = false, type = "String"), - @ApiImplicitParam(name = "releaseState", value = "RELEASE_PROCESS_DEFINITION_NOTES", required = false, dataType = "ReleaseState") + @ApiImplicitParam(name = "name", value = "PROCESS_DEFINITION_NAME", required = true, type = "String"), + @ApiImplicitParam(name = "code", value = "PROCESS_DEFINITION_CODE", required = true, dataType = "Long", example = "123456789"), + @ApiImplicitParam(name = "locations", value = "PROCESS_DEFINITION_LOCATIONS", required = true, type = "String"), + @ApiImplicitParam(name = "description", value = "PROCESS_DEFINITION_DESC", required = false, type = "String"), + @ApiImplicitParam(name = "releaseState", value = "RELEASE_PROCESS_DEFINITION_NOTES", required = false, dataType = "ReleaseState") }) - @PostMapping(value = "/update") + @PutMapping(value = "/{code}") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_PROCESS_DEFINITION_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, @RequestParam(value = "name", required = true) String name, - @RequestParam(value = "id", required = true) int id, - @RequestParam(value = "processDefinitionJson", required = true) String processDefinitionJson, - @RequestParam(value = "locations", required = false) String locations, - @RequestParam(value = "connects", required = false) String connects, + @PathVariable(value = "code", required = true) long code, @RequestParam(value = "description", required = false) String description, + @RequestParam(value = "globalParams", required = false, defaultValue = "[]") String globalParams, + @RequestParam(value = "locations", required = false) String locations, + @RequestParam(value = "timeout", required = false, defaultValue = "0") int timeout, + @RequestParam(value = "tenantCode", required = true) String tenantCode, + @RequestParam(value = "taskRelationJson", required = true) String taskRelationJson, + @RequestParam(value = "taskDefinitionJson", required = true) String taskDefinitionJson, @RequestParam(value = "releaseState", required = false, defaultValue = "OFFLINE") ReleaseState releaseState) { - Map result = processDefinitionService.updateProcessDefinition(loginUser, projectName, id, name, - processDefinitionJson, description, locations, connects); + Map result = processDefinitionService.updateProcessDefinition(loginUser, projectCode, name, code, description, globalParams, + locations, timeout, tenantCode, taskRelationJson, taskDefinitionJson); // If the update fails, the result will be returned directly if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataList(result); @@ -248,7 +254,7 @@ public class ProcessDefinitionController extends BaseController { // Judge whether to go online after editing,0 means offline, 1 means online if (releaseState == ReleaseState.ONLINE) { - result = processDefinitionService.releaseProcessDefinition(loginUser, projectName, id, releaseState); + result = processDefinitionService.releaseProcessDefinition(loginUser, projectCode, code, releaseState); } return returnDataList(result); } @@ -257,33 +263,33 @@ public class ProcessDefinitionController extends BaseController { * query process definition version paging list info * * @param loginUser login user info - * @param projectName the process definition project name + * @param projectCode project code * @param pageNo the process definition version list current page number * @param pageSize the process definition version list page size - * @param processDefinitionCode the process definition code + * @param code the process definition code * @return the process definition version list */ - @ApiOperation(value = "queryProcessDefinitionVersions", notes = "QUERY_PROCESS_DEFINITION_VERSIONS_NOTES") + @ApiOperation(value = "queryVersions", notes = "QUERY_PROCESS_DEFINITION_VERSIONS_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "processDefinitionCode", value = "PROCESS_DEFINITION_CODE", required = true, dataType = "Long", example = "1") + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "10"), + @ApiImplicitParam(name = "code", value = "PROCESS_DEFINITION_CODE", required = true, dataType = "Long", example = "1") }) - @GetMapping(value = "/versions") + @GetMapping(value = "/{code}/versions") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PROCESS_DEFINITION_VERSIONS_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProcessDefinitionVersions(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, @RequestParam(value = "pageNo") int pageNo, @RequestParam(value = "pageSize") int pageSize, - @RequestParam(value = "processDefinitionCode") long processDefinitionCode) { + @PathVariable(value = "code") long code) { + Result result = checkPageParams(pageNo, pageSize); if (!result.checkResult()) { return result; } - result = processDefinitionService.queryProcessDefinitionVersions(loginUser - , projectName, pageNo, pageSize, processDefinitionCode); + result = processDefinitionService.queryProcessDefinitionVersions(loginUser, projectCode, pageNo, pageSize, code); return result; } @@ -292,52 +298,51 @@ public class ProcessDefinitionController extends BaseController { * switch certain process definition version * * @param loginUser login user info - * @param projectName the process definition project name - * @param processDefinitionId the process definition id + * @param projectCode project code + * @param code the process definition code * @param version the version user want to switch * @return switch version result code */ - @ApiOperation(value = "switchProcessDefinitionVersion", notes = "SWITCH_PROCESS_DEFINITION_VERSION_NOTES") + @ApiOperation(value = "switchVersion", notes = "SWITCH_PROCESS_DEFINITION_VERSION_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "version", value = "VERSION", required = true, dataType = "Long", example = "100") + @ApiImplicitParam(name = "code", value = "PROCESS_DEFINITION_CODE", required = true, dataType = "Long", example = "1"), + @ApiImplicitParam(name = "version", value = "VERSION", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/version/switch") + @GetMapping(value = "/{code}/versions/{version}") @ResponseStatus(HttpStatus.OK) @ApiException(SWITCH_PROCESS_DEFINITION_VERSION_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result switchProcessDefinitionVersion(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam(value = "processDefinitionId") int processDefinitionId, - @RequestParam(value = "version") long version) { - Map result = processDefinitionService.switchProcessDefinitionVersion(loginUser, projectName - , processDefinitionId, version); + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable(value = "code") long code, + @PathVariable(value = "version") int version) { + Map result = processDefinitionService.switchProcessDefinitionVersion(loginUser, projectCode, code, version); return returnDataList(result); } /** - * delete the certain process definition version by version and process definition id + * delete the certain process definition version by version and process definition code * * @param loginUser login user info - * @param projectName the process definition project name - * @param processDefinitionId process definition id + * @param projectCode project code + * @param code the process definition code * @param version the process definition version user want to delete * @return delete version result code */ - @ApiOperation(value = "deleteProcessDefinitionVersion", notes = "DELETE_PROCESS_DEFINITION_VERSION_NOTES") + @ApiOperation(value = "deleteVersion", notes = "DELETE_PROCESS_DEFINITION_VERSION_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "version", value = "VERSION", required = true, dataType = "Long", example = "100") + @ApiImplicitParam(name = "code", value = "PROCESS_DEFINITION_CODE", required = true, dataType = "Long", example = "1"), + @ApiImplicitParam(name = "version", value = "VERSION", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/version/delete") + @DeleteMapping(value = "/{code}/versions/{version}") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_PROCESS_DEFINITION_VERSION_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteProcessDefinitionVersion(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam(value = "processDefinitionId") int processDefinitionId, - @RequestParam(value = "version") long version) { - Map result = processDefinitionService.deleteByProcessDefinitionIdAndVersion(loginUser, projectName, processDefinitionId, version); + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable(value = "code") long code, + @PathVariable(value = "version") int version) { + Map result = processDefinitionService.deleteProcessDefinitionVersion(loginUser, projectCode, code, version); return returnDataList(result); } @@ -345,51 +350,49 @@ public class ProcessDefinitionController extends BaseController { * release process definition * * @param loginUser login user - * @param projectName project name - * @param processId process definition id + * @param projectCode project code + * @param code process definition code * @param releaseState release state * @return release result code */ - @ApiOperation(value = "releaseProcessDefinition", notes = "RELEASE_PROCESS_DEFINITION_NOTES") + @ApiOperation(value = "release", notes = "RELEASE_PROCESS_DEFINITION_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "name", value = "PROCESS_DEFINITION_NAME", required = true, type = "String"), - @ApiImplicitParam(name = "processId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "releaseState", value = "PROCESS_DEFINITION_CONNECTS", required = true, dataType = "ReleaseState"), + @ApiImplicitParam(name = "name", value = "PROCESS_DEFINITION_NAME", required = true, type = "String"), + @ApiImplicitParam(name = "code", value = "PROCESS_DEFINITION_CODE", required = true, dataType = "Long", example = "123456789"), + @ApiImplicitParam(name = "releaseState", value = "PROCESS_DEFINITION_RELEASE", required = true, dataType = "ReleaseState"), }) - @PostMapping(value = "/release") + @PostMapping(value = "/{code}/release") @ResponseStatus(HttpStatus.OK) @ApiException(RELEASE_PROCESS_DEFINITION_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result releaseProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam(value = "processId", required = true) int processId, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable(value = "code", required = true) long code, @RequestParam(value = "releaseState", required = true) ReleaseState releaseState) { - - Map result = processDefinitionService.releaseProcessDefinition(loginUser, projectName, processId, releaseState); + Map result = processDefinitionService.releaseProcessDefinition(loginUser, projectCode, code, releaseState); return returnDataList(result); } /** - * query detail of process definition by id + * query detail of process definition by code * * @param loginUser login user - * @param projectName project name - * @param processId process definition id + * @param projectCode project code + * @param code process definition code * @return process definition detail */ - @ApiOperation(value = "queryProcessDefinitionById", notes = "QUERY_PROCESS_DEFINITION_BY_ID_NOTES") + @ApiOperation(value = "queryProcessDefinitionByCode", notes = "QUERY_PROCESS_DEFINITION_BY_CODE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "code", value = "PROCESS_DEFINITION_CODE", required = true, dataType = "Long", example = "123456789") }) - @GetMapping(value = "/select-by-id") + @GetMapping(value = "/{code}") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") - public Result queryProcessDefinitionById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("processId") Integer processId - ) { - Map result = processDefinitionService.queryProcessDefinitionById(loginUser, projectName, processId); + public Result queryProcessDefinitionByCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable(value = "code", required = true) long code) { + Map result = processDefinitionService.queryProcessDefinitionByCode(loginUser, projectCode, code); return returnDataList(result); } @@ -397,23 +400,22 @@ public class ProcessDefinitionController extends BaseController { * query detail of process definition by name * * @param loginUser login user - * @param projectName project name - * @param processDefinitionName process definition name + * @param projectCode project code + * @param name process definition name * @return process definition detail */ @ApiOperation(value = "queryProcessDefinitionByName", notes = "QUERY_PROCESS_DEFINITION_BY_NAME_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processDefinitionName", value = "PROCESS_DEFINITION_ID", required = true, dataType = "String") + @ApiImplicitParam(name = "name", value = "PROCESS_DEFINITION_NAME", required = true, dataType = "String") }) - @GetMapping(value = "/select-by-name") + @GetMapping(value = "/query-by-name") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProcessDefinitionByName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("processDefinitionName") String processDefinitionName - ) { - Map result = processDefinitionService.queryProcessDefinitionByName(loginUser, projectName, processDefinitionName); + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @RequestParam("name") String name) { + Map result = processDefinitionService.queryProcessDefinitionByName(loginUser, projectCode, name); return returnDataList(result); } @@ -421,18 +423,17 @@ public class ProcessDefinitionController extends BaseController { * query Process definition list * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @return process definition list */ - @ApiOperation(value = "queryProcessDefinitionList", notes = "QUERY_PROCESS_DEFINITION_LIST_NOTES") + @ApiOperation(value = "queryList", notes = "QUERY_PROCESS_DEFINITION_LIST_NOTES") @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PROCESS_DEFINITION_LIST) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProcessDefinitionList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName - ) { - Map result = processDefinitionService.queryProcessDefinitionList(loginUser, projectName); + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode) { + Map result = processDefinitionService.queryProcessDefinitionList(loginUser, projectCode); return returnDataList(result); } @@ -440,62 +441,62 @@ public class ProcessDefinitionController extends BaseController { * query process definition list paging * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param searchVal search value * @param pageNo page number * @param pageSize page size * @param userId user id * @return process definition page */ - @ApiOperation(value = "queryProcessDefinitionListPaging", notes = "QUERY_PROCESS_DEFINITION_LIST_PAGING_NOTES") + @ApiOperation(value = "queryListPaging", notes = "QUERY_PROCESS_DEFINITION_LIST_PAGING_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", required = false, type = "String"), - @ApiImplicitParam(name = "userId", value = "USER_ID", required = false, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", required = false, type = "String"), + @ApiImplicitParam(name = "userId", value = "USER_ID", required = false, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "10") }) - @GetMapping(value = "/list-paging") + @GetMapping() @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PROCESS_DEFINITION_LIST_PAGING_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProcessDefinitionListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("pageNo") Integer pageNo, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam(value = "userId", required = false, defaultValue = "0") Integer userId, + @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) { Result result = checkPageParams(pageNo, pageSize); if (!result.checkResult()) { return result; } searchVal = ParameterUtils.handleEscapes(searchVal); - return processDefinitionService.queryProcessDefinitionListPaging(loginUser, projectName, searchVal, pageNo, pageSize, userId); + return processDefinitionService.queryProcessDefinitionListPaging(loginUser, projectCode, searchVal, userId, pageNo, pageSize); } /** * encapsulation tree view structure * * @param loginUser login user - * @param projectName project name - * @param id process definition id + * @param projectCode project code + * @param code process definition code * @param limit limit * @return tree view json data */ @ApiOperation(value = "viewTree", notes = "VIEW_TREE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "limit", value = "LIMIT", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "code", value = "PROCESS_DEFINITION_CODE", required = true, dataType = "Long", example = "100"), + @ApiImplicitParam(name = "limit", value = "LIMIT", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/view-tree") + @GetMapping(value = "/{code}/view-tree") @ResponseStatus(HttpStatus.OK) @ApiException(ENCAPSULATION_TREEVIEW_STRUCTURE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result viewTree(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("processId") Integer id, - @RequestParam("limit") Integer limit) throws Exception { - Map result = processDefinitionService.viewTree(id, limit); + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable("code") long code, + @RequestParam("limit") Integer limit) { + Map result = processDefinitionService.viewTree(code, limit); return returnDataList(result); } @@ -503,167 +504,177 @@ public class ProcessDefinitionController extends BaseController { * get tasks list by process definition code * * @param loginUser login user - * @param projectName project name - * @param processDefinitionCode process definition code + * @param projectCode project code + * @param code process definition code * @return task list */ - @ApiOperation(value = "getNodeListByDefinitionCode", notes = "GET_NODE_LIST_BY_DEFINITION_CODE_NOTES") + @ApiOperation(value = "getTasksByDefinitionCode", notes = "GET_TASK_LIST_BY_DEFINITION_CODE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processDefinitionCode", value = "PROCESS_DEFINITION_CODE", required = true, dataType = "Long", example = "100") + @ApiImplicitParam(name = "code", value = "PROCESS_DEFINITION_CODE", required = true, dataType = "Long", example = "100") }) - @GetMapping(value = "gen-task-list") + @GetMapping(value = "/{code}/tasks") @ResponseStatus(HttpStatus.OK) @ApiException(GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR) - public Result getNodeListByDefinitionCode( - @ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("processDefinitionCode") Long processDefinitionCode) throws Exception { - logger.info("query task node name list by definitionCode, login user:{}, project name:{}, code : {}", - loginUser.getUserName(), projectName, processDefinitionCode); - Map result = processDefinitionService.getTaskNodeListByDefinitionCode(processDefinitionCode); + public Result getNodeListByDefinitionCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable("code") long code) { + Map result = processDefinitionService.getTaskNodeListByDefinitionCode(loginUser, projectCode, code); return returnDataList(result); } /** - * get tasks list by process definition code list + * get tasks list map by process definition multiple code * * @param loginUser login user - * @param projectName project name - * @param processDefinitionCodeList process definition code list + * @param projectCode project code + * @param codes process definition codes * @return node list data */ - @ApiOperation(value = "getNodeListByDefinitionCodeList", notes = "GET_NODE_LIST_BY_DEFINITION_CODE_NOTES") + @ApiOperation(value = "getTaskListByDefinitionCodes", notes = "GET_TASK_LIST_BY_DEFINITION_CODE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processDefinitionCodeList", value = "PROCESS_DEFINITION_CODE_LIST", required = true, type = "String") + @ApiImplicitParam(name = "processDefinitionCodes", value = "PROCESS_DEFINITION_CODES", required = true, type = "String", example = "100,200,300") }) - @GetMapping(value = "get-task-list") + @GetMapping(value = "/batch-query-tasks") @ResponseStatus(HttpStatus.OK) @ApiException(GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR) - public Result getNodeListByDefinitionCodeList( - @ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("processDefinitionCodeList") String processDefinitionCodeList) { - Map result = processDefinitionService.getTaskNodeListByDefinitionCodeList(processDefinitionCodeList); + public Result getNodeListMapByDefinitionCodes(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @RequestParam("codes") String codes) { + Map result = processDefinitionService.getNodeListMapByDefinitionCodes(loginUser, projectCode, codes); return returnDataList(result); } /** - * delete process definition by id + * delete process definition by code * * @param loginUser login user - * @param projectName project name - * @param processDefinitionId process definition id + * @param projectCode project code + * @param code process definition code * @return delete result code */ - @ApiOperation(value = "deleteProcessDefinitionById", notes = "DELETE_PROCESS_DEFINITION_BY_ID_NOTES") + @ApiOperation(value = "deleteByCode", notes = "DELETE_PROCESS_DEFINITION_BY_ID_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "code", value = "PROCESS_DEFINITION_CODE", dataType = "Int", example = "100") }) - @GetMapping(value = "/delete") + @DeleteMapping(value = "/{code}") @ResponseStatus(HttpStatus.OK) - @ApiException(DELETE_PROCESS_DEFINE_BY_ID_ERROR) + @ApiException(DELETE_PROCESS_DEFINE_BY_CODE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") - public Result deleteProcessDefinitionById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("processDefinitionId") Integer processDefinitionId - ) { - Map result = processDefinitionService.deleteProcessDefinitionById(loginUser, projectName, processDefinitionId); + public Result deleteProcessDefinitionByCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable("code") long code) { + Map result = processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, code); return returnDataList(result); } /** - * batch delete process definition by ids + * batch delete process definition by codes * * @param loginUser login user - * @param projectName project name - * @param processDefinitionIds process definition id list + * @param projectCode project code + * @param codes process definition code list * @return delete result code */ - @ApiOperation(value = "batchDeleteProcessDefinitionByIds", notes = "BATCH_DELETE_PROCESS_DEFINITION_BY_IDS_NOTES") + @ApiOperation(value = "batchDeleteByCodes", notes = "BATCH_DELETE_PROCESS_DEFINITION_BY_IDS_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processDefinitionIds", value = "PROCESS_DEFINITION_IDS", required = true, type = "String") + @ApiImplicitParam(name = "codes", value = "PROCESS_DEFINITION_CODE", required = true, dataType = "String") }) - @GetMapping(value = "/batch-delete") + @PostMapping(value = "/batch-delete") @ResponseStatus(HttpStatus.OK) - @ApiException(BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR) + @ApiException(BATCH_DELETE_PROCESS_DEFINE_BY_CODES_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") - public Result batchDeleteProcessDefinitionByIds(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("processDefinitionIds") String processDefinitionIds - ) { + public Result batchDeleteProcessDefinitionByCodes(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @RequestParam("codes") String codes) { Map result = new HashMap<>(); - List deleteFailedIdList = new ArrayList<>(); - if (StringUtils.isNotEmpty(processDefinitionIds)) { - String[] processDefinitionIdArray = processDefinitionIds.split(","); - for (String strProcessDefinitionId : processDefinitionIdArray) { - int processDefinitionId = Integer.parseInt(strProcessDefinitionId); + List deleteFailedCodeList = new ArrayList<>(); + if (StringUtils.isNotEmpty(codes)) { + String[] processDefinitionCodeArray = codes.split(","); + for (String strProcessDefinitionCode : processDefinitionCodeArray) { + long code = Long.parseLong(strProcessDefinitionCode); try { - Map deleteResult = processDefinitionService.deleteProcessDefinitionById(loginUser, projectName, processDefinitionId); + Map deleteResult = processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, code); if (!Status.SUCCESS.equals(deleteResult.get(Constants.STATUS))) { - deleteFailedIdList.add(strProcessDefinitionId); + deleteFailedCodeList.add(strProcessDefinitionCode); logger.error((String) deleteResult.get(Constants.MSG)); } } catch (Exception e) { - deleteFailedIdList.add(strProcessDefinitionId); + deleteFailedCodeList.add(strProcessDefinitionCode); } } } - if (!deleteFailedIdList.isEmpty()) { - putMsg(result, Status.BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR, String.join(",", deleteFailedIdList)); + if (!deleteFailedCodeList.isEmpty()) { + putMsg(result, BATCH_DELETE_PROCESS_DEFINE_BY_CODES_ERROR, String.join(",", deleteFailedCodeList)); } else { putMsg(result, Status.SUCCESS); } - return returnDataList(result); } /** - * batch export process definition by ids + * batch export process definition by codes * * @param loginUser login user - * @param projectName project name - * @param processDefinitionIds process definition ids + * @param projectCode project code + * @param codes process definition codes * @param response response */ - - @ApiOperation(value = "batchExportProcessDefinitionByIds", notes = "BATCH_EXPORT_PROCESS_DEFINITION_BY_IDS_NOTES") + @ApiOperation(value = "batchExportByCodes", notes = "BATCH_EXPORT_PROCESS_DEFINITION_BY_CODES_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processDefinitionIds", value = "PROCESS_DEFINITION_ID", required = true, dataType = "String") + @ApiImplicitParam(name = "codes", value = "PROCESS_DEFINITION_CODE", required = true, dataType = "String") }) - @GetMapping(value = "/export") + @PostMapping(value = "/batch-export") @ResponseBody @AccessLogAnnotation(ignoreRequestArgs = {"loginUser", "response"}) - public void batchExportProcessDefinitionByIds(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("processDefinitionIds") String processDefinitionIds, - HttpServletResponse response) { + public void batchExportProcessDefinitionByCodes(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @RequestParam("codes") String codes, + HttpServletResponse response) { try { - processDefinitionService.batchExportProcessDefinitionByIds(loginUser, projectName, processDefinitionIds, response); + processDefinitionService.batchExportProcessDefinitionByCodes(loginUser, projectCode, codes, response); } catch (Exception e) { logger.error(Status.BATCH_EXPORT_PROCESS_DEFINE_BY_IDS_ERROR.getMsg(), e); } } /** - * query process definition all by project id + * query all process definition by project code * * @param loginUser login user - * @param projectId project id + * @param projectCode project code * @return process definition list */ - @ApiOperation(value = "queryProcessDefinitionAllByProjectId", notes = "QUERY_PROCESS_DEFINITION_All_BY_PROJECT_ID_NOTES") - @ApiImplicitParams({ - @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", required = true, dataType = "Int", example = "100") - }) - @GetMapping(value = "/queryProcessDefinitionAllByProjectId") + @ApiOperation(value = "queryAllByProjectCode", notes = "QUERY_PROCESS_DEFINITION_All_BY_PROJECT_CODE_NOTES") + @GetMapping(value = "/all") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PROCESS_DEFINITION_LIST) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") - public Result queryProcessDefinitionAllByProjectId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("projectId") Integer projectId) { - Map result = processDefinitionService.queryProcessDefinitionAllByProjectId(projectId); + public Result queryAllProcessDefinitionByProjectCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode) { + Map result = processDefinitionService.queryAllProcessDefinitionByProjectCode(loginUser, projectCode); return returnDataList(result); } + /** + * import process definition + * + * @param loginUser login user + * @param projectCode project code + * @param file resource file + * @return import result code + */ + @ApiOperation(value = "importProcessDefinition", notes = "IMPORT_PROCESS_DEFINITION_NOTES") + @ApiImplicitParams({ + @ApiImplicitParam(name = "file", value = "RESOURCE_FILE", required = true, dataType = "MultipartFile") + }) + @PostMapping(value = "/import") + @ApiException(IMPORT_PROCESS_DEFINE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = {"loginUser", "file"}) + public Result importProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @RequestParam("file") MultipartFile file) { + Map result = processDefinitionService.importProcessDefinition(loginUser, projectCode, file); + return returnDataList(result); + } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java index 48bbf64f2d..4b91d41b76 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java @@ -42,7 +42,6 @@ import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.User; import java.io.IOException; -import java.text.ParseException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -52,9 +51,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -73,49 +74,48 @@ import springfox.documentation.annotations.ApiIgnore; */ @Api(tags = "PROCESS_INSTANCE_TAG") @RestController -@RequestMapping("projects/{projectName}/instance") +@RequestMapping("projects/{projectCode}/process-instances") public class ProcessInstanceController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(ProcessInstanceController.class); - @Autowired ProcessInstanceService processInstanceService; /** * query process instance list paging * - * @param loginUser login user - * @param projectName project name - * @param pageNo page number - * @param pageSize page size - * @param processDefinitionId process definition id - * @param searchVal search value - * @param stateType state type - * @param host host - * @param startTime start time - * @param endTime end time + * @param loginUser login user + * @param projectCode project code + * @param pageNo page number + * @param pageSize page size + * @param processDefineCode process definition code + * @param searchVal search value + * @param stateType state type + * @param host host + * @param startTime start time + * @param endTime end time * @return process instance list */ - @ApiOperation(value = "queryProcessInstanceList", notes = "QUERY_PROCESS_INSTANCE_LIST_NOTES") + @ApiOperation(value = "queryProcessInstanceListPaging", notes = "QUERY_PROCESS_INSTANCE_LIST_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", dataType = "Int", example = "100"), - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"), - @ApiImplicitParam(name = "executorName", value = "EXECUTOR_NAME", type = "String"), - @ApiImplicitParam(name = "stateType", value = "EXECUTION_STATUS", type = "ExecutionStatus"), - @ApiImplicitParam(name = "host", value = "HOST", type = "String"), - @ApiImplicitParam(name = "startDate", value = "START_DATE", type = "String"), - @ApiImplicitParam(name = "endDate", value = "END_DATE", type = "String"), - @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "processDefiniteCode", value = "PROCESS_DEFINITION_CODE", dataType = "Long", example = "100"), + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"), + @ApiImplicitParam(name = "executorName", value = "EXECUTOR_NAME", type = "String"), + @ApiImplicitParam(name = "stateType", value = "EXECUTION_STATUS", type = "ExecutionStatus"), + @ApiImplicitParam(name = "host", value = "HOST", type = "String"), + @ApiImplicitParam(name = "startDate", value = "START_DATE", type = "String"), + @ApiImplicitParam(name = "endDate", value = "END_DATE", type = "String"), + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "10") }) - @GetMapping(value = "list-paging") + @GetMapping() @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PROCESS_INSTANCE_LIST_PAGING_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProcessInstanceList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam(value = "processDefinitionId", required = false, defaultValue = "0") Integer processDefinitionId, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @RequestParam(value = "processDefineCode", required = false, defaultValue = "0") long processDefineCode, @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam(value = "executorName", required = false) String executorName, @RequestParam(value = "stateType", required = false) ExecutionStatus stateType, @@ -130,131 +130,130 @@ public class ProcessInstanceController extends BaseController { return result; } searchVal = ParameterUtils.handleEscapes(searchVal); - result = processInstanceService.queryProcessInstanceList( - loginUser, projectName, processDefinitionId, startTime, endTime, searchVal, executorName, stateType, host, pageNo, pageSize); + result = processInstanceService.queryProcessInstanceList(loginUser, projectCode, processDefineCode, startTime, endTime, + searchVal, executorName, stateType, host, pageNo, pageSize); return result; } /** * query task list by process instance id * - * @param loginUser login user - * @param projectName project name - * @param processInstanceId process instance id + * @param loginUser login user + * @param projectCode project code + * @param id process instance id * @return task list for the process instance */ @ApiOperation(value = "queryTaskListByProcessId", notes = "QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "id", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/task-list-by-process-id") + @GetMapping(value = "/{id}/tasks") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryTaskListByProcessId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("processInstanceId") Integer processInstanceId - ) throws IOException { - Map result = processInstanceService.queryTaskListByProcessId(loginUser, projectName, processInstanceId); + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable("id") Integer id) throws IOException { + Map result = processInstanceService.queryTaskListByProcessId(loginUser, projectCode, id); return returnDataList(result); } /** * update process instance * - * @param loginUser login user - * @param projectName project name - * @param processInstanceJson process instance json - * @param processInstanceId process instance id - * @param scheduleTime schedule time - * @param syncDefine sync define - * @param flag flag - * @param locations locations - * @param connects connects + * @param loginUser login user + * @param projectCode project code + * @param taskRelationJson process task relation json + * @param taskDefinitionJson taskDefinitionJson + * @param id process instance id + * @param scheduleTime schedule time + * @param syncDefine sync define + * @param locations locations + * @param tenantCode tenantCode * @return update result code */ @ApiOperation(value = "updateProcessInstance", notes = "UPDATE_PROCESS_INSTANCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processInstanceJson", value = "PROCESS_INSTANCE_JSON", type = "String"), - @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "scheduleTime", value = "SCHEDULE_TIME", type = "String"), - @ApiImplicitParam(name = "syncDefine", value = "SYNC_DEFINE", required = true, type = "Boolean"), - @ApiImplicitParam(name = "locations", value = "PROCESS_INSTANCE_LOCATIONS", type = "String"), - @ApiImplicitParam(name = "connects", value = "PROCESS_INSTANCE_CONNECTS", type = "String"), - @ApiImplicitParam(name = "flag", value = "RECOVERY_PROCESS_INSTANCE_FLAG", type = "Flag"), + @ApiImplicitParam(name = "taskRelationJson", value = "TASK_RELATION_JSON", type = "String"), + @ApiImplicitParam(name = "taskDefinitionJson", value = "TASK_DEFINITION_JSON", type = "String"), + @ApiImplicitParam(name = "id", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "scheduleTime", value = "SCHEDULE_TIME", type = "String"), + @ApiImplicitParam(name = "syncDefine", value = "SYNC_DEFINE", required = true, type = "Boolean"), + @ApiImplicitParam(name = "globalParams", value = "PROCESS_GLOBAL_PARAMS", type = "String"), + @ApiImplicitParam(name = "locations", value = "PROCESS_INSTANCE_LOCATIONS", type = "String"), + @ApiImplicitParam(name = "timeout", value = "PROCESS_TIMEOUT", type = "String"), + @ApiImplicitParam(name = "tenantCode", value = "TENANT_CODE", type = "Int", example = "0") }) - @PostMapping(value = "/update") + @PutMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_PROCESS_INSTANCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateProcessInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam(value = "processInstanceJson", required = false) String processInstanceJson, - @RequestParam(value = "processInstanceId") Integer processInstanceId, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @RequestParam(value = "taskRelationJson", required = true) String taskRelationJson, + @RequestParam(value = "taskDefinitionJson", required = true) String taskDefinitionJson, + @PathVariable(value = "id") Integer id, @RequestParam(value = "scheduleTime", required = false) String scheduleTime, @RequestParam(value = "syncDefine", required = true) Boolean syncDefine, + @RequestParam(value = "globalParams", required = false, defaultValue = "[]") String globalParams, @RequestParam(value = "locations", required = false) String locations, - @RequestParam(value = "connects", required = false) String connects, - @RequestParam(value = "flag", required = false) Flag flag - ) throws ParseException { - Map result = processInstanceService.updateProcessInstance(loginUser, projectName, - processInstanceId, processInstanceJson, scheduleTime, syncDefine, flag, locations, connects); + @RequestParam(value = "timeout", required = false, defaultValue = "0") int timeout, + @RequestParam(value = "tenantCode", required = true) String tenantCode, + @RequestParam(value = "flag", required = false) Flag flag) { + Map result = processInstanceService.updateProcessInstance(loginUser, projectCode, id, + taskRelationJson, taskDefinitionJson, scheduleTime, syncDefine, globalParams, locations, timeout, tenantCode); return returnDataList(result); } /** * query process instance by id * - * @param loginUser login user - * @param projectName project name - * @param processInstanceId process instance id + * @param loginUser login user + * @param projectCode project code + * @param id process instance id * @return process instance detail */ @ApiOperation(value = "queryProcessInstanceById", notes = "QUERY_PROCESS_INSTANCE_BY_ID_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "id", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/select-by-id") + @GetMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PROCESS_INSTANCE_BY_ID_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProcessInstanceById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("processInstanceId") Integer processInstanceId - ) { - Map result = processInstanceService.queryProcessInstanceById(loginUser, projectName, processInstanceId); + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable("id") Integer id) { + Map result = processInstanceService.queryProcessInstanceById(loginUser, projectCode, id); return returnDataList(result); } /** * query top n process instance order by running duration * - * @param loginUser login user - * @param projectName project name - * @param size number of process instance - * @param startTime start time - * @param endTime end time - * @return list of process instance + * @param loginUser login user + * @param projectCode project code + * @param size number of process instance + * @param startTime start time + * @param endTime end time + * @return list of process instance */ @ApiOperation(value = "queryTopNLongestRunningProcessInstance", notes = "QUERY_TOPN_LONGEST_RUNNING_PROCESS_INSTANCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "size", value = "PROCESS_INSTANCE_SIZE", required = true, dataType = "Int", example = "10"), - @ApiImplicitParam(name = "startTime", value = "PROCESS_INSTANCE_START_TIME", required = true, dataType = "String"), - @ApiImplicitParam(name = "endTime", value = "PROCESS_INSTANCE_END_TIME", required = true, dataType = "String"), + @ApiImplicitParam(name = "size", value = "PROCESS_INSTANCE_SIZE", required = true, dataType = "Int", example = "10"), + @ApiImplicitParam(name = "startTime", value = "PROCESS_INSTANCE_START_TIME", required = true, dataType = "String"), + @ApiImplicitParam(name = "endTime", value = "PROCESS_INSTANCE_END_TIME", required = true, dataType = "String"), }) @GetMapping(value = "/top-n") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PROCESS_INSTANCE_BY_ID_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryTopNLongestRunningProcessInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("size") Integer size, - @RequestParam(value = "startTime",required = true) String startTime, - @RequestParam(value = "endTime",required = true) String endTime - - ) { - projectName = ParameterUtils.handleEscapes(projectName); - Map result = processInstanceService.queryTopNLongestRunningProcessInstance(loginUser, projectName, size, startTime, endTime); + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @RequestParam("size") Integer size, + @RequestParam(value = "startTime", required = true) String startTime, + @RequestParam(value = "endTime", required = true) String endTime) { + Map result = processInstanceService.queryTopNLongestRunningProcessInstance(loginUser, projectCode, size, startTime, endTime); return returnDataList(result); } @@ -262,115 +261,113 @@ public class ProcessInstanceController extends BaseController { * delete process instance by id, at the same time, * delete task instance and their mapping relation data * - * @param loginUser login user - * @param projectName project name - * @param processInstanceId process instance id + * @param loginUser login user + * @param projectCode project code + * @param id process instance id * @return delete result code */ @ApiOperation(value = "deleteProcessInstanceById", notes = "DELETE_PROCESS_INSTANCE_BY_ID_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "id", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/delete") + @DeleteMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_PROCESS_INSTANCE_BY_ID_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteProcessInstanceById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("processInstanceId") Integer processInstanceId - ) { - // task queue - Map result = processInstanceService.deleteProcessInstanceById(loginUser, projectName, processInstanceId); + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable("id") Integer id) { + Map result = processInstanceService.deleteProcessInstanceById(loginUser, projectCode, id); return returnDataList(result); } /** * query sub process instance detail info by task id * - * @param loginUser login user - * @param projectName project name - * @param taskId task id + * @param loginUser login user + * @param projectCode project code + * @param taskId task id * @return sub process instance detail */ - @ApiOperation(value = "querySubProcessInstanceByTaskId", notes = "QUERY_SUBPROCESS_INSTANCE_BY_TASK_ID_NOTES") + @ApiOperation(value = "querySubProcessInstanceByTaskCode", notes = "QUERY_SUBPROCESS_INSTANCE_BY_TASK_CODE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "taskId", value = "TASK_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "taskCode", value = "TASK_CODE", required = true, dataType = "Long", example = "100") }) - @GetMapping(value = "/select-sub-process") + @GetMapping(value = "/query-sub-by-parent") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_SUB_PROCESS_INSTANCE_DETAIL_INFO_BY_TASK_ID_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result querySubProcessInstanceByTaskId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, @RequestParam("taskId") Integer taskId) { - Map result = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectName, taskId); + Map result = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectCode, taskId); return returnDataList(result); } /** * query parent process instance detail info by sub process instance id * - * @param loginUser login user - * @param projectName project name - * @param subId sub process id + * @param loginUser login user + * @param projectCode project code + * @param subId sub process id * @return parent instance detail */ @ApiOperation(value = "queryParentInstanceBySubId", notes = "QUERY_PARENT_PROCESS_INSTANCE_BY_SUB_PROCESS_INSTANCE_ID_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "subId", value = "SUB_PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "subId", value = "SUB_PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/select-parent-process") + @GetMapping(value = "/query-parent-by-sub") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PARENT_PROCESS_INSTANCE_DETAIL_INFO_BY_SUB_PROCESS_INSTANCE_ID_ERROR) @AccessLogAnnotation public Result queryParentInstanceBySubId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, @RequestParam("subId") Integer subId) { - Map result = processInstanceService.queryParentInstanceBySubId(loginUser, projectName, subId); + Map result = processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, subId); return returnDataList(result); } /** * query process instance global variables and local variables * - * @param loginUser login user - * @param processInstanceId process instance id + * @param loginUser login user + * @param id process instance id * @return variables data */ @ApiOperation(value = "viewVariables", notes = "QUERY_PROCESS_INSTANCE_GLOBAL_VARIABLES_AND_LOCAL_VARIABLES_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "id", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/view-variables") + @GetMapping(value = "/{id}/view-variables") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PROCESS_INSTANCE_ALL_VARIABLES_ERROR) @AccessLogAnnotation public Result viewVariables(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("processInstanceId") Integer processInstanceId) throws Exception { - Map result = processInstanceService.viewVariables(processInstanceId); + @PathVariable("id") Integer id) { + Map result = processInstanceService.viewVariables(id); return returnDataList(result); } /** * encapsulation gantt structure * - * @param loginUser login user - * @param projectName project name - * @param processInstanceId process instance id + * @param loginUser login user + * @param projectCode project code + * @param id process instance id * @return gantt tree data */ @ApiOperation(value = "vieGanttTree", notes = "VIEW_GANTT_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "id", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/view-gantt") + @GetMapping(value = "/{id}/view-gantt") @ResponseStatus(HttpStatus.OK) @ApiException(ENCAPSULATION_PROCESS_INSTANCE_GANTT_STRUCTURE_ERROR) @AccessLogAnnotation public Result viewTree(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("processInstanceId") Integer processInstanceId) throws Exception { - Map result = processInstanceService.viewGantt(processInstanceId); + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable("id") Integer id) throws Exception { + Map result = processInstanceService.viewGantt(id); return returnDataList(result); } @@ -378,24 +375,23 @@ public class ProcessInstanceController extends BaseController { * batch delete process instance by ids, at the same time, * delete task instance and their mapping relation data * - * @param loginUser login user - * @param projectName project name + * @param loginUser login user + * @param projectCode project code * @param processInstanceIds process instance id * @return delete result code */ @ApiOperation(value = "batchDeleteProcessInstanceByIds", notes = "BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "projectName", value = "PROJECT_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "processInstanceIds", value = "PROCESS_INSTANCE_IDS", required = true, dataType = "String"), + @ApiImplicitParam(name = "projectName", value = "PROJECT_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "processInstanceIds", value = "PROCESS_INSTANCE_IDS", required = true, dataType = "String"), }) - @GetMapping(value = "/batch-delete") + @PostMapping(value = "/batch-delete") @ResponseStatus(HttpStatus.OK) @ApiException(BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR) @AccessLogAnnotation public Result batchDeleteProcessInstanceByIds(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @PathVariable String projectName, - @RequestParam("processInstanceIds") String processInstanceIds - ) { + @PathVariable long projectCode, + @RequestParam("processInstanceIds") String processInstanceIds) { // task queue Map result = new HashMap<>(); List deleteFailedIdList = new ArrayList<>(); @@ -405,7 +401,7 @@ public class ProcessInstanceController extends BaseController { for (String strProcessInstanceId : processInstanceIdArray) { int processInstanceId = Integer.parseInt(strProcessInstanceId); try { - Map deleteResult = processInstanceService.deleteProcessInstanceById(loginUser, projectName, processInstanceId); + Map deleteResult = processInstanceService.deleteProcessInstanceById(loginUser, projectCode, processInstanceId); if (!Status.SUCCESS.equals(deleteResult.get(Constants.STATUS))) { deleteFailedIdList.add(strProcessInstanceId); logger.error((String) deleteResult.get(Constants.MSG)); @@ -420,7 +416,6 @@ public class ProcessInstanceController extends BaseController { } else { putMsg(result, Status.SUCCESS); } - return returnDataList(result); } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java index d8f1eaceab..ca3bd5f563 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java @@ -19,17 +19,15 @@ package org.apache.dolphinscheduler.api.controller; import static org.apache.dolphinscheduler.api.enums.Status.CREATE_PROJECT_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.DELETE_PROJECT_ERROR; -import static org.apache.dolphinscheduler.api.enums.Status.IMPORT_PROCESS_DEFINE_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_AUTHORIZED_AND_USER_CREATED_PROJECT_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_AUTHORIZED_PROJECT; -import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PROJECT_DETAILS_BY_ID_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PROJECT_DETAILS_BY_CODE_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_UNAUTHORIZED_PROJECT_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_PROJECT_ERROR; import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.exceptions.ApiException; -import org.apache.dolphinscheduler.api.service.ProcessDefinitionService; import org.apache.dolphinscheduler.api.service.ProjectService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; @@ -40,14 +38,16 @@ import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; 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 org.springframework.web.multipart.MultipartFile; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -66,82 +66,77 @@ public class ProjectController extends BaseController { @Autowired private ProjectService projectService; - @Autowired - private ProcessDefinitionService processDefinitionService; - /** * create project * - * @param loginUser login user + * @param loginUser login user * @param projectName project name * @param description description * @return returns an error if it exists */ - @ApiOperation(value = "createProject", notes = "CREATE_PROJECT_NOTES") + @ApiOperation(value = "create", notes = "CREATE_PROJECT_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "projectName", value = "PROJECT_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "description", value = "PROJECT_DESC", required = true, dataType = "String") + @ApiImplicitParam(name = "projectName", value = "PROJECT_NAME", dataType = "String"), + @ApiImplicitParam(name = "description", value = "PROJECT_DESC", dataType = "String") }) - @PostMapping(value = "/create") + @PostMapping() @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_PROJECT_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result createProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("projectName") String projectName, @RequestParam(value = "description", required = false) String description) { - Map result = projectService.createProject(loginUser, projectName, description); return returnDataList(result); } /** - * updateProcessInstance project + * update project * - * @param loginUser login user - * @param projectId project id + * @param loginUser login user + * @param code project code * @param projectName project name * @param description description * @return update result code */ - @ApiOperation(value = "updateProject", notes = "UPDATE_PROJECT_NOTES") + @ApiOperation(value = "update", notes = "UPDATE_PROJECT_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "projectName", value = "PROJECT_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "description", value = "PROJECT_DESC", dataType = "String"), - @ApiImplicitParam(name = "userName", value = "USER_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "code", value = "PROJECT_CODE", dataType = "Long", example = "123456"), + @ApiImplicitParam(name = "projectName", value = "PROJECT_NAME", dataType = "String"), + @ApiImplicitParam(name = "description", value = "PROJECT_DESC", dataType = "String"), + @ApiImplicitParam(name = "userName", value = "USER_NAME", dataType = "String"), }) - @PostMapping(value = "/update") + @PutMapping(value = "/{code}") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_PROJECT_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("projectId") Integer projectId, + @PathVariable("code") Long code, @RequestParam("projectName") String projectName, @RequestParam(value = "description", required = false) String description, @RequestParam(value = "userName") String userName) { - Map result = projectService.update(loginUser, projectId, projectName, description, userName); + Map result = projectService.update(loginUser, code, projectName, description, userName); return returnDataList(result); } /** - * query project details by id + * query project details by code * * @param loginUser login user - * @param projectId project id + * @param code project code * @return project detail information */ - @ApiOperation(value = "queryProjectById", notes = "QUERY_PROJECT_BY_ID_NOTES") + @ApiOperation(value = "queryProjectByCode", notes = "QUERY_PROJECT_BY_ID_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "code", value = "PROJECT_CODE", dataType = "Long", example = "123456") }) - @GetMapping(value = "/query-by-id") + @GetMapping(value = "/{code}") @ResponseStatus(HttpStatus.OK) - @ApiException(QUERY_PROJECT_DETAILS_BY_ID_ERROR) + @ApiException(QUERY_PROJECT_DETAILS_BY_CODE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") - public Result queryProjectById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("projectId") Integer projectId) { - - Map result = projectService.queryById(projectId); + public Result queryProjectByCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @PathVariable("code") long code) { + Map result = projectService.queryByCode(loginUser, code); return returnDataList(result); } @@ -150,17 +145,17 @@ public class ProjectController extends BaseController { * * @param loginUser login user * @param searchVal search value - * @param pageSize page size - * @param pageNo page number + * @param pageSize page size + * @param pageNo page number * @return project list which the login user have permission to see */ @ApiOperation(value = "queryProjectListPaging", notes = "QUERY_PROJECT_LIST_PAGING_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20"), - @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1") + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "10"), + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1") }) - @GetMapping(value = "/list-paging") + @GetMapping() @ResponseStatus(HttpStatus.OK) @ApiException(LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -180,25 +175,23 @@ public class ProjectController extends BaseController { } /** - * delete project by id + * delete project by code * * @param loginUser login user - * @param projectId project id + * @param code project code * @return delete result code */ - @ApiOperation(value = "deleteProjectById", notes = "DELETE_PROJECT_BY_ID_NOTES") + @ApiOperation(value = "delete", notes = "DELETE_PROJECT_BY_ID_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "code", value = "PROJECT_CODE", dataType = "Long", example = "123456") }) - @GetMapping(value = "/delete") + @DeleteMapping(value = "/{code}") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_PROJECT_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("projectId") Integer projectId - ) { - - Map result = projectService.deleteProject(loginUser, projectId); + @PathVariable("code") Long code) { + Map result = projectService.deleteProject(loginUser, code); return returnDataList(result); } @@ -206,14 +199,14 @@ public class ProjectController extends BaseController { * query unauthorized project * * @param loginUser login user - * @param userId user id + * @param userId user id * @return the projects which user have not permission to see */ @ApiOperation(value = "queryUnauthorizedProject", notes = "QUERY_UNAUTHORIZED_PROJECT_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "userId", value = "USER_ID", dataType = "Int", example = "100") }) - @GetMapping(value = "/unauth-project") + @GetMapping(value = "/unauth") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_UNAUTHORIZED_PROJECT_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -223,19 +216,18 @@ public class ProjectController extends BaseController { return returnDataList(result); } - /** * query authorized project * * @param loginUser login user - * @param userId user id + * @param userId user id * @return projects which the user have permission to see, Except for items created by this user */ @ApiOperation(value = "queryAuthorizedProject", notes = "QUERY_AUTHORIZED_PROJECT_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "userId", value = "USER_ID", dataType = "Int", example = "100") }) - @GetMapping(value = "/authed-project") + @GetMapping(value = "/authed") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_AUTHORIZED_PROJECT) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -252,7 +244,7 @@ public class ProjectController extends BaseController { * @return projects which the user create and authorized */ @ApiOperation(value = "queryProjectCreatedAndAuthorizedByUser", notes = "QUERY_AUTHORIZED_AND_USER_CREATED_PROJECT_NOTES") - @GetMapping(value = "/created-and-authorized-project") + @GetMapping(value = "/created-and-authed") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_AUTHORIZED_AND_USER_CREATED_PROJECT_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -261,30 +253,6 @@ public class ProjectController extends BaseController { return returnDataList(result); } - /** - * import process definition - * - * @param loginUser login user - * @param file resource file - * @param projectName project name - * @return import result code - */ - - @ApiOperation(value = "importProcessDefinition", notes = "IMPORT_PROCESS_DEFINITION_NOTES") - @ApiImplicitParams({ - @ApiImplicitParam(name = "file", value = "RESOURCE_FILE", required = true, dataType = "MultipartFile"), - @ApiImplicitParam(name = "projectName", value = "PROJECT_NAME", required = true, dataType = "String") - }) - @PostMapping(value = "/import-definition") - @ApiException(IMPORT_PROCESS_DEFINE_ERROR) - @AccessLogAnnotation(ignoreRequestArgs = {"loginUser", "file"}) - public Result importProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("file") MultipartFile file, - @RequestParam("projectName") String projectName) { - Map result = processDefinitionService.importProcessDefinition(loginUser, file, projectName); - return returnDataList(result); - } - /** * query all project list * @@ -292,7 +260,7 @@ public class ProjectController extends BaseController { * @return all project list */ @ApiOperation(value = "queryAllProjectList", notes = "QUERY_ALL_PROJECT_LIST_NOTES") - @GetMapping(value = "/query-project-list") + @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) @ApiException(LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/QueueController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/QueueController.java index 461ff41f67..2fc407df85 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/QueueController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/QueueController.java @@ -35,7 +35,9 @@ import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -53,7 +55,7 @@ import springfox.documentation.annotations.ApiIgnore; */ @Api(tags = "QUEUE_TAG") @RestController -@RequestMapping("/queue") +@RequestMapping("/queues") public class QueueController extends BaseController { @Autowired @@ -80,18 +82,18 @@ public class QueueController extends BaseController { * query queue list paging * * @param loginUser login user - * @param pageNo page number + * @param pageNo page number * @param searchVal search value - * @param pageSize page size + * @param pageSize page size * @return queue list */ @ApiOperation(value = "queryQueueListPaging", notes = "QUERY_QUEUE_LIST_PAGING_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), - @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") }) - @GetMapping(value = "/list-paging") + @GetMapping() @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_QUEUE_LIST_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -113,16 +115,16 @@ public class QueueController extends BaseController { * create queue * * @param loginUser login user - * @param queue queue + * @param queue queue * @param queueName queue name * @return create result */ @ApiOperation(value = "createQueue", notes = "CREATE_QUEUE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "queue", value = "YARN_QUEUE_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "queueName", value = "QUEUE_NAME", required = true, dataType = "String") + @ApiImplicitParam(name = "queue", value = "YARN_QUEUE_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "queueName", value = "QUEUE_NAME", required = true, dataType = "String") }) - @PostMapping(value = "/create") + @PostMapping() @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_QUEUE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -137,23 +139,23 @@ public class QueueController extends BaseController { * update queue * * @param loginUser login user - * @param queue queue - * @param id queue id + * @param queue queue + * @param id queue id * @param queueName queue name * @return update result code */ @ApiOperation(value = "updateQueue", notes = "UPDATE_QUEUE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "QUEUE_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "queue", value = "YARN_QUEUE_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "queueName", value = "QUEUE_NAME", required = true, dataType = "String") + @ApiImplicitParam(name = "id", value = "QUEUE_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "queue", value = "YARN_QUEUE_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "queueName", value = "QUEUE_NAME", required = true, dataType = "String") }) - @PostMapping(value = "/update") + @PutMapping(value = "/{id}") @ResponseStatus(HttpStatus.CREATED) @ApiException(UPDATE_QUEUE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int id, + @PathVariable(value = "id") int id, @RequestParam(value = "queue") String queue, @RequestParam(value = "queueName") String queueName) { Map result = queueService.updateQueue(loginUser, id, queue, queueName); @@ -164,16 +166,16 @@ public class QueueController extends BaseController { * verify queue and queue name * * @param loginUser login user - * @param queue queue + * @param queue queue * @param queueName queue name * @return true if the queue name not exists, otherwise return false */ @ApiOperation(value = "verifyQueue", notes = "VERIFY_QUEUE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "queue", value = "YARN_QUEUE_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "queueName", value = "QUEUE_NAME", required = true, dataType = "String") + @ApiImplicitParam(name = "queue", value = "YARN_QUEUE_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "queueName", value = "QUEUE_NAME", required = true, dataType = "String") }) - @PostMapping(value = "/verify-queue") + @PostMapping(value = "/verify") @ResponseStatus(HttpStatus.OK) @ApiException(VERIFY_QUEUE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java index b8ab1f51db..d5fa60f531 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java @@ -64,8 +64,11 @@ import org.springframework.core.io.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -96,24 +99,23 @@ public class ResourcesController extends BaseController { private UdfFuncService udfFuncService; /** - * - * @param loginUser login user - * @param type type - * @param alias alias + * @param loginUser login user + * @param type type + * @param alias alias * @param description description - * @param pid parent id - * @param currentDir current directory + * @param pid parent id + * @param currentDir current directory * @return create result code */ @ApiOperation(value = "createDirctory", notes = "CREATE_RESOURCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"), - @ApiImplicitParam(name = "name", value = "RESOURCE_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "description", value = "RESOURCE_DESC", dataType = "String"), - @ApiImplicitParam(name = "pid", value = "RESOURCE_PID", required = true, dataType = "Int", example = "10"), - @ApiImplicitParam(name = "currentDir", value = "RESOURCE_CURRENTDIR", required = true, dataType = "String") + @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"), + @ApiImplicitParam(name = "name", value = "RESOURCE_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "description", value = "RESOURCE_DESC", dataType = "String"), + @ApiImplicitParam(name = "pid", value = "RESOURCE_PID", required = true, dataType = "Int", example = "10"), + @ApiImplicitParam(name = "currentDir", value = "RESOURCE_CURRENTDIR", required = true, dataType = "String") }) - @PostMapping(value = "/directory/create") + @PostMapping(value = "/directory") @ApiException(CREATE_RESOURCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result createDirectory(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @@ -127,25 +129,19 @@ public class ResourcesController extends BaseController { /** * create resource - * @param loginUser - * @param type - * @param alias - * @param description - * @param file - * @param pid - * @param currentDir + * * @return create result code */ @ApiOperation(value = "createResource", notes = "CREATE_RESOURCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"), - @ApiImplicitParam(name = "name", value = "RESOURCE_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "description", value = "RESOURCE_DESC", dataType = "String"), - @ApiImplicitParam(name = "file", value = "RESOURCE_FILE", required = true, dataType = "MultipartFile"), - @ApiImplicitParam(name = "pid", value = "RESOURCE_PID", required = true, dataType = "Int", example = "10"), - @ApiImplicitParam(name = "currentDir", value = "RESOURCE_CURRENTDIR", required = true, dataType = "String") + @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"), + @ApiImplicitParam(name = "name", value = "RESOURCE_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "description", value = "RESOURCE_DESC", dataType = "String"), + @ApiImplicitParam(name = "file", value = "RESOURCE_FILE", required = true, dataType = "MultipartFile"), + @ApiImplicitParam(name = "pid", value = "RESOURCE_PID", required = true, dataType = "Int", example = "10"), + @ApiImplicitParam(name = "currentDir", value = "RESOURCE_CURRENTDIR", required = true, dataType = "String") }) - @PostMapping(value = "/create") + @PostMapping() @ApiException(CREATE_RESOURCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result createResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @@ -166,26 +162,26 @@ public class ResourcesController extends BaseController { * @param resourceId resource id * @param type resource type * @param description description - * @param file resource file + * @param file resource file * @return update result code */ @ApiOperation(value = "updateResource", notes = "UPDATE_RESOURCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"), - @ApiImplicitParam(name = "name", value = "RESOURCE_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "description", value = "RESOURCE_DESC", dataType = "String"), - @ApiImplicitParam(name = "file", value = "RESOURCE_FILE", required = true, dataType = "MultipartFile") + @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"), + @ApiImplicitParam(name = "name", value = "RESOURCE_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "description", value = "RESOURCE_DESC", dataType = "String"), + @ApiImplicitParam(name = "file", value = "RESOURCE_FILE", required = true, dataType = "MultipartFile") }) - @PostMapping(value = "/update") + @PutMapping(value = "/{id}") @ApiException(UPDATE_RESOURCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int resourceId, + @PathVariable(value = "id") int resourceId, @RequestParam(value = "type") ResourceType type, @RequestParam(value = "name") String alias, @RequestParam(value = "description", required = false) String description, - @RequestParam(value = "file",required = false) MultipartFile file) { + @RequestParam(value = "file", required = false) MultipartFile file) { return resourceService.updateResource(loginUser, resourceId, alias, description, type, file); } @@ -198,7 +194,7 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "queryResourceList", notes = "QUERY_RESOURCE_LIST_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType") + @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType") }) @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) @@ -223,13 +219,13 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "queryResourceListPaging", notes = "QUERY_RESOURCE_LIST_PAGING_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"), - @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "int", example = "10"), - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), - @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") + @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"), + @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "int", example = "10"), + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") }) - @GetMapping(value = "/list-paging") + @GetMapping() @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_RESOURCES_LIST_PAGING) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -260,14 +256,14 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "deleteResource", notes = "DELETE_RESOURCE_BY_ID_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/delete") + @DeleteMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_RESOURCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int resourceId + @PathVariable(value = "id") int resourceId ) throws Exception { return resourceService.delete(loginUser, resourceId); } @@ -283,8 +279,8 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "verifyResourceName", notes = "VERIFY_RESOURCE_NAME_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"), - @ApiImplicitParam(name = "fullName", value = "RESOURCE_FULL_NAME", required = true, dataType = "String") + @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"), + @ApiImplicitParam(name = "fullName", value = "RESOURCE_FULL_NAME", required = true, dataType = "String") }) @GetMapping(value = "/verify-name") @ResponseStatus(HttpStatus.OK) @@ -298,7 +294,7 @@ public class ResourcesController extends BaseController { } /** - * query resources jar list + * query resources by type * * @param loginUser login user * @param type resource type @@ -306,17 +302,17 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "queryResourceByProgramType", notes = "QUERY_RESOURCE_LIST_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType") + @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType") }) - @GetMapping(value = "/list/jar") + @GetMapping(value = "/query-by-type") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_RESOURCES_LIST_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryResourceJarList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "type") ResourceType type, - @RequestParam(value = "programType",required = false) ProgramType programType + @RequestParam(value = "programType", required = false) ProgramType programType ) { - Map result = resourceService.queryResourceByProgramType(loginUser, type,programType); + Map result = resourceService.queryResourceByProgramType(loginUser, type, programType); return returnDataList(result); } @@ -331,17 +327,17 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "queryResource", notes = "QUERY_BY_RESOURCE_NAME") @ApiImplicitParams({ - @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"), - @ApiImplicitParam(name = "fullName", value = "RESOURCE_FULL_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = false, dataType = "Int", example = "10") + @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"), + @ApiImplicitParam(name = "fullName", value = "RESOURCE_FULL_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = false, dataType = "Int", example = "10") }) - @GetMapping(value = "/queryResource") + @GetMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(RESOURCE_NOT_EXIST) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "fullName", required = false) String fullName, - @RequestParam(value = "id", required = false) Integer id, + @PathVariable(value = "id", required = false) Integer id, @RequestParam(value = "type") ResourceType type ) { @@ -359,15 +355,15 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "viewResource", notes = "VIEW_RESOURCE_BY_ID_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "skipLineNum", value = "SKIP_LINE_NUM", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "limit", value = "LIMIT", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "skipLineNum", value = "SKIP_LINE_NUM", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "limit", value = "LIMIT", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/view") + @GetMapping(value = "/{id}/view") @ApiException(VIEW_RESOURCE_FILE_ON_LINE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result viewResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int resourceId, + @PathVariable(value = "id") int resourceId, @RequestParam(value = "skipLineNum") int skipLineNum, @RequestParam(value = "limit") int limit ) { @@ -376,25 +372,18 @@ public class ResourcesController extends BaseController { /** * create resource file online - * @param loginUser - * @param type - * @param fileName - * @param fileSuffix - * @param description - * @param content - * @param pid - * @param currentDir + * * @return create result code */ @ApiOperation(value = "onlineCreateResource", notes = "ONLINE_CREATE_RESOURCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"), - @ApiImplicitParam(name = "fileName", value = "RESOURCE_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "suffix", value = "SUFFIX", required = true, dataType = "String"), - @ApiImplicitParam(name = "description", value = "RESOURCE_DESC", dataType = "String"), - @ApiImplicitParam(name = "content", value = "CONTENT", required = true, dataType = "String"), - @ApiImplicitParam(name = "pid", value = "RESOURCE_PID", required = true, dataType = "Int", example = "10"), - @ApiImplicitParam(name = "currentDir", value = "RESOURCE_CURRENTDIR", required = true, dataType = "String") + @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"), + @ApiImplicitParam(name = "fileName", value = "RESOURCE_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "suffix", value = "SUFFIX", required = true, dataType = "String"), + @ApiImplicitParam(name = "description", value = "RESOURCE_DESC", dataType = "String"), + @ApiImplicitParam(name = "content", value = "CONTENT", required = true, dataType = "String"), + @ApiImplicitParam(name = "pid", value = "RESOURCE_PID", required = true, dataType = "Int", example = "10"), + @ApiImplicitParam(name = "currentDir", value = "RESOURCE_CURRENTDIR", required = true, dataType = "String") }) @PostMapping(value = "/online-create") @ApiException(CREATE_RESOURCE_FILE_ON_LINE_ERROR) @@ -425,14 +414,14 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "updateResourceContent", notes = "UPDATE_RESOURCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "content", value = "CONTENT", required = true, dataType = "String") + @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "content", value = "CONTENT", required = true, dataType = "String") }) - @PostMapping(value = "/update-content") + @PutMapping(value = "/{id}/update-content") @ApiException(EDIT_RESOURCE_FILE_ON_LINE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateResourceContent(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int resourceId, + @PathVariable(value = "id") int resourceId, @RequestParam(value = "content") String content ) { if (StringUtils.isEmpty(content)) { @@ -451,22 +440,22 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "downloadResource", notes = "DOWNLOAD_RESOURCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/download") + @GetMapping(value = "/{id}/download") @ResponseBody @ApiException(DOWNLOAD_RESOURCE_FILE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public ResponseEntity downloadResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int resourceId) throws Exception { + @PathVariable(value = "id") int resourceId) throws Exception { Resource file = resourceService.downloadResource(resourceId); if (file == null) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(Status.RESOURCE_NOT_EXIST.getMsg()); } return ResponseEntity - .ok() - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getFilename() + "\"") - .body(file); + .ok() + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getFilename() + "\"") + .body(file); } @@ -485,16 +474,16 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "createUdfFunc", notes = "CREATE_UDF_FUNCTION_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "type", value = "UDF_TYPE", required = true, dataType = "UdfType"), - @ApiImplicitParam(name = "funcName", value = "FUNC_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "className", value = "CLASS_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "argTypes", value = "ARG_TYPES", dataType = "String"), - @ApiImplicitParam(name = "database", value = "DATABASE_NAME", dataType = "String"), - @ApiImplicitParam(name = "description", value = "UDF_DESC", dataType = "String"), - @ApiImplicitParam(name = "resourceId", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "type", value = "UDF_TYPE", required = true, dataType = "UdfType"), + @ApiImplicitParam(name = "funcName", value = "FUNC_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "className", value = "CLASS_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "argTypes", value = "ARG_TYPES", dataType = "String"), + @ApiImplicitParam(name = "database", value = "DATABASE_NAME", dataType = "String"), + @ApiImplicitParam(name = "description", value = "UDF_DESC", dataType = "String"), + @ApiImplicitParam(name = "resourceId", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100") }) - @PostMapping(value = "/udf-func/create") + @PostMapping(value = "/{resourceId}/udf-func") @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_UDF_FUNCTION_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -505,7 +494,7 @@ public class ResourcesController extends BaseController { @RequestParam(value = "argTypes", required = false) String argTypes, @RequestParam(value = "database", required = false) String database, @RequestParam(value = "description", required = false) String description, - @RequestParam(value = "resourceId") int resourceId) { + @PathVariable(value = "resourceId") int resourceId) { return udfFuncService.createUdfFunction(loginUser, funcName, className, argTypes, database, description, type, resourceId); } @@ -518,15 +507,15 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "viewUIUdfFunction", notes = "VIEW_UDF_FUNCTION_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/udf-func/update-ui") + @GetMapping(value = "/{id}/udf-func") @ResponseStatus(HttpStatus.OK) @ApiException(VIEW_UDF_FUNCTION_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result viewUIUdfFunction(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("id") int id) { + @PathVariable("id") int id) { Map map = udfFuncService.queryUdfFuncDetail(id); return returnDataList(map); } @@ -547,28 +536,28 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "updateUdfFunc", notes = "UPDATE_UDF_FUNCTION_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "UDF_ID", required = true, dataType = "Int"), - @ApiImplicitParam(name = "type", value = "UDF_TYPE", required = true, dataType = "UdfType"), - @ApiImplicitParam(name = "funcName", value = "FUNC_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "className", value = "CLASS_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "argTypes", value = "ARG_TYPES", dataType = "String"), - @ApiImplicitParam(name = "database", value = "DATABASE_NAME", dataType = "String"), - @ApiImplicitParam(name = "description", value = "UDF_DESC", dataType = "String"), - @ApiImplicitParam(name = "resourceId", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "id", value = "UDF_ID", required = true, dataType = "Int"), + @ApiImplicitParam(name = "type", value = "UDF_TYPE", required = true, dataType = "UdfType"), + @ApiImplicitParam(name = "funcName", value = "FUNC_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "className", value = "CLASS_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "argTypes", value = "ARG_TYPES", dataType = "String"), + @ApiImplicitParam(name = "database", value = "DATABASE_NAME", dataType = "String"), + @ApiImplicitParam(name = "description", value = "UDF_DESC", dataType = "String"), + @ApiImplicitParam(name = "resourceId", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100") }) - @PostMapping(value = "/udf-func/update") + @PutMapping(value = "/{resourceId}/udf-func/{id}") @ApiException(UPDATE_UDF_FUNCTION_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateUdfFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int udfFuncId, + @PathVariable(value = "id") int udfFuncId, @RequestParam(value = "type") UdfType type, @RequestParam(value = "funcName") String funcName, @RequestParam(value = "className") String className, @RequestParam(value = "argTypes", required = false) String argTypes, @RequestParam(value = "database", required = false) String database, @RequestParam(value = "description", required = false) String description, - @RequestParam(value = "resourceId") int resourceId) { + @PathVariable(value = "resourceId") int resourceId) { Map result = udfFuncService.updateUdfFunc(udfFuncId, funcName, className, argTypes, database, description, type, resourceId); return returnDataList(result); } @@ -584,18 +573,18 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "queryUdfFuncListPaging", notes = "QUERY_UDF_FUNCTION_LIST_PAGING_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), - @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") }) - @GetMapping(value = "/udf-func/list-paging") + @GetMapping(value = "/udf-func") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_UDF_FUNCTION_LIST_PAGING_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryUdfFuncListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("pageNo") Integer pageNo, - @RequestParam(value = "searchVal", required = false) String searchVal, - @RequestParam("pageSize") Integer pageSize + @RequestParam("pageNo") Integer pageNo, + @RequestParam(value = "searchVal", required = false) String searchVal, + @RequestParam("pageSize") Integer pageSize ) { Result result = checkPageParams(pageNo, pageSize); if (!result.checkResult()) { @@ -615,14 +604,14 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "queryUdfFuncList", notes = "QUERY_UDF_FUNC_LIST_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "type", value = "UDF_TYPE", required = true, dataType = "UdfType") + @ApiImplicitParam(name = "type", value = "UDF_TYPE", required = true, dataType = "UdfType") }) @GetMapping(value = "/udf-func/list") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_DATASOURCE_BY_TYPE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryUdfFuncList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("type") UdfType type) { + @RequestParam("type") UdfType type) { Map result = udfFuncService.queryUdfFuncList(loginUser, type.ordinal()); return returnDataList(result); } @@ -636,7 +625,7 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "verifyUdfFuncName", notes = "VERIFY_UDF_FUNCTION_NAME_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "name", value = "FUNC_NAME", required = true, dataType = "String") + @ApiImplicitParam(name = "name", value = "FUNC_NAME", required = true, dataType = "String") }) @GetMapping(value = "/udf-func/verify-name") @@ -659,14 +648,14 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "deleteUdfFunc", notes = "DELETE_UDF_FUNCTION_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "id", value = "UDF_FUNC_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/udf-func/delete") + @DeleteMapping(value = "/udf-func/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_UDF_FUNCTION_ERROR) @AccessLogAnnotation public Result deleteUdfFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int udfFuncId + @PathVariable(value = "id") int udfFuncId ) { return udfFuncService.delete(udfFuncId); } @@ -680,7 +669,7 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "authorizedFile", notes = "AUTHORIZED_FILE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100") }) @GetMapping(value = "/authed-file") @ResponseStatus(HttpStatus.CREATED) @@ -702,9 +691,9 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "authorizeResourceTree", notes = "AUTHORIZE_RESOURCE_TREE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/authorize-resource-tree") + @GetMapping(value = "/authed-resource-tree") @ResponseStatus(HttpStatus.CREATED) @ApiException(AUTHORIZE_RESOURCE_TREE) @AccessLogAnnotation @@ -724,7 +713,7 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "unauthUDFFunc", notes = "UNAUTHORIZED_UDF_FUNC_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100") }) @GetMapping(value = "/unauth-udf-func") @ResponseStatus(HttpStatus.CREATED) @@ -747,7 +736,7 @@ public class ResourcesController extends BaseController { */ @ApiOperation(value = "authUDFFunc", notes = "AUTHORIZED_UDF_FUNC_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100") }) @GetMapping(value = "/authed-udf-func") @ResponseStatus(HttpStatus.CREATED) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java index 7ced43d3e1..f3b5290d65 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java @@ -42,9 +42,11 @@ import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -63,7 +65,7 @@ import springfox.documentation.annotations.ApiIgnore; */ @Api(tags = "SCHEDULER_TAG") @RestController -@RequestMapping("/projects/{projectName}/schedule") +@RequestMapping("/projects/{projectCode}/schedules") public class SchedulerController extends BaseController { public static final String DEFAULT_WARNING_TYPE = "NONE"; @@ -78,8 +80,8 @@ public class SchedulerController extends BaseController { * create schedule * * @param loginUser login user - * @param projectName project name - * @param processDefinitionId process definition id + * @param projectCode project code + * @param processDefinitionCode process definition code * @param schedule scheduler * @param warningType warning type * @param warningGroupId warning group id @@ -90,24 +92,23 @@ public class SchedulerController extends BaseController { */ @ApiOperation(value = "createSchedule", notes = "CREATE_SCHEDULE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "schedule", value = "SCHEDULE", required = true, dataType = "String", - example = "{'startTime':'2019-06-10 00:00:00','endTime':'2019-06-13 00:00:00','timezoneId':'America/Phoenix','crontab':'0 0 3/6 * * ? *'}"), + @ApiImplicitParam(name = "processDefinitionCode", value = "PROCESS_DEFINITION_CODE", required = true, dataType = "Long", example = "100"), + @ApiImplicitParam(name = "schedule", value = "SCHEDULE", dataType = "String", + example = "{'startTime':'2019-06-10 00:00:00','endTime':'2019-06-13 00:00:00','timezoneId':'America/Phoenix','crontab':'0 0 3/6 * * ? *'}"), @ApiImplicitParam(name = "warningType", value = "WARNING_TYPE", type = "WarningType"), @ApiImplicitParam(name = "warningGroupId", value = "WARNING_GROUP_ID", dataType = "Int", example = "100"), @ApiImplicitParam(name = "failureStrategy", value = "FAILURE_STRATEGY", type = "FailureStrategy"), @ApiImplicitParam(name = "workerGroupId", value = "WORKER_GROUP_ID", dataType = "Int", example = "100"), - @ApiImplicitParam(name = "workerGroup", value = "WORKER_GROUP", dataType = "String"), @ApiImplicitParam(name = "environmentCode", value = "ENVIRONMENT_CODE", dataType = "Long"), @ApiImplicitParam(name = "processInstancePriority", value = "PROCESS_INSTANCE_PRIORITY", type = "Priority"), }) - @PostMapping("/create") + @PostMapping() @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_SCHEDULE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result createSchedule(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam(value = "processDefinitionId") Integer processDefinitionId, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @RequestParam(value = "processDefinitionCode") long processDefinitionCode, @RequestParam(value = "schedule") String schedule, @RequestParam(value = "warningType", required = false, defaultValue = DEFAULT_WARNING_TYPE) WarningType warningType, @RequestParam(value = "warningGroupId", required = false, defaultValue = DEFAULT_NOTIFY_GROUP_ID) int warningGroupId, @@ -115,8 +116,8 @@ public class SchedulerController extends BaseController { @RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, @RequestParam(value = "environmentCode", required = false, defaultValue = "-1") Long environmentCode, @RequestParam(value = "processInstancePriority", required = false, defaultValue = DEFAULT_PROCESS_INSTANCE_PRIORITY) Priority processInstancePriority) { - Map result = schedulerService.insertSchedule(loginUser, projectName, processDefinitionId, schedule, - warningType, warningGroupId, failureStrategy, processInstancePriority, workerGroup, environmentCode); + Map result = schedulerService.insertSchedule(loginUser, projectCode, processDefinitionCode, schedule, + warningType, warningGroupId, failureStrategy, processInstancePriority, workerGroup, environmentCode); return returnDataList(result); } @@ -125,7 +126,7 @@ public class SchedulerController extends BaseController { * updateProcessInstance schedule * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param id scheduler id * @param schedule scheduler * @param warningType warning type @@ -138,23 +139,20 @@ public class SchedulerController extends BaseController { @ApiOperation(value = "updateSchedule", notes = "UPDATE_SCHEDULE_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "SCHEDULE_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "schedule", value = "SCHEDULE", required = true, dataType = "String", - example = "{'startTime':'2019-06-10 00:00:00','endTime':'2019-06-13 00:00:00'," - + "'crontab':'0 0 3/6 * * ? *'}"), + @ApiImplicitParam(name = "schedule", value = "SCHEDULE", dataType = "String", example = "{'startTime':'2019-06-10 00:00:00','endTime':'2019-06-13 00:00:00','crontab':'0 0 3/6 * * ? *'}"), @ApiImplicitParam(name = "warningType", value = "WARNING_TYPE", type = "WarningType"), @ApiImplicitParam(name = "warningGroupId", value = "WARNING_GROUP_ID", dataType = "Int", example = "100"), @ApiImplicitParam(name = "failureStrategy", value = "FAILURE_STRATEGY", type = "FailureStrategy"), @ApiImplicitParam(name = "workerGroupId", value = "WORKER_GROUP_ID", dataType = "Int", example = "100"), - @ApiImplicitParam(name = "workerGroup", value = "WORKER_GROUP", dataType = "String"), + @ApiImplicitParam(name = "processInstancePriority", value = "PROCESS_INSTANCE_PRIORITY", type = "Priority"), @ApiImplicitParam(name = "environmentCode", value = "ENVIRONMENT_CODE", dataType = "Long"), - @ApiImplicitParam(name = "processInstancePriority", value = "PROCESS_INSTANCE_PRIORITY", type = "Priority") }) - @PostMapping("/update") + @PutMapping("/{id}") @ApiException(UPDATE_SCHEDULE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateSchedule(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam(value = "id") Integer id, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable(value = "id") Integer id, @RequestParam(value = "schedule") String schedule, @RequestParam(value = "warningType", required = false, defaultValue = DEFAULT_WARNING_TYPE) WarningType warningType, @RequestParam(value = "warningGroupId", required = false) int warningGroupId, @@ -163,8 +161,8 @@ public class SchedulerController extends BaseController { @RequestParam(value = "environmentCode", required = false, defaultValue = "-1") Long environmentCode, @RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority) { - Map result = schedulerService.updateSchedule(loginUser, projectName, id, schedule, - warningType, warningGroupId, failureStrategy, null, processInstancePriority, workerGroup, environmentCode); + Map result = schedulerService.updateSchedule(loginUser, projectCode, id, schedule, + warningType, warningGroupId, failureStrategy, processInstancePriority, workerGroup, environmentCode); return returnDataList(result); } @@ -172,7 +170,7 @@ public class SchedulerController extends BaseController { * publish schedule setScheduleState * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param id scheduler id * @return publish result code */ @@ -180,13 +178,13 @@ public class SchedulerController extends BaseController { @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "SCHEDULE_ID", required = true, dataType = "Int", example = "100") }) - @PostMapping("/online") + @PostMapping("/{id}/online") @ApiException(PUBLISH_SCHEDULE_ONLINE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result online(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("id") Integer id) { - Map result = schedulerService.setScheduleState(loginUser, projectName, id, ReleaseState.ONLINE); + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable("id") Integer id) { + Map result = schedulerService.setScheduleState(loginUser, projectCode, id, ReleaseState.ONLINE); return returnDataList(result); } @@ -194,7 +192,7 @@ public class SchedulerController extends BaseController { * offline schedule * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param id schedule id * @return operation result code */ @@ -202,14 +200,14 @@ public class SchedulerController extends BaseController { @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "SCHEDULE_ID", required = true, dataType = "Int", example = "100") }) - @PostMapping("/offline") + @PostMapping("/{id}/offline") @ApiException(OFFLINE_SCHEDULE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result offline(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("id") Integer id) { + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable("id") Integer id) { - Map result = schedulerService.setScheduleState(loginUser, projectName, id, ReleaseState.OFFLINE); + Map result = schedulerService.setScheduleState(loginUser, projectCode, id, ReleaseState.OFFLINE); return returnDataList(result); } @@ -217,8 +215,8 @@ public class SchedulerController extends BaseController { * query schedule list paging * * @param loginUser login user - * @param projectName project name - * @param processDefinitionId process definition id + * @param projectCode project code + * @param processDefinitionCode process definition code * @param pageNo page number * @param pageSize page size * @param searchVal search value @@ -228,16 +226,15 @@ public class SchedulerController extends BaseController { @ApiImplicitParams({ @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"), - @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "100") - + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20") }) - @GetMapping("/list-paging") + @GetMapping() @ApiException(QUERY_SCHEDULE_LIST_PAGING_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryScheduleListPaging(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam Integer processDefinitionId, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @RequestParam long processDefinitionCode, @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) { @@ -246,32 +243,31 @@ public class SchedulerController extends BaseController { return result; } searchVal = ParameterUtils.handleEscapes(searchVal); - result = schedulerService.querySchedule(loginUser, projectName, processDefinitionId, searchVal, pageNo, pageSize); + result = schedulerService.querySchedule(loginUser, projectCode, processDefinitionCode, searchVal, pageNo, pageSize); return result; + } /** * delete schedule by id * * @param loginUser login user - * @param projectName project name - * @param scheduleId schedule id + * @param projectCode project code + * @param id scheule id * @return delete result code */ @ApiOperation(value = "deleteScheduleById", notes = "OFFLINE_SCHEDULE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "scheduleId", value = "SCHEDULE_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "projectName", value = "PROJECT_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "id", value = "SCHEDULE_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value = "/delete") + @DeleteMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_SCHEDULE_CRON_BY_ID_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteScheduleById(@RequestAttribute(value = SESSION_USER) User loginUser, - @PathVariable String projectName, - @RequestParam("scheduleId") Integer scheduleId - ) { - Map result = schedulerService.deleteScheduleById(loginUser, projectName, scheduleId); + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable("id") Integer id) { + Map result = schedulerService.deleteScheduleById(loginUser, projectCode, id); return returnDataList(result); } @@ -279,7 +275,7 @@ public class SchedulerController extends BaseController { * query schedule list * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @return schedule list */ @ApiOperation(value = "queryScheduleList", notes = "QUERY_SCHEDULE_LIST_NOTES") @@ -287,8 +283,8 @@ public class SchedulerController extends BaseController { @ApiException(QUERY_SCHEDULE_LIST_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryScheduleList(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName) { - Map result = schedulerService.queryScheduleList(loginUser, projectName); + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode) { + Map result = schedulerService.queryScheduleList(loginUser, projectCode); return returnDataList(result); } @@ -296,25 +292,20 @@ public class SchedulerController extends BaseController { * preview schedule * * @param loginUser login user - * @param projectName project name * @param schedule schedule expression * @return the next five fire time */ @ApiOperation(value = "previewSchedule", notes = "PREVIEW_SCHEDULE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "schedule", value = "SCHEDULE", required = true, dataType = "String", - example = "{'startTime':'2019-06-10 00:00:00'," - + "'endTime':'2019-06-13 00:00:00','crontab':'0 0 3/6 * * ? *'}"), + @ApiImplicitParam(name = "schedule", value = "SCHEDULE", dataType = "String", example = "{'startTime':'2019-06-10 00:00:00','endTime':'2019-06-13 00:00:00','crontab':'0 0 3/6 * * ? *'}"), }) @PostMapping("/preview") @ResponseStatus(HttpStatus.CREATED) @ApiException(PREVIEW_SCHEDULE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result previewSchedule(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam(value = "schedule") String schedule - ) { - Map result = schedulerService.previewSchedule(loginUser, projectName, schedule); + @RequestParam(value = "schedule") String schedule) { + Map result = schedulerService.previewSchedule(loginUser, schedule); return returnDataList(result); } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java new file mode 100644 index 0000000000..fd2bf3e99f --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java @@ -0,0 +1,313 @@ +/* + * 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.controller; + +import static org.apache.dolphinscheduler.api.enums.Status.CREATE_TASK_DEFINITION_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.DELETE_TASK_DEFINE_BY_CODE_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.DELETE_TASK_DEFINITION_VERSION_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.QUERY_DETAIL_OF_TASK_DEFINITION_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_DEFINITION_LIST_PAGING_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_DEFINITION_VERSIONS_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.SWITCH_TASK_DEFINITION_VERSION_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_TASK_DEFINITION_ERROR; + +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; +import org.apache.dolphinscheduler.api.exceptions.ApiException; +import org.apache.dolphinscheduler.api.service.TaskDefinitionService; +import org.apache.dolphinscheduler.api.utils.Result; +import org.apache.dolphinscheduler.common.Constants; +import org.apache.dolphinscheduler.common.utils.ParameterUtils; +import org.apache.dolphinscheduler.dao.entity.User; + +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +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; + +/** + * task definition controller + */ +@Api(tags = "TASK_DEFINITION_TAG") +@RestController +@RequestMapping("projects/{projectCode}/task-definition") +public class TaskDefinitionController extends BaseController { + + @Autowired + private TaskDefinitionService taskDefinitionService; + + /** + * create task definition + * + * @param loginUser login user + * @param projectCode project code + * @param taskDefinitionJson task definition json + * @return create result code + */ + @ApiOperation(value = "save", notes = "CREATE_TASK_DEFINITION_NOTES") + @ApiImplicitParams({ + @ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE", required = true, type = "Long"), + @ApiImplicitParam(name = "taskDefinitionJson", value = "TASK_DEFINITION_JSON", required = true, type = "String") + }) + @PostMapping() + @ResponseStatus(HttpStatus.CREATED) + @ApiException(CREATE_TASK_DEFINITION_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") + public Result createTaskDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @RequestParam(value = "taskDefinitionJson", required = true) String taskDefinitionJson) { + Map result = taskDefinitionService.createTaskDefinition(loginUser, projectCode, taskDefinitionJson); + return returnDataList(result); + } + + /** + * update task definition + * + * @param loginUser login user + * @param projectCode project code + * @param code task definition code + * @param taskDefinitionJsonObj task definition json object + * @return update result code + */ + @ApiOperation(value = "update", notes = "UPDATE_TASK_DEFINITION_NOTES") + @ApiImplicitParams({ + @ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE", required = true, type = "Long"), + @ApiImplicitParam(name = "code", value = "TASK_DEFINITION_CODE", required = true, dataType = "Long", example = "1"), + @ApiImplicitParam(name = "taskDefinitionJsonObj", value = "TASK_DEFINITION_JSON", required = true, type = "String") + }) + @PutMapping(value = "/{code}") + @ResponseStatus(HttpStatus.OK) + @ApiException(UPDATE_TASK_DEFINITION_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") + public Result updateTaskDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable(value = "code") long code, + @RequestParam(value = "taskDefinitionJsonObj", required = true) String taskDefinitionJsonObj) { + Map result = taskDefinitionService.updateTaskDefinition(loginUser, projectCode, code, taskDefinitionJsonObj); + return returnDataList(result); + } + + /** + * query task definition version paging list info + * + * @param loginUser login user info + * @param projectCode project code + * @param code task definition code + * @param pageNo the task definition version list current page number + * @param pageSize the task definition version list page size + * @param code the task definition code + * @return the task definition version list + */ + @ApiOperation(value = "queryVersions", notes = "QUERY_TASK_DEFINITION_VERSIONS_NOTES") + @ApiImplicitParams({ + @ApiImplicitParam(name = "code", value = "TASK_DEFINITION_CODE", required = true, dataType = "Long", example = "1"), + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "10") + }) + @GetMapping(value = "/{code}/versions") + @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_TASK_DEFINITION_VERSIONS_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") + public Result queryTaskDefinitionVersions(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable(value = "code") long code, + @RequestParam(value = "pageNo") int pageNo, + @RequestParam(value = "pageSize") int pageSize) { + Result result = checkPageParams(pageNo, pageSize); + if (!result.checkResult()) { + return result; + } + return taskDefinitionService.queryTaskDefinitionVersions(loginUser, projectCode, code, pageNo, pageSize); + } + + /** + * switch task definition version + * + * @param loginUser login user info + * @param projectCode project code + * @param code the task definition code + * @param version the version user want to switch + * @return switch version result code + */ + @ApiOperation(value = "switchVersion", notes = "SWITCH_TASK_DEFINITION_VERSION_NOTES") + @ApiImplicitParams({ + @ApiImplicitParam(name = "code", value = "TASK_DEFINITION_CODE", required = true, dataType = "Long", example = "1"), + @ApiImplicitParam(name = "version", value = "VERSION", required = true, dataType = "Int", example = "100") + }) + @GetMapping(value = "/{code}/versions/{version}") + @ResponseStatus(HttpStatus.OK) + @ApiException(SWITCH_TASK_DEFINITION_VERSION_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") + public Result switchTaskDefinitionVersion(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable(value = "code") long code, + @PathVariable(value = "version") int version) { + Map result = taskDefinitionService.switchVersion(loginUser, projectCode, code, version); + return returnDataList(result); + } + + /** + * delete the certain task definition version by version and code + * + * @param loginUser login user info + * @param projectCode project code + * @param code the task definition code + * @param version the task definition version user want to delete + * @return delete version result code + */ + @ApiOperation(value = "deleteVersion", notes = "DELETE_TASK_DEFINITION_VERSION_NOTES") + @ApiImplicitParams({ + @ApiImplicitParam(name = "code", value = "TASK_DEFINITION_CODE", required = true, dataType = "Long", example = "1"), + @ApiImplicitParam(name = "version", value = "VERSION", required = true, dataType = "Int", example = "100") + }) + @DeleteMapping(value = "/{code}/versions/{version}") + @ResponseStatus(HttpStatus.OK) + @ApiException(DELETE_TASK_DEFINITION_VERSION_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") + public Result deleteTaskDefinitionVersion(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable(value = "code") long code, + @PathVariable(value = "version") int version) { + Map result = taskDefinitionService.deleteByCodeAndVersion(loginUser, projectCode, code, version); + return returnDataList(result); + } + + /** + * delete task definition by code + * + * @param loginUser login user + * @param projectCode project code + * @param code the task definition code + * @return delete result code + */ + @ApiOperation(value = "deleteTaskDefinition", notes = "DELETE_TASK_DEFINITION_BY_CODE_NOTES") + @ApiImplicitParams({ + @ApiImplicitParam(name = "code", value = "TASK_DEFINITION_CODE", required = true, dataType = "Long", example = "1") + }) + @DeleteMapping(value = "/{code}") + @ResponseStatus(HttpStatus.OK) + @ApiException(DELETE_TASK_DEFINE_BY_CODE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") + public Result deleteTaskDefinitionByCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable(value = "code") long code) { + Map result = taskDefinitionService.deleteTaskDefinitionByCode(loginUser, projectCode, code); + return returnDataList(result); + } + + /** + * query detail of task definition by code + * + * @param loginUser login user + * @param projectCode project code + * @param code the task definition code + * @return task definition detail + */ + @ApiOperation(value = "queryTaskDefinitionByCode", notes = "QUERY_TASK_DEFINITION_DETAIL_NOTES") + @ApiImplicitParams({ + @ApiImplicitParam(name = "code", value = "TASK_DEFINITION_CODE", required = true, dataType = "Long", example = "1") + }) + @GetMapping(value = "/{code}") + @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_DETAIL_OF_TASK_DEFINITION_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") + public Result queryTaskDefinitionDetail(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable(value = "code") long code) { + Map result = taskDefinitionService.queryTaskDefinitionDetail(loginUser, projectCode, code); + return returnDataList(result); + } + + /** + * query task definition list paging + * + * @param loginUser login user + * @param projectCode project code + * @param taskType taskType + * @param searchVal search value + * @param userId user id + * @param pageNo page number + * @param pageSize page size + * @return task definition page + */ + @ApiOperation(value = "queryTaskDefinitionListPaging", notes = "QUERY_TASK_DEFINITION_LIST_PAGING_NOTES") + @ApiImplicitParams({ + @ApiImplicitParam(name = "taskType", value = "TASK_TYPE", required = false, type = "String"), + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", required = false, type = "String"), + @ApiImplicitParam(name = "userId", value = "USER_ID", required = false, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "10") + }) + @GetMapping() + @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_TASK_DEFINITION_LIST_PAGING_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") + public Result queryTaskDefinitionListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @RequestParam(value = "taskType", required = false) String taskType, + @RequestParam(value = "searchVal", required = false) String searchVal, + @RequestParam(value = "userId", required = false, defaultValue = "0") Integer userId, + @RequestParam("pageNo") Integer pageNo, + @RequestParam("pageSize") Integer pageSize) { + Result result = checkPageParams(pageNo, pageSize); + if (!result.checkResult()) { + return result; + } + taskType = ParameterUtils.handleEscapes(taskType); + searchVal = ParameterUtils.handleEscapes(searchVal); + return taskDefinitionService.queryTaskDefinitionListPaging(loginUser, projectCode, taskType, searchVal, userId, pageNo, pageSize); + } + + /** + * gen task code list + * + * @param loginUser login user + * @param genNum gen num + * @return task code list + */ + @ApiOperation(value = "genTaskCodeList", notes = "GEN_TASK_CODE_LIST_NOTES") + @ApiImplicitParams({ + @ApiImplicitParam(name = "genNum", value = "GEN_NUM", required = true, dataType = "Int", example = "1") + }) + @GetMapping(value = "/gen-task-codes") + @ResponseStatus(HttpStatus.OK) + @ApiException(LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") + public Result genTaskCodeList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @RequestParam("genNum") Integer genNum) { + Map result = taskDefinitionService.genTaskCodeList(loginUser, genNum); + return returnDataList(result); + } +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceController.java index 217844ffa3..35ad434f4e 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceController.java @@ -54,49 +54,48 @@ import springfox.documentation.annotations.ApiIgnore; */ @Api(tags = "TASK_INSTANCE_TAG") @RestController -@RequestMapping("/projects/{projectName}/task-instance") +@RequestMapping("/projects/{projectCode}/task-instances") public class TaskInstanceController extends BaseController { - @Autowired TaskInstanceService taskInstanceService; /** * query task list paging * - * @param loginUser login user - * @param projectName project name + * @param loginUser login user + * @param projectCode project code * @param processInstanceId process instance id - * @param searchVal search value - * @param taskName task name - * @param stateType state type - * @param host host - * @param startTime start time - * @param endTime end time - * @param pageNo page number - * @param pageSize page size + * @param searchVal search value + * @param taskName task name + * @param stateType state type + * @param host host + * @param startTime start time + * @param endTime end time + * @param pageNo page number + * @param pageSize page size * @return task list page */ @ApiOperation(value = "queryTaskListPaging", notes = "QUERY_TASK_INSTANCE_LIST_PAGING_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = false, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "processInstanceName", value = "PROCESS_INSTANCE_NAME", required = false, type = "String"), - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"), - @ApiImplicitParam(name = "taskName", value = "TASK_NAME", type = "String"), - @ApiImplicitParam(name = "executorName", value = "EXECUTOR_NAME", type = "String"), - @ApiImplicitParam(name = "stateType", value = "EXECUTION_STATUS", type = "ExecutionStatus"), - @ApiImplicitParam(name = "host", value = "HOST", type = "String"), - @ApiImplicitParam(name = "startDate", value = "START_DATE", type = "String"), - @ApiImplicitParam(name = "endDate", value = "END_DATE", type = "String"), - @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") + @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = false, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "processInstanceName", value = "PROCESS_INSTANCE_NAME", required = false, type = "String"), + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"), + @ApiImplicitParam(name = "taskName", value = "TASK_NAME", type = "String"), + @ApiImplicitParam(name = "executorName", value = "EXECUTOR_NAME", type = "String"), + @ApiImplicitParam(name = "stateType", value = "EXECUTION_STATUS", type = "ExecutionStatus"), + @ApiImplicitParam(name = "host", value = "HOST", type = "String"), + @ApiImplicitParam(name = "startDate", value = "START_DATE", type = "String"), + @ApiImplicitParam(name = "endDate", value = "END_DATE", type = "String"), + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") }) - @GetMapping("/list-paging") + @GetMapping() @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_TASK_LIST_PAGING_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryTaskListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, @RequestParam(value = "processInstanceId", required = false, defaultValue = "0") Integer processInstanceId, @RequestParam(value = "processInstanceName", required = false) String processInstanceName, @RequestParam(value = "searchVal", required = false) String searchVal, @@ -113,31 +112,31 @@ public class TaskInstanceController extends BaseController { return result; } searchVal = ParameterUtils.handleEscapes(searchVal); - result = taskInstanceService.queryTaskListPaging( - loginUser, projectName, processInstanceId, processInstanceName, taskName, executorName, startTime, endTime, searchVal, stateType, host, pageNo, pageSize); + result = taskInstanceService.queryTaskListPaging(loginUser, projectCode, processInstanceId, processInstanceName, + taskName, executorName, startTime, endTime, searchVal, stateType, host, pageNo, pageSize); return result; } /** * change one task instance's state from FAILURE to FORCED_SUCCESS * - * @param loginUser login user - * @param projectName project name - * @param taskInstanceId task instance id + * @param loginUser login user + * @param projectCode project code + * @param id task instance id * @return the result code and msg */ @ApiOperation(value = "force-success", notes = "FORCE_TASK_SUCCESS") @ApiImplicitParams({ - @ApiImplicitParam(name = "taskInstanceId", value = "TASK_INSTANCE_ID", required = true, dataType = "Int", example = "12") + @ApiImplicitParam(name = "id", value = "TASK_INSTANCE_ID", required = true, dataType = "Int", example = "12") }) - @PostMapping(value = "/force-success") + @PostMapping(value = "/{id}/force-success") @ResponseStatus(HttpStatus.OK) @ApiException(FORCE_TASK_SUCCESS_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result forceTaskSuccess(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam(value = "taskInstanceId") Integer taskInstanceId) { - Map result = taskInstanceService.forceTaskSuccess(loginUser, projectName, taskInstanceId); + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @PathVariable(value = "id") Integer id) { + Map result = taskInstanceService.forceTaskSuccess(loginUser, projectCode, id); return returnDataList(result); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TenantController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TenantController.java index 3280ac6187..6d1ea6b218 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TenantController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TenantController.java @@ -36,8 +36,11 @@ import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -55,7 +58,7 @@ import springfox.documentation.annotations.ApiIgnore; */ @Api(tags = "TENANT_TAG") @RestController -@RequestMapping("/tenant") +@RequestMapping("/tenants") public class TenantController extends BaseController { @Autowired @@ -72,12 +75,11 @@ public class TenantController extends BaseController { */ @ApiOperation(value = "createTenant", notes = "CREATE_TENANT_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "tenantCode", value = "TENANT_CODE", required = true, dataType = "String"), - @ApiImplicitParam(name = "queueId", value = "QUEUE_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "description", value = "TENANT_DESC", dataType = "String") - + @ApiImplicitParam(name = "tenantCode", value = "TENANT_CODE", required = true, dataType = "String"), + @ApiImplicitParam(name = "queueId", value = "QUEUE_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "description", value = "TENANT_DESC", dataType = "String") }) - @PostMapping(value = "/create") + @PostMapping() @ResponseStatus(HttpStatus.CREATED) @ApiException(CREATE_TENANT_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -101,11 +103,11 @@ public class TenantController extends BaseController { */ @ApiOperation(value = "queryTenantlistPaging", notes = "QUERY_TENANT_LIST_PAGING_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), - @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") }) - @GetMapping(value = "/list-paging") + @GetMapping() @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_TENANT_LIST_PAGING_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -153,18 +155,17 @@ public class TenantController extends BaseController { */ @ApiOperation(value = "updateTenant", notes = "UPDATE_TENANT_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "TENANT_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "tenantCode", value = "TENANT_CODE", required = true, dataType = "String"), - @ApiImplicitParam(name = "queueId", value = "QUEUE_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "description", value = "TENANT_DESC", type = "String") - + @ApiImplicitParam(name = "id", value = "TENANT_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "tenantCode", value = "TENANT_CODE", required = true, dataType = "String"), + @ApiImplicitParam(name = "queueId", value = "QUEUE_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "description", value = "TENANT_DESC", type = "String") }) - @PostMapping(value = "/update") + @PutMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_TENANT_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateTenant(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int id, + @PathVariable(value = "id") int id, @RequestParam(value = "tenantCode") String tenantCode, @RequestParam(value = "queueId") int queueId, @RequestParam(value = "description", required = false) String description) throws Exception { @@ -182,15 +183,14 @@ public class TenantController extends BaseController { */ @ApiOperation(value = "deleteTenantById", notes = "DELETE_TENANT_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "TENANT_ID", required = true, dataType = "Int", example = "100") - + @ApiImplicitParam(name = "id", value = "TENANT_ID", required = true, dataType = "Int", example = "100") }) - @PostMapping(value = "/delete") + @DeleteMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_TENANT_BY_ID_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteTenantById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int id) throws Exception { + @PathVariable(value = "id") int id) throws Exception { Map result = tenantService.deleteTenantById(loginUser, id); return returnDataList(result); } @@ -204,9 +204,9 @@ public class TenantController extends BaseController { */ @ApiOperation(value = "verifyTenantCode", notes = "VERIFY_TENANT_CODE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "tenantCode", value = "TENANT_CODE", required = true, dataType = "String") + @ApiImplicitParam(name = "tenantCode", value = "TENANT_CODE", required = true, dataType = "String") }) - @GetMapping(value = "/verify-tenant-code") + @GetMapping(value = "/verify-code") @ResponseStatus(HttpStatus.OK) @ApiException(VERIFY_OS_TENANT_CODE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UiPluginController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UiPluginController.java index 276f4ea9fe..fc1c00d2f4 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UiPluginController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UiPluginController.java @@ -31,6 +31,8 @@ import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +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; @@ -62,7 +64,7 @@ public class UiPluginController extends BaseController { @ApiImplicitParams({ @ApiImplicitParam(name = "pluginType", value = "pluginType", required = true, dataType = "PluginType"), }) - @PostMapping(value = "/queryUiPluginsByType") + @GetMapping(value = "/query-by-type") @ResponseStatus(HttpStatus.CREATED) @ApiException(QUERY_PLUGINS_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -75,14 +77,14 @@ public class UiPluginController extends BaseController { @ApiOperation(value = "queryUiPluginDetailById", notes = "QUERY_UI_PLUGIN_DETAIL_BY_ID") @ApiImplicitParams({ - @ApiImplicitParam(name = "pluginId", value = "PLUGIN_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "id", value = "PLUGIN_ID", required = true, dataType = "Int", example = "100"), }) - @PostMapping(value = "/queryUiPluginDetailById") + @GetMapping(value = "/{id}") @ResponseStatus(HttpStatus.CREATED) @ApiException(QUERY_PLUGINS_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryUiPluginDetailById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("pluginId") Integer pluginId) { + @PathVariable("id") Integer pluginId) { Map result = uiPluginService.queryUiPluginDetailById(pluginId); return returnDataList(result); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java index 1012ec9daf..11de0389ad 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java @@ -79,24 +79,24 @@ public class UsersController extends BaseController { /** * create user * - * @param loginUser login user - * @param userName user name + * @param loginUser login user + * @param userName user name * @param userPassword user password - * @param email email - * @param tenantId tenant id - * @param phone phone - * @param queue queue + * @param email email + * @param tenantId tenant id + * @param phone phone + * @param queue queue * @return create result code */ @ApiOperation(value = "createUser", notes = "CREATE_USER_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userName", value = "USER_NAME", required = true, type = "String"), - @ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", required = true, type = "String"), - @ApiImplicitParam(name = "tenantId", value = "TENANT_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "queue", value = "QUEUE", dataType = "String"), - @ApiImplicitParam(name = "email", value = "EMAIL", required = true, dataType = "String"), - @ApiImplicitParam(name = "phone", value = "PHONE", dataType = "String"), - @ApiImplicitParam(name = "state", value = "STATE", dataType = "Int", example = "1") + @ApiImplicitParam(name = "userName", value = "USER_NAME", required = true, type = "String"), + @ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", required = true, type = "String"), + @ApiImplicitParam(name = "tenantId", value = "TENANT_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "queue", value = "QUEUE", dataType = "String"), + @ApiImplicitParam(name = "email", value = "EMAIL", required = true, dataType = "String"), + @ApiImplicitParam(name = "phone", value = "PHONE", dataType = "String"), + @ApiImplicitParam(name = "state", value = "STATE", dataType = "Int", example = "1") }) @PostMapping(value = "/create") @ResponseStatus(HttpStatus.CREATED) @@ -118,16 +118,16 @@ public class UsersController extends BaseController { * query user list paging * * @param loginUser login user - * @param pageNo page number - * @param searchVal search value - * @param pageSize page size + * @param pageNo page number + * @param searchVal search avlue + * @param pageSize page size * @return user list page */ @ApiOperation(value = "queryUserList", notes = "QUERY_USER_LIST_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "10"), - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String") + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "10"), + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String") }) @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) @@ -151,26 +151,26 @@ public class UsersController extends BaseController { /** * update user * - * @param loginUser login user - * @param id user id - * @param userName user name + * @param loginUser login user + * @param id user id + * @param userName user name * @param userPassword user password - * @param email email - * @param tenantId tenant id - * @param phone phone - * @param queue queue + * @param email email + * @param tenantId tennat id + * @param phone phone + * @param queue queue * @return update result code */ @ApiOperation(value = "updateUser", notes = "UPDATE_USER_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "USER_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "userName", value = "USER_NAME", required = true, type = "String"), - @ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", required = true, type = "String"), - @ApiImplicitParam(name = "tenantId", value = "TENANT_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "queue", value = "QUEUE", dataType = "String"), - @ApiImplicitParam(name = "email", value = "EMAIL", required = true, dataType = "String"), - @ApiImplicitParam(name = "phone", value = "PHONE", dataType = "String"), - @ApiImplicitParam(name = "state", value = "STATE", dataType = "Int", example = "1") + @ApiImplicitParam(name = "id", value = "USER_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "userName", value = "USER_NAME", required = true, type = "String"), + @ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", required = true, type = "String"), + @ApiImplicitParam(name = "tenantId", value = "TENANT_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "queue", value = "QUEUE", dataType = "String"), + @ApiImplicitParam(name = "email", value = "EMAIL", required = true, dataType = "String"), + @ApiImplicitParam(name = "phone", value = "PHONE", dataType = "String"), + @ApiImplicitParam(name = "state", value = "STATE", dataType = "Int", example = "1") }) @PostMapping(value = "/update") @ResponseStatus(HttpStatus.OK) @@ -193,12 +193,12 @@ public class UsersController extends BaseController { * delete user by id * * @param loginUser login user - * @param id user id + * @param id user id * @return delete result code */ @ApiOperation(value = "delUserById", notes = "DELETE_USER_BY_ID_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "USER_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "id", value = "USER_ID", required = true, dataType = "Int", example = "100") }) @PostMapping(value = "/delete") @ResponseStatus(HttpStatus.OK) @@ -213,15 +213,15 @@ public class UsersController extends BaseController { /** * grant project * - * @param loginUser login user - * @param userId user id + * @param loginUser login user + * @param userId user id * @param projectIds project id array * @return grant result code */ @ApiOperation(value = "grantProject", notes = "GRANT_PROJECT_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "projectIds", value = "PROJECT_IDS", required = true, type = "String") + @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "projectIds", value = "PROJECT_IDS", required = true, type = "String") }) @PostMapping(value = "/grant-project") @ResponseStatus(HttpStatus.OK) @@ -237,15 +237,15 @@ public class UsersController extends BaseController { /** * grant resource * - * @param loginUser login user - * @param userId user id + * @param loginUser login user + * @param userId user id * @param resourceIds resource id array * @return grant result code */ @ApiOperation(value = "grantResource", notes = "GRANT_RESOURCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "resourceIds", value = "RESOURCE_IDS", required = true, type = "String") + @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "resourceIds", value = "RESOURCE_IDS", required = true, type = "String") }) @PostMapping(value = "/grant-file") @ResponseStatus(HttpStatus.OK) @@ -263,14 +263,14 @@ public class UsersController extends BaseController { * grant udf function * * @param loginUser login user - * @param userId user id - * @param udfIds udf id array + * @param userId user id + * @param udfIds udf id array * @return grant result code */ @ApiOperation(value = "grantUDFFunc", notes = "GRANT_UDF_FUNC_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "udfIds", value = "UDF_IDS", required = true, type = "String") + @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "udfIds", value = "UDF_IDS", required = true, type = "String") }) @PostMapping(value = "/grant-udf-func") @ResponseStatus(HttpStatus.OK) @@ -287,15 +287,15 @@ public class UsersController extends BaseController { /** * grant datasource * - * @param loginUser login user - * @param userId user id + * @param loginUser login user + * @param userId user id * @param datasourceIds data source id array * @return grant result code */ @ApiOperation(value = "grantDataSource", notes = "GRANT_DATASOURCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "datasourceIds", value = "DATASOURCE_IDS", required = true, type = "String") + @ApiImplicitParam(name = "userId", value = "USER_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "datasourceIds", value = "DATASOURCE_IDS", required = true, type = "String") }) @PostMapping(value = "/grant-datasource") @ResponseStatus(HttpStatus.OK) @@ -362,12 +362,12 @@ public class UsersController extends BaseController { * verify username * * @param loginUser login user - * @param userName user name + * @param userName user name * @return true if user name not exists, otherwise return false */ @ApiOperation(value = "verifyUserName", notes = "VERIFY_USER_NAME_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userName", value = "USER_NAME", required = true, type = "String") + @ApiImplicitParam(name = "userName", value = "USER_NAME", required = true, type = "String") }) @GetMapping(value = "/verify-user-name") @ResponseStatus(HttpStatus.OK) @@ -383,13 +383,13 @@ public class UsersController extends BaseController { /** * unauthorized user * - * @param loginUser login user + * @param loginUser login user * @param alertgroupId alert group id * @return unauthorize result code */ @ApiOperation(value = "unauthorizedUser", notes = "UNAUTHORIZED_USER_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "alertgroupId", value = "ALERT_GROUP_ID", required = true, type = "String") + @ApiImplicitParam(name = "alertgroupId", value = "ALERT_GROUP_ID", required = true, type = "String") }) @GetMapping(value = "/unauth-user") @ResponseStatus(HttpStatus.OK) @@ -405,13 +405,13 @@ public class UsersController extends BaseController { /** * authorized user * - * @param loginUser login user + * @param loginUser login user * @param alertgroupId alert group id * @return authorized result code */ @ApiOperation(value = "authorizedUser", notes = "AUTHORIZED_USER_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "alertgroupId", value = "ALERT_GROUP_ID", required = true, type = "String") + @ApiImplicitParam(name = "alertgroupId", value = "ALERT_GROUP_ID", required = true, type = "String") }) @GetMapping(value = "/authed-user") @ResponseStatus(HttpStatus.OK) @@ -431,26 +431,26 @@ public class UsersController extends BaseController { /** * user registry * - * @param userName user name - * @param userPassword user password + * @param userName user name + * @param userPassword user password * @param repeatPassword repeat password - * @param email user email + * @param email user email */ - @ApiOperation(value = "registerUser",notes = "REGISTER_USER_NOTES") + @ApiOperation(value = "registerUser", notes = "REGISTER_USER_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userName", value = "USER_NAME", required = true, type = "String"), - @ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", required = true, type = "String"), - @ApiImplicitParam(name = "repeatPassword", value = "REPEAT_PASSWORD", required = true, type = "String"), - @ApiImplicitParam(name = "email", value = "EMAIL", required = true, type = "String"), + @ApiImplicitParam(name = "userName", value = "USER_NAME", required = true, type = "String"), + @ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", required = true, type = "String"), + @ApiImplicitParam(name = "repeatPassword", value = "REPEAT_PASSWORD", required = true, type = "String"), + @ApiImplicitParam(name = "email", value = "EMAIL", required = true, type = "String"), }) @PostMapping("/register") @ResponseStatus(HttpStatus.OK) @ApiException(CREATE_USER_ERROR) @AccessLogAnnotation public Result registerUser(@RequestParam(value = "userName") String userName, - @RequestParam(value = "userPassword") String userPassword, - @RequestParam(value = "repeatPassword") String repeatPassword, - @RequestParam(value = "email") String email) throws Exception { + @RequestParam(value = "userPassword") String userPassword, + @RequestParam(value = "repeatPassword") String repeatPassword, + @RequestParam(value = "email") String email) throws Exception { userName = ParameterUtils.handleEscapes(userName); userPassword = ParameterUtils.handleEscapes(userPassword); repeatPassword = ParameterUtils.handleEscapes(repeatPassword); @@ -462,11 +462,11 @@ public class UsersController extends BaseController { /** * user activate * - * @param userName user name + * @param userName user name */ - @ApiOperation(value = "activateUser",notes = "ACTIVATE_USER_NOTES") + @ApiOperation(value = "activateUser", notes = "ACTIVATE_USER_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userName", value = "USER_NAME", type = "String"), + @ApiImplicitParam(name = "userName", value = "USER_NAME", type = "String"), }) @PostMapping("/activate") @ResponseStatus(HttpStatus.OK) @@ -482,18 +482,18 @@ public class UsersController extends BaseController { /** * user batch activate * - * @param userNames user names + * @param userNames user names */ - @ApiOperation(value = "batchActivateUser",notes = "BATCH_ACTIVATE_USER_NOTES") + @ApiOperation(value = "batchActivateUser", notes = "BATCH_ACTIVATE_USER_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userNames", value = "USER_NAMES", required = true, type = "String"), + @ApiImplicitParam(name = "userNames", value = "USER_NAMES", required = true, type = "String"), }) @PostMapping("/batch/activate") @ResponseStatus(HttpStatus.OK) @ApiException(UPDATE_USER_ERROR) @AccessLogAnnotation public Result batchActivateUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestBody List userNames) { + @RequestBody List userNames) { List formatUserNames = userNames.stream().map(ParameterUtils::handleEscapes).collect(Collectors.toList()); Map result = usersService.batchActivateUser(loginUser, formatUserNames); return returnDataList(result); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageController.java index 507580d60b..f32a280e29 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageController.java @@ -54,7 +54,7 @@ import springfox.documentation.annotations.ApiIgnore; */ @Api(tags = "WORK_FLOW_LINEAGE_TAG") @RestController -@RequestMapping("lineages/{projectId}") +@RequestMapping("lineages/{projectCode}") public class WorkFlowLineageController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(WorkFlowLineageController.class); @@ -66,14 +66,14 @@ public class WorkFlowLineageController extends BaseController { @ResponseStatus(HttpStatus.OK) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result> queryWorkFlowLineageByName(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, - @ApiParam(name = "projectId", value = "PROJECT_ID", required = true, example = "1") @PathVariable int projectId, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true, example = "1") @PathVariable long projectCode, @ApiIgnore @RequestParam(value = "searchVal", required = false) String searchVal) { try { searchVal = ParameterUtils.handleEscapes(searchVal); - Map result = workFlowLineageService.queryWorkFlowLineageByName(searchVal,projectId); + Map result = workFlowLineageService.queryWorkFlowLineageByName(searchVal, projectCode); return returnDataList(result); } catch (Exception e) { - logger.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(),e); + logger.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(), e); return error(QUERY_WORKFLOW_LINEAGE_ERROR.getCode(), QUERY_WORKFLOW_LINEAGE_ERROR.getMsg()); } } @@ -83,7 +83,7 @@ public class WorkFlowLineageController extends BaseController { @ResponseStatus(HttpStatus.OK) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result> queryWorkFlowLineageByIds(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, - @ApiParam(name = "projectId", value = "PROJECT_ID", required = true, example = "1") @PathVariable int projectId, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true, example = "1") @PathVariable long projectCode, @ApiIgnore @RequestParam(value = "ids", required = false) String ids) { try { ids = ParameterUtils.handleEscapes(ids); @@ -95,10 +95,10 @@ public class WorkFlowLineageController extends BaseController { } } - Map result = workFlowLineageService.queryWorkFlowLineageByIds(idsSet, projectId); + Map result = workFlowLineageService.queryWorkFlowLineageByIds(idsSet, projectCode); return returnDataList(result); } catch (Exception e) { - logger.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(),e); + logger.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(), e); return error(QUERY_WORKFLOW_LINEAGE_ERROR.getCode(), QUERY_WORKFLOW_LINEAGE_ERROR.getMsg()); } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkerGroupController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkerGroupController.java index e22a46622b..7ddf6e6127 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkerGroupController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkerGroupController.java @@ -34,7 +34,9 @@ import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +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; @@ -53,7 +55,7 @@ import springfox.documentation.annotations.ApiIgnore; */ @Api(tags = "WORKER_GROUP_TAG") @RestController -@RequestMapping("/worker-group") +@RequestMapping("/worker-groups") public class WorkerGroupController extends BaseController { @Autowired @@ -63,18 +65,18 @@ public class WorkerGroupController extends BaseController { * create or update a worker group * * @param loginUser login user - * @param id worker group id - * @param name worker group name - * @param addrList addr list + * @param id worker group id + * @param name worker group name + * @param addrList addr list * @return create or update result code */ @ApiOperation(value = "saveWorkerGroup", notes = "CREATE_WORKER_GROUP_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "WORKER_GROUP_ID", dataType = "Int", example = "10", defaultValue = "0"), - @ApiImplicitParam(name = "name", value = "WORKER_GROUP_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "addrList", value = "WORKER_ADDR_LIST", required = true, dataType = "String") + @ApiImplicitParam(name = "id", value = "WORKER_GROUP_ID", dataType = "Int", example = "10", defaultValue = "0"), + @ApiImplicitParam(name = "name", value = "WORKER_GROUP_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "addrList", value = "WORKER_ADDR_LIST", required = true, dataType = "String") }) - @PostMapping(value = "/save") + @PostMapping() @ResponseStatus(HttpStatus.OK) @ApiException(SAVE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -91,18 +93,18 @@ public class WorkerGroupController extends BaseController { * query worker groups paging * * @param loginUser login user - * @param pageNo page number + * @param pageNo page number * @param searchVal search value - * @param pageSize page size + * @param pageSize page size * @return worker group list page */ @ApiOperation(value = "queryAllWorkerGroupsPaging", notes = "QUERY_WORKER_GROUP_PAGING_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20"), - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String") + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20"), + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String") }) - @GetMapping(value = "/list-paging") + @GetMapping() @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_WORKER_GROUP_FAIL) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -128,7 +130,7 @@ public class WorkerGroupController extends BaseController { * @return all worker group list */ @ApiOperation(value = "queryAllWorkerGroups", notes = "QUERY_WORKER_GROUP_LIST_NOTES") - @GetMapping(value = "/all-groups") + @GetMapping(value = "/all") @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_WORKER_GROUP_FAIL) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") @@ -141,19 +143,19 @@ public class WorkerGroupController extends BaseController { * delete worker group by id * * @param loginUser login user - * @param id group id + * @param id group id * @return delete result code */ @ApiOperation(value = "deleteById", notes = "DELETE_WORKER_GROUP_BY_ID_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "WORKER_GROUP_ID", required = true, dataType = "Int", example = "10"), + @ApiImplicitParam(name = "id", value = "WORKER_GROUP_ID", required = true, dataType = "Int", example = "10"), }) - @PostMapping(value = "/delete-by-id") + @DeleteMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) @ApiException(DELETE_WORKER_GROUP_FAIL) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("id") Integer id + @PathVariable("id") Integer id ) { Map result = workerGroupService.deleteWorkerGroupById(loginUser, id); return returnDataList(result); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/DagDataSchedule.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/DagDataSchedule.java new file mode 100644 index 0000000000..249d8b3a68 --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/DagDataSchedule.java @@ -0,0 +1,47 @@ +/* + * 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.dto; + +import org.apache.dolphinscheduler.dao.entity.DagData; +import org.apache.dolphinscheduler.dao.entity.Schedule; + +/** + * DagDataSchedule + */ +public class DagDataSchedule extends DagData { + + /** + * schedule + */ + private Schedule schedule; + + public DagDataSchedule(DagData dagData) { + super(); + this.setProcessDefinition(dagData.getProcessDefinition()); + this.setTaskDefinitionList(dagData.getTaskDefinitionList()); + this.setProcessTaskRelationList(dagData.getProcessTaskRelationList()); + } + + public Schedule getSchedule() { + return schedule; + } + + public void setSchedule(Schedule schedule) { + this.schedule = schedule; + } +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/ProcessMeta.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/ProcessMeta.java deleted file mode 100644 index 61e3752c69..0000000000 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/ProcessMeta.java +++ /dev/null @@ -1,231 +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.dto; - -/** - * ProcessMeta - */ -public class ProcessMeta { - - /** - * project name - */ - private String projectName; - - /** - * process definition name - */ - private String processDefinitionName; - - /** - * processs definition json - */ - private String processDefinitionJson; - - /** - * process definition desc - */ - private String processDefinitionDescription; - - /** - * process definition locations - */ - private String processDefinitionLocations; - - /** - * process definition connects - */ - private String processDefinitionConnects; - - /** - * warning type - */ - private String scheduleWarningType; - - /** - * warning group id - */ - private Integer scheduleWarningGroupId; - - /** - * warning group name - */ - private String scheduleWarningGroupName; - - /** - * start time - */ - private String scheduleStartTime; - - /** - * end time - */ - private String scheduleEndTime; - - /** - * crontab - */ - private String scheduleCrontab; - - /** - * failure strategy - */ - private String scheduleFailureStrategy; - - /** - * release state - */ - private String scheduleReleaseState; - - /** - * process instance priority - */ - private String scheduleProcessInstancePriority; - - /** - * worker group name - */ - private String scheduleWorkerGroupName; - - public String getProjectName() { - return projectName; - } - - public void setProjectName(String projectName) { - this.projectName = projectName; - } - - public String getProcessDefinitionName() { - return processDefinitionName; - } - - public void setProcessDefinitionName(String processDefinitionName) { - this.processDefinitionName = processDefinitionName; - } - - public String getProcessDefinitionJson() { - return processDefinitionJson; - } - - public void setProcessDefinitionJson(String processDefinitionJson) { - this.processDefinitionJson = processDefinitionJson; - } - - public String getProcessDefinitionDescription() { - return processDefinitionDescription; - } - - public void setProcessDefinitionDescription(String processDefinitionDescription) { - this.processDefinitionDescription = processDefinitionDescription; - } - - public String getProcessDefinitionLocations() { - return processDefinitionLocations; - } - - public void setProcessDefinitionLocations(String processDefinitionLocations) { - this.processDefinitionLocations = processDefinitionLocations; - } - - public String getProcessDefinitionConnects() { - return processDefinitionConnects; - } - - public void setProcessDefinitionConnects(String processDefinitionConnects) { - this.processDefinitionConnects = processDefinitionConnects; - } - - public String getScheduleWarningType() { - return scheduleWarningType; - } - - public void setScheduleWarningType(String scheduleWarningType) { - this.scheduleWarningType = scheduleWarningType; - } - - public Integer getScheduleWarningGroupId() { - return scheduleWarningGroupId; - } - - public void setScheduleWarningGroupId(int scheduleWarningGroupId) { - this.scheduleWarningGroupId = scheduleWarningGroupId; - } - - public String getScheduleWarningGroupName() { - return scheduleWarningGroupName; - } - - public void setScheduleWarningGroupName(String scheduleWarningGroupName) { - this.scheduleWarningGroupName = scheduleWarningGroupName; - } - - public String getScheduleStartTime() { - return scheduleStartTime; - } - - public void setScheduleStartTime(String scheduleStartTime) { - this.scheduleStartTime = scheduleStartTime; - } - - public String getScheduleEndTime() { - return scheduleEndTime; - } - - public void setScheduleEndTime(String scheduleEndTime) { - this.scheduleEndTime = scheduleEndTime; - } - - public String getScheduleCrontab() { - return scheduleCrontab; - } - - public void setScheduleCrontab(String scheduleCrontab) { - this.scheduleCrontab = scheduleCrontab; - } - - public String getScheduleFailureStrategy() { - return scheduleFailureStrategy; - } - - public void setScheduleFailureStrategy(String scheduleFailureStrategy) { - this.scheduleFailureStrategy = scheduleFailureStrategy; - } - - public String getScheduleReleaseState() { - return scheduleReleaseState; - } - - public void setScheduleReleaseState(String scheduleReleaseState) { - this.scheduleReleaseState = scheduleReleaseState; - } - - public String getScheduleProcessInstancePriority() { - return scheduleProcessInstancePriority; - } - - public void setScheduleProcessInstancePriority(String scheduleProcessInstancePriority) { - this.scheduleProcessInstancePriority = scheduleProcessInstancePriority; - } - - public String getScheduleWorkerGroupName() { - return scheduleWorkerGroupName; - } - - public void setScheduleWorkerGroupName(String scheduleWorkerGroupName) { - this.scheduleWorkerGroupName = scheduleWorkerGroupName; - } -} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java index 04446b00ad..e2a79e819d 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java @@ -74,7 +74,7 @@ public enum Status { LIST_WORKERS_ERROR(10044, "list workers error", "查询worker列表错误"), LIST_MASTERS_ERROR(10045, "list masters error", "查询master列表错误"), UPDATE_PROJECT_ERROR(10046, "update project error", "更新项目信息错误"), - QUERY_PROJECT_DETAILS_BY_ID_ERROR(10047, "query project details by id error", "查询项目详细信息错误"), + QUERY_PROJECT_DETAILS_BY_CODE_ERROR(10047, "query project details by code error", "查询项目详细信息错误"), CREATE_PROJECT_ERROR(10048, "create project error", "创建项目错误"), LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR(10049, "login user query project list paging error", "分页查询项目列表错误"), DELETE_PROJECT_ERROR(10050, "delete project error", "删除项目错误"), @@ -132,7 +132,7 @@ public enum Status { AUTHORIZED_USER_ERROR(10102, "authorized user error", "查询授权用户错误"), QUERY_TASK_INSTANCE_LOG_ERROR(10103, "view task instance log error", "查询任务实例日志错误"), DOWNLOAD_TASK_INSTANCE_LOG_FILE_ERROR(10104, "download task instance log file error", "下载任务日志文件错误"), - CREATE_PROCESS_DEFINITION(10105, "create process definition", "创建工作流错误"), + CREATE_PROCESS_DEFINITION_ERROR(10105, "create process definition error", "创建工作流错误"), VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR(10106, "verify process definition name unique error", "工作流定义名称验证错误"), UPDATE_PROCESS_DEFINITION_ERROR(10107, "update process definition error", "更新工作流定义错误"), RELEASE_PROCESS_DEFINITION_ERROR(10108, "release process definition error", "上线工作流错误"), @@ -184,17 +184,15 @@ public enum Status { SWITCH_PROCESS_DEFINITION_VERSION_NOT_EXIST_PROCESS_DEFINITION_VERSION_ERROR(10153 , "Switch process definition version error: not exists process definition version, [process definition id {0}] [version number {1}]", "切换工作流版本出错:工作流版本信息不存在,[工作流id {0}] [版本号 {1}]"), QUERY_PROCESS_DEFINITION_VERSIONS_ERROR(10154, "query process definition versions error", "查询工作流历史版本信息出错"), - QUERY_PROCESS_DEFINITION_VERSIONS_PAGE_NO_OR_PAGE_SIZE_LESS_THAN_1_ERROR(10155 - , "query process definition versions error: [page number:{0}] < 1 or [page size:{1}] < 1", "查询工作流历史版本出错:[pageNo:{0}] < 1 或 [pageSize:{1}] < 1"), DELETE_PROCESS_DEFINITION_VERSION_ERROR(10156, "delete process definition version error", "删除工作流历史版本出错"), QUERY_USER_CREATED_PROJECT_ERROR(10157, "query user created project error error", "查询用户创建的项目错误"), - PROCESS_DEFINITION_IDS_IS_EMPTY(10158, "process definition ids is empty", "工作流IDS不能为空"), + PROCESS_DEFINITION_CODES_IS_EMPTY(10158, "process definition codes is empty", "工作流CODES不能为空"), BATCH_COPY_PROCESS_DEFINITION_ERROR(10159, "batch copy process definition error", "复制工作流错误"), BATCH_MOVE_PROCESS_DEFINITION_ERROR(10160, "batch move process definition error", "移动工作流错误"), QUERY_WORKFLOW_LINEAGE_ERROR(10161, "query workflow lineage error", "查询血缘失败"), QUERY_AUTHORIZED_AND_USER_CREATED_PROJECT_ERROR(10162, "query authorized and user created project error error", "查询授权的和用户创建的项目错误"), - DELETE_PROCESS_DEFINITION_BY_ID_FAIL(10163, "delete process definition by id fail, for there are {0} process instances in executing using it", "删除工作流定义失败,有[{0}]个运行中的工作流实例正在使用"), + DELETE_PROCESS_DEFINITION_BY_CODE_FAIL(10163, "delete process definition by code fail, for there are {0} process instances in executing using it", "删除工作流定义失败,有[{0}]个运行中的工作流实例正在使用"), CHECK_OS_TENANT_CODE_ERROR(10164, "Please enter the English os tenant code", "请输入英文操作系统租户"), FORCE_TASK_SUCCESS_ERROR(10165, "force task success error", "强制成功任务实例错误"), TASK_INSTANCE_STATE_OPERATION_ERROR(10166, "the status of task instance {0} is {1},Cannot perform force success operation", "任务实例[{0}]的状态是[{1}],无法执行强制成功操作"), @@ -256,21 +254,30 @@ public enum Status { PROCESS_NODE_HAS_CYCLE(50019, "process node has cycle", "流程节点间存在循环依赖"), PROCESS_NODE_S_PARAMETER_INVALID(50020, "process node {0} parameter invalid", "流程节点[{0}]参数无效"), PROCESS_DEFINE_STATE_ONLINE(50021, "process definition {0} is already on line", "工作流定义[{0}]已上线"), - DELETE_PROCESS_DEFINE_BY_ID_ERROR(50022, "delete process definition by id error", "删除工作流定义错误"), + DELETE_PROCESS_DEFINE_BY_CODE_ERROR(50022, "delete process definition by code error", "删除工作流定义错误"), SCHEDULE_CRON_STATE_ONLINE(50023, "the status of schedule {0} is already on line", "调度配置[{0}]已上线"), DELETE_SCHEDULE_CRON_BY_ID_ERROR(50024, "delete schedule by id error", "删除调度配置错误"), BATCH_DELETE_PROCESS_DEFINE_ERROR(50025, "batch delete process definition error", "批量删除工作流定义错误"), - BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR(50026, "batch delete process definition by ids {0} error", "批量删除工作流定义[{0}]错误"), + BATCH_DELETE_PROCESS_DEFINE_BY_CODES_ERROR(50026, "batch delete process definition by codes {0} error", "批量删除工作流定义[{0}]错误"), TENANT_NOT_SUITABLE(50027, "there is not any tenant suitable, please choose a tenant available.", "没有合适的租户,请选择可用的租户"), EXPORT_PROCESS_DEFINE_BY_ID_ERROR(50028, "export process definition by id error", "导出工作流定义错误"), BATCH_EXPORT_PROCESS_DEFINE_BY_IDS_ERROR(50028, "batch export process definition by ids error", "批量导出工作流定义错误"), IMPORT_PROCESS_DEFINE_ERROR(50029, "import process definition error", "导入工作流定义错误"), TASK_DEFINE_NOT_EXIST(50030, "task definition {0} does not exist", "任务定义[{0}]不存在"), - DELETE_TASK_DEFINE_BY_CODE_ERROR(50031, "delete task definition by code error", "删除任务定义错误"), DELETE_PROCESS_TASK_RELATION_ERROR(50032, "delete process task relation error", "删除工作流任务关系错误"), PROCESS_TASK_RELATION_NOT_EXIST(50033, "process task relation {0} does not exist", "工作流任务关系[{0}]不存在"), PROCESS_TASK_RELATION_EXIST(50034, "process task relation is already exist, processCode:[{0}]", "工作流任务关系已存在, processCode:[{0}]"), PROCESS_DAG_IS_EMPTY(50035, "process dag can not be empty", "工作流dag不能为空"), + CHECK_PROCESS_TASK_RELATION_ERROR(50036, "check process task relation error", "工作流任务关系参数错误"), + CREATE_TASK_DEFINITION_ERROR(50037, "create task definition error", "创建任务错误"), + UPDATE_TASK_DEFINITION_ERROR(50038, "update task definition error", "更新任务定义错误"), + QUERY_TASK_DEFINITION_VERSIONS_ERROR(50039, "query task definition versions error", "查询任务历史版本信息出错"), + SWITCH_TASK_DEFINITION_VERSION_ERROR(50040, "Switch task definition version error", "切换任务版本出错"), + DELETE_TASK_DEFINITION_VERSION_ERROR(50041, "delete task definition version error", "删除任务历史版本出错"), + DELETE_TASK_DEFINE_BY_CODE_ERROR(50042, "delete task definition by code error", "删除任务定义错误"), + QUERY_DETAIL_OF_TASK_DEFINITION_ERROR(50043, "query detail of task definition error", "查询任务详细信息错误"), + QUERY_TASK_DEFINITION_LIST_PAGING_ERROR(50044, "query task definition list paging error", "分页查询任务定义列表错误"), + TASK_DEFINITION_NAME_EXISTED(50045, "task definition name [{0}] already exists", "任务定义名称[{0}]已经存在"), HDFS_NOT_STARTUP(60001, "hdfs not startup", "hdfs未启用"), /** diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java index b8b6be58ff..9a5dbe50ca 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java @@ -30,51 +30,47 @@ public interface DataAnalysisService { * statistical task instance status data * * @param loginUser login user - * @param projectId project id + * @param projectCode project code * @param startDate start date * @param endDate end date * @return task state count data */ - Map countTaskStateByProject(User loginUser, int projectId, String startDate, String endDate); + Map countTaskStateByProject(User loginUser, long projectCode, String startDate, String endDate); /** * statistical process instance status data * * @param loginUser login user - * @param projectId project id + * @param projectCode project code * @param startDate start date * @param endDate end date * @return process instance state count data */ - Map countProcessInstanceStateByProject(User loginUser, int projectId, String startDate, String endDate); + Map countProcessInstanceStateByProject(User loginUser, long projectCode, String startDate, String endDate); /** * statistics the process definition quantities of certain person * * @param loginUser login user - * @param projectId project id + * @param projectCode project code * @return definition count data */ - Map countDefinitionByUser(User loginUser, int projectId); + Map countDefinitionByUser(User loginUser, long projectCode); /** * statistical command status data * * @param loginUser login user - * @param projectId project id - * @param startDate start date - * @param endDate end date * @return command state count data */ - Map countCommandState(User loginUser, int projectId, String startDate, String endDate); + Map countCommandState(User loginUser); /** * count queue state * * @param loginUser login user - * @param projectId project id * @return queue state count data */ - Map countQueueState(User loginUser, int projectId); + Map countQueueState(User loginUser); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java index 323fa7a23c..e86881599d 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java @@ -38,8 +38,8 @@ public interface ExecutorService { * execute process instance * * @param loginUser login user - * @param projectName project name - * @param processDefinitionId process Definition Id + * @param projectCode project code + * @param processDefinitionCode process definition code * @param cronTime cron time * @param commandType command type * @param failureStrategy failuer strategy @@ -56,8 +56,8 @@ public interface ExecutorService { * @param expectedParallelismNumber the expected parallelism number when execute complement in parallel mode * @return execute process instance code */ - Map execProcessInstance(User loginUser, String projectName, - int processDefinitionId, String cronTime, CommandType commandType, + Map execProcessInstance(User loginUser, long projectCode, + long processDefinitionCode, String cronTime, CommandType commandType, FailureStrategy failureStrategy, String startNodeList, TaskDependType taskDependType, WarningType warningType, int warningGroupId, RunMode runMode, @@ -77,18 +77,18 @@ public interface ExecutorService { * do action to process instance:pause, stop, repeat, recover from pause, recover from stop * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param processInstanceId process instance id * @param executeType execute type * @return execute result code */ - Map execute(User loginUser, String projectName, Integer processInstanceId, ExecuteType executeType); + Map execute(User loginUser, long projectCode, Integer processInstanceId, ExecuteType executeType); /** * check if sub processes are offline before starting process definition * - * @param processDefineId process definition id + * @param processDefinitionCode process definition code * @return check result code */ - Map startCheckByProcessDefinedId(int processDefineId); + Map startCheckByProcessDefinedCode(long processDefinitionCode); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java index 2d4ba4eb7e..42fce02bad 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java @@ -19,7 +19,6 @@ package org.apache.dolphinscheduler.api.service; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.enums.ReleaseState; -import org.apache.dolphinscheduler.dao.entity.ProcessData; import org.apache.dolphinscheduler.dao.entity.User; import java.util.Map; @@ -28,8 +27,6 @@ import javax.servlet.http.HttpServletResponse; import org.springframework.web.multipart.MultipartFile; -import com.fasterxml.jackson.core.JsonProcessingException; - /** * process definition service */ @@ -39,38 +36,43 @@ public interface ProcessDefinitionService { * create process definition * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param name process definition name - * @param processDefinitionJson process definition json - * @param desc description + * @param description description + * @param globalParams global params * @param locations locations for nodes - * @param connects connects for nodes + * @param timeout timeout + * @param tenantCode tenantCode + * @param taskRelationJson relation json for nodes + * @param taskDefinitionJson taskDefinitionJson * @return create result code - * @throws JsonProcessingException JsonProcessingException */ Map createProcessDefinition(User loginUser, - String projectName, + long projectCode, String name, - String processDefinitionJson, - String desc, + String description, + String globalParams, String locations, - String connects) throws JsonProcessingException; + int timeout, + String tenantCode, + String taskRelationJson, + String taskDefinitionJson); /** * query process definition list * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @return definition list */ Map queryProcessDefinitionList(User loginUser, - String projectName); + long projectCode); /** * query process definition list paging * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param searchVal search value * @param pageNo page number * @param pageSize page size @@ -78,236 +80,247 @@ public interface ProcessDefinitionService { * @return process definition page */ Result queryProcessDefinitionListPaging(User loginUser, - String projectName, + long projectCode, String searchVal, + Integer userId, Integer pageNo, - Integer pageSize, - Integer userId); + Integer pageSize); /** - * query datail of process definition + * query detail of process definition * * @param loginUser login user - * @param projectName project name - * @param processId process definition id + * @param projectCode project code + * @param code process definition code * @return process definition detail */ - Map queryProcessDefinitionById(User loginUser, - String projectName, - Integer processId); + Map queryProcessDefinitionByCode(User loginUser, + long projectCode, + long code); /** - * query datail of process definition + * query detail of process definition * * @param loginUser login user - * @param projectName project name - * @param processDefinitionName process definition name + * @param projectCode project code + * @param name process definition name * @return process definition detail */ Map queryProcessDefinitionByName(User loginUser, - String projectName, - String processDefinitionName); + long projectCode, + String name); /** * batch copy process definition * * @param loginUser loginUser - * @param projectName projectName - * @param processDefinitionIds processDefinitionIds - * @param targetProjectId targetProjectId + * @param projectCode projectCode + * @param codes processDefinitionCodes + * @param targetProjectCode targetProjectCode */ Map batchCopyProcessDefinition(User loginUser, - String projectName, - String processDefinitionIds, - int targetProjectId); + long projectCode, + String codes, + long targetProjectCode); /** * batch move process definition * * @param loginUser loginUser - * @param projectName projectName - * @param processDefinitionIds processDefinitionIds - * @param targetProjectId targetProjectId + * @param projectCode projectCode + * @param codes processDefinitionCodes + * @param targetProjectCode targetProjectCode */ Map batchMoveProcessDefinition(User loginUser, - String projectName, - String processDefinitionIds, - int targetProjectId); + long projectCode, + String codes, + long targetProjectCode); /** * update process definition * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param name process definition name - * @param id process definition id - * @param processDefinitionJson process definition json - * @param desc description + * @param code process definition code + * @param description description + * @param globalParams global params * @param locations locations for nodes - * @param connects connects for nodes + * @param timeout timeout + * @param tenantCode tenantCode + * @param taskRelationJson relation json for nodes + * @param taskDefinitionJson taskDefinitionJson * @return update result code */ Map updateProcessDefinition(User loginUser, - String projectName, - int id, + long projectCode, String name, - String processDefinitionJson, String desc, - String locations, String connects); + long code, + String description, + String globalParams, + String locations, + int timeout, + String tenantCode, + String taskRelationJson, + String taskDefinitionJson); /** * verify process definition name unique * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param name name * @return true if process definition name not exists, otherwise false */ Map verifyProcessDefinitionName(User loginUser, - String projectName, + long projectCode, String name); /** - * delete process definition by id + * delete process definition by code * * @param loginUser login user - * @param projectName project name - * @param processDefinitionId process definition id + * @param projectCode project code + * @param code process definition code * @return delete result code */ - Map deleteProcessDefinitionById(User loginUser, - String projectName, - Integer processDefinitionId); + Map deleteProcessDefinitionByCode(User loginUser, + long projectCode, + long code); /** * release process definition: online / offline * * @param loginUser login user - * @param projectName project name - * @param id process definition id + * @param projectCode project code + * @param code process definition code * @param releaseState release state * @return release result code */ Map releaseProcessDefinition(User loginUser, - String projectName, - int id, + long projectCode, + long code, ReleaseState releaseState); /** - * batch export process definition by ids + * batch export process definition by codes * * @param loginUser login user - * @param projectName project name - * @param processDefinitionIds process definition ids + * @param projectCode project code + * @param codes process definition codes * @param response http servlet response */ - void batchExportProcessDefinitionByIds(User loginUser, - String projectName, - String processDefinitionIds, - HttpServletResponse response); + void batchExportProcessDefinitionByCodes(User loginUser, + long projectCode, + String codes, + HttpServletResponse response); /** * import process definition * * @param loginUser login user + * @param projectCode project code * @param file process metadata json file - * @param currentProjectName current project name * @return import process */ Map importProcessDefinition(User loginUser, - MultipartFile file, - String currentProjectName); + long projectCode, + MultipartFile file); /** - * check the process definition node meets the specifications + * check the process task relation json * - * @param processData process data - * @param processDefinitionJson process definition json + * @param processTaskRelationJson process task relation json * @return check result code */ - Map checkProcessNodeList(ProcessData processData, - String processDefinitionJson); + Map checkProcessNodeList(String processTaskRelationJson); /** * get task node details based on process definition * - * @param defineCode define code + * @param loginUser loginUser + * @param projectCode project code + * @param code processDefinition code * @return task node list */ - Map getTaskNodeListByDefinitionCode(Long defineCode); + Map getTaskNodeListByDefinitionCode(User loginUser, + long projectCode, + long code); /** - * get task node details based on process definition + * get task node details map based on process definition * - * @param defineCodeList define code list + * @param loginUser loginUser + * @param projectCode project code + * @param codes define code list * @return task node list */ - Map getTaskNodeListByDefinitionCodeList(String defineCodeList); + Map getNodeListMapByDefinitionCodes(User loginUser, + long projectCode, + String codes); /** - * query process definition all by project id + * query process definition all by project code * - * @param projectId project id + * @param projectCode project code * @return process definitions in the project */ - Map queryProcessDefinitionAllByProjectId(Integer projectId); + Map queryAllProcessDefinitionByProjectCode(User loginUser, long projectCode); /** * Encapsulates the TreeView structure * - * @param processId process definition id + * @param code process definition code * @param limit limit * @return tree view json data - * @throws Exception exception */ - Map viewTree(Integer processId, - Integer limit) throws Exception; + Map viewTree(long code, Integer limit); /** - * switch the defined process definition verison + * switch the defined process definition version * * @param loginUser login user - * @param projectName project name - * @param processDefinitionId process definition id + * @param projectCode project code + * @param code process definition code * @param version the version user want to switch * @return switch process definition version result code */ - Map switchProcessDefinitionVersion(User loginUser, String projectName - , int processDefinitionId, long version); + Map switchProcessDefinitionVersion(User loginUser, + long projectCode, + long code, + int version); /** * query the pagination versions info by one certain process definition code * * @param loginUser login user info to check auth - * @param projectName process definition project name + * @param projectCode project code * @param pageNo page number * @param pageSize page size - * @param processDefinitionCode process definition code + * @param code process definition code * @return the pagination process definition versions info of the certain process definition */ - Result queryProcessDefinitionVersions(User loginUser, String projectName, - int pageNo, int pageSize, long processDefinitionCode); + Result queryProcessDefinitionVersions(User loginUser, + long projectCode, + int pageNo, + int pageSize, + long code); /** - * delete one certain process definition by version number and process definition id + * delete one certain process definition by version number and process definition code * * @param loginUser login user info to check auth - * @param projectName process definition project name - * @param processDefinitionId process definition id + * @param projectCode project code + * @param code process definition code * @param version version number * @return delele result code */ - Map deleteByProcessDefinitionIdAndVersion(User loginUser, String projectName, - int processDefinitionId, long version); + Map deleteProcessDefinitionVersion(User loginUser, + long projectCode, + long code, + int version); - /** - * check has associated process definition - * - * @param processDefinitionId process definition id - * @param version version - * @return The query result has a specific process definition return true - */ - boolean checkHasAssociatedProcessDefinition(int processDefinitionId, long version); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java index 8fc9d550d0..3dbf46d8b8 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java @@ -26,7 +26,6 @@ import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.User; import java.io.IOException; -import java.text.ParseException; import java.util.List; import java.util.Map; @@ -39,26 +38,32 @@ public interface ProcessInstanceService { /** * return top n SUCCESS process instance order by running time which started between startTime and endTime */ - Map queryTopNLongestRunningProcessInstance(User loginUser, String projectName, int size, String startTime, String endTime); + Map queryTopNLongestRunningProcessInstance(User loginUser, + long projectCode, + int size, + String startTime, + String endTime); /** * query process instance by id * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param processId process instance id * @return process instance detail */ - Map queryProcessInstanceById(User loginUser, String projectName, Integer processId); + Map queryProcessInstanceById(User loginUser, + long projectCode, + Integer processId); /** * paging query process instance list, filtering according to project, process definition, time range, keyword, process status * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param pageNo page number * @param pageSize page size - * @param processDefineId process definition id + * @param processDefineCode process definition code * @param searchVal search value * @param stateType state type * @param host host @@ -66,21 +71,30 @@ public interface ProcessInstanceService { * @param endDate end time * @return process instance list */ - Result queryProcessInstanceList(User loginUser, String projectName, Integer processDefineId, - String startDate, String endDate, - String searchVal, String executorName, ExecutionStatus stateType, String host, - Integer pageNo, Integer pageSize); + Result queryProcessInstanceList(User loginUser, + long projectCode, + long processDefineCode, + String startDate, + String endDate, + String searchVal, + String executorName, + ExecutionStatus stateType, + String host, + Integer pageNo, + Integer pageSize); /** * query task list by process instance id * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param processId process instance id * @return task list for the process instance * @throws IOException io exception */ - Map queryTaskListByProcessId(User loginUser, String projectName, Integer processId) throws IOException; + Map queryTaskListByProcessId(User loginUser, + long projectCode, + Integer processId) throws IOException; Map parseLogForDependentResult(String log) throws IOException; @@ -88,50 +102,65 @@ public interface ProcessInstanceService { * query sub process instance detail info by task id * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param taskId task id * @return sub process instance detail */ - Map querySubProcessInstanceByTaskId(User loginUser, String projectName, Integer taskId); + Map querySubProcessInstanceByTaskId(User loginUser, + long projectCode, + Integer taskId); /** * update process instance * * @param loginUser login user - * @param projectName project name - * @param processInstanceJson process instance json + * @param projectCode project code + * @param taskRelationJson process task relation json + * @param taskDefinitionJson taskDefinitionJson * @param processInstanceId process instance id * @param scheduleTime schedule time * @param syncDefine sync define - * @param flag flag - * @param locations locations - * @param connects connects + * @param globalParams global params + * @param locations locations for nodes + * @param timeout timeout + * @param tenantCode tenantCode * @return update result code - * @throws ParseException parse exception for json parse */ - Map updateProcessInstance(User loginUser, String projectName, Integer processInstanceId, - String processInstanceJson, String scheduleTime, Boolean syncDefine, - Flag flag, String locations, String connects) throws ParseException; + Map updateProcessInstance(User loginUser, + long projectCode, + Integer processInstanceId, + String taskRelationJson, + String taskDefinitionJson, + String scheduleTime, + Boolean syncDefine, + String globalParams, + String locations, + int timeout, + String tenantCode); /** * query parent process instance detail info by sub process instance id * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param subId sub process id * @return parent instance detail */ - Map queryParentInstanceBySubId(User loginUser, String projectName, Integer subId); + Map queryParentInstanceBySubId(User loginUser, + long projectCode, + Integer subId); /** * delete process instance by id, at the same time,delete task instance and their mapping relation data * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param processInstanceId process instance id * @return delete result code */ - Map deleteProcessInstanceById(User loginUser, String projectName, Integer processInstanceId); + Map deleteProcessInstanceById(User loginUser, + long projectCode, + Integer processInstanceId); /** * view process instance variables @@ -157,7 +186,8 @@ public interface ProcessInstanceService { * @param states states array * @return process instance list */ - List queryByProcessDefineCodeAndStatus(Long processDefinitionCode, int[] states); + List queryByProcessDefineCodeAndStatus(Long processDefinitionCode, + int[] states); /** * query process instance by processDefinitionCode @@ -166,6 +196,6 @@ public interface ProcessInstanceService { * @param size size * @return process instance list */ - List queryByProcessDefineCode(Long processDefinitionCode,int size); - + List queryByProcessDefineCode(Long processDefinitionCode, + int size); } \ No newline at end of file diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java index 82a4d5176d..dffa866ac8 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java @@ -39,22 +39,22 @@ public interface ProjectService { Map createProject(User loginUser, String name, String desc); /** - * query project details by id + * query project details by code * - * @param projectId project id + * @param projectCode project code * @return project detail information */ - Map queryById(Integer projectId); + Map queryByCode(User loginUser, long projectCode); /** * check project and authorization * * @param loginUser login user * @param project project - * @param projectName project name + * @param projectCode project code * @return true if the login user have permission to see the project */ - Map checkProjectAndAuth(User loginUser, Project project, String projectName); + Map checkProjectAndAuth(User loginUser, Project project, long projectCode); boolean hasProjectAndPerm(User loginUser, Project project, Map result); @@ -72,25 +72,25 @@ public interface ProjectService { Result queryProjectListPaging(User loginUser, Integer pageSize, Integer pageNo, String searchVal); /** - * delete project by id + * delete project by code * * @param loginUser login user - * @param projectId project id + * @param projectCode project code * @return delete result code */ - Map deleteProject(User loginUser, Integer projectId); + Map deleteProject(User loginUser, Long projectCode); /** * updateProcessInstance project * * @param loginUser login user - * @param projectId project id + * @param projectCode project code * @param projectName project name * @param desc description * @param userName project owner * @return update result code */ - Map update(User loginUser, Integer projectId, String projectName, String desc, String userName); + Map update(User loginUser, Long projectCode, String projectName, String desc, String userName); /** * query unauthorized project @@ -127,8 +127,8 @@ public interface ProjectService { /** * query authorized and user create project list by user id - * @param loginUser - * @return + * @param loginUser login user + * @return project list */ Map queryProjectCreatedAndAuthorizedByUser(User loginUser); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java index d8902b1562..bad9b3596f 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java @@ -35,8 +35,8 @@ public interface SchedulerService { * save schedule * * @param loginUser login user - * @param projectName project name - * @param processDefineId process definition id + * @param projectCode project code + * @param processDefineCode process definition code * @param schedule scheduler * @param warningType warning type * @param warningGroupId warning group id @@ -46,8 +46,9 @@ public interface SchedulerService { * @param environmentCode environment code * @return create result code */ - Map insertSchedule(User loginUser, String projectName, - Integer processDefineId, + Map insertSchedule(User loginUser, + long projectCode, + long processDefineCode, String schedule, WarningType warningType, int warningGroupId, @@ -60,7 +61,7 @@ public interface SchedulerService { * updateProcessInstance schedule * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param id scheduler id * @param scheduleExpression scheduler * @param warningType warning type @@ -69,17 +70,15 @@ public interface SchedulerService { * @param workerGroup worker group * @param environmentCode environment code * @param processInstancePriority process instance priority - * @param scheduleStatus schedule status * @return update result code */ Map updateSchedule(User loginUser, - String projectName, + long projectCode, Integer id, String scheduleExpression, WarningType warningType, int warningGroupId, FailureStrategy failureStrategy, - ReleaseState scheduleStatus, Priority processInstancePriority, String workerGroup, Long environmentCode); @@ -89,13 +88,13 @@ public interface SchedulerService { * set schedule online or offline * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param id scheduler id * @param scheduleStatus schedule status * @return publish result code */ Map setScheduleState(User loginUser, - String projectName, + long projectCode, Integer id, ReleaseState scheduleStatus); @@ -103,23 +102,24 @@ public interface SchedulerService { * query schedule * * @param loginUser login user - * @param projectName project name - * @param processDefineId process definition id + * @param projectCode project code + * @param processDefineCode process definition code * @param pageNo page number * @param pageSize page size * @param searchVal search value * @return schedule list page */ - Result querySchedule(User loginUser, String projectName, Integer processDefineId, String searchVal, Integer pageNo, Integer pageSize); + Result querySchedule(User loginUser, long projectCode, long processDefineCode, String searchVal, + Integer pageNo, Integer pageSize); /** * query schedule list * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @return schedule list */ - Map queryScheduleList(User loginUser, String projectName); + Map queryScheduleList(User loginUser, long projectCode); /** * delete schedule @@ -134,19 +134,18 @@ public interface SchedulerService { * delete schedule by id * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param scheduleId scheule id * @return delete result code */ - Map deleteScheduleById(User loginUser, String projectName, Integer scheduleId); + Map deleteScheduleById(User loginUser, long projectCode, Integer scheduleId); /** * preview schedule * * @param loginUser login user - * @param projectName project name * @param schedule schedule expression * @return the next five fire time */ - Map previewSchedule(User loginUser, String projectName, String schedule); -} \ No newline at end of file + Map previewSchedule(User loginUser, String schedule); +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskDefinitionService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskDefinitionService.java index ea0031ab76..32fe150b0d 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskDefinitionService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskDefinitionService.java @@ -17,6 +17,7 @@ package org.apache.dolphinscheduler.api.service; +import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.dao.entity.User; import java.util.Map; @@ -30,59 +31,131 @@ public interface TaskDefinitionService { * create task definition * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param taskDefinitionJson task definition json */ Map createTaskDefinition(User loginUser, - String projectName, + long projectCode, String taskDefinitionJson); /** * query task definition * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param taskName task name */ Map queryTaskDefinitionByName(User loginUser, - String projectName, + long projectCode, String taskName); /** * delete task definition * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param taskCode task code */ Map deleteTaskDefinitionByCode(User loginUser, - String projectName, - Long taskCode); + long projectCode, + long taskCode); /** * update task definition * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param taskCode task code - * @param taskDefinitionJson task definition json + * @param taskDefinitionJsonObj task definition json object */ Map updateTaskDefinition(User loginUser, - String projectName, - Long taskCode, - String taskDefinitionJson); + long projectCode, + long taskCode, + String taskDefinitionJsonObj); /** * update task definition * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param taskCode task code * @param version the version user want to switch */ Map switchVersion(User loginUser, - String projectName, - Long taskCode, + long projectCode, + long taskCode, int version); -} + /** + * query the pagination versions info by one certain task definition code + * + * @param loginUser login user info to check auth + * @param projectCode project code + * @param taskCode task definition code + * @param pageNo page number + * @param pageSize page size + * @return the pagination task definition versions info of the certain task definition + */ + Result queryTaskDefinitionVersions(User loginUser, + long projectCode, + long taskCode, + int pageNo, + int pageSize); + + /** + * delete the certain task definition version by version and code + * + * @param loginUser login user info + * @param projectCode project code + * @param taskCode the task definition code + * @param version the task definition version user want to delete + * @return delete version result code + */ + Map deleteByCodeAndVersion(User loginUser, + long projectCode, + long taskCode, + int version); + + /** + * query detail of task definition by code + * + * @param loginUser login user + * @param projectCode project code + * @param taskCode the task definition code + * @return task definition detail + */ + Map queryTaskDefinitionDetail(User loginUser, + long projectCode, + long taskCode); + + /** + * query task definition list paging + * + * @param loginUser login user + * @param projectCode project code + * @param taskType taskType + * @param searchVal search value + * @param userId user id + * @param pageNo page number + * @param pageSize page size + * @return task definition page + */ + Result queryTaskDefinitionListPaging(User loginUser, + long projectCode, + String taskType, + String searchVal, + Integer userId, + Integer pageNo, + Integer pageSize); + + /** + * gen task code list + * + * @param loginUser login user + * @param genNum gen num + * @return task code list + */ + Map genTaskCodeList(User loginUser, + Integer genNum); + +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java index 7dace1ddad..73e3a489a5 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java @@ -32,7 +32,7 @@ public interface TaskInstanceService { * query task list by project, process instance, task name, task start time, task end time, task status, keyword paging * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param processInstanceId process instance id * @param searchVal search value * @param taskName task name @@ -44,19 +44,29 @@ public interface TaskInstanceService { * @param pageSize page size * @return task list page */ - Result queryTaskListPaging(User loginUser, String projectName, - Integer processInstanceId, String processInstanceName, String taskName, String executorName, String startDate, - String endDate, String searchVal, ExecutionStatus stateType, String host, - Integer pageNo, Integer pageSize); + Result queryTaskListPaging(User loginUser, + long projectCode, + Integer processInstanceId, + String processInstanceName, + String taskName, + String executorName, + String startDate, + String endDate, + String searchVal, + ExecutionStatus stateType, + String host, + Integer pageNo, + Integer pageSize); /** * change one task instance's state from failure to forced success * - * @param loginUser login user - * @param projectName project name + * @param loginUser login user + * @param projectCode project code * @param taskInstanceId task instance id * @return the result code and msg */ - Map forceTaskSuccess(User loginUser, String projectName, Integer taskInstanceId); - + Map forceTaskSuccess(User loginUser, + long projectCode, + Integer taskInstanceId); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageService.java index 360e813c68..c88d3529f5 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageService.java @@ -25,8 +25,8 @@ import java.util.Set; */ public interface WorkFlowLineageService { - Map queryWorkFlowLineageByName(String workFlowName, int projectId); + Map queryWorkFlowLineageByName(String workFlowName, long projectCode); - Map queryWorkFlowLineageByIds(Set ids,int projectId); + Map queryWorkFlowLineageByIds(Set ids, long projectCode); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java index a867deafc2..98bae2ad5a 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java @@ -90,17 +90,17 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal * statistical task instance status data * * @param loginUser login user - * @param projectId project id + * @param projectCode project code * @param startDate start date * @param endDate end date * @return task state count data */ @Override - public Map countTaskStateByProject(User loginUser, int projectId, String startDate, String endDate) { + public Map countTaskStateByProject(User loginUser, long projectCode, String startDate, String endDate) { return countStateByProject( loginUser, - projectId, + projectCode, startDate, endDate, (start, end, projectCodes) -> this.taskInstanceMapper.countTaskInstanceStateByUser(start, end, projectCodes)); @@ -110,16 +110,16 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal * statistical process instance status data * * @param loginUser login user - * @param projectId project id + * @param projectCode project code * @param startDate start date * @param endDate end date * @return process instance state count data */ @Override - public Map countProcessInstanceStateByProject(User loginUser, int projectId, String startDate, String endDate) { + public Map countProcessInstanceStateByProject(User loginUser, long projectCode, String startDate, String endDate) { Map result = this.countStateByProject( loginUser, - projectId, + projectCode, startDate, endDate, (start, end, projectCodes) -> this.processInstanceMapper.countInstanceStateByUser(start, end, projectCodes)); @@ -130,12 +130,16 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal return result; } - private Map countStateByProject(User loginUser, int projectId, String startDate, String endDate + private Map countStateByProject(User loginUser, long projectCode, String startDate, String endDate , TriFunction> instanceStateCounter) { Map result = new HashMap<>(); - boolean checkProject = checkProject(loginUser, projectId, result); - if (!checkProject) { - return result; + + if (projectCode != 0) { + Project project = projectMapper.queryByCode(projectCode); + result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; + } } Date start = null; @@ -149,8 +153,8 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal } } - Long[] projectCodeArray = projectId == 0 ? getProjectCodesArrays(loginUser) - : new Long[] { projectMapper.selectById(projectId).getCode() }; + Long[] projectCodeArray = projectCode == 0 ? getProjectCodesArrays(loginUser) + : new Long[] { projectCode }; List processInstanceStateCounts = instanceStateCounter.apply(start, end, projectCodeArray); @@ -167,18 +171,23 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal * statistics the process definition quantities of certain person * * @param loginUser login user - * @param projectId project id + * @param projectCode project code * @return definition count data */ @Override - public Map countDefinitionByUser(User loginUser, int projectId) { + public Map countDefinitionByUser(User loginUser, long projectCode) { Map result = new HashMap<>(); - boolean checkProject = checkProject(loginUser, projectId, result); - if (!checkProject) { - return result; + + if (projectCode != 0) { + Project project = projectMapper.queryByCode(projectCode); + result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; + } } - Long[] projectCodeArray = projectId == 0 ? getProjectCodesArrays(loginUser) - : new Long[] { projectMapper.selectById(projectId).getCode() }; + + Long[] projectCodeArray = projectCode == 0 ? getProjectCodesArrays(loginUser) + : new Long[] { projectCode }; List defineGroupByUsers = processDefinitionMapper.countDefinitionGroupByUser( loginUser.getId(), projectCodeArray, isAdmin(loginUser)); @@ -193,43 +202,20 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal * statistical command status data * * @param loginUser login user - * @param projectId project id - * @param startDate start date - * @param endDate end date * @return command state count data */ @Override - public Map countCommandState(User loginUser, int projectId, String startDate, String endDate) { - + public Map countCommandState(User loginUser) { Map result = new HashMap<>(); - boolean checkProject = checkProject(loginUser, projectId, result); - if (!checkProject) { - return result; - } /** * find all the task lists in the project under the user * statistics based on task status execution, failure, completion, wait, total */ Date start = null; - if (StringUtils.isNotEmpty(startDate)) { - start = DateUtils.getScheduleDate(startDate); - if (Objects.isNull(start)) { - putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.START_END_DATE); - return result; - } - } Date end = null; - if (StringUtils.isNotEmpty(endDate)) { - end = DateUtils.getScheduleDate(endDate); - if (Objects.isNull(end)) { - putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.START_END_DATE); - return result; - } - } + Long[] projectCodeArray = getProjectCodesArrays(loginUser); - Long[] projectCodeArray = projectId == 0 ? getProjectCodesArrays(loginUser) - : new Long[] { projectMapper.selectById(projectId).getCode() }; // count normal command state Map normalCountCommandCounts = commandMapper.countCommandState(loginUser.getId(), start, end, projectCodeArray) .stream() @@ -267,20 +253,13 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal /** * count queue state * - * @param loginUser login user - * @param projectId project id * @return queue state count data */ @Override - public Map countQueueState(User loginUser, int projectId) { + public Map countQueueState(User loginUser) { Map result = new HashMap<>(); - boolean checkProject = checkProject(loginUser, projectId, result); - if (!checkProject) { - return result; - } - - //TODO need to add detail data info + //TODO need to add detail data info Map dataMap = new HashMap<>(); dataMap.put("taskQueue", 0); dataMap.put("taskKill", 0); @@ -289,12 +268,4 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal return result; } - private boolean checkProject(User loginUser, int projectId, Map result) { - if (projectId != 0) { - Project project = projectMapper.selectById(projectId); - return projectService.hasProjectAndPerm(loginUser, project, result); - } - return true; - } - } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java index 3c48cc80d1..d18c2605ac 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java @@ -308,7 +308,8 @@ public class DataSourceServiceImpl extends BaseServiceImpl implements DataSource * check connection * * @param type data source type - * @param connectionParam data source parameters + * @param connectionParam connectionParam + * @return true if connect successfully, otherwise false * @return true if connect successfully, otherwise false */ @Override diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java index e15fb69c91..465ef7e95d 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java @@ -107,8 +107,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ * execute process instance * * @param loginUser login user - * @param projectName project name - * @param processDefinitionId process Definition Id + * @param projectCode project code + * @param processDefinitionCode process definition code * @param cronTime cron time * @param commandType command type * @param failureStrategy failure strategy @@ -126,28 +126,28 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ * @return execute process instance code */ @Override - public Map execProcessInstance(User loginUser, String projectName, - int processDefinitionId, String cronTime, CommandType commandType, + public Map execProcessInstance(User loginUser, long projectCode, + long processDefinitionCode, String cronTime, CommandType commandType, FailureStrategy failureStrategy, String startNodeList, TaskDependType taskDependType, WarningType warningType, int warningGroupId, RunMode runMode, - Priority processInstancePriority, String workerGroup, Long environmentCode, Integer timeout, + Priority processInstancePriority, String workerGroup, Long environmentCode,Integer timeout, Map startParams, Integer expectedParallelismNumber) { - Map result = new HashMap<>(); + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; + } // timeout is invalid if (timeout <= 0 || timeout > MAX_TASK_TIMEOUT) { putMsg(result, Status.TASK_TIMEOUT_PARAMS_ERROR); return result; } - Project project = projectMapper.queryByName(projectName); - Map checkResultAndAuth = checkResultAndAuth(loginUser, projectName, project); - if (checkResultAndAuth != null) { - return checkResultAndAuth; - } // check process define release state - ProcessDefinition processDefinition = processDefinitionMapper.selectById(processDefinitionId); - result = checkProcessDefinitionValid(processDefinition, processDefinitionId); + ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(processDefinitionCode); + result = checkProcessDefinitionValid(processDefinition, processDefinitionCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -167,7 +167,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ /** * create command */ - int create = this.createCommand(commandType, processDefinitionId, + int create = this.createCommand(commandType, processDefinition.getCode(), taskDependType, failureStrategy, startNodeList, cronTime, warningType, loginUser.getId(), warningGroupId, runMode, processInstancePriority, workerGroup, environmentCode, startParams, expectedParallelismNumber); @@ -225,19 +225,18 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ * do action to process instance:pause, stop, repeat, recover from pause, recover from stop * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param processInstanceId process instance id * @param executeType execute type * @return execute result code */ @Override - public Map execute(User loginUser, String projectName, Integer processInstanceId, ExecuteType executeType) { - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = checkResultAndAuth(loginUser, projectName, project); - if (checkResult != null) { - return checkResult; + public Map execute(User loginUser, long projectCode, Integer processInstanceId, ExecuteType executeType) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } // check master exists @@ -260,10 +259,9 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ } } - checkResult = checkExecuteType(processInstance, executeType); - Status status = (Status) checkResult.get(Constants.STATUS); - if (status != Status.SUCCESS) { - return checkResult; + result = checkExecuteType(processInstance, executeType); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } if (!checkTenantSuitable(processDefinition)) { logger.error("there is not any valid tenant for the process definition: id:{},name:{}, ", @@ -283,13 +281,13 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ switch (executeType) { case REPEAT_RUNNING: - result = insertCommand(loginUser, processInstanceId, processDefinition.getId(), CommandType.REPEAT_RUNNING, startParams); + result = insertCommand(loginUser, processInstanceId, processDefinition.getCode(), CommandType.REPEAT_RUNNING, startParams); break; case RECOVER_SUSPENDED_PROCESS: - result = insertCommand(loginUser, processInstanceId, processDefinition.getId(), CommandType.RECOVER_SUSPENDED_PROCESS, startParams); + result = insertCommand(loginUser, processInstanceId, processDefinition.getCode(), CommandType.RECOVER_SUSPENDED_PROCESS, startParams); break; case START_FAILURE_TASK_PROCESS: - result = insertCommand(loginUser, processInstanceId, processDefinition.getId(), CommandType.START_FAILURE_TASK_PROCESS, startParams); + result = insertCommand(loginUser, processInstanceId, processDefinition.getCode(), CommandType.START_FAILURE_TASK_PROCESS, startParams); break; case STOP: if (processInstance.getState() == ExecutionStatus.READY_STOP) { @@ -406,13 +404,13 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ /** * insert command, used in the implementation of the page, re run, recovery (pause / failure) execution * - * @param loginUser login user - * @param instanceId instance id - * @param processDefinitionId process definition id - * @param commandType command type + * @param loginUser login user + * @param instanceId instance id + * @param processDefinitionCode process definition code + * @param commandType command type * @return insert result code */ - private Map insertCommand(User loginUser, Integer instanceId, Integer processDefinitionId, CommandType commandType, String startParams) { + private Map insertCommand(User loginUser, Integer instanceId, long processDefinitionCode, CommandType commandType, String startParams) { Map result = new HashMap<>(); //To add startParams only when repeat running is needed @@ -424,12 +422,12 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ Command command = new Command(); command.setCommandType(commandType); - command.setProcessDefinitionId(processDefinitionId); + command.setProcessDefinitionCode(processDefinitionCode); command.setCommandParam(JSONUtils.toJsonString(cmdParam)); command.setExecutorId(loginUser.getId()); if (!processService.verifyIsNeedCreateCommand(command)) { - putMsg(result, Status.PROCESS_INSTANCE_EXECUTING_COMMAND, processDefinitionId); + putMsg(result, Status.PROCESS_INSTANCE_EXECUTING_COMMAND, processDefinitionCode); return result; } @@ -447,31 +445,35 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ /** * check if sub processes are offline before starting process definition * - * @param processDefineId process definition id + * @param processDefinitionCode process definition code * @return check result code */ @Override - public Map startCheckByProcessDefinedId(int processDefineId) { + public Map startCheckByProcessDefinedCode(long processDefinitionCode) { Map result = new HashMap<>(); - if (processDefineId == 0) { - logger.error("process definition id is null"); - putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, "process definition id"); + ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(processDefinitionCode); + + if (processDefinition == null) { + logger.error("process definition is not found"); + putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, "processDefinitionCode"); + return result; } + List ids = new ArrayList<>(); - processService.recurseFindSubProcessId(processDefineId, ids); + processService.recurseFindSubProcessId(processDefinition.getId(), ids); Integer[] idArray = ids.toArray(new Integer[ids.size()]); if (!ids.isEmpty()) { List processDefinitionList = processDefinitionMapper.queryDefinitionListByIdList(idArray); if (processDefinitionList != null) { - for (ProcessDefinition processDefinition : processDefinitionList) { + for (ProcessDefinition processDefinitionTmp : processDefinitionList) { /** * if there is no online process, exit directly */ - if (processDefinition.getReleaseState() != ReleaseState.ONLINE) { - putMsg(result, Status.PROCESS_DEFINE_NOT_RELEASE, processDefinition.getName()); + if (processDefinitionTmp.getReleaseState() != ReleaseState.ONLINE) { + putMsg(result, Status.PROCESS_DEFINE_NOT_RELEASE, processDefinitionTmp.getName()); logger.info("not release process definition id: {} , name : {}", - processDefinition.getId(), processDefinition.getName()); + processDefinitionTmp.getId(), processDefinitionTmp.getName()); return result; } } @@ -485,7 +487,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ * create command * * @param commandType commandType - * @param processDefineId processDefineId + * @param processDefineCode processDefineCode * @param nodeDep nodeDep * @param failureStrategy failureStrategy * @param startNodeList startNodeList @@ -499,7 +501,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ * @param environmentCode environmentCode * @return command id */ - private int createCommand(CommandType commandType, int processDefineId, + private int createCommand(CommandType commandType, long processDefineCode, TaskDependType nodeDep, FailureStrategy failureStrategy, String startNodeList, String schedule, WarningType warningType, int executorId, int warningGroupId, @@ -517,7 +519,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ } else { command.setCommandType(commandType); } - command.setProcessDefinitionId(processDefineId); + command.setProcessDefinitionCode(processDefineCode); if (nodeDep != null) { command.setTaskDependType(nodeDep); } @@ -560,7 +562,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ command.setCommandParam(JSONUtils.toJsonString(cmdParam)); return processService.createCommand(command); } else if (runMode == RunMode.RUN_MODE_PARALLEL) { - List schedules = processService.queryReleaseSchedulerListByProcessDefinitionId(processDefineId); + List schedules = processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefineCode); LinkedList listDate = new LinkedList<>(); if (!CollectionUtils.isEmpty(schedules)) { for (Schedule item : schedules) { @@ -601,7 +603,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ } } } else { - logger.error("there is not valid schedule date for the process definition: id:{}", processDefineId); + logger.error("there is not valid schedule date for the process definition code:{}", processDefineCode); } } else { command.setCommandParam(JSONUtils.toJsonString(cmdParam)); @@ -610,18 +612,4 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ return 0; } - - /** - * check result and auth - */ - private Map checkResultAndAuth(User loginUser, String projectName, Project project) { - // check project auth - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status status = (Status) checkResult.get(Constants.STATUS); - if (status != Status.SUCCESS) { - return checkResult; - } - return null; - } - } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java index 6ca928150a..a40f821ce3 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java @@ -19,7 +19,7 @@ package org.apache.dolphinscheduler.api.service.impl; import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_SUB_PROCESS_DEFINE_ID; -import org.apache.dolphinscheduler.api.dto.ProcessMeta; +import org.apache.dolphinscheduler.api.dto.DagDataSchedule; import org.apache.dolphinscheduler.api.dto.treeview.Instance; import org.apache.dolphinscheduler.api.dto.treeview.TreeViewDto; import org.apache.dolphinscheduler.api.enums.Status; @@ -33,12 +33,8 @@ import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.enums.AuthorizationType; -import org.apache.dolphinscheduler.common.enums.FailureStrategy; -import org.apache.dolphinscheduler.common.enums.Priority; import org.apache.dolphinscheduler.common.enums.ReleaseState; -import org.apache.dolphinscheduler.common.enums.TaskType; import org.apache.dolphinscheduler.common.enums.UserType; -import org.apache.dolphinscheduler.common.enums.WarningType; import org.apache.dolphinscheduler.common.graph.DAG; import org.apache.dolphinscheduler.common.model.TaskNode; import org.apache.dolphinscheduler.common.model.TaskNodeRelation; @@ -48,39 +44,40 @@ import org.apache.dolphinscheduler.common.utils.DateUtils; import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.common.utils.SnowFlakeUtils; import org.apache.dolphinscheduler.common.utils.SnowFlakeUtils.SnowFlakeException; -import org.apache.dolphinscheduler.common.utils.StreamUtils; import org.apache.dolphinscheduler.common.utils.StringUtils; -import org.apache.dolphinscheduler.dao.entity.DataSource; +import org.apache.dolphinscheduler.dao.entity.DagData; import org.apache.dolphinscheduler.dao.entity.ProcessData; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessDefinitionLog; import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation; +import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog; import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.Schedule; import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; import org.apache.dolphinscheduler.dao.entity.TaskInstance; +import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.dolphinscheduler.dao.mapper.DataSourceMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; +import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; +import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.service.permission.PermissionCheck; import org.apache.dolphinscheduler.service.process.ProcessService; -import org.apache.commons.collections.map.HashedMap; - import java.io.BufferedOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -104,11 +101,7 @@ import org.springframework.web.multipart.MultipartFile; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - +import com.google.common.collect.Lists; /** * process definition service impl @@ -118,12 +111,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro private static final Logger logger = LoggerFactory.getLogger(ProcessDefinitionServiceImpl.class); - private static final String PROCESSDEFINITIONCODE = "processDefinitionCode"; - private static final String RELEASESTATE = "releaseState"; - private static final String TASKS = "tasks"; - @Autowired private ProjectMapper projectMapper; @@ -157,102 +146,192 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro @Autowired TaskDefinitionLogMapper taskDefinitionLogMapper; + @Autowired + private TaskDefinitionMapper taskDefinitionMapper; + @Autowired private SchedulerService schedulerService; @Autowired - private DataSourceMapper dataSourceMapper; + private TenantMapper tenantMapper; /** * create process definition * * @param loginUser login user - * @param projectName project name - * @param processDefinitionName process definition name - * @param processDefinitionJson process definition json - * @param desc description + * @param projectCode project code + * @param name process definition name + * @param description description + * @param globalParams global params * @param locations locations for nodes - * @param connects connects for nodes + * @param timeout timeout + * @param tenantCode tenantCode + * @param taskRelationJson relation json for nodes + * @param taskDefinitionJson taskDefinitionJson * @return create result code */ @Override - @Transactional(rollbackFor = Exception.class) + @Transactional(rollbackFor = RuntimeException.class) public Map createProcessDefinition(User loginUser, - String projectName, - String processDefinitionName, - String processDefinitionJson, - String desc, + long projectCode, + String name, + String description, + String globalParams, String locations, - String connects) { - - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - // check project auth - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultStatus = (Status) checkResult.get(Constants.STATUS); - if (resultStatus != Status.SUCCESS) { - return checkResult; - } - - ProcessDefinition processDefinition = new ProcessDefinition(); - ProcessData processData = JSONUtils.parseObject(processDefinitionJson, ProcessData.class); - Map checkProcessJson = checkProcessNodeList(processData, processDefinitionJson); - if (checkProcessJson.get(Constants.STATUS) != Status.SUCCESS) { - return checkProcessJson; - } - - try { - long processDefinitionCode = SnowFlakeUtils.getInstance().nextId(); - processDefinition.setCode(processDefinitionCode); - processDefinition.setVersion(1); - } catch (SnowFlakeException e) { - putMsg(result, Status.CREATE_PROCESS_DEFINITION); + int timeout, + String tenantCode, + String taskRelationJson, + String taskDefinitionJson) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } - int saveResult = processService.saveProcessDefinition(loginUser, project, processDefinitionName, desc, - locations, connects, processData, processDefinition, true); + // check whether the new process define name exist + ProcessDefinition definition = processDefinitionMapper.verifyByDefineName(project.getCode(), name); + if (definition != null) { + putMsg(result, Status.PROCESS_DEFINITION_NAME_EXIST, name); + return result; + } + List taskDefinitionLogs = JSONUtils.toList(taskDefinitionJson, TaskDefinitionLog.class); + createTaskDefinition(result, loginUser, projectCode, taskDefinitionLogs, taskDefinitionJson); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; + } + List taskRelationList = JSONUtils.toList(taskRelationJson, ProcessTaskRelationLog.class); + Map checkRelationJson = checkTaskRelationList(taskRelationList, taskRelationJson, taskDefinitionLogs); + if (checkRelationJson.get(Constants.STATUS) != Status.SUCCESS) { + return checkRelationJson; + } - if (saveResult > 0) { + int tenantId = -1; + if (!Constants.DEFAULT.equals(tenantCode)) { + Tenant tenant = tenantMapper.queryByTenantCode(tenantCode); + if (tenant == null) { + putMsg(result, Status.TENANT_NOT_EXIST); + return result; + } + tenantId = tenant.getId(); + } + + long processDefinitionCode; + try { + processDefinitionCode = SnowFlakeUtils.getInstance().nextId(); + } catch (SnowFlakeException e) { + putMsg(result, Status.CREATE_PROCESS_DEFINITION_ERROR); + return result; + } + ProcessDefinition processDefinition = new ProcessDefinition(projectCode, name, processDefinitionCode, description, + globalParams, locations, timeout, loginUser.getId(), tenantId); + + return createProcessDefine(loginUser, result, taskRelationList, processDefinition, taskDefinitionLogs); + } + + private void createTaskDefinition(Map result, + User loginUser, + long projectCode, + List taskDefinitionLogs, + String taskDefinitionJson) { + if (taskDefinitionLogs.isEmpty()) { + logger.error("taskDefinitionJson invalid: {}", taskDefinitionJson); + putMsg(result, Status.DATA_IS_NOT_VALID, taskDefinitionJson); + return; + } + for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) { + if (!CheckUtils.checkTaskDefinitionParameters(taskDefinitionLog)) { + logger.error("task definition {} parameter invalid", taskDefinitionLog.getName()); + putMsg(result, Status.PROCESS_NODE_S_PARAMETER_INVALID, taskDefinitionLog.getName()); + return; + } + } + if (processService.saveTaskDefine(loginUser, projectCode, taskDefinitionLogs)) { putMsg(result, Status.SUCCESS); - // return processDefinition object with ID - result.put(Constants.DATA_LIST, processDefinition.getId()); } else { - putMsg(result, Status.CREATE_PROCESS_DEFINITION); + putMsg(result, Status.CREATE_TASK_DEFINITION_ERROR); + } + } + + private Map createProcessDefine(User loginUser, + Map result, + List taskRelationList, + ProcessDefinition processDefinition, + List taskDefinitionLogs) { + int insertVersion = processService.saveProcessDefine(loginUser, processDefinition, true); + if (insertVersion > 0) { + int insertResult = processService.saveTaskRelation(loginUser, processDefinition.getProjectCode(), processDefinition.getCode(), insertVersion, taskRelationList, taskDefinitionLogs); + if (insertResult == Constants.EXIT_CODE_SUCCESS) { + putMsg(result, Status.SUCCESS); + result.put(Constants.DATA_LIST, processDefinition); + } else { + putMsg(result, Status.CREATE_PROCESS_DEFINITION_ERROR); + } + } else { + putMsg(result, Status.CREATE_PROCESS_DEFINITION_ERROR); } return result; + } + private Map checkTaskRelationList(List taskRelationList, String taskRelationJson, List taskDefinitionLogs) { + Map result = new HashMap<>(); + try { + if (taskRelationList == null || taskRelationList.isEmpty()) { + logger.error("task relation list is null"); + putMsg(result, Status.DATA_IS_NOT_VALID, taskRelationJson); + return result; + } + + List taskNodeList = processService.transformTask(taskRelationList, taskDefinitionLogs); + if (taskNodeList.size() != taskRelationList.size()) { + Set postTaskCodes = taskRelationList.stream().map(ProcessTaskRelationLog::getPostTaskCode).collect(Collectors.toSet()); + Set taskNodeCodes = taskNodeList.stream().map(TaskNode::getCode).collect(Collectors.toSet()); + Collection codes = CollectionUtils.subtract(postTaskCodes, taskNodeCodes); + logger.error("the task code is not exit"); + putMsg(result, Status.TASK_DEFINE_NOT_EXIST, StringUtils.join(codes, Constants.COMMA)); + return result; + } + if (graphHasCycle(taskNodeList)) { + logger.error("process DAG has cycle"); + putMsg(result, Status.PROCESS_NODE_HAS_CYCLE); + return result; + } + + // check whether the task relation json is normal + for (ProcessTaskRelationLog processTaskRelationLog : taskRelationList) { + if (processTaskRelationLog.getPostTaskCode() == 0) { + logger.error("the post_task_code or post_task_version can't be zero"); + putMsg(result, Status.CHECK_PROCESS_TASK_RELATION_ERROR); + return result; + } + } + putMsg(result, Status.SUCCESS); + } catch (Exception e) { + result.put(Constants.STATUS, Status.REQUEST_PARAMS_NOT_VALID_ERROR); + result.put(Constants.MSG, e.getMessage()); + } + return result; } /** * query process definition list * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @return definition list */ @Override - public Map queryProcessDefinitionList(User loginUser, String projectName) { - - HashMap result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultStatus = (Status) checkResult.get(Constants.STATUS); - if (resultStatus != Status.SUCCESS) { - return checkResult; + public Map queryProcessDefinitionList(User loginUser, long projectCode) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } - - List resourceList = processDefinitionMapper.queryAllDefinitionList(project.getCode()); - - resourceList.forEach(processDefinition -> { - ProcessData processData = processService.genProcessData(processDefinition); - processDefinition.setProcessDefinitionJson(JSONUtils.toJsonString(processData)); - }); - - result.put(Constants.DATA_LIST, resourceList); + List resourceList = processDefinitionMapper.queryAllDefinitionList(projectCode); + List dagDataList = resourceList.stream().map(processService::genDagData).collect(Collectors.toList()); + result.put(Constants.DATA_LIST, dagDataList); putMsg(result, Status.SUCCESS); - return result; } @@ -260,40 +339,35 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro * query process definition list paging * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param searchVal search value + * @param userId user id * @param pageNo page number * @param pageSize page size - * @param userId user id * @return process definition page */ @Override - public Result queryProcessDefinitionListPaging(User loginUser, String projectName, String searchVal, Integer pageNo, Integer pageSize, Integer userId) { - + public Result queryProcessDefinitionListPaging(User loginUser, long projectCode, String searchVal, Integer userId, Integer pageNo, Integer pageSize) { Result result = new Result(); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectCode); Status resultStatus = (Status) checkResult.get(Constants.STATUS); if (resultStatus != Status.SUCCESS) { - putMsg(result,resultStatus); + putMsg(result, resultStatus); return result; } Page page = new Page<>(pageNo, pageSize); IPage processDefinitionIPage = processDefinitionMapper.queryDefineListPaging( - page, searchVal, userId, project.getCode(), isAdmin(loginUser)); + page, searchVal, userId, project.getCode(), isAdmin(loginUser)); List records = processDefinitionIPage.getRecords(); - for (ProcessDefinition pd : records) { - ProcessDefinitionLog processDefinitionLog = processDefinitionLogMapper.queryMaxVersionDefinitionLog(pd.getCode()); - int operator = processDefinitionLog.getOperator(); - User user = userMapper.selectById(operator); + ProcessDefinitionLog processDefinitionLog = processDefinitionLogMapper.queryByDefinitionCodeAndVersion(pd.getCode(), pd.getVersion()); + User user = userMapper.selectById(processDefinitionLog.getOperator()); pd.setModifyBy(user.getUserName()); - pd.setProjectId(project.getId()); } - processDefinitionIPage.setRecords(records); PageInfo pageInfo = new PageInfo<>(pageNo, pageSize); pageInfo.setTotal((int) processDefinitionIPage.getTotal()); @@ -305,58 +379,52 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro } /** - * query datail of process definition + * query detail of process definition * * @param loginUser login user - * @param projectName project name - * @param processId process definition id + * @param projectCode project code + * @param code process definition code * @return process definition detail */ @Override - public Map queryProcessDefinitionById(User loginUser, String projectName, Integer processId) { - - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultStatus = (Status) checkResult.get(Constants.STATUS); - if (resultStatus != Status.SUCCESS) { - return checkResult; + public Map queryProcessDefinitionByCode(User loginUser, long projectCode, long code) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } - ProcessDefinition processDefinition = processDefinitionMapper.selectById(processId); - + ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(code); if (processDefinition == null) { - putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processId); + putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, code); } else { - ProcessData processData = processService.genProcessData(processDefinition); - processDefinition.setProcessDefinitionJson(JSONUtils.toJsonString(processData)); - result.put(Constants.DATA_LIST, processDefinition); + Tenant tenant = tenantMapper.queryById(processDefinition.getTenantId()); + if (tenant != null) { + processDefinition.setTenantCode(tenant.getTenantCode()); + } + DagData dagData = processService.genDagData(processDefinition); + result.put(Constants.DATA_LIST, dagData); putMsg(result, Status.SUCCESS); } return result; } @Override - public Map queryProcessDefinitionByName(User loginUser, String projectName, String processDefinitionName) { - - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultStatus = (Status) checkResult.get(Constants.STATUS); - if (resultStatus != Status.SUCCESS) { - return checkResult; + public Map queryProcessDefinitionByName(User loginUser, long projectCode, String name) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } - - ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineName(project.getCode(), processDefinitionName); + ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineName(projectCode, name); if (processDefinition == null) { - putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionName); + putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, name); } else { - ProcessData processData = processService.genProcessData(processDefinition); - processDefinition.setProcessDefinitionJson(JSONUtils.toJsonString(processData)); - result.put(Constants.DATA_LIST, processDefinition); + DagData dagData = processService.genDagData(processDefinition); + result.put(Constants.DATA_LIST, dagData); putMsg(result, Status.SUCCESS); } return result; @@ -366,43 +434,63 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro * update process definition * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param name process definition name - * @param id process definition id - * @param processDefinitionJson process definition json - * @param desc description + * @param code process definition code + * @param description description + * @param globalParams global params * @param locations locations for nodes - * @param connects connects for nodes + * @param timeout timeout + * @param tenantCode tenantCode + * @param taskRelationJson relation json for nodes + * @param taskDefinitionJson taskDefinitionJson * @return update result code */ + @Transactional(rollbackFor = RuntimeException.class) @Override public Map updateProcessDefinition(User loginUser, - String projectName, - int id, + long projectCode, String name, - String processDefinitionJson, - String desc, + long code, + String description, + String globalParams, String locations, - String connects) { - Map result = new HashMap<>(); - - Project project = projectMapper.queryByName(projectName); - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultStatus = (Status) checkResult.get(Constants.STATUS); - if (resultStatus != Status.SUCCESS) { - return checkResult; + int timeout, + String tenantCode, + String taskRelationJson, + String taskDefinitionJson) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } - ProcessData processData = JSONUtils.parseObject(processDefinitionJson, ProcessData.class); - Map checkProcessJson = checkProcessNodeList(processData, processDefinitionJson); - if ((checkProcessJson.get(Constants.STATUS) != Status.SUCCESS)) { - return checkProcessJson; + List taskDefinitionLogs = JSONUtils.toList(taskDefinitionJson, TaskDefinitionLog.class); + createTaskDefinition(result, loginUser, projectCode, taskDefinitionLogs, taskDefinitionJson); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } - // TODO processDefinitionMapper.queryByCode - ProcessDefinition processDefinition = processService.findProcessDefineById(id); + List taskRelationList = JSONUtils.toList(taskRelationJson, ProcessTaskRelationLog.class); + Map checkRelationJson = checkTaskRelationList(taskRelationList, taskRelationJson, taskDefinitionLogs); + if (checkRelationJson.get(Constants.STATUS) != Status.SUCCESS) { + return checkRelationJson; + } + + int tenantId = -1; + if (!Constants.DEFAULT.equals(tenantCode)) { + Tenant tenant = tenantMapper.queryByTenantCode(tenantCode); + if (tenant == null) { + putMsg(result, Status.TENANT_NOT_EXIST); + return result; + } + tenantId = tenant.getId(); + } + + ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(code); // check process definition exists if (processDefinition == null) { - putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, id); + putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, code); return result; } if (processDefinition.getReleaseState() == ReleaseState.ONLINE) { @@ -418,38 +506,54 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro return result; } } - ProcessData newProcessData = JSONUtils.parseObject(processDefinitionJson, ProcessData.class); - int saveResult = processService.saveProcessDefinition(loginUser, project, name, desc, - locations, connects, newProcessData, processDefinition, true); + ProcessDefinition processDefinitionDeepCopy = JSONUtils.parseObject(JSONUtils.toJsonString(processDefinition), ProcessDefinition.class); + processDefinition.set(projectCode, name, description, globalParams, locations, timeout, tenantId); + return updateProcessDefine(loginUser, result, taskRelationList, processDefinition, processDefinitionDeepCopy, taskDefinitionLogs); + } - if (saveResult > 0) { - putMsg(result, Status.SUCCESS); - result.put(Constants.DATA_LIST, processDefinition); + private Map updateProcessDefine(User loginUser, + Map result, + List taskRelationList, + ProcessDefinition processDefinition, + ProcessDefinition processDefinitionDeepCopy, + List taskDefinitionLogs) { + int insertVersion; + if (processDefinition.equals(processDefinitionDeepCopy)) { + insertVersion = processDefinitionDeepCopy.getVersion(); + } else { + processDefinition.setUpdateTime(new Date()); + insertVersion = processService.saveProcessDefine(loginUser, processDefinition, true); + } + if (insertVersion > 0) { + int insertResult = processService.saveTaskRelation(loginUser, processDefinition.getProjectCode(), + processDefinition.getCode(), insertVersion, taskRelationList, taskDefinitionLogs); + if (insertResult == Constants.EXIT_CODE_SUCCESS) { + putMsg(result, Status.SUCCESS); + result.put(Constants.DATA_LIST, processDefinition); + } else { + putMsg(result, Status.UPDATE_PROCESS_DEFINITION_ERROR); + } } else { putMsg(result, Status.UPDATE_PROCESS_DEFINITION_ERROR); } return result; } - /** * verify process definition name unique * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param name name * @return true if process definition name not exists, otherwise false */ @Override - public Map verifyProcessDefinitionName(User loginUser, String projectName, String name) { - - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultEnum = (Status) checkResult.get(Constants.STATUS); - if (resultEnum != Status.SUCCESS) { - return checkResult; + public Map verifyProcessDefinitionName(User loginUser, long projectCode, String name) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } ProcessDefinition processDefinition = processDefinitionMapper.verifyByDefineName(project.getCode(), name.trim()); if (processDefinition == null) { @@ -461,33 +565,25 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro } /** - * delete process definition by id + * delete process definition by code * * @param loginUser login user - * @param projectName project name - * @param processDefinitionId process definition id + * @param projectCode project code + * @param code process definition code * @return delete result code */ @Override @Transactional(rollbackFor = RuntimeException.class) - public Map deleteProcessDefinitionById(User loginUser, String projectName, Integer processDefinitionId) { - - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultEnum = (Status) checkResult.get(Constants.STATUS); - if (resultEnum != Status.SUCCESS) { - return checkResult; + public Map deleteProcessDefinitionByCode(User loginUser, long projectCode, long code) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } - - ProcessDefinition processDefinition = processDefinitionMapper.selectById(processDefinitionId); - - // TODO: replace id to code - // ProcessDefinition processDefinition = processDefineMapper.selectByCode(processDefinitionCode); - + ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(code); if (processDefinition == null) { - putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionId); + putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, code); return result; } @@ -499,21 +595,21 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro // check process definition is already online if (processDefinition.getReleaseState() == ReleaseState.ONLINE) { - putMsg(result, Status.PROCESS_DEFINE_STATE_ONLINE, processDefinitionId); + putMsg(result, Status.PROCESS_DEFINE_STATE_ONLINE, code); return result; } // check process instances is already running List processInstances = processInstanceService.queryByProcessDefineCodeAndStatus(processDefinition.getCode(), Constants.NOT_TERMINATED_STATES); if (CollectionUtils.isNotEmpty(processInstances)) { - putMsg(result, Status.DELETE_PROCESS_DEFINITION_BY_ID_FAIL, processInstances.size()); + putMsg(result, Status.DELETE_PROCESS_DEFINITION_BY_CODE_FAIL, processInstances.size()); return result; } // get the timing according to the process definition - List schedules = scheduleMapper.queryByProcessDefinitionId(processDefinitionId); + List schedules = scheduleMapper.queryByProcessDefinitionCode(code); if (!schedules.isEmpty() && schedules.size() > 1) { logger.warn("scheduler num is {},Greater than 1", schedules.size()); - putMsg(result, Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR); + putMsg(result, Status.DELETE_PROCESS_DEFINE_BY_CODE_ERROR); return result; } else if (schedules.size() == 1) { Schedule schedule = schedules.get(0); @@ -525,12 +621,12 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro } } - int delete = processDefinitionMapper.deleteById(processDefinitionId); + int delete = processDefinitionMapper.deleteById(processDefinition.getId()); processTaskRelationMapper.deleteByCode(project.getCode(), processDefinition.getCode()); if (delete > 0) { putMsg(result, Status.SUCCESS); } else { - putMsg(result, Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR); + putMsg(result, Status.DELETE_PROCESS_DEFINE_BY_CODE_ERROR); } return result; } @@ -539,21 +635,19 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro * release process definition: online / offline * * @param loginUser login user - * @param projectName project name - * @param id process definition id + * @param projectCode project code + * @param code process definition code * @param releaseState release state * @return release result code */ @Override @Transactional(rollbackFor = RuntimeException.class) - public Map releaseProcessDefinition(User loginUser, String projectName, int id, ReleaseState releaseState) { - HashMap result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultEnum = (Status) checkResult.get(Constants.STATUS); - if (resultEnum != Status.SUCCESS) { - return checkResult; + public Map releaseProcessDefinition(User loginUser, long projectCode, long code, ReleaseState releaseState) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } // check state @@ -562,7 +656,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro return result; } - ProcessDefinition processDefinition = processDefinitionMapper.selectById(id); + ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(code); switch (releaseState) { case ONLINE: @@ -587,11 +681,11 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro processDefinition.setReleaseState(releaseState); processDefinitionMapper.updateById(processDefinition); List scheduleList = scheduleMapper.selectAllByProcessDefineArray( - new int[]{processDefinition.getId()} + new long[]{processDefinition.getCode()} ); for (Schedule schedule : scheduleList) { - logger.info("set schedule offline, project id: {}, schedule id: {}, process definition id: {}", project.getId(), schedule.getId(), id); + logger.info("set schedule offline, project id: {}, schedule id: {}, process definition code: {}", project.getId(), schedule.getId(), code); // set status schedule.setReleaseState(ReleaseState.OFFLINE); scheduleMapper.updateById(schedule); @@ -608,61 +702,38 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro } /** - * batch export process definition by ids + * batch export process definition by codes */ @Override - public void batchExportProcessDefinitionByIds(User loginUser, String projectName, String processDefinitionIds, HttpServletResponse response) { - - if (StringUtils.isEmpty(processDefinitionIds)) { + public void batchExportProcessDefinitionByCodes(User loginUser, long projectCode, String codes, HttpServletResponse response) { + if (StringUtils.isEmpty(codes)) { return; } - - //export project info - Project project = projectMapper.queryByName(projectName); - + Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultStatus = (Status) checkResult.get(Constants.STATUS); - - if (resultStatus != Status.SUCCESS) { + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { return; } - - List processDefinitionList = - getProcessDefinitionList(processDefinitionIds); - - if (CollectionUtils.isNotEmpty(processDefinitionList)) { - downloadProcessDefinitionFile(response, processDefinitionList); + Set defineCodeSet = Lists.newArrayList(codes.split(Constants.COMMA)).stream().map(Long::parseLong).collect(Collectors.toSet()); + List processDefinitionList = processDefinitionMapper.queryByCodes(defineCodeSet); + List dagDataSchedules = processDefinitionList.stream().map(this::exportProcessDagData).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(dagDataSchedules)) { + downloadProcessDefinitionFile(response, dagDataSchedules); } } - /** - * get process definition list by ids - */ - private List getProcessDefinitionList(String processDefinitionIds) { - String[] processDefinitionIdArray = processDefinitionIds.split(","); - - List processDefinitionList = new ArrayList<>(); - for (String strProcessDefinitionId : processDefinitionIdArray) { - //get workflow info - int processDefinitionId = Integer.parseInt(strProcessDefinitionId); - ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineId(processDefinitionId); - processDefinitionList.add(exportProcessMetaData(processDefinition)); - } - return processDefinitionList; - } - /** * download the process definition file */ - private void downloadProcessDefinitionFile(HttpServletResponse response, List processDefinitionList) { + private void downloadProcessDefinitionFile(HttpServletResponse response, List dagDataSchedules) { response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); BufferedOutputStream buff = null; ServletOutputStream out = null; try { out = response.getOutputStream(); buff = new BufferedOutputStream(out); - buff.write(JSONUtils.toJsonString(processDefinitionList).getBytes(StandardCharsets.UTF_8)); + buff.write(JSONUtils.toJsonString(dagDataSchedules).getBytes(StandardCharsets.UTF_8)); buff.flush(); buff.close(); } catch (IOException e) { @@ -686,234 +757,126 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro } /** - * get export process metadata string + * get export process dag data * * @param processDefinition process definition - * @return export process metadata string + * @return DagDataSchedule */ - public ProcessMeta exportProcessMetaData(ProcessDefinition processDefinition) { - ProcessData processData = processService.genProcessData(processDefinition); - //correct task param which has data source or dependent param - addExportTaskNodeSpecialParam(processData); - - //export process metadata - ProcessMeta exportProcessMeta = new ProcessMeta(); - exportProcessMeta.setProjectName(processDefinition.getProjectName()); - exportProcessMeta.setProcessDefinitionName(processDefinition.getName()); - exportProcessMeta.setProcessDefinitionJson(JSONUtils.toJsonString(processService.genProcessData(processDefinition))); - exportProcessMeta.setProcessDefinitionDescription(processDefinition.getDescription()); - exportProcessMeta.setProcessDefinitionLocations(processDefinition.getLocations()); - exportProcessMeta.setProcessDefinitionConnects(processDefinition.getConnects()); - - //schedule info - List schedules = scheduleMapper.queryByProcessDefinitionId(processDefinition.getId()); + public DagDataSchedule exportProcessDagData(ProcessDefinition processDefinition) { + List schedules = scheduleMapper.queryByProcessDefinitionCode(processDefinition.getCode()); + DagDataSchedule dagDataSchedule = new DagDataSchedule(processService.genDagData(processDefinition)); if (!schedules.isEmpty()) { Schedule schedule = schedules.get(0); - exportProcessMeta.setScheduleWarningType(schedule.getWarningType().toString()); - exportProcessMeta.setScheduleWarningGroupId(schedule.getWarningGroupId()); - exportProcessMeta.setScheduleStartTime(DateUtils.dateToString(schedule.getStartTime())); - exportProcessMeta.setScheduleEndTime(DateUtils.dateToString(schedule.getEndTime())); - exportProcessMeta.setScheduleCrontab(schedule.getCrontab()); - exportProcessMeta.setScheduleFailureStrategy(String.valueOf(schedule.getFailureStrategy())); - exportProcessMeta.setScheduleReleaseState(String.valueOf(ReleaseState.OFFLINE)); - exportProcessMeta.setScheduleProcessInstancePriority(String.valueOf(schedule.getProcessInstancePriority())); - exportProcessMeta.setScheduleWorkerGroupName(schedule.getWorkerGroup()); + schedule.setReleaseState(ReleaseState.OFFLINE); + dagDataSchedule.setSchedule(schedule); } - //create workflow json file - return exportProcessMeta; - } - - /** - * Injecting parameters into export process definition - * Because the import and export environment resource IDs may be inconsistent,So inject the resource name - * - * SQL and PROCEDURE node, inject datasourceName - * DEPENDENT node, inject projectName and definitionName - * - * @param processData process data - */ - private void addExportTaskNodeSpecialParam(ProcessData processData) { - for (TaskNode taskNode : processData.getTasks()) { - if (TaskType.SQL.getDesc().equals(taskNode.getType()) - || TaskType.PROCEDURE.getDesc().equals(taskNode.getType())) { - ObjectNode sqlParameters = JSONUtils.parseObject(taskNode.getParams()); - - DataSource dataSource = dataSourceMapper.selectById( - sqlParameters.path(Constants.TASK_PARAMS_DATASOURCE).asInt()); - - if (dataSource != null) { - sqlParameters.put(Constants.TASK_PARAMS_DATASOURCE_NAME, dataSource.getName()); - taskNode.setParams(JSONUtils.toJsonString(sqlParameters)); - } - } - - if (TaskType.DEPENDENT.getDesc().equals(taskNode.getType())) { - ObjectNode dependentParameters = JSONUtils.parseObject(taskNode.getDependence()); - - if (dependentParameters != null) { - ArrayNode dependTaskList = (ArrayNode)dependentParameters.get( - Constants.TASK_DEPENDENCE_DEPEND_TASK_LIST); - for (int j = 0; j < dependTaskList.size(); j++) { - JsonNode dependentTaskModel = dependTaskList.path(j); - ArrayNode dependItemList = (ArrayNode)dependentTaskModel.get( - Constants.TASK_DEPENDENCE_DEPEND_ITEM_LIST); - for (int k = 0; k < dependItemList.size(); k++) { - ObjectNode dependentItem = (ObjectNode)dependItemList.path(k); - int definitionId = dependentItem.path(Constants.TASK_DEPENDENCE_DEFINITION_ID).asInt(); - ProcessDefinition definition = processDefinitionMapper.queryByDefineId(definitionId); - if (definition != null) { - dependentItem.put(Constants.TASK_DEPENDENCE_PROJECT_NAME, definition.getProjectName()); - dependentItem.put(Constants.TASK_DEPENDENCE_DEFINITION_NAME, definition.getName()); - } - } - } - - taskNode.setDependence(dependentParameters.toString()); - } - } - } - } - - /** - * check task if has sub process - * - * @param taskType task type - * @return if task has sub process return true else false - */ - private boolean checkTaskHasSubProcess(String taskType) { - return taskType.equals(TaskType.SUB_PROCESS.getDesc()); + return dagDataSchedule; } /** * import process definition * * @param loginUser login user + * @param projectCode project code * @param file process metadata json file - * @param currentProjectName current project name * @return import process */ @Override @Transactional(rollbackFor = RuntimeException.class) - public Map importProcessDefinition(User loginUser, MultipartFile file, String currentProjectName) { + public Map importProcessDefinition(User loginUser, long projectCode, MultipartFile file) { Map result = new HashMap<>(); - String processMetaJson = FileUtils.file2String(file); - List processMetaList = JSONUtils.toList(processMetaJson, ProcessMeta.class); - + String dagDataScheduleJson = FileUtils.file2String(file); + List dagDataScheduleList = JSONUtils.toList(dagDataScheduleJson, DagDataSchedule.class); //check file content - if (CollectionUtils.isEmpty(processMetaList)) { + if (CollectionUtils.isEmpty(dagDataScheduleList)) { putMsg(result, Status.DATA_IS_NULL, "fileContent"); return result; } - - for (ProcessMeta processMeta : processMetaList) { - - if (!checkAndImportProcessDefinition(loginUser, currentProjectName, result, processMeta)) { + for (DagDataSchedule dagDataSchedule : dagDataScheduleList) { + if (!checkAndImport(loginUser, projectCode, result, dagDataSchedule)) { return result; } } - return result; } /** - * check and import process definition + * check and import */ - private boolean checkAndImportProcessDefinition(User loginUser, String currentProjectName, Map result, ProcessMeta processMeta) { - - if (!checkImportanceParams(processMeta, result)) { + private boolean checkAndImport(User loginUser, long projectCode, Map result, DagDataSchedule dagDataSchedule) { + if (!checkImportanceParams(dagDataSchedule, result)) { return false; } - - //deal with process name - String processDefinitionName = processMeta.getProcessDefinitionName(); - //use currentProjectName to query - Project targetProject = projectMapper.queryByName(currentProjectName); - if (null != targetProject) { - processDefinitionName = recursionProcessDefinitionName(targetProject.getCode(), - processDefinitionName, 1); - } - + ProcessDefinition processDefinition = dagDataSchedule.getProcessDefinition(); //unique check - Map checkResult = verifyProcessDefinitionName(loginUser, currentProjectName, processDefinitionName); - Status status = (Status) checkResult.get(Constants.STATUS); - if (Status.SUCCESS.equals(status)) { + Map checkResult = verifyProcessDefinitionName(loginUser, projectCode, processDefinition.getName()); + if (Status.SUCCESS.equals(checkResult.get(Constants.STATUS))) { putMsg(result, Status.SUCCESS); } else { result.putAll(checkResult); return false; } - - // get create process result - Map createProcessResult = - getCreateProcessResult(loginUser, - currentProjectName, - result, - processMeta, - processDefinitionName, - addImportTaskNodeParam(loginUser, processMeta.getProcessDefinitionJson(), targetProject)); - - if (createProcessResult == null) { + String processDefinitionName = recursionProcessDefinitionName(projectCode, processDefinition.getName(), 1); + processDefinition.setName(processDefinitionName + "_import_" + DateUtils.getCurrentTimeStamp()); + processDefinition.setUserId(loginUser.getId()); + try { + processDefinition.setCode(SnowFlakeUtils.getInstance().nextId()); + } catch (SnowFlakeException e) { + putMsg(result, Status.CREATE_PROCESS_DEFINITION_ERROR); + return false; + } + List taskDefinitionList = dagDataSchedule.getTaskDefinitionList(); + Map taskCodeMap = new HashMap<>(); + Date now = new Date(); + for (TaskDefinitionLog taskDefinitionLog : taskDefinitionList) { + taskDefinitionLog.setName(taskDefinitionLog.getName() + "_import_" + DateUtils.getCurrentTimeStamp()); + taskDefinitionLog.setProjectCode(projectCode); + taskDefinitionLog.setUserId(loginUser.getId()); + taskDefinitionLog.setVersion(Constants.VERSION_FIRST); + taskDefinitionLog.setCreateTime(now); + taskDefinitionLog.setUpdateTime(now); + taskDefinitionLog.setOperator(loginUser.getId()); + taskDefinitionLog.setOperateTime(now); + try { + long code = SnowFlakeUtils.getInstance().nextId(); + taskCodeMap.put(taskDefinitionLog.getCode(), code); + taskDefinitionLog.setCode(code); + } catch (SnowFlakeException e) { + logger.error("Task code get error, ", e); + putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS, "Error generating task definition code"); + return false; + } + } + int insert = taskDefinitionMapper.batchInsert(taskDefinitionList); + int logInsert = taskDefinitionLogMapper.batchInsert(taskDefinitionList); + if ((logInsert & insert) == 0) { + putMsg(result, Status.CREATE_TASK_DEFINITION_ERROR); return false; } - //create process definition - Integer processDefinitionId = - Objects.isNull(createProcessResult.get(Constants.DATA_LIST)) - ? null : Integer.parseInt(createProcessResult.get(Constants.DATA_LIST).toString()); - - //scheduler param - return getImportProcessScheduleResult(loginUser, - currentProjectName, - result, - processMeta, - processDefinitionName, - processDefinitionId); - - } - - /** - * get create process result - */ - private Map getCreateProcessResult(User loginUser, - String currentProjectName, - Map result, - ProcessMeta processMeta, - String processDefinitionName, - String importProcessParam) { - Map createProcessResult = null; - try { - createProcessResult = createProcessDefinition(loginUser - , currentProjectName, - processDefinitionName + "_import_" + DateUtils.getCurrentTimeStamp(), - importProcessParam, - processMeta.getProcessDefinitionDescription(), - processMeta.getProcessDefinitionLocations(), - processMeta.getProcessDefinitionConnects()); - putMsg(result, Status.SUCCESS); - } catch (Exception e) { - logger.error("import process meta json data: {}", e.getMessage(), e); - putMsg(result, Status.IMPORT_PROCESS_DEFINE_ERROR); + List taskRelationList = dagDataSchedule.getProcessTaskRelationList(); + taskRelationList.forEach(processTaskRelationLog -> { + processTaskRelationLog.setPreTaskCode(taskCodeMap.get(processTaskRelationLog.getPreTaskCode())); + processTaskRelationLog.setPostTaskCode(taskCodeMap.get(processTaskRelationLog.getPostTaskCode())); + processTaskRelationLog.setPreTaskVersion(Constants.VERSION_FIRST); + processTaskRelationLog.setPostTaskVersion(Constants.VERSION_FIRST); + }); + Map createProcessResult = createProcessDefine(loginUser, result, taskRelationList, processDefinition, null); + if (Status.SUCCESS.equals(createProcessResult.get(Constants.STATUS))) { + putMsg(createProcessResult, Status.SUCCESS); + } else { + result.putAll(createProcessResult); + return false; } - return createProcessResult; - } - - /** - * get import process schedule result - */ - private boolean getImportProcessScheduleResult(User loginUser, - String currentProjectName, - Map result, - ProcessMeta processMeta, - String processDefinitionName, - Integer processDefinitionId) { - if (null != processMeta.getScheduleCrontab() && null != processDefinitionId) { - int scheduleInsert = importProcessSchedule(loginUser, - currentProjectName, - processMeta, - processDefinitionName, - processDefinitionId); - + Schedule schedule = dagDataSchedule.getSchedule(); + if (null != schedule) { + ProcessDefinition newProcessDefinition = processDefinitionMapper.queryByCode(processDefinition.getCode()); + schedule.setProcessDefinitionCode(newProcessDefinition.getCode()); + schedule.setUserId(loginUser.getId()); + schedule.setCreateTime(now); + schedule.setUpdateTime(now); + int scheduleInsert = scheduleMapper.insert(schedule); if (0 == scheduleInsert) { putMsg(result, Status.IMPORT_PROCESS_DEFINE_ERROR); return false; @@ -925,262 +888,56 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro /** * check importance params */ - private boolean checkImportanceParams(ProcessMeta processMeta, Map result) { - if (StringUtils.isEmpty(processMeta.getProjectName())) { - putMsg(result, Status.DATA_IS_NULL, "projectName"); + private boolean checkImportanceParams(DagDataSchedule dagDataSchedule, Map result) { + if (dagDataSchedule.getProcessDefinition() == null) { + putMsg(result, Status.DATA_IS_NULL, "ProcessDefinition"); return false; } - if (StringUtils.isEmpty(processMeta.getProcessDefinitionName())) { - putMsg(result, Status.DATA_IS_NULL, "processDefinitionName"); + if (CollectionUtils.isEmpty(dagDataSchedule.getTaskDefinitionList())) { + putMsg(result, Status.DATA_IS_NULL, "TaskDefinitionList"); return false; } - if (StringUtils.isEmpty(processMeta.getProcessDefinitionJson())) { - putMsg(result, Status.DATA_IS_NULL, "processDefinitionJson"); + if (CollectionUtils.isEmpty(dagDataSchedule.getProcessTaskRelationList())) { + putMsg(result, Status.DATA_IS_NULL, "ProcessTaskRelationList"); return false; } - return true; } - /** - * import process add special task param - * - * @param loginUser login user - * @param processDefinitionJson process definition json - * @param targetProject target project - * @return import process param - */ - private String addImportTaskNodeParam(User loginUser, String processDefinitionJson, Project targetProject) { - ObjectNode jsonObject = JSONUtils.parseObject(processDefinitionJson); - ArrayNode jsonArray = (ArrayNode) jsonObject.get(TASKS); - - addImportTaskNodeSpecialParam(jsonArray); - - //recursive sub-process parameter correction map key for old process code value for new process code - Map subProcessCodeMap = new HashMap<>(); - - List subProcessList = StreamUtils.asStream(jsonArray.elements()) - .filter(elem -> checkTaskHasSubProcess(JSONUtils.parseObject(elem.toString()).path("type").asText())) - .collect(Collectors.toList()); - - if (CollectionUtils.isNotEmpty(subProcessList)) { - importSubProcess(loginUser, targetProject, jsonArray, subProcessCodeMap); + private String recursionProcessDefinitionName(long projectCode, String processDefinitionName, int num) { + ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineName(projectCode, processDefinitionName); + if (processDefinition != null) { + if (num > 1) { + String str = processDefinitionName.substring(0, processDefinitionName.length() - 3); + processDefinitionName = str + "(" + num + ")"; + } else { + processDefinitionName = processDefinition.getName() + "(" + num + ")"; + } + } else { + return processDefinitionName; } - - jsonObject.set(TASKS, jsonArray); - return jsonObject.toString(); + return recursionProcessDefinitionName(projectCode, processDefinitionName, num + 1); } /** - * Replace the injecting parameters in import process definition + * check the process task relation json * - * SQL and PROCEDURE node, inject datasource by datasourceName - * DEPENDENT node, inject projectId and definitionId by projectName and definitionName - * - * @param jsonArray array node - */ - private void addImportTaskNodeSpecialParam(ArrayNode jsonArray) { - // add sql and dependent param - for (int i = 0; i < jsonArray.size(); i++) { - JsonNode taskNode = jsonArray.path(i); - String taskType = taskNode.path("type").asText(); - - if (TaskType.SQL.getDesc().equals(taskType) || TaskType.PROCEDURE.getDesc().equals(taskType)) { - ObjectNode sqlParameters = (ObjectNode)taskNode.path(Constants.TASK_PARAMS); - - List dataSources = dataSourceMapper.queryDataSourceByName( - sqlParameters.path(Constants.TASK_PARAMS_DATASOURCE_NAME).asText()); - if (!dataSources.isEmpty()) { - DataSource dataSource = dataSources.get(0); - sqlParameters.put(Constants.TASK_PARAMS_DATASOURCE, dataSource.getId()); - } - - ((ObjectNode)taskNode).set(Constants.TASK_PARAMS, sqlParameters); - } - - if (TaskType.DEPENDENT.getDesc().equals(taskType)) { - ObjectNode dependentParameters = (ObjectNode)taskNode.path(Constants.DEPENDENCE); - if (dependentParameters != null) { - ArrayNode dependTaskList = (ArrayNode)dependentParameters.path( - Constants.TASK_DEPENDENCE_DEPEND_TASK_LIST); - for (int h = 0; h < dependTaskList.size(); h++) { - ObjectNode dependentTaskModel = (ObjectNode)dependTaskList.path(h); - ArrayNode dependItemList = (ArrayNode)dependentTaskModel.get( - Constants.TASK_DEPENDENCE_DEPEND_ITEM_LIST); - for (int k = 0; k < dependItemList.size(); k++) { - ObjectNode dependentItem = (ObjectNode)dependItemList.path(k); - Project dependentItemProject = projectMapper.queryByName( - dependentItem.path(Constants.TASK_DEPENDENCE_PROJECT_NAME).asText()); - if (dependentItemProject != null) { - ProcessDefinition definition = processDefinitionMapper.queryByDefineName( - dependentItemProject.getCode(), - dependentItem.path(Constants.TASK_DEPENDENCE_DEFINITION_NAME).asText()); - if (definition != null) { - dependentItem.put(Constants.TASK_DEPENDENCE_PROJECT_ID, - dependentItemProject.getId()); - dependentItem.put(Constants.TASK_DEPENDENCE_DEFINITION_ID, definition.getId()); - } - } - } - } - - ((ObjectNode)taskNode).set(Constants.DEPENDENCE, dependentParameters); - } - } - } - } - - /** - * import process schedule - * - * @param loginUser login user - * @param currentProjectName current project name - * @param processMeta process meta data - * @param processDefinitionName process definition name - * @param processDefinitionId process definition id - * @return insert schedule flag - */ - public int importProcessSchedule(User loginUser, String currentProjectName, ProcessMeta processMeta, - String processDefinitionName, Integer processDefinitionId) { - Date now = new Date(); - Schedule scheduleObj = new Schedule(); - scheduleObj.setProjectName(currentProjectName); - scheduleObj.setProcessDefinitionId(processDefinitionId); - scheduleObj.setProcessDefinitionName(processDefinitionName); - scheduleObj.setCreateTime(now); - scheduleObj.setUpdateTime(now); - scheduleObj.setUserId(loginUser.getId()); - scheduleObj.setUserName(loginUser.getUserName()); - - scheduleObj.setCrontab(processMeta.getScheduleCrontab()); - - if (null != processMeta.getScheduleStartTime()) { - scheduleObj.setStartTime(DateUtils.stringToDate(processMeta.getScheduleStartTime())); - } - if (null != processMeta.getScheduleEndTime()) { - scheduleObj.setEndTime(DateUtils.stringToDate(processMeta.getScheduleEndTime())); - } - if (null != processMeta.getScheduleWarningType()) { - scheduleObj.setWarningType(WarningType.valueOf(processMeta.getScheduleWarningType())); - } - if (null != processMeta.getScheduleWarningGroupId()) { - scheduleObj.setWarningGroupId(processMeta.getScheduleWarningGroupId()); - } - if (null != processMeta.getScheduleFailureStrategy()) { - scheduleObj.setFailureStrategy(FailureStrategy.valueOf(processMeta.getScheduleFailureStrategy())); - } - if (null != processMeta.getScheduleReleaseState()) { - scheduleObj.setReleaseState(ReleaseState.valueOf(processMeta.getScheduleReleaseState())); - } - if (null != processMeta.getScheduleProcessInstancePriority()) { - scheduleObj.setProcessInstancePriority(Priority.valueOf(processMeta.getScheduleProcessInstancePriority())); - } - - if (null != processMeta.getScheduleWorkerGroupName()) { - scheduleObj.setWorkerGroup(processMeta.getScheduleWorkerGroupName()); - } - - return scheduleMapper.insert(scheduleObj); - } - - /** - * check import process has sub process - * recursion create sub process - * - * @param loginUser login user - * @param targetProject target project - * @param jsonArray process task array - * @param subProcessCodeMap correct sub process id map - */ - private void importSubProcess(User loginUser, Project targetProject, ArrayNode jsonArray, Map subProcessCodeMap) { - for (int i = 0; i < jsonArray.size(); i++) { - ObjectNode taskNode = (ObjectNode) jsonArray.path(i); - String taskType = taskNode.path("type").asText(); - - if (!checkTaskHasSubProcess(taskType)) { - continue; - } - //get sub process info - ObjectNode subParams = (ObjectNode) taskNode.path("params"); - Long subProcessCode = subParams.path(PROCESSDEFINITIONCODE).asLong(); - ProcessDefinition subProcess = processDefinitionMapper.queryByCode(subProcessCode); - //check is sub process exist in db - if (null == subProcess) { - continue; - } - - String subProcessJson = JSONUtils.toJsonString(processService.genProcessData(subProcess)); - //check current project has sub process - ProcessDefinition currentProjectSubProcess = processDefinitionMapper.queryByDefineName(targetProject.getCode(), subProcess.getName()); - - if (null == currentProjectSubProcess) { - ArrayNode subJsonArray = (ArrayNode) JSONUtils.parseObject(subProcessJson).get(TASKS); - - List subProcessList = StreamUtils.asStream(subJsonArray.elements()) - .filter(item -> checkTaskHasSubProcess(JSONUtils.parseObject(item.toString()).path("type").asText())) - .collect(Collectors.toList()); - - if (CollectionUtils.isNotEmpty(subProcessList)) { - importSubProcess(loginUser, targetProject, subJsonArray, subProcessCodeMap); - //sub process processId correct - if (!subProcessCodeMap.isEmpty()) { - - for (Map.Entry entry : subProcessCodeMap.entrySet()) { - String oldSubProcessCode = "\"processDefinitionCode\":" + entry.getKey(); - String newSubProcessCode = "\"processDefinitionCode\":" + entry.getValue(); - subProcessJson = subProcessJson.replaceAll(oldSubProcessCode, newSubProcessCode); - } - - subProcessCodeMap.clear(); - } - } - - try { - createProcessDefinition(loginUser - , targetProject.getName(), - subProcess.getName(), - subProcessJson, - subProcess.getDescription(), - subProcess.getLocations(), - subProcess.getConnects()); - logger.info("create sub process, project: {}, process name: {}", targetProject.getName(), subProcess.getName()); - - } catch (Exception e) { - logger.error("import process meta json data: {}", e.getMessage(), e); - } - - //modify task node - ProcessDefinition newSubProcessDefine = processDefinitionMapper.queryByDefineName(subProcess.getCode(), subProcess.getName()); - - if (null != newSubProcessDefine) { - subProcessCodeMap.put(subProcessCode, newSubProcessDefine.getCode()); - subParams.put(PROCESSDEFINITIONCODE, newSubProcessDefine.getId()); - taskNode.set("params", subParams); - } - } - } - } - - /** - * check the process definition node meets the specifications - * - * @param processData process data - * @param processDefinitionJson process definition json + * @param processTaskRelationJson process task relation json * @return check result code */ @Override - public Map checkProcessNodeList(ProcessData processData, String processDefinitionJson) { - + public Map checkProcessNodeList(String processTaskRelationJson) { Map result = new HashMap<>(); try { - if (processData == null) { + if (processTaskRelationJson == null) { logger.error("process data is null"); - putMsg(result, Status.DATA_IS_NOT_VALID, processDefinitionJson); + putMsg(result, Status.DATA_IS_NOT_VALID, processTaskRelationJson); return result; } + List taskRelationList = JSONUtils.toList(processTaskRelationJson, ProcessTaskRelationLog.class); // Check whether the task node is normal - List taskNodes = processData.getTasks(); + List taskNodes = processService.transformTask(taskRelationList, Lists.newArrayList()); if (CollectionUtils.isEmpty(taskNodes)) { logger.error("process node info is empty"); @@ -1217,63 +974,60 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro /** * get task node details based on process definition * - * @param defineCode define code - * @return task node list - */ - public Map getTaskNodeListByDefinitionCode(Long defineCode) { - Map result = new HashMap<>(); - - ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(defineCode); - if (processDefinition == null) { - logger.info("process define not exists"); - putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, defineCode); - return result; - } - ProcessData processData = processService.genProcessData(processDefinition); - - //process data check - if (null == processData) { - logger.error("process data is null"); - putMsg(result, Status.DATA_IS_NOT_VALID, JSONUtils.toJsonString(processData)); - return result; - } - - List taskNodeList = (processData.getTasks() == null) ? new ArrayList<>() : processData.getTasks(); - - result.put(Constants.DATA_LIST, taskNodeList); - putMsg(result, Status.SUCCESS); - - return result; - - } - - /** - * get task node details based on process definition - * - * @param defineCodeList define code list + * @param loginUser loginUser + * @param projectCode project code + * @param code process definition code * @return task node list */ @Override - public Map getTaskNodeListByDefinitionCodeList(String defineCodeList) { - Map result = new HashMap<>(); - - Map> taskNodeMap = new HashMap<>(); - String[] codeArr = defineCodeList.split(","); - List codeList = new ArrayList<>(); - for (String definitionCode : codeArr) { - codeList.add(Long.parseLong(definitionCode)); + public Map getTaskNodeListByDefinitionCode(User loginUser, long projectCode, long code) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } - List processDefinitionList = processDefinitionMapper.queryByCodes(codeList); - if (CollectionUtils.isEmpty(processDefinitionList)) { - logger.info("process definition not exists"); - putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, defineCodeList); + ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(code); + if (processDefinition == null) { + logger.info("process define not exists"); + putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, code); + return result; + } + DagData dagData = processService.genDagData(processDefinition); + result.put(Constants.DATA_LIST, dagData.getTaskDefinitionList()); + putMsg(result, Status.SUCCESS); + + return result; + } + + /** + * get task node details map based on process definition + * + * @param loginUser loginUser + * @param projectCode project code + * @param codes define codes + * @return task node list + */ + @Override + public Map getNodeListMapByDefinitionCodes(User loginUser, long projectCode, String codes) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } + Set defineCodeSet = Lists.newArrayList(codes.split(Constants.COMMA)).stream().map(Long::parseLong).collect(Collectors.toSet()); + List processDefinitionList = processDefinitionMapper.queryByCodes(defineCodeSet); + if (CollectionUtils.isEmpty(processDefinitionList)) { + logger.info("process definition not exists"); + putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, codes); + return result; + } + Map> taskNodeMap = new HashMap<>(); for (ProcessDefinition processDefinition : processDefinitionList) { - ProcessData processData = processService.genProcessData(processDefinition); - List taskNodeList = (processData.getTasks() == null) ? new ArrayList<>() : processData.getTasks(); - taskNodeMap.put(processDefinition.getId(), taskNodeList); + DagData dagData = processService.genDagData(processDefinition); + taskNodeMap.put(processDefinition.getCode(), dagData.getTaskDefinitionList()); } result.put(Constants.DATA_LIST, taskNodeMap); @@ -1284,69 +1038,56 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro } /** - * query process definition all by project id + * query process definition all by project code * - * @param projectId project id + * @param loginUser loginUser + * @param projectCode project code * @return process definitions in the project */ @Override - public Map queryProcessDefinitionAllByProjectId(Integer projectId) { - - HashMap result = new HashMap<>(); - - Project project = projectMapper.selectById(projectId); - List resourceList = processDefinitionMapper.queryAllDefinitionList(project.getCode()); - resourceList.forEach(processDefinition -> { - ProcessData processData = processService.genProcessData(processDefinition); - processDefinition.setProcessDefinitionJson(JSONUtils.toJsonString(processData)); - }); - result.put(Constants.DATA_LIST, resourceList); + public Map queryAllProcessDefinitionByProjectCode(User loginUser, long projectCode) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; + } + List processDefinitions = processDefinitionMapper.queryAllDefinitionList(projectCode); + List dagDataList = processDefinitions.stream().map(processService::genDagData).collect(Collectors.toList()); + result.put(Constants.DATA_LIST, dagDataList); putMsg(result, Status.SUCCESS); - return result; } /** * Encapsulates the TreeView structure * - * @param processId process definition id + * @param code process definition code * @param limit limit * @return tree view json data - * @throws Exception exception */ @Override - public Map viewTree(Integer processId, Integer limit) throws Exception { + public Map viewTree(long code, Integer limit) { Map result = new HashMap<>(); - - ProcessDefinition processDefinition = processDefinitionMapper.selectById(processId); + ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(code); if (null == processDefinition) { logger.info("process define not exists"); - putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processDefinition); + putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, code); return result; } DAG dag = processService.genDagGraph(processDefinition); - /** - * nodes that is running - */ + // nodes that is running Map> runningNodeMap = new ConcurrentHashMap<>(); - /** - * nodes that is waiting torun - */ + //nodes that is waiting to run Map> waitingRunningNodeMap = new ConcurrentHashMap<>(); - /** - * List of process instances - */ - List processInstanceList = processInstanceService.queryByProcessDefineCode(processDefinition.getCode(), limit); - List taskDefinitionList = processService.queryTaskDefinitionList(processDefinition.getCode(), - processDefinition.getVersion()); - Map taskDefinitionMap = new HashedMap(); - taskDefinitionList.forEach(taskDefinitionLog -> taskDefinitionMap.put(taskDefinitionLog.getCode(), taskDefinitionLog)); - - for (ProcessInstance processInstance : processInstanceList) { - processInstance.setDuration(DateUtils.format2Duration(processInstance.getStartTime(), processInstance.getEndTime())); - } + // List of process instances + List processInstanceList = processInstanceService.queryByProcessDefineCode(code, limit); + processInstanceList.forEach(processInstance -> processInstance.setDuration(DateUtils.format2Duration(processInstance.getStartTime(), processInstance.getEndTime()))); + List taskDefinitionList = processService.queryTaskDefinitionListByProcess(code, processDefinition.getVersion()); + Map taskDefinitionMap = taskDefinitionList.stream() + .collect(Collectors.toMap(TaskDefinitionLog::getCode, taskDefinitionLog -> taskDefinitionLog)); if (limit > processInstanceList.size()) { limit = processInstanceList.size(); @@ -1356,13 +1097,12 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro parentTreeViewDto.setName("DAG"); parentTreeViewDto.setType(""); // Specify the process definition, because it is a TreeView for a process definition - for (int i = limit - 1; i >= 0; i--) { ProcessInstance processInstance = processInstanceList.get(i); - Date endTime = processInstance.getEndTime() == null ? new Date() : processInstance.getEndTime(); - parentTreeViewDto.getInstances().add(new Instance(processInstance.getId(), processInstance.getName(), "", processInstance.getState().toString() - , processInstance.getStartTime(), endTime, processInstance.getHost(), DateUtils.format2Readable(endTime.getTime() - processInstance.getStartTime().getTime()))); + parentTreeViewDto.getInstances().add(new Instance(processInstance.getId(), processInstance.getName(), "", + processInstance.getState().toString(), processInstance.getStartTime(), endTime, processInstance.getHost(), + DateUtils.format2Readable(endTime.getTime() - processInstance.getStartTime().getTime()))); } List parentTreeViewDtoList = new ArrayList<>(); @@ -1373,7 +1113,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro } while (Stopper.isRunning()) { - Set postNodeList = null; + Set postNodeList; Iterator>> iter = runningNodeMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry> en = iter.next(); @@ -1396,16 +1136,15 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro Date endTime = taskInstance.getEndTime() == null ? new Date() : taskInstance.getEndTime(); int subProcessId = 0; - /** - * if process is sub process, the return sub id, or sub id=0 - */ + // if process is sub process, the return sub id, or sub id=0 if (taskInstance.isSubProcess()) { TaskDefinition taskDefinition = taskDefinitionMap.get(taskInstance.getTaskCode()); subProcessId = Integer.parseInt(JSONUtils.parseObject( - taskDefinition.getTaskParams()).path(CMD_PARAM_SUB_PROCESS_DEFINE_ID).asText()); + taskDefinition.getTaskParams()).path(CMD_PARAM_SUB_PROCESS_DEFINE_ID).asText()); } - treeViewDto.getInstances().add(new Instance(taskInstance.getId(), taskInstance.getName(), taskInstance.getTaskType(), taskInstance.getState().toString() - , taskInstance.getStartTime(), taskInstance.getEndTime(), taskInstance.getHost(), DateUtils.format2Readable(endTime.getTime() - startTime.getTime()), subProcessId)); + treeViewDto.getInstances().add(new Instance(taskInstance.getId(), taskInstance.getName(), taskInstance.getTaskType(), + taskInstance.getState().toString(), taskInstance.getStartTime(), taskInstance.getEndTime(), taskInstance.getHost(), + DateUtils.format2Readable(endTime.getTime() - startTime.getTime()), subProcessId)); } } for (TreeViewDto pTreeViewDto : parentTreeViewDtoList) { @@ -1463,111 +1202,26 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro return graph.hasCycle(); } - private String recursionProcessDefinitionName(Long projectCode, String processDefinitionName, int num) { - ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineName(projectCode, processDefinitionName); - if (processDefinition != null) { - if (num > 1) { - String str = processDefinitionName.substring(0, processDefinitionName.length() - 3); - processDefinitionName = str + "(" + num + ")"; - } else { - processDefinitionName = processDefinition.getName() + "(" + num + ")"; - } - } else { - return processDefinitionName; - } - return recursionProcessDefinitionName(projectCode, processDefinitionName, num + 1); - } - - private Map copyProcessDefinition(User loginUser, - Integer processId, - Project targetProject) throws JsonProcessingException { - - Map result = new HashMap<>(); - String currentTimeStamp = DateUtils.getCurrentTimeStamp(); - ProcessDefinition processDefinition = processDefinitionMapper.selectById(processId); - if (processDefinition == null) { - putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processId); - return result; - } else { - ProcessData processData = processService.genProcessData(processDefinition); - List taskNodeList = processData.getTasks(); - String locations = processDefinition.getLocations(); - ObjectNode locationsJN = JSONUtils.parseObject(locations); - - for (TaskNode taskNode : taskNodeList) { - String suffix = "_copy_" + currentTimeStamp; - String id = taskNode.getId(); - String newName = locationsJN.path(id).path("name").asText() + suffix; - ((ObjectNode) locationsJN.get(id)).put("name", newName); - - List depList = taskNode.getDepList(); - List newDepList = depList.stream() - .map(s -> s + suffix) - .collect(Collectors.toList()); - - taskNode.setDepList(newDepList); - taskNode.setName(taskNode.getName() + suffix); - taskNode.setCode(0L); - } - processData.setTasks(taskNodeList); - String processDefinitionJson = JSONUtils.toJsonString(processData); - return createProcessDefinition( - loginUser, - targetProject.getName(), - processDefinition.getName() + "_copy_" + currentTimeStamp, - processDefinitionJson, - processDefinition.getDescription(), - locationsJN.toString(), - processDefinition.getConnects()); - - } - } - /** * batch copy process definition * * @param loginUser loginUser - * @param projectName projectName - * @param processDefinitionIds processDefinitionIds - * @param targetProjectId targetProjectId + * @param projectCode projectCode + * @param codes processDefinitionCodes + * @param targetProjectCode targetProjectCode */ @Override public Map batchCopyProcessDefinition(User loginUser, - String projectName, - String processDefinitionIds, - int targetProjectId) { - Map result = new HashMap<>(); + long projectCode, + String codes, + long targetProjectCode) { + Map result = checkParams(loginUser, projectCode, codes, targetProjectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; + } List failedProcessList = new ArrayList<>(); - - if (StringUtils.isEmpty(processDefinitionIds)) { - putMsg(result, Status.PROCESS_DEFINITION_IDS_IS_EMPTY, processDefinitionIds); - return result; - } - - //check src project auth - Map checkResult = checkProjectAndAuth(loginUser, projectName); - if (checkResult != null) { - return checkResult; - } - - Project targetProject = projectMapper.queryDetailById(targetProjectId); - if (targetProject == null) { - putMsg(result, Status.PROJECT_NOT_FOUNT, targetProjectId); - return result; - } - - if (!(targetProject.getName()).equals(projectName)) { - Map checkTargetProjectResult = checkProjectAndAuth(loginUser, targetProject.getName()); - if (checkTargetProjectResult != null) { - return checkTargetProjectResult; - } - } - - String[] processDefinitionIdList = processDefinitionIds.split(Constants.COMMA); - doBatchCopyProcessDefinition(loginUser, targetProject, failedProcessList, processDefinitionIdList); - - checkBatchOperateResult(projectName, targetProject.getName(), result, failedProcessList, true); - + doBatchOperateProcessDefinition(loginUser, targetProjectCode, failedProcessList, codes, result, true); + checkBatchOperateResult(projectCode, targetProjectCode, result, failedProcessList, true); return result; } @@ -1575,136 +1229,113 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro * batch move process definition * * @param loginUser loginUser - * @param projectName projectName - * @param processDefinitionIds processDefinitionIds - * @param targetProjectId targetProjectId + * @param projectCode projectCode + * @param codes processDefinitionCodes + * @param targetProjectCode targetProjectCode */ @Override public Map batchMoveProcessDefinition(User loginUser, - String projectName, - String processDefinitionIds, - int targetProjectId) { - Map result = new HashMap<>(); + long projectCode, + String codes, + long targetProjectCode) { + Map result = checkParams(loginUser, projectCode, codes, targetProjectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; + } + if (projectCode == targetProjectCode) { + return result; + } List failedProcessList = new ArrayList<>(); - //check src project auth - Map checkResult = checkProjectAndAuth(loginUser, projectName); - if (checkResult != null) { - return checkResult; - } - - if (StringUtils.isEmpty(processDefinitionIds)) { - putMsg(result, Status.PROCESS_DEFINITION_IDS_IS_EMPTY, processDefinitionIds); - return result; - } - - Project targetProject = projectMapper.queryDetailById(targetProjectId); - if (targetProject == null) { - putMsg(result, Status.PROJECT_NOT_FOUNT, targetProjectId); - return result; - } - - if (!(targetProject.getName()).equals(projectName)) { - Map checkTargetProjectResult = checkProjectAndAuth(loginUser, targetProject.getName()); - if (checkTargetProjectResult != null) { - return checkTargetProjectResult; - } - } - - Integer[] definitionIds = Arrays.stream(processDefinitionIds.split(Constants.COMMA)).map(Integer::parseInt).toArray(Integer[]::new); - List processDefinitionList = processDefinitionMapper.queryDefinitionListByIdList(definitionIds); - for (ProcessDefinition processDefinition : processDefinitionList) { - ProcessDefinitionLog processDefinitionLog = moveProcessDefinition(loginUser, targetProject.getCode(), processDefinition, result, failedProcessList); - if (processDefinitionLog != null) { - moveTaskRelation(loginUser, processDefinition.getProjectCode(), processDefinitionLog); - } - } - - checkBatchOperateResult(projectName, targetProject.getName(), result, failedProcessList, false); + doBatchOperateProcessDefinition(loginUser, targetProjectCode, failedProcessList, codes, result, false); + checkBatchOperateResult(projectCode, targetProjectCode, result, failedProcessList, false); return result; } - private ProcessDefinitionLog moveProcessDefinition(User loginUser, Long targetProjectCode, ProcessDefinition processDefinition, - Map result, List failedProcessList) { - try { - Integer version = processDefinitionLogMapper.queryMaxVersionForDefinition(processDefinition.getCode()); - ProcessDefinitionLog processDefinitionLog = new ProcessDefinitionLog(processDefinition); - processDefinitionLog.setVersion(version == null || version == 0 ? 1 : version + 1); - processDefinitionLog.setProjectCode(targetProjectCode); - processDefinitionLog.setOperator(loginUser.getId()); - Date now = new Date(); - processDefinitionLog.setOperateTime(now); - processDefinitionLog.setUpdateTime(now); - processDefinitionLog.setCreateTime(now); - int update = processDefinitionMapper.updateById(processDefinitionLog); - int insertLog = processDefinitionLogMapper.insert(processDefinitionLog); - if ((insertLog & update) > 0) { - putMsg(result, Status.SUCCESS); - } else { - failedProcessList.add(processDefinition.getId() + "[" + processDefinition.getName() + "]"); - putMsg(result, Status.UPDATE_PROCESS_DEFINITION_ERROR); - } - return processDefinitionLog; - } catch (Exception e) { - putMsg(result, Status.UPDATE_PROCESS_DEFINITION_ERROR); - failedProcessList.add(processDefinition.getId() + "[" + processDefinition.getName() + "]"); - logger.error("move processDefinition error: {}", e.getMessage(), e); + private Map checkParams(User loginUser, + long projectCode, + String processDefinitionCodes, + long targetProjectCode) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } - return null; + + if (StringUtils.isEmpty(processDefinitionCodes)) { + putMsg(result, Status.PROCESS_DEFINITION_CODES_IS_EMPTY, processDefinitionCodes); + return result; + } + + if (projectCode != targetProjectCode) { + Project targetProject = projectMapper.queryByCode(targetProjectCode); + //check user access for project + Map targetResult = projectService.checkProjectAndAuth(loginUser, targetProject, targetProjectCode); + if (targetResult.get(Constants.STATUS) != Status.SUCCESS) { + return targetResult; + } + } + return result; } - private void moveTaskRelation(User loginUser, Long projectCode, ProcessDefinitionLog processDefinition) { - List processTaskRelationList = processTaskRelationMapper.queryByProcessCode(projectCode, processDefinition.getCode()); - if (!processTaskRelationList.isEmpty()) { - processTaskRelationMapper.deleteByCode(projectCode, processDefinition.getCode()); - } - Date now = new Date(); - for (ProcessTaskRelation processTaskRelation : processTaskRelationList) { - processTaskRelation.setProjectCode(processDefinition.getProjectCode()); - processTaskRelation.setProcessDefinitionVersion(processDefinition.getVersion()); - processTaskRelation.setCreateTime(now); - processTaskRelation.setUpdateTime(now); - processService.saveTaskRelation(loginUser, processTaskRelation); + private void doBatchOperateProcessDefinition(User loginUser, + long targetProjectCode, + List failedProcessList, + String processDefinitionCodes, + Map result, + boolean isCopy) { + Set definitionCodes = Arrays.stream(processDefinitionCodes.split(Constants.COMMA)).map(Long::parseLong).collect(Collectors.toSet()); + List processDefinitionList = processDefinitionMapper.queryByCodes(definitionCodes); + Set queryCodes = processDefinitionList.stream().map(ProcessDefinition::getCode).collect(Collectors.toSet()); + // definitionCodes - queryCodes + Set diffCode = definitionCodes.stream().filter(code -> !queryCodes.contains(code)).collect(Collectors.toSet()); + diffCode.forEach(code -> failedProcessList.add(code + "[null]")); + for (ProcessDefinition processDefinition : processDefinitionList) { + List processTaskRelations = + processTaskRelationMapper.queryByProcessCode(processDefinition.getProjectCode(), processDefinition.getCode()); + List taskRelationList = processTaskRelations.stream().map(ProcessTaskRelationLog::new).collect(Collectors.toList()); + processDefinition.setProjectCode(targetProjectCode); + if (isCopy) { + processDefinition.setName(processDefinition.getName() + "_copy_" + DateUtils.getCurrentTimeStamp()); + createProcessDefine(loginUser, result, taskRelationList, processDefinition, Lists.newArrayList()); + } else { + updateProcessDefine(loginUser, result, taskRelationList, processDefinition, null, Lists.newArrayList()); + } + if (result.get(Constants.STATUS) != Status.SUCCESS) { + failedProcessList.add(processDefinition.getCode() + "[" + processDefinition.getName() + "]"); + } } } /** - * switch the defined process definition verison + * switch the defined process definition version * * @param loginUser login user - * @param projectName project name - * @param processDefinitionId process definition id + * @param projectCode project code + * @param code process definition code * @param version the version user want to switch * @return switch process definition version result code */ @Override - public Map switchProcessDefinitionVersion(User loginUser, String projectName - , int processDefinitionId, long version) { - - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - // check project auth - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultStatus = (Status) checkResult.get(Constants.STATUS); - if (resultStatus != Status.SUCCESS) { - return checkResult; + public Map switchProcessDefinitionVersion(User loginUser, long projectCode, long code, int version) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } - ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineId(processDefinitionId); + ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(code); if (Objects.isNull(processDefinition)) { - putMsg(result - , Status.SWITCH_PROCESS_DEFINITION_VERSION_NOT_EXIST_PROCESS_DEFINITION_ERROR - , processDefinitionId); + putMsg(result, Status.SWITCH_PROCESS_DEFINITION_VERSION_NOT_EXIST_PROCESS_DEFINITION_ERROR, code); return result; } ProcessDefinitionLog processDefinitionLog = processDefinitionLogMapper - .queryByDefinitionCodeAndVersion(processDefinition.getCode(), version); + .queryByDefinitionCodeAndVersion(code, version); if (Objects.isNull(processDefinitionLog)) { - putMsg(result - , Status.SWITCH_PROCESS_DEFINITION_VERSION_NOT_EXIST_PROCESS_DEFINITION_VERSION_ERROR - , processDefinition.getCode() - , version); + putMsg(result, Status.SWITCH_PROCESS_DEFINITION_VERSION_NOT_EXIST_PROCESS_DEFINITION_VERSION_ERROR, processDefinition.getCode(), version); return result; } int switchVersion = processService.switchVersion(processDefinition, processDefinitionLog); @@ -1716,179 +1347,87 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro return result; } - /** - * batch copy process definition - * - * @param loginUser loginUser - * @param targetProject targetProject - * @param failedProcessList failedProcessList - * @param processDefinitionIdList processDefinitionIdList - */ - private void doBatchCopyProcessDefinition(User loginUser, Project targetProject, List failedProcessList, String[] processDefinitionIdList) { - for (String processDefinitionId : processDefinitionIdList) { - try { - Map copyProcessDefinitionResult = - copyProcessDefinition(loginUser, Integer.valueOf(processDefinitionId), targetProject); - if (!Status.SUCCESS.equals(copyProcessDefinitionResult.get(Constants.STATUS))) { - setFailedProcessList(failedProcessList, processDefinitionId); - logger.error((String) copyProcessDefinitionResult.get(Constants.MSG)); - } - } catch (Exception e) { - setFailedProcessList(failedProcessList, processDefinitionId); - logger.error("copy processDefinition error: {}", e.getMessage(), e); - - } - } - } - - /** - * set failed processList - * - * @param failedProcessList failedProcessList - * @param processDefinitionId processDefinitionId - */ - private void setFailedProcessList(List failedProcessList, String processDefinitionId) { - ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineId(Integer.parseInt(processDefinitionId)); - if (processDefinition != null) { - failedProcessList.add(processDefinitionId + "[" + processDefinition.getName() + "]"); - } else { - failedProcessList.add(processDefinitionId + "[null]"); - } - } - - /** - * check project and auth - * - * @param loginUser loginUser - * @param projectName projectName - */ - private Map checkProjectAndAuth(User loginUser, String projectName) { - Project project = projectMapper.queryByName(projectName); - - //check user access for project - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultStatus = (Status) checkResult.get(Constants.STATUS); - - if (resultStatus != Status.SUCCESS) { - return checkResult; - } - return null; - } - /** * check batch operate result * - * @param srcProjectName srcProjectName - * @param targetProjectName targetProjectName + * @param srcProjectCode srcProjectCode + * @param targetProjectCode targetProjectCode * @param result result * @param failedProcessList failedProcessList * @param isCopy isCopy */ - private void checkBatchOperateResult(String srcProjectName, String targetProjectName, + private void checkBatchOperateResult(long srcProjectCode, long targetProjectCode, Map result, List failedProcessList, boolean isCopy) { if (!failedProcessList.isEmpty()) { if (isCopy) { - putMsg(result, Status.COPY_PROCESS_DEFINITION_ERROR, srcProjectName, targetProjectName, String.join(",", failedProcessList)); + putMsg(result, Status.COPY_PROCESS_DEFINITION_ERROR, srcProjectCode, targetProjectCode, String.join(",", failedProcessList)); } else { - putMsg(result, Status.MOVE_PROCESS_DEFINITION_ERROR, srcProjectName, targetProjectName, String.join(",", failedProcessList)); + putMsg(result, Status.MOVE_PROCESS_DEFINITION_ERROR, srcProjectCode, targetProjectCode, String.join(",", failedProcessList)); } } else { putMsg(result, Status.SUCCESS); } } - /** - * check has associated process definition - * - * @param processDefinitionId process definition id - * @param version version - * @return The query result has a specific process definition return true - */ - @Override - public boolean checkHasAssociatedProcessDefinition(int processDefinitionId, long version) { - Integer hasAssociatedDefinitionId = processDefinitionMapper.queryHasAssociatedDefinitionByIdAndVersion(processDefinitionId, version); - return Objects.nonNull(hasAssociatedDefinitionId); - } - /** * query the pagination versions info by one certain process definition code * * @param loginUser login user info to check auth - * @param projectName process definition project name + * @param projectCode project code * @param pageNo page number * @param pageSize page size - * @param processDefinitionCode process definition code + * @param code process definition code * @return the pagination process definition versions info of the certain process definition */ @Override - public Result queryProcessDefinitionVersions(User loginUser, String projectName, int pageNo, int pageSize, long processDefinitionCode) { - + public Result queryProcessDefinitionVersions(User loginUser, long projectCode, int pageNo, int pageSize, long code) { Result result = new Result(); - - // check the if pageNo or pageSize less than 1 - if (pageNo <= 0 || pageSize <= 0) { - putMsg(result - , Status.QUERY_PROCESS_DEFINITION_VERSIONS_PAGE_NO_OR_PAGE_SIZE_LESS_THAN_1_ERROR - , pageNo - , pageSize); - return result; - } - - Project project = projectMapper.queryByName(projectName); - - // check project auth - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); + Project project = projectMapper.queryByCode(projectCode); + // check user access for project + Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectCode); Status resultStatus = (Status) checkResult.get(Constants.STATUS); if (resultStatus != Status.SUCCESS) { - putMsg(result,resultStatus); + putMsg(result, resultStatus); return result; } - - ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(processDefinitionCode); - PageInfo pageInfo = new PageInfo<>(pageNo, pageSize); Page page = new Page<>(pageNo, pageSize); - IPage processDefinitionVersionsPaging = processDefinitionLogMapper.queryProcessDefinitionVersionsPaging(page, processDefinition.getCode()); + IPage processDefinitionVersionsPaging = processDefinitionLogMapper.queryProcessDefinitionVersionsPaging(page, code); List processDefinitionLogs = processDefinitionVersionsPaging.getRecords(); - ProcessData processData = processService.genProcessData(processDefinition); - processDefinition.setProcessDefinitionJson(JSONUtils.toJsonString(processData)); pageInfo.setTotalList(processDefinitionLogs); pageInfo.setTotal((int) processDefinitionVersionsPaging.getTotal()); result.setData(pageInfo); - putMsg(result,Status.SUCCESS); + putMsg(result, Status.SUCCESS); return result; } /** - * delete one certain process definition by version number and process definition id + * delete one certain process definition by version number and process definition code * * @param loginUser login user info to check auth - * @param projectName process definition project name - * @param processDefinitionId process definition id + * @param projectCode project code + * @param code process definition code * @param version version number * @return delele result code */ @Override - public Map deleteByProcessDefinitionIdAndVersion(User loginUser, String projectName, int processDefinitionId, long version) { - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - // check project auth - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultStatus = (Status) checkResult.get(Constants.STATUS); - if (resultStatus != Status.SUCCESS) { - return checkResult; + public Map deleteProcessDefinitionVersion(User loginUser, long projectCode, long code, int version) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } - ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineId(processDefinitionId); + ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(code); if (processDefinition == null) { - putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionId); + putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, code); } else { - processDefinitionLogMapper.deleteByProcessDefinitionCodeAndVersion(processDefinition.getCode(), version); + processDefinitionLogMapper.deleteByProcessDefinitionCodeAndVersion(code, version); putMsg(result, Status.SUCCESS); } return result; - } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java index 400ef88b5e..f5dd51dcfa 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java @@ -33,6 +33,7 @@ import org.apache.dolphinscheduler.api.service.ProcessDefinitionService; import org.apache.dolphinscheduler.api.service.ProcessInstanceService; import org.apache.dolphinscheduler.api.service.ProjectService; import org.apache.dolphinscheduler.api.service.UsersService; +import org.apache.dolphinscheduler.api.utils.CheckUtils; import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; @@ -50,9 +51,9 @@ import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.common.utils.ParameterUtils; import org.apache.dolphinscheduler.common.utils.StringUtils; import org.apache.dolphinscheduler.common.utils.placeholder.BusinessTimeUtils; -import org.apache.dolphinscheduler.dao.entity.ProcessData; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessInstance; +import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog; import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; import org.apache.dolphinscheduler.dao.entity.TaskInstance; @@ -64,6 +65,7 @@ import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; +import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.service.process.ProcessService; import java.io.BufferedReader; @@ -72,17 +74,13 @@ import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Optional; import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -96,8 +94,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @Service public class ProcessInstanceServiceImpl extends BaseServiceImpl implements ProcessInstanceService { - private static final Logger logger = LoggerFactory.getLogger(ProcessInstanceService.class); - public static final String TASK_TYPE = "taskType"; public static final String LOCAL_PARAMS_LIST = "localParamsList"; @@ -137,18 +133,19 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce @Autowired UsersService usersService; + @Autowired + private TenantMapper tenantMapper; + /** * return top n SUCCESS process instance order by running time which started between startTime and endTime */ @Override - public Map queryTopNLongestRunningProcessInstance(User loginUser, String projectName, int size, String startTime, String endTime) { - Map result = new HashMap<>(); - - Project project = projectMapper.queryByName(projectName); - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultEnum = (Status) checkResult.get(Constants.STATUS); - if (resultEnum != Status.SUCCESS) { - return checkResult; + public Map queryTopNLongestRunningProcessInstance(User loginUser, long projectCode, int size, String startTime, String endTime) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } if (0 > size) { @@ -184,34 +181,29 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce * query process instance by id * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param processId process instance id * @return process instance detail */ @Override - public Map queryProcessInstanceById(User loginUser, String projectName, Integer processId) { - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultEnum = (Status) checkResult.get(Constants.STATUS); - if (resultEnum != Status.SUCCESS) { - return checkResult; + public Map queryProcessInstanceById(User loginUser, long projectCode, Integer processId) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } ProcessInstance processInstance = processService.findProcessInstanceDetailById(processId); ProcessDefinition processDefinition = processService.findProcessDefinition(processInstance.getProcessDefinitionCode(), - processInstance.getProcessDefinitionVersion()); + processInstance.getProcessDefinitionVersion()); if (processDefinition == null) { putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processId); } else { processInstance.setWarningGroupId(processDefinition.getWarningGroupId()); - processInstance.setConnects(processDefinition.getConnects()); processInstance.setLocations(processDefinition.getLocations()); - - ProcessData processData = processService.genProcessData(processDefinition); - processInstance.setProcessInstanceJson(JSONUtils.toJsonString(processData)); + processInstance.setDagData(processService.genDagData(processDefinition)); result.put(DATA_LIST, processInstance); putMsg(result, Status.SUCCESS); } @@ -223,10 +215,10 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce * paging query process instance list, filtering according to project, process definition, time range, keyword, process status * * @param loginUser login user - * @param projectName project name + * @param projectCode project code + * @param processDefineCode process definition code * @param pageNo page number * @param pageSize page size - * @param processDefineId process definition id * @param searchVal search value * @param stateType state type * @param host host @@ -235,15 +227,13 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce * @return process instance list */ @Override - public Result queryProcessInstanceList(User loginUser, String projectName, Integer processDefineId, - String startDate, String endDate, - String searchVal, String executorName, ExecutionStatus stateType, String host, - Integer pageNo, Integer pageSize) { + public Result queryProcessInstanceList(User loginUser, long projectCode, long processDefineCode, String startDate, String endDate, String searchVal, String executorName, + ExecutionStatus stateType, String host, Integer pageNo, Integer pageSize) { Result result = new Result(); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectCode); Status resultEnum = (Status) checkResult.get(Constants.STATUS); if (resultEnum != Status.SUCCESS) { putMsg(result,resultEnum); @@ -269,11 +259,8 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce PageInfo pageInfo = new PageInfo<>(pageNo, pageSize); int executorId = usersService.getUserIdByName(executorName); - ProcessDefinition processDefinition = processDefineMapper.queryByDefineId(processDefineId); - IPage processInstanceList = processInstanceMapper.queryProcessInstanceListPaging(page, - project.getCode(), processDefinition == null ? 0L : processDefinition.getCode(), searchVal, - executorId, statusArray, host, start, end); + project.getCode(), processDefineCode, searchVal, executorId, statusArray, host, start, end); List processInstances = processInstanceList.getRecords(); List userIds = CollectionUtils.transformToList(processInstances, ProcessInstance::getExecutorId); @@ -298,20 +285,18 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce * query task list by process instance id * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param processId process instance id * @return task list for the process instance * @throws IOException io exception */ @Override - public Map queryTaskListByProcessId(User loginUser, String projectName, Integer processId) throws IOException { - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultEnum = (Status) checkResult.get(Constants.STATUS); - if (resultEnum != Status.SUCCESS) { - return checkResult; + public Map queryTaskListByProcessId(User loginUser, long projectCode, Integer processId) throws IOException { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } ProcessInstance processInstance = processService.findProcessInstanceDetailById(processId); List taskInstanceList = processService.findValidTaskListByProcessId(processId); @@ -332,8 +317,8 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce for (TaskInstance taskInstance : taskInstanceList) { if (TaskType.DEPENDENT.getDesc().equalsIgnoreCase(taskInstance.getTaskType())) { Result logResult = loggerService.queryLog( - taskInstance.getId(), Constants.LOG_QUERY_SKIP_LINE_NUMBER, Constants.LOG_QUERY_LIMIT); - if (logResult.isSuccess()) { + taskInstance.getId(), Constants.LOG_QUERY_SKIP_LINE_NUMBER, Constants.LOG_QUERY_LIMIT); + if (logResult.getCode() == Status.SUCCESS.ordinal()) { String log = logResult.getData(); Map resultMap = parseLogForDependentResult(log); taskInstance.setDependentResult(JSONUtils.toJsonString(resultMap)); @@ -350,7 +335,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce } BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(log.getBytes( - StandardCharsets.UTF_8)), StandardCharsets.UTF_8)); + StandardCharsets.UTF_8)), StandardCharsets.UTF_8)); String line; while ((line = br.readLine()) != null) { if (line.contains(DEPENDENT_SPLIT)) { @@ -375,19 +360,17 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce * query sub process instance detail info by task id * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param taskId task id * @return sub process instance detail */ @Override - public Map querySubProcessInstanceByTaskId(User loginUser, String projectName, Integer taskId) { - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultEnum = (Status) checkResult.get(Constants.STATUS); - if (resultEnum != Status.SUCCESS) { - return checkResult; + public Map querySubProcessInstanceByTaskId(User loginUser, long projectCode, Integer taskId) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } TaskInstance taskInstance = processService.findTaskInstanceById(taskId); @@ -401,7 +384,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce } ProcessInstance subWorkflowInstance = processService.findSubProcessInstance( - taskInstance.getProcessInstanceId(), taskInstance.getId()); + taskInstance.getProcessInstanceId(), taskInstance.getId()); if (subWorkflowInstance == null) { putMsg(result, Status.SUB_PROCESS_INSTANCE_NOT_EXIST, taskId); return result; @@ -417,28 +400,28 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce * update process instance * * @param loginUser login user - * @param projectName project name - * @param processInstanceJson process instance json + * @param projectCode project code + * @param taskRelationJson process task relation json + * @param taskDefinitionJson taskDefinitionJson * @param processInstanceId process instance id * @param scheduleTime schedule time * @param syncDefine sync define - * @param flag flag - * @param locations locations - * @param connects connects + * @param globalParams global params + * @param locations locations for nodes + * @param timeout timeout + * @param tenantCode tenantCode * @return update result code */ @Transactional @Override - public Map updateProcessInstance(User loginUser, String projectName, Integer processInstanceId, - String processInstanceJson, String scheduleTime, Boolean syncDefine, - Flag flag, String locations, String connects) { - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - //check project permission - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultEnum = (Status) checkResult.get(Constants.STATUS); - if (resultEnum != Status.SUCCESS) { - return checkResult; + public Map updateProcessInstance(User loginUser, long projectCode, Integer processInstanceId, String taskRelationJson, + String taskDefinitionJson, String scheduleTime, Boolean syncDefine, String globalParams, + String locations, int timeout, String tenantCode) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } //check process instance exists ProcessInstance processInstance = processService.findProcessInstanceDetailById(processInstanceId); @@ -449,32 +432,64 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce //check process instance status if (!processInstance.getState().typeIsFinished()) { putMsg(result, Status.PROCESS_INSTANCE_STATE_OPERATION_ERROR, - processInstance.getName(), processInstance.getState().toString(), "update"); + processInstance.getName(), processInstance.getState().toString(), "update"); return result; } - ProcessDefinition processDefinition = processService.findProcessDefinition(processInstance.getProcessDefinitionCode(), - processInstance.getProcessDefinitionVersion()); - ProcessData processData = JSONUtils.parseObject(processInstanceJson, ProcessData.class); - //check workflow json is valid - result = processDefinitionService.checkProcessNodeList(processData, processInstanceJson); - if (result.get(Constants.STATUS) != Status.SUCCESS) { - return result; - } - Tenant tenant = processService.getTenantForProcess(processData.getTenantId(), - processDefinition.getUserId()); - setProcessInstance(processInstance, tenant, scheduleTime, processData); - int updateDefine = 1; + setProcessInstance(processInstance, tenantCode, scheduleTime, globalParams, timeout); if (Boolean.TRUE.equals(syncDefine)) { - processDefinition.setId(processDefineMapper.queryByCode(processInstance.getProcessDefinitionCode()).getId()); - updateDefine = syncDefinition(loginUser, project, locations, connects, - processInstance, processDefinition, processData); + List taskDefinitionLogs = JSONUtils.toList(taskDefinitionJson, TaskDefinitionLog.class); + if (taskDefinitionLogs.isEmpty()) { + putMsg(result, Status.DATA_IS_NOT_VALID, taskDefinitionJson); + return result; + } + for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) { + if (!CheckUtils.checkTaskDefinitionParameters(taskDefinitionLog)) { + putMsg(result, Status.PROCESS_NODE_S_PARAMETER_INVALID, taskDefinitionLog.getName()); + return result; + } + } + if (!processService.saveTaskDefine(loginUser, projectCode, taskDefinitionLogs)) { + putMsg(result, Status.CREATE_TASK_DEFINITION_ERROR); + return result; + } + ProcessDefinition processDefinition = processDefineMapper.queryByCode(processInstance.getProcessDefinitionCode()); + List taskRelationList = JSONUtils.toList(taskRelationJson, ProcessTaskRelationLog.class); + //check workflow json is valid + result = processDefinitionService.checkProcessNodeList(taskRelationJson); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; + } + int tenantId = -1; + if (!Constants.DEFAULT.equals(tenantCode)) { + Tenant tenant = tenantMapper.queryByTenantCode(tenantCode); + if (tenant == null) { + putMsg(result, Status.TENANT_NOT_EXIST); + return result; + } + tenantId = tenant.getId(); + } - processInstance.setProcessDefinitionVersion(processDefinitionLogMapper. - queryMaxVersionForDefinition(processInstance.getProcessDefinitionCode())); + processDefinition.set(projectCode, processDefinition.getName(), processDefinition.getDescription(), globalParams, locations, timeout, tenantId); + processDefinition.setUpdateTime(new Date()); + int insertVersion = processService.saveProcessDefine(loginUser, processDefinition, false); + if (insertVersion > 0) { + int insertResult = processService.saveTaskRelation(loginUser, processDefinition.getProjectCode(), + processDefinition.getCode(), insertVersion, taskRelationList, taskDefinitionLogs); + if (insertResult > 0) { + putMsg(result, Status.SUCCESS); + result.put(Constants.DATA_LIST, processDefinition); + } else { + putMsg(result, Status.UPDATE_PROCESS_DEFINITION_ERROR); + return result; + } + } else { + putMsg(result, Status.UPDATE_PROCESS_DEFINITION_ERROR); + return result; + } + processInstance.setProcessDefinitionVersion(insertVersion); } - int update = processService.updateProcessInstance(processInstance); - if (update > 0 && updateDefine > 0) { + if (update > 0) { putMsg(result, Status.SUCCESS); } else { putMsg(result, Status.UPDATE_PROCESS_INSTANCE_ERROR); @@ -482,46 +497,20 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce return result; } - /** - * sync definition according process instance - */ - private int syncDefinition(User loginUser, Project project, String locations, String connects, - ProcessInstance processInstance, ProcessDefinition processDefinition, - ProcessData processData) { - - String originDefParams = JSONUtils.toJsonString(processData.getGlobalParams()); - processDefinition.setGlobalParams(originDefParams); - processDefinition.setLocations(locations); - processDefinition.setConnects(connects); - processDefinition.setTimeout(processInstance.getTimeout()); - processDefinition.setUpdateTime(new Date()); - - return processService.saveProcessDefinition(loginUser, project, processDefinition.getName(), - processDefinition.getDescription(), locations, connects, - processData, processDefinition, false); - } - /** * update process instance attributes */ - private void setProcessInstance(ProcessInstance processInstance, Tenant tenant, String scheduleTime, ProcessData processData) { - + private void setProcessInstance(ProcessInstance processInstance, String tenantCode, String scheduleTime, String globalParams, int timeout) { Date schedule = processInstance.getScheduleTime(); if (scheduleTime != null) { schedule = DateUtils.getScheduleDate(scheduleTime); } processInstance.setScheduleTime(schedule); - List globalParamList = processData.getGlobalParams(); - Map globalParamMap = Optional.ofNullable(globalParamList) - .orElse(Collections.emptyList()) - .stream() - .collect(Collectors.toMap(Property::getProp, Property::getValue)); - String globalParams = ParameterUtils.curingGlobalParams(globalParamMap, globalParamList, - processInstance.getCmdTypeIfComplement(), schedule); - processInstance.setTimeout(processData.getTimeout()); - if (tenant != null) { - processInstance.setTenantCode(tenant.getTenantCode()); - } + List globalParamList = JSONUtils.toList(globalParams, Property.class); + Map globalParamMap = globalParamList.stream().collect(Collectors.toMap(Property::getProp, Property::getValue)); + globalParams = ParameterUtils.curingGlobalParams(globalParamMap, globalParamList, processInstance.getCmdTypeIfComplement(), schedule); + processInstance.setTimeout(timeout); + processInstance.setTenantCode(tenantCode); processInstance.setGlobalParams(globalParams); } @@ -529,19 +518,17 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce * query parent process instance detail info by sub process instance id * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param subId sub process id * @return parent instance detail */ @Override - public Map queryParentInstanceBySubId(User loginUser, String projectName, Integer subId) { - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultEnum = (Status) checkResult.get(Constants.STATUS); - if (resultEnum != Status.SUCCESS) { - return checkResult; + public Map queryParentInstanceBySubId(User loginUser, long projectCode, Integer subId) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } ProcessInstance subInstance = processService.findProcessInstanceDetailById(subId); @@ -570,21 +557,18 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce * delete process instance by id, at the same time,delete task instance and their mapping relation data * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param processInstanceId process instance id * @return delete result code */ @Override @Transactional(rollbackFor = RuntimeException.class) - public Map deleteProcessInstanceById(User loginUser, String projectName, Integer processInstanceId) { - - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultEnum = (Status) checkResult.get(Constants.STATUS); - if (resultEnum != Status.SUCCESS) { - return checkResult; + public Map deleteProcessInstanceById(User loginUser, long projectCode, Integer processInstanceId) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } ProcessInstance processInstance = processService.findProcessInstanceDetailById(processInstanceId); if (null == processInstance) { @@ -595,7 +579,6 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce try { processService.removeTaskLogFile(processInstanceId); } catch (Exception e) { - logger.error("remove task log failed", e); } // delete database cascade @@ -630,8 +613,8 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce } Map timeParams = BusinessTimeUtils - .getBusinessTime(processInstance.getCmdTypeIfComplement(), - processInstance.getScheduleTime()); + .getBusinessTime(processInstance.getCmdTypeIfComplement(), + processInstance.getScheduleTime()); String userDefinedParams = processInstance.getGlobalParams(); // global params List globalParams = new ArrayList<>(); @@ -667,7 +650,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce List taskInstanceList = taskInstanceMapper.findValidTaskListByProcessId(processInstance.getId(), Flag.YES); for (TaskInstance taskInstance : taskInstanceList) { TaskDefinitionLog taskDefinitionLog = taskDefinitionLogMapper.queryByDefinitionCodeAndVersion( - taskInstance.getTaskCode(), taskInstance.getTaskDefinitionVersion()); + taskInstance.getTaskCode(), taskInstance.getTaskDefinitionVersion()); String localParams = JSONUtils.getNodeString(taskDefinitionLog.getTaskParams(), LOCAL_PARAMS); if (StringUtils.isNotEmpty(localParams)) { @@ -703,8 +686,8 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce } ProcessDefinition processDefinition = processDefinitionLogMapper.queryByDefinitionCodeAndVersion( - processInstance.getProcessDefinitionCode(), - processInstance.getProcessDefinitionVersion() + processInstance.getProcessDefinitionCode(), + processInstance.getProcessDefinitionVersion() ); GanttDto ganttDto = new GanttDto(); DAG dag = processService.genDagGraph(processDefinition); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessTaskRelationServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessTaskRelationServiceImpl.java deleted file mode 100644 index 488c60cd22..0000000000 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessTaskRelationServiceImpl.java +++ /dev/null @@ -1,78 +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.impl; - -import org.apache.dolphinscheduler.api.enums.Status; -import org.apache.dolphinscheduler.api.service.ProcessTaskRelationService; -import org.apache.dolphinscheduler.api.service.ProjectService; -import org.apache.dolphinscheduler.common.Constants; -import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation; -import org.apache.dolphinscheduler.dao.entity.Project; -import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; -import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -/** - * task definition service impl - */ -@Service -public class ProcessTaskRelationServiceImpl extends BaseServiceImpl implements - ProcessTaskRelationService { - - private static final Logger logger = LoggerFactory.getLogger(ProcessTaskRelationServiceImpl.class); - - @Autowired - private ProjectMapper projectMapper; - - @Autowired - private ProjectService projectService; - - @Autowired - private ProcessTaskRelationMapper processTaskRelationMapper; - - /** - * query process task relation - * - * @param loginUser login user - * @param projectName project name - * @param processDefinitionCode process definition code - */ - @Override - public Map queryProcessTaskRelation(User loginUser, String projectName, Long processDefinitionCode) { - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - // check project auth - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - if (checkResult.get(Constants.STATUS) != Status.SUCCESS) { - return checkResult; - } - List processTaskRelationList = processTaskRelationMapper.queryByProcessCode(project.getCode(), processDefinitionCode); - result.put(Constants.DATA_LIST, processTaskRelationList); - putMsg(result, Status.SUCCESS); - return result; - } -} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java index 4e3c588282..80603ef3a8 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java @@ -44,8 +44,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -70,8 +68,6 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic @Autowired private UserMapper userMapper; - private Logger logger = LoggerFactory.getLogger(ProjectServiceImpl.class); - /** * create project * @@ -99,15 +95,15 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic try { project = Project - .newBuilder() - .name(name) - .code(SnowFlakeUtils.getInstance().nextId()) - .description(desc) - .userId(loginUser.getId()) - .userName(loginUser.getUserName()) - .createTime(now) - .updateTime(now) - .build(); + .newBuilder() + .name(name) + .code(SnowFlakeUtils.getInstance().nextId()) + .description(desc) + .userId(loginUser.getId()) + .userName(loginUser.getUserName()) + .createTime(now) + .updateTime(now) + .build(); } catch (SnowFlakeException e) { putMsg(result, Status.CREATE_PROJECT_ERROR); return result; @@ -123,22 +119,22 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic } /** - * query project details by id + * query project details by code * - * @param projectId project id + * @param projectCode project code * @return project detail information */ @Override - public Map queryById(Integer projectId) { - + public Map queryByCode(User loginUser, long projectCode) { Map result = new HashMap<>(); - Project project = projectMapper.selectById(projectId); - + Project project = projectMapper.queryByCode(projectCode); + boolean hasProjectAndPerm = hasProjectAndPerm(loginUser, project, result); + if (!hasProjectAndPerm) { + return result; + } if (project != null) { result.put(Constants.DATA_LIST, project); putMsg(result, Status.SUCCESS); - } else { - putMsg(result, Status.PROJECT_NOT_FOUNT, projectId); } return result; } @@ -148,17 +144,17 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic * * @param loginUser login user * @param project project - * @param projectName project name + * @param projectCode project code * @return true if the login user have permission to see the project */ @Override - public Map checkProjectAndAuth(User loginUser, Project project, String projectName) { + public Map checkProjectAndAuth(User loginUser, Project project, long projectCode) { Map result = new HashMap<>(); if (project == null) { - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); } else if (!checkReadPermission(loginUser, project)) { // check read permission - putMsg(result, Status.USER_NO_OPERATION_PROJECT_PERM, loginUser.getUserName(), projectName); + putMsg(result, Status.USER_NO_OPERATION_PROJECT_PERM, loginUser.getUserName(), projectCode); } else { putMsg(result, Status.SUCCESS); } @@ -171,7 +167,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic if (project == null) { putMsg(result, Status.PROJECT_NOT_FOUNT, ""); } else if (!checkReadPermission(loginUser, project)) { - putMsg(result, Status.USER_NO_OPERATION_PROJECT_PERM, loginUser.getUserName(), project.getName()); + putMsg(result, Status.USER_NO_OPERATION_PROJECT_PERM, loginUser.getUserName(), project.getCode()); } else { checkResult = true; } @@ -224,16 +220,16 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic } /** - * delete project by id + * delete project by code * * @param loginUser login user - * @param projectId project id + * @param projectCode project code * @return delete result code */ @Override - public Map deleteProject(User loginUser, Integer projectId) { + public Map deleteProject(User loginUser, Long projectCode) { Map result = new HashMap<>(); - Project project = projectMapper.selectById(projectId); + Project project = projectMapper.queryByCode(projectCode); Map checkResult = getCheckResult(loginUser, project); if (checkResult != null) { return checkResult; @@ -250,7 +246,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic putMsg(result, Status.DELETE_PROJECT_ERROR_DEFINES_NOT_NULL); return result; } - int delete = projectMapper.deleteById(projectId); + int delete = projectMapper.deleteById(project.getId()); if (delete > 0) { putMsg(result, Status.SUCCESS); } else { @@ -267,8 +263,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic * @return check result */ private Map getCheckResult(User loginUser, Project project) { - String projectName = project == null ? null : project.getName(); - Map checkResult = checkProjectAndAuth(loginUser, project, projectName); + Map checkResult = checkProjectAndAuth(loginUser, project, project == null ? 0L : project.getCode()); Status status = (Status) checkResult.get(Constants.STATUS); if (status != Status.SUCCESS) { return checkResult; @@ -280,14 +275,14 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic * updateProcessInstance project * * @param loginUser login user - * @param projectId project id + * @param projectCode project code * @param projectName project name * @param desc description * @param userName project owner * @return update result code */ @Override - public Map update(User loginUser, Integer projectId, String projectName, String desc, String userName) { + public Map update(User loginUser, Long projectCode, String projectName, String desc, String userName) { Map result = new HashMap<>(); Map descCheck = checkDesc(desc); @@ -295,13 +290,13 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic return descCheck; } - Project project = projectMapper.selectById(projectId); + Project project = projectMapper.queryByCode(projectCode); boolean hasProjectAndPerm = hasProjectAndPerm(loginUser, project, result); if (!hasProjectAndPerm) { return result; } Project tempProject = projectMapper.queryByName(projectName); - if (tempProject != null && tempProject.getId() != projectId) { + if (tempProject != null) { putMsg(result, Status.PROJECT_ALREADY_EXISTS, projectName); return result; } @@ -337,12 +332,10 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic if (loginUser.getId() != userId && isNotAdmin(loginUser, result)) { return result; } - /** - * query all project list except specified userId - */ + // query all project list except specified userId List projectList = projectMapper.queryProjectExceptUserId(userId); List resultList = new ArrayList<>(); - Set projectSet = null; + Set projectSet; if (projectList != null && !projectList.isEmpty()) { projectSet = new HashSet<>(projectList); @@ -364,7 +357,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic */ private List getUnauthorizedProjects(Set projectSet, List authedProjectList) { List resultList; - Set authedProjectSet = null; + Set authedProjectSet; if (authedProjectList != null && !authedProjectList.isEmpty()) { authedProjectSet = new HashSet<>(authedProjectList); projectSet.removeAll(authedProjectSet); @@ -374,7 +367,6 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic return resultList; } - /** * query authorized project * @@ -418,7 +410,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic * query authorized and user create project list by user * * @param loginUser login user - * @return + * @return project list */ @Override public Map queryProjectCreatedAndAuthorizedByUser(User loginUser) { diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java index 3c9786b967..4908eaf4e2 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java @@ -128,12 +128,12 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe int pid, String currentDir) { Result result = checkResourceUploadStartupState(); - if (result.isFailed()) { + if (!result.getCode().equals(Status.SUCCESS.getCode())) { return result; } String fullName = currentDir.equals("/") ? String.format("%s%s",currentDir,name) : String.format("%s/%s",currentDir,name); result = verifyResource(loginUser, type, fullName, pid); - if (result.isFailed()) { + if (!result.getCode().equals(Status.SUCCESS.getCode())) { return result; } @@ -193,17 +193,17 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe int pid, String currentDir) { Result result = checkResourceUploadStartupState(); - if (result.isFailed()) { + if (!result.getCode().equals(Status.SUCCESS.getCode())) { return result; } result = verifyPid(loginUser, pid); - if (result.isFailed()) { + if (!result.getCode().equals(Status.SUCCESS.getCode())) { return result; } result = verifyFile(name, type, file); - if (result.isFailed()) { + if (!result.getCode().equals(Status.SUCCESS.getCode())) { return result; } @@ -275,7 +275,7 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe ResourceType type, MultipartFile file) { Result result = checkResourceUploadStartupState(); - if (result.isFailed()) { + if (!result.getCode().equals(Status.SUCCESS.getCode())) { return result; } @@ -306,7 +306,7 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe } result = verifyFile(name, type, file); - if (result.isFailed()) { + if (!result.getCode().equals(Status.SUCCESS.getCode())) { return result; } @@ -674,7 +674,7 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe @Transactional(rollbackFor = Exception.class) public Result delete(User loginUser, int resourceId) throws IOException { Result result = checkResourceUploadStartupState(); - if (result.isFailed()) { + if (!result.getCode().equals(Status.SUCCESS.getCode())) { return result; } @@ -830,7 +830,7 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe @Override public Result readResource(int resourceId, int skipLineNum, int limit) { Result result = checkResourceUploadStartupState(); - if (result.isFailed()) { + if (!result.getCode().equals(Status.SUCCESS.getCode())) { return result; } @@ -899,7 +899,7 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe @Transactional(rollbackFor = Exception.class) public Result onlineCreateResource(User loginUser, ResourceType type, String fileName, String fileSuffix, String desc, String content,int pid,String currentDir) { Result result = checkResourceUploadStartupState(); - if (result.isFailed()) { + if (!result.getCode().equals(Status.SUCCESS.getCode())) { return result; } @@ -918,7 +918,7 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe String name = fileName.trim() + "." + nameSuffix; String fullName = currentDir.equals("/") ? String.format("%s%s",currentDir,name) : String.format("%s/%s",currentDir,name); result = verifyResource(loginUser, type, fullName, pid); - if (result.isFailed()) { + if (!result.getCode().equals(Status.SUCCESS.getCode())) { return result; } @@ -941,7 +941,7 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe String tenantCode = tenantMapper.queryById(loginUser.getTenantId()).getTenantCode(); result = uploadContentToHdfs(fullName, tenantCode, content); - if (result.isFailed()) { + if (!result.getCode().equals(Status.SUCCESS.getCode())) { throw new ServiceException(result.getMsg()); } return result; @@ -961,7 +961,7 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe private Result verifyResource(User loginUser, ResourceType type, String fullName, int pid) { Result result = verifyResourceName(fullName, type, loginUser); - if (result.isFailed()) { + if (!result.getCode().equals(Status.SUCCESS.getCode())) { return result; } return verifyPid(loginUser, pid); @@ -995,7 +995,7 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe @Transactional(rollbackFor = Exception.class) public Result updateResourceContent(int resourceId, String content) { Result result = checkResourceUploadStartupState(); - if (result.isFailed()) { + if (!result.getCode().equals(Status.SUCCESS.getCode())) { return result; } @@ -1026,7 +1026,7 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe resourcesMapper.updateById(resource); result = uploadContentToHdfs(resource.getFullName(), tenantCode, content); - if (result.isFailed()) { + if (!result.getCode().equals(Status.SUCCESS.getCode())) { throw new ServiceException(result.getMsg()); } return result; diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java index ca433cd96f..d03de22a91 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java @@ -98,8 +98,8 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe * save schedule * * @param loginUser login user - * @param projectName project name - * @param processDefineId process definition id + * @param projectCode project name + * @param processDefineCode process definition code * @param schedule scheduler * @param warningType warning type * @param warningGroupId warning group id @@ -111,8 +111,9 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe */ @Override @Transactional(rollbackFor = RuntimeException.class) - public Map insertSchedule(User loginUser, String projectName, - Integer processDefineId, + public Map insertSchedule(User loginUser, + long projectCode, + long processDefineCode, String schedule, WarningType warningType, int warningGroupId, @@ -123,7 +124,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); + Project project = projectMapper.queryByCode(projectCode); // check project auth boolean hasProjectAndPerm = projectService.hasProjectAndPerm(loginUser, project, result); @@ -132,8 +133,8 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe } // check work flow define release state - ProcessDefinition processDefinition = processService.findProcessDefineById(processDefineId); - result = executorService.checkProcessDefinitionValid(processDefinition, processDefineId); + ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(processDefineCode); + result = executorService.checkProcessDefinitionValid(processDefinition, processDefineCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -141,8 +142,8 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe Schedule scheduleObj = new Schedule(); Date now = new Date(); - scheduleObj.setProjectName(projectName); - scheduleObj.setProcessDefinitionId(processDefinition.getId()); + scheduleObj.setProjectName(project.getName()); + scheduleObj.setProcessDefinitionCode(processDefineCode); scheduleObj.setProcessDefinitionName(processDefinition.getName()); ScheduleParam scheduleParam = JSONUtils.parseObject(schedule, ScheduleParam.class); @@ -192,7 +193,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe * updateProcessInstance schedule * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param id scheduler id * @param scheduleExpression scheduler * @param warningType warning type @@ -201,25 +202,23 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe * @param workerGroup worker group * @param environmentCode environment code * @param processInstancePriority process instance priority - * @param scheduleStatus schedule status * @return update result code */ @Override @Transactional(rollbackFor = RuntimeException.class) public Map updateSchedule(User loginUser, - String projectName, + long projectCode, Integer id, String scheduleExpression, WarningType warningType, int warningGroupId, FailureStrategy failureStrategy, - ReleaseState scheduleStatus, Priority processInstancePriority, String workerGroup, Long environmentCode) { Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); + Project project = projectMapper.queryByCode(projectCode); // check project auth boolean hasProjectAndPerm = projectService.hasProjectAndPerm(loginUser, project, result); @@ -235,9 +234,9 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe return result; } - ProcessDefinition processDefinition = processService.findProcessDefineById(schedule.getProcessDefinitionId()); + ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(schedule.getProcessDefinitionCode()); if (processDefinition == null) { - putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, schedule.getProcessDefinitionId()); + putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, schedule.getProcessDefinitionCode()); return result; } @@ -278,9 +277,6 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe schedule.setFailureStrategy(failureStrategy); } - if (scheduleStatus != null) { - schedule.setReleaseState(scheduleStatus); - } schedule.setWorkerGroup(workerGroup); schedule.setEnvironmentCode(environmentCode); schedule.setUpdateTime(now); @@ -303,7 +299,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe * set schedule online or offline * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param id scheduler id * @param scheduleStatus schedule status * @return publish result code @@ -311,12 +307,12 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe @Override @Transactional(rollbackFor = RuntimeException.class) public Map setScheduleState(User loginUser, - String projectName, + long projectCode, Integer id, ReleaseState scheduleStatus) { Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); + Project project = projectMapper.queryByCode(projectCode); // check project auth boolean hasProjectAndPerm = projectService.hasProjectAndPerm(loginUser, project, result); if (!hasProjectAndPerm) { @@ -337,9 +333,9 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe putMsg(result, Status.SCHEDULE_CRON_REALEASE_NEED_NOT_CHANGE, scheduleStatus); return result; } - ProcessDefinition processDefinition = processService.findProcessDefineById(scheduleObj.getProcessDefinitionId()); + ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(scheduleObj.getProcessDefinitionCode()); if (processDefinition == null) { - putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, scheduleObj.getProcessDefinitionId()); + putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, scheduleObj.getProcessDefinitionCode()); return result; } @@ -353,7 +349,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe } // check sub process definition release state List subProcessDefineIds = new ArrayList<>(); - processService.recurseFindSubProcessId(scheduleObj.getProcessDefinitionId(), subProcessDefineIds); + processService.recurseFindSubProcessId(processDefinition.getId(), subProcessDefineIds); Integer[] idArray = subProcessDefineIds.toArray(new Integer[subProcessDefineIds.size()]); if (!subProcessDefineIds.isEmpty()) { List subProcessDefinitionList = @@ -414,19 +410,19 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe * query schedule * * @param loginUser login user - * @param projectName project name - * @param processDefineId process definition id + * @param projectCode project code + * @param processDefineCode process definition code * @param pageNo page number * @param pageSize page size * @param searchVal search value * @return schedule list page */ @Override - public Result querySchedule(User loginUser, String projectName, Integer processDefineId, String searchVal, Integer pageNo, Integer pageSize) { - + public Result querySchedule(User loginUser, long projectCode, long processDefineCode, String searchVal, + Integer pageNo, Integer pageSize) { Result result = new Result(); - Project project = projectMapper.queryByName(projectName); + Project project = projectMapper.queryByCode(projectCode); // check project auth boolean hasProjectAndPerm = projectService.hasProjectAndPerm(loginUser, project, result); @@ -434,15 +430,15 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe return result; } - ProcessDefinition processDefinition = processService.findProcessDefineById(processDefineId); + ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(processDefineCode); if (processDefinition == null) { - putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processDefineId); + putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processDefineCode); return result; } + Page page = new Page<>(pageNo, pageSize); - IPage scheduleIPage = scheduleMapper.queryByProcessDefineIdPaging( - page, processDefineId, searchVal - ); + IPage scheduleIPage = scheduleMapper.queryByProcessDefineCodePaging(page, processDefineCode, + searchVal); PageInfo pageInfo = new PageInfo<>(pageNo, pageSize); pageInfo.setTotal((int) scheduleIPage.getTotal()); @@ -456,13 +452,13 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe * query schedule list * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @return schedule list */ @Override - public Map queryScheduleList(User loginUser, String projectName) { + public Map queryScheduleList(User loginUser, long projectCode) { Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); + Project project = projectMapper.queryByCode(projectCode); // check project auth boolean hasProjectAndPerm = projectService.hasProjectAndPerm(loginUser, project, result); @@ -470,7 +466,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe return result; } - List schedules = scheduleMapper.querySchedulerListByProjectName(projectName); + List schedules = scheduleMapper.querySchedulerListByProjectName(project.getName()); result.put(Constants.DATA_LIST, schedules); putMsg(result, Status.SUCCESS); @@ -526,17 +522,17 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe * delete schedule by id * * @param loginUser login user - * @param projectName project name - * @param scheduleId schedule id + * @param projectCode project code + * @param scheduleId scheule id * @return delete result code */ @Override - public Map deleteScheduleById(User loginUser, String projectName, Integer scheduleId) { + public Map deleteScheduleById(User loginUser, long projectCode, Integer scheduleId) { Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); + Project project = projectMapper.queryByCode(projectCode); - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); + Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectCode); Status resultEnum = (Status) checkResult.get(Constants.STATUS); if (resultEnum != Status.SUCCESS) { return checkResult; @@ -576,12 +572,11 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe * preview schedule * * @param loginUser login user - * @param projectName project name * @param schedule schedule expression * @return the next five fire time */ @Override - public Map previewSchedule(User loginUser, String projectName, String schedule) { + public Map previewSchedule(User loginUser, String schedule) { Map result = new HashMap<>(); CronExpression cronExpression; ScheduleParam scheduleParam = JSONUtils.parseObject(schedule, ScheduleParam.class); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java index e3608a72da..35f3f1e23d 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java @@ -17,14 +17,13 @@ package org.apache.dolphinscheduler.api.service.impl; -import static org.apache.dolphinscheduler.api.enums.Status.DATA_IS_NOT_VALID; - import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.service.ProjectService; import org.apache.dolphinscheduler.api.service.TaskDefinitionService; import org.apache.dolphinscheduler.api.utils.CheckUtils; +import org.apache.dolphinscheduler.api.utils.PageInfo; +import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; -import org.apache.dolphinscheduler.common.model.TaskNode; import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.common.utils.SnowFlakeUtils; import org.apache.dolphinscheduler.common.utils.SnowFlakeUtils.SnowFlakeException; @@ -38,8 +37,10 @@ import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; +import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.service.process.ProcessService; +import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -53,6 +54,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; + /** * task definition service impl */ @@ -79,50 +83,56 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe @Autowired private ProcessService processService; + @Autowired + private UserMapper userMapper; + /** * create task definition * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param taskDefinitionJson task definition json */ @Transactional(rollbackFor = RuntimeException.class) @Override public Map createTaskDefinition(User loginUser, - String projectName, + long projectCode, String taskDefinitionJson) { - - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - // check project auth - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultStatus = (Status) checkResult.get(Constants.STATUS); - if (resultStatus != Status.SUCCESS) { - return checkResult; - } - - TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); - checkTaskNode(result, taskNode, taskDefinitionJson); - if (result.get(Constants.STATUS) == DATA_IS_NOT_VALID - || result.get(Constants.STATUS) == Status.PROCESS_NODE_S_PARAMETER_INVALID) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } - TaskDefinition taskDefinition = new TaskDefinition(); - long code = 0L; - try { - code = SnowFlakeUtils.getInstance().nextId(); - taskDefinition.setCode(code); - } catch (SnowFlakeException e) { - logger.error("Task code get error, ", e); - } - if (code == 0L) { - putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS, "Error generating task definition code"); + + List taskDefinitionLogs = JSONUtils.toList(taskDefinitionJson, TaskDefinitionLog.class); + if (taskDefinitionLogs.isEmpty()) { + logger.error("taskDefinitionJson invalid: {}", taskDefinitionJson); + putMsg(result, Status.DATA_IS_NOT_VALID, taskDefinitionJson); return result; } - int insert = processService.saveTaskDefinition(loginUser, project.getCode(), taskNode, taskDefinition); - // return taskDefinition object with code - result.put(Constants.DATA_LIST, code); - putMsg(result, Status.SUCCESS, insert); + for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) { + if (!CheckUtils.checkTaskDefinitionParameters(taskDefinitionLog)) { + logger.error("task definition {} parameter invalid", taskDefinitionLog.getName()); + putMsg(result, Status.PROCESS_NODE_S_PARAMETER_INVALID, taskDefinitionLog.getName()); + return result; + } + TaskDefinition taskDefinition = taskDefinitionMapper.queryByName(projectCode, taskDefinitionLog.getName()); + if (taskDefinition != null) { + logger.error("task definition name {} already exists", taskDefinitionLog.getName()); + putMsg(result, Status.TASK_DEFINITION_NAME_EXISTED, taskDefinitionLog.getName()); + return result; + } + } + if (processService.saveTaskDefine(loginUser, projectCode, taskDefinitionLogs)) { + Map resData = new HashMap<>(); + resData.put("total", taskDefinitionLogs.size()); + resData.put("code", StringUtils.join(taskDefinitionLogs.stream().map(TaskDefinition::getCode).collect(Collectors.toList()), ",")); + putMsg(result, Status.SUCCESS); + result.put(Constants.DATA_LIST, resData); + } else { + putMsg(result, Status.CREATE_TASK_DEFINITION_ERROR); + } return result; } @@ -130,21 +140,19 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe * query task definition * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param taskName task name */ @Override - public Map queryTaskDefinitionByName(User loginUser, String projectName, String taskName) { - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultStatus = (Status) checkResult.get(Constants.STATUS); - if (resultStatus != Status.SUCCESS) { - return checkResult; + public Map queryTaskDefinitionByName(User loginUser, long projectCode, String taskName) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } - TaskDefinition taskDefinition = taskDefinitionMapper.queryByDefinitionName(project.getCode(), taskName); + TaskDefinition taskDefinition = taskDefinitionMapper.queryByName(project.getCode(), taskName); if (taskDefinition == null) { putMsg(result, Status.TASK_DEFINE_NOT_EXIST, taskName); } else { @@ -158,26 +166,24 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe * delete task definition * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param taskCode task code */ @Transactional(rollbackFor = RuntimeException.class) @Override - public Map deleteTaskDefinitionByCode(User loginUser, String projectName, Long taskCode) { - Map result = new HashMap<>(5); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultEnum = (Status) checkResult.get(Constants.STATUS); - if (resultEnum != Status.SUCCESS) { - return checkResult; + public Map deleteTaskDefinitionByCode(User loginUser, long projectCode, long taskCode) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } List processTaskRelationList = processTaskRelationMapper.queryByTaskCode(taskCode); if (!processTaskRelationList.isEmpty()) { Set processDefinitionCodes = processTaskRelationList - .stream() - .map(ProcessTaskRelation::getProcessDefinitionCode) - .collect(Collectors.toSet()); + .stream() + .map(ProcessTaskRelation::getProcessDefinitionCode) + .collect(Collectors.toSet()); putMsg(result, Status.PROCESS_TASK_RELATION_EXIST, StringUtils.join(processDefinitionCodes, ",")); return result; } @@ -194,77 +200,88 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe * update task definition * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param taskCode task code - * @param taskDefinitionJson task definition json + * @param taskDefinitionJsonObj task definition json object */ @Transactional(rollbackFor = RuntimeException.class) @Override - public Map updateTaskDefinition(User loginUser, String projectName, Long taskCode, String taskDefinitionJson) { - Map result = new HashMap<>(5); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultEnum = (Status) checkResult.get(Constants.STATUS); - if (resultEnum != Status.SUCCESS) { - return checkResult; + public Map updateTaskDefinition(User loginUser, long projectCode, long taskCode, String taskDefinitionJsonObj) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } if (processService.isTaskOnline(taskCode)) { putMsg(result, Status.PROCESS_DEFINE_STATE_ONLINE); return result; } - TaskDefinition taskDefinition = taskDefinitionMapper.queryByDefinitionCode(taskCode); + TaskDefinition taskDefinition = taskDefinitionMapper.queryByCode(taskCode); if (taskDefinition == null) { putMsg(result, Status.TASK_DEFINE_NOT_EXIST, taskCode); return result; } - TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); - checkTaskNode(result, taskNode, taskDefinitionJson); - if (result.get(Constants.STATUS) == DATA_IS_NOT_VALID - || result.get(Constants.STATUS) == Status.PROCESS_NODE_S_PARAMETER_INVALID) { + TaskDefinitionLog taskDefinitionToUpdate = JSONUtils.parseObject(taskDefinitionJsonObj, TaskDefinitionLog.class); + if (taskDefinitionToUpdate == null) { + logger.error("taskDefinitionJson is not valid json"); + putMsg(result, Status.DATA_IS_NOT_VALID, taskDefinitionJsonObj); + return result; + } + if (!CheckUtils.checkTaskDefinitionParameters(taskDefinitionToUpdate)) { + logger.error("task definition {} parameter invalid", taskDefinitionToUpdate.getName()); + putMsg(result, Status.PROCESS_NODE_S_PARAMETER_INVALID, taskDefinitionToUpdate.getName()); + return result; + } + Integer version = taskDefinitionLogMapper.queryMaxVersionForDefinition(taskCode); + if (version == null || version == 0) { + putMsg(result, Status.DATA_IS_NOT_VALID, taskCode); + return result; + } + Date now = new Date(); + taskDefinitionToUpdate.setCode(taskCode); + taskDefinitionToUpdate.setId(taskDefinition.getId()); + taskDefinitionToUpdate.setProjectCode(projectCode); + taskDefinitionToUpdate.setUserId(taskDefinition.getUserId()); + taskDefinitionToUpdate.setVersion(version + 1); + taskDefinitionToUpdate.setTaskType(taskDefinitionToUpdate.getTaskType().toUpperCase()); + taskDefinitionToUpdate.setResourceIds(processService.getResourceIds(taskDefinitionToUpdate)); + taskDefinitionToUpdate.setUpdateTime(now); + int update = taskDefinitionMapper.updateById(taskDefinitionToUpdate); + taskDefinitionToUpdate.setOperator(loginUser.getId()); + taskDefinitionToUpdate.setOperateTime(now); + taskDefinitionToUpdate.setCreateTime(now); + int insert = taskDefinitionLogMapper.insert(taskDefinitionToUpdate); + if ((update & insert) != 1) { + putMsg(result, Status.CREATE_TASK_DEFINITION_ERROR); return result; } - int update = processService.updateTaskDefinition(loginUser, project.getCode(), taskNode, taskDefinition); result.put(Constants.DATA_LIST, taskCode); putMsg(result, Status.SUCCESS, update); return result; } - public void checkTaskNode(Map result, TaskNode taskNode, String taskDefinitionJson) { - if (taskNode == null) { - logger.error("taskDefinitionJson is not valid json"); - putMsg(result, Status.DATA_IS_NOT_VALID, taskDefinitionJson); - return; - } - if (!CheckUtils.checkTaskNodeParameters(taskNode)) { - logger.error("task node {} parameter invalid", taskNode.getName()); - putMsg(result, Status.PROCESS_NODE_S_PARAMETER_INVALID, taskNode.getName()); - } - } - /** * update task definition * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param taskCode task code * @param version the version user want to switch */ @Override - public Map switchVersion(User loginUser, String projectName, Long taskCode, int version) { - Map result = new HashMap<>(5); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultEnum = (Status) checkResult.get(Constants.STATUS); - if (resultEnum != Status.SUCCESS) { - return checkResult; + public Map switchVersion(User loginUser, long projectCode, long taskCode, int version) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } if (processService.isTaskOnline(taskCode)) { putMsg(result, Status.PROCESS_DEFINE_STATE_ONLINE); return result; } - TaskDefinition taskDefinition = taskDefinitionMapper.queryByDefinitionCode(taskCode); + TaskDefinition taskDefinition = taskDefinitionMapper.queryByCode(taskCode); if (taskDefinition == null) { putMsg(result, Status.TASK_DEFINE_NOT_EXIST, taskCode); return result; @@ -272,10 +289,145 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe TaskDefinitionLog taskDefinitionLog = taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(taskCode, version); taskDefinitionLog.setUserId(loginUser.getId()); taskDefinitionLog.setUpdateTime(new Date()); - taskDefinitionMapper.updateById(taskDefinitionLog); - result.put(Constants.DATA_LIST, taskCode); + int switchVersion = taskDefinitionMapper.updateById(taskDefinitionLog); + if (switchVersion > 0) { + result.put(Constants.DATA_LIST, taskCode); + putMsg(result, Status.SUCCESS); + } else { + putMsg(result, Status.SWITCH_TASK_DEFINITION_VERSION_ERROR); + } + return result; + } + + @Override + public Result queryTaskDefinitionVersions(User loginUser, + long projectCode, + long taskCode, + int pageNo, + int pageSize) { + Result result = new Result(); + Project project = projectMapper.queryByCode(projectCode); + // check user access for project + Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectCode); + Status resultStatus = (Status) checkResult.get(Constants.STATUS); + if (resultStatus != Status.SUCCESS) { + putMsg(result, resultStatus); + return result; + } + PageInfo pageInfo = new PageInfo<>(pageNo, pageSize); + Page page = new Page<>(pageNo, pageSize); + IPage taskDefinitionVersionsPaging = taskDefinitionLogMapper.queryTaskDefinitionVersionsPaging(page, taskCode); + List taskDefinitionLogs = taskDefinitionVersionsPaging.getRecords(); + + pageInfo.setTotalList(taskDefinitionLogs); + pageInfo.setTotal((int) taskDefinitionVersionsPaging.getTotal()); + result.setData(pageInfo); putMsg(result, Status.SUCCESS); return result; } -} + @Override + public Map deleteByCodeAndVersion(User loginUser, long projectCode, long taskCode, int version) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; + } + TaskDefinition taskDefinition = taskDefinitionMapper.queryByCode(taskCode); + + if (taskDefinition == null) { + putMsg(result, Status.TASK_DEFINE_NOT_EXIST, taskCode); + } else { + int delete = taskDefinitionLogMapper.deleteByCodeAndVersion(taskCode, version); + if (delete > 0) { + putMsg(result, Status.SUCCESS); + } else { + putMsg(result, Status.DELETE_TASK_DEFINITION_VERSION_ERROR); + } + } + return result; + } + + @Override + public Map queryTaskDefinitionDetail(User loginUser, long projectCode, long taskCode) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; + } + + TaskDefinition taskDefinition = taskDefinitionMapper.queryByCode(taskCode); + if (taskDefinition == null) { + putMsg(result, Status.TASK_DEFINE_NOT_EXIST, taskCode); + } else { + result.put(Constants.DATA_LIST, taskDefinition); + putMsg(result, Status.SUCCESS); + } + return result; + } + + @Override + public Result queryTaskDefinitionListPaging(User loginUser, + long projectCode, + String taskType, + String searchVal, + Integer userId, + Integer pageNo, + Integer pageSize) { + Result result = new Result(); + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectCode); + Status resultStatus = (Status) checkResult.get(Constants.STATUS); + if (resultStatus != Status.SUCCESS) { + putMsg(result, resultStatus); + return result; + } + if (StringUtils.isNotBlank(taskType)) { + taskType = taskType.toUpperCase(); + } + Page page = new Page<>(pageNo, pageSize); + IPage taskDefinitionIPage = taskDefinitionMapper.queryDefineListPaging( + page, projectCode, taskType, searchVal, userId, isAdmin(loginUser)); + if (StringUtils.isNotBlank(taskType)) { + List records = taskDefinitionIPage.getRecords(); + for (TaskDefinition pd : records) { + TaskDefinitionLog taskDefinitionLog = taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(pd.getCode(), pd.getVersion()); + User user = userMapper.selectById(taskDefinitionLog.getOperator()); + pd.setModifyBy(user.getUserName()); + } + taskDefinitionIPage.setRecords(records); + } + PageInfo pageInfo = new PageInfo<>(pageNo, pageSize); + pageInfo.setTotal((int) taskDefinitionIPage.getTotal()); + pageInfo.setTotalList(taskDefinitionIPage.getRecords()); + result.setData(pageInfo); + putMsg(result, Status.SUCCESS); + return result; + } + + @Override + public Map genTaskCodeList(User loginUser, Integer genNum) { + Map result = new HashMap<>(); + if (genNum == null || genNum < 1 || genNum > 100) { + logger.error("the genNum must be great than 1 and less than 100"); + putMsg(result, Status.DATA_IS_NOT_VALID, genNum); + return result; + } + List taskCodes = new ArrayList<>(); + try { + for (int i = 0; i < genNum; i++) { + taskCodes.add(SnowFlakeUtils.getInstance().nextId()); + } + } catch (SnowFlakeException e) { + logger.error("Task code get error, ", e); + putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS, "Error generating task definition code"); + } + putMsg(result, Status.SUCCESS); + // return processDefinitionCode + result.put(Constants.DATA_LIST, taskCodes); + return result; + } +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java index 53239e8bb2..9f4b8cb8e5 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java @@ -36,7 +36,6 @@ import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; import org.apache.dolphinscheduler.service.process.ProcessService; import java.util.Date; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -76,7 +75,7 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst * query task list by project, process instance, task name, task start time, task end time, task status, keyword paging * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param processInstanceId process instance id * @param searchVal search value * @param taskName task name @@ -89,13 +88,23 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst * @return task list page */ @Override - public Result queryTaskListPaging(User loginUser, String projectName, - Integer processInstanceId, String processInstanceName, String taskName, String executorName, String startDate, - String endDate, String searchVal, ExecutionStatus stateType, String host, - Integer pageNo, Integer pageSize) { + public Result queryTaskListPaging(User loginUser, + long projectCode, + Integer processInstanceId, + String processInstanceName, + String taskName, + String executorName, + String startDate, + String endDate, + String searchVal, + ExecutionStatus stateType, + String host, + Integer pageNo, + Integer pageSize) { Result result = new Result(); - Project project = projectMapper.queryByName(projectName); - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectCode); Status status = (Status) checkResult.get(Constants.STATUS); if (status != Status.SUCCESS) { putMsg(result,status); @@ -117,7 +126,7 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst PageInfo> pageInfo = new PageInfo<>(pageNo, pageSize); int executorId = usersService.getUserIdByName(executorName); IPage taskInstanceIPage = taskInstanceMapper.queryTaskInstanceListPaging( - page, project.getCode(), processInstanceId, processInstanceName, searchVal, taskName, executorId, statusArray, host, start, end + page, project.getCode(), processInstanceId, processInstanceName, searchVal, taskName, executorId, statusArray, host, start, end ); Set exclusionSet = new HashSet<>(); exclusionSet.add(Constants.CLASS); @@ -141,21 +150,18 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst /** * change one task instance's state from failure to forced success * - * @param loginUser login user - * @param projectName project name + * @param loginUser login user + * @param projectCode project code * @param taskInstanceId task instance id * @return the result code and msg */ @Override - public Map forceTaskSuccess(User loginUser, String projectName, Integer taskInstanceId) { - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - - // check user auth - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status status = (Status) checkResult.get(Constants.STATUS); - if (status != Status.SUCCESS) { - return checkResult; + public Map forceTaskSuccess(User loginUser, long projectCode, Integer taskInstanceId) { + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } // check whether the task instance can be found @@ -179,7 +185,6 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst } else { putMsg(result, Status.FORCE_TASK_SUCCESS_ERROR); } - return result; } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java index 88066dbd7c..c690ed38b0 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java @@ -279,26 +279,6 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService return processInstanceMapper.queryByTenantIdAndStatus(tenant.getId(), Constants.NOT_TERMINATED_STATES); } - /** - * query tenant list - * - * @param tenantCode tenant code - * @return tenant list - */ - public Map queryTenantList(String tenantCode) { - - Map result = new HashMap<>(); - - List resourceList = tenantMapper.queryByTenantCode(tenantCode); - if (CollectionUtils.isNotEmpty(resourceList)) { - result.put(Constants.DATA_LIST, resourceList); - putMsg(result, Status.SUCCESS); - } else { - putMsg(result, Status.TENANT_NOT_EXIST); - } - return result; - } - /** * query tenant list * diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkFlowLineageServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkFlowLineageServiceImpl.java index 72aa12eb1b..bcf7bddf8b 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkFlowLineageServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkFlowLineageServiceImpl.java @@ -50,8 +50,8 @@ public class WorkFlowLineageServiceImpl extends BaseServiceImpl implements WorkF private ProjectMapper projectMapper; @Override - public Map queryWorkFlowLineageByName(String workFlowName, int projectId) { - Project project = projectMapper.selectById(projectId); + public Map queryWorkFlowLineageByName(String workFlowName, long projectCode) { + Project project = projectMapper.queryByCode(projectCode); Map result = new HashMap<>(); List workFlowLineageList = workFlowLineageMapper.queryByName(workFlowName, project.getCode()); result.put(Constants.DATA_LIST, workFlowLineageList); @@ -103,9 +103,9 @@ public class WorkFlowLineageServiceImpl extends BaseServiceImpl implements WorkF } @Override - public Map queryWorkFlowLineageByIds(Set ids, int projectId) { + public Map queryWorkFlowLineageByIds(Set ids, long projectCode) { Map result = new HashMap<>(); - Project project = projectMapper.selectById(projectId); + Project project = projectMapper.queryByCode(projectCode); List processLineages = workFlowLineageMapper.queryRelationByIds(ids, project.getCode()); Map workFlowLineages = new HashMap<>(); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/CheckUtils.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/CheckUtils.java index ad2f574cbe..7f0d8cb7ba 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/CheckUtils.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/CheckUtils.java @@ -24,6 +24,7 @@ import org.apache.dolphinscheduler.common.task.AbstractParameters; import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.common.utils.StringUtils; import org.apache.dolphinscheduler.common.utils.TaskParametersUtils; +import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import java.text.MessageFormat; import java.util.HashMap; @@ -129,7 +130,23 @@ public class CheckUtils { } else if (TaskType.SWITCH.getDesc().equalsIgnoreCase(taskType)) { abstractParameters = TaskParametersUtils.getParameters(taskType.toUpperCase(), taskNode.getSwitchResult()); } else { - abstractParameters = TaskParametersUtils.getParameters(taskType.toUpperCase(), taskNode.getParams()); + abstractParameters = TaskParametersUtils.getParameters(taskType.toUpperCase(), taskNode.getTaskParams()); + } + + if (abstractParameters != null) { + return abstractParameters.checkParameters(); + } + + return false; + } + + public static boolean checkTaskDefinitionParameters(TaskDefinition taskDefinition) { + AbstractParameters abstractParameters; + String taskType = taskDefinition.getTaskType(); + if (TaskType.DEPENDENT.getDesc().equalsIgnoreCase(taskType)) { + abstractParameters = TaskParametersUtils.getParameters(taskType.toUpperCase(), taskDefinition.getDependence()); + } else { + abstractParameters = TaskParametersUtils.getParameters(taskType.toUpperCase(), taskDefinition.getTaskParams()); } if (abstractParameters != null) { diff --git a/dolphinscheduler-api/src/main/resources/logback-api.xml b/dolphinscheduler-api/src/main/resources/logback-api.xml index 77d3226e99..ed655a0870 100644 --- a/dolphinscheduler-api/src/main/resources/logback-api.xml +++ b/dolphinscheduler-api/src/main/resources/logback-api.xml @@ -18,13 +18,12 @@ - - + - [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %message%n + [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %msg%n UTF-8 @@ -43,7 +42,7 @@ - [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %message%n + [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %msg%n UTF-8 diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AbstractControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AbstractControllerTest.java index 2881b29c18..6c0faa1a8d 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AbstractControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AbstractControllerTest.java @@ -18,13 +18,19 @@ package org.apache.dolphinscheduler.api.controller; import org.apache.dolphinscheduler.api.ApiApplicationServer; +import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.service.SessionService; import org.apache.dolphinscheduler.api.utils.RegistryCenterUtils; +import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.enums.UserType; import org.apache.dolphinscheduler.common.utils.StringUtils; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.service.registry.RegistryClient; +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.Map; + import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -92,6 +98,20 @@ public class AbstractControllerTest { sessionId = session; Assert.assertTrue(StringUtils.isNotEmpty(session)); + } + public Map success() { + Map serviceResult = new HashMap<>(); + putMsg(serviceResult, Status.SUCCESS); + return serviceResult; + } + + public void putMsg(Map result, Status status, Object... statusParams) { + result.put(Constants.STATUS, status); + if (statusParams != null && statusParams.length > 0) { + result.put(Constants.MSG, MessageFormat.format(status.getMsg(), statusParams)); + } else { + result.put(Constants.MSG, status.getMsg()); + } } } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AccessTokenControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AccessTokenControllerTest.java index 1e1e398502..a13d773abf 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AccessTokenControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AccessTokenControllerTest.java @@ -55,7 +55,7 @@ public class AccessTokenControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -72,7 +72,7 @@ public class AccessTokenControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isStatus(Status.CREATE_ACCESS_TOKEN_ERROR)); + Assert.assertEquals(Status.CREATE_ACCESS_TOKEN_ERROR.getCode(), result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -88,7 +88,7 @@ public class AccessTokenControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -105,7 +105,7 @@ public class AccessTokenControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -120,7 +120,7 @@ public class AccessTokenControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -138,7 +138,7 @@ public class AccessTokenControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertGroupControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertGroupControllerTest.java index 6075b16dd7..0510bcd0df 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertGroupControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertGroupControllerTest.java @@ -57,7 +57,7 @@ public class AlertGroupControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -71,7 +71,7 @@ public class AlertGroupControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -89,7 +89,7 @@ public class AlertGroupControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -104,7 +104,7 @@ public class AlertGroupControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isStatus(Status.ALERT_GROUP_NOT_EXIST)); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -123,7 +123,7 @@ public class AlertGroupControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isStatus(Status.ALERT_GROUP_NOT_EXIST)); + Assert.assertEquals(Status.ALERT_GROUP_EXIST.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -138,7 +138,7 @@ public class AlertGroupControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isStatus(Status.ALERT_GROUP_EXIST)); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -153,7 +153,7 @@ public class AlertGroupControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isStatus(Status.ALERT_GROUP_EXIST)); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -168,7 +168,7 @@ public class AlertGroupControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isStatus(Status.ALERT_GROUP_NOT_EXIST)); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataAnalysisControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataAnalysisControllerTest.java index 962f78d749..d63ffff30e 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataAnalysisControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataAnalysisControllerTest.java @@ -21,13 +21,19 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder 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.Status; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.utils.JSONUtils; +import org.apache.dolphinscheduler.dao.entity.Project; +import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.junit.Assert; import org.junit.Test; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; import org.springframework.util.LinkedMultiValueMap; @@ -40,13 +46,17 @@ public class DataAnalysisControllerTest extends AbstractControllerTest { private static Logger logger = LoggerFactory.getLogger(DataAnalysisControllerTest.class); + @MockBean + ProjectMapper projectMapper; + @Test public void testCountTaskState() throws Exception { + PowerMockito.when(projectMapper.queryByCode(Mockito.any())).thenReturn(getProject("test")); MultiValueMap paramsMap = new LinkedMultiValueMap<>(); paramsMap.add("startDate","2019-12-01 00:00:00"); paramsMap.add("endDate","2019-12-28 00:00:00"); - paramsMap.add("projectId","16"); + paramsMap.add("projectCode","16"); MvcResult mvcResult = mockMvc.perform(get("/projects/analysis/task-state-count") .header("sessionId", sessionId) @@ -55,17 +65,19 @@ public class DataAnalysisControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals( + Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @Test public void testCountProcessInstanceState() throws Exception { + PowerMockito.when(projectMapper.queryByCode(Mockito.any())).thenReturn(getProject("test")); MultiValueMap paramsMap = new LinkedMultiValueMap<>(); paramsMap.add("startDate","2019-12-01 00:00:00"); paramsMap.add("endDate","2019-12-28 00:00:00"); - paramsMap.add("projectId","16"); + paramsMap.add("projectCode","16"); MvcResult mvcResult = mockMvc.perform(get("/projects/analysis/process-state-count") .header("sessionId", sessionId) @@ -74,12 +86,13 @@ public class DataAnalysisControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @Test public void testCountDefinitionByUser() throws Exception { + PowerMockito.when(projectMapper.queryByCode(Mockito.any())).thenReturn(getProject("test")); MultiValueMap paramsMap = new LinkedMultiValueMap<>(); paramsMap.add("projectId","16"); @@ -91,40 +104,46 @@ public class DataAnalysisControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @Test public void testCountCommandState() throws Exception { - MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("startDate","2019-12-01"); - paramsMap.add("endDate","2019-12-15"); - paramsMap.add("projectId","16"); MvcResult mvcResult = mockMvc.perform(get("/projects/analysis/command-state-count") - .header("sessionId", sessionId) - .params(paramsMap)) + .header("sessionId", sessionId)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @Test public void testCountQueueState() throws Exception { - - MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("projectId","16"); MvcResult mvcResult = mockMvc.perform(get("/projects/analysis/queue-count") - .header("sessionId", sessionId) - .params(paramsMap)) + .header("sessionId", sessionId)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } + + /** + * get mock Project + * + * @param projectName projectName + * @return Project + */ + private Project getProject(String projectName) { + Project project = new Project(); + project.setCode(11L); + project.setId(1); + project.setName(projectName); + project.setUserId(1); + return project; + } } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataSourceControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataSourceControllerTest.java index ae088a9320..e7863739de 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataSourceControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataSourceControllerTest.java @@ -22,6 +22,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder 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.Status; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.datasource.mysql.MysqlDatasourceParamDTO; import org.apache.dolphinscheduler.common.utils.JSONUtils; @@ -65,7 +66,7 @@ public class DataSourceControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -91,7 +92,7 @@ public class DataSourceControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -107,7 +108,7 @@ public class DataSourceControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -122,7 +123,7 @@ public class DataSourceControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -139,7 +140,7 @@ public class DataSourceControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -162,7 +163,7 @@ public class DataSourceControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -178,7 +179,7 @@ public class DataSourceControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -193,7 +194,7 @@ public class DataSourceControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -208,7 +209,7 @@ public class DataSourceControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -223,7 +224,7 @@ public class DataSourceControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -235,7 +236,7 @@ public class DataSourceControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -251,7 +252,7 @@ public class DataSourceControllerTest extends AbstractControllerTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/LoggerControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/LoggerControllerTest.java index be424eaa29..4dafaaa61f 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/LoggerControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/LoggerControllerTest.java @@ -21,6 +21,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder 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.Status; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.utils.JSONUtils; @@ -58,7 +59,7 @@ public class LoggerControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -75,7 +76,7 @@ public class LoggerControllerTest extends AbstractControllerTest { /*.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))*/ .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/LoginControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/LoginControllerTest.java index fda2b5c7f5..5c56230832 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/LoginControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/LoginControllerTest.java @@ -21,6 +21,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder 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.Status; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.utils.JSONUtils; @@ -53,7 +54,7 @@ public class LoginControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -69,7 +70,7 @@ public class LoginControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/MonitorControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/MonitorControllerTest.java index 352ac7002d..057a73adfe 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/MonitorControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/MonitorControllerTest.java @@ -21,6 +21,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder 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.Status; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.utils.JSONUtils; @@ -49,8 +50,9 @@ public class MonitorControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); + result.getCode().equals(Status.SUCCESS.getCode()); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -65,8 +67,9 @@ public class MonitorControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); + result.getCode().equals(Status.SUCCESS.getCode()); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -80,8 +83,9 @@ public class MonitorControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); + result.getCode().equals(Status.SUCCESS.getCode()); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -95,8 +99,9 @@ public class MonitorControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); + result.getCode().equals(Status.SUCCESS.getCode()); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java index c6d9c55b32..4737c2f8f8 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java @@ -67,33 +67,38 @@ public class ProcessDefinitionControllerTest { loginUser.setId(1); loginUser.setUserType(UserType.GENERAL_USER); loginUser.setUserName("admin"); - user = loginUser; } @Test - public void testCreateProcessDefinition() throws Exception { - String json = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\"" - + ":\"ssh_test1\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\" - + "necho ${aa}\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\"" - + ",\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false}," - + "\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}"; - String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}"; - - String projectName = "test"; + public void testCreateProcessDefinition() { + String relationJson = "[{\"name\":\"\",\"pre_task_code\":0,\"pre_task_version\":0,\"post_task_code\":123456789,\"post_task_version\":1," + + "\"condition_type\":0,\"condition_params\":\"{}\"},{\"name\":\"\",\"pre_task_code\":123456789,\"pre_task_version\":1," + + "\"post_task_code\":123451234,\"post_task_version\":1,\"condition_type\":0,\"condition_params\":\"{}\"}]"; + String taskDefinitionJson = "[{\"name\":\"detail_up\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":" + + "\"{\\\"resourceList\\\":[],\\\"localParams\\\":[{\\\"prop\\\":\\\"datetime\\\",\\\"direct\\\":\\\"IN\\\"," + + "\\\"type\\\":\\\"VARCHAR\\\",\\\"value\\\":\\\"${system.datetime}\\\"}],\\\"rawScript\\\":" + + "\\\"echo ${datetime}\\\",\\\"conditionResult\\\":\\\"{\\\\\\\"successNode\\\\\\\":[\\\\\\\"\\\\\\\"]," + + "\\\\\\\"failedNode\\\\\\\":[\\\\\\\"\\\\\\\"]}\\\",\\\"dependence\\\":{}}\",\"flag\":0,\"taskPriority\":0," + + "\"workerGroup\":\"default\",\"failRetryTimes\":0,\"failRetryInterval\":0,\"timeoutFlag\":0," + + "\"timeoutNotifyStrategy\":0,\"timeout\":0,\"delayTime\":0,\"resourceIds\":\"\"}]"; + long projectCode = 1L; String name = "dag_test"; String description = "desc test"; - String connects = "[]"; + String globalParams = "[]"; + String locations = "[]"; + int timeout = 0; + String tenantCode = "root"; Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); result.put(Constants.DATA_LIST, 1); - Mockito.when(processDefinitionService.createProcessDefinition(user, projectName, name, json, - description, locations, connects)).thenReturn(result); + Mockito.when(processDefinitionService.createProcessDefinition(user, projectCode, name, description, globalParams, + locations, timeout, tenantCode, relationJson, taskDefinitionJson)).thenReturn(result); - Result response = processDefinitionController.createProcessDefinition(user, projectName, name, json, - locations, connects, description); - Assert.assertTrue(response.isSuccess()); + Result response = processDefinitionController.createProcessDefinition(user, projectCode, name, description, globalParams, + locations, timeout, tenantCode, relationJson, taskDefinitionJson); + Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); } private void putMsg(Map result, Status status, Object... statusParams) { @@ -115,77 +120,74 @@ public class ProcessDefinitionControllerTest { } @Test - public void testVerifyProcessDefinitionName() throws Exception { - + public void testVerifyProcessDefinitionName() { Map result = new HashMap<>(); putMsg(result, Status.PROCESS_DEFINITION_NAME_EXIST); - String projectName = "test"; + long projectCode = 1L; String name = "dag_test"; - Mockito.when(processDefinitionService.verifyProcessDefinitionName(user, projectName, name)).thenReturn(result); + Mockito.when(processDefinitionService.verifyProcessDefinitionName(user, projectCode, name)).thenReturn(result); - Result response = processDefinitionController.verifyProcessDefinitionName(user, projectName, name); + Result response = processDefinitionController.verifyProcessDefinitionName(user, projectCode, name); Assert.assertTrue(response.isStatus(Status.PROCESS_DEFINITION_NAME_EXIST)); - } @Test - public void updateProcessDefinition() throws Exception { - - String json = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1\"" - + ",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}\"}" - + ",\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\"" - + ":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\"" - + ":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}"; + public void updateProcessDefinition() { + String relationJson = "[{\"name\":\"\",\"pre_task_code\":0,\"pre_task_version\":0,\"post_task_code\":123456789,\"post_task_version\":1," + + "\"condition_type\":0,\"condition_params\":\"{}\"},{\"name\":\"\",\"pre_task_code\":123456789,\"pre_task_version\":1," + + "\"post_task_code\":123451234,\"post_task_version\":1,\"condition_type\":0,\"condition_params\":\"{}\"}]"; + String taskDefinitionJson = "[{\"name\":\"detail_up\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":" + + "\"{\\\"resourceList\\\":[],\\\"localParams\\\":[{\\\"prop\\\":\\\"datetime\\\",\\\"direct\\\":\\\"IN\\\"," + + "\\\"type\\\":\\\"VARCHAR\\\",\\\"value\\\":\\\"${system.datetime}\\\"}],\\\"rawScript\\\":" + + "\\\"echo ${datetime}\\\",\\\"conditionResult\\\":\\\"{\\\\\\\"successNode\\\\\\\":[\\\\\\\"\\\\\\\"]," + + "\\\\\\\"failedNode\\\\\\\":[\\\\\\\"\\\\\\\"]}\\\",\\\"dependence\\\":{}}\",\"flag\":0,\"taskPriority\":0," + + "\"workerGroup\":\"default\",\"failRetryTimes\":0,\"failRetryInterval\":0,\"timeoutFlag\":0," + + "\"timeoutNotifyStrategy\":0,\"timeout\":0,\"delayTime\":0,\"resourceIds\":\"\"}]"; String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}"; - String projectName = "test"; + long projectCode = 1L; String name = "dag_test"; String description = "desc test"; - String connects = "[]"; - int id = 1; + String globalParams = "[]"; + int timeout = 0; + String tenantCode = "root"; + long code = 123L; Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); result.put("processDefinitionId", 1); - Mockito.when(processDefinitionService.updateProcessDefinition(user, projectName, id, name, json, - description, locations, connects)).thenReturn(result); + Mockito.when(processDefinitionService.updateProcessDefinition(user, projectCode, name, code, description, globalParams, + locations, timeout, tenantCode, relationJson, taskDefinitionJson)).thenReturn(result); - Result response = processDefinitionController.updateProcessDefinition(user, projectName, name, id, json, - locations, connects, description,ReleaseState.OFFLINE); - Assert.assertTrue(response != null && response.isSuccess()); } + Result response = processDefinitionController.updateProcessDefinition(user, projectCode, name, code, description, globalParams, + locations, timeout, tenantCode, relationJson, taskDefinitionJson, ReleaseState.OFFLINE); + Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); + } @Test - public void testReleaseProcessDefinition() throws Exception { - String projectName = "test"; + public void testReleaseProcessDefinition() { + long projectCode = 1L; int id = 1; Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); - Mockito.when(processDefinitionService.releaseProcessDefinition(user, projectName, id, ReleaseState.OFFLINE)).thenReturn(result); - Result response = processDefinitionController.releaseProcessDefinition(user, projectName, id, ReleaseState.OFFLINE); + Mockito.when(processDefinitionService.releaseProcessDefinition(user, projectCode, id, ReleaseState.OFFLINE)).thenReturn(result); + Result response = processDefinitionController.releaseProcessDefinition(user, projectCode, id, ReleaseState.OFFLINE); Assert.assertTrue(response != null && response.isSuccess()); } @Test - public void testQueryProcessDefinitionById() throws Exception { - - String json = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1" - + "\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}" - + "\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\"" - + ":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":" - + "\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}"; + public void testQueryProcessDefinitionByCode() { String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}"; - String projectName = "test"; + long projectCode = 1L; String name = "dag_test"; String description = "desc test"; - String connects = "[]"; - int id = 1; + long code = 1L; ProcessDefinition processDefinition = new ProcessDefinition(); - processDefinition.setProjectName(projectName); - processDefinition.setConnects(connects); + processDefinition.setProjectCode(projectCode); processDefinition.setDescription(description); - processDefinition.setId(id); + processDefinition.setCode(code); processDefinition.setLocations(locations); processDefinition.setName(name); @@ -193,79 +195,67 @@ public class ProcessDefinitionControllerTest { putMsg(result, Status.SUCCESS); result.put(Constants.DATA_LIST, processDefinition); - Mockito.when(processDefinitionService.queryProcessDefinitionById(user, projectName, id)).thenReturn(result); - Result response = processDefinitionController.queryProcessDefinitionById(user, projectName, id); + Mockito.when(processDefinitionService.queryProcessDefinitionByCode(user, projectCode, code)).thenReturn(result); + Result response = processDefinitionController.queryProcessDefinitionByCode(user, projectCode, code); + + Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); + } + + @Test + public void testBatchCopyProcessDefinition() { + long projectCode = 1L; + long targetProjectCode = 2L; + String code = "1"; + + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS); + + Mockito.when(processDefinitionService.batchCopyProcessDefinition(user, projectCode, code, targetProjectCode)).thenReturn(result); + Result response = processDefinitionController.copyProcessDefinition(user, projectCode, code, targetProjectCode); Assert.assertTrue(response != null && response.isSuccess()); } @Test - public void testBatchCopyProcessDefinition() throws Exception { - - String projectName = "test"; - int targetProjectId = 2; + public void testBatchMoveProcessDefinition() { + long projectCode = 1L; + long targetProjectCode = 2L; String id = "1"; Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); - Mockito.when(processDefinitionService.batchCopyProcessDefinition(user, projectName, id, targetProjectId)).thenReturn(result); - Result response = processDefinitionController.copyProcessDefinition(user, projectName, id, targetProjectId); + Mockito.when(processDefinitionService.batchMoveProcessDefinition(user, projectCode, id, targetProjectCode)).thenReturn(result); + Result response = processDefinitionController.moveProcessDefinition(user, projectCode, id, targetProjectCode); Assert.assertTrue(response != null && response.isSuccess()); } @Test - public void testBatchMoveProcessDefinition() throws Exception { - - String projectName = "test"; - int targetProjectId = 2; - String id = "1"; - - Map result = new HashMap<>(); - putMsg(result, Status.SUCCESS); - - Mockito.when(processDefinitionService.batchMoveProcessDefinition(user, projectName, id, targetProjectId)).thenReturn(result); - Result response = processDefinitionController.moveProcessDefinition(user, projectName, id, targetProjectId); - - Assert.assertTrue(response != null && response.isSuccess()); - } - - @Test - public void testQueryProcessDefinitionList() throws Exception { - - String projectName = "test"; + public void testQueryProcessDefinitionList() { + long projectCode = 1L; List resourceList = getDefinitionList(); Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); result.put(Constants.DATA_LIST, resourceList); - Mockito.when(processDefinitionService.queryProcessDefinitionList(user, projectName)).thenReturn(result); - Result response = processDefinitionController.queryProcessDefinitionList(user, projectName); + Mockito.when(processDefinitionService.queryProcessDefinitionList(user, projectCode)).thenReturn(result); + Result response = processDefinitionController.queryProcessDefinitionList(user, projectCode); Assert.assertTrue(response != null && response.isSuccess()); } public List getDefinitionList() { - List resourceList = new ArrayList<>(); - - String json = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1" - + "\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}" - + "\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval" - + "\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\"" - + ":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}"; String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}"; String projectName = "test"; String name = "dag_test"; String description = "desc test"; - String connects = "[]"; int id = 1; ProcessDefinition processDefinition = new ProcessDefinition(); processDefinition.setProjectName(projectName); - processDefinition.setConnects(connects); processDefinition.setDescription(description); processDefinition.setId(id); processDefinition.setLocations(locations); @@ -276,7 +266,6 @@ public class ProcessDefinitionControllerTest { ProcessDefinition processDefinition2 = new ProcessDefinition(); processDefinition2.setProjectName(projectName); - processDefinition2.setConnects(connects); processDefinition2.setDescription(description); processDefinition2.setId(id2); processDefinition2.setLocations(locations); @@ -289,76 +278,76 @@ public class ProcessDefinitionControllerTest { } @Test - public void testDeleteProcessDefinitionById() throws Exception { - String projectName = "test"; - int id = 1; + public void testDeleteProcessDefinitionByCode() { + long projectCode = 1L; + long code = 1L; Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); - Mockito.when(processDefinitionService.deleteProcessDefinitionById(user, projectName, id)).thenReturn(result); - Result response = processDefinitionController.deleteProcessDefinitionById(user, projectName, id); + Mockito.when(processDefinitionService.deleteProcessDefinitionByCode(user, projectCode, code)).thenReturn(result); + Result response = processDefinitionController.deleteProcessDefinitionByCode(user, projectCode, code); Assert.assertTrue(response != null && response.isSuccess()); } @Test - public void testGetNodeListByDefinitionId() throws Exception { - String projectName = "test"; + public void testGetNodeListByDefinitionId() { + long projectCode = 1L; Long code = 1L; Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); - Mockito.when(processDefinitionService.getTaskNodeListByDefinitionCode(code)).thenReturn(result); - Result response = processDefinitionController.getNodeListByDefinitionCode(user, projectName, code); + Mockito.when(processDefinitionService.getTaskNodeListByDefinitionCode(user, projectCode, code)).thenReturn(result); + Result response = processDefinitionController.getNodeListByDefinitionCode(user, projectCode, code); Assert.assertTrue(response != null && response.isSuccess()); } @Test - public void testGetNodeListByDefinitionIdList() throws Exception { - String projectName = "test"; + public void testGetNodeListByDefinitionIdList() { + long projectCode = 1L; String codeList = "1,2,3"; Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); - Mockito.when(processDefinitionService.getTaskNodeListByDefinitionCodeList(codeList)).thenReturn(result); - Result response = processDefinitionController.getNodeListByDefinitionCodeList(user, projectName, codeList); + Mockito.when(processDefinitionService.getNodeListMapByDefinitionCodes(user, projectCode, codeList)).thenReturn(result); + Result response = processDefinitionController.getNodeListMapByDefinitionCodes(user, projectCode, codeList); Assert.assertTrue(response != null && response.isSuccess()); } @Test - public void testQueryProcessDefinitionAllByProjectId() throws Exception { - int projectId = 1; + public void testQueryProcessDefinitionAllByProjectId() { + long projectCode = 1L; Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); - Mockito.when(processDefinitionService.queryProcessDefinitionAllByProjectId(projectId)).thenReturn(result); - Result response = processDefinitionController.queryProcessDefinitionAllByProjectId(user, projectId); + Mockito.when(processDefinitionService.queryAllProcessDefinitionByProjectCode(user, projectCode)).thenReturn(result); + Result response = processDefinitionController.queryAllProcessDefinitionByProjectCode(user, projectCode); Assert.assertTrue(response != null && response.isSuccess()); } @Test public void testViewTree() throws Exception { - String projectName = "test"; + long projectCode = 1L; int processId = 1; int limit = 2; Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); Mockito.when(processDefinitionService.viewTree(processId, limit)).thenReturn(result); - Result response = processDefinitionController.viewTree(user, projectName, processId, limit); + Result response = processDefinitionController.viewTree(user, projectCode, processId, limit); Assert.assertTrue(response != null && response.isSuccess()); } @Test - public void testQueryProcessDefinitionListPaging() throws Exception { - String projectName = "test"; + public void testQueryProcessDefinitionListPaging() { + long projectCode = 1L; int pageNo = 1; int pageSize = 10; String searchVal = ""; @@ -368,38 +357,38 @@ public class ProcessDefinitionControllerTest { putMsg(result, Status.SUCCESS); result.setData(new PageInfo(1, 10)); - Mockito.when(processDefinitionService.queryProcessDefinitionListPaging(user, projectName, searchVal, pageNo, pageSize, userId)).thenReturn(result); - Result response = processDefinitionController.queryProcessDefinitionListPaging(user, projectName, pageNo, searchVal, userId, pageSize); + Mockito.when(processDefinitionService.queryProcessDefinitionListPaging(user, projectCode, searchVal, userId, pageNo, pageSize)).thenReturn(result); + Result response = processDefinitionController.queryProcessDefinitionListPaging(user, projectCode, searchVal, userId, pageNo, pageSize); Assert.assertTrue(response != null && response.isSuccess()); } @Test - public void testBatchExportProcessDefinitionByIds() throws Exception { - + public void testBatchExportProcessDefinitionByCodes() { String processDefinitionIds = "1,2"; - String projectName = "test"; + long projectCode = 1L; HttpServletResponse response = new MockHttpServletResponse(); - Mockito.doNothing().when(this.processDefinitionService).batchExportProcessDefinitionByIds(user, projectName, processDefinitionIds, response); - processDefinitionController.batchExportProcessDefinitionByIds(user, projectName, processDefinitionIds, response); + Mockito.doNothing().when(this.processDefinitionService).batchExportProcessDefinitionByCodes(user, projectCode, processDefinitionIds, response); + processDefinitionController.batchExportProcessDefinitionByCodes(user, projectCode, processDefinitionIds, response); } @Test public void testQueryProcessDefinitionVersions() { - String projectName = "test"; + + long projectCode = 1L; Result resultMap = new Result(); putMsg(resultMap, Status.SUCCESS); resultMap.setData(new PageInfo(1, 10)); Mockito.when(processDefinitionService.queryProcessDefinitionVersions( user - , projectName + , projectCode , 1 , 10 , 1)) .thenReturn(resultMap); Result result = processDefinitionController.queryProcessDefinitionVersions( user - , projectName + , projectCode , 1 , 10 , 1); @@ -409,31 +398,24 @@ public class ProcessDefinitionControllerTest { @Test public void testSwitchProcessDefinitionVersion() { - String projectName = "test"; + long projectCode = 1L; Map resultMap = new HashMap<>(); putMsg(resultMap, Status.SUCCESS); - Mockito.when(processDefinitionService.switchProcessDefinitionVersion(user, projectName, 1, 10)).thenReturn(resultMap); - Result result = processDefinitionController.switchProcessDefinitionVersion(user, projectName, 1, 10); + Mockito.when(processDefinitionService.switchProcessDefinitionVersion(user, projectCode, 1, 10)).thenReturn(resultMap); + Result result = processDefinitionController.switchProcessDefinitionVersion(user, projectCode, 1, 10); Assert.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode()); } @Test public void testDeleteProcessDefinitionVersion() { - String projectName = "test"; + long projectCode = 1L; Map resultMap = new HashMap<>(); putMsg(resultMap, Status.SUCCESS); - Mockito.when(processDefinitionService.deleteByProcessDefinitionIdAndVersion( - user - , projectName - , 1 - , 10)) - .thenReturn(resultMap); + Mockito.when(processDefinitionService.deleteProcessDefinitionVersion( + user, projectCode, 1, 10)).thenReturn(resultMap); Result result = processDefinitionController.deleteProcessDefinitionVersion( - user - , projectName - , 1 - , 10); + user, projectCode, 1, 10); Assert.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode()); } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceControllerTest.java index 0692ab82db..7d6fabc127 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceControllerTest.java @@ -42,7 +42,7 @@ public class ProcessInstanceControllerTest extends AbstractControllerTest { @Test public void testQueryProcessInstanceList() throws Exception { MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("processDefinitionId", "91"); + paramsMap.add("processDefineCode", "91"); paramsMap.add("searchVal", "cxc"); paramsMap.add("stateType", String.valueOf(ExecutionStatus.SUCCESS)); paramsMap.add("host", "192.168.1.13"); @@ -51,144 +51,138 @@ public class ProcessInstanceControllerTest extends AbstractControllerTest { paramsMap.add("pageNo", "2"); paramsMap.add("pageSize", "2"); - MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/instance/list-paging", "cxc_1113") - .header("sessionId", sessionId) - .params(paramsMap)) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) - .andReturn(); + MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/instance/list-paging", "cxc_1113") + .header("sessionId", sessionId) + .params(paramsMap)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) + .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Assert.assertNotNull(result); - Assert.assertTrue(result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); } @Test public void testQueryTaskListByProcessId() throws Exception { - MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/instance/task-list-by-process-id", "cxc_1113") - .header(SESSION_ID, sessionId) - .param("processInstanceId", "1203")) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) - .andReturn(); + MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/instance/task-list-by-process-id", "cxc_1113") + .header(SESSION_ID, sessionId) + .param("processInstanceId", "1203")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) + .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Assert.assertNotNull(result); - Assert.assertTrue(result.isStatus(Status.PROJECT_NOT_FOUNT)); + Assert.assertEquals(Status.PROJECT_NOT_FOUNT.getCode(), result.getCode().intValue()); } @Test public void testUpdateProcessInstance() throws Exception { - String json = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":" - + "\"aa=\\\"1234\\\"\\necho ${aa}\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\"," - + "\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}"; + String json = "[{\"name\":\"\",\"pre_task_code\":0,\"pre_task_version\":0,\"post_task_code\":123456789,\"post_task_version\":1," + + "\"condition_type\":0,\"condition_params\":\"{}\"},{\"name\":\"\",\"pre_task_code\":123456789,\"pre_task_version\":1," + + "\"post_task_code\":123451234,\"post_task_version\":1,\"condition_type\":0,\"condition_params\":\"{}\"}]"; + String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}"; MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("processInstanceJson", json); + paramsMap.add("taskRelationJson", json); paramsMap.add("processInstanceId", "91"); paramsMap.add("scheduleTime", "2019-12-15 00:00:00"); paramsMap.add("syncDefine", "false"); paramsMap.add("locations", locations); - paramsMap.add("connects", "[]"); - MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/instance/update", "cxc_1113") - .header("sessionId", sessionId) - .params(paramsMap)) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) - .andReturn(); + MvcResult mvcResult = mockMvc.perform(post("/projects/{projectCode}/instance/update", "cxc_1113") + .header("sessionId", sessionId) + .params(paramsMap)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) + .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Assert.assertNotNull(result); - Assert.assertTrue(result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); } @Test public void testQueryProcessInstanceById() throws Exception { - - MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/instance/select-by-id", "cxc_1113") - .header(SESSION_ID, sessionId) - .param("processInstanceId", "1203")) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) - .andReturn(); + MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/instance/select-by-id", "cxc_1113") + .header(SESSION_ID, sessionId) + .param("processInstanceId", "1203")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) + .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Assert.assertNotNull(result); - Assert.assertTrue(result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); } @Test public void testQuerySubProcessInstanceByTaskId() throws Exception { - - MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/instance/select-sub-process", "cxc_1113") - .header(SESSION_ID, sessionId) - .param("taskId", "1203")) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) - .andReturn(); + MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/instance/select-sub-process", "cxc_1113") + .header(SESSION_ID, sessionId) + .param("taskId", "1203")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) + .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Assert.assertNotNull(result); - Assert.assertTrue(result.isStatus(Status.TASK_INSTANCE_NOT_EXISTS)); + Assert.assertEquals(Status.TASK_INSTANCE_NOT_EXISTS.getCode(), result.getCode().intValue()); } @Test public void testQueryParentInstanceBySubId() throws Exception { - - MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/instance/select-parent-process", "cxc_1113") - .header(SESSION_ID, sessionId) - .param("subId", "1204")) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) - .andReturn(); + MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/instance/select-parent-process", "cxc_1113") + .header(SESSION_ID, sessionId) + .param("subId", "1204")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) + .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Assert.assertNotNull(result); - Assert.assertTrue(result.isStatus(Status.PROCESS_INSTANCE_NOT_SUB_PROCESS_INSTANCE)); + Assert.assertEquals(Status.PROCESS_INSTANCE_NOT_SUB_PROCESS_INSTANCE.getCode(), result.getCode().intValue()); } @Test public void testViewVariables() throws Exception { - - MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/instance/view-variables", "cxc_1113") - .header(SESSION_ID, sessionId) - .param("processInstanceId", "1204")) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) - .andReturn(); + MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/instance/view-variables", "cxc_1113") + .header(SESSION_ID, sessionId) + .param("processInstanceId", "1204")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) + .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Assert.assertNotNull(result); - Assert.assertTrue(result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); } @Test public void testDeleteProcessInstanceById() throws Exception { - - MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/instance/delete", "cxc_1113") - .header(SESSION_ID, sessionId) - .param("processInstanceId", "1204")) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) - .andReturn(); + MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/instance/delete", "cxc_1113") + .header(SESSION_ID, sessionId) + .param("processInstanceId", "1204")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) + .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Assert.assertNotNull(result); - Assert.assertTrue(result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); } @Test public void testBatchDeleteProcessInstanceByIds() throws Exception { - - MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/instance/batch-delete", "cxc_1113") - .header(SESSION_ID, sessionId) - .param("processInstanceIds", "1205,1206")) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) - .andReturn(); + MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/instance/batch-delete", "cxc_1113") + .header(SESSION_ID, sessionId) + .param("processInstanceIds", "1205,1206")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) + .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Assert.assertNotNull(result); - Assert.assertTrue(result.isStatus(Status.DELETE_PROCESS_INSTANCE_BY_ID_ERROR)); + Assert.assertEquals(Status.DELETE_PROCESS_INSTANCE_BY_ID_ERROR.getCode(), result.getCode().intValue()); } } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectControllerTest.java index 5d4ab098ef..0bce72d9f9 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectControllerTest.java @@ -17,220 +17,138 @@ package org.apache.dolphinscheduler.api.controller; -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; - import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; +import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.api.utils.Result; -import org.apache.dolphinscheduler.common.utils.JSONUtils; +import org.apache.dolphinscheduler.common.Constants; +import org.apache.dolphinscheduler.common.enums.UserType; +import org.apache.dolphinscheduler.dao.entity.Project; +import org.apache.dolphinscheduler.dao.entity.Resource; +import org.apache.dolphinscheduler.dao.entity.User; +import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; + +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.Map; -import org.junit.After; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MvcResult; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; - -import com.fasterxml.jackson.core.type.TypeReference; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; /** * project controller test */ -public class ProjectControllerTest extends AbstractControllerTest { +@RunWith(MockitoJUnitRunner.Silent.class) +public class ProjectControllerTest { - private static Logger logger = LoggerFactory.getLogger(ProjectControllerTest.class); + @InjectMocks + private ProjectController projectController; - private String projectId; + @Mock + private ProjectServiceImpl projectService; + + @Mock + private ProjectMapper projectMapper; + + protected User user; @Before - public void before() throws Exception { - projectId = testCreateProject("project_test1", "the test project"); - } - - @After - public void after() throws Exception { - testDeleteProject(projectId); - } - - private String testCreateProject(String projectName, String description) throws Exception { - - MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("projectName",projectName); - paramsMap.add("description",description); - - MvcResult mvcResult = mockMvc.perform(post("/projects/create") - .header(SESSION_ID, sessionId) - .params(paramsMap)) - .andExpect(status().isCreated()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) - .andReturn(); - - Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), new TypeReference>() {}); - Assert.assertTrue(result != null && result.isSuccess()); - Assert.assertNotNull(result.getData()); - logger.info("create project return result:{}", mvcResult.getResponse().getContentAsString()); - - return (String)result.getData(); + public void before() { + User loginUser = new User(); + loginUser.setId(1); + loginUser.setUserType(UserType.GENERAL_USER); + loginUser.setUserName("admin"); + user = loginUser; } @Test - public void testUpdateProject() throws Exception { - - MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("projectId", projectId); - paramsMap.add("projectName","project_test_update"); - paramsMap.add("desc","the test project update"); - paramsMap.add("userName", "the project owner"); - - MvcResult mvcResult = mockMvc.perform(post("/projects/update") - .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.assertTrue(result != null && result.isStatus(Status.USER_NOT_EXIST)); - logger.info("update project return result:{}", mvcResult.getResponse().getContentAsString()); + public void testUpdateProject() { + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS); + result.put("projectId", 1); + long projectCode = 1L; + String projectName = "test"; + String desc = ""; + String userName = "jack"; + Mockito.when(projectService.update(user, projectCode, projectName, desc, userName)).thenReturn(result); + Result response = projectController.updateProject(user, projectCode, projectName, desc, userName); + Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); } @Test - public void testQueryProjectById() throws Exception { - - MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("projectId", projectId); - - MvcResult mvcResult = mockMvc.perform(get("/projects/query-by-id") - .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.assertTrue(result != null && result.isSuccess()); - logger.info(mvcResult.getResponse().getContentAsString()); - logger.info("query project by id :{}, return result:{}", projectId, mvcResult.getResponse().getContentAsString()); - + public void testQueryProjectByCode() { + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS); + long projectCode = 1L; + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject()); + Mockito.when(projectService.queryByCode(user, projectCode)).thenReturn(result); + Result response = projectController.queryProjectByCode(user, projectCode); + Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); } @Test - public void testQueryProjectListPaging() throws Exception { + public void testQueryProjectListPaging() { + int pageNo = 1; + int pageSize = 10; + String searchVal = ""; - MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("searchVal","test"); - paramsMap.add("pageSize","2"); - paramsMap.add("pageNo","2"); + Result result = Result.success(new PageInfo(1, 10)); - MvcResult mvcResult = mockMvc.perform(get("/projects/list-paging") - .header(SESSION_ID, sessionId) - .params(paramsMap)) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) - .andReturn(); + Mockito.when(projectService.queryProjectListPaging(user, pageSize, pageNo, searchVal)).thenReturn(result); + Result response = projectController.queryProjectListPaging(user, searchVal, pageSize, pageNo); - Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); - logger.info("query list-paging project return result:{}", mvcResult.getResponse().getContentAsString()); + Assert.assertTrue(response != null && response.isSuccess()); } @Test - public void testQueryUnauthorizedProject() throws Exception { - - MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("userId","2"); - - MvcResult mvcResult = mockMvc.perform(get("/projects/unauth-project") - .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.assertTrue(result != null && result.isSuccess()); - logger.info("query unauth project return result:{}", mvcResult.getResponse().getContentAsString()); + public void testQueryUnauthorizedProject() { + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS); + Mockito.when(projectService.queryUnauthorizedProject(user, 2)).thenReturn(result); + Result response = projectController.queryUnauthorizedProject(user, 2); + Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); } @Test - public void testQueryAuthorizedProject() throws Exception { - - MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("userId",String.valueOf(user.getId())); - - MvcResult mvcResult = mockMvc.perform(get("/projects/authed-project") - .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.assertTrue(result != null && result.isSuccess()); - logger.info("query authed project return result:{}", mvcResult.getResponse().getContentAsString()); - + public void testQueryAuthorizedProject() { + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS); + Mockito.when(projectService.queryAuthorizedProject(user, 2)).thenReturn(result); + Result response = projectController.queryAuthorizedProject(user, 2); + Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); } @Test - public void testQueryAllProjectList() throws Exception { - - MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - - MvcResult mvcResult = mockMvc.perform(get("/projects/query-project-list") - .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.assertTrue(result != null && result.isSuccess()); - logger.info("query all project return result:{}", mvcResult.getResponse().getContentAsString()); - + public void testQueryAllProjectList() { + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS); + Mockito.when(projectService.queryAllProjectList()).thenReturn(result); + Result response = projectController.queryAllProjectList(user); + Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); } - @Ignore - @Test - public void testImportProcessDefinition() throws Exception { - - MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("file","test"); - - MvcResult mvcResult = mockMvc.perform(post("/projects/import-definition") - .header(SESSION_ID, sessionId) - .params(paramsMap)) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.TEXT_PLAIN)) - .andReturn(); - - Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isStatus(Status.IMPORT_PROCESS_DEFINE_ERROR)); - logger.info(mvcResult.getResponse().getContentAsString()); + private Project getProject() { + Project project = new Project(); + project.setCode(1L); + project.setId(1); + project.setName("test"); + project.setUserId(1); + return project; } - private void testDeleteProject(String projectId) throws Exception { - - MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("projectId", projectId); - - MvcResult mvcResult = mockMvc.perform(get("/projects/delete") - .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.assertTrue(result != null && result.isSuccess()); - logger.info("delete project return result:{}", mvcResult.getResponse().getContentAsString()); + private void putMsg(Map result, Status status, Object... statusParams) { + result.put(Constants.STATUS, status); + if (statusParams != null && statusParams.length > 0) { + result.put(Constants.MSG, MessageFormat.format(status.getMsg(), statusParams)); + } else { + result.put(Constants.MSG, status.getMsg()); + } } - } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/QueueControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/QueueControllerTest.java index 600c309536..a324dc77ec 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/QueueControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/QueueControllerTest.java @@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.api.controller; 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.request.MockMvcRequestBuilders.put; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -47,14 +48,14 @@ public class QueueControllerTest extends AbstractControllerTest { @Test public void testQueryList() throws Exception { - MvcResult mvcResult = mockMvc.perform(get("/queue/list") + MvcResult mvcResult = mockMvc.perform(get("/queues/list") .header(SESSION_ID, sessionId)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info("query list queue return result:{}", mvcResult.getResponse().getContentAsString()); } @@ -66,14 +67,14 @@ public class QueueControllerTest extends AbstractControllerTest { paramsMap.add("pageNo","1"); paramsMap.add("pageSize","20"); - MvcResult mvcResult = mockMvc.perform(get("/queue/list-paging") + MvcResult mvcResult = mockMvc.perform(get("/queues") .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.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info("query list-paging queue return result:{}", mvcResult.getResponse().getContentAsString()); } @@ -85,14 +86,14 @@ public class QueueControllerTest extends AbstractControllerTest { paramsMap.add("queue", QUEUE_CREATE_STRING); paramsMap.add("queueName","root.queue1"); - MvcResult mvcResult = mockMvc.perform(post("/queue/create") + MvcResult mvcResult = mockMvc.perform(post("/queues") .header(SESSION_ID, sessionId) .params(paramsMap)) .andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); logger.info("create queue return result:{}", mvcResult.getResponse().getContentAsString()); } @@ -104,14 +105,14 @@ public class QueueControllerTest extends AbstractControllerTest { paramsMap.add("queue","queue2"); paramsMap.add("queueName","root.queue2"); - MvcResult mvcResult = mockMvc.perform(post("/queue/update") + MvcResult mvcResult = mockMvc.perform(put("/queues/{id}", 1) .header(SESSION_ID, sessionId) .params(paramsMap)) .andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info("update queue return result:{}", mvcResult.getResponse().getContentAsString()); } @@ -123,28 +124,28 @@ public class QueueControllerTest extends AbstractControllerTest { paramsMap.add("queue",QUEUE_CREATE_STRING); paramsMap.add("queueName","queue.name"); - MvcResult mvcResult = mockMvc.perform(post("/queue/verify-queue") + MvcResult mvcResult = mockMvc.perform(post("/queues/verify") .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.assertTrue(result.isStatus(Status.QUEUE_VALUE_EXIST)); + Assert.assertEquals(Status.QUEUE_VALUE_EXIST.getCode(),result.getCode().intValue()); // success paramsMap.clear(); paramsMap.add("queue","ait123"); paramsMap.add("queueName","aitName"); - mvcResult = mockMvc.perform(post("/queue/verify-queue") + mvcResult = mockMvc.perform(post("/queues/verify") .header(SESSION_ID, sessionId) .params(paramsMap)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); logger.info("verify queue return result:{}", mvcResult.getResponse().getContentAsString()); } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ResourcesControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ResourcesControllerTest.java index 616733253f..6946cb192e 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ResourcesControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ResourcesControllerTest.java @@ -56,7 +56,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -77,7 +77,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -97,7 +97,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isStatus(Status.TENANT_NOT_EXIST)); + Assert.assertEquals(Status.TENANT_NOT_EXIST.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -118,7 +118,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -141,7 +141,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isStatus(Status.TENANT_NOT_EXIST)); + Assert.assertEquals(Status.TENANT_NOT_EXIST.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -161,7 +161,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isStatus(Status.TENANT_NOT_EXIST)); + Assert.assertEquals(Status.TENANT_NOT_EXIST.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -180,7 +180,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isStatus(Status.TENANT_NOT_EXIST)); + Assert.assertEquals(Status.TENANT_NOT_EXIST.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -205,7 +205,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isStatus(Status.TENANT_NOT_EXIST)); + Assert.assertEquals(Status.TENANT_NOT_EXIST.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -224,7 +224,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isStatus(Status.TENANT_NOT_EXIST)); + Assert.assertEquals(Status.TENANT_NOT_EXIST.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -250,7 +250,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isStatus(Status.TENANT_NOT_EXIST)); + Assert.assertEquals(Status.TENANT_NOT_EXIST.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -270,7 +270,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -288,7 +288,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -306,7 +306,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -324,7 +324,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -342,7 +342,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -360,7 +360,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -378,7 +378,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -396,7 +396,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -412,7 +412,7 @@ public class ResourcesControllerTest extends AbstractControllerTest { Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java index 3652140c13..62022d8b40 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java @@ -17,21 +17,32 @@ package org.apache.dolphinscheduler.api.controller; +import static org.mockito.ArgumentMatchers.isA; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; 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.request.MockMvcRequestBuilders.put; 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.Status; +import org.apache.dolphinscheduler.api.service.SchedulerService; +import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.enums.FailureStrategy; import org.apache.dolphinscheduler.common.enums.Priority; +import org.apache.dolphinscheduler.common.enums.ReleaseState; import org.apache.dolphinscheduler.common.enums.WarningType; import org.apache.dolphinscheduler.common.utils.JSONUtils; +import org.apache.dolphinscheduler.dao.entity.Resource; +import org.apache.dolphinscheduler.dao.entity.User; import org.junit.Assert; import org.junit.Test; +import org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; import org.springframework.util.LinkedMultiValueMap; @@ -44,10 +55,13 @@ public class SchedulerControllerTest extends AbstractControllerTest { private static Logger logger = LoggerFactory.getLogger(SchedulerControllerTest.class); + @MockBean + private SchedulerService schedulerService; + @Test public void testCreateSchedule() throws Exception { MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("processDefinitionId","40"); + paramsMap.add("processDefinitionCode","40"); paramsMap.add("schedule","{'startTime':'2019-12-16 00:00:00','endTime':'2019-12-17 00:00:00','crontab':'0 0 6 * * ? *'}"); paramsMap.add("warningType",String.valueOf(WarningType.NONE)); paramsMap.add("warningGroupId","1"); @@ -57,7 +71,11 @@ public class SchedulerControllerTest extends AbstractControllerTest { paramsMap.add("workerGroupId","1"); paramsMap.add("processInstancePriority",String.valueOf(Priority.HIGH)); - MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/schedule/create","cxc_1113") + Mockito.when(schedulerService.insertSchedule(isA(User.class), isA(Long.class), isA(Long.class), + isA(String.class), isA(WarningType.class), isA(int.class), isA(FailureStrategy.class), + isA(Priority.class), isA(String.class), isA(Long.class))).thenReturn(success()); + + MvcResult mvcResult = mockMvc.perform(post("/projects/{projectCode}/schedules/",123) .header(SESSION_ID, sessionId) .params(paramsMap)) .andExpect(status().isCreated()) @@ -65,7 +83,7 @@ public class SchedulerControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -82,7 +100,11 @@ public class SchedulerControllerTest extends AbstractControllerTest { paramsMap.add("workerGroupId","1"); paramsMap.add("processInstancePriority",String.valueOf(Priority.HIGH)); - MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/schedule/update","cxc_1113") + Mockito.when(schedulerService.updateSchedule(isA(User.class), isA(Long.class), isA(Integer.class), + isA(String.class), isA(WarningType.class), isA(Integer.class), isA(FailureStrategy.class), + isA(Priority.class), isA(String.class), isA(Long.class))).thenReturn(success()); + + MvcResult mvcResult = mockMvc.perform(put("/projects/{projectCode}/schedules/{id}",123, 37) .header(SESSION_ID, sessionId) .params(paramsMap)) .andExpect(status().isOk()) @@ -90,7 +112,7 @@ public class SchedulerControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -99,7 +121,10 @@ public class SchedulerControllerTest extends AbstractControllerTest { MultiValueMap paramsMap = new LinkedMultiValueMap<>(); paramsMap.add("id","37"); - MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/schedule/online","cxc_1113") + Mockito.when(schedulerService.setScheduleState(isA(User.class), isA(Long.class), isA(Integer.class), + isA(ReleaseState.class))).thenReturn(success()); + + MvcResult mvcResult = mockMvc.perform(post("/projects/{projectCode}/schedules/{id}/online",123, 37) .header(SESSION_ID, sessionId) .params(paramsMap)) .andExpect(status().isOk()) @@ -107,7 +132,7 @@ public class SchedulerControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -116,7 +141,10 @@ public class SchedulerControllerTest extends AbstractControllerTest { MultiValueMap paramsMap = new LinkedMultiValueMap<>(); paramsMap.add("id","28"); - MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/schedule/offline","cxc_1113") + Mockito.when(schedulerService.setScheduleState(isA(User.class), isA(Long.class), isA(Integer.class), + isA(ReleaseState.class))).thenReturn(success()); + + MvcResult mvcResult = mockMvc.perform(post("/projects/{projectCode}/schedules/{id}/offline",123, 28) .header(SESSION_ID, sessionId) .params(paramsMap)) .andExpect(status().isOk()) @@ -124,19 +152,25 @@ public class SchedulerControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @Test public void testQueryScheduleListPaging() throws Exception { MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("processDefinitionId","40"); + paramsMap.add("processDefinitionCode","40"); paramsMap.add("searchVal","test"); paramsMap.add("pageNo","1"); paramsMap.add("pageSize","30"); - MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/schedule/list-paging","cxc_1113") + PageInfo pageInfo = new PageInfo<>(1, 10); + Result mockResult = Result.success(pageInfo); + + Mockito.when(schedulerService.querySchedule(isA(User.class), isA(Long.class), isA(Long.class), + isA(String.class), isA(Integer.class), isA(Integer.class))).thenReturn(mockResult); + + MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/schedules/",123) .header(SESSION_ID, sessionId) .params(paramsMap)) .andExpect(status().isOk()) @@ -144,26 +178,31 @@ public class SchedulerControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @Test public void testQueryScheduleList() throws Exception { - MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/schedule/list","cxc_1113") + Mockito.when(schedulerService.queryScheduleList(isA(User.class), isA(Long.class))).thenReturn(success()); + + MvcResult mvcResult = mockMvc.perform(post("/projects/{projectCode}/schedules/list",123) .header(SESSION_ID, sessionId)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @Test public void testPreviewSchedule() throws Exception { - MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/schedule/preview","cxc_1113") + Mockito.when(schedulerService.previewSchedule(isA(User.class), isA(String.class))) + .thenReturn(success()); + + MvcResult mvcResult = mockMvc.perform(post("/projects/{projectCode}/schedules/preview",123) .header(SESSION_ID, sessionId) .param("schedule","{'startTime':'2019-06-10 00:00:00','endTime':'2019-06-13 00:00:00','crontab':'0 0 3/6 * * ? *'}")) .andExpect(status().isCreated()) @@ -171,7 +210,7 @@ public class SchedulerControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -180,7 +219,10 @@ public class SchedulerControllerTest extends AbstractControllerTest { MultiValueMap paramsMap = new LinkedMultiValueMap<>(); paramsMap.add("scheduleId","37"); - MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/schedule/delete","cxc_1113") + Mockito.when(schedulerService.deleteScheduleById(isA(User.class), isA(Long.class), isA(Integer.class))) + .thenReturn(success()); + + MvcResult mvcResult = mockMvc.perform(delete("/projects/{projectCode}/schedules/{id}",123, 37) .header(SESSION_ID, sessionId) .params(paramsMap)) .andExpect(status().isOk()) @@ -188,7 +230,7 @@ public class SchedulerControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java index d91a269750..486707cf9f 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java @@ -19,7 +19,7 @@ package org.apache.dolphinscheduler.api.controller; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -72,9 +72,9 @@ public class TaskInstanceControllerTest extends AbstractControllerTest { result.setCode(Status.SUCCESS.getCode()); result.setMsg(Status.SUCCESS.getMsg()); - when(taskInstanceService.queryTaskListPaging(any(), eq(""), eq(1), eq(""), eq(""), eq(""),any(), any(), + when(taskInstanceService.queryTaskListPaging(any(), eq(1L), eq(1), eq(""), eq(""), eq(""),any(), any(), eq(""), Mockito.any(), eq("192.168.xx.xx"), any(), any())).thenReturn(result); - Result taskResult = taskInstanceController.queryTaskListPaging(null, "", 1, "", "", + Result taskResult = taskInstanceController.queryTaskListPaging(null, 1L, 1, "", "", "", "", ExecutionStatus.SUCCESS,"192.168.xx.xx", "2020-01-01 00:00:00", "2020-01-02 00:00:00",pageNo, pageSize); Assert.assertEquals(Integer.valueOf(Status.SUCCESS.getCode()), taskResult.getCode()); } @@ -88,7 +88,7 @@ public class TaskInstanceControllerTest extends AbstractControllerTest { Map mockResult = new HashMap<>(5); mockResult.put(Constants.STATUS, Status.SUCCESS); mockResult.put(Constants.MSG, Status.SUCCESS.getMsg()); - when(taskInstanceService.forceTaskSuccess(any(User.class), anyString(), anyInt())).thenReturn(mockResult); + when(taskInstanceService.forceTaskSuccess(any(User.class), anyLong(), anyInt())).thenReturn(mockResult); MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/task-instance/force-success", "cxc_1113") .header(SESSION_ID, sessionId) @@ -98,7 +98,7 @@ public class TaskInstanceControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); } } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TenantControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TenantControllerTest.java index 8eacaab25d..14cd52fbe1 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TenantControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TenantControllerTest.java @@ -17,8 +17,10 @@ package org.apache.dolphinscheduler.api.controller; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; 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.request.MockMvcRequestBuilders.put; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -49,7 +51,7 @@ public class TenantControllerTest extends AbstractControllerTest { paramsMap.add("queueId","1"); paramsMap.add("description","tenant description"); - MvcResult mvcResult = mockMvc.perform(post("/tenant/create") + MvcResult mvcResult = mockMvc.perform(post("/tenants/") .header(SESSION_ID, sessionId) .params(paramsMap)) .andExpect(status().isCreated()) @@ -57,7 +59,7 @@ public class TenantControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -69,7 +71,7 @@ public class TenantControllerTest extends AbstractControllerTest { paramsMap.add("searchVal","tenant"); paramsMap.add("pageSize","30"); - MvcResult mvcResult = mockMvc.perform(get("/tenant/list-paging") + MvcResult mvcResult = mockMvc.perform(get("/tenants/") .header(SESSION_ID, sessionId) .params(paramsMap)) .andExpect(status().isOk()) @@ -77,7 +79,7 @@ public class TenantControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -89,7 +91,7 @@ public class TenantControllerTest extends AbstractControllerTest { paramsMap.add("queueId","1"); paramsMap.add("description","tenant description"); - MvcResult mvcResult = mockMvc.perform(post("/tenant/update") + MvcResult mvcResult = mockMvc.perform(put("/tenants/{id}", 9) .header(SESSION_ID, sessionId) .params(paramsMap)) .andExpect(status().isOk()) @@ -97,7 +99,7 @@ public class TenantControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isStatus(Status.TENANT_NOT_EXIST)); + Assert.assertEquals(Status.TENANT_NOT_EXIST.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -107,7 +109,7 @@ public class TenantControllerTest extends AbstractControllerTest { MultiValueMap paramsMap = new LinkedMultiValueMap<>(); paramsMap.add("tenantCode","cxc_test"); - MvcResult mvcResult = mockMvc.perform(get("/tenant/verify-tenant-code") + MvcResult mvcResult = mockMvc.perform(get("/tenants/verify-code") .header(SESSION_ID, sessionId) .params(paramsMap)) .andExpect(status().isOk()) @@ -115,7 +117,7 @@ public class TenantControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -125,7 +127,7 @@ public class TenantControllerTest extends AbstractControllerTest { MultiValueMap paramsMap = new LinkedMultiValueMap<>(); paramsMap.add("tenantCode", "hayden"); - MvcResult mvcResult = mockMvc.perform(get("/tenant/verify-tenant-code") + MvcResult mvcResult = mockMvc.perform(get("/tenants/verify-code") .header(SESSION_ID, sessionId) .params(paramsMap)) .andExpect(status().isOk()) @@ -133,7 +135,7 @@ public class TenantControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isStatus(Status.OS_TENANT_CODE_EXIST)); + Assert.assertEquals(Status.OS_TENANT_CODE_EXIST.getCode(), result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -141,14 +143,14 @@ public class TenantControllerTest extends AbstractControllerTest { @Test public void testQueryTenantlist() throws Exception { - MvcResult mvcResult = mockMvc.perform(get("/tenant/list") + MvcResult mvcResult = mockMvc.perform(get("/tenants/list") .header(SESSION_ID, sessionId)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -158,14 +160,14 @@ public class TenantControllerTest extends AbstractControllerTest { MultiValueMap paramsMap = new LinkedMultiValueMap<>(); paramsMap.add("id","64"); - MvcResult mvcResult = mockMvc.perform(post("/tenant/delete") + MvcResult mvcResult = mockMvc.perform(delete("/tenants/{id}", 64) .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.assertTrue(result != null && result.isStatus(Status.TENANT_NOT_EXIST)); + Assert.assertEquals(Status.TENANT_NOT_EXIST.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/UsersControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/UsersControllerTest.java index f439b37882..fb4b0cee4a 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/UsersControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/UsersControllerTest.java @@ -22,6 +22,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder 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.Status; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.utils.JSONUtils; @@ -62,7 +63,7 @@ public class UsersControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -85,7 +86,7 @@ public class UsersControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -103,7 +104,7 @@ public class UsersControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -121,7 +122,7 @@ public class UsersControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -139,7 +140,7 @@ public class UsersControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -157,7 +158,7 @@ public class UsersControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -170,7 +171,7 @@ public class UsersControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -187,7 +188,7 @@ public class UsersControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -204,7 +205,7 @@ public class UsersControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -221,7 +222,7 @@ public class UsersControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -234,7 +235,7 @@ public class UsersControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -251,7 +252,7 @@ public class UsersControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -265,7 +266,7 @@ public class UsersControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -284,7 +285,7 @@ public class UsersControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); } @Test @@ -300,7 +301,7 @@ public class UsersControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); } @Test @@ -318,6 +319,6 @@ public class UsersControllerTest extends AbstractControllerTest { .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertTrue(result != null && result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); } } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageControllerTest.java index 77e157447e..8c413b2d8c 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageControllerTest.java @@ -21,23 +21,17 @@ import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.service.impl.WorkFlowLineageServiceImpl; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; -import org.apache.dolphinscheduler.dao.entity.Project; -import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; -import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; -import java.text.MessageFormat; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.springframework.context.ApplicationContext; /** * work flow lineage controller test @@ -50,53 +44,30 @@ public class WorkFlowLineageControllerTest extends AbstractControllerTest { @Mock private WorkFlowLineageServiceImpl workFlowLineageService; - @Before - public void init() { - ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class); - SpringApplicationContext springApplicationContext = new SpringApplicationContext(); - springApplicationContext.setApplicationContext(applicationContext); - - ProjectMapper projectMapper = Mockito.mock(ProjectMapper.class); - Mockito.when(applicationContext.getBean(ProjectMapper.class)).thenReturn(projectMapper); - Project project = new Project(); - project.setId(1); - project.setCode(1L); - Mockito.when(projectMapper.selectById(1)).thenReturn(project); - } - @Test public void testQueryWorkFlowLineageByName() { - int projectId = 1; + long projectCode = 1L; String searchVal = "test"; Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); result.put(Constants.DATA_LIST, 1); - Mockito.when(workFlowLineageService.queryWorkFlowLineageByName(searchVal, projectId)).thenReturn(result); - Result response = workFlowLineageController.queryWorkFlowLineageByName(user, projectId, searchVal); - Assert.assertTrue(response.isSuccess()); - } - - private void putMsg(Map result, Status status, Object... statusParams) { - result.put(Constants.STATUS, status); - if (statusParams != null && statusParams.length > 0) { - result.put(Constants.MSG, MessageFormat.format(status.getMsg(), statusParams)); - } else { - result.put(Constants.MSG, status.getMsg()); - } + Mockito.when(workFlowLineageService.queryWorkFlowLineageByName(searchVal, projectCode)).thenReturn(result); + Result response = workFlowLineageController.queryWorkFlowLineageByName(user, projectCode, searchVal); + Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); } @Test public void testQueryWorkFlowLineageByIds() { - int projectId = 1; + long projectCode = 1L; String ids = "1"; Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); result.put(Constants.DATA_LIST, 1); Set idSet = new HashSet<>(); idSet.add(1); - Mockito.when(workFlowLineageService.queryWorkFlowLineageByIds(idSet, projectId)).thenReturn(result); - Result response = workFlowLineageController.queryWorkFlowLineageByIds(user, projectId, ids); - Assert.assertTrue(response.isSuccess()); + Mockito.when(workFlowLineageService.queryWorkFlowLineageByIds(idSet, projectCode)).thenReturn(result); + Result response = workFlowLineageController.queryWorkFlowLineageByIds(user, projectCode, ids); + Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); } } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandlerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandlerTest.java index 992289b029..b5ebd5a156 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandlerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandlerTest.java @@ -25,11 +25,8 @@ import org.junit.Assert; import org.junit.Test; import org.springframework.web.method.HandlerMethod; -import javax.servlet.http.HttpServletResponse; import java.lang.reflect.Method; -import static org.junit.Assert.*; - public class ApiExceptionHandlerTest { @Test @@ -39,16 +36,16 @@ public class ApiExceptionHandlerTest { Method method = controller.getClass().getMethod("createToken", User.class, int.class, String.class, String.class); HandlerMethod hm = new HandlerMethod(controller, method); Result result = handler.exceptionHandler(new RuntimeException("test exception"), hm); - Assert.assertTrue(result.isStatus(Status.CREATE_ACCESS_TOKEN_ERROR)); + Assert.assertEquals(Status.CREATE_ACCESS_TOKEN_ERROR.getCode(),result.getCode().intValue()); } @Test public void exceptionHandlerRuntime() throws NoSuchMethodException { ApiExceptionHandler handler = new ApiExceptionHandler(); ProcessDefinitionController controller = new ProcessDefinitionController(); - Method method = controller.getClass().getMethod("batchExportProcessDefinitionByIds", User.class, String.class, String.class, HttpServletResponse.class); + Method method = controller.getClass().getMethod("queryAllProcessDefinitionByProjectCode", User.class, long.class); HandlerMethod hm = new HandlerMethod(controller, method); Result result = handler.exceptionHandler(new RuntimeException("test exception"), hm); - Assert.assertTrue(result.isStatus(Status.INTERNAL_SERVER_ERROR_ARGS)); + Assert.assertEquals(Status.QUERY_PROCESS_DEFINITION_LIST.getCode(),result.getCode().intValue()); } } \ No newline at end of file diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java index d145cefd12..f115370415 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java @@ -20,18 +20,18 @@ package org.apache.dolphinscheduler.api.service; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; import org.apache.dolphinscheduler.api.dto.CommandStateCount; -import org.apache.dolphinscheduler.api.dto.TaskStateCount; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.service.impl.DataAnalysisServiceImpl; -import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.enums.CommandType; import org.apache.dolphinscheduler.common.enums.ExecutionStatus; import org.apache.dolphinscheduler.common.enums.UserType; import org.apache.dolphinscheduler.common.utils.DateUtils; import org.apache.dolphinscheduler.dao.entity.CommandCount; +import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser; import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount; import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.User; @@ -43,6 +43,7 @@ import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; import org.apache.dolphinscheduler.service.process.ProcessService; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -57,6 +58,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; import org.powermock.modules.junit4.PowerMockRunner; /** @@ -66,13 +68,13 @@ import org.powermock.modules.junit4.PowerMockRunner; public class DataAnalysisServiceTest { @InjectMocks - private DataAnalysisServiceImpl dataAnalysisService; + private DataAnalysisServiceImpl dataAnalysisServiceImpl; @Mock ProjectMapper projectMapper; @Mock - ProjectServiceImpl projectService; + ProjectService projectService; @Mock ProcessInstanceMapper processInstanceMapper; @@ -102,29 +104,30 @@ public class DataAnalysisServiceTest { user = new User(); Project project = new Project(); project.setId(1); + project.setName("test"); resultMap = new HashMap<>(); Mockito.when(projectMapper.selectById(1)).thenReturn(project); Mockito.when(projectService.hasProjectAndPerm(user, project, resultMap)).thenReturn(true); + Mockito.when(projectMapper.queryByCode(1L)).thenReturn(project); } @After public void after() { - user = null; projectMapper = null; resultMap = null; } @Test - public void testCountTaskStateByProject() { - + public void testCountTaskStateByProject_success() { String startDate = "2020-02-11 16:02:18"; String endDate = "2020-02-11 16:03:18"; - //checkProject false - Map result = dataAnalysisService.countTaskStateByProject(user, 2, startDate, endDate); - Assert.assertTrue(result.isEmpty()); + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS, null); + Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong())).thenReturn(result); + Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject("test")); //SUCCESS Mockito.when(taskInstanceMapper.countTaskInstanceStateByUser(DateUtils.getScheduleDate(startDate), @@ -132,150 +135,140 @@ public class DataAnalysisServiceTest { Mockito.when(projectMapper.selectById(Mockito.any())).thenReturn(getProject("test")); Mockito.when(projectService.hasProjectAndPerm(Mockito.any(), Mockito.any(), (Map)Mockito.any())).thenReturn(true); - result = dataAnalysisService.countTaskStateByProject(user, 1, startDate, endDate); + result = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate, endDate); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); + } + + @Test + public void testCountTaskStateByProject_projectNotFound() { + String startDate = "2020-02-11 16:02:18"; + String endDate = "2020-02-11 16:03:18"; + + // checkProject false + Map failResult = new HashMap<>(); + putMsg(failResult, Status.PROJECT_NOT_FOUNT, 1); + Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong())).thenReturn(failResult); + failResult = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate, endDate); + Assert.assertEquals(Status.PROJECT_NOT_FOUNT, failResult.get(Constants.STATUS)); + } + + @Test + public void testCountTaskStateByProject_paramValid() { + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS, null); + Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong())).thenReturn(result); + Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject("test")); // when date in illegal format then return error message String startDate2 = "illegalDateString"; String endDate2 = "illegalDateString"; - result = dataAnalysisService.countTaskStateByProject(user, 0, startDate2, endDate2); + result = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate2, endDate2); Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result.get(Constants.STATUS)); // when one of date in illegal format then return error message String startDate3 = "2020-08-28 14:13:40"; String endDate3 = "illegalDateString"; - result = dataAnalysisService.countTaskStateByProject(user, 0, startDate3, endDate3); + result = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate3, endDate3); Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result.get(Constants.STATUS)); // when one of date in illegal format then return error message String startDate4 = "illegalDateString"; String endDate4 = "2020-08-28 14:13:40"; - result = dataAnalysisService.countTaskStateByProject(user, 0, startDate4, endDate4); + result = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate4, endDate4); Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result.get(Constants.STATUS)); + } - // when counting general user's task status then return user's task status count - user.setUserType(UserType.GENERAL_USER); - Mockito.when(processService.getProjectIdListHavePerm(anyInt())) - .thenReturn(Collections.singletonList(123L)); - ExecuteStatusCount executeStatusCount = new ExecuteStatusCount(); - executeStatusCount.setExecutionStatus(ExecutionStatus.RUNNING_EXECUTION); - executeStatusCount.setCount(10); - Mockito.when(taskInstanceMapper.countTaskInstanceStateByUser(any(), any(), any())) - .thenReturn(Collections.singletonList(executeStatusCount)); - result = dataAnalysisService.countTaskStateByProject(user, 0, startDate, null); - assertThat(result.get(Constants.DATA_LIST)).extracting("taskCountDtos").first().asList() - .hasSameSizeAs(ExecutionStatus.values()); - assertThat(result.get(Constants.DATA_LIST)).extracting("totalCount").first().isEqualTo(10); - TaskStateCount taskStateCount = new TaskStateCount(ExecutionStatus.RUNNING_EXECUTION, 10); - assertThat(result.get(Constants.DATA_LIST)).extracting("taskCountDtos").first().asList().containsOnlyOnce(taskStateCount); + @Test + public void testCountTaskStateByProject_allCountZero() { + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS, null); + Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong())).thenReturn(result); + Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject("test")); // when general user doesn't have any task then return all count are 0 user.setUserType(UserType.GENERAL_USER); - Mockito.when(processService.getProjectIdListHavePerm(anyInt())) - .thenReturn(new ArrayList<>()); - Mockito.when(taskInstanceMapper.countTaskInstanceStateByUser(any(), any(), any())) - .thenReturn(Collections.emptyList()); - result = dataAnalysisService.countTaskStateByProject(user, 0, null, null); + Mockito.when(taskInstanceMapper.countTaskInstanceStateByUser(any(), any(), any())).thenReturn( + Collections.emptyList()); + result = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, null, null); assertThat(result.get(Constants.DATA_LIST)).extracting("totalCount").first().isEqualTo(0); - assertThat(result.get(Constants.DATA_LIST)).extracting("taskCountDtos").first().asList() - .hasSameSizeAs(ExecutionStatus.values()); - assertThat(result.get(Constants.DATA_LIST)).extracting("taskCountDtos").first().asList() - .extracting("count").allMatch(count -> count.equals(0)); + assertThat(result.get(Constants.DATA_LIST)).extracting("taskCountDtos").first().asList().hasSameSizeAs( + ExecutionStatus.values()); + assertThat(result.get(Constants.DATA_LIST)).extracting("taskCountDtos").first().asList().extracting( + "count").allMatch(count -> count.equals(0)); + } - // when general user doesn't have any task then return all count are 0 - user.setUserType(UserType.GENERAL_USER); - Mockito.when(processService.getProjectIdListHavePerm(anyInt())) - .thenReturn(new ArrayList<>()); - Mockito.when(taskInstanceMapper.countTaskInstanceStateByUser(any(), any(), any())) - .thenReturn(Collections.emptyList()); - result = dataAnalysisService.countTaskStateByProject(user, 0, null, null); - assertThat(result.get(Constants.DATA_LIST)).extracting("totalCount").first().isEqualTo(0); - assertThat(result.get(Constants.DATA_LIST)).extracting("taskCountDtos").first().asList() - .hasSameSizeAs(ExecutionStatus.values()); - assertThat(result.get(Constants.DATA_LIST)).extracting("taskCountDtos").first().asList() - .extracting("count").allMatch(count -> count.equals(0)); + @Test + public void testCountTaskStateByProject_noData() { + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS, null); + Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong())).thenReturn(result); + Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject("test")); // when instanceStateCounter return null, then return nothing user.setUserType(UserType.GENERAL_USER); - Mockito.when(processService.getProjectIdListHavePerm(anyInt())) - .thenReturn(new ArrayList<>()); - Mockito.when(taskInstanceMapper.countTaskInstanceStateByUser(any(), any(), any())) - .thenReturn(null); - result = dataAnalysisService.countTaskStateByProject(user, 0, null, null); - assertThat(result).isEmpty(); + PowerMockito.when(taskInstanceMapper.countTaskInstanceStateByUser(any(), any(), any())).thenReturn(null); + result = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, null, null); + Assert.assertNull(result.get(Constants.DATA_LIST)); } @Test public void testCountProcessInstanceStateByProject() { - String startDate = "2020-02-11 16:02:18"; String endDate = "2020-02-11 16:03:18"; + + Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject("test")); + //checkProject false - Map result = dataAnalysisService.countProcessInstanceStateByProject(user, 2, startDate, endDate); - Assert.assertTrue(result.isEmpty()); + Map failResult = new HashMap<>(); + putMsg(failResult, Status.PROJECT_NOT_FOUNT, 1); + Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong())).thenReturn(failResult); + failResult = dataAnalysisServiceImpl.countProcessInstanceStateByProject(user, 1, startDate, endDate); + Assert.assertEquals(Status.PROJECT_NOT_FOUNT, failResult.get(Constants.STATUS)); + + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS, null); + Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong())).thenReturn(result); //SUCCESS - Mockito.when(projectMapper.selectById(Mockito.any())).thenReturn(getProject("test")); Mockito.when(processInstanceMapper.countInstanceStateByUser(DateUtils.getScheduleDate(startDate), DateUtils.getScheduleDate(endDate), new Long[]{1L})).thenReturn(getTaskInstanceStateCounts()); Mockito.when(projectService.hasProjectAndPerm(Mockito.any(), Mockito.any(), (Map)Mockito.any())).thenReturn(true); - result = dataAnalysisService.countProcessInstanceStateByProject(user, 1, startDate, endDate); + result = dataAnalysisServiceImpl.countProcessInstanceStateByProject(user, 1, startDate, endDate); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); } @Test public void testCountDefinitionByUser() { - Mockito.when(projectMapper.selectById(Mockito.any())).thenReturn(getProject("test")); - Map result = dataAnalysisService.countDefinitionByUser(user, 0); + Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject("test")); + + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS, null); + Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong())).thenReturn(result); + + Mockito.when(processDefinitionMapper.countDefinitionGroupByUser(Mockito.anyInt(), Mockito.any(Long[].class), + Mockito.anyBoolean())).thenReturn(new ArrayList()); + result = dataAnalysisServiceImpl.countDefinitionByUser(user, 0); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); } @Test public void testCountCommandState() { - - String startDate = "2020-02-11 16:02:18"; - String endDate = "2020-02-11 16:03:18"; - //checkProject false - Map result = dataAnalysisService.countCommandState(user, 2, startDate, endDate); - Assert.assertTrue(result.isEmpty()); List commandCounts = new ArrayList<>(1); CommandCount commandCount = new CommandCount(); commandCount.setCommandType(CommandType.START_PROCESS); commandCounts.add(commandCount); - Mockito.when(commandMapper.countCommandState(0, DateUtils.getScheduleDate(startDate), - DateUtils.getScheduleDate(endDate), new Long[]{1L})).thenReturn(commandCounts); - Mockito.when(errorCommandMapper.countCommandState(DateUtils.getScheduleDate(startDate), - DateUtils.getScheduleDate(endDate), new Long[]{1L})).thenReturn(commandCounts); - Mockito.when(projectMapper.selectById(Mockito.any())).thenReturn(getProject("test")); - Mockito.when(projectService.hasProjectAndPerm(Mockito.any(), Mockito.any(), (Map)Mockito.any())).thenReturn(true); + Mockito.when(commandMapper.countCommandState(0, null, null, new Long[]{1L})).thenReturn(commandCounts); + Mockito.when(errorCommandMapper.countCommandState(null, null, new Long[]{1L})).thenReturn(commandCounts); - result = dataAnalysisService.countCommandState(user, 1, startDate, endDate); + Map result = dataAnalysisServiceImpl.countCommandState(user); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - // when all date in illegal format then return error message - String startDate2 = "illegalDateString"; - String endDate2 = "illegalDateString"; - Map result2 = dataAnalysisService.countCommandState(user, 0, startDate2, endDate2); - Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result2.get(Constants.STATUS)); - - // when one of date in illegal format then return error message - String startDate3 = "2020-08-22 09:23:10"; - String endDate3 = "illegalDateString"; - Map result3 = dataAnalysisService.countCommandState(user, 0, startDate3, endDate3); - Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result3.get(Constants.STATUS)); - - // when one of date in illegal format then return error message - String startDate4 = "illegalDateString"; - String endDate4 = "2020-08-22 09:23:10"; - Map result4 = dataAnalysisService.countCommandState(user, 0, startDate4, endDate4); - Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result4.get(Constants.STATUS)); - // when no command found then return all count are 0 Mockito.when(commandMapper.countCommandState(anyInt(), any(), any(), any())).thenReturn(Collections.emptyList()); Mockito.when(errorCommandMapper.countCommandState(any(), any(), any())).thenReturn(Collections.emptyList()); - Map result5 = dataAnalysisService.countCommandState(user, 0, startDate, null); + Map result5 = dataAnalysisServiceImpl.countCommandState(user); assertThat(result5).containsEntry(Constants.STATUS, Status.SUCCESS); assertThat(result5.get(Constants.DATA_LIST)).asList().extracting("errorCount").allMatch(count -> count.equals(0)); assertThat(result5.get(Constants.DATA_LIST)).asList().extracting("normalCount").allMatch(count -> count.equals(0)); @@ -290,7 +283,7 @@ public class DataAnalysisServiceTest { Mockito.when(commandMapper.countCommandState(anyInt(), any(), any(), any())).thenReturn(Collections.singletonList(normalCommandCount)); Mockito.when(errorCommandMapper.countCommandState(any(), any(), any())).thenReturn(Collections.singletonList(errorCommandCount)); - Map result6 = dataAnalysisService.countCommandState(user, 0, null, null); + Map result6 = dataAnalysisServiceImpl.countCommandState(user); assertThat(result6).containsEntry(Constants.STATUS, Status.SUCCESS); CommandStateCount commandStateCount = new CommandStateCount(); @@ -302,12 +295,8 @@ public class DataAnalysisServiceTest { @Test public void testCountQueueState() { - // when project check fail then return nothing - Map result1 = dataAnalysisService.countQueueState(user, 2); - Assert.assertTrue(result1.isEmpty()); - // when project check success when return all count are 0 - Map result2 = dataAnalysisService.countQueueState(user, 1); + Map result2 = dataAnalysisServiceImpl.countQueueState(user); assertThat(result2.get(Constants.DATA_LIST)).extracting("taskQueue", "taskKill") .isNotEmpty() .allMatch(count -> count.equals(0)); @@ -317,7 +306,6 @@ public class DataAnalysisServiceTest { * get list */ private List getTaskInstanceStateCounts() { - List taskInstanceStateCounts = new ArrayList<>(1); ExecuteStatusCount executeStatusCount = new ExecuteStatusCount(); executeStatusCount.setExecutionStatus(ExecutionStatus.RUNNING_EXECUTION); @@ -334,10 +322,19 @@ public class DataAnalysisServiceTest { */ private Project getProject(String projectName) { Project project = new Project(); - project.setCode(11L); + project.setCode(1L); project.setId(1); project.setName(projectName); project.setUserId(1); return project; } -} \ No newline at end of file + + private void putMsg(Map result, Status status, Object... statusParams) { + result.put(Constants.STATUS, status); + if (statusParams != null && statusParams.length > 0) { + result.put(Constants.MSG, MessageFormat.format(status.getMsg(), statusParams)); + } else { + result.put(Constants.MSG, status.getMsg()); + } + } +} diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java index 70f15bb674..022ea24db2 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java @@ -93,7 +93,7 @@ public class DataSourceServiceTest { dataSourceList.add(dataSource); PowerMockito.when(dataSourceMapper.queryDataSourceByName(dataSourceName.trim())).thenReturn(dataSourceList); Result dataSourceExitsResult = dataSourceService.createDataSource(loginUser, postgreSqlDatasourceParam); - Assert.assertTrue(dataSourceExitsResult.isStatus(Status.DATASOURCE_EXIST)); + Assert.assertEquals(Status.DATASOURCE_EXIST.getCode(), dataSourceExitsResult.getCode().intValue()); ConnectionParam connectionParam = DatasourceUtil.buildConnectionParams(postgreSqlDatasourceParam); DbType dataSourceType = postgreSqlDatasourceParam.getType(); @@ -103,20 +103,20 @@ public class DataSourceServiceTest { //PowerMockito.when(dataSourceService.checkConnection(dataSourceType, parameter)).thenReturn(connectionResult); PowerMockito.doReturn(connectionResult).when(dataSourceService).checkConnection(dataSourceType, connectionParam); Result connectFailedResult = dataSourceService.createDataSource(loginUser, postgreSqlDatasourceParam); - Assert.assertTrue(connectFailedResult.isStatus(Status.DATASOURCE_CONNECT_FAILED)); + Assert.assertEquals(Status.DATASOURCE_CONNECT_FAILED.getCode(), connectFailedResult.getCode().intValue()); // data source exits PowerMockito.when(dataSourceMapper.queryDataSourceByName(dataSourceName.trim())).thenReturn(null); connectionResult = new Result(Status.SUCCESS.getCode(), Status.SUCCESS.getMsg()); PowerMockito.when(dataSourceService.checkConnection(dataSourceType, connectionParam)).thenReturn(connectionResult); Result notValidError = dataSourceService.createDataSource(loginUser, postgreSqlDatasourceParam); - Assert.assertTrue(notValidError.isStatus(Status.REQUEST_PARAMS_NOT_VALID_ERROR)); + Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getCode(), notValidError.getCode().intValue()); // success PowerMockito.when(dataSourceMapper.queryDataSourceByName(dataSourceName.trim())).thenReturn(null); PowerMockito.when(dataSourceService.checkConnection(dataSourceType, connectionParam)).thenReturn(connectionResult); Result success = dataSourceService.createDataSource(loginUser, postgreSqlDatasourceParam); - Assert.assertTrue(success.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(), success.getCode().intValue()); } public void updateDataSourceTest() { @@ -138,13 +138,13 @@ public class DataSourceServiceTest { // data source not exits PowerMockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(null); Result resourceNotExits = dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam); - Assert.assertTrue(resourceNotExits.isStatus(Status.RESOURCE_NOT_EXIST)); + Assert.assertEquals(Status.RESOURCE_NOT_EXIST.getCode(), resourceNotExits.getCode().intValue()); // user no operation perm DataSource dataSource = new DataSource(); dataSource.setUserId(0); PowerMockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(dataSource); Result userNoOperationPerm = dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam); - Assert.assertTrue(userNoOperationPerm.isStatus(Status.USER_NO_OPERATION_PERM)); + Assert.assertEquals(Status.USER_NO_OPERATION_PERM.getCode(), userNoOperationPerm.getCode().intValue()); // data source name exits dataSource.setUserId(-1); @@ -153,7 +153,7 @@ public class DataSourceServiceTest { PowerMockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(dataSource); PowerMockito.when(dataSourceMapper.queryDataSourceByName(dataSourceName)).thenReturn(dataSourceList); Result dataSourceNameExist = dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam); - Assert.assertTrue(dataSourceNameExist.isStatus(Status.DATASOURCE_EXIST)); + Assert.assertEquals(Status.DATASOURCE_EXIST.getCode(), dataSourceNameExist.getCode().intValue()); // data source connect failed DbType dataSourceType = postgreSqlDatasourceParam.getType(); @@ -163,14 +163,15 @@ public class DataSourceServiceTest { Result connectionResult = new Result(Status.SUCCESS.getCode(), Status.SUCCESS.getMsg()); PowerMockito.when(dataSourceService.checkConnection(dataSourceType, connectionParam)).thenReturn(connectionResult); Result connectFailed = dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam); - Assert.assertTrue(connectFailed.isStatus(Status.DATASOURCE_CONNECT_FAILED)); + Assert.assertEquals(Status.DATASOURCE_CONNECT_FAILED.getCode(), connectFailed.getCode().intValue()); + //success PowerMockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(dataSource); PowerMockito.when(dataSourceMapper.queryDataSourceByName(dataSourceName)).thenReturn(null); connectionResult = new Result(Status.DATASOURCE_CONNECT_FAILED.getCode(), Status.DATASOURCE_CONNECT_FAILED.getMsg()); PowerMockito.when(dataSourceService.checkConnection(dataSourceType, connectionParam)).thenReturn(connectionResult); Result success = dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam); - Assert.assertTrue(success.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(), success.getCode().intValue()); } @@ -189,7 +190,7 @@ public class DataSourceServiceTest { int dataSourceId = -1; PowerMockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(null); Result result = dataSourceService.connectionTest(dataSourceId); - Assert.assertTrue(result.isStatus(Status.RESOURCE_NOT_EXIST)); + Assert.assertEquals(Status.RESOURCE_NOT_EXIST.getCode(), result.getCode().intValue()); } @Test @@ -397,12 +398,13 @@ public class DataSourceServiceTest { PowerMockito.mockStatic(DatasourceUtil.class); Result result = dataSourceService.checkConnection(dataSourceType, connectionParam); - Assert.assertTrue(result.isStatus(Status.CONNECTION_TEST_FAILURE)); + Assert.assertEquals(Status.CONNECTION_TEST_FAILURE.getCode(), result.getCode().intValue()); Connection connection = PowerMockito.mock(Connection.class); PowerMockito.when(DatasourceUtil.getConnection(Mockito.any(), Mockito.any())).thenReturn(connection); result = dataSourceService.checkConnection(dataSourceType, connectionParam); - Assert.assertTrue(result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); + } } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorService2Test.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorService2Test.java deleted file mode 100644 index 6f7aeb2449..0000000000 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorService2Test.java +++ /dev/null @@ -1,308 +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 static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import org.apache.dolphinscheduler.api.enums.ExecuteType; -import org.apache.dolphinscheduler.api.enums.Status; -import org.apache.dolphinscheduler.api.service.impl.ExecutorServiceImpl; -import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; -import org.apache.dolphinscheduler.common.Constants; -import org.apache.dolphinscheduler.common.enums.CommandType; -import org.apache.dolphinscheduler.common.enums.ExecutionStatus; -import org.apache.dolphinscheduler.common.enums.Priority; -import org.apache.dolphinscheduler.common.enums.ReleaseState; -import org.apache.dolphinscheduler.common.enums.RunMode; -import org.apache.dolphinscheduler.common.model.Server; -import org.apache.dolphinscheduler.dao.entity.Command; -import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; -import org.apache.dolphinscheduler.dao.entity.ProcessInstance; -import org.apache.dolphinscheduler.dao.entity.Project; -import org.apache.dolphinscheduler.dao.entity.Schedule; -import org.apache.dolphinscheduler.dao.entity.Tenant; -import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; -import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; -import org.apache.dolphinscheduler.service.process.ProcessService; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; - -/** - * executor service 2 test - */ -@RunWith(MockitoJUnitRunner.Silent.class) -public class ExecutorService2Test { - - @InjectMocks - private ExecutorServiceImpl executorService; - - @Mock - private ProcessService processService; - - @Mock - private ProcessDefinitionMapper processDefinitionMapper; - - @Mock - private ProjectMapper projectMapper; - - @Mock - private ProjectServiceImpl projectService; - - @Mock - private MonitorService monitorService; - - private int processDefinitionId = 1; - - private int processInstanceId = 1; - - private int tenantId = 1; - - private int userId = 1; - - private ProcessDefinition processDefinition = new ProcessDefinition(); - - private ProcessInstance processInstance = new ProcessInstance(); - - private User loginUser = new User(); - - private String projectName = "projectName"; - - private Project project = new Project(); - - private String cronTime; - - @Before - public void init() { - // user - loginUser.setId(userId); - - // processDefinition - processDefinition.setId(processDefinitionId); - processDefinition.setReleaseState(ReleaseState.ONLINE); - processDefinition.setTenantId(tenantId); - processDefinition.setUserId(userId); - processDefinition.setVersion(1); - processDefinition.setCode(1L); - - // processInstance - processInstance.setId(processInstanceId); - processInstance.setState(ExecutionStatus.FAILURE); - processInstance.setExecutorId(userId); - processInstance.setTenantId(tenantId); - processInstance.setProcessDefinitionVersion(1); - processInstance.setProcessDefinitionCode(1L); - - // project - project.setName(projectName); - - // cronRangeTime - cronTime = "2020-01-01 00:00:00,2020-01-31 23:00:00"; - - // mock - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(checkProjectAndAuth()); - Mockito.when(processDefinitionMapper.selectById(processDefinitionId)).thenReturn(processDefinition); - Mockito.when(processService.getTenantForProcess(tenantId, userId)).thenReturn(new Tenant()); - Mockito.when(processService.createCommand(any(Command.class))).thenReturn(1); - Mockito.when(monitorService.getServerListFromRegistry(true)).thenReturn(getMasterServersList()); - Mockito.when(processService.findProcessInstanceDetailById(processInstanceId)).thenReturn(processInstance); - Mockito.when(processService.findProcessDefinition(1L, 1)).thenReturn(processDefinition); - } - - /** - * not complement - */ - @Test - public void testNoComplement() { - - Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList()); - Map result = executorService.execProcessInstance(loginUser, projectName, - processDefinitionId, cronTime, CommandType.START_PROCESS, - null, null, - null, null, 0, - RunMode.RUN_MODE_SERIAL, - Priority.LOW, Constants.DEFAULT_WORKER_GROUP,-1L, 110, null, 4); - Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - verify(processService, times(1)).createCommand(any(Command.class)); - - } - - /** - * not complement - */ - @Test - public void testComplementWithStartNodeList() { - - Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList()); - Map result = executorService.execProcessInstance(loginUser, projectName, - processDefinitionId, cronTime, CommandType.START_PROCESS, - null, "n1,n2", - null, null, 0, - RunMode.RUN_MODE_SERIAL, - Priority.LOW, Constants.DEFAULT_WORKER_GROUP,-1L, 110, null, null); - Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - verify(processService, times(1)).createCommand(any(Command.class)); - - } - - /** - * date error - */ - @Test - public void testDateError() { - - Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList()); - Map result = executorService.execProcessInstance(loginUser, projectName, - processDefinitionId, "2020-01-31 23:00:00,2020-01-01 00:00:00", CommandType.COMPLEMENT_DATA, - null, null, - null, null, 0, - RunMode.RUN_MODE_SERIAL, - Priority.LOW, Constants.DEFAULT_WORKER_GROUP,-1L, 110, null, null); - Assert.assertEquals(Status.START_PROCESS_INSTANCE_ERROR, result.get(Constants.STATUS)); - verify(processService, times(0)).createCommand(any(Command.class)); - } - - /** - * serial - */ - @Test - public void testSerial() { - - Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList()); - Map result = executorService.execProcessInstance(loginUser, projectName, - processDefinitionId, cronTime, CommandType.COMPLEMENT_DATA, - null, null, - null, null, 0, - RunMode.RUN_MODE_SERIAL, - Priority.LOW, Constants.DEFAULT_WORKER_GROUP,-1L, 110, null, null); - Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - verify(processService, times(1)).createCommand(any(Command.class)); - - } - - /** - * without schedule - */ - @Test - public void testParallelWithOutSchedule() { - - Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList()); - Map 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,-1L, 110, null, null); - Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - verify(processService, times(31)).createCommand(any(Command.class)); - - } - - /** - * with schedule - */ - @Test - public void testParallelWithSchedule() { - - Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(oneSchedulerList()); - Map 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,-1L, 110, null, 4); - Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - verify(processService, times(4)).createCommand(any(Command.class)); - - } - - @Test - public void testNoMsterServers() { - Mockito.when(monitorService.getServerListFromRegistry(true)).thenReturn(new ArrayList<>()); - - Map 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,-1L, 110, null, 4); - Assert.assertEquals(result.get(Constants.STATUS), Status.MASTER_NOT_EXISTS); - - } - - @Test - public void testExecuteRepeatRunning() { - Mockito.when(processService.verifyIsNeedCreateCommand(any(Command.class))).thenReturn(true); - - Map result = executorService.execute(loginUser, projectName, processInstanceId, ExecuteType.REPEAT_RUNNING); - Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - } - - private List getMasterServersList() { - List masterServerList = new ArrayList<>(); - Server masterServer1 = new Server(); - masterServer1.setId(1); - masterServer1.setHost("192.168.220.188"); - masterServer1.setPort(1121); - masterServerList.add(masterServer1); - - Server masterServer2 = new Server(); - masterServer2.setId(2); - masterServer2.setHost("192.168.220.189"); - masterServer2.setPort(1122); - masterServerList.add(masterServer2); - - return masterServerList; - - } - - private List zeroSchedulerList() { - return Collections.EMPTY_LIST; - } - - private List oneSchedulerList() { - List schedulerList = new LinkedList<>(); - Schedule schedule = new Schedule(); - schedule.setCrontab("0 0 0 1/2 * ?"); - schedulerList.add(schedule); - return schedulerList; - } - - private Map checkProjectAndAuth() { - Map result = new HashMap<>(); - result.put(Constants.STATUS, Status.SUCCESS); - return result; - } -} diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorServiceTest.java index 071b77c756..01e81adbb8 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorServiceTest.java @@ -17,52 +17,313 @@ package org.apache.dolphinscheduler.api.service; -import org.apache.dolphinscheduler.api.controller.AbstractControllerTest; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.apache.dolphinscheduler.api.enums.ExecuteType; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.service.impl.ExecutorServiceImpl; +import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; import org.apache.dolphinscheduler.common.Constants; +import org.apache.dolphinscheduler.common.enums.CommandType; +import org.apache.dolphinscheduler.common.enums.ExecutionStatus; +import org.apache.dolphinscheduler.common.enums.Priority; +import org.apache.dolphinscheduler.common.enums.ReleaseState; +import org.apache.dolphinscheduler.common.enums.RunMode; +import org.apache.dolphinscheduler.common.model.Server; +import org.apache.dolphinscheduler.dao.entity.Command; +import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; +import org.apache.dolphinscheduler.dao.entity.ProcessInstance; +import org.apache.dolphinscheduler.dao.entity.Project; +import org.apache.dolphinscheduler.dao.entity.Schedule; +import org.apache.dolphinscheduler.dao.entity.Tenant; +import org.apache.dolphinscheduler.dao.entity.User; +import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; +import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; +import org.apache.dolphinscheduler.service.process.ProcessService; -import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import org.junit.Assert; -import org.junit.Ignore; +import org.junit.Before; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; /** - * executor service test + * executor service 2 test */ -public class ExecutorServiceTest extends AbstractControllerTest { +@RunWith(MockitoJUnitRunner.Silent.class) +public class ExecutorServiceTest { - private static final Logger logger = LoggerFactory.getLogger(ExecutorServiceTest.class); - - @Autowired + @InjectMocks private ExecutorServiceImpl executorService; - @Ignore + @Mock + private ProcessService processService; + + @Mock + private ProcessDefinitionMapper processDefinitionMapper; + + @Mock + private ProjectMapper projectMapper; + + @Mock + private ProjectServiceImpl projectService; + + @Mock + private MonitorService monitorService; + + private int processDefinitionId = 1; + + private long processDefinitionCode = 1L; + + private int processInstanceId = 1; + + private int tenantId = 1; + + private int userId = 1; + + private ProcessDefinition processDefinition = new ProcessDefinition(); + + private ProcessInstance processInstance = new ProcessInstance(); + + private User loginUser = new User(); + + private long projectCode = 1L; + + private String projectName = "projectName"; + + private Project project = new Project(); + + private String cronTime; + + @Before + public void init() { + // user + loginUser.setId(userId); + + // processDefinition + processDefinition.setId(processDefinitionId); + processDefinition.setReleaseState(ReleaseState.ONLINE); + processDefinition.setTenantId(tenantId); + processDefinition.setUserId(userId); + processDefinition.setVersion(1); + processDefinition.setCode(1L); + + // processInstance + processInstance.setId(processInstanceId); + processInstance.setState(ExecutionStatus.FAILURE); + processInstance.setExecutorId(userId); + processInstance.setTenantId(tenantId); + processInstance.setProcessDefinitionVersion(1); + processInstance.setProcessDefinitionCode(1L); + + // project + project.setCode(projectCode); + project.setName(projectName); + + // cronRangeTime + cronTime = "2020-01-01 00:00:00,2020-01-31 23:00:00"; + + // mock + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(checkProjectAndAuth()); + Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition); + Mockito.when(processService.getTenantForProcess(tenantId, userId)).thenReturn(new Tenant()); + Mockito.when(processService.createCommand(any(Command.class))).thenReturn(1); + Mockito.when(monitorService.getServerListFromRegistry(true)).thenReturn(getMasterServersList()); + Mockito.when(processService.findProcessInstanceDetailById(processInstanceId)).thenReturn(processInstance); + Mockito.when(processService.findProcessDefinition(1L, 1)).thenReturn(processDefinition); + } + + /** + * not complement + */ @Test - public void startCheckByProcessDefinedId() { - Map map = executorService.startCheckByProcessDefinedId(1234); - Assert.assertNull(map); + public void testNoComplement() { + + Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)).thenReturn(zeroSchedulerList()); + Map result = executorService.execProcessInstance(loginUser, projectCode, + processDefinitionCode, cronTime, CommandType.START_PROCESS, + null, null, + null, null, 0, + RunMode.RUN_MODE_SERIAL, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 100L, 10, null, 0); + Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); + verify(processService, times(1)).createCommand(any(Command.class)); + + } + + /** + * not complement + */ + @Test + public void testComplementWithStartNodeList() { + + Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)).thenReturn(zeroSchedulerList()); + Map result = executorService.execProcessInstance(loginUser, projectCode, + processDefinitionCode, cronTime, CommandType.START_PROCESS, + null, "n1,n2", + null, null, 0, + RunMode.RUN_MODE_SERIAL, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 100L,110, null, 0); + Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); + verify(processService, times(1)).createCommand(any(Command.class)); + + } + + /** + * date error + */ + @Test + public void testDateError() { + + Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)).thenReturn(zeroSchedulerList()); + Map result = executorService.execProcessInstance(loginUser, projectCode, + processDefinitionCode, "2020-01-31 23:00:00,2020-01-01 00:00:00", CommandType.COMPLEMENT_DATA, + null, null, + null, null, 0, + RunMode.RUN_MODE_SERIAL, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP,100L, 110, null, 0); + Assert.assertEquals(Status.START_PROCESS_INSTANCE_ERROR, result.get(Constants.STATUS)); + verify(processService, times(0)).createCommand(any(Command.class)); + } + + /** + * serial + */ + @Test + public void testSerial() { + + Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)).thenReturn(zeroSchedulerList()); + Map result = executorService.execProcessInstance(loginUser, projectCode, + processDefinitionCode, cronTime, CommandType.COMPLEMENT_DATA, + null, null, + null, null, 0, + RunMode.RUN_MODE_SERIAL, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP,100L, 110, null, 0); + Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); + verify(processService, times(1)).createCommand(any(Command.class)); + } + + /** + * without schedule + */ + @Test + public void testParallelWithOutSchedule() { + + Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)).thenReturn(zeroSchedulerList()); + Map result = executorService.execProcessInstance(loginUser, projectCode, + processDefinitionCode, cronTime, CommandType.COMPLEMENT_DATA, + null, null, + null, null, 0, + RunMode.RUN_MODE_PARALLEL, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP,100L, 110, null, 0); + Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); + verify(processService, times(31)).createCommand(any(Command.class)); + + } + + /** + * with schedule + */ + @Test + public void testParallelWithSchedule() { + + Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)).thenReturn(oneSchedulerList()); + Map result = executorService.execProcessInstance(loginUser, projectCode, + processDefinitionCode, cronTime, CommandType.COMPLEMENT_DATA, + null, null, + null, null, 0, + RunMode.RUN_MODE_PARALLEL, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 100L,110, null, 15); + Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); + verify(processService, times(15)).createCommand(any(Command.class)); + } @Test - public void putMsgWithParamsTest() { - Map map = new HashMap<>(); - putMsgWithParams(map, Status.PROJECT_ALREADY_EXISTS); - logger.info(map.toString()); + public void testNoMasterServers() { + Mockito.when(monitorService.getServerListFromRegistry(true)).thenReturn(new ArrayList<>()); + + Map result = executorService.execProcessInstance(loginUser, projectCode, + processDefinitionCode, cronTime, CommandType.COMPLEMENT_DATA, + null, null, + null, null, 0, + RunMode.RUN_MODE_PARALLEL, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 100L,110, null, 0); + Assert.assertEquals(result.get(Constants.STATUS), Status.MASTER_NOT_EXISTS); + } - void putMsgWithParams(Map result, Status status, Object... statusParams) { - result.put(Constants.STATUS, status); - if (statusParams != null && statusParams.length > 0) { - result.put(Constants.MSG, MessageFormat.format(status.getMsg(), statusParams)); - } else { - result.put(Constants.MSG, status.getMsg()); - } + @Test + public void testExecuteRepeatRunning() { + Mockito.when(processService.verifyIsNeedCreateCommand(any(Command.class))).thenReturn(true); + + Map result = executorService.execute(loginUser, projectCode, processInstanceId, ExecuteType.REPEAT_RUNNING); + Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); } -} \ No newline at end of file + + @Test + public void testStartCheckByProcessDefinedCode() { + List ids = new ArrayList<>(); + ids.add(1); + Mockito.doNothing().when(processService).recurseFindSubProcessId(1, ids); + + List processDefinitionList = new ArrayList<>(); + ProcessDefinition processDefinition = new ProcessDefinition(); + processDefinition.setId(1); + processDefinition.setReleaseState(ReleaseState.ONLINE); + processDefinitionList.add(processDefinition); + Mockito.when(processDefinitionMapper.queryDefinitionListByIdList(new Integer[ids.size()])) + .thenReturn(processDefinitionList); + + Map result = executorService.startCheckByProcessDefinedCode(1L); + Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); + } + + private List getMasterServersList() { + List masterServerList = new ArrayList<>(); + Server masterServer1 = new Server(); + masterServer1.setId(1); + masterServer1.setHost("192.168.220.188"); + masterServer1.setPort(1121); + masterServerList.add(masterServer1); + + Server masterServer2 = new Server(); + masterServer2.setId(2); + masterServer2.setHost("192.168.220.189"); + masterServer2.setPort(1122); + masterServerList.add(masterServer2); + + return masterServerList; + } + + private List zeroSchedulerList() { + return Collections.EMPTY_LIST; + } + + private List oneSchedulerList() { + List schedulerList = new LinkedList<>(); + Schedule schedule = new Schedule(); + schedule.setCrontab("0 0 0 1/2 * ?"); + schedulerList.add(schedule); + return schedulerList; + } + + private Map checkProjectAndAuth() { + Map result = new HashMap<>(); + result.put(Constants.STATUS, Status.SUCCESS); + return result; + } +} diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/LoggerServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/LoggerServiceTest.java index 433cc95edd..bd8aa72fef 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/LoggerServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/LoggerServiceTest.java @@ -63,7 +63,7 @@ public class LoggerServiceTest { Mockito.when(processService.findTaskInstanceById(1)).thenReturn(taskInstance); Result result = loggerService.queryLog(2, 1, 1); //TASK_INSTANCE_NOT_FOUND - Assert.assertTrue(result.isStatus(Status.TASK_INSTANCE_NOT_FOUND)); + Assert.assertEquals(Status.TASK_INSTANCE_NOT_FOUND.getCode(), result.getCode().intValue()); try { //HOST NOT FOUND OR ILLEGAL @@ -72,14 +72,14 @@ public class LoggerServiceTest { Assert.assertTrue(true); logger.error("testQueryDataSourceList error {}", e.getMessage()); } - Assert.assertTrue(result.isStatus(Status.TASK_INSTANCE_NOT_FOUND)); + Assert.assertEquals(Status.TASK_INSTANCE_NOT_FOUND.getCode(), result.getCode().intValue()); //SUCCESS taskInstance.setHost("127.0.0.1:8080"); taskInstance.setLogPath("/temp/log"); Mockito.when(processService.findTaskInstanceById(1)).thenReturn(taskInstance); result = loggerService.queryLog(1, 1, 1); - Assert.assertTrue(result.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); } @Test diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java index a36b7708e5..b4ab9ce216 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java @@ -18,35 +18,25 @@ package org.apache.dolphinscheduler.api.service; import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; -import org.apache.dolphinscheduler.api.dto.ProcessMeta; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.service.impl.ProcessDefinitionServiceImpl; import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; -import org.apache.dolphinscheduler.common.enums.ExecutionStatus; import org.apache.dolphinscheduler.common.enums.FailureStrategy; import org.apache.dolphinscheduler.common.enums.Priority; import org.apache.dolphinscheduler.common.enums.ReleaseState; -import org.apache.dolphinscheduler.common.enums.TaskType; import org.apache.dolphinscheduler.common.enums.UserType; import org.apache.dolphinscheduler.common.enums.WarningType; import org.apache.dolphinscheduler.common.graph.DAG; -import org.apache.dolphinscheduler.common.model.TaskNode; -import org.apache.dolphinscheduler.common.process.Property; -import org.apache.dolphinscheduler.common.utils.DateUtils; -import org.apache.dolphinscheduler.common.utils.FileUtils; -import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.common.utils.StringUtils; -import org.apache.dolphinscheduler.dao.entity.DataSource; -import org.apache.dolphinscheduler.dao.entity.ProcessData; +import org.apache.dolphinscheduler.dao.entity.DagData; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; -import org.apache.dolphinscheduler.dao.entity.ProcessInstance; +import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation; import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.Schedule; -import org.apache.dolphinscheduler.dao.entity.TaskInstance; +import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.DataSourceMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; @@ -54,14 +44,9 @@ import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; +import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.service.process.ProcessService; -import org.apache.http.entity.ContentType; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.lang.reflect.Method; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; @@ -69,8 +54,9 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; -import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import org.junit.Assert; @@ -80,14 +66,10 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.mock.web.MockMultipartFile; -import org.springframework.web.multipart.MultipartFile; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.common.collect.Lists; /** * process definition service test @@ -95,155 +77,15 @@ import com.fasterxml.jackson.databind.node.ObjectNode; @RunWith(MockitoJUnitRunner.class) public class ProcessDefinitionServiceTest { - private static final String SHELL_JSON = "{\n" - + " \"globalParams\": [\n" - + " \n" - + " ],\n" - + " \"tasks\": [\n" - + " {\n" - + " \"type\": \"SHELL\",\n" - + " \"id\": \"tasks-9527\",\n" - + " \"name\": \"shell-1\",\n" - + " \"params\": {\n" - + " \"resourceList\": [\n" - + " \n" - + " ],\n" - + " \"localParams\": [\n" - + " \n" - + " ],\n" - + " \"rawScript\": \"#!/bin/bash\\necho \\\"shell-1\\\"\"\n" - + " },\n" - + " \"description\": \"\",\n" - + " \"runFlag\": \"NORMAL\",\n" - + " \"dependence\": {\n" - + " \n" - + " },\n" - + " \"maxRetryTimes\": \"0\",\n" - + " \"retryInterval\": \"1\",\n" - + " \"timeout\": {\n" - + " \"strategy\": \"\",\n" - + " \"interval\": 1,\n" - + " \"enable\": false\n" - + " },\n" - + " \"taskInstancePriority\": \"MEDIUM\",\n" - + " \"workerGroupId\": -1,\n" - + " \"preTasks\": [\n" - + " \n" - + " ]\n" - + " }\n" - + " ],\n" - + " \"tenantId\": 1,\n" - + " \"timeout\": 0\n" - + "}"; - - private static final String CYCLE_SHELL_JSON = "{\n" - + " \"globalParams\": [\n" - + " \n" - + " ],\n" - + " \"tasks\": [\n" - + " {\n" - + " \"type\": \"SHELL\",\n" - + " \"id\": \"tasks-9527\",\n" - + " \"name\": \"shell-1\",\n" - + " \"params\": {\n" - + " \"resourceList\": [\n" - + " \n" - + " ],\n" - + " \"localParams\": [\n" - + " \n" - + " ],\n" - + " \"rawScript\": \"#!/bin/bash\\necho \\\"shell-1\\\"\"\n" - + " },\n" - + " \"description\": \"\",\n" - + " \"runFlag\": \"NORMAL\",\n" - + " \"dependence\": {\n" - + " \n" - + " },\n" - + " \"maxRetryTimes\": \"0\",\n" - + " \"retryInterval\": \"1\",\n" - + " \"timeout\": {\n" - + " \"strategy\": \"\",\n" - + " \"interval\": 1,\n" - + " \"enable\": false\n" - + " },\n" - + " \"taskInstancePriority\": \"MEDIUM\",\n" - + " \"workerGroupId\": -1,\n" - + " \"preTasks\": [\n" - + " \"tasks-9529\"\n" - + " ]\n" - + " },\n" - + " {\n" - + " \"type\": \"SHELL\",\n" - + " \"id\": \"tasks-9528\",\n" - + " \"name\": \"shell-1\",\n" - + " \"params\": {\n" - + " \"resourceList\": [\n" - + " \n" - + " ],\n" - + " \"localParams\": [\n" - + " \n" - + " ],\n" - + " \"rawScript\": \"#!/bin/bash\\necho \\\"shell-1\\\"\"\n" - + " },\n" - + " \"description\": \"\",\n" - + " \"runFlag\": \"NORMAL\",\n" - + " \"dependence\": {\n" - + " \n" - + " },\n" - + " \"maxRetryTimes\": \"0\",\n" - + " \"retryInterval\": \"1\",\n" - + " \"timeout\": {\n" - + " \"strategy\": \"\",\n" - + " \"interval\": 1,\n" - + " \"enable\": false\n" - + " },\n" - + " \"taskInstancePriority\": \"MEDIUM\",\n" - + " \"workerGroupId\": -1,\n" - + " \"preTasks\": [\n" - + " \"tasks-9527\"\n" - + " ]\n" - + " },\n" - + " {\n" - + " \"type\": \"SHELL\",\n" - + " \"id\": \"tasks-9529\",\n" - + " \"name\": \"shell-1\",\n" - + " \"params\": {\n" - + " \"resourceList\": [\n" - + " \n" - + " ],\n" - + " \"localParams\": [\n" - + " \n" - + " ],\n" - + " \"rawScript\": \"#!/bin/bash\\necho \\\"shell-1\\\"\"\n" - + " },\n" - + " \"description\": \"\",\n" - + " \"runFlag\": \"NORMAL\",\n" - + " \"dependence\": {\n" - + " \n" - + " },\n" - + " \"maxRetryTimes\": \"0\",\n" - + " \"retryInterval\": \"1\",\n" - + " \"timeout\": {\n" - + " \"strategy\": \"\",\n" - + " \"interval\": 1,\n" - + " \"enable\": false\n" - + " },\n" - + " \"taskInstancePriority\": \"MEDIUM\",\n" - + " \"workerGroupId\": -1,\n" - + " \"preTasks\": [\n" - + " \"tasks-9528\"\n" - + " ]\n" - + " }\n" - + " ],\n" - + " \"tenantId\": 1,\n" - + " \"timeout\": 0\n" - + "}"; + private static final String taskRelationJson = "[{\"name\":\"\",\"preTaskCode\":0,\"preTaskVersion\":0,\"postTaskCode\":123456789," + + "\"postTaskVersion\":1,\"conditionType\":0,\"conditionParams\":\"{}\"},{\"name\":\"\",\"preTaskCode\":123456789," + + "\"preTaskVersion\":1,\"postTaskCode\":123451234,\"postTaskVersion\":1,\"conditionType\":0,\"conditionParams\":\"{}\"}]"; @InjectMocks private ProcessDefinitionServiceImpl processDefinitionService; @Mock - private ProcessDefinitionMapper processDefinitionMapper; + private ProcessDefinitionMapper processDefineMapper; @Mock private ProcessTaskRelationMapper processTaskRelationMapper; @@ -265,64 +107,66 @@ public class ProcessDefinitionServiceTest { @Mock private TaskInstanceMapper taskInstanceMapper; + @Mock + private TenantMapper tenantMapper; @Mock private DataSourceMapper dataSourceMapper; @Test public void testQueryProcessDefinitionList() { - String projectName = "project_test1"; - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); + long projectCode = 1L; + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); - Project project = getProject(projectName); + Project project = getProject(projectCode); User loginUser = new User(); loginUser.setId(-1); loginUser.setUserType(UserType.GENERAL_USER); Map result = new HashMap<>(); - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); //project not found - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - Map map = processDefinitionService.queryProcessDefinitionList(loginUser, "project_test1"); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Map map = processDefinitionService.queryProcessDefinitionList(loginUser, projectCode); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); //project check auth success - putMsg(result, Status.SUCCESS, projectName); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); List resourceList = new ArrayList<>(); resourceList.add(getProcessDefinition()); - Mockito.when(processDefinitionMapper.queryAllDefinitionList(project.getCode())).thenReturn(resourceList); - Map checkSuccessRes = processDefinitionService.queryProcessDefinitionList(loginUser, "project_test1"); + Mockito.when(processDefineMapper.queryAllDefinitionList(project.getCode())).thenReturn(resourceList); + Map checkSuccessRes = processDefinitionService.queryProcessDefinitionList(loginUser, projectCode); Assert.assertEquals(Status.SUCCESS, checkSuccessRes.get(Constants.STATUS)); } @Test @SuppressWarnings("unchecked") public void testQueryProcessDefinitionListPaging() { - String projectName = "project_test1"; - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); + long projectCode = 1L; + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); - Project project = getProject(projectName); + Project project = getProject(projectCode); User loginUser = new User(); loginUser.setId(-1); loginUser.setUserType(UserType.GENERAL_USER); Map result = new HashMap<>(); - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); //project not found - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - Result map = processDefinitionService.queryProcessDefinitionListPaging(loginUser, "project_test1", "", 1, 5, 0); - Assert.assertEquals(Status.PROJECT_NOT_FOUNT.getCode(), (int)map.getCode()); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Result map = processDefinitionService.queryProcessDefinitionListPaging(loginUser, projectCode, "", 1, 5, 0); + Assert.assertEquals(Status.PROJECT_NOT_FOUNT.getCode(), (int) map.getCode()); - putMsg(result, Status.SUCCESS, projectName); + putMsg(result, Status.SUCCESS, projectCode); loginUser.setId(1); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Page page = new Page<>(1, 10); page.setTotal(30); - Mockito.when(processDefinitionMapper.queryDefineListPaging( + Mockito.when(processDefineMapper.queryDefineListPaging( Mockito.any(IPage.class) , Mockito.eq("") , Mockito.eq(loginUser.getId()) @@ -330,478 +174,412 @@ public class ProcessDefinitionServiceTest { , Mockito.anyBoolean())).thenReturn(page); Result map1 = processDefinitionService.queryProcessDefinitionListPaging( - loginUser, projectName, "", 1, 10, loginUser.getId()); + loginUser, 1L, "", 1, 10, loginUser.getId()); Assert.assertEquals(Status.SUCCESS.getMsg(), map1.getMsg()); } @Test - public void testQueryProcessDefinitionById() { - String projectName = "project_test1"; - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); + public void testQueryProcessDefinitionByCode() { + long projectCode = 1L; + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); - Project project = getProject(projectName); + Project project = getProject(projectCode); User loginUser = new User(); loginUser.setId(-1); loginUser.setUserType(UserType.GENERAL_USER); - + Tenant tenant = new Tenant(); + tenant.setId(1); + tenant.setTenantCode("root"); Map result = new HashMap<>(); - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); //project check auth fail - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - Map map = processDefinitionService.queryProcessDefinitionById(loginUser, - "project_test1", 1); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Map map = processDefinitionService.queryProcessDefinitionByCode(loginUser, 1L, 1L); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); //project check auth success, instance not exist - putMsg(result, Status.SUCCESS, projectName); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - Mockito.when(processDefinitionMapper.selectById(1)).thenReturn(null); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + DagData dagData = new DagData(getProcessDefinition(), null, null); + Mockito.when(processService.genDagData(Mockito.any())).thenReturn(dagData); - String processDefinitionJson = "{\"globalParams\":[],\"tasks\":[{\"conditionResult\":" - + "{\"failedNode\":[\"\"],\"successNode\":[\"\"]},\"delayTime\":\"0\",\"dependence\":{}" - + ",\"description\":\"\",\"id\":\"tasks-3011\",\"maxRetryTimes\":\"0\",\"name\":\"tsssss\"" - + ",\"params\":{\"localParams\":[],\"rawScript\":\"echo \\\"123123\\\"\",\"resourceList\":[]}" - + ",\"preTasks\":[],\"retryInterval\":\"1\",\"runFlag\":\"NORMAL\",\"taskInstancePriority\":\"MEDIUM\"" - + ",\"timeout\":{\"enable\":false,\"interval\":null,\"strategy\":\"\"},\"type\":\"SHELL\"" - + ",\"waitStartTimeout\":{},\"workerGroup\":\"default\"}],\"tenantId\":4,\"timeout\":0}"; - ProcessData processData = JSONUtils.parseObject(processDefinitionJson, ProcessData.class); - Mockito.when(processService.genProcessData(Mockito.any())).thenReturn(processData); - - Map instanceNotexitRes = processDefinitionService.queryProcessDefinitionById(loginUser, - "project_test1", 1); + Map instanceNotexitRes = processDefinitionService.queryProcessDefinitionByCode(loginUser, projectCode, 1L); Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotexitRes.get(Constants.STATUS)); //instance exit - Mockito.when(processDefinitionMapper.selectById(46)).thenReturn(getProcessDefinition()); - Map successRes = processDefinitionService.queryProcessDefinitionById(loginUser, - "project_test1", 46); + Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(getProcessDefinition()); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Mockito.when(tenantMapper.queryById(1)).thenReturn(tenant); + Map successRes = processDefinitionService.queryProcessDefinitionByCode(loginUser, projectCode, 46L); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); } @Test public void testQueryProcessDefinitionByName() { - String projectName = "project_test1"; - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); + long projectCode = 1L; + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); - Project project = getProject(projectName); + Project project = getProject(projectCode); User loginUser = new User(); loginUser.setId(-1); loginUser.setUserType(UserType.GENERAL_USER); Map result = new HashMap<>(); - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); //project check auth fail - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - Map map = processDefinitionService.queryProcessDefinitionByName(loginUser, - "project_test1", "test_def"); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Map map = processDefinitionService.queryProcessDefinitionByName(loginUser, projectCode, "test_def"); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); //project check auth success, instance not exist - putMsg(result, Status.SUCCESS, projectName); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - Mockito.when(processDefinitionMapper.queryByDefineName(project.getCode(), "test_def")).thenReturn(null); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Mockito.when(processDefineMapper.queryByDefineName(project.getCode(), "test_def")).thenReturn(null); - ProcessData processData = getProcessData(); - Mockito.when(processService.genProcessData(Mockito.any())).thenReturn(processData); - Map instanceNotexitRes = processDefinitionService.queryProcessDefinitionByName(loginUser, - "project_test1", "test_def"); - Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotexitRes.get(Constants.STATUS)); + Map instanceNotExitRes = processDefinitionService.queryProcessDefinitionByName(loginUser, projectCode, "test_def"); + Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotExitRes.get(Constants.STATUS)); //instance exit - Mockito.when(processDefinitionMapper.queryByDefineName(project.getCode(), "test")).thenReturn(getProcessDefinition()); - Map successRes = processDefinitionService.queryProcessDefinitionByName(loginUser, - "project_test1", "test"); + Mockito.when(processDefineMapper.queryByDefineName(project.getCode(), "test")).thenReturn(getProcessDefinition()); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Map successRes = processDefinitionService.queryProcessDefinitionByName(loginUser, projectCode, "test"); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); } @Test public void testBatchCopyProcessDefinition() { - - String projectName = "project_test1"; - Project project = getProject(projectName); + long projectCode = 1L; + Project project = getProject(projectCode); User loginUser = new User(); - loginUser.setId(-1); + loginUser.setId(1); loginUser.setUserType(UserType.GENERAL_USER); + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); // copy project definition ids empty test - Map map = processDefinitionService.batchCopyProcessDefinition(loginUser, projectName, StringUtils.EMPTY, 0); - Assert.assertEquals(Status.PROCESS_DEFINITION_IDS_IS_EMPTY, map.get(Constants.STATUS)); - - Map result = new HashMap<>(); + Map map = processDefinitionService.batchCopyProcessDefinition(loginUser, projectCode, StringUtils.EMPTY, 2L); + Assert.assertEquals(Status.PROCESS_DEFINITION_CODES_IS_EMPTY, map.get(Constants.STATUS)); // project check auth fail - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map map1 = processDefinitionService.batchCopyProcessDefinition( - loginUser, projectName, String.valueOf(project.getId()), 0); + loginUser, projectCode, String.valueOf(project.getId()), 2L); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map1.get(Constants.STATUS)); - // project check auth success, target project is null - putMsg(result, Status.SUCCESS, projectName); - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - Mockito.when(projectMapper.queryDetailById(0)).thenReturn(null); - Map map2 = processDefinitionService.batchCopyProcessDefinition( - loginUser, projectName, String.valueOf(project.getId()), 0); - Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map2.get(Constants.STATUS)); - // project check auth success, target project name not equal project name, check auth target project fail - Project project1 = getProject(projectName); - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project1); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); + projectCode = 2L; + Project project1 = getProject(projectCode); + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project1); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); - putMsg(result, Status.SUCCESS, projectName); - String projectName2 = "project_test2"; - Project project2 = getProject(projectName2); - Mockito.when(projectMapper.queryByName(projectName2)).thenReturn(project2); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project2, projectName2)).thenReturn(result); - Mockito.when(projectMapper.queryDetailById(1)).thenReturn(project2); - // instance exit + putMsg(result, Status.SUCCESS, projectCode); ProcessDefinition definition = getProcessDefinition(); - definition.setLocations("{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}"); - definition.setConnects("[]"); - - Mockito.when(processDefinitionMapper.selectById(46)).thenReturn(definition); - Mockito.when(processService.genProcessData(Mockito.any())).thenReturn(getProcessData()); + List processDefinitionList = new ArrayList<>(); + processDefinitionList.add(definition); + Set definitionCodes = Arrays.stream("46".split(Constants.COMMA)).map(Long::parseLong).collect(Collectors.toSet()); + Mockito.when(processDefineMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList); Map map3 = processDefinitionService.batchCopyProcessDefinition( - loginUser, projectName, "46", 1); + loginUser, projectCode, "46", 1L); Assert.assertEquals(Status.COPY_PROCESS_DEFINITION_ERROR, map3.get(Constants.STATUS)); } @Test public void testBatchMoveProcessDefinition() { - String projectName = "project_test1"; - Project project1 = getProject(projectName); - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project1); + long projectCode = 1L; + Project project1 = getProject(projectCode); + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project1); - String projectName2 = "project_test2"; - Project project2 = getProject(projectName2); - Mockito.when(projectMapper.queryByName(projectName2)).thenReturn(project2); - - int targetProjectId = 2; - Mockito.when(projectMapper.queryDetailById(targetProjectId)).thenReturn(getProjectById(targetProjectId)); - - Project project = getProject(projectName); - Project targetProject = getProjectById(targetProjectId); + long projectCode2 = 2L; + Project project2 = getProject(projectCode2); + Mockito.when(projectMapper.queryByCode(projectCode2)).thenReturn(project2); User loginUser = new User(); loginUser.setId(-1); loginUser.setUserType(UserType.GENERAL_USER); Map result = new HashMap<>(); - putMsg(result, Status.SUCCESS, projectName); + putMsg(result, Status.SUCCESS, projectCode); - Map result2 = new HashMap<>(); - putMsg(result2, Status.SUCCESS, targetProject.getName()); - - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project2, projectName2)).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project1, projectCode)).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project2, projectCode2)).thenReturn(result); ProcessDefinition definition = getProcessDefinition(); - definition.setLocations("{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}"); - definition.setConnects("[]"); - + List processDefinitionList = new ArrayList<>(); + processDefinitionList.add(definition); + Set definitionCodes = Arrays.stream("46".split(Constants.COMMA)).map(Long::parseLong).collect(Collectors.toSet()); + Mockito.when(processDefineMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList); + Mockito.when(processTaskRelationMapper.queryByProcessCode(projectCode, 46L)).thenReturn(getProcessTaskRelation(projectCode)); putMsg(result, Status.SUCCESS); Map successRes = processDefinitionService.batchMoveProcessDefinition( - loginUser, "project_test1", "46", 2); - - Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); + loginUser, projectCode, "46", projectCode2); + Assert.assertEquals(Status.MOVE_PROCESS_DEFINITION_ERROR, successRes.get(Constants.STATUS)); } @Test - public void deleteProcessDefinitionByIdTest() { - String projectName = "project_test1"; - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); + public void deleteProcessDefinitionByCodeTest() { + long projectCode = 1L; + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); - Project project = getProject(projectName); + Project project = getProject(projectCode); User loginUser = new User(); loginUser.setId(-1); loginUser.setUserType(UserType.GENERAL_USER); //project check auth fail Map result = new HashMap<>(); - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - Map map = processDefinitionService.deleteProcessDefinitionById(loginUser, "project_test1", 6); + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Map map = processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 6L); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); //project check auth success, instance not exist - putMsg(result, Status.SUCCESS, projectName); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - Mockito.when(processDefinitionMapper.selectById(1)).thenReturn(null); - Map instanceNotexitRes = processDefinitionService.deleteProcessDefinitionById(loginUser, - "project_test1", 1); - Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotexitRes.get(Constants.STATUS)); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Mockito.when(processDefineMapper.queryByCode(1L)).thenReturn(null); + Map instanceNotExitRes = processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 1L); + Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotExitRes.get(Constants.STATUS)); ProcessDefinition processDefinition = getProcessDefinition(); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); //user no auth loginUser.setUserType(UserType.GENERAL_USER); - Mockito.when(processDefinitionMapper.selectById(46)).thenReturn(processDefinition); - Map userNoAuthRes = processDefinitionService.deleteProcessDefinitionById(loginUser, - "project_test1", 46); + Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); + Map userNoAuthRes = processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 46L); Assert.assertEquals(Status.USER_NO_OPERATION_PERM, userNoAuthRes.get(Constants.STATUS)); //process definition online loginUser.setUserType(UserType.ADMIN_USER); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); processDefinition.setReleaseState(ReleaseState.ONLINE); - Mockito.when(processDefinitionMapper.selectById(46)).thenReturn(processDefinition); - Map dfOnlineRes = processDefinitionService.deleteProcessDefinitionById(loginUser, - "project_test1", 46); + Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); + Map dfOnlineRes = processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 46L); Assert.assertEquals(Status.PROCESS_DEFINE_STATE_ONLINE, dfOnlineRes.get(Constants.STATUS)); //scheduler list elements > 1 processDefinition.setReleaseState(ReleaseState.OFFLINE); - Mockito.when(processDefinitionMapper.selectById(46)).thenReturn(processDefinition); + Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); List schedules = new ArrayList<>(); schedules.add(getSchedule()); schedules.add(getSchedule()); - Mockito.when(scheduleMapper.queryByProcessDefinitionId(46)).thenReturn(schedules); - Map schedulerGreaterThanOneRes = processDefinitionService.deleteProcessDefinitionById(loginUser, - "project_test1", 46); - Assert.assertEquals(Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR, schedulerGreaterThanOneRes.get(Constants.STATUS)); + Mockito.when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(schedules); + Map schedulerGreaterThanOneRes = processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 46L); + Assert.assertEquals(Status.DELETE_PROCESS_DEFINE_BY_CODE_ERROR, schedulerGreaterThanOneRes.get(Constants.STATUS)); //scheduler online schedules.clear(); Schedule schedule = getSchedule(); schedule.setReleaseState(ReleaseState.ONLINE); schedules.add(schedule); - Mockito.when(scheduleMapper.queryByProcessDefinitionId(46)).thenReturn(schedules); - Map schedulerOnlineRes = processDefinitionService.deleteProcessDefinitionById(loginUser, - "project_test1", 46); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Mockito.when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(schedules); + Map schedulerOnlineRes = processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 46L); Assert.assertEquals(Status.SCHEDULE_CRON_STATE_ONLINE, schedulerOnlineRes.get(Constants.STATUS)); //delete fail schedules.clear(); schedule.setReleaseState(ReleaseState.OFFLINE); schedules.add(schedule); - Mockito.when(scheduleMapper.queryByProcessDefinitionId(46)).thenReturn(schedules); - Mockito.when(processDefinitionMapper.deleteById(46)).thenReturn(0); - Map deleteFail = processDefinitionService.deleteProcessDefinitionById(loginUser, - "project_test1", 46); - Assert.assertEquals(Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR, deleteFail.get(Constants.STATUS)); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Mockito.when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(schedules); + Mockito.when(processDefineMapper.deleteById(46)).thenReturn(0); + Map deleteFail = processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 46L); + Assert.assertEquals(Status.DELETE_PROCESS_DEFINE_BY_CODE_ERROR, deleteFail.get(Constants.STATUS)); //delete success - Mockito.when(processDefinitionMapper.deleteById(46)).thenReturn(1); - Map deleteSuccess = processDefinitionService.deleteProcessDefinitionById(loginUser, - "project_test1", 46); + Mockito.when(processDefineMapper.deleteById(46)).thenReturn(1); + Mockito.when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(schedules); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Map deleteSuccess = processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 46L); Assert.assertEquals(Status.SUCCESS, deleteSuccess.get(Constants.STATUS)); } @Test public void testReleaseProcessDefinition() { + long projectCode = 1L; + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); - String projectName = "project_test1"; - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); - - Project project = getProject(projectName); + Project project = getProject(projectCode); User loginUser = new User(); loginUser.setId(1); loginUser.setUserType(UserType.GENERAL_USER); //project check auth fail Map result = new HashMap<>(); - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - Map map = processDefinitionService.releaseProcessDefinition(loginUser, "project_test1", + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Map map = processDefinitionService.releaseProcessDefinition(loginUser, projectCode, 6, ReleaseState.OFFLINE); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); // project check auth success, processs definition online - putMsg(result, Status.SUCCESS, projectName); - Mockito.when(processDefinitionMapper.selectById(46)).thenReturn(getProcessDefinition()); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(getProcessDefinition()); Map onlineRes = processDefinitionService.releaseProcessDefinition( - loginUser, "project_test1", 46, ReleaseState.ONLINE); + loginUser, projectCode, 46, ReleaseState.ONLINE); Assert.assertEquals(Status.SUCCESS, onlineRes.get(Constants.STATUS)); // project check auth success, processs definition online ProcessDefinition processDefinition1 = getProcessDefinition(); processDefinition1.setResourceIds("1,2"); - Mockito.when(processDefinitionMapper.selectById(46)).thenReturn(processDefinition1); - Mockito.when(processService.getUserById(1)).thenReturn(loginUser); Map onlineWithResourceRes = processDefinitionService.releaseProcessDefinition( - loginUser, "project_test1", 46, ReleaseState.ONLINE); + loginUser, projectCode, 46, ReleaseState.ONLINE); Assert.assertEquals(Status.SUCCESS, onlineWithResourceRes.get(Constants.STATUS)); // release error code Map failRes = processDefinitionService.releaseProcessDefinition( - loginUser, "project_test1", 46, ReleaseState.getEnum(2)); + loginUser, projectCode, 46, ReleaseState.getEnum(2)); Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, failRes.get(Constants.STATUS)); } @Test public void testVerifyProcessDefinitionName() { - String projectName = "project_test1"; - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); + long projectCode = 1L; + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); - Project project = getProject(projectName); + Project project = getProject(projectCode); User loginUser = new User(); loginUser.setId(-1); loginUser.setUserType(UserType.GENERAL_USER); //project check auth fail Map result = new HashMap<>(); - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map map = processDefinitionService.verifyProcessDefinitionName(loginUser, - "project_test1", "test_pdf"); + projectCode, "test_pdf"); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); //project check auth success, process not exist - putMsg(result, Status.SUCCESS, projectName); - Mockito.when(processDefinitionMapper.verifyByDefineName(project.getCode(), "test_pdf")).thenReturn(null); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(processDefineMapper.verifyByDefineName(project.getCode(), "test_pdf")).thenReturn(null); Map processNotExistRes = processDefinitionService.verifyProcessDefinitionName(loginUser, - "project_test1", "test_pdf"); + projectCode, "test_pdf"); Assert.assertEquals(Status.SUCCESS, processNotExistRes.get(Constants.STATUS)); //process exist - Mockito.when(processDefinitionMapper.verifyByDefineName(project.getCode(), "test_pdf")).thenReturn(getProcessDefinition()); + Mockito.when(processDefineMapper.verifyByDefineName(project.getCode(), "test_pdf")).thenReturn(getProcessDefinition()); Map processExistRes = processDefinitionService.verifyProcessDefinitionName(loginUser, - "project_test1", "test_pdf"); + projectCode, "test_pdf"); Assert.assertEquals(Status.PROCESS_DEFINITION_NAME_EXIST, processExistRes.get(Constants.STATUS)); } @Test public void testCheckProcessNodeList() { - - Map dataNotValidRes = processDefinitionService.checkProcessNodeList(null, ""); + Map dataNotValidRes = processDefinitionService.checkProcessNodeList(null); Assert.assertEquals(Status.DATA_IS_NOT_VALID, dataNotValidRes.get(Constants.STATUS)); - // task not empty - String processDefinitionJson = SHELL_JSON; - ProcessData processData = JSONUtils.parseObject(processDefinitionJson, ProcessData.class); - Assert.assertNotNull(processData); - Map taskEmptyRes = processDefinitionService.checkProcessNodeList(processData, processDefinitionJson); - Assert.assertEquals(Status.SUCCESS, taskEmptyRes.get(Constants.STATUS)); - - // task empty - processData.setTasks(null); - Map taskNotEmptyRes = processDefinitionService.checkProcessNodeList(processData, processDefinitionJson); - Assert.assertEquals(Status.PROCESS_DAG_IS_EMPTY, taskNotEmptyRes.get(Constants.STATUS)); - - // task cycle - String processDefinitionJsonCycle = CYCLE_SHELL_JSON; - ProcessData processDataCycle = JSONUtils.parseObject(processDefinitionJsonCycle, ProcessData.class); - Map taskCycleRes = processDefinitionService.checkProcessNodeList(processDataCycle, processDefinitionJsonCycle); - Assert.assertEquals(Status.PROCESS_NODE_HAS_CYCLE, taskCycleRes.get(Constants.STATUS)); - - //json abnormal - String abnormalJson = processDefinitionJson.replaceAll(TaskType.SHELL.getDesc(), ""); - processData = JSONUtils.parseObject(abnormalJson, ProcessData.class); - Map abnormalTaskRes = processDefinitionService.checkProcessNodeList(processData, abnormalJson); - Assert.assertEquals(Status.PROCESS_NODE_S_PARAMETER_INVALID, abnormalTaskRes.get(Constants.STATUS)); + Map taskEmptyRes = processDefinitionService.checkProcessNodeList(taskRelationJson); + Assert.assertEquals(Status.PROCESS_DAG_IS_EMPTY, taskEmptyRes.get(Constants.STATUS)); } @Test - public void testGetTaskNodeListByDefinitionId() { + public void testGetTaskNodeListByDefinitionCode() { + long projectCode = 1L; + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + + Project project = getProject(projectCode); + User loginUser = new User(); + loginUser.setId(-1); + loginUser.setUserType(UserType.GENERAL_USER); + + //project check auth fail + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); //process definition not exist - Mockito.when(processDefinitionMapper.queryByCode(46L)).thenReturn(null); - Map processDefinitionNullRes = processDefinitionService.getTaskNodeListByDefinitionCode(46L); + Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(null); + Map processDefinitionNullRes = processDefinitionService.getTaskNodeListByDefinitionCode(loginUser, projectCode, 46L); Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionNullRes.get(Constants.STATUS)); - //process data null - ProcessDefinition processDefinition = getProcessDefinition(); - Mockito.when(processDefinitionMapper.queryByCode(46L)).thenReturn(processDefinition); - Map successRes = processDefinitionService.getTaskNodeListByDefinitionCode(46L); - Assert.assertEquals(Status.DATA_IS_NOT_VALID, successRes.get(Constants.STATUS)); - //success - Mockito.when(processService.genProcessData(Mockito.any())).thenReturn(new ProcessData()); - Mockito.when(processDefinitionMapper.queryByCode(46L)).thenReturn(processDefinition); - Map dataNotValidRes = processDefinitionService.getTaskNodeListByDefinitionCode(46L); + ProcessDefinition processDefinition = getProcessDefinition(); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(processService.genDagData(Mockito.any())).thenReturn(new DagData(processDefinition, null, null)); + Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); + Map dataNotValidRes = processDefinitionService.getTaskNodeListByDefinitionCode(loginUser, projectCode, 46L); Assert.assertEquals(Status.SUCCESS, dataNotValidRes.get(Constants.STATUS)); } @Test - public void testGetTaskNodeListByDefinitionIdList() { + public void testGetTaskNodeListByDefinitionCodes() { + long projectCode = 1L; + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + + Project project = getProject(projectCode); + User loginUser = new User(); + loginUser.setId(-1); + loginUser.setUserType(UserType.GENERAL_USER); + + //project check auth fail + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); //process definition not exist - String defineCodeList = "46"; - Long[] codeArray = {46L}; - List codeList = Arrays.asList(codeArray); - Mockito.when(processDefinitionMapper.queryByCodes(codeList)).thenReturn(null); - Map processNotExistRes = processDefinitionService.getTaskNodeListByDefinitionCodeList(defineCodeList); + String defineCodes = "46"; + Set defineCodeSet = Lists.newArrayList(defineCodes.split(Constants.COMMA)).stream().map(Long::parseLong).collect(Collectors.toSet()); + Mockito.when(processDefineMapper.queryByCodes(defineCodeSet)).thenReturn(null); + Map processNotExistRes = processDefinitionService.getNodeListMapByDefinitionCodes(loginUser, projectCode, defineCodes); Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, processNotExistRes.get(Constants.STATUS)); - //process definition exist + putMsg(result, Status.SUCCESS, projectCode); ProcessDefinition processDefinition = getProcessDefinition(); List processDefinitionList = new ArrayList<>(); processDefinitionList.add(processDefinition); - Mockito.when(processDefinitionMapper.queryByCodes(codeList)).thenReturn(processDefinitionList); - ProcessData processData = getProcessData(); - Mockito.when(processService.genProcessData(processDefinition)).thenReturn(processData); + Mockito.when(processDefineMapper.queryByCodes(defineCodeSet)).thenReturn(processDefinitionList); + Mockito.when(processService.genDagData(Mockito.any())).thenReturn(new DagData(processDefinition, null, null)); - Map successRes = processDefinitionService.getTaskNodeListByDefinitionCodeList(defineCodeList); - Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); - } - - private ProcessData getProcessData() { - ProcessData processData = new ProcessData(); - List taskNodeList = new ArrayList<>(); - processData.setTasks(taskNodeList); - List properties = new ArrayList<>(); - processData.setGlobalParams(properties); - processData.setTenantId(10); - processData.setTimeout(100); - return processData; - } - - @Test - public void testQueryProcessDefinitionAllByProjectId() { - int projectId = 1; - Long projectCode = 2L; - Project project = new Project(); - project.setId(projectId); - project.setCode(projectCode); - Mockito.when(projectMapper.selectById(projectId)).thenReturn(project); - - ProcessDefinition processDefinition = getProcessDefinition(); - List processDefinitionList = new ArrayList<>(); - processDefinitionList.add(processDefinition); - Project test = getProject("test"); - Mockito.when(projectMapper.selectById(projectId)).thenReturn(test); - Mockito.when(processDefinitionMapper.queryAllDefinitionList(test.getCode())).thenReturn(processDefinitionList); - Map successRes = processDefinitionService.queryProcessDefinitionAllByProjectId(projectId); + Map successRes = processDefinitionService.getNodeListMapByDefinitionCodes(loginUser, projectCode, defineCodes); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); } @Test - public void testViewTree() throws Exception { + public void testQueryAllProcessDefinitionByProjectCode() { + User loginUser = new User(); + loginUser.setId(1); + loginUser.setUserType(UserType.GENERAL_USER); + Map result = new HashMap<>(); + long projectCode = 2L; + Project project = getProject(projectCode); + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + ProcessDefinition processDefinition = getProcessDefinition(); + List processDefinitionList = new ArrayList<>(); + processDefinitionList.add(processDefinition); + Mockito.when(processDefineMapper.queryAllDefinitionList(projectCode)).thenReturn(processDefinitionList); + Map successRes = processDefinitionService.queryAllProcessDefinitionByProjectCode(loginUser, projectCode); + Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); + } + + @Test + public void testViewTree() { //process definition not exist ProcessDefinition processDefinition = getProcessDefinition(); - processDefinition.setProcessDefinitionJson(SHELL_JSON); - Mockito.when(processDefinitionMapper.selectById(46)).thenReturn(null); Map processDefinitionNullRes = processDefinitionService.viewTree(46, 10); Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionNullRes.get(Constants.STATUS)); - List processInstanceList = new ArrayList<>(); - ProcessInstance processInstance = new ProcessInstance(); - processInstance.setId(1); - processInstance.setName("test_instance"); - processInstance.setState(ExecutionStatus.RUNNING_EXECUTION); - processInstance.setHost("192.168.xx.xx"); - processInstance.setStartTime(new Date()); - processInstance.setEndTime(new Date()); - processInstanceList.add(processInstance); - - TaskInstance taskInstance = new TaskInstance(); - taskInstance.setStartTime(new Date()); - taskInstance.setEndTime(new Date()); - taskInstance.setTaskType(TaskType.SHELL.getDesc()); - taskInstance.setId(1); - taskInstance.setName("test_task_instance"); - taskInstance.setState(ExecutionStatus.RUNNING_EXECUTION); - taskInstance.setHost("192.168.xx.xx"); - //task instance not exist - Mockito.when(processDefinitionMapper.selectById(46)).thenReturn(processDefinition); + Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); Mockito.when(processService.genDagGraph(processDefinition)).thenReturn(new DAG<>()); Map taskNullRes = processDefinitionService.viewTree(46, 10); Assert.assertEquals(Status.SUCCESS, taskNullRes.get(Constants.STATUS)); @@ -809,142 +587,15 @@ public class ProcessDefinitionServiceTest { //task instance exist Map taskNotNuLLRes = processDefinitionService.viewTree(46, 10); Assert.assertEquals(Status.SUCCESS, taskNotNuLLRes.get(Constants.STATUS)); - } @Test - public void testSubProcessViewTree() throws Exception { - + public void testSubProcessViewTree() { ProcessDefinition processDefinition = getProcessDefinition(); - processDefinition.setProcessDefinitionJson(SHELL_JSON); - List processInstanceList = new ArrayList<>(); - ProcessInstance processInstance = new ProcessInstance(); - processInstance.setId(1); - processInstance.setName("test_instance"); - processInstance.setState(ExecutionStatus.RUNNING_EXECUTION); - processInstance.setHost("192.168.xx.xx"); - processInstance.setStartTime(new Date()); - processInstance.setEndTime(new Date()); - processInstanceList.add(processInstance); - - TaskInstance taskInstance = new TaskInstance(); - taskInstance.setStartTime(new Date()); - taskInstance.setEndTime(new Date()); - taskInstance.setTaskType(TaskType.SUB_PROCESS.getDesc()); - taskInstance.setId(1); - taskInstance.setName("test_task_instance"); - taskInstance.setState(ExecutionStatus.RUNNING_EXECUTION); - taskInstance.setHost("192.168.xx.xx"); - taskInstance.setTaskParams("\"processDefinitionId\": \"222\",\n"); - Mockito.when(processDefinitionMapper.selectById(46)).thenReturn(processDefinition); + Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); Mockito.when(processService.genDagGraph(processDefinition)).thenReturn(new DAG<>()); Map taskNotNuLLRes = processDefinitionService.viewTree(46, 10); Assert.assertEquals(Status.SUCCESS, taskNotNuLLRes.get(Constants.STATUS)); - - } - - @Test - public void testImportProcessDefinitionById() throws IOException { - - String processJson = "[\n" - + " {\n" - + " \"projectName\": \"testProject\",\n" - + " \"processDefinitionName\": \"shell-4\",\n" - + " \"processDefinitionJson\": \"{\\\"tenantId\\\":1" - + ",\\\"globalParams\\\":[],\\\"tasks\\\":[{\\\"workerGroupId\\\":\\\"3\\\",\\\"description\\\"" - + ":\\\"\\\",\\\"runFlag\\\":\\\"NORMAL\\\",\\\"type\\\":\\\"SHELL\\\",\\\"params\\\":{\\\"rawScript\\\"" - + ":\\\"#!/bin/bash\\\\necho \\\\\\\"shell-4\\\\\\\"\\\",\\\"localParams\\\":[],\\\"resourceList\\\":[]}" - + ",\\\"timeout\\\":{\\\"enable\\\":false,\\\"strategy\\\":\\\"\\\"},\\\"maxRetryTimes\\\":\\\"0\\\"" - + ",\\\"taskInstancePriority\\\":\\\"MEDIUM\\\",\\\"name\\\":\\\"shell-4\\\",\\\"dependence\\\":{}" - + ",\\\"retryInterval\\\":\\\"1\\\",\\\"preTasks\\\":[],\\\"id\\\":\\\"tasks-84090\\\"}" - + ",{\\\"taskInstancePriority\\\":\\\"MEDIUM\\\",\\\"name\\\":\\\"shell-5\\\",\\\"workerGroupId\\\"" - + ":\\\"3\\\",\\\"description\\\":\\\"\\\",\\\"dependence\\\":{},\\\"preTasks\\\":[\\\"shell-4\\\"]" - + ",\\\"id\\\":\\\"tasks-87364\\\",\\\"runFlag\\\":\\\"NORMAL\\\",\\\"type\\\":\\\"SUB_PROCESS\\\"" - + ",\\\"params\\\":{\\\"processDefinitionId\\\":46},\\\"timeout\\\":{\\\"enable\\\":false" - + ",\\\"strategy\\\":\\\"\\\"}}],\\\"timeout\\\":0}\",\n" - + " \"processDefinitionDescription\": \"\",\n" - + " \"processDefinitionLocations\": \"{\\\"tasks-84090\\\":{\\\"name\\\":\\\"shell-4\\\"" - + ",\\\"targetarr\\\":\\\"\\\",\\\"x\\\":128,\\\"y\\\":114},\\\"tasks-87364\\\":{\\\"name\\\"" - + ":\\\"shell-5\\\",\\\"targetarr\\\":\\\"tasks-84090\\\",\\\"x\\\":266,\\\"y\\\":115}}\",\n" - + " \"processDefinitionConnects\": \"[{\\\"endPointSourceId\\\":\\\"tasks-84090\\\"" - + ",\\\"endPointTargetId\\\":\\\"tasks-87364\\\"}]\"\n" - + " }\n" - + "]"; - - String subProcessJson = "{\n" - + " \"globalParams\": [\n" - + " \n" - + " ],\n" - + " \"tasks\": [\n" - + " {\n" - + " \"type\": \"SHELL\",\n" - + " \"id\": \"tasks-52423\",\n" - + " \"name\": \"shell-5\",\n" - + " \"params\": {\n" - + " \"resourceList\": [\n" - + " \n" - + " ],\n" - + " \"localParams\": [\n" - + " \n" - + " ],\n" - + " \"rawScript\": \"echo \\\"shell-5\\\"\"\n" - + " },\n" - + " \"description\": \"\",\n" - + " \"runFlag\": \"NORMAL\",\n" - + " \"dependence\": {\n" - + " \n" - + " },\n" - + " \"maxRetryTimes\": \"0\",\n" - + " \"retryInterval\": \"1\",\n" - + " \"timeout\": {\n" - + " \"strategy\": \"\",\n" - + " \"interval\": null,\n" - + " \"enable\": false\n" - + " },\n" - + " \"taskInstancePriority\": \"MEDIUM\",\n" - + " \"workerGroupId\": \"3\",\n" - + " \"preTasks\": [\n" - + " \n" - + " ]\n" - + " }\n" - + " ],\n" - + " \"tenantId\": 1,\n" - + " \"timeout\": 0\n" - + "}"; - - FileUtils.writeStringToFile(new File("/tmp/task.json"), processJson); - - File file = new File("/tmp/task.json"); - - FileInputStream fileInputStream = new FileInputStream("/tmp/task.json"); - - MultipartFile multipartFile = new MockMultipartFile(file.getName(), file.getName(), - ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream); - - User loginUser = new User(); - loginUser.setId(1); - loginUser.setUserType(UserType.ADMIN_USER); - - String currentProjectName = "testProject"; - Map result = new HashMap<>(); - putMsg(result, Status.SUCCESS, currentProjectName); - - ProcessDefinition shellDefinition2 = new ProcessDefinition(); - shellDefinition2.setId(46); - shellDefinition2.setName("shell-5"); - shellDefinition2.setProjectId(2); - shellDefinition2.setProcessDefinitionJson(subProcessJson); - - Mockito.when(projectMapper.queryByName(currentProjectName)).thenReturn(getProject(currentProjectName)); - Mockito.when(projectService.checkProjectAndAuth(loginUser, getProject(currentProjectName), currentProjectName)).thenReturn(result); - - Map importProcessResult = processDefinitionService.importProcessDefinition(loginUser, multipartFile, currentProjectName); - - Assert.assertEquals(Status.SUCCESS, importProcessResult.get(Constants.STATUS)); - - boolean delete = file.delete(); - - Assert.assertTrue(delete); } @Test @@ -956,168 +607,47 @@ public class ProcessDefinitionServiceTest { Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); - String projectName = "project_test1"; - Project project = getProject(projectName); + long projectCode = 1L; + Project project = getProject(projectCode); + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); - ProcessDefinition processDefinition = getProcessDefinition(); - - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - Mockito.when(processService.findProcessDefineById(1)).thenReturn(processDefinition); - - String sqlDependentJson = "{\n" - + " \"globalParams\": [\n" - + " \n" - + " ],\n" - + " \"tasks\": [\n" - + " {\n" - + " \"type\": \"SQL\",\n" - + " \"id\": \"tasks-27297\",\n" - + " \"name\": \"sql\",\n" - + " \"params\": {\n" - + " \"type\": \"MYSQL\",\n" - + " \"datasource\": 1,\n" - + " \"sql\": \"select * from test\",\n" - + " \"udfs\": \"\",\n" - + " \"sqlType\": \"1\",\n" - + " \"title\": \"\",\n" - + " \"receivers\": \"\",\n" - + " \"receiversCc\": \"\",\n" - + " \"showType\": \"TABLE\",\n" - + " \"localParams\": [\n" - + " \n" - + " ],\n" - + " \"connParams\": \"\",\n" - + " \"preStatements\": [\n" - + " \n" - + " ],\n" - + " \"postStatements\": [\n" - + " \n" - + " ]\n" - + " },\n" - + " \"description\": \"\",\n" - + " \"runFlag\": \"NORMAL\",\n" - + " \"dependence\": {\n" - + " \n" - + " },\n" - + " \"maxRetryTimes\": \"0\",\n" - + " \"retryInterval\": \"1\",\n" - + " \"timeout\": {\n" - + " \"strategy\": \"\",\n" - + " \"enable\": false\n" - + " },\n" - + " \"taskInstancePriority\": \"MEDIUM\",\n" - + " \"workerGroupId\": -1,\n" - + " \"preTasks\": [\n" - + " \"dependent\"\n" - + " ]\n" - + " },\n" - + " {\n" - + " \"type\": \"DEPENDENT\",\n" - + " \"id\": \"tasks-33787\",\n" - + " \"name\": \"dependent\",\n" - + " \"params\": {\n" - + " \n" - + " },\n" - + " \"description\": \"\",\n" - + " \"runFlag\": \"NORMAL\",\n" - + " \"dependence\": {\n" - + " \"relation\": \"AND\",\n" - + " \"dependTaskList\": [\n" - + " {\n" - + " \"relation\": \"AND\",\n" - + " \"dependItemList\": [\n" - + " {\n" - + " \"projectId\": 2,\n" - + " \"definitionId\": 46,\n" - + " \"depTasks\": \"ALL\",\n" - + " \"cycle\": \"day\",\n" - + " \"dateValue\": \"today\"\n" - + " }\n" - + " ]\n" - + " }\n" - + " ]\n" - + " },\n" - + " \"maxRetryTimes\": \"0\",\n" - + " \"retryInterval\": \"1\",\n" - + " \"timeout\": {\n" - + " \"strategy\": \"\",\n" - + " \"enable\": false\n" - + " },\n" - + " \"taskInstancePriority\": \"MEDIUM\",\n" - + " \"workerGroupId\": -1,\n" - + " \"preTasks\": [\n" - + " \n" - + " ]\n" - + " }\n" - + " ],\n" - + " \"tenantId\": 1,\n" - + " \"timeout\": 0\n" - + "}"; - - Map updateResult = processDefinitionService.updateProcessDefinition(loginUser, projectName, 1, "test", - sqlDependentJson, "", "", ""); - - Assert.assertEquals(Status.UPDATE_PROCESS_DEFINITION_ERROR, updateResult.get(Constants.STATUS)); + Map updateResult = processDefinitionService.updateProcessDefinition(loginUser, projectCode, "test", 1, + "", "", "", 0, "root", null, null); + Assert.assertEquals(Status.DATA_IS_NOT_VALID, updateResult.get(Constants.STATUS)); } @Test - public void testBatchExportProcessDefinitionByIds() throws IOException { - processDefinitionService.batchExportProcessDefinitionByIds( - null, null, null, null); + public void testBatchExportProcessDefinitionByCodes() { + processDefinitionService.batchExportProcessDefinitionByCodes(null, 1L, null, null); - String processDefinitionJson = "{\"globalParams\":[],\"tasks\":[{\"conditionResult\":" - + "{\"failedNode\":[\"\"],\"successNode\":[\"\"]},\"delayTime\":\"0\",\"dependence\":{}" - + ",\"description\":\"\",\"id\":\"tasks-3011\",\"maxRetryTimes\":\"0\",\"name\":\"tsssss\"" - + ",\"params\":{\"localParams\":[],\"rawScript\":\"echo \\\"123123\\\"\",\"resourceList\":[]}" - + ",\"preTasks\":[],\"retryInterval\":\"1\",\"runFlag\":\"NORMAL\",\"taskInstancePriority\":\"MEDIUM\"" - + ",\"timeout\":{\"enable\":false,\"interval\":null,\"strategy\":\"\"},\"type\":\"SHELL\"" - + ",\"waitStartTimeout\":{},\"workerGroup\":\"default\"}],\"tenantId\":4,\"timeout\":0}"; User loginUser = new User(); loginUser.setId(1); loginUser.setUserType(UserType.ADMIN_USER); - String projectName = "project_test1"; - Project project = getProject(projectName); + long projectCode = 1L; + Project project = getProject(projectCode); Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT); - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); - processDefinitionService.batchExportProcessDefinitionByIds( - loginUser, projectName, "1", null); + processDefinitionService.batchExportProcessDefinitionByCodes( + loginUser, projectCode, "1", null); ProcessDefinition processDefinition = new ProcessDefinition(); processDefinition.setId(1); - processDefinition.setProcessDefinitionJson(processDefinitionJson); Map checkResult = new HashMap<>(); checkResult.put(Constants.STATUS, Status.SUCCESS); - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(checkResult); - Mockito.when(processDefinitionMapper.queryByDefineId(1)).thenReturn(processDefinition); + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(checkResult); HttpServletResponse response = mock(HttpServletResponse.class); - ProcessData processData = JSONUtils.parseObject(processDefinitionJson, ProcessData.class); - Mockito.when(processService.genProcessData(processDefinition)).thenReturn(processData); - - ServletOutputStream outputStream = mock(ServletOutputStream.class); - when(response.getOutputStream()).thenReturn(outputStream); - processDefinitionService.batchExportProcessDefinitionByIds( - loginUser, projectName, "1", response); - Assert.assertNotNull(processDefinitionService.exportProcessMetaData(processDefinition)); - } - - /** - * get mock datasource - * - * @return DataSource - */ - private DataSource getDataSource() { - DataSource dataSource = new DataSource(); - dataSource.setId(2); - dataSource.setName("test"); - return dataSource; + DagData dagData = new DagData(getProcessDefinition(), null, null); + Mockito.when(processService.genDagData(Mockito.any())).thenReturn(dagData); + processDefinitionService.batchExportProcessDefinitionByCodes(loginUser, projectCode, "1", response); + Assert.assertNotNull(processDefinitionService.exportProcessDagData(processDefinition)); } /** @@ -1128,42 +658,37 @@ public class ProcessDefinitionServiceTest { private ProcessDefinition getProcessDefinition() { ProcessDefinition processDefinition = new ProcessDefinition(); processDefinition.setId(46); + processDefinition.setProjectCode(1L); processDefinition.setName("test_pdf"); - processDefinition.setProjectId(2); processDefinition.setTenantId(1); processDefinition.setDescription(""); - processDefinition.setCode(9999L); - + processDefinition.setCode(46L); return processDefinition; } /** * get mock Project * - * @param projectName projectName + * @param projectCode projectCode * @return Project */ - private Project getProject(String projectName) { + private Project getProject(long projectCode) { Project project = new Project(); - project.setCode(1L); + project.setCode(projectCode); project.setId(1); - project.setName(projectName); + project.setName("test"); project.setUserId(1); return project; } - /** - * get mock Project - * - * @param projectId projectId - * @return Project - */ - private Project getProjectById(int projectId) { - Project project = new Project(); - project.setId(projectId); - project.setName("project_test2"); - project.setUserId(1); - return project; + private List getProcessTaskRelation(long projectCode) { + List processTaskRelations = new ArrayList<>(); + ProcessTaskRelation processTaskRelation = new ProcessTaskRelation(); + processTaskRelation.setProjectCode(projectCode); + processTaskRelation.setProcessDefinitionCode(46L); + processTaskRelation.setProcessDefinitionVersion(1); + processTaskRelations.add(processTaskRelation); + return processTaskRelations; } /** @@ -1175,7 +700,7 @@ public class ProcessDefinitionServiceTest { Date date = new Date(); Schedule schedule = new Schedule(); schedule.setId(46); - schedule.setProcessDefinitionId(1); + schedule.setProcessDefinitionCode(1); schedule.setStartTime(date); schedule.setEndTime(date); schedule.setCrontab("0 0 5 * * ? *"); @@ -1189,32 +714,6 @@ public class ProcessDefinitionServiceTest { return schedule; } - /** - * get mock processMeta - * - * @return processMeta - */ - private ProcessMeta getProcessMeta() { - ProcessMeta processMeta = new ProcessMeta(); - Schedule schedule = getSchedule(); - processMeta.setScheduleCrontab(schedule.getCrontab()); - processMeta.setScheduleStartTime(DateUtils.dateToString(schedule.getStartTime())); - processMeta.setScheduleEndTime(DateUtils.dateToString(schedule.getEndTime())); - processMeta.setScheduleWarningType(String.valueOf(schedule.getWarningType())); - processMeta.setScheduleWarningGroupId(schedule.getWarningGroupId()); - processMeta.setScheduleFailureStrategy(String.valueOf(schedule.getFailureStrategy())); - processMeta.setScheduleReleaseState(String.valueOf(schedule.getReleaseState())); - processMeta.setScheduleProcessInstancePriority(String.valueOf(schedule.getProcessInstancePriority())); - processMeta.setScheduleWorkerGroupName("workgroup1"); - return processMeta; - } - - private List getSchedulerList() { - List scheduleList = new ArrayList<>(); - scheduleList.add(getSchedule()); - return scheduleList; - } - private void putMsg(Map result, Status status, Object... statusParams) { result.put(Constants.STATUS, status); if (statusParams != null && statusParams.length > 0) { @@ -1223,125 +722,4 @@ public class ProcessDefinitionServiceTest { result.put(Constants.MSG, status.getMsg()); } } - - @Test - public void testImportProcessSchedule() { - User loginUser = new User(); - loginUser.setId(1); - loginUser.setUserType(UserType.ADMIN_USER); - Integer processDefinitionId = 111; - String processDefinitionName = "testProcessDefinition"; - String projectName = "project_test1"; - Map result = new HashMap<>(); - putMsg(result, Status.PROJECT_NOT_FOUNT); - ProcessMeta processMeta = new ProcessMeta(); - Assert.assertEquals(0, processDefinitionService.importProcessSchedule(loginUser, projectName, processMeta, processDefinitionName, processDefinitionId)); - } - - @Test - public void testAddExportTaskNodeSpecialParam() { - String sqlDependentJson = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SQL\",\"id\":\"tasks-27297\",\"name\":" - + "\"sql\",\"params\":{\"type\":\"MYSQL\",\"datasource\":1,\"sql\":\"select * from test\",\"udfs\":\"\"" - + ",\"sqlType\":\"1\",\"title\":\"\",\"receivers\":\"\",\"receiversCc\":\"\",\"showType\":\"TABLE\"," - + "\"localParams\":[],\"connParams\":\"\",\"preStatements\":[],\"postStatements\":[]},\"description\":" - + "\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\"," - + "\"timeout\":{\"strategy\":\"\",\"enable\":false},\"taskInstancePriority\":\"MEDIUM\"," - + "\"workerGroupId\":-1,\"preTasks\":[\"dependent\"]},{\"type\":\"DEPENDENT\",\"id\":\"tasks-33787\"," - + "\"name\":\"dependent\",\"params\":{},\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":" - + "{\"relation\":\"AND\",\"dependTaskList\":[{\"relation\":\"AND\",\"dependItemList\":[{\"projectId\":" - + "2,\"definitionId\":46,\"depTasks\":\"ALL\",\"cycle\":\"day\",\"dateValue\":\"today\"}]}]}," - + "\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"enable\":false}," - + "\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":1," - + "\"timeout\":0}"; - - ProcessData processData = JSONUtils.parseObject(sqlDependentJson, ProcessData.class); - - DataSource dataSource = new DataSource(); - dataSource.setName("testDataSource"); - when(dataSourceMapper.selectById(1)).thenReturn(dataSource); - - ProcessDefinition processDefinition = new ProcessDefinition(); - processDefinition.setProjectName("testProjectName"); - processDefinition.setName("testDefinitionName"); - when(processDefinitionMapper.queryByDefineId(46)).thenReturn(processDefinition); - - try { - Class clazz = ProcessDefinitionServiceImpl.class; - Method method = clazz.getDeclaredMethod("addExportTaskNodeSpecialParam", ProcessData.class); - method.setAccessible(true); - method.invoke(processDefinitionService, processData); - } catch (Exception e) { - e.printStackTrace(); - Assert.fail(e.toString()); - } - - List taskNodeList = processData.getTasks(); - ObjectNode sqlParameters = JSONUtils.parseObject(taskNodeList.get(0).getParams()); - Assert.assertEquals("testDataSource", sqlParameters.get(Constants.TASK_PARAMS_DATASOURCE_NAME).asText()); - - ObjectNode dependentParameters = JSONUtils.parseObject(taskNodeList.get(1).getDependence()); - ArrayNode dependTaskList = (ArrayNode)dependentParameters.get(Constants.TASK_DEPENDENCE_DEPEND_TASK_LIST); - JsonNode dependentTaskModel = dependTaskList.path(0); - ArrayNode dependItemList = (ArrayNode)dependentTaskModel.get(Constants.TASK_DEPENDENCE_DEPEND_ITEM_LIST); - ObjectNode dependentItem = (ObjectNode)dependItemList.path(0); - Assert.assertEquals("testProjectName", dependentItem.get(Constants.TASK_DEPENDENCE_PROJECT_NAME).asText()); - Assert.assertEquals("testDefinitionName", dependentItem.get(Constants.TASK_DEPENDENCE_DEFINITION_NAME).asText()); - } - - @Test - public void testAddImportTaskNodeSpecialParam() { - String definitionJson = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SQL\",\"id\":\"tasks-27297\",\"name\":\"sql\"," - + "\"params\":{\"type\":\"MYSQL\",\"datasourceName\":\"testDataSource\",\"sql\":\"select * from test\"," - + "\"udfs\":\"\",\"sqlType\":\"1\",\"title\":\"\",\"receivers\":\"\",\"receiversCc\":\"\",\"showType\":" - + "\"TABLE\",\"localParams\":[],\"connParams\":\"\",\"preStatements\":[],\"postStatements\":[]}," - + "\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\"," - + "\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"enable\":false},\"taskInstancePriority\":" - + "\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[\"dependent\"]},{\"type\":\"DEPENDENT\",\"id\":" - + "\"tasks-33787\",\"name\":\"dependent\",\"params\":{},\"description\":\"\",\"runFlag\":\"NORMAL\"," - + "\"dependence\":{\"relation\":\"AND\",\"dependTaskList\":[{\"relation\":\"AND\",\"dependItemList\":" - + "[{\"projectName\":\"testProjectName\",\"definitionName\":\"testDefinitionName\",\"depTasks\":\"ALL\"" - + ",\"cycle\":\"day\",\"dateValue\":\"today\"}]}]},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"" - + "timeout\":{\"strategy\":\"\",\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\"" - + ":-1,\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}"; - - ObjectNode jsonObject = JSONUtils.parseObject(definitionJson); - ArrayNode jsonArray = (ArrayNode) jsonObject.get("tasks"); - - List dataSources = new ArrayList<>(); - DataSource dataSource = new DataSource(); - dataSource.setId(1); - dataSources.add(dataSource); - when(dataSourceMapper.queryDataSourceByName("testDataSource")).thenReturn(dataSources); - - Project project = new Project(); - project.setId(1); - project.setCode(1L); - when(projectMapper.queryByName("testProjectName")).thenReturn(project); - - ProcessDefinition processDefinition = new ProcessDefinition(); - processDefinition.setId(1); - when(processDefinitionMapper.queryByDefineName(1L, "testDefinitionName")).thenReturn(processDefinition); - - try { - Class clazz = ProcessDefinitionServiceImpl.class; - Method method = clazz.getDeclaredMethod("addImportTaskNodeSpecialParam", ArrayNode.class); - method.setAccessible(true); - method.invoke(processDefinitionService, jsonArray); - } catch (Exception e) { - e.printStackTrace(); - Assert.fail(e.toString()); - } - - ObjectNode sqlParameters = (ObjectNode)jsonArray.path(0).path(Constants.TASK_PARAMS); - Assert.assertEquals(1, sqlParameters.get(Constants.TASK_PARAMS_DATASOURCE).asInt()); - - ObjectNode dependentParameters = (ObjectNode)jsonArray.path(1).path(Constants.DEPENDENCE); - ArrayNode dependTaskList = (ArrayNode)dependentParameters.get(Constants.TASK_DEPENDENCE_DEPEND_TASK_LIST); - JsonNode dependentTaskModel = dependTaskList.path(0); - ArrayNode dependItemList = (ArrayNode)dependentTaskModel.get(Constants.TASK_DEPENDENCE_DEPEND_ITEM_LIST); - ObjectNode dependentItem = (ObjectNode)dependItemList.path(0); - Assert.assertEquals(1, dependentItem.get(Constants.TASK_DEPENDENCE_PROJECT_ID).asInt()); - Assert.assertEquals(1, dependentItem.get(Constants.TASK_DEPENDENCE_DEFINITION_ID).asInt()); - } - } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java index 4078277f89..630769344b 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java @@ -49,6 +49,7 @@ import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; +import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.service.process.ProcessService; import java.io.IOException; @@ -108,26 +109,36 @@ public class ProcessInstanceServiceTest { @Mock UsersService usersService; - private String shellJson = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-9527\",\"name\":\"shell-1\"," - + "\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"#!/bin/bash\\necho \\\"shell-1\\\"\"}," - + "\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\"," - + "\"timeout\":{\"strategy\":\"\",\"interval\":1,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\"," - + "\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}"; + @Mock + TenantMapper tenantMapper; + + private String shellJson = "[{\"name\":\"\",\"preTaskCode\":0,\"preTaskVersion\":0,\"postTaskCode\":123456789," + + "\"postTaskVersion\":1,\"conditionType\":0,\"conditionParams\":\"{}\"},{\"name\":\"\",\"preTaskCode\":123456789," + + "\"preTaskVersion\":1,\"postTaskCode\":123451234,\"postTaskVersion\":1,\"conditionType\":0,\"conditionParams\":\"{}\"}]"; + + private String taskJson = "[{\"name\":\"shell1\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":{\"resourceList\":[]," + + "\"localParams\":[],\"rawScript\":\"echo 1\",\"conditionResult\":{\"successNode\":[\"\"],\"failedNode\":[\"\"]},\"dependence\":{}}," + + "\"flag\":\"NORMAL\",\"taskPriority\":\"MEDIUM\",\"workerGroup\":\"default\",\"failRetryTimes\":\"0\",\"failRetryInterval\":\"1\"," + + "\"timeoutFlag\":\"CLOSE\",\"timeoutNotifyStrategy\":\"\",\"timeout\":null,\"delayTime\":\"0\"},{\"name\":\"shell2\",\"description\":\"\"," + + "\"taskType\":\"SHELL\",\"taskParams\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo 2\",\"conditionResult\":{\"successNode\"" + + ":[\"\"],\"failedNode\":[\"\"]},\"dependence\":{}},\"flag\":\"NORMAL\",\"taskPriority\":\"MEDIUM\",\"workerGroup\":\"default\"," + + "\"failRetryTimes\":\"0\",\"failRetryInterval\":\"1\",\"timeoutFlag\":\"CLOSE\",\"timeoutNotifyStrategy\":\"\",\"timeout\":null,\"delayTime\":\"0\"}]"; @Test public void testQueryProcessInstanceList() { - String projectName = "project_test1"; + long projectCode = 1L; User loginUser = getAdminUser(); + Project project = getProject(projectCode); Map result = new HashMap<>(); - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); //project auth fail - when(projectMapper.queryByName(projectName)).thenReturn(null); - when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result); - Result proejctAuthFailRes = processInstanceService.queryProcessInstanceList(loginUser, projectName, 46, "2020-01-01 00:00:00", - "2020-01-02 00:00:00", "", "test_user", ExecutionStatus.SUBMITTED_SUCCESS, - "192.168.xx.xx", 1, 10); - Assert.assertEquals(Status.PROJECT_NOT_FOUNT.getCode(),(int) proejctAuthFailRes.getCode()); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Result proejctAuthFailRes = processInstanceService.queryProcessInstanceList(loginUser, projectCode, 46, "2020-01-01 00:00:00", + "2020-01-02 00:00:00", "", "test_user", ExecutionStatus.SUBMITTED_SUCCESS, + "192.168.xx.xx", 1, 10); + Assert.assertEquals(Status.PROJECT_NOT_FOUNT.getCode(), (int) proejctAuthFailRes.getCode()); Date start = DateUtils.getScheduleDate("2020-01-01 00:00:00"); Date end = DateUtils.getScheduleDate("2020-01-02 00:00:00"); @@ -138,67 +149,69 @@ public class ProcessInstanceServiceTest { pageReturn.setRecords(processInstanceList); // data parameter check - putMsg(result, Status.SUCCESS, projectName); - Project project = getProject(projectName); - when(projectMapper.queryByName(projectName)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); + putMsg(result, Status.SUCCESS, projectCode); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(processDefineMapper.selectById(Mockito.anyInt())).thenReturn(getProcessDefinition()); when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class) - , Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), - eq("192.168.xx.xx"), Mockito.any(), Mockito.any())).thenReturn(pageReturn); + , Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + eq("192.168.xx.xx"), Mockito.any(), Mockito.any())).thenReturn(pageReturn); - Result dataParameterRes = processInstanceService.queryProcessInstanceList(loginUser, projectName, 1, "20200101 00:00:00", - "20200102 00:00:00", "", loginUser.getUserName(), ExecutionStatus.SUBMITTED_SUCCESS, - "192.168.xx.xx", 1, 10); - Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getCode(),(int) dataParameterRes.getCode()); + Result dataParameterRes = processInstanceService.queryProcessInstanceList(loginUser, projectCode, 1, "20200101 00:00:00", + "20200102 00:00:00", "", loginUser.getUserName(), ExecutionStatus.SUBMITTED_SUCCESS, + "192.168.xx.xx", 1, 10); + Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getCode(), (int) dataParameterRes.getCode()); //project auth success - putMsg(result, Status.SUCCESS, projectName); + putMsg(result, Status.SUCCESS, projectCode); - when(projectMapper.queryByName(projectName)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser); when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId()); when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1L), eq(""), eq(-1), Mockito.any(), - eq("192.168.xx.xx"), eq(start), eq(end))).thenReturn(pageReturn); + eq("192.168.xx.xx"), eq(start), eq(end))).thenReturn(pageReturn); when(usersService.queryUser(processInstance.getExecutorId())).thenReturn(loginUser); - Result successRes = processInstanceService.queryProcessInstanceList(loginUser, projectName, 1, "2020-01-01 00:00:00", - "2020-01-02 00:00:00", "", loginUser.getUserName(), ExecutionStatus.SUBMITTED_SUCCESS, - "192.168.xx.xx", 1, 10); + + Result successRes = processInstanceService.queryProcessInstanceList(loginUser, projectCode, 1, "2020-01-01 00:00:00", + "2020-01-02 00:00:00", "", loginUser.getUserName(), ExecutionStatus.SUBMITTED_SUCCESS, + "192.168.xx.xx", 1, 10); Assert.assertEquals(Status.SUCCESS.getCode(), (int)successRes.getCode()); // data parameter empty when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1L), eq(""), eq(-1), Mockito.any(), - eq("192.168.xx.xx"), eq(null), eq(null))).thenReturn(pageReturn); - successRes = processInstanceService.queryProcessInstanceList(loginUser, projectName, 1, "", - "", "", loginUser.getUserName(), ExecutionStatus.SUBMITTED_SUCCESS, - "192.168.xx.xx", 1, 10); - Assert.assertEquals(Status.SUCCESS.getCode(), (int)successRes.getCode()); + eq("192.168.xx.xx"), eq(null), eq(null))).thenReturn(pageReturn); + successRes = processInstanceService.queryProcessInstanceList(loginUser, projectCode, 1, "", + "", "", loginUser.getUserName(), ExecutionStatus.SUBMITTED_SUCCESS, + "192.168.xx.xx", 1, 10); + Assert.assertEquals(Status.SUCCESS.getCode(), (int)successRes.getCode()); //executor null when(usersService.queryUser(loginUser.getId())).thenReturn(null); when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(-1); - Result executorExistRes = processInstanceService.queryProcessInstanceList(loginUser, projectName, 1, "2020-01-01 00:00:00", - "2020-01-02 00:00:00", "", "admin", ExecutionStatus.SUBMITTED_SUCCESS, - "192.168.xx.xx", 1, 10); + Result executorExistRes = processInstanceService.queryProcessInstanceList(loginUser, projectCode, 1, "2020-01-01 00:00:00", + "2020-01-02 00:00:00", "", "admin", ExecutionStatus.SUBMITTED_SUCCESS, + "192.168.xx.xx", 1, 10); + Assert.assertEquals(Status.SUCCESS.getCode(), (int)executorExistRes.getCode()); //executor name empty when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1L), eq(""), eq(0), Mockito.any(), - eq("192.168.xx.xx"), eq(start), eq(end))).thenReturn(pageReturn); - Result executorEmptyRes = processInstanceService.queryProcessInstanceList(loginUser, projectName, 1, "2020-01-01 00:00:00", - "2020-01-02 00:00:00", "", "", ExecutionStatus.SUBMITTED_SUCCESS, - "192.168.xx.xx", 1, 10); + eq("192.168.xx.xx"), eq(start), eq(end))).thenReturn(pageReturn); + Result executorEmptyRes = processInstanceService.queryProcessInstanceList(loginUser, projectCode, 1, "2020-01-01 00:00:00", + "2020-01-02 00:00:00", "", "", ExecutionStatus.SUBMITTED_SUCCESS, + "192.168.xx.xx", 1, 10); Assert.assertEquals(Status.SUCCESS.getCode(), (int)executorEmptyRes.getCode()); } @Test public void testQueryTopNLongestRunningProcessInstance() { - String projectName = "project_test1"; + long projectCode = 1L; User loginUser = getAdminUser(); + Project project = getProject(projectCode); Map result = new HashMap<>(5); - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); int size = 10; String startTime = "2020-01-01 00:00:00"; String endTime = "2020-08-02 00:00:00"; @@ -206,77 +219,76 @@ public class ProcessInstanceServiceTest { Date end = DateUtils.getScheduleDate(endTime); //project auth fail - when(projectMapper.queryByName(projectName)).thenReturn(null); - when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result); - Map proejctAuthFailRes = processInstanceService.queryTopNLongestRunningProcessInstance(loginUser, projectName, size, startTime, endTime); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Map proejctAuthFailRes = processInstanceService.queryTopNLongestRunningProcessInstance(loginUser, projectCode, size, startTime, endTime); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); //project auth success - putMsg(result, Status.SUCCESS, projectName); - Project project = getProject(projectName); + putMsg(result, Status.SUCCESS, projectCode); ProcessInstance processInstance = getProcessInstance(); - when(projectMapper.queryByName(projectName)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser); when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId()); when(usersService.queryUser(processInstance.getExecutorId())).thenReturn(loginUser); - Map successRes = processInstanceService.queryTopNLongestRunningProcessInstance(loginUser, projectName, size, startTime, endTime); + Map successRes = processInstanceService.queryTopNLongestRunningProcessInstance(loginUser, projectCode, size, startTime, endTime); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); } @Test public void testQueryProcessInstanceById() { - String projectName = "project_test1"; + long projectCode = 1L; User loginUser = getAdminUser(); + Project project = getProject(projectCode); Map result = new HashMap<>(); - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); //project auth fail - when(projectMapper.queryByName(projectName)).thenReturn(null); - when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result); - Map proejctAuthFailRes = processInstanceService.queryProcessInstanceById(loginUser, projectName, 1); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Map proejctAuthFailRes = processInstanceService.queryProcessInstanceById(loginUser, projectCode, 1); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); //project auth success ProcessInstance processInstance = getProcessInstance(); - putMsg(result, Status.SUCCESS, projectName); - Project project = getProject(projectName); + putMsg(result, Status.SUCCESS, projectCode); ProcessDefinition processDefinition = getProcessDefinition(); - when(projectMapper.queryByName(projectName)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(processService.findProcessInstanceDetailById(processInstance.getId())).thenReturn(processInstance); when(processService.findProcessDefinition(processInstance.getProcessDefinitionCode(), - processInstance.getProcessDefinitionVersion())).thenReturn(processDefinition); - Map successRes = processInstanceService.queryProcessInstanceById(loginUser, projectName, 1); + processInstance.getProcessDefinitionVersion())).thenReturn(processDefinition); + Map successRes = processInstanceService.queryProcessInstanceById(loginUser, projectCode, 1); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); //worker group null - Map workerNullRes = processInstanceService.queryProcessInstanceById(loginUser, projectName, 1); + Map workerNullRes = processInstanceService.queryProcessInstanceById(loginUser, projectCode, 1); Assert.assertEquals(Status.SUCCESS, workerNullRes.get(Constants.STATUS)); //worker group exist WorkerGroup workerGroup = getWorkGroup(); - Map workerExistRes = processInstanceService.queryProcessInstanceById(loginUser, projectName, 1); + Map workerExistRes = processInstanceService.queryProcessInstanceById(loginUser, projectCode, 1); Assert.assertEquals(Status.SUCCESS, workerExistRes.get(Constants.STATUS)); } @Test public void testQueryTaskListByProcessId() throws IOException { - String projectName = "project_test1"; + long projectCode = 1L; User loginUser = getAdminUser(); + Project project = getProject(projectCode); Map result = new HashMap<>(); - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); //project auth fail - when(projectMapper.queryByName(projectName)).thenReturn(null); - when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result); - Map proejctAuthFailRes = processInstanceService.queryTaskListByProcessId(loginUser, projectName, 1); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Map proejctAuthFailRes = processInstanceService.queryTaskListByProcessId(loginUser, projectCode, 1); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); //project auth success - putMsg(result, Status.SUCCESS, projectName); - Project project = getProject(projectName); + putMsg(result, Status.SUCCESS, projectCode); ProcessInstance processInstance = getProcessInstance(); processInstance.setState(ExecutionStatus.SUCCESS); TaskInstance taskInstance = new TaskInstance(); @@ -286,103 +298,107 @@ public class ProcessInstanceServiceTest { Result res = new Result(); res.setCode(Status.SUCCESS.ordinal()); res.setData("xxx"); - when(projectMapper.queryByName(projectName)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(processService.findProcessInstanceDetailById(processInstance.getId())).thenReturn(processInstance); when(processService.findValidTaskListByProcessId(processInstance.getId())).thenReturn(taskInstanceList); when(loggerService.queryLog(taskInstance.getId(), 0, 4098)).thenReturn(res); - Map successRes = processInstanceService.queryTaskListByProcessId(loginUser, projectName, 1); + Map successRes = processInstanceService.queryTaskListByProcessId(loginUser, projectCode, 1); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); } @Test public void testParseLogForDependentResult() throws IOException { String logString = "[INFO] 2019-03-19 17:11:08.475 org.apache.dolphinscheduler.server.worker.log.TaskLogger:[172]" - + " - [taskAppId=TASK_223_10739_452334] dependent item complete :|| 223-ALL-day-last1Day,SUCCESS\n" - + "[INFO] 2019-03-19 17:11:08.476 org.apache.dolphinscheduler.server.worker.runner.TaskScheduleThread:[172]" - + " - task : 223_10739_452334 exit status code : 0\n" - + "[root@node2 current]# "; + + " - [taskAppId=TASK_223_10739_452334] dependent item complete :|| 223-ALL-day-last1Day,SUCCESS\n" + + "[INFO] 2019-03-19 17:11:08.476 org.apache.dolphinscheduler.server.worker.runner.TaskScheduleThread:[172]" + + " - task : 223_10739_452334 exit status code : 0\n" + + "[root@node2 current]# "; Map resultMap = - processInstanceService.parseLogForDependentResult(logString); + processInstanceService.parseLogForDependentResult(logString); Assert.assertEquals(1, resultMap.size()); } @Test public void testQuerySubProcessInstanceByTaskId() { - String projectName = "project_test1"; + long projectCode = 1L; User loginUser = getAdminUser(); + Project project = getProject(projectCode); Map result = new HashMap<>(); - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); //project auth fail - when(projectMapper.queryByName(projectName)).thenReturn(null); - when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result); - Map proejctAuthFailRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectName, 1); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Map proejctAuthFailRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectCode, 1); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); //task null - Project project = getProject(projectName); - putMsg(result, Status.SUCCESS, projectName); - when(projectMapper.queryByName(projectName)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); + putMsg(result, Status.SUCCESS, projectCode); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(processService.findTaskInstanceById(1)).thenReturn(null); - Map taskNullRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectName, 1); + Map taskNullRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectCode, 1); Assert.assertEquals(Status.TASK_INSTANCE_NOT_EXISTS, taskNullRes.get(Constants.STATUS)); //task not sub process TaskInstance taskInstance = getTaskInstance(); taskInstance.setTaskType(TaskType.HTTP.getDesc()); taskInstance.setProcessInstanceId(1); + putMsg(result, Status.SUCCESS, projectCode); when(processService.findTaskInstanceById(1)).thenReturn(taskInstance); - Map notSubprocessRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectName, 1); + Map notSubprocessRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectCode, 1); Assert.assertEquals(Status.TASK_INSTANCE_NOT_SUB_WORKFLOW_INSTANCE, notSubprocessRes.get(Constants.STATUS)); //sub process not exist TaskInstance subTask = getTaskInstance(); subTask.setTaskType(TaskType.SUB_PROCESS.getDesc()); subTask.setProcessInstanceId(1); + putMsg(result, Status.SUCCESS, projectCode); when(processService.findTaskInstanceById(subTask.getId())).thenReturn(subTask); when(processService.findSubProcessInstance(subTask.getProcessInstanceId(), subTask.getId())).thenReturn(null); - Map subprocessNotExistRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectName, 1); + Map subprocessNotExistRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectCode, 1); Assert.assertEquals(Status.SUB_PROCESS_INSTANCE_NOT_EXIST, subprocessNotExistRes.get(Constants.STATUS)); //sub process exist ProcessInstance processInstance = getProcessInstance(); + putMsg(result, Status.SUCCESS, projectCode); when(processService.findSubProcessInstance(taskInstance.getProcessInstanceId(), taskInstance.getId())).thenReturn(processInstance); - Map subprocessExistRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectName, 1); + Map subprocessExistRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectCode, 1); Assert.assertEquals(Status.SUCCESS, subprocessExistRes.get(Constants.STATUS)); } @Test public void testUpdateProcessInstance() { - String projectName = "project_test1"; + long projectCode = 1L; User loginUser = getAdminUser(); + Project project = getProject(projectCode); Map result = new HashMap<>(); - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); //project auth fail - when(projectMapper.queryByName(projectName)).thenReturn(null); - when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result); - Map proejctAuthFailRes = processInstanceService.updateProcessInstance(loginUser, projectName, 1, - shellJson, "2020-02-21 00:00:00", true, Flag.YES, "", ""); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Map proejctAuthFailRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1, + shellJson, taskJson, "2020-02-21 00:00:00", true, "", "", 0, ""); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); //process instance null - Project project = getProject(projectName); - putMsg(result, Status.SUCCESS, projectName); + putMsg(result, Status.SUCCESS, projectCode); ProcessInstance processInstance = getProcessInstance(); - when(projectMapper.queryByName(projectName)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(processService.findProcessInstanceDetailById(1)).thenReturn(null); - Map processInstanceNullRes = processInstanceService.updateProcessInstance(loginUser, projectName, 1, - shellJson, "2020-02-21 00:00:00", true, Flag.YES, "", ""); + Map processInstanceNullRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1, + shellJson, taskJson,"2020-02-21 00:00:00", true, "", "", 0, ""); Assert.assertEquals(Status.PROCESS_INSTANCE_NOT_EXIST, processInstanceNullRes.get(Constants.STATUS)); //process instance not finish when(processService.findProcessInstanceDetailById(1)).thenReturn(processInstance); processInstance.setState(ExecutionStatus.RUNNING_EXECUTION); - Map processInstanceNotFinishRes = processInstanceService.updateProcessInstance(loginUser, projectName, 1, - shellJson, "2020-02-21 00:00:00", true, Flag.YES, "", ""); + putMsg(result, Status.SUCCESS, projectCode); + Map processInstanceNotFinishRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1, + shellJson, taskJson,"2020-02-21 00:00:00", true, "", "", 0, ""); Assert.assertEquals(Status.PROCESS_INSTANCE_STATE_OPERATION_ERROR, processInstanceNotFinishRes.get(Constants.STATUS)); //process instance finish @@ -394,90 +410,81 @@ public class ProcessInstanceServiceTest { ProcessDefinition processDefinition = getProcessDefinition(); processDefinition.setId(1); processDefinition.setUserId(1); - Tenant tenant = new Tenant(); - tenant.setId(1); - tenant.setTenantCode("test_tenant"); + Tenant tenant = getTenant(); when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); + when(tenantMapper.queryByTenantCode("root")).thenReturn(tenant); when(processService.getTenantForProcess(Mockito.anyInt(), Mockito.anyInt())).thenReturn(tenant); when(processService.updateProcessInstance(processInstance)).thenReturn(1); - when(processDefinitionService.checkProcessNodeList(Mockito.any(), eq(shellJson))).thenReturn(result); - when(processService.findProcessDefinition(processInstance.getProcessDefinitionCode(), - processInstance.getProcessDefinitionVersion())).thenReturn(processDefinition); - - Map processInstanceFinishRes = processInstanceService.updateProcessInstance(loginUser, projectName, 1, - shellJson, "2020-02-21 00:00:00", true, Flag.YES, "", ""); - Assert.assertEquals(Status.UPDATE_PROCESS_INSTANCE_ERROR, processInstanceFinishRes.get(Constants.STATUS)); + when(processDefinitionService.checkProcessNodeList(shellJson)).thenReturn(result); + putMsg(result, Status.SUCCESS, projectCode); + Map processInstanceFinishRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1, + shellJson, taskJson,"2020-02-21 00:00:00", true, "", "", 0, "root"); + Assert.assertEquals(Status.CREATE_TASK_DEFINITION_ERROR, processInstanceFinishRes.get(Constants.STATUS)); //success - when(processService.saveProcessDefinition(Mockito.any(), Mockito.any(), - Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), - Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.anyBoolean())).thenReturn(1); - when(processService.findProcessDefinition(46L, 0)).thenReturn(processDefinition); - putMsg(result, Status.SUCCESS, projectName); + when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); + putMsg(result, Status.SUCCESS, projectCode); - Map successRes = processInstanceService.updateProcessInstance(loginUser, projectName, 1, - shellJson, "2020-02-21 00:00:00", true, Flag.YES, "", ""); + Map successRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1, + shellJson, taskJson,"2020-02-21 00:00:00", false, "", "", 0, "root"); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); } @Test public void testQueryParentInstanceBySubId() { - String projectName = "project_test1"; + long projectCode = 1L; User loginUser = getAdminUser(); + Project project = getProject(projectCode); Map result = new HashMap<>(); - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); //project auth fail - when(projectMapper.queryByName(projectName)).thenReturn(null); - when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result); - Map proejctAuthFailRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectName, 1); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Map proejctAuthFailRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, 1); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); //process instance null - Project project = getProject(projectName); - putMsg(result, Status.SUCCESS, projectName); - when(projectMapper.queryByName(projectName)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); + putMsg(result, Status.SUCCESS, projectCode); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(processService.findProcessInstanceDetailById(1)).thenReturn(null); - when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - Map processInstanceNullRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectName, 1); + Map processInstanceNullRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, 1); Assert.assertEquals(Status.PROCESS_INSTANCE_NOT_EXIST, processInstanceNullRes.get(Constants.STATUS)); //not sub process ProcessInstance processInstance = getProcessInstance(); processInstance.setIsSubProcess(Flag.NO); + putMsg(result, Status.SUCCESS, projectCode); when(processService.findProcessInstanceDetailById(1)).thenReturn(processInstance); - Map notSubProcessRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectName, 1); + Map notSubProcessRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, 1); Assert.assertEquals(Status.PROCESS_INSTANCE_NOT_SUB_PROCESS_INSTANCE, notSubProcessRes.get(Constants.STATUS)); //sub process processInstance.setIsSubProcess(Flag.YES); + putMsg(result, Status.SUCCESS, projectCode); when(processService.findParentProcessInstance(1)).thenReturn(null); - Map subProcessNullRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectName, 1); + Map subProcessNullRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, 1); Assert.assertEquals(Status.SUB_PROCESS_INSTANCE_NOT_EXIST, subProcessNullRes.get(Constants.STATUS)); //success + putMsg(result, Status.SUCCESS, projectCode); when(processService.findParentProcessInstance(1)).thenReturn(processInstance); - Map successRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectName, 1); + Map successRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, 1); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); } @Test public void testDeleteProcessInstanceById() { - String projectName = "project_test1"; + long projectCode = 1L; User loginUser = getAdminUser(); + Project project = getProject(projectCode); Map result = new HashMap<>(); - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); - - //project auth fail - when(projectMapper.queryByName(projectName)).thenReturn(null); - when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result); - + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); //process instance null - Project project = getProject(projectName); - putMsg(result, Status.SUCCESS, projectName); - when(projectMapper.queryByName(projectName)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); + putMsg(result, Status.SUCCESS, projectCode); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(processService.findProcessInstanceDetailById(1)).thenReturn(null); } @@ -487,7 +494,6 @@ public class ProcessInstanceServiceTest { ProcessInstance processInstance = getProcessInstance(); processInstance.setCommandType(CommandType.SCHEDULER); processInstance.setScheduleTime(new Date()); - processInstance.setProcessInstanceJson(shellJson); processInstance.setGlobalParams(""); when(processInstanceMapper.queryDetailById(1)).thenReturn(processInstance); Map successRes = processInstanceService.viewVariables(1); @@ -497,14 +503,13 @@ public class ProcessInstanceServiceTest { @Test public void testViewGantt() throws Exception { ProcessInstance processInstance = getProcessInstance(); - processInstance.setProcessInstanceJson(shellJson); TaskInstance taskInstance = getTaskInstance(); taskInstance.setState(ExecutionStatus.RUNNING_EXECUTION); taskInstance.setStartTime(new Date()); when(processInstanceMapper.queryDetailById(1)).thenReturn(processInstance); when(processDefinitionLogMapper.queryByDefinitionCodeAndVersion( - processInstance.getProcessDefinitionCode(), - processInstance.getProcessDefinitionVersion() + processInstance.getProcessDefinitionCode(), + processInstance.getProcessDefinitionVersion() )).thenReturn(new ProcessDefinitionLog()); when(processInstanceMapper.queryDetailById(1)).thenReturn(processInstance); when(taskInstanceMapper.queryByInstanceIdAndName(Mockito.anyInt(), Mockito.any())).thenReturn(taskInstance); @@ -514,7 +519,7 @@ public class ProcessInstanceServiceTest { } when(processService.genDagGraph(Mockito.any(ProcessDefinition.class))) - .thenReturn(graph); + .thenReturn(graph); Map successRes = processInstanceService.viewGantt(1); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); @@ -536,14 +541,14 @@ public class ProcessInstanceServiceTest { /** * get mock Project * - * @param projectName projectName + * @param projectCode projectCode * @return Project */ - private Project getProject(String projectName) { + private Project getProject(long projectCode) { Project project = new Project(); - project.setCode(1L); + project.setCode(projectCode); project.setId(1); - project.setName(projectName); + project.setName("project_test1"); project.setUserId(1); return project; } @@ -575,13 +580,19 @@ public class ProcessInstanceServiceTest { processDefinition.setVersion(1); processDefinition.setId(46); processDefinition.setName("test_pdf"); - processDefinition.setProjectId(2); processDefinition.setProjectCode(2L); processDefinition.setTenantId(1); processDefinition.setDescription(""); return processDefinition; } + private Tenant getTenant() { + Tenant tenant = new Tenant(); + tenant.setId(1); + tenant.setTenantCode("root"); + return tenant; + } + /** * get Mock worker group * diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessTaskRelationServiceImplTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessTaskRelationServiceImplTest.java deleted file mode 100644 index b1b20a7e5e..0000000000 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessTaskRelationServiceImplTest.java +++ /dev/null @@ -1,107 +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.api.enums.Status; -import org.apache.dolphinscheduler.api.service.impl.ProcessTaskRelationServiceImpl; -import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; -import org.apache.dolphinscheduler.common.Constants; -import org.apache.dolphinscheduler.common.enums.UserType; -import org.apache.dolphinscheduler.dao.entity.Project; -import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; -import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; -import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; - -import java.text.MessageFormat; -import java.util.HashMap; -import java.util.Map; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; - -@RunWith(MockitoJUnitRunner.class) -public class ProcessTaskRelationServiceImplTest { - @InjectMocks - private ProcessTaskRelationServiceImpl processTaskRelationService; - - @Mock - private ProcessDefinitionMapper processDefineMapper; - - @Mock - private ProcessTaskRelationMapper processTaskRelationMapper; - - @Mock - private ProjectMapper projectMapper; - - @Mock - private ProjectServiceImpl projectService; - - @Test - public void queryProcessTaskRelationTest() { - String projectName = "project_test1"; - - Project project = getProject(projectName); - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); - - User loginUser = new User(); - loginUser.setId(-1); - loginUser.setUserType(UserType.GENERAL_USER); - - Map result = new HashMap<>(); - putMsg(result, Status.SUCCESS, projectName); - - //project check auth fail - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - - Map relation = processTaskRelationService - .queryProcessTaskRelation(loginUser, projectName, 11L); - - Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); - } - - private void putMsg(Map result, Status status, Object... statusParams) { - result.put(Constants.STATUS, status); - if (statusParams != null && statusParams.length > 0) { - result.put(Constants.MSG, MessageFormat.format(status.getMsg(), statusParams)); - } else { - result.put(Constants.MSG, status.getMsg()); - } - } - - /** - * get mock Project - * - * @param projectName projectName - * @return Project - */ - private Project getProject(String projectName) { - Project project = new Project(); - project.setCode(11L); - project.setId(1); - project.setName(projectName); - project.setUserId(1); - return project; - } - -} diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java index e7f0f908ec..61c8a1d8a2 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java @@ -102,29 +102,14 @@ public class ProjectServiceTest { } - @Test - public void testQueryById() { - - //not exist - Map result = projectService.queryById(Integer.MAX_VALUE); - Assert.assertEquals(Status.PROJECT_NOT_FOUNT, result.get(Constants.STATUS)); - logger.info(result.toString()); - - //success - Mockito.when(projectMapper.selectById(1)).thenReturn(getProject()); - result = projectService.queryById(1); - logger.info(result.toString()); - Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - - } - @Test public void testCheckProjectAndAuth() { + long projectCode = 1L; Mockito.when(projectUserMapper.queryProjectRelation(1, 1)).thenReturn(getProjectUser()); User loginUser = getLoginUser(); - Map result = projectService.checkProjectAndAuth(loginUser, null, projectName); + Map result = projectService.checkProjectAndAuth(loginUser, null, projectCode); logger.info(result.toString()); Status status = (Status) result.get(Constants.STATUS); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, result.get(Constants.STATUS)); @@ -132,30 +117,30 @@ public class ProjectServiceTest { Project project = getProject(); //USER_NO_OPERATION_PROJECT_PERM project.setUserId(2); - result = projectService.checkProjectAndAuth(loginUser, project, projectName); + result = projectService.checkProjectAndAuth(loginUser, project, projectCode); logger.info(result.toString()); Assert.assertEquals(Status.USER_NO_OPERATION_PROJECT_PERM, result.get(Constants.STATUS)); //success project.setUserId(1); - result = projectService.checkProjectAndAuth(loginUser, project, projectName); + result = projectService.checkProjectAndAuth(loginUser, project, projectCode); logger.info(result.toString()); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); Map result2 = new HashMap<>(); - result2 = projectService.checkProjectAndAuth(loginUser, null, projectName); + result2 = projectService.checkProjectAndAuth(loginUser, null, projectCode); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, result2.get(Constants.STATUS)); Project project1 = getProject(); // USER_NO_OPERATION_PROJECT_PERM project1.setUserId(2); - result2 = projectService.checkProjectAndAuth(loginUser, project1, projectName); + result2 = projectService.checkProjectAndAuth(loginUser, project1, projectCode); Assert.assertEquals(Status.USER_NO_OPERATION_PROJECT_PERM, result2.get(Constants.STATUS)); //success project1.setUserId(1); - projectService.checkProjectAndAuth(loginUser, project1, projectName); + projectService.checkProjectAndAuth(loginUser, project1, projectCode); } @@ -207,33 +192,31 @@ public class ProjectServiceTest { @Test public void testDeleteProject() { - - Mockito.when(projectMapper.selectById(1)).thenReturn(getProject()); User loginUser = getLoginUser(); + Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject()); //PROJECT_NOT_FOUNT - Map result = projectService.deleteProject(loginUser, 12); + Map result = projectService.deleteProject(loginUser, 11L); logger.info(result.toString()); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, result.get(Constants.STATUS)); loginUser.setId(2); //USER_NO_OPERATION_PROJECT_PERM - result = projectService.deleteProject(loginUser, 1); + result = projectService.deleteProject(loginUser, 1L); logger.info(result.toString()); Assert.assertEquals(Status.USER_NO_OPERATION_PROJECT_PERM, result.get(Constants.STATUS)); //DELETE_PROJECT_ERROR_DEFINES_NOT_NULL Mockito.when(processDefinitionMapper.queryAllDefinitionList(1L)).thenReturn(getProcessDefinitions()); loginUser.setUserType(UserType.ADMIN_USER); - result = projectService.deleteProject(loginUser, 1); + result = projectService.deleteProject(loginUser, 1L); logger.info(result.toString()); Assert.assertEquals(Status.DELETE_PROJECT_ERROR_DEFINES_NOT_NULL, result.get(Constants.STATUS)); //success Mockito.when(projectMapper.deleteById(1)).thenReturn(1); Mockito.when(processDefinitionMapper.queryAllDefinitionList(1L)).thenReturn(new ArrayList<>()); - result = projectService.deleteProject(loginUser, 1); + result = projectService.deleteProject(loginUser, 1L); logger.info(result.toString()); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - } @Test @@ -241,28 +224,28 @@ public class ProjectServiceTest { User loginUser = getLoginUser(); Project project = getProject(); - project.setId(2); + project.setCode(2L); Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); - Mockito.when(projectMapper.selectById(1)).thenReturn(getProject()); + Mockito.when(projectMapper.queryByCode(2L)).thenReturn(getProject()); // PROJECT_NOT_FOUNT - Map result = projectService.update(loginUser, 12, projectName, "desc", "testUser"); + Map result = projectService.update(loginUser, 1L, projectName, "desc", "testUser"); logger.info(result.toString()); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, result.get(Constants.STATUS)); //PROJECT_ALREADY_EXISTS - result = projectService.update(loginUser, 1, projectName, "desc", "testUser"); + result = projectService.update(loginUser, 2L, projectName, "desc", userName); logger.info(result.toString()); Assert.assertEquals(Status.PROJECT_ALREADY_EXISTS, result.get(Constants.STATUS)); Mockito.when(userMapper.queryByUserNameAccurately(Mockito.any())).thenReturn(null); - result = projectService.update(loginUser, 1, "test", "desc", "testuser"); + result = projectService.update(loginUser, 2L, "test", "desc", "testuser"); Assert.assertEquals(Status.USER_NOT_EXIST, result.get(Constants.STATUS)); //success Mockito.when(userMapper.queryByUserNameAccurately(Mockito.any())).thenReturn(new User()); project.setUserId(1); Mockito.when(projectMapper.updateById(Mockito.any(Project.class))).thenReturn(1); - result = projectService.update(loginUser, 1, "test", "desc", "testUser"); + result = projectService.update(loginUser, 2L, "test", "desc", "testUser"); logger.info(result.toString()); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); @@ -394,7 +377,7 @@ public class ProjectServiceTest { private List getProcessDefinitions() { List list = new ArrayList<>(); ProcessDefinition processDefinition = new ProcessDefinition(); - processDefinition.setProjectId(1); + processDefinition.setProjectCode(1L); list.add(processDefinition); return list; } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/QueueServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/QueueServiceTest.java index c033a277ad..7d69d6598c 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/QueueServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/QueueServiceTest.java @@ -156,27 +156,27 @@ public class QueueServiceTest { //queue null Result result = queueService.verifyQueue(null,queueName); logger.info(result.toString()); - Assert.assertTrue(result.isStatus(Status.REQUEST_PARAMS_NOT_VALID_ERROR)); + Assert.assertEquals(result.getCode().intValue(), Status.REQUEST_PARAMS_NOT_VALID_ERROR.getCode()); //queueName null result = queueService.verifyQueue(queueName,null); logger.info(result.toString()); - Assert.assertTrue(result.isStatus(Status.REQUEST_PARAMS_NOT_VALID_ERROR)); + Assert.assertEquals(result.getCode().intValue(), Status.REQUEST_PARAMS_NOT_VALID_ERROR.getCode()); //exist queueName result = queueService.verifyQueue(queueName,queueName); logger.info(result.toString()); - Assert.assertTrue(result.isStatus(Status.QUEUE_NAME_EXIST)); + Assert.assertEquals(result.getCode().intValue(), Status.QUEUE_NAME_EXIST.getCode()); //exist queue result = queueService.verifyQueue(queueName,"test"); logger.info(result.toString()); - Assert.assertTrue(result.isStatus(Status.QUEUE_VALUE_EXIST)); + Assert.assertEquals(result.getCode().intValue(), Status.QUEUE_VALUE_EXIST.getCode()); // success result = queueService.verifyQueue("test","test"); logger.info(result.toString()); - Assert.assertTrue(result.isSuccess()); + Assert.assertEquals(result.getCode().intValue(), Status.SUCCESS.getCode()); } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java index 15ad0f2337..65a087286b 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java @@ -235,7 +235,7 @@ public class ResourcesServiceTest { Mockito.when(userMapper.selectById(Mockito.anyInt())).thenReturn(null); result = resourcesService.updateResource(user, 1, "ResourcesServiceTest1.jar", "ResourcesServiceTest", ResourceType.UDF, null); logger.info(result.toString()); - Assert.assertTrue(result.isStatus(Status.USER_NOT_EXIST)); + Assert.assertTrue(Status.USER_NOT_EXIST.getCode() == result.getCode()); //TENANT_NOT_EXIST Mockito.when(userMapper.selectById(1)).thenReturn(getUser()); @@ -372,8 +372,7 @@ public class ResourcesServiceTest { PowerMockito.when(HadoopUtils.getHdfsResourceFileName("123", "test1")).thenReturn("test"); result = resourcesService.verifyResourceName("/ResourcesServiceTest.jar", ResourceType.FILE, user); logger.info(result.toString()); - - Assert.assertTrue(result.isStatus(Status.RESOURCE_EXIST)); + Assert.assertTrue(Status.RESOURCE_EXIST.getCode() == result.getCode()); //SUCCESS result = resourcesService.verifyResourceName("test2", ResourceType.FILE, user); @@ -411,7 +410,7 @@ public class ResourcesServiceTest { PowerMockito.when(FileUtils.suffix("ResourcesServiceTest.jar")).thenReturn("jar"); result = resourcesService.readResource(1, 1, 10); logger.info(result.toString()); - Assert.assertTrue(result.isStatus(Status.USER_NOT_EXIST)); + Assert.assertTrue(Status.USER_NOT_EXIST.getCode() == result.getCode()); //TENANT_NOT_EXIST Mockito.when(userMapper.selectById(1)).thenReturn(getUser()); @@ -428,7 +427,7 @@ public class ResourcesServiceTest { } result = resourcesService.readResource(1, 1, 10); logger.info(result.toString()); - Assert.assertTrue(result.isStatus(Status.RESOURCE_FILE_NOT_EXIST)); + Assert.assertTrue(Status.RESOURCE_FILE_NOT_EXIST.getCode() == result.getCode()); //SUCCESS try { @@ -512,13 +511,13 @@ public class ResourcesServiceTest { PowerMockito.when(FileUtils.suffix("ResourcesServiceTest.jar")).thenReturn("jar"); result = resourcesService.updateResourceContent(1, "content"); logger.info(result.toString()); - Assert.assertTrue(result.isStatus(Status.USER_NOT_EXIST)); + Assert.assertTrue(Status.USER_NOT_EXIST.getCode() == result.getCode()); //TENANT_NOT_EXIST Mockito.when(userMapper.selectById(1)).thenReturn(getUser()); result = resourcesService.updateResourceContent(1, "content"); logger.info(result.toString()); - Assert.assertTrue(result.isStatus(Status.TENANT_NOT_EXIST)); + Assert.assertTrue(Status.TENANT_NOT_EXIST.getCode() == result.getCode()); //SUCCESS Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java index 0866e40e91..238d1d08fc 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java @@ -27,6 +27,7 @@ import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.Schedule; import org.apache.dolphinscheduler.dao.entity.User; +import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; import org.apache.dolphinscheduler.service.process.ProcessService; @@ -70,6 +71,9 @@ public class SchedulerServiceTest { @Mock private ProjectMapper projectMapper; + @Mock + private ProcessDefinitionMapper processDefinitionMapper; + @Mock private ProjectServiceImpl projectService; @@ -91,18 +95,18 @@ public class SchedulerServiceTest { @Test public void testSetScheduleState() { - String projectName = "test"; + long projectCode = 1L; User loginUser = new User(); loginUser.setId(1); Map result = new HashMap(); - Project project = getProject(projectName); + Project project = getProject(projectName, projectCode); ProcessDefinition processDefinition = new ProcessDefinition(); Schedule schedule = new Schedule(); schedule.setId(1); - schedule.setProcessDefinitionId(1); + schedule.setProcessDefinitionCode(1); schedule.setReleaseState(ReleaseState.OFFLINE); List masterServers = new ArrayList<>(); @@ -110,49 +114,50 @@ public class SchedulerServiceTest { Mockito.when(scheduleMapper.selectById(1)).thenReturn(schedule); + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); - Mockito.when(processService.findProcessDefineById(1)).thenReturn(processDefinition); + Mockito.when(processDefinitionMapper.queryByCode(1)).thenReturn(processDefinition); //hash no auth - result = schedulerService.setScheduleState(loginUser, projectName, 1, ReleaseState.ONLINE); + result = schedulerService.setScheduleState(loginUser, project.getCode(), 1, ReleaseState.ONLINE); Mockito.when(projectService.hasProjectAndPerm(loginUser, project, result)).thenReturn(true); //schedule not exists - result = schedulerService.setScheduleState(loginUser, projectName, 2, ReleaseState.ONLINE); + result = schedulerService.setScheduleState(loginUser, project.getCode(), 2, ReleaseState.ONLINE); Assert.assertEquals(Status.SCHEDULE_CRON_NOT_EXISTS, result.get(Constants.STATUS)); //SCHEDULE_CRON_REALEASE_NEED_NOT_CHANGE - result = schedulerService.setScheduleState(loginUser, projectName, 1, ReleaseState.OFFLINE); + result = schedulerService.setScheduleState(loginUser, project.getCode(), 1, ReleaseState.OFFLINE); Assert.assertEquals(Status.SCHEDULE_CRON_REALEASE_NEED_NOT_CHANGE, result.get(Constants.STATUS)); //PROCESS_DEFINE_NOT_EXIST - schedule.setProcessDefinitionId(2); - result = schedulerService.setScheduleState(loginUser, projectName, 1, ReleaseState.ONLINE); + schedule.setProcessDefinitionCode(2); + result = schedulerService.setScheduleState(loginUser, project.getCode(), 1, ReleaseState.ONLINE); Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, result.get(Constants.STATUS)); - schedule.setProcessDefinitionId(1); + schedule.setProcessDefinitionCode(1); // PROCESS_DEFINE_NOT_RELEASE - result = schedulerService.setScheduleState(loginUser, projectName, 1, ReleaseState.ONLINE); + result = schedulerService.setScheduleState(loginUser, project.getCode(), 1, ReleaseState.ONLINE); Assert.assertEquals(Status.PROCESS_DEFINE_NOT_RELEASE, result.get(Constants.STATUS)); processDefinition.setReleaseState(ReleaseState.ONLINE); Mockito.when(processService.findProcessDefineById(1)).thenReturn(processDefinition); //MASTER_NOT_EXISTS - result = schedulerService.setScheduleState(loginUser, projectName, 1, ReleaseState.ONLINE); + result = schedulerService.setScheduleState(loginUser, project.getCode(), 1, ReleaseState.ONLINE); Assert.assertEquals(Status.MASTER_NOT_EXISTS, result.get(Constants.STATUS)); //set master Mockito.when(monitorService.getServerListFromRegistry(true)).thenReturn(masterServers); //SUCCESS - result = schedulerService.setScheduleState(loginUser, projectName, 1, ReleaseState.ONLINE); + result = schedulerService.setScheduleState(loginUser, project.getCode(), 1, ReleaseState.ONLINE); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); //OFFLINE Mockito.when(quartzExecutors.deleteJob(null, null)).thenReturn(true); - result = schedulerService.setScheduleState(loginUser, projectName, 1, ReleaseState.OFFLINE); + result = schedulerService.setScheduleState(loginUser, project.getCode(), 1, ReleaseState.OFFLINE); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); } @@ -174,7 +179,6 @@ public class SchedulerServiceTest { } private Project getProject(String name) { - Project project = new Project(); project.setName(name); project.setUserId(1); @@ -182,4 +186,13 @@ public class SchedulerServiceTest { return project; } -} \ No newline at end of file + private Project getProject(String name, long code) { + Project project = new Project(); + project.setName(name); + project.setCode(code); + project.setUserId(1); + + return project; + } + +} diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java index bd2961411c..18d42144e5 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java @@ -22,13 +22,12 @@ import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; import org.apache.dolphinscheduler.api.service.impl.TaskDefinitionServiceImpl; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.enums.UserType; -import org.apache.dolphinscheduler.common.model.TaskNode; +import org.apache.dolphinscheduler.common.task.shell.ShellParameters; import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; @@ -36,7 +35,9 @@ import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.service.process.ProcessService; import java.text.MessageFormat; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.junit.Assert; @@ -50,49 +51,6 @@ import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class TaskDefinitionServiceImplTest { - String taskDefinitionJson = "{\n" - + " \"type\": \"SQL\",\n" - + " \"id\": \"tasks-27297\",\n" - + " \"name\": \"SQL\",\n" - + " \"params\": {\n" - + " \"type\": \"MYSQL\",\n" - + " \"datasource\": 1,\n" - + " \"sql\": \"select * from test\",\n" - + " \"udfs\": \"\",\n" - + " \"sqlType\": \"1\",\n" - + " \"title\": \"\",\n" - + " \"receivers\": \"\",\n" - + " \"receiversCc\": \"\",\n" - + " \"showType\": \"TABLE\",\n" - + " \"localParams\": [\n" - + " \n" - + " ],\n" - + " \"connParams\": \"\",\n" - + " \"preStatements\": [\n" - + " \n" - + " ],\n" - + " \"postStatements\": [\n" - + " \n" - + " ]\n" - + " },\n" - + " \"description\": \"\",\n" - + " \"runFlag\": \"NORMAL\",\n" - + " \"dependence\": {\n" - + " \n" - + " },\n" - + " \"maxRetryTimes\": \"0\",\n" - + " \"retryInterval\": \"1\",\n" - + " \"timeout\": {\n" - + " \"strategy\": \"\",\n" - + " \"enable\": false\n" - + " },\n" - + " \"taskInstancePriority\": \"MEDIUM\",\n" - + " \"workerGroupId\": -1,\n" - + " \"preTasks\": [\n" - + " \"dependent\"\n" - + " ]\n" - + "}\n"; - @InjectMocks private TaskDefinitionServiceImpl taskDefinitionService; @@ -102,12 +60,6 @@ public class TaskDefinitionServiceImplTest { @Mock private TaskDefinitionLogMapper taskDefinitionLogMapper; - @Mock - private ProcessDefinitionMapper processDefineMapper; - - @Mock - private ProcessTaskRelationMapper processTaskRelationMapper; - @Mock private ProjectMapper projectMapper; @@ -117,157 +69,147 @@ public class TaskDefinitionServiceImplTest { @Mock private ProcessService processService; + @Mock + private ProcessTaskRelationMapper processTaskRelationMapper; + ; + @Test public void createTaskDefinition() { - String projectName = "project_test1"; + long projectCode = 1L; - Project project = getProject(projectName); - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); + Project project = getProject(projectCode); + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); User loginUser = new User(); loginUser.setId(-1); loginUser.setUserType(UserType.GENERAL_USER); Map result = new HashMap<>(); - putMsg(result, Status.SUCCESS, projectName); - - //project check auth fail - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - - TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); - - Mockito.when(processService.saveTaskDefinition(Mockito.eq(loginUser) - , Mockito.eq(project.getCode()) - , Mockito.eq(taskNode) - , Mockito.any(TaskDefinition.class))) - .thenReturn(1); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + String createTaskDefinitionJson = "[{\"name\":\"detail_up\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":" + + "\"{\\\"resourceList\\\":[],\\\"localParams\\\":[{\\\"prop\\\":\\\"datetime\\\",\\\"direct\\\":\\\"IN\\\"," + + "\\\"type\\\":\\\"VARCHAR\\\",\\\"value\\\":\\\"${system.datetime}\\\"}],\\\"rawScript\\\":" + + "\\\"echo ${datetime}\\\",\\\"conditionResult\\\":\\\"{\\\\\\\"successNode\\\\\\\":[\\\\\\\"\\\\\\\"]," + + "\\\\\\\"failedNode\\\\\\\":[\\\\\\\"\\\\\\\"]}\\\",\\\"dependence\\\":{}}\",\"flag\":0,\"taskPriority\":0," + + "\"workerGroup\":\"default\",\"failRetryTimes\":0,\"failRetryInterval\":0,\"timeoutFlag\":0," + + "\"timeoutNotifyStrategy\":0,\"timeout\":0,\"delayTime\":0,\"resourceIds\":\"\"}]"; + List taskDefinitions = JSONUtils.toList(createTaskDefinitionJson, TaskDefinitionLog.class); + Mockito.when(processService.saveTaskDefine(loginUser, projectCode, taskDefinitions)).thenReturn(true); Map relation = taskDefinitionService - .createTaskDefinition(loginUser, projectName, taskDefinitionJson); - - Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); - - } - - @Test - public void queryTaskDefinitionByName() { - String projectName = "project_test1"; - String taskName = "task"; - Project project = getProject(projectName); - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); - - User loginUser = new User(); - loginUser.setId(-1); - loginUser.setUserType(UserType.GENERAL_USER); - - Map result = new HashMap<>(); - putMsg(result, Status.SUCCESS, projectName); - - //project check auth fail - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - - TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); - - Mockito.when(taskDefinitionMapper.queryByDefinitionName(project.getCode(), taskName)) - .thenReturn(new TaskDefinition()); - - Map relation = taskDefinitionService - .queryTaskDefinitionByName(loginUser, projectName, taskName); - - Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); - } - - @Test - public void deleteTaskDefinitionByCode() { - String projectName = "project_test1"; - - Project project = getProject(projectName); - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); - - User loginUser = new User(); - loginUser.setId(-1); - loginUser.setUserType(UserType.GENERAL_USER); - - Map result = new HashMap<>(); - putMsg(result, Status.SUCCESS, projectName); - - //project check auth fail - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - - TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); - - Mockito.when(taskDefinitionMapper.deleteByCode(Mockito.anyLong())) - .thenReturn(1); - - Map relation = taskDefinitionService - .deleteTaskDefinitionByCode(loginUser, projectName, 11L); - + .createTaskDefinition(loginUser, projectCode, createTaskDefinitionJson); Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); } @Test public void updateTaskDefinition() { - String projectName = "project_test1"; + String taskDefinitionJson = "{\"name\":\"detail_up\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":" + + "\"{\\\"resourceList\\\":[],\\\"localParams\\\":[{\\\"prop\\\":\\\"datetime\\\",\\\"direct\\\":\\\"IN\\\"," + + "\\\"type\\\":\\\"VARCHAR\\\",\\\"value\\\":\\\"${system.datetime}\\\"}],\\\"rawScript\\\":" + + "\\\"echo ${datetime}\\\",\\\"conditionResult\\\":\\\"{\\\\\\\"successNode\\\\\\\":[\\\\\\\"\\\\\\\"]," + + "\\\\\\\"failedNode\\\\\\\":[\\\\\\\"\\\\\\\"]}\\\",\\\"dependence\\\":{}}\",\"flag\":0,\"taskPriority\":0," + + "\"workerGroup\":\"default\",\"failRetryTimes\":0,\"failRetryInterval\":0,\"timeoutFlag\":0," + + "\"timeoutNotifyStrategy\":0,\"timeout\":0,\"delayTime\":0,\"resourceIds\":\"\"}"; + long projectCode = 1L; + long taskCode = 1L; - Project project = getProject(projectName); - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); + Project project = getProject(projectCode); + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); User loginUser = new User(); loginUser.setId(-1); loginUser.setUserType(UserType.GENERAL_USER); Map result = new HashMap<>(); - putMsg(result, Status.SUCCESS, projectName); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); - //project check auth fail - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); + Mockito.when(processService.isTaskOnline(taskCode)).thenReturn(Boolean.FALSE); + Mockito.when(taskDefinitionMapper.queryByCode(taskCode)).thenReturn(new TaskDefinition()); + Mockito.when(taskDefinitionMapper.updateById(Mockito.any(TaskDefinitionLog.class))).thenReturn(1); + Mockito.when(taskDefinitionLogMapper.insert(Mockito.any(TaskDefinitionLog.class))).thenReturn(1); + Mockito.when(taskDefinitionLogMapper.queryMaxVersionForDefinition(taskCode)).thenReturn(1); + result = taskDefinitionService.updateTaskDefinition(loginUser, projectCode, taskCode, taskDefinitionJson); + Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); + } - TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); + @Test + public void queryTaskDefinitionByName() { + String taskName = "task"; + long projectCode = 1L; - Mockito.when(processService.updateTaskDefinition(Mockito.eq(loginUser) - , Mockito.eq(project.getCode()) - , Mockito.eq(taskNode) - , Mockito.any(TaskDefinition.class))) - .thenReturn(1); + Project project = getProject(projectCode); + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); - Mockito.when(taskDefinitionMapper.queryByDefinitionCode(11L)) - .thenReturn(new TaskDefinition()); + User loginUser = new User(); + loginUser.setId(-1); + loginUser.setUserType(UserType.GENERAL_USER); + + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + + Mockito.when(taskDefinitionMapper.queryByName(project.getCode(), taskName)) + .thenReturn(new TaskDefinition()); Map relation = taskDefinitionService - .updateTaskDefinition(loginUser, projectName, 11L, taskDefinitionJson); + .queryTaskDefinitionByName(loginUser, projectCode, taskName); + + Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); + } + + @Test + public void deleteTaskDefinitionByCode() { + long projectCode = 1L; + + Project project = getProject(projectCode); + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); + + User loginUser = new User(); + loginUser.setId(-1); + loginUser.setUserType(UserType.GENERAL_USER); + + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Mockito.when(processTaskRelationMapper.queryByTaskCode(Mockito.anyLong())) + .thenReturn(new ArrayList<>()); + Mockito.when(taskDefinitionMapper.deleteByCode(Mockito.anyLong())) + .thenReturn(1); + + Map relation = taskDefinitionService + .deleteTaskDefinitionByCode(loginUser, projectCode, Mockito.anyLong()); Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); } @Test public void switchVersion() { - String projectName = "project_test1"; int version = 1; - Long taskCode = 11L; - Project project = getProject(projectName); - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); + long taskCode = 11L; + long projectCode = 1L; + + Project project = getProject(projectCode); + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); User loginUser = new User(); loginUser.setId(-1); loginUser.setUserType(UserType.GENERAL_USER); Map result = new HashMap<>(); - putMsg(result, Status.SUCCESS, projectName); - - //project check auth fail - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - - TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); + putMsg(result, Status.SUCCESS, projectCode); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Mockito.when(taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(taskCode, version)) - .thenReturn(new TaskDefinitionLog()); + .thenReturn(new TaskDefinitionLog()); - Mockito.when(taskDefinitionMapper.queryByDefinitionCode(taskCode)) - .thenReturn(new TaskDefinition()); - + Mockito.when(taskDefinitionMapper.queryByCode(taskCode)) + .thenReturn(new TaskDefinition()); + Mockito.when(taskDefinitionMapper.updateById(new TaskDefinitionLog())).thenReturn(1); Map relation = taskDefinitionService - .switchVersion(loginUser, projectName, taskCode, version); + .switchVersion(loginUser, projectCode, taskCode, version); Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); } @@ -284,15 +226,54 @@ public class TaskDefinitionServiceImplTest { /** * get mock Project * - * @param projectName projectName + * @param projectCode projectCode * @return Project */ - private Project getProject(String projectName) { + private Project getProject(long projectCode) { Project project = new Project(); project.setId(1); - project.setName(projectName); + project.setCode(projectCode); + project.setName("test"); project.setUserId(1); return project; } -} + @Test + public void checkJson() { + String taskDefinitionJson = "[{\"name\":\"detail_up\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":" + + "\"{\\\"resourceList\\\":[],\\\"localParams\\\":[{\\\"prop\\\":\\\"datetime\\\",\\\"direct\\\":\\\"IN\\\"," + + "\\\"type\\\":\\\"VARCHAR\\\",\\\"value\\\":\\\"${system.datetime}\\\"}],\\\"rawScript\\\":" + + "\\\"echo ${datetime}\\\",\\\"conditionResult\\\":\\\"{\\\\\\\"successNode\\\\\\\":[\\\\\\\"\\\\\\\"]," + + "\\\\\\\"failedNode\\\\\\\":[\\\\\\\"\\\\\\\"]}\\\",\\\"dependence\\\":{}}\",\"flag\":0,\"taskPriority\":0," + + "\"workerGroup\":\"default\",\"failRetryTimes\":0,\"failRetryInterval\":0,\"timeoutFlag\":0," + + "\"timeoutNotifyStrategy\":0,\"timeout\":0,\"delayTime\":0,\"resourceIds\":\"\"}]"; + List taskDefinitionLogs = JSONUtils.toList(taskDefinitionJson, TaskDefinitionLog.class); + Assert.assertFalse(taskDefinitionLogs.isEmpty()); + String taskJson = "[{\"name\":\"shell1\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":{\"resourceList\":[]," + + "\"localParams\":[],\"rawScript\":\"echo 1\",\"conditionResult\":{\"successNode\":[\"\"],\"failedNode\":[\"\"]},\"dependence\":{}}," + + "\"flag\":\"NORMAL\",\"taskPriority\":\"MEDIUM\",\"workerGroup\":\"default\",\"failRetryTimes\":\"0\",\"failRetryInterval\":\"1\"," + + "\"timeoutFlag\":\"CLOSE\",\"timeoutNotifyStrategy\":\"\",\"timeout\":null,\"delayTime\":\"0\"},{\"name\":\"shell2\",\"description\":\"\"," + + "\"taskType\":\"SHELL\",\"taskParams\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo 2\",\"conditionResult\":{\"successNode\"" + + ":[\"\"],\"failedNode\":[\"\"]},\"dependence\":{}},\"flag\":\"NORMAL\",\"taskPriority\":\"MEDIUM\",\"workerGroup\":\"default\"," + + "\"failRetryTimes\":\"0\",\"failRetryInterval\":\"1\",\"timeoutFlag\":\"CLOSE\",\"timeoutNotifyStrategy\":\"\",\"timeout\":null,\"delayTime\":\"0\"}]"; + taskDefinitionLogs = JSONUtils.toList(taskJson, TaskDefinitionLog.class); + Assert.assertFalse(taskDefinitionLogs.isEmpty()); + String taskParams = "{\"resourceList\":[],\"localParams\":[{\"prop\":\"datetime\",\"direct\":\"IN\",\"type\":\"VARCHAR\"," + + "\"value\":\"${system.datetime}\"}],\"rawScript\":\"echo ${datetime}\",\"conditionResult\":\"{\\\"successNode\\\":[\\\"\\\"]," + + "\\\"failedNode\\\":[\\\"\\\"]}\",\"dependence\":{}}"; + ShellParameters parameters = JSONUtils.parseObject(taskParams, ShellParameters.class); + Assert.assertNotNull(parameters); + String params = "{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo 1\",\"conditionResult\":{\"successNode\":[\"\"],\"failedNode\":[\"\"]},\"dependence\":{}}"; + ShellParameters parameters1 = JSONUtils.parseObject(params, ShellParameters.class); + Assert.assertNotNull(parameters1); + } + + @Test + public void genTaskCodeList() { + User loginUser = new User(); + loginUser.setId(-1); + loginUser.setUserType(UserType.GENERAL_USER); + Map genTaskCodeList = taskDefinitionService.genTaskCodeList(loginUser, 10); + Assert.assertEquals(Status.SUCCESS, genTaskCodeList.get(Constants.STATUS)); + } +} \ No newline at end of file diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java index 3b5006cdf5..08fdf5fe51 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java @@ -83,29 +83,29 @@ public class TaskInstanceServiceTest { @Test public void queryTaskListPaging() { - String projectName = "project_test1"; + long projectCode = 1L; User loginUser = getAdminUser(); + Project project = getProject(projectCode); Map result = new HashMap<>(); - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); //project auth fail - when(projectMapper.queryByName(projectName)).thenReturn(null); - when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result); - Result proejctAuthFailRes = taskInstanceService.queryTaskListPaging(loginUser, "project_test1", 0, "", "", + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Result projectAuthFailRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 0, "", "", "test_user", "2019-02-26 19:48:00", "2019-02-26 19:48:22", "", null, "", 1, 20); - Assert.assertEquals(Status.PROJECT_NOT_FOUNT.getCode(), (int)proejctAuthFailRes.getCode()); + Assert.assertEquals(Status.PROJECT_NOT_FOUNT.getCode(), (int)projectAuthFailRes.getCode()); // data parameter check - putMsg(result, Status.SUCCESS, projectName); - Project project = getProject(projectName); - when(projectMapper.queryByName(Mockito.anyString())).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - Result dataParameterRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "", + putMsg(result, Status.SUCCESS, projectCode); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); + Result dataParameterRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 1, "", "", "test_user", "20200101 00:00:00", "2020-01-02 00:00:00", "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getCode(), (int)dataParameterRes.getCode()); //project - putMsg(result, Status.SUCCESS, projectName); + putMsg(result, Status.SUCCESS, projectCode); Date start = DateUtils.getScheduleDate("2020-01-01 00:00:00"); Date end = DateUtils.getScheduleDate("2020-01-02 00:00:00"); ProcessInstance processInstance = getProcessInstance(); @@ -114,8 +114,8 @@ public class TaskInstanceServiceTest { Page pageReturn = new Page<>(1, 10); taskInstanceList.add(taskInstance); pageReturn.setRecords(taskInstanceList); - when(projectMapper.queryByName(Mockito.anyString())).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser); when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId()); when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1), eq(""), eq(""), eq(""), @@ -123,39 +123,39 @@ public class TaskInstanceServiceTest { when(usersService.queryUser(processInstance.getExecutorId())).thenReturn(loginUser); when(processService.findProcessInstanceDetailById(taskInstance.getProcessInstanceId())).thenReturn(processInstance); - - Result successRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "", + Result successRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 1, "", "", "test_user", "2020-01-01 00:00:00", "2020-01-02 00:00:00", "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); Assert.assertEquals(Status.SUCCESS.getCode(), (int)successRes.getCode()); //executor name empty when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1), eq(""), eq(""), eq(""), eq(0), Mockito.any(), eq("192.168.xx.xx"), eq(start), eq(end))).thenReturn(pageReturn); - Result executorEmptyRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "", + Result executorEmptyRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 1, "", "", "", "2020-01-01 00:00:00", "2020-01-02 00:00:00", "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); Assert.assertEquals(Status.SUCCESS.getCode(), (int)executorEmptyRes.getCode()); //executor null when(usersService.queryUser(loginUser.getId())).thenReturn(null); when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(-1); - Result executorNullRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "", + Result executorNullRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 1, "", "", "test_user", "2020-01-01 00:00:00", "2020-01-02 00:00:00", "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); Assert.assertEquals(Status.SUCCESS.getCode(),(int)executorNullRes.getCode()); //start/end date null when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1), eq(""), eq(""), eq(""), eq(0), Mockito.any(), eq("192.168.xx.xx"), any(), any())).thenReturn(pageReturn); - Result executorNullDateRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "", + Result executorNullDateRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 1, "", "", "", null, null, "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); Assert.assertEquals(Status.SUCCESS.getCode(),(int) executorNullDateRes.getCode()); //start date error format when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1), eq(""), eq(""), eq(""), eq(0), Mockito.any(), eq("192.168.xx.xx"), any(), any())).thenReturn(pageReturn); - Result executorErrorStartDateRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "", + + Result executorErrorStartDateRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 1, "", "", "", "error date", null, "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getCode(), (int)executorErrorStartDateRes.getCode()); - Result executorErrorEndDateRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "", + Result executorErrorEndDateRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 1, "", "", "", null, "error date", "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getCode(), (int)executorErrorEndDateRes.getCode()); } @@ -176,14 +176,14 @@ public class TaskInstanceServiceTest { /** * get mock Project * - * @param projectName projectName + * @param projectCode projectCode * @return Project */ - private Project getProject(String projectName) { + private Project getProject(long projectCode) { Project project = new Project(); - project.setCode(1L); + project.setCode(projectCode); project.setId(1); - project.setName(projectName); + project.setName("project_test1"); project.setUserId(1); return project; } @@ -230,44 +230,54 @@ public class TaskInstanceServiceTest { @Test public void forceTaskSuccess() { User user = getAdminUser(); - String projectName = "test"; - Project project = getProject(projectName); + long projectCode = 1L; + Project project = getProject(projectCode); int taskId = 1; TaskInstance task = getTaskInstance(); Map mockSuccess = new HashMap<>(5); putMsg(mockSuccess, Status.SUCCESS); - when(projectMapper.queryByName(projectName)).thenReturn(project); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); // user auth failed Map mockFailure = new HashMap<>(5); - putMsg(mockFailure, Status.USER_NO_OPERATION_PROJECT_PERM, user.getUserName(), projectName); - when(projectService.checkProjectAndAuth(user, project, projectName)).thenReturn(mockFailure); - Map authFailRes = taskInstanceService.forceTaskSuccess(user, projectName, taskId); + putMsg(mockFailure, Status.USER_NO_OPERATION_PROJECT_PERM, user.getUserName(), projectCode); + when(projectService.checkProjectAndAuth(user, project, projectCode)).thenReturn(mockFailure); + Map authFailRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId); Assert.assertNotSame(Status.SUCCESS, authFailRes.get(Constants.STATUS)); // test task not found - when(projectService.checkProjectAndAuth(user, project, projectName)).thenReturn(mockSuccess); + when(projectService.checkProjectAndAuth(user, project, projectCode)).thenReturn(mockSuccess); when(taskInstanceMapper.selectById(Mockito.anyInt())).thenReturn(null); - Map taskNotFoundRes = taskInstanceService.forceTaskSuccess(user, projectName, taskId); + Map taskNotFoundRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId); Assert.assertEquals(Status.TASK_INSTANCE_NOT_FOUND, taskNotFoundRes.get(Constants.STATUS)); // test task instance state error task.setState(ExecutionStatus.SUCCESS); when(taskInstanceMapper.selectById(1)).thenReturn(task); - Map taskStateErrorRes = taskInstanceService.forceTaskSuccess(user, projectName, taskId); + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS, projectCode); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(user, project, projectCode)).thenReturn(result); + Map taskStateErrorRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId); Assert.assertEquals(Status.TASK_INSTANCE_STATE_OPERATION_ERROR, taskStateErrorRes.get(Constants.STATUS)); // test error task.setState(ExecutionStatus.FAILURE); when(taskInstanceMapper.updateById(task)).thenReturn(0); - Map errorRes = taskInstanceService.forceTaskSuccess(user, projectName, taskId); + putMsg(result, Status.SUCCESS, projectCode); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(user, project, projectCode)).thenReturn(result); + Map errorRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId); Assert.assertEquals(Status.FORCE_TASK_SUCCESS_ERROR, errorRes.get(Constants.STATUS)); // test success task.setState(ExecutionStatus.FAILURE); when(taskInstanceMapper.updateById(task)).thenReturn(1); - Map successRes = taskInstanceService.forceTaskSuccess(user, projectName, taskId); + putMsg(result, Status.SUCCESS, projectCode); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectService.checkProjectAndAuth(user, project, projectCode)).thenReturn(result); + Map successRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); } } \ No newline at end of file diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java index 7add356359..7f662dc7e8 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java @@ -193,7 +193,7 @@ public class TenantServiceTest { Assert.assertEquals(Status.SUCCESS.getMsg(), result.getMsg()); // tenantCode exist result = tenantService.verifyTenantCode(getTenant().getTenantCode()); - Assert.assertTrue(result.isStatus(Status.OS_TENANT_CODE_EXIST)); + Assert.assertEquals(Status.OS_TENANT_CODE_EXIST.getCode(), result.getCode().intValue()); } /** diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageServiceTest.java index 8b00eefd81..c43a9ad395 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageServiceTest.java @@ -77,9 +77,9 @@ public class WorkFlowLineageServiceTest { public void testQueryWorkFlowLineageByName() { Project project = getProject("test"); String searchVal = "test"; - when(projectMapper.selectById(1)).thenReturn(project); + when(projectMapper.queryByCode(1L)).thenReturn(project); when(workFlowLineageMapper.queryByName(Mockito.any(), Mockito.any())).thenReturn(getWorkFlowLineages()); - Map result = workFlowLineageService.queryWorkFlowLineageByName(searchVal, 1); + Map result = workFlowLineageService.queryWorkFlowLineageByName(searchVal, 1L); List workFlowLineageList = (List) result.get(Constants.DATA_LIST); Assert.assertTrue(workFlowLineageList.size() > 0); } @@ -106,7 +106,7 @@ public class WorkFlowLineageServiceTest { WorkFlowLineage workFlowLineage = new WorkFlowLineage(); workFlowLineage.setSourceWorkFlowId(""); - when(projectMapper.selectById(1)).thenReturn(project); + when(projectMapper.queryByCode(1L)).thenReturn(project); when(workFlowLineageMapper.queryRelationByIds(ids, project.getCode())).thenReturn(processLineages); when(workFlowLineageMapper.queryCodeRelation(processLineage.getPostTaskCode() , processLineage.getPreTaskVersion() @@ -117,7 +117,7 @@ public class WorkFlowLineageServiceTest { .queryWorkFlowLineageByCode(processLineage.getProcessDefinitionCode(), processLineage.getProjectCode())) .thenReturn(workFlowLineage); - Map result = workFlowLineageService.queryWorkFlowLineageByIds(ids, 1); + Map result = workFlowLineageService.queryWorkFlowLineageByIds(ids, 1L); Map workFlowLists = (Map) result.get(Constants.DATA_LIST); Collection workFlowLineages = (Collection) workFlowLists.get(Constants.WORKFLOW_LIST); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/utils/ResultTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/utils/ResultTest.java index f8b115998d..01fb75cdf7 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/utils/ResultTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/utils/ResultTest.java @@ -31,18 +31,18 @@ public class ResultTest { HashMap map = new HashMap<>(); map.put("testdata", "test"); Result ret = Result.success(map); - Assert.assertTrue(ret.isSuccess()); + Assert.assertEquals(Status.SUCCESS.getCode(), ret.getCode().intValue()); } @Test public void error() { Result ret = Result.error(Status.ACCESS_TOKEN_NOT_EXIST); - Assert.assertTrue(ret.isStatus(Status.ACCESS_TOKEN_NOT_EXIST)); + Assert.assertEquals(Status.ACCESS_TOKEN_NOT_EXIST.getCode(), ret.getCode().intValue()); } @Test public void errorWithArgs() { Result ret = Result.errorWithArgs(Status.INTERNAL_SERVER_ERROR_ARGS, "test internal server error"); - Assert.assertTrue(ret.isStatus(Status.INTERNAL_SERVER_ERROR_ARGS)); + Assert.assertEquals(Status.INTERNAL_SERVER_ERROR_ARGS.getCode(), ret.getCode().intValue()); } } \ No newline at end of file diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java index 58c0608e7a..29169c9e46 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java @@ -437,7 +437,7 @@ public final class Constants { public static final String COMMON_TASK_TYPE = "common"; - public static final String DEFAULT = "Default"; + public static final String DEFAULT = "default"; public static final String USER = "user"; public static final String PASSWORD = "password"; public static final String XXXXXX = "******"; @@ -637,6 +637,11 @@ public final class Constants { */ public static final int DEFINITION_FAILURE = -1; + /** + * process or task definition first version + */ + public static final int VERSION_FIRST = 1; + /** * date format of yyyyMMdd */ @@ -876,7 +881,6 @@ public final class Constants { public static final String FLINK_MAIN_CLASS = "-c"; public static final String FLINK_PARALLELISM = "-p"; public static final String FLINK_SHUTDOWN_ON_ATTACHED_EXIT = "-sae"; - public static final String FLINK_PYTHON = "-py"; public static final int[] NOT_TERMINATED_STATES = new int[] { diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/Flag.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/Flag.java index 622e9d17d4..fa69f2978d 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/Flag.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/Flag.java @@ -34,8 +34,7 @@ public enum Flag { NO(0, "no"), YES(1, "yes"); - - Flag(int code, String descp){ + Flag(int code, String descp) { this.code = code; this.descp = descp; } diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/Priority.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/Priority.java index bdd7128eac..53ca3f9c74 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/Priority.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/Priority.java @@ -35,7 +35,7 @@ public enum Priority { LOW(3, "low"), LOWEST(4, "lowest"); - Priority(int code, String descp){ + Priority(int code, String descp) { this.code = code; this.descp = descp; } diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/TaskStateType.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/TaskStateType.java index bfebb912f9..36766a7f4d 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/TaskStateType.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/TaskStateType.java @@ -27,7 +27,7 @@ public enum TaskStateType { * 3 failed * 4 success */ - WAITING, RUNNING, FINISH, FAILED, SUCCESS; + WAITTING, RUNNING, FINISH, FAILED, SUCCESS; /** * convert task state to execute status integer array ; @@ -55,7 +55,7 @@ public enum TaskStateType { ExecutionStatus.DELAY_EXECUTION.ordinal(), ExecutionStatus.READY_PAUSE.ordinal(), ExecutionStatus.READY_STOP.ordinal()}; - case WAITING: + case WAITTING: return new int[]{ ExecutionStatus.SUBMITTED_SUCCESS.ordinal() }; diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/TaskTimeoutStrategy.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/TaskTimeoutStrategy.java index 335b986010..a203fd4d53 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/TaskTimeoutStrategy.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/TaskTimeoutStrategy.java @@ -28,11 +28,10 @@ public enum TaskTimeoutStrategy { * 2 warn+failed */ WARN(0, "warn"), - FAILED(1,"failed"), - WARNFAILED(2,"warnfailed"); + FAILED(1, "failed"), + WARNFAILED(2, "warnfailed"); - - TaskTimeoutStrategy(int code, String descp){ + TaskTimeoutStrategy(int code, String descp) { this.code = code; this.descp = descp; } @@ -49,9 +48,9 @@ public enum TaskTimeoutStrategy { return descp; } - public static TaskTimeoutStrategy of(int status){ - for(TaskTimeoutStrategy es : values()){ - if(es.getCode() == status){ + public static TaskTimeoutStrategy of(int status) { + for (TaskTimeoutStrategy es : values()) { + if (es.getCode() == status) { return es; } } diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java index 2a1e2ac0b0..0b1edec6df 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java @@ -159,7 +159,6 @@ public class JSONUtils { } try { - CollectionType listType = objectMapper.getTypeFactory().constructCollectionType(ArrayList.class, clazz); return objectMapper.readValue(json, listType); } catch (Exception e) { diff --git a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/task/SqlParametersTest.java b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/task/SqlParametersTest.java index 3cd3f46dbb..17e95cf9d6 100644 --- a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/task/SqlParametersTest.java +++ b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/task/SqlParametersTest.java @@ -43,7 +43,6 @@ public class SqlParametersTest { private final String showType = "TABLE"; private final String title = "sql test"; private final int groupId = 0; - private final int limit = 0; @Test public void testSqlParameters() { @@ -68,7 +67,6 @@ public class SqlParametersTest { sqlParameters.setShowType(showType); sqlParameters.setTitle(title); sqlParameters.setGroupId(groupId); - sqlParameters.setLimit(limit); Assert.assertEquals(type, sqlParameters.getType()); Assert.assertEquals(sql, sqlParameters.getSql()); @@ -80,7 +78,6 @@ public class SqlParametersTest { Assert.assertEquals(showType, sqlParameters.getShowType()); Assert.assertEquals(title, sqlParameters.getTitle()); Assert.assertEquals(groupId, sqlParameters.getGroupId()); - Assert.assertEquals(limit, sqlParameters.getLimit()); String sqlResult = "[{\"id\":6,\"test1\":\"6\"},{\"id\":70002,\"test1\":\"+1\"}]"; String sqlResult1 = "[{\"id\":6,\"test1\":\"6\"}]"; diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Command.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Command.java index 95b87be841..e3088d022b 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Command.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Command.java @@ -49,10 +49,10 @@ public class Command { private CommandType commandType; /** - * process definition id + * process definition code */ - @TableField("process_definition_id") - private int processDefinitionId; + @TableField("process_definition_code") + private long processDefinitionCode; /** * executor id @@ -138,7 +138,7 @@ public class Command { TaskDependType taskDependType, FailureStrategy failureStrategy, int executorId, - int processDefinitionId, + long processDefinitionCode, String commandParam, WarningType warningType, int warningGroupId, @@ -148,7 +148,7 @@ public class Command { Priority processInstancePriority) { this.commandType = commandType; this.executorId = executorId; - this.processDefinitionId = processDefinitionId; + this.processDefinitionCode = processDefinitionCode; this.commandParam = commandParam; this.warningType = warningType; this.warningGroupId = warningGroupId; @@ -186,12 +186,12 @@ public class Command { this.commandType = commandType; } - public int getProcessDefinitionId() { - return processDefinitionId; + public long getProcessDefinitionCode() { + return processDefinitionCode; } - public void setProcessDefinitionId(int processDefinitionId) { - this.processDefinitionId = processDefinitionId; + public void setProcessDefinitionCode(long processDefinitionCode) { + this.processDefinitionCode = processDefinitionCode; } public FailureStrategy getFailureStrategy() { @@ -296,7 +296,7 @@ public class Command { if (id != command.id) { return false; } - if (processDefinitionId != command.processDefinitionId) { + if (processDefinitionCode != command.processDefinitionCode) { return false; } if (executorId != command.executorId) { @@ -345,7 +345,7 @@ public class Command { public int hashCode() { int result = id; result = 31 * result + (commandType != null ? commandType.hashCode() : 0); - result = 31 * result + processDefinitionId; + result = 31 * result + Long.hashCode(processDefinitionCode); result = 31 * result + executorId; result = 31 * result + (commandParam != null ? commandParam.hashCode() : 0); result = 31 * result + (taskDependType != null ? taskDependType.hashCode() : 0); @@ -366,7 +366,7 @@ public class Command { return "Command{" + "id=" + id + ", commandType=" + commandType - + ", processDefinitionId=" + processDefinitionId + + ", processDefinitionCode=" + processDefinitionCode + ", executorId=" + executorId + ", commandParam='" + commandParam + '\'' + ", taskDependType=" + taskDependType diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/DagData.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/DagData.java new file mode 100644 index 0000000000..e66d4d09e0 --- /dev/null +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/DagData.java @@ -0,0 +1,74 @@ +/* + * 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 java.util.List; + +/** + * DagData + */ +public class DagData { + + /** + * processDefinition + */ + private ProcessDefinition processDefinition; + + /** + * processTaskRelationList + */ + private List processTaskRelationList; + + /** + * processTaskRelationList + */ + private List taskDefinitionList; + + public DagData(ProcessDefinition processDefinition, List processTaskRelationList, List taskDefinitionList) { + this.processDefinition = processDefinition; + this.processTaskRelationList = processTaskRelationList; + this.taskDefinitionList = taskDefinitionList; + } + + public DagData() { + } + + public ProcessDefinition getProcessDefinition() { + return processDefinition; + } + + public void setProcessDefinition(ProcessDefinition processDefinition) { + this.processDefinition = processDefinition; + } + + public List getProcessTaskRelationList() { + return processTaskRelationList; + } + + public void setProcessTaskRelationList(List processTaskRelationList) { + this.processTaskRelationList = processTaskRelationList; + } + + public List getTaskDefinitionList() { + return taskDefinitionList; + } + + public void setTaskDefinitionList(List taskDefinitionList) { + this.taskDefinitionList = taskDefinitionList; + } +} diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ErrorCommand.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ErrorCommand.java index 6444ee5663..d03570d9e8 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ErrorCommand.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ErrorCommand.java @@ -48,9 +48,9 @@ public class ErrorCommand { private CommandType commandType; /** - * process definition id + * process definition code */ - private int processDefinitionId; + private long processDefinitionCode; /** * executor id @@ -126,7 +126,7 @@ public class ErrorCommand { this.id = command.getId(); this.commandType = command.getCommandType(); this.executorId = command.getExecutorId(); - this.processDefinitionId = command.getProcessDefinitionId(); + this.processDefinitionCode = command.getProcessDefinitionCode(); this.commandParam = command.getCommandParam(); this.warningType = command.getWarningType(); this.warningGroupId = command.getWarningGroupId(); @@ -140,33 +140,6 @@ public class ErrorCommand { this.message = message; } - public ErrorCommand( - CommandType commandType, - TaskDependType taskDependType, - FailureStrategy failureStrategy, - int executorId, - int processDefinitionId, - String commandParam, - WarningType warningType, - int warningGroupId, - Date scheduleTime, - Priority processInstancePriority, - String message) { - this.commandType = commandType; - this.executorId = executorId; - this.processDefinitionId = processDefinitionId; - this.commandParam = commandParam; - this.warningType = warningType; - this.warningGroupId = warningGroupId; - this.scheduleTime = scheduleTime; - this.taskDependType = taskDependType; - this.failureStrategy = failureStrategy; - this.startTime = new Date(); - this.updateTime = new Date(); - this.processInstancePriority = processInstancePriority; - this.message = message; - } - public TaskDependType getTaskDependType() { return taskDependType; } @@ -191,12 +164,12 @@ public class ErrorCommand { this.commandType = commandType; } - public int getProcessDefinitionId() { - return processDefinitionId; + public long getProcessDefinitionCode() { + return processDefinitionCode; } - public void setProcessDefinitionId(int processDefinitionId) { - this.processDefinitionId = processDefinitionId; + public void setProcessDefinitionCode(long processDefinitionCode) { + this.processDefinitionCode = processDefinitionCode; } public FailureStrategy getFailureStrategy() { @@ -300,7 +273,7 @@ public class ErrorCommand { return "ErrorCommand{" + "id=" + id + ", commandType=" + commandType - + ", processDefinitionId=" + processDefinitionId + + ", processDefinitionCode=" + processDefinitionCode + ", executorId=" + executorId + ", commandParam='" + commandParam + '\'' + ", taskDependType=" + taskDependType diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java index 98fe7eec04..8e50ce8a68 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; import com.baomidou.mybatisplus.annotation.IdType; @@ -35,7 +36,6 @@ import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.fasterxml.jackson.annotation.JsonFormat; - /** * process definition */ @@ -51,7 +51,7 @@ public class ProcessDefinition { /** * code */ - private Long code; + private long code; /** * name @@ -68,24 +68,10 @@ public class ProcessDefinition { */ private ReleaseState releaseState; - /** - * project id - * TODO: delete - */ - @TableField(exist = false) - private int projectId; - /** * project code */ - private Long projectCode; - - /** - * definition json string - * TODO: delete - */ - @TableField(exist = false) - private String processDefinitionJson; + private long projectCode; /** * description @@ -148,12 +134,6 @@ public class ProcessDefinition { */ private String locations; - /** - * connects array for web - * TODO: delete - */ - private String connects; - /** * schedule release state : online/offline */ @@ -170,6 +150,12 @@ public class ProcessDefinition { */ private int tenantId; + /** + * tenant code + */ + @TableField(exist = false) + private String tenantCode; + /** * modify user name */ @@ -188,7 +174,42 @@ public class ProcessDefinition { @TableField(exist = false) private int warningGroupId; - public ProcessDefinition(){} + public ProcessDefinition() { + } + + public ProcessDefinition(long projectCode, + String name, + long code, + String description, + String globalParams, + String locations, + int timeout, + int userId, + int tenantId) { + set(projectCode, name, description, globalParams, locations, timeout, tenantId); + this.code = code; + this.userId = userId; + Date date = new Date(); + this.createTime = date; + this.updateTime = date; + } + + public void set(long projectCode, + String name, + String description, + String globalParams, + String locations, + int timeout, + int tenantId) { + this.projectCode = projectCode; + this.name = name; + this.description = description; + this.globalParams = globalParams; + this.locations = locations; + this.timeout = timeout; + this.tenantId = tenantId; + this.flag = Flag.YES; + } public String getName() { return name; @@ -222,14 +243,6 @@ public class ProcessDefinition { this.releaseState = releaseState; } - public String getProcessDefinitionJson() { - return processDefinitionJson; - } - - public void setProcessDefinitionJson(String processDefinitionJson) { - this.processDefinitionJson = processDefinitionJson; - } - public Date getCreateTime() { return createTime; } @@ -238,14 +251,6 @@ public class ProcessDefinition { this.createTime = createTime; } - public int getProjectId() { - return projectId; - } - - public void setProjectId(int projectId) { - this.projectId = projectId; - } - public Date getUpdateTime() { return updateTime; } @@ -291,10 +296,9 @@ public class ProcessDefinition { } public void setGlobalParams(String globalParams) { - if (globalParams == null) { + this.globalParamList = JSONUtils.toList(globalParams, Property.class); + if (this.globalParamList == null) { this.globalParamList = new ArrayList<>(); - } else { - this.globalParamList = JSONUtils.toList(globalParams, Property.class); } this.globalParams = globalParams; } @@ -304,7 +308,6 @@ public class ProcessDefinition { } public void setGlobalParamList(List globalParamList) { - this.globalParams = JSONUtils.toJsonString(globalParamList); this.globalParamList = globalParamList; } @@ -329,14 +332,6 @@ public class ProcessDefinition { this.locations = locations; } - public String getConnects() { - return connects; - } - - public void setConnects(String connects) { - this.connects = connects; - } - public ReleaseState getScheduleReleaseState() { return scheduleReleaseState; } @@ -369,6 +364,14 @@ public class ProcessDefinition { this.tenantId = tenantId; } + public String getTenantCode() { + return tenantCode; + } + + public void setTenantCode(String tenantCode) { + this.tenantCode = tenantCode; + } + public String getDescription() { return description; } @@ -385,19 +388,19 @@ public class ProcessDefinition { this.modifyBy = modifyBy; } - public Long getCode() { + public long getCode() { return code; } - public void setCode(Long code) { + public void setCode(long code) { this.code = code; } - public Long getProjectCode() { + public long getProjectCode() { return projectCode; } - public void setProjectCode(Long projectCode) { + public void setProjectCode(long projectCode) { this.projectCode = projectCode; } @@ -409,17 +412,36 @@ public class ProcessDefinition { this.warningGroupId = warningGroupId; } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ProcessDefinition that = (ProcessDefinition) o; + return projectCode == that.projectCode + && userId == that.userId + && timeout == that.timeout + && tenantId == that.tenantId + && Objects.equals(name, that.name) + && releaseState == that.releaseState + && Objects.equals(description, that.description) + && Objects.equals(globalParams, that.globalParams) + && flag == that.flag + && Objects.equals(locations, that.locations); + } + @Override public String toString() { return "ProcessDefinition{" + "id=" + id - + ", name='" + name + '\'' + ", code=" + code + + ", name='" + name + '\'' + ", version=" + version + ", releaseState=" + releaseState - + ", projectId=" + projectId + ", projectCode=" + projectCode - + ", processDefinitionJson='" + processDefinitionJson + '\'' + ", description='" + description + '\'' + ", globalParams='" + globalParams + '\'' + ", globalParamList=" + globalParamList @@ -431,13 +453,13 @@ public class ProcessDefinition { + ", userName='" + userName + '\'' + ", projectName='" + projectName + '\'' + ", locations='" + locations + '\'' - + ", connects='" + connects + '\'' + ", scheduleReleaseState=" + scheduleReleaseState + ", timeout=" + timeout - + ", warningGroupId=" + warningGroupId + ", tenantId=" + tenantId + + ", tenantCode='" + tenantCode + '\'' + ", modifyBy='" + modifyBy + '\'' + ", resourceIds='" + resourceIds + '\'' + + ", warningGroupId=" + warningGroupId + '}'; } } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinitionLog.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinitionLog.java index fcd773d3a3..30840e8602 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinitionLog.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinitionLog.java @@ -61,7 +61,6 @@ public class ProcessDefinitionLog extends ProcessDefinition { this.setUserName(processDefinition.getUserName()); this.setProjectName(processDefinition.getProjectName()); this.setLocations(processDefinition.getLocations()); - this.setConnects(processDefinition.getConnects()); this.setScheduleReleaseState(processDefinition.getScheduleReleaseState()); this.setTimeout(processDefinition.getTimeout()); this.setTenantId(processDefinition.getTenantId()); @@ -86,4 +85,8 @@ public class ProcessDefinitionLog extends ProcessDefinition { this.operateTime = operateTime; } + @Override + public boolean equals(Object o) { + return super.equals(o); + } } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstance.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstance.java index cb1eab69c9..693f019e4a 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstance.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstance.java @@ -151,11 +151,10 @@ public class ProcessInstance { private String globalParams; /** - * process instance json - * TODO delete + * dagData */ @TableField(exist = false) - private String processInstanceJson; + private DagData dagData; /** * executor id @@ -191,12 +190,6 @@ public class ProcessInstance { @TableField(exist = false) private String locations; - /** - * task connects for web - */ - @TableField(exist = false) - private String connects; - /** * history command */ @@ -258,12 +251,12 @@ public class ProcessInstance { public ProcessInstance(ProcessDefinition processDefinition) { this.processDefinition = processDefinition; this.name = processDefinition.getName() - + "-" - + - processDefinition.getVersion() - + "-" - + - DateUtils.getCurrentTimeStamp(); + + "-" + + + processDefinition.getVersion() + + "-" + + + DateUtils.getCurrentTimeStamp(); } public String getVarPool() { @@ -430,12 +423,12 @@ public class ProcessInstance { this.globalParams = globalParams; } - public String getProcessInstanceJson() { - return processInstanceJson; + public DagData getDagData() { + return dagData; } - public void setProcessInstanceJson(String processInstanceJson) { - this.processInstanceJson = processInstanceJson; + public void setDagData(DagData dagData) { + this.dagData = dagData; } public String getTenantCode() { @@ -486,14 +479,6 @@ public class ProcessInstance { this.locations = locations; } - public String getConnects() { - return connects; - } - - public void setConnects(String connects) { - this.connects = connects; - } - public String getHistoryCmd() { return historyCmd; } @@ -615,83 +600,75 @@ public class ProcessInstance { @Override public String toString() { return "ProcessInstance{" - + "id=" + id - + ", state=" + state - + ", recovery=" + recovery - + ", startTime=" + startTime - + ", endTime=" + endTime - + ", runTimes=" + runTimes - + ", name='" + name + '\'' - + ", host='" + host + '\'' - + ", processDefinition=" - + processDefinition - + ", commandType=" - + commandType - + ", commandParam='" - + commandParam - + '\'' - + ", taskDependType=" - + taskDependType - + ", maxTryTimes=" - + maxTryTimes - + ", failureStrategy=" - + failureStrategy - + ", warningType=" - + warningType - + ", warningGroupId=" - + warningGroupId - + ", scheduleTime=" - + scheduleTime - + ", commandStartTime=" - + commandStartTime - + ", globalParams='" - + globalParams - + '\'' - + ", processInstanceJson='" - + processInstanceJson - + '\'' - + ", executorId=" - + executorId - + ", tenantCode='" - + tenantCode - + '\'' - + ", queue='" - + queue - + '\'' - + ", isSubProcess=" - + isSubProcess - + ", locations='" - + locations - + '\'' - + ", connects='" - + connects - + '\'' - + ", historyCmd='" - + historyCmd - + '\'' - + ", dependenceScheduleTimes='" - + dependenceScheduleTimes - + '\'' - + ", duration=" - + duration - + ", processInstancePriority=" - + processInstancePriority - + ", workerGroup='" - + workerGroup - + '\'' - + ", environmentCode=" - + environmentCode - + ", timeout=" - + timeout - + ", tenantId=" - + tenantId - + ", processDefinitionCode='" - + processDefinitionCode - + '\'' - + ", processDefinitionVersion='" - + processDefinitionVersion - + '\'' - + '}'; + + "id=" + id + + ", state=" + state + + ", recovery=" + recovery + + ", startTime=" + startTime + + ", endTime=" + endTime + + ", runTimes=" + runTimes + + ", name='" + name + '\'' + + ", host='" + host + '\'' + + ", processDefinition=" + + processDefinition + + ", commandType=" + + commandType + + ", commandParam='" + + commandParam + + '\'' + + ", taskDependType=" + + taskDependType + + ", maxTryTimes=" + + maxTryTimes + + ", failureStrategy=" + + failureStrategy + + ", warningType=" + + warningType + + ", warningGroupId=" + + warningGroupId + + ", scheduleTime=" + + scheduleTime + + ", commandStartTime=" + + commandStartTime + + ", globalParams='" + + globalParams + + '\'' + + ", executorId=" + + executorId + + ", tenantCode='" + + tenantCode + + '\'' + + ", queue='" + + queue + + '\'' + + ", isSubProcess=" + + isSubProcess + + ", locations='" + + locations + + '\'' + + ", historyCmd='" + + historyCmd + + '\'' + + ", dependenceScheduleTimes='" + + dependenceScheduleTimes + + '\'' + + ", duration=" + + duration + + ", processInstancePriority=" + + processInstancePriority + + ", workerGroup='" + + workerGroup + + '\'' + + ", timeout=" + + timeout + + ", tenantId=" + + tenantId + + ", processDefinitionCode='" + + processDefinitionCode + + '\'' + + ", processDefinitionVersion='" + + processDefinitionVersion + + '\'' + + '}'; } @Override diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelation.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelation.java index 1dae5d8a42..06f7cd0344 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelation.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelation.java @@ -18,13 +18,17 @@ package org.apache.dolphinscheduler.dao.entity; import org.apache.dolphinscheduler.common.enums.ConditionType; +import org.apache.dolphinscheduler.common.utils.JSONUtils; import java.util.Date; +import java.util.Objects; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; /** * process task relation @@ -86,6 +90,8 @@ public class ProcessTaskRelation { /** * condition parameters */ + @JsonDeserialize(using = JSONUtils.JsonDataDeserializer.class) + @JsonSerialize(using = JSONUtils.JsonDataSerializer.class) private String conditionParams; /** @@ -233,22 +239,46 @@ public class ProcessTaskRelation { this.postTaskVersion = postTaskVersion; } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ProcessTaskRelation that = (ProcessTaskRelation) o; + return processDefinitionVersion == that.processDefinitionVersion + && projectCode == that.projectCode + && processDefinitionCode == that.processDefinitionCode + && preTaskCode == that.preTaskCode + && preTaskVersion == that.preTaskVersion + && postTaskCode == that.postTaskCode + && postTaskVersion == that.postTaskVersion + && Objects.equals(name, that.name); + } + + @Override + public int hashCode() { + return Objects.hash(name, processDefinitionVersion, projectCode, processDefinitionCode, preTaskCode, preTaskVersion, postTaskCode, postTaskVersion); + } + @Override public String toString() { return "ProcessTaskRelation{" - + "id=" + id - + ", name='" + name + '\'' - + ", processDefinitionVersion=" + processDefinitionVersion - + ", projectCode=" + projectCode - + ", processDefinitionCode=" + processDefinitionCode - + ", preTaskCode=" + preTaskCode - + ", preTaskVersion=" + preTaskVersion - + ", postTaskCode=" + postTaskCode - + ", postTaskVersion=" + postTaskVersion - + ", conditionType=" + conditionType - + ", conditionParams='" + conditionParams + '\'' - + ", createTime=" + createTime - + ", updateTime=" + updateTime - + '}'; + + "id=" + id + + ", name='" + name + '\'' + + ", processDefinitionVersion=" + processDefinitionVersion + + ", projectCode=" + projectCode + + ", processDefinitionCode=" + processDefinitionCode + + ", preTaskCode=" + preTaskCode + + ", preTaskVersion=" + preTaskVersion + + ", postTaskCode=" + postTaskCode + + ", postTaskVersion=" + postTaskVersion + + ", conditionType=" + conditionType + + ", conditionParams='" + conditionParams + '\'' + + ", createTime=" + createTime + + ", updateTime=" + updateTime + + '}'; } } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelationLog.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelationLog.java index 34dc027b57..28e89e5848 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelationLog.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelationLog.java @@ -76,6 +76,16 @@ public class ProcessTaskRelationLog extends ProcessTaskRelation { this.operateTime = operateTime; } + @Override + public boolean equals(Object o) { + return super.equals(o); + } + + @Override + public int hashCode() { + return super.hashCode(); + } + @Override public String toString() { return super.toString(); diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Project.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Project.java index ad173b8547..82e5cd7a8f 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Project.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Project.java @@ -50,7 +50,7 @@ public class Project { /** * project code */ - private Long code; + private long code; /** * project name @@ -90,11 +90,11 @@ public class Project { @TableField(exist = false) private int instRunningCount; - public Long getCode() { + public long getCode() { return code; } - public void setCode(Long code) { + public void setCode(long code) { this.code = code; } @@ -228,7 +228,7 @@ public class Project { private int id; private int userId; private String userName; - private Long code; + private long code; private String name; private String description; private Date createTime; @@ -240,7 +240,7 @@ public class Project { private Builder() { } - public Builder code(Long code) { + public Builder code(long code) { this.code = code; return this; } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Schedule.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Schedule.java index 39b5bcda06..0d2ea9eca8 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Schedule.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Schedule.java @@ -39,10 +39,11 @@ public class Schedule { @TableId(value = "id", type = IdType.AUTO) private int id; + /** - * process definition id + * process definition code */ - private int processDefinitionId; + private long processDefinitionCode; /** * process definition name @@ -227,12 +228,12 @@ public class Schedule { this.releaseState = releaseState; } - public int getProcessDefinitionId() { - return processDefinitionId; + public long getProcessDefinitionCode() { + return processDefinitionCode; } - public void setProcessDefinitionId(int processDefinitionId) { - this.processDefinitionId = processDefinitionId; + public void setProcessDefinitionCode(long processDefinitionCode) { + this.processDefinitionCode = processDefinitionCode; } public String getProcessDefinitionName() { @@ -303,7 +304,7 @@ public class Schedule { public String toString() { return "Schedule{" + "id=" + id - + ", processDefinitionId=" + processDefinitionId + + ", processDefinitionCode=" + processDefinitionCode + ", processDefinitionName='" + processDefinitionName + '\'' + ", projectName='" + projectName + '\'' + ", description='" + definitionDescription + '\'' diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskDefinition.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskDefinition.java index 8f1d75284e..2b27fc4631 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskDefinition.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskDefinition.java @@ -17,6 +17,7 @@ package org.apache.dolphinscheduler.dao.entity; +import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.enums.Flag; import org.apache.dolphinscheduler.common.enums.Priority; import org.apache.dolphinscheduler.common.enums.TaskTimeoutStrategy; @@ -27,6 +28,7 @@ import org.apache.dolphinscheduler.common.utils.JSONUtils; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; import com.baomidou.mybatisplus.annotation.IdType; @@ -36,6 +38,8 @@ import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; /** * task definition @@ -87,6 +91,8 @@ public class TaskDefinition { /** * user defined parameters */ + @JsonDeserialize(using = JSONUtils.JsonDataDeserializer.class) + @JsonSerialize(using = JSONUtils.JsonDataSerializer.class) private String taskParams; /** @@ -180,6 +186,12 @@ public class TaskDefinition { @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date updateTime; + /** + * modify user name + */ + @TableField(exist = false) + private String modifyBy; + public TaskDefinition() { } @@ -400,6 +412,18 @@ public class TaskDefinition { this.delayTime = delayTime; } + public String getDependence() { + return JSONUtils.getNodeString(this.taskParams, Constants.DEPENDENCE); + } + + public String getModifyBy() { + return modifyBy; + } + + public void setModifyBy(String modifyBy) { + this.modifyBy = modifyBy; + } + public Long getEnvironmentCode() { return this.environmentCode; } @@ -408,35 +432,57 @@ public class TaskDefinition { this.environmentCode = environmentCode; } + @Override + public boolean equals(Object o) { + if (o == null) { + return false; + } + TaskDefinition that = (TaskDefinition) o; + return failRetryTimes == that.failRetryTimes + && failRetryInterval == that.failRetryInterval + && timeout == that.timeout + && delayTime == that.delayTime + && Objects.equals(name, that.name) + && Objects.equals(description, that.description) + && Objects.equals(taskType, that.taskType) + && Objects.equals(taskParams, that.taskParams) + && flag == that.flag + && taskPriority == that.taskPriority + && Objects.equals(workerGroup, that.workerGroup) + && timeoutFlag == that.timeoutFlag + && timeoutNotifyStrategy == that.timeoutNotifyStrategy + && Objects.equals(resourceIds, that.resourceIds); + } + @Override public String toString() { return "TaskDefinition{" - + "id=" + id - + ", code=" + code - + ", name='" + name + '\'' - + ", version=" + version - + ", description='" + description + '\'' - + ", projectCode=" + projectCode - + ", userId=" + userId - + ", taskType=" + taskType - + ", taskParams='" + taskParams + '\'' - + ", taskParamList=" + taskParamList - + ", taskParamMap=" + taskParamMap - + ", flag=" + flag - + ", taskPriority=" + taskPriority - + ", userName='" + userName + '\'' - + ", projectName='" + projectName + '\'' - + ", workerGroup='" + workerGroup + '\'' - + ", environmentCode='" + environmentCode + '\'' - + ", failRetryTimes=" + failRetryTimes - + ", failRetryInterval=" + failRetryInterval - + ", timeoutFlag=" + timeoutFlag - + ", timeoutNotifyStrategy=" + timeoutNotifyStrategy - + ", timeout=" + timeout - + ", delayTime=" + delayTime - + ", resourceIds='" + resourceIds + '\'' - + ", createTime=" + createTime - + ", updateTime=" + updateTime - + '}'; + + "id=" + id + + ", code=" + code + + ", name='" + name + '\'' + + ", version=" + version + + ", description='" + description + '\'' + + ", projectCode=" + projectCode + + ", userId=" + userId + + ", taskType=" + taskType + + ", taskParams='" + taskParams + '\'' + + ", taskParamList=" + taskParamList + + ", taskParamMap=" + taskParamMap + + ", flag=" + flag + + ", taskPriority=" + taskPriority + + ", userName='" + userName + '\'' + + ", projectName='" + projectName + '\'' + + ", workerGroup='" + workerGroup + '\'' + + ", failRetryTimes=" + failRetryTimes + + ", environmentCode='" + environmentCode + '\'' + + ", failRetryInterval=" + failRetryInterval + + ", timeoutFlag=" + timeoutFlag + + ", timeoutNotifyStrategy=" + timeoutNotifyStrategy + + ", timeout=" + timeout + + ", delayTime=" + delayTime + + ", resourceIds='" + resourceIds + '\'' + + ", createTime=" + createTime + + ", updateTime=" + updateTime + + '}'; } } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskDefinitionLog.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskDefinitionLog.java index 41713fc642..55b8bfbcd2 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskDefinitionLog.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskDefinitionLog.java @@ -71,6 +71,7 @@ public class TaskDefinitionLog extends TaskDefinition { this.setFailRetryInterval(taskDefinition.getFailRetryInterval()); this.setFailRetryTimes(taskDefinition.getFailRetryTimes()); this.setFlag(taskDefinition.getFlag()); + this.setModifyBy(taskDefinition.getModifyBy()); } public int getOperator() { @@ -89,6 +90,16 @@ public class TaskDefinitionLog extends TaskDefinition { this.operateTime = operateTime; } + @Override + public boolean equals(Object o) { + return super.equals(o); + } + + @Override + public int hashCode() { + return super.hashCode(); + } + @Override public String toString() { return super.toString(); diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.java index 4511051a43..038ed5d2f6 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.java @@ -36,56 +36,53 @@ public interface ProcessDefinitionLogMapper extends BaseMapper queryByDefinitionName(@Param("projectCode") Long projectCode, - @Param("processDefinitionName") String name); + List queryByDefinitionName(@Param("projectCode") long projectCode, @Param("name") String name); /** * query process definition log list * - * @param processDefinitionCode processDefinitionCode + * @param code process definition code * @return process definition log list */ - List queryByDefinitionCode(@Param("processDefinitionCode") long processDefinitionCode); + List queryByDefinitionCode(@Param("code") long code); /** * query max version for definition */ - Integer queryMaxVersionForDefinition(@Param("processDefinitionCode") long processDefinitionCode); + Integer queryMaxVersionForDefinition(@Param("code") long code); /** * query max version definition log */ - ProcessDefinitionLog queryMaxVersionDefinitionLog(@Param("processDefinitionCode") long processDefinitionCode); + ProcessDefinitionLog queryMaxVersionDefinitionLog(@Param("code") long code); /** * query the certain process definition version info by process definition code and version number * - * @param processDefinitionCode process definition code + * @param code process definition code * @param version version number * @return the process definition version info */ - ProcessDefinitionLog queryByDefinitionCodeAndVersion(@Param("processDefinitionCode") Long processDefinitionCode, - @Param("version") long version); - + ProcessDefinitionLog queryByDefinitionCodeAndVersion(@Param("code") long code, @Param("version") int version); + /** * query the paging process definition version list by pagination info * * @param page pagination info - * @param processDefinitionCode process definition code + * @param code process definition code * @return the paging process definition version list */ - IPage queryProcessDefinitionVersionsPaging(Page page, - @Param("processDefinitionCode") Long processDefinitionCode); + IPage queryProcessDefinitionVersionsPaging(Page page, @Param("code") long code); /** * delete the certain process definition version by process definition id and version number * - * @param processDefinitionCode process definition code + * @param code process definition code * @param version version number * @return delete result */ - int deleteByProcessDefinitionCodeAndVersion(@Param("processDefinitionCode") Long processDefinitionCode, @Param("version") long version); + int deleteByProcessDefinitionCodeAndVersion(@Param("code") long code, @Param("version") int version); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java index 45dfc3d84b..3a731ea1fb 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java @@ -43,7 +43,7 @@ public interface ProcessDefinitionMapper extends BaseMapper { * @param code code * @return process definition */ - ProcessDefinition queryByCode(@Param("code") Long code); + ProcessDefinition queryByCode(@Param("code") long code); /** * query process definition by code list @@ -59,8 +59,8 @@ public interface ProcessDefinitionMapper extends BaseMapper { * @param code code * @return delete result */ - int deleteByCode(@Param("code") Long code); - + int deleteByCode(@Param("code") long code); + /** * verify process definition by name * @@ -68,8 +68,8 @@ public interface ProcessDefinitionMapper extends BaseMapper { * @param name name * @return process definition */ - ProcessDefinition verifyByDefineName(@Param("projectCode") Long projectCode, - @Param("processDefinitionName") String name); + ProcessDefinition verifyByDefineName(@Param("projectCode") long projectCode, + @Param("processDefinitionName") String name); /** * query process definition by name @@ -78,7 +78,7 @@ public interface ProcessDefinitionMapper extends BaseMapper { * @param name name * @return process definition */ - ProcessDefinition queryByDefineName(@Param("projectCode") Long projectCode, + ProcessDefinition queryByDefineName(@Param("projectCode") long projectCode, @Param("processDefinitionName") String name); /** @@ -102,7 +102,7 @@ public interface ProcessDefinitionMapper extends BaseMapper { IPage queryDefineListPaging(IPage page, @Param("searchVal") String searchVal, @Param("userId") int userId, - @Param("projectCode") Long projectCode, + @Param("projectCode") long projectCode, @Param("isAdmin") boolean isAdmin); /** @@ -111,7 +111,7 @@ public interface ProcessDefinitionMapper extends BaseMapper { * @param projectCode projectCode * @return process definition list */ - List queryAllDefinitionList(@Param("projectCode") Long projectCode); + List queryAllDefinitionList(@Param("projectCode") long projectCode); /** * query process definition by ids @@ -158,35 +158,10 @@ public interface ProcessDefinitionMapper extends BaseMapper { @MapKey("id") List> listResourcesByUser(@Param("userId") Integer userId); - /** - * update process definition version by process definitionId - * - * @param processDefinitionId process definition id - * @param version version - */ - void updateVersionByProcessDefinitionId(@Param("processDefinitionId") int processDefinitionId, @Param("version") long version); - /** * list all project ids + * * @return project ids list */ List listProjectIds(); - - - /** - * query the paging process definition version list by pagination info - * - * @param page pagination info - * @param processDefinitionCode process definition code - * @return the paging process definition version list - */ - IPage queryProcessDefinitionVersionsPaging(Page page, - @Param("processDefinitionCode") Long processDefinitionCode); - /** - * query has associated definition by id and version - * @param processDefinitionId process definition id - * @param version version - * @return definition id - */ - Integer queryHasAssociatedDefinitionByIdAndVersion(@Param("processDefinitionId") int processDefinitionId, @Param("version") long version); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapper.java index 9183b0f624..e735a1cff7 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapper.java @@ -40,8 +40,11 @@ public interface ProcessTaskRelationLogMapper extends BaseMapper queryByProcessCodeAndVersion(@Param("processCode") long processCode, @Param("processVersion") int processVersion); - List queryByTaskRelationList(@Param("processCode") long processCode, - @Param("processVersion") int processVersion, - @Param("taskCode") long taskCode, - @Param("taskVersion") long taskVersion); + /** + * batch insert process task relation + * + * @param taskRelationList taskRelationList + * @return int + */ + int batchInsert(@Param("taskRelationList") List taskRelationList); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.java index 5334606ed4..c9c3a8aac3 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.java @@ -18,6 +18,7 @@ package org.apache.dolphinscheduler.dao.mapper; import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation; +import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog; import org.apache.ibatis.annotations.Param; @@ -37,8 +38,8 @@ public interface ProcessTaskRelationMapper extends BaseMapper queryByProcessCode(@Param("projectCode") Long projectCode, - @Param("processCode") Long processCode); + List queryByProcessCode(@Param("projectCode") long projectCode, + @Param("processCode") long processCode); /** * process task relation by taskCode @@ -54,7 +55,7 @@ public interface ProcessTaskRelationMapper extends BaseMapper queryByTaskCode(@Param("taskCode") Long taskCode); + List queryByTaskCode(@Param("taskCode") long taskCode); /** * delete process task relation by processCode @@ -63,6 +64,14 @@ public interface ProcessTaskRelationMapper extends BaseMapper taskRelationList); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.java index ecc57a15ec..509fedbe2f 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.java @@ -36,7 +36,7 @@ public interface ProjectMapper extends BaseMapper { * @param projectCode projectCode * @return project */ - Project queryByCode(@Param("projectCode") Long projectCode); + Project queryByCode(@Param("projectCode") long projectCode); /** * TODO: delete @@ -51,7 +51,7 @@ public interface ProjectMapper extends BaseMapper { * @param projectCode projectCode * @return project */ - Project queryDetailByCode(@Param("projectCode") Long projectCode); + Project queryDetailByCode(@Param("projectCode") long projectCode); /** * query project by name @@ -118,5 +118,4 @@ public interface ProjectMapper extends BaseMapper { * @return projectList */ List queryAllProject(); - } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.java index 225677d152..37fae5d393 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.java @@ -17,12 +17,14 @@ package org.apache.dolphinscheduler.dao.mapper; import org.apache.dolphinscheduler.dao.entity.Schedule; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.core.metadata.IPage; + import org.apache.ibatis.annotations.Param; import java.util.List; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; + /** * scheduler mapper interface */ @@ -31,13 +33,13 @@ public interface ScheduleMapper extends BaseMapper { /** * scheduler page * @param page page - * @param processDefinitionId processDefinitionId + * @param processDefinitionCode processDefinitionCode * @param searchVal searchVal * @return scheduler IPage */ - IPage queryByProcessDefineIdPaging(IPage page, - @Param("processDefinitionId") int processDefinitionId, - @Param("searchVal") String searchVal); + IPage queryByProcessDefineCodePaging(IPage page, + @Param("processDefinitionCode") long processDefinitionCode, + @Param("searchVal") String searchVal); /** * query schedule list by project name @@ -47,24 +49,24 @@ public interface ScheduleMapper extends BaseMapper { List querySchedulerListByProjectName(@Param("projectName") String projectName); /** - * query schedule list by process definition ids - * @param processDefineIds processDefineIds + * query schedule list by process definition codes + * @param processDefineCodes processDefineCodes * @return schedule list */ - List selectAllByProcessDefineArray(@Param("processDefineIds") int[] processDefineIds); + List selectAllByProcessDefineArray(@Param("processDefineCodes") long[] processDefineCodes); /** - * query schedule list by process definition id - * @param processDefinitionId processDefinitionId + * query schedule list by process definition code + * @param processDefinitionCode processDefinitionCode * @return schedule list */ - List queryByProcessDefinitionId(@Param("processDefinitionId") int processDefinitionId); + List queryByProcessDefinitionCode(@Param("processDefinitionCode") long processDefinitionCode); /** - * query schedule list by process definition id - * @param processDefinitionId processDefinitionId + * query schedule list by process definition code + * @param processDefinitionCode processDefinitionCode * @return schedule list */ - List queryReleaseSchedulerListByProcessDefinitionId(@Param("processDefinitionId") int processDefinitionId); + List queryReleaseSchedulerListByProcessDefinitionCode(@Param("processDefinitionCode") long processDefinitionCode); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapper.java index 1ad40e0124..70ca9f70c3 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapper.java @@ -26,45 +26,60 @@ import java.util.Collection; import java.util.List; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; /** * task definition log mapper interface */ public interface TaskDefinitionLogMapper extends BaseMapper { - /** - * query task definition log by name - * - * @param projectCode projectCode - * @param name name - * @return task definition log list - */ - List queryByDefinitionName(@Param("projectCode") Long projectCode, - @Param("taskDefinitionName") String name); - /** * query max version for definition * - * @param taskDefinitionCode taskDefinitionCode + * @param code taskDefinitionCode */ - Integer queryMaxVersionForDefinition(@Param("taskDefinitionCode") long taskDefinitionCode); + Integer queryMaxVersionForDefinition(@Param("code") long code); /** * query task definition log * - * @param taskDefinitionCode taskDefinitionCode + * @param code taskDefinitionCode * @param version version * @return task definition log */ - TaskDefinitionLog queryByDefinitionCodeAndVersion(@Param("taskDefinitionCode") long taskDefinitionCode, + TaskDefinitionLog queryByDefinitionCodeAndVersion(@Param("code") long code, @Param("version") int version); - /** - * - * @param taskDefinitions - * @return + * @param taskDefinitions taskDefinition list + * @return list */ List queryByTaskDefinitions(@Param("taskDefinitions") Collection taskDefinitions); + /** + * batch insert task definition logs + * + * @param taskDefinitionLogs taskDefinitionLogs + * @return int + */ + int batchInsert(@Param("taskDefinitionLogs") List taskDefinitionLogs); + + /** + * delete the certain task definition version by task definition code and version + * + * @param code task definition code + * @param version task definition version + * @return delete result + */ + int deleteByCodeAndVersion(@Param("code") long code, @Param("version") int version); + + /** + * query the paging task definition version list by pagination info + * + * @param page pagination info + * @param code process definition code + * @return the paging task definition version list + */ + IPage queryTaskDefinitionVersionsPaging(Page page, @Param("code") long code); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.java index b200d9a523..68400999fc 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.java @@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.dao.mapper; import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser; import org.apache.dolphinscheduler.dao.entity.TaskDefinition; +import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.Param; @@ -27,6 +28,7 @@ import java.util.List; import java.util.Map; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; /** * task definition mapper interface @@ -40,24 +42,16 @@ public interface TaskDefinitionMapper extends BaseMapper { * @param name name * @return task definition */ - TaskDefinition queryByDefinitionName(@Param("projectCode") Long projectCode, - @Param("taskDefinitionName") String name); - - /** - * query task definition by id - * - * @param taskDefinitionId taskDefinitionId - * @return task definition - */ - TaskDefinition queryByDefinitionId(@Param("taskDefinitionId") int taskDefinitionId); + TaskDefinition queryByName(@Param("projectCode") long projectCode, + @Param("name") String name); /** * query task definition by code * - * @param taskDefinitionCode taskDefinitionCode + * @param code taskDefinitionCode * @return task definition */ - TaskDefinition queryByDefinitionCode(@Param("taskDefinitionCode") Long taskDefinitionCode); + TaskDefinition queryByCode(@Param("code") long code); /** * query all task definition list @@ -65,15 +59,7 @@ public interface TaskDefinitionMapper extends BaseMapper { * @param projectCode projectCode * @return task definition list */ - List queryAllDefinitionList(@Param("projectCode") Long projectCode); - - /** - * query task definition by ids - * - * @param ids ids - * @return task definition list - */ - List queryDefinitionListByIdList(@Param("ids") Integer[] ids); + List queryAllDefinitionList(@Param("projectCode") long projectCode); /** * count task definition group by user @@ -105,5 +91,31 @@ public interface TaskDefinitionMapper extends BaseMapper { * @param code code * @return int */ - int deleteByCode(@Param("code") Long code); + int deleteByCode(@Param("code") long code); + + /** + * batch insert task definitions + * + * @param taskDefinitions taskDefinitions + * @return int + */ + int batchInsert(@Param("taskDefinitions") List taskDefinitions); + + /** + * task definition page + * + * @param page page + * @param taskType taskType + * @param searchVal searchVal + * @param userId userId + * @param projectCode projectCode + * @param isAdmin isAdmin + * @return task definition IPage + */ + IPage queryDefineListPaging(IPage page, + @Param("projectCode") long projectCode, + @Param("taskType") String taskType, + @Param("searchVal") String searchVal, + @Param("userId") int userId, + @Param("isAdmin") boolean isAdmin); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TenantMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TenantMapper.java index 45c824ce89..89b62378c0 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TenantMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TenantMapper.java @@ -38,9 +38,9 @@ public interface TenantMapper extends BaseMapper { /** * query tenant by code * @param tenantCode tenantCode - * @return tenant list + * @return tenant */ - List queryByTenantCode(@Param("tenantCode") String tenantCode); + Tenant queryByTenantCode(@Param("tenantCode") String tenantCode); /** * tenant page diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/CommandMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/CommandMapper.xml index b3572ecd43..d0e9141bc5 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/CommandMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/CommandMapper.xml @@ -19,11 +19,11 @@ select cmd.command_type as command_type, count(1) as count from t_ds_command cmd, t_ds_process_definition process - where cmd.process_definition_id = process.id + where cmd.process_definition_code = process.code and process.project_code in diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapper.xml index 5f93854a3d..8179ff44d1 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapper.xml @@ -21,7 +21,7 @@ - \ No newline at end of file + diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml index 92642e2592..40afa04628 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml @@ -21,39 +21,39 @@ id, code, name, version, description, project_code, - release_state, user_id,global_params, flag, locations, connects, + release_state, user_id,global_params, flag, locations, warning_group_id, timeout, tenant_id,operator, operate_time, create_time, update_time delete from t_ds_process_definition_log - where code = #{processDefinitionCode} + where code = #{code} and version = #{version} diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml index fec3342cf1..9f76dd13dc 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml @@ -20,14 +20,12 @@ id, code, name, version, release_state, project_code, user_id, description, - global_params, flag, locations, connects, warning_group_id, create_time, timeout, - tenant_id, update_time + global_params, flag, locations, warning_group_id, create_time, timeout, tenant_id, update_time select pd.id, pd.code, pd.name, pd.version, pd.release_state, pd.project_code, p.id as project_id, pd.user_id, pd.description, - pd.global_params, pd.flag, pd.locations, pd.connects, pd.warning_group_id, pd.create_time, pd.timeout, - pd.tenant_id, pd.update_time, + pd.global_params, pd.flag, pd.locations, pd.warning_group_id, pd.create_time, pd.timeout, pd.tenant_id, pd.update_time, u.user_name,p.name as project_name,t.tenant_code,q.queue,q.queue_name from t_ds_process_definition pd JOIN t_ds_user u ON pd.user_id = u.id @@ -75,8 +72,8 @@ td.global_params, td.flag, td.warning_group_id, td.timeout, td.tenant_id, td.update_time, td.create_time, sc.schedule_release_state, tu.user_name 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_code,release_state as schedule_release_state from t_ds_schedules group by + process_definition_code,release_state) sc on sc.process_definition_code = td.code left join t_ds_user tu on td.user_id = tu.id where td.project_code = #{projectCode} @@ -125,11 +122,11 @@ group by td.user_id,tu.user_name - + - - - - update t_ds_process_definition - set version = #{version} - where id = #{processDefinitionId} - - - diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapper.xml index a216a13be3..c2884c420b 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapper.xml @@ -19,7 +19,7 @@ - id, name, process_definition_version, project_code, process_definition_code, pre_task_code, pre_task_version, + id, `name`, process_definition_version, project_code, process_definition_code, pre_task_code, pre_task_version, post_task_code, post_task_version, condition_type, condition_params, operator, operate_time, create_time, update_time - + + insert into t_ds_process_task_relation_log (`name`, process_definition_version, project_code, process_definition_code, + pre_task_code, pre_task_version, post_task_code, post_task_version, condition_type, condition_params, operator, operate_time, + create_time, update_time) + values + + (#{relation.name},#{relation.processDefinitionVersion},#{relation.projectCode},#{relation.processDefinitionCode}, + #{relation.preTaskCode},#{relation.preTaskVersion},#{relation.postTaskCode},#{relation.postTaskVersion}, + #{relation.conditionType},#{relation.conditionParams},#{relation.operator},#{relation.operateTime}, + #{relation.createTime},#{relation.updateTime}) + + diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.xml index 890af8f729..73e67f5a64 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.xml @@ -19,7 +19,7 @@ - id, name, process_definition_version, project_code, process_definition_code, pre_task_code, pre_task_version, + id, `name`, process_definition_version, project_code, process_definition_code, pre_task_code, pre_task_version, post_task_code, post_task_version, condition_type, condition_params, create_time, update_time + - select from t_ds_schedules - where process_definition_id =#{processDefinitionId} + where process_definition_code = #{processDefinitionCode} - diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapper.xml index 81de0a7bc4..458b096cdd 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapper.xml @@ -19,31 +19,20 @@ - id, code, name, version, description, project_code, user_id, task_type, task_params, flag, task_priority, + id, code, `name`, version, description, project_code, user_id, task_type, task_params, flag, task_priority, worker_group, environment_code, fail_retry_times, fail_retry_interval, timeout_flag, timeout_notify_strategy, timeout, delay_time, resource_ids, operator, operate_time, create_time, update_time - + + insert into t_ds_task_definition_log (code, `name`, version, description, project_code, user_id, + task_type, task_params, flag, task_priority, worker_group, fail_retry_times, fail_retry_interval, + timeout_flag, timeout_notify_strategy, timeout, delay_time, resource_ids, operator, operate_time, create_time, update_time) + values + + (#{taskDefinitionLog.code},#{taskDefinitionLog.name},#{taskDefinitionLog.version},#{taskDefinitionLog.description}, + #{taskDefinitionLog.projectCode},#{taskDefinitionLog.userId},#{taskDefinitionLog.taskType},#{taskDefinitionLog.taskParams}, + #{taskDefinitionLog.flag},#{taskDefinitionLog.taskPriority},#{taskDefinitionLog.workerGroup},#{taskDefinitionLog.failRetryTimes}, + #{taskDefinitionLog.failRetryInterval},#{taskDefinitionLog.timeoutFlag},#{taskDefinitionLog.timeoutNotifyStrategy},#{taskDefinitionLog.timeout}, + #{taskDefinitionLog.delayTime},#{taskDefinitionLog.resourceIds},#{taskDefinitionLog.operator},#{taskDefinitionLog.operateTime}, + #{taskDefinitionLog.createTime},#{taskDefinitionLog.updateTime}) + + + + delete + from t_ds_task_definition_log + where code = #{code} + and version = #{version} + + diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.xml index 37f623ec9a..c9d4b1a2ee 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.xml @@ -19,16 +19,16 @@ - id, code, name, version, description, project_code, user_id, task_type, task_params, flag, task_priority, + id, code, `name`, version, description, project_code, user_id, task_type, task_params, flag, task_priority, worker_group, environment_code, fail_retry_times, fail_retry_interval, timeout_flag, timeout_notify_strategy, timeout, delay_time, resource_ids, create_time, update_time - select from t_ds_task_definition WHERE project_code = #{projectCode} - and name = #{taskDefinitionName} + and `name` = #{name} - - - - select from t_ds_task_definition - where code = #{taskDefinitionCode} + where code = #{code} + select td.id, td.code, td.name, td.version, td.description, td.project_code, td.user_id, td.task_type, td.task_params, + td.flag, td.task_priority, td.worker_group, td.fail_retry_times, td.fail_retry_interval, td.timeout_flag, td.timeout_notify_strategy, + td.timeout, td.delay_time, td.resource_ids, td.create_time, td.update_time, u.user_name,p.name as project_name + from t_ds_task_definition td + JOIN t_ds_user u ON td.user_id = u.id + JOIN t_ds_project p ON td.project_code = p.code + where td.project_code = #{projectCode} + + and td.task_type = #{taskType} + + + and td.name like concat('%', #{searchVal}, '%') + + + and td.user_id = #{userId} + + order by td.update_time desc + diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/WorkFlowLineageMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/WorkFlowLineageMapper.xml index 0004f1dc67..7d1dbfb40f 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/WorkFlowLineageMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/WorkFlowLineageMapper.xml @@ -22,7 +22,7 @@ diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/CommandMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/CommandMapperTest.java index dd73bc36f6..dc9dbeebe7 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/CommandMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/CommandMapperTest.java @@ -14,15 +14,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + 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.Constants; +import org.apache.dolphinscheduler.common.enums.CommandType; +import org.apache.dolphinscheduler.common.enums.FailureStrategy; +import org.apache.dolphinscheduler.common.enums.Flag; +import org.apache.dolphinscheduler.common.enums.Priority; +import org.apache.dolphinscheduler.common.enums.ReleaseState; +import org.apache.dolphinscheduler.common.enums.TaskDependType; +import org.apache.dolphinscheduler.common.enums.WarningType; import org.apache.dolphinscheduler.common.utils.DateUtils; import org.apache.dolphinscheduler.dao.entity.Command; import org.apache.dolphinscheduler.dao.entity.CommandCount; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; -import org.apache.dolphinscheduler.common.enums.*; -import org.junit.Assert; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -31,14 +50,6 @@ 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.HashMap; -import java.util.List; -import java.util.Map; - -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; - /** * command mapper test */ @@ -48,24 +59,21 @@ import static org.junit.Assert.*; @Rollback(true) public class CommandMapperTest { - @Autowired CommandMapper commandMapper; @Autowired ProcessDefinitionMapper processDefinitionMapper; - /** * test insert */ @Test - public void testInsert(){ + public void testInsert() { Command command = createCommand(); assertThat(command.getId(),greaterThan(0)); } - /** * test select by id */ @@ -76,14 +84,14 @@ public class CommandMapperTest { Command actualCommand = commandMapper.selectById(expectedCommand.getId()); assertNotNull(actualCommand); - assertEquals(expectedCommand.getProcessDefinitionId(), actualCommand.getProcessDefinitionId()); + assertEquals(expectedCommand.getProcessDefinitionCode(), actualCommand.getProcessDefinitionCode()); } /** * test update */ @Test - public void testUpdate(){ + public void testUpdate() { Command expectedCommand = createCommand(); @@ -103,7 +111,7 @@ public class CommandMapperTest { * test delete */ @Test - public void testDelete(){ + public void testDelete() { Command expectedCommand = createCommand(); commandMapper.deleteById(expectedCommand.getId()); @@ -124,7 +132,6 @@ public class CommandMapperTest { Map commandMap = createCommandMap(count); - List actualCommands = commandMapper.selectList(null); assertThat(actualCommands.size(), greaterThanOrEqualTo(count)); @@ -138,7 +145,7 @@ public class CommandMapperTest { ProcessDefinition processDefinition = createProcessDefinition(); - Command expectedCommand = createCommand(CommandType.START_PROCESS,processDefinition.getId()); + createCommand(CommandType.START_PROCESS, processDefinition.getCode()); Command actualCommand = commandMapper.getOneToRun(); @@ -154,7 +161,7 @@ public class CommandMapperTest { ProcessDefinition processDefinition = createProcessDefinition(); - CommandCount expectedCommandCount = createCommandMap(count, CommandType.START_PROCESS, processDefinition.getId()); + createCommandMap(count, CommandType.START_PROCESS, processDefinition.getCode()); Long[] projectCodeArray = {processDefinition.getProjectCode()}; @@ -167,23 +174,22 @@ public class CommandMapperTest { assertThat(actualCommandCounts.size(),greaterThanOrEqualTo(1)); } - /** * create command map * @param count map count * @param commandType comman type - * @param processDefinitionId process definition id + * @param processDefinitionCode process definition code * @return command map */ private CommandCount createCommandMap( Integer count, CommandType commandType, - Integer processDefinitionId){ + long processDefinitionCode) { CommandCount commandCount = new CommandCount(); - for (int i = 0 ;i < count ;i++){ - createCommand(commandType,processDefinitionId); + for (int i = 0;i < count;i++) { + createCommand(commandType, processDefinitionCode); } commandCount.setCommandType(commandType); commandCount.setCount(count); @@ -195,7 +201,7 @@ public class CommandMapperTest { * create process definition * @return process definition */ - private ProcessDefinition createProcessDefinition(){ + private ProcessDefinition createProcessDefinition() { ProcessDefinition processDefinition = new ProcessDefinition(); processDefinition.setCode(1L); processDefinition.setReleaseState(ReleaseState.ONLINE); @@ -215,22 +221,21 @@ public class CommandMapperTest { * @param count map count * @return command map */ - private Map createCommandMap(Integer count){ + private Map createCommandMap(Integer count) { Map commandMap = new HashMap<>(); - for (int i = 0; i < count ;i++){ + for (int i = 0;i < count;i++) { Command command = createCommand(); commandMap.put(command.getId(),command); } return commandMap; } - /** * create command * @return */ - private Command createCommand(){ + private Command createCommand() { return createCommand(CommandType.START_PROCESS,1); } @@ -238,11 +243,11 @@ public class CommandMapperTest { * create command * @return Command */ - private Command createCommand(CommandType commandType,Integer processDefinitionId){ + private Command createCommand(CommandType commandType, long processDefinitionCode) { Command command = new Command(); command.setCommandType(commandType); - command.setProcessDefinitionId(processDefinitionId); + command.setProcessDefinitionCode(processDefinitionCode); command.setExecutorId(4); command.setCommandParam("test command param"); command.setTaskDependType(TaskDependType.TASK_ONLY); @@ -259,6 +264,4 @@ public class CommandMapperTest { return command; } - - -} \ No newline at end of file +} diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapperTest.java index 6e18aa97d2..58bd93a915 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapperTest.java @@ -21,6 +21,10 @@ import org.apache.dolphinscheduler.common.enums.CommandType; import org.apache.dolphinscheduler.dao.entity.CommandCount; import org.apache.dolphinscheduler.dao.entity.ErrorCommand; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; + +import java.util.Date; +import java.util.List; + import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -30,9 +34,6 @@ 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 @@ -81,7 +82,7 @@ public class ErrorCommandMapperTest { processDefinition.setCreateTime(new Date()); processDefinitionMapper.insert(processDefinition); - errorCommand.setProcessDefinitionId(processDefinition.getId()); + errorCommand.setProcessDefinitionCode(processDefinition.getCode()); errorCommandMapper.updateById(errorCommand); @@ -103,4 +104,4 @@ public class ErrorCommandMapperTest { Assert.assertNotEquals(commandCounts.size(), 0); Assert.assertNotEquals(commandCounts2.size(), 0); } -} \ No newline at end of file +} diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java index c997c245d6..1eb9cf7b96 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java @@ -90,7 +90,7 @@ public class ProcessDefinitionMapperTest { private ProcessDefinition insertTwo() { //insertOne ProcessDefinition processDefinition = new ProcessDefinition(); - processDefinition.setCode(2L); + processDefinition.setCode(1L); processDefinition.setName("def 2"); processDefinition.setProjectCode(1010L); processDefinition.setUserId(101); @@ -368,17 +368,6 @@ public class ProcessDefinitionMapperTest { Assert.assertNotNull(maps); } - @Test - public void testUpdateVersionByProcessDefinitionId() { - int expectedVersion = 10; - ProcessDefinition processDefinition = insertOne(); - processDefinition.setVersion(expectedVersion); - processDefinitionMapper.updateVersionByProcessDefinitionId( - processDefinition.getId(), processDefinition.getVersion()); - ProcessDefinition processDefinition1 = processDefinitionMapper.selectById(processDefinition.getId()); - Assert.assertEquals(expectedVersion, processDefinition1.getVersion()); - } - @Test public void listProjectIds() { ProcessDefinition processDefinition = insertOne(); diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapperTest.java index 1232e7b56e..a492beba92 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapperTest.java @@ -173,7 +173,6 @@ public class ProcessInstanceMapperTest { ProcessDefinition processDefinition = new ProcessDefinition(); processDefinition.setCode(1L); - processDefinition.setProjectId(1010); processDefinition.setProjectCode(1L); processDefinition.setReleaseState(ReleaseState.ONLINE); processDefinition.setUpdateTime(new Date()); @@ -267,7 +266,6 @@ public class ProcessInstanceMapperTest { ProcessDefinition processDefinition = new ProcessDefinition(); processDefinition.setCode(1L); - processDefinition.setProjectId(1010); processDefinition.setProjectCode(1L); processDefinition.setReleaseState(ReleaseState.ONLINE); processDefinition.setUpdateTime(new Date()); diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ScheduleMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ScheduleMapperTest.java index e55aacaa6c..46f0b950ca 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ScheduleMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ScheduleMapperTest.java @@ -14,8 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dolphinscheduler.dao.mapper; +package org.apache.dolphinscheduler.dao.mapper; import org.apache.dolphinscheduler.common.enums.FailureStrategy; import org.apache.dolphinscheduler.common.enums.ReleaseState; @@ -24,8 +24,10 @@ import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.Schedule; import org.apache.dolphinscheduler.dao.entity.User; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; + +import java.util.Date; +import java.util.List; + import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -35,8 +37,8 @@ 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; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @RunWith(SpringRunner.class) @SpringBootTest @@ -61,7 +63,7 @@ public class ScheduleMapperTest { * insert * @return Schedule */ - private Schedule insertOne(){ + private Schedule insertOne() { //insertOne Schedule schedule = new Schedule(); schedule.setStartTime(new Date()); @@ -80,7 +82,7 @@ public class ScheduleMapperTest { * test update */ @Test - public void testUpdate(){ + public void testUpdate() { //insertOne Schedule schedule = insertOne(); schedule.setCreateTime(new Date()); @@ -93,7 +95,7 @@ public class ScheduleMapperTest { * test delete */ @Test - public void testDelete(){ + public void testDelete() { Schedule schedule = insertOne(); int delete = scheduleMapper.deleteById(schedule.getId()); Assert.assertEquals(delete, 1); @@ -131,25 +133,21 @@ public class ScheduleMapperTest { ProcessDefinition processDefinition = new ProcessDefinition(); processDefinition.setCode(1L); processDefinition.setProjectCode(project.getCode()); - processDefinition.setProjectId(project.getId()); processDefinition.setUserId(user.getId()); processDefinition.setLocations(""); processDefinition.setCreateTime(new Date()); processDefinition.setUpdateTime(new Date()); processDefinitionMapper.insert(processDefinition); - Schedule schedule= insertOne(); + Schedule schedule = insertOne(); schedule.setUserId(user.getId()); - schedule.setProcessDefinitionId(processDefinition.getId()); + schedule.setProcessDefinitionCode(processDefinition.getCode()); scheduleMapper.insert(schedule); Page page = new Page(1,3); - IPage scheduleIPage = scheduleMapper.queryByProcessDefineIdPaging(page, - processDefinition.getId(), "" - ); + IPage scheduleIPage = scheduleMapper.queryByProcessDefineCodePaging(page, + processDefinition.getCode(), ""); Assert.assertNotEquals(scheduleIPage.getSize(), 0); - - } /** @@ -158,7 +156,6 @@ public class ScheduleMapperTest { @Test public void testQuerySchedulerListByProjectName() { - User user = new User(); user.setUserName("ut name"); userMapper.insert(user); @@ -174,16 +171,15 @@ public class ScheduleMapperTest { ProcessDefinition processDefinition = new ProcessDefinition(); processDefinition.setCode(1L); processDefinition.setProjectCode(project.getCode()); - processDefinition.setProjectId(project.getId()); processDefinition.setUserId(user.getId()); processDefinition.setLocations(""); processDefinition.setCreateTime(new Date()); processDefinition.setUpdateTime(new Date()); processDefinitionMapper.insert(processDefinition); - Schedule schedule= insertOne(); + Schedule schedule = insertOne(); schedule.setUserId(user.getId()); - schedule.setProcessDefinitionId(processDefinition.getId()); + schedule.setProcessDefinitionCode(processDefinition.getCode()); scheduleMapper.insert(schedule); Page page = new Page(1,3); @@ -201,11 +197,11 @@ public class ScheduleMapperTest { public void testSelectAllByProcessDefineArray() { Schedule schedule = insertOne(); - schedule.setProcessDefinitionId(12345); + schedule.setProcessDefinitionCode(12345); schedule.setReleaseState(ReleaseState.ONLINE); scheduleMapper.updateById(schedule); - List schedules= scheduleMapper.selectAllByProcessDefineArray(new int[] {schedule.getProcessDefinitionId()}); + List schedules = scheduleMapper.selectAllByProcessDefineArray(new long[] {schedule.getProcessDefinitionCode()}); Assert.assertNotEquals(schedules.size(), 0); } @@ -215,10 +211,10 @@ public class ScheduleMapperTest { @Test public void queryByProcessDefinitionId() { Schedule schedule = insertOne(); - schedule.setProcessDefinitionId(12345); + schedule.setProcessDefinitionCode(12345); scheduleMapper.updateById(schedule); - List schedules= scheduleMapper.queryByProcessDefinitionId(schedule.getProcessDefinitionId()); + List schedules = scheduleMapper.queryByProcessDefinitionCode(schedule.getProcessDefinitionCode()); Assert.assertNotEquals(schedules.size(), 0); } -} \ No newline at end of file +} diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapperTest.java index bdd39179a0..cc3af636e0 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapperTest.java @@ -80,26 +80,6 @@ public class TaskDefinitionLogMapperTest { Assert.assertNotEquals(taskDefinitionLog.getId(), 0); } - @Test - public void testQueryByDefinitionName() { - User user = new User(); - user.setUserName("un"); - userMapper.insert(user); - User un = userMapper.queryByUserNameAccurately("un"); - - Project project = new Project(); - project.setCode(1L); - project.setCreateTime(new Date()); - project.setUpdateTime(new Date()); - projectMapper.insert(project); - - TaskDefinitionLog taskDefinitionLog = insertOne(un.getId()); - - List taskDefinitionLogs = taskDefinitionLogMapper - .queryByDefinitionName(taskDefinitionLog.getProjectCode(), taskDefinitionLog.getName()); - Assert.assertNotEquals(taskDefinitionLogs.size(), 0); - } - @Test public void testQueryMaxVersionForDefinition() { TaskDefinitionLog taskDefinitionLog = insertOne(); diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapperTest.java index ecdc58fd33..f30e55a220 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapperTest.java @@ -81,38 +81,16 @@ public class TaskDefinitionMapperTest { @Test public void testQueryByDefinitionName() { TaskDefinition taskDefinition = insertOne(); - TaskDefinition result = taskDefinitionMapper.queryByDefinitionName(taskDefinition.getProjectCode() + TaskDefinition result = taskDefinitionMapper.queryByName(taskDefinition.getProjectCode() , taskDefinition.getName()); Assert.assertNotNull(result); } - @Test - public void testQueryByDefinitionId() { - - User user = new User(); - user.setUserName("un"); - userMapper.insert(user); - User un = userMapper.queryByUserNameAccurately("un"); - - Project project = new Project(); - project.setCode(1L); - project.setCreateTime(new Date()); - project.setUpdateTime(new Date()); - projectMapper.insert(project); - - TaskDefinition taskDefinition = insertOne(un.getId()); - TaskDefinition td = taskDefinitionMapper.queryByDefinitionName(taskDefinition.getProjectCode() - , taskDefinition.getName()); - TaskDefinition result = taskDefinitionMapper.queryByDefinitionId(td.getId()); - Assert.assertNotNull(result); - - } - @Test public void testQueryByDefinitionCode() { TaskDefinition taskDefinition = insertOne(); - TaskDefinition result = taskDefinitionMapper.queryByDefinitionCode(taskDefinition.getCode()); + TaskDefinition result = taskDefinitionMapper.queryByCode(taskDefinition.getCode()); Assert.assertNotNull(result); } @@ -125,14 +103,6 @@ public class TaskDefinitionMapperTest { } - @Test - public void testQueryDefinitionListByIdList() { - TaskDefinition taskDefinition = insertOne(); - List taskDefinitions = taskDefinitionMapper.queryDefinitionListByIdList(new Integer[]{taskDefinition.getId()}); - Assert.assertNotEquals(taskDefinitions.size(), 0); - - } - @Test public void testCountDefinitionGroupByUser() { User user = new User(); diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java index fd755ee682..c53460f002 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java @@ -323,7 +323,6 @@ public class TaskInstanceMapperTest { TaskInstance task = insertTaskInstance(processInstance.getId()); ProcessDefinition definition = new ProcessDefinition(); definition.setCode(1111L); - definition.setProjectId(1111); definition.setProjectCode(1111L); definition.setCreateTime(new Date()); definition.setUpdateTime(new Date()); @@ -348,7 +347,6 @@ public class TaskInstanceMapperTest { public void testQueryTaskInstanceListPaging() { ProcessDefinition definition = new ProcessDefinition(); definition.setCode(1L); - definition.setProjectId(1111); definition.setProjectCode(1111L); definition.setCreateTime(new Date()); definition.setUpdateTime(new Date()); diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TenantMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TenantMapperTest.java index b8a97e15c6..bfd7f88cfd 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TenantMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TenantMapperTest.java @@ -119,12 +119,10 @@ public class TenantMapperTest { */ @Test public void testQueryByTenantCode() { - Tenant tenant = insertOne(); tenant.setTenantCode("ut code"); tenantMapper.updateById(tenant); - List tenantList = tenantMapper.queryByTenantCode("ut code"); - Assert.assertEquals(1, tenantList.size()); + Assert.assertNotNull(tenantMapper.queryByTenantCode("ut code")); } /** diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkFlowLineageMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkFlowLineageMapperTest.java index 28e9dc2ba4..cc60ce4504 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkFlowLineageMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkFlowLineageMapperTest.java @@ -112,7 +112,7 @@ public class WorkFlowLineageMapperTest { schedule.setWarningType(WarningType.NONE); schedule.setCreateTime(new Date()); schedule.setUpdateTime(new Date()); - schedule.setProcessDefinitionId(id); + schedule.setProcessDefinitionCode(id); scheduleMapper.insert(schedule); return schedule; } @@ -131,8 +131,9 @@ public class WorkFlowLineageMapperTest { public void testQueryCodeRelation() { ProcessTaskRelation processTaskRelation = insertOneProcessTaskRelation(); - List workFlowLineages = workFlowLineageMapper.queryCodeRelation(processTaskRelation.getPreTaskCode() - , processTaskRelation.getPreTaskVersion(), 11L, 1L); + List workFlowLineages = workFlowLineageMapper.queryCodeRelation( + processTaskRelation.getPostTaskCode(), processTaskRelation.getPostTaskVersion(), + processTaskRelation.getProcessDefinitionCode(), processTaskRelation.getProjectCode()); Assert.assertNotEquals(workFlowLineages.size(), 0); } diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/log/SensitiveDataConverter.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/log/SensitiveDataConverter.java similarity index 93% rename from dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/log/SensitiveDataConverter.java rename to dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/log/SensitiveDataConverter.java index f6a6929ca1..73ee5d577a 100644 --- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/log/SensitiveDataConverter.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/log/SensitiveDataConverter.java @@ -15,7 +15,10 @@ * limitations under the License. */ -package org.apache.dolphinscheduler.service.log; +package org.apache.dolphinscheduler.server.log; + +import ch.qos.logback.classic.pattern.MessageConverter; +import ch.qos.logback.classic.spi.ILoggingEvent; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.utils.SensitiveLogUtils; @@ -24,18 +27,17 @@ import org.apache.dolphinscheduler.common.utils.StringUtils; import java.util.regex.Matcher; import java.util.regex.Pattern; -import ch.qos.logback.classic.pattern.ClassicConverter; -import ch.qos.logback.classic.spi.ILoggingEvent; - /** * sensitive data log converter */ -public class SensitiveDataConverter extends ClassicConverter { +public class SensitiveDataConverter extends MessageConverter { + /** * password pattern */ private final Pattern pwdPattern = Pattern.compile(Constants.DATASOURCE_PASSWORD_REGEX); + @Override public String convert(ILoggingEvent event) { @@ -67,6 +69,7 @@ public class SensitiveDataConverter extends ClassicConverter { * @param logMsg original log */ private String passwordHandler(Pattern pwdPattern, String logMsg) { + Matcher matcher = pwdPattern.matcher(logMsg); StringBuffer sb = new StringBuffer(logMsg.length()); @@ -84,4 +87,5 @@ public class SensitiveDataConverter extends ClassicConverter { return sb.toString(); } + } diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/cache/impl/TaskInstanceCacheManagerImpl.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/cache/impl/TaskInstanceCacheManagerImpl.java index 0df38c9220..43632aed65 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/cache/impl/TaskInstanceCacheManagerImpl.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/cache/impl/TaskInstanceCacheManagerImpl.java @@ -110,7 +110,6 @@ public class TaskInstanceCacheManagerImpl implements TaskInstanceCacheManager { @Override public void cacheTaskInstance(TaskExecuteAckCommand taskAckCommand) { TaskInstance taskInstance = new TaskInstance(); - taskInstance.setId(taskAckCommand.getTaskInstanceId()); taskInstance.setState(ExecutionStatus.of(taskAckCommand.getStatus())); taskInstance.setStartTime(taskAckCommand.getStartTime()); taskInstance.setHost(taskAckCommand.getHost()); diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/CommonTaskProcessor.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/CommonTaskProcessor.java index 853a8cc7dd..cb04b16514 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/CommonTaskProcessor.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/CommonTaskProcessor.java @@ -35,6 +35,8 @@ import org.apache.dolphinscheduler.service.queue.TaskPriority; import org.apache.dolphinscheduler.service.queue.TaskPriorityQueue; import org.apache.dolphinscheduler.service.queue.TaskPriorityQueueImpl; +import org.apache.logging.log4j.util.Strings; + import java.util.Date; import org.slf4j.Logger; @@ -90,6 +92,8 @@ public class CommonTaskProcessor extends BaseTaskProcessor { /** * common task cannot be paused + * + * @return */ @Override protected boolean pauseTask() { @@ -147,7 +151,7 @@ public class CommonTaskProcessor extends BaseTaskProcessor { if (taskInstance.getState().typeIsFinished()) { return true; } - if (null == taskInstance.getHost() || taskInstance.getHost().isEmpty()) { + if (Strings.isBlank(taskInstance.getHost())) { taskInstance.setState(ExecutionStatus.KILL); taskInstance.setEndTime(new Date()); processService.updateTaskInstance(taskInstance); diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/FlinkArgsUtils.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/FlinkArgsUtils.java index e12ebfca08..dbd92e020f 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/FlinkArgsUtils.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/FlinkArgsUtils.java @@ -117,15 +117,9 @@ public class FlinkArgsUtils { ProgramType programType = param.getProgramType(); String mainClass = param.getMainClass(); - - if (ProgramType.PYTHON == programType) { - // -py - args.add(Constants.FLINK_PYTHON); - } else if (programType != null && StringUtils.isNotEmpty(mainClass)) { - // -c - args.add(Constants.FLINK_MAIN_CLASS); - // main class - args.add(param.getMainClass()); + if (programType != null && programType != ProgramType.PYTHON && StringUtils.isNotEmpty(mainClass)) { + args.add(Constants.FLINK_MAIN_CLASS); //-c + args.add(param.getMainClass()); //main class } ResourceInfo mainJar = param.getMainJar(); diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/DependentTaskExecThread.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/DependentTaskExecThread.java deleted file mode 100644 index f3184a98aa..0000000000 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/DependentTaskExecThread.java +++ /dev/null @@ -1,231 +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.server.worker.runner; - -import static org.apache.dolphinscheduler.common.Constants.DEPENDENT_SPLIT; - -import org.apache.dolphinscheduler.common.Constants; -import org.apache.dolphinscheduler.common.enums.DependResult; -import org.apache.dolphinscheduler.common.enums.ExecutionStatus; -import org.apache.dolphinscheduler.common.model.DependentTaskModel; -import org.apache.dolphinscheduler.common.task.dependent.DependentParameters; -import org.apache.dolphinscheduler.common.thread.Stopper; -import org.apache.dolphinscheduler.common.utils.DependentUtils; -import org.apache.dolphinscheduler.common.utils.LoggerUtils; -import org.apache.dolphinscheduler.common.utils.NetUtils; -import org.apache.dolphinscheduler.dao.entity.TaskInstance; -import org.apache.dolphinscheduler.server.utils.DependentExecute; -import org.apache.dolphinscheduler.server.utils.LogUtils; - -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.annotation.JsonFormat; - -public class DependentTaskExecThread extends MasterBaseTaskExecThread { - - private DependentParameters dependentParameters; - - /** - * dependent task list - */ - private List dependentTaskList = new ArrayList<>(); - - /** - * depend item result map - * save the result to log file - */ - private Map dependResultMap = new HashMap<>(); - - - /** - * dependent date - */ - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") - private Date dependentDate; - - /** - * constructor of MasterBaseTaskExecThread - * - * @param taskInstance task instance - */ - public DependentTaskExecThread(TaskInstance taskInstance) { - super(taskInstance); - taskInstance.setStartTime(new Date()); - } - - - @Override - public Boolean submitWaitComplete() { - try { - logger.info("dependent task start"); - this.taskInstance = submit(); - logger = LoggerFactory.getLogger(LoggerUtils.buildTaskId(LoggerUtils.TASK_LOGGER_INFO_PREFIX, - processInstance.getProcessDefinitionCode(), - processInstance.getProcessDefinitionVersion(), - taskInstance.getProcessInstanceId(), - taskInstance.getId())); - String threadLoggerInfoName = String.format(Constants.TASK_LOG_INFO_FORMAT, processService.formatTaskAppId(this.taskInstance)); - Thread.currentThread().setName(threadLoggerInfoName); - initTaskParameters(); - initDependParameters(); - waitTaskQuit(); - updateTaskState(); - } catch (Exception e) { - logger.error("dependent task run exception", e); - } - return true; - } - - /** - * init dependent parameters - */ - private void initDependParameters() { - this.dependentParameters = taskInstance.getDependency(); - for (DependentTaskModel taskModel : dependentParameters.getDependTaskList()) { - this.dependentTaskList.add(new DependentExecute(taskModel.getDependItemList(), taskModel.getRelation())); - } - if (this.processInstance.getScheduleTime() != null) { - this.dependentDate = this.processInstance.getScheduleTime(); - } else { - this.dependentDate = new Date(); - } - } - - /** - * - */ - private void updateTaskState() { - ExecutionStatus status; - if (this.cancel) { - status = ExecutionStatus.KILL; - } else { - DependResult result = getTaskDependResult(); - status = (result == DependResult.SUCCESS) ? ExecutionStatus.SUCCESS : ExecutionStatus.FAILURE; - } - taskInstance.setState(status); - taskInstance.setEndTime(new Date()); - processService.saveTaskInstance(taskInstance); - } - - /** - * wait dependent tasks quit - */ - private Boolean waitTaskQuit() { - logger.info("wait depend task : {} complete", this.taskInstance.getName()); - if (taskInstance.getState().typeIsFinished()) { - logger.info("task {} already complete. task state:{}", - this.taskInstance.getName(), - this.taskInstance.getState()); - return true; - } - while (Stopper.isRunning()) { - try { - if (this.processInstance == null) { - logger.error("process instance not exists , master task exec thread exit"); - return true; - } - if (checkTaskTimeout()) { - this.checkTimeoutFlag = !alertTimeout(); - handleTimeoutFailed(); - } - if (this.cancel || this.processInstance.getState() == ExecutionStatus.READY_STOP) { - cancelTaskInstance(); - break; - } - - if (allDependentTaskFinish() || taskInstance.getState().typeIsFinished()) { - break; - } - // update process task - taskInstance = processService.findTaskInstanceById(taskInstance.getId()); - processInstance = processService.findProcessInstanceById(processInstance.getId()); - Thread.sleep(Constants.SLEEP_TIME_MILLIS); - } catch (Exception e) { - Thread.currentThread().interrupt(); - logger.error("exception", e); - if (processInstance != null) { - logger.error("wait task quit failed, instance id:{}, task id:{}", - processInstance.getId(), taskInstance.getId()); - } - } - } - return true; - } - - /** - * cancel dependent task - */ - private void cancelTaskInstance() { - this.cancel = true; - } - - private void initTaskParameters() { - taskInstance.setLogPath(LogUtils.getTaskLogPath(processInstance.getProcessDefinitionCode(), - processInstance.getProcessDefinitionVersion(), - taskInstance.getProcessInstanceId(), - taskInstance.getId())); - taskInstance.setHost(NetUtils.getAddr(masterConfig.getListenPort())); - taskInstance.setState(ExecutionStatus.RUNNING_EXECUTION); - taskInstance.setStartTime(new Date()); - processService.updateTaskInstance(taskInstance); - } - - /** - * judge all dependent tasks finish - * - * @return whether all dependent tasks finish - */ - private boolean allDependentTaskFinish() { - boolean finish = true; - for (DependentExecute dependentExecute : dependentTaskList) { - for (Map.Entry entry : dependentExecute.getDependResultMap().entrySet()) { - if (!dependResultMap.containsKey(entry.getKey())) { - dependResultMap.put(entry.getKey(), entry.getValue()); - //save depend result to log - logger.info("dependent item complete {} {},{}", DEPENDENT_SPLIT, entry.getKey(), entry.getValue()); - } - } - if (!dependentExecute.finish(dependentDate)) { - finish = false; - } - } - return finish; - } - - /** - * get dependent result - * - * @return DependResult - */ - private DependResult getTaskDependResult() { - List dependResultList = new ArrayList<>(); - for (DependentExecute dependentExecute : dependentTaskList) { - DependResult dependResult = dependentExecute.getModelDependResult(dependentDate); - dependResultList.add(dependResult); - } - DependResult result = DependentUtils.getDependResultForRelation(this.dependentParameters.getRelation(), dependResultList); - logger.info("dependent task completed, dependent result:{}", result); - return result; - } -} \ No newline at end of file diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/MasterBaseTaskExecThread.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/MasterBaseTaskExecThread.java deleted file mode 100644 index fe077aabd8..0000000000 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/MasterBaseTaskExecThread.java +++ /dev/null @@ -1,325 +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.server.worker.runner; - -import org.apache.dolphinscheduler.common.enums.ExecutionStatus; -import org.apache.dolphinscheduler.common.enums.TaskTimeoutStrategy; -import org.apache.dolphinscheduler.common.enums.TimeoutFlag; -import org.apache.dolphinscheduler.common.task.TaskTimeoutParameter; -import org.apache.dolphinscheduler.common.utils.JSONUtils; -import org.apache.dolphinscheduler.dao.AlertDao; -import org.apache.dolphinscheduler.dao.entity.ProcessInstance; -import org.apache.dolphinscheduler.dao.entity.TaskDefinition; -import org.apache.dolphinscheduler.dao.entity.TaskInstance; -import org.apache.dolphinscheduler.server.master.config.MasterConfig; -import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; -import org.apache.dolphinscheduler.service.process.ProcessService; -import org.apache.dolphinscheduler.service.queue.TaskPriority; -import org.apache.dolphinscheduler.service.queue.TaskPriorityQueue; -import org.apache.dolphinscheduler.service.queue.TaskPriorityQueueImpl; - -import java.util.Date; -import java.util.concurrent.Callable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * master task exec base class - */ -public class MasterBaseTaskExecThread implements Callable { - - /** - * logger of MasterBaseTaskExecThread - */ - protected Logger logger = LoggerFactory.getLogger(getClass()); - - - /** - * process service - */ - protected ProcessService processService; - - /** - * alert database access - */ - protected AlertDao alertDao; - - /** - * process instance - */ - protected ProcessInstance processInstance; - - /** - * task instance - */ - protected TaskInstance taskInstance; - - /** - * whether need cancel - */ - protected boolean cancel; - - /** - * master config - */ - protected MasterConfig masterConfig; - - /** - * taskUpdateQueue - */ - private TaskPriorityQueue taskUpdateQueue; - - /** - * whether need check task time out. - */ - protected boolean checkTimeoutFlag = false; - - /** - * task timeout parameters - */ - protected TaskTimeoutParameter taskTimeoutParameter; - - /** - * constructor of MasterBaseTaskExecThread - * - * @param taskInstance task instance - */ - public MasterBaseTaskExecThread(TaskInstance taskInstance) { - this.processService = SpringApplicationContext.getBean(ProcessService.class); - this.alertDao = SpringApplicationContext.getBean(AlertDao.class); - this.cancel = false; - this.taskInstance = taskInstance; - this.masterConfig = SpringApplicationContext.getBean(MasterConfig.class); - this.taskUpdateQueue = SpringApplicationContext.getBean(TaskPriorityQueueImpl.class); - initTaskParams(); - } - - /** - * init task ordinary parameters - */ - private void initTaskParams() { - initTimeoutParams(); - } - - /** - * init task timeout parameters - */ - private void initTimeoutParams() { - TaskDefinition taskDefinition = processService.findTaskDefinition(taskInstance.getTaskCode(), taskInstance.getTaskDefinitionVersion()); - boolean timeoutEnable = taskDefinition.getTimeoutFlag() == TimeoutFlag.OPEN; - taskTimeoutParameter = new TaskTimeoutParameter(timeoutEnable, - taskDefinition.getTimeoutNotifyStrategy(), - taskDefinition.getTimeout()); - if (taskTimeoutParameter.getEnable()) { - checkTimeoutFlag = true; - } - } - - /** - * get task instance - * - * @return TaskInstance - */ - public TaskInstance getTaskInstance() { - return this.taskInstance; - } - - /** - * kill master base task exec thread - */ - public void kill() { - this.cancel = true; - } - - /** - * submit master base task exec thread - * - * @return TaskInstance - */ - protected TaskInstance submit() { - Integer commitRetryTimes = masterConfig.getMasterTaskCommitRetryTimes(); - Integer commitRetryInterval = masterConfig.getMasterTaskCommitInterval(); - - int retryTimes = 1; - boolean submitDB = false; - boolean submitTask = false; - TaskInstance task = null; - while (retryTimes <= commitRetryTimes) { - try { - if (!submitDB) { - // submit task to db - task = processService.submitTask(taskInstance); - if (task != null && task.getId() != 0) { - submitDB = true; - } - } - if (submitDB && !submitTask) { - // dispatch task - submitTask = dispatchTask(task); - } - if (submitDB && submitTask) { - return task; - } - if (!submitDB) { - logger.error("task commit to db failed , taskId {} has already retry {} times, please check the database", taskInstance.getId(), retryTimes); - } else if (!submitTask) { - logger.error("task commit failed , taskId {} has already retry {} times, please check", taskInstance.getId(), retryTimes); - } - Thread.sleep(commitRetryInterval); - } catch (Exception e) { - Thread.currentThread().interrupt(); - logger.error("task commit to mysql and dispatcht task failed", e); - } - retryTimes += 1; - } - return task; - } - - /** - * dispatch task - * - * @param taskInstance taskInstance - * @return whether submit task success - */ - public Boolean dispatchTask(TaskInstance taskInstance) { - - try { - if (taskInstance.isConditionsTask() - || taskInstance.isDependTask() - || taskInstance.isSubProcess()) { - return true; - } - if (taskInstance.getState().typeIsFinished()) { - logger.info(String.format("submit task , but task [%s] state [%s] is already finished. ", taskInstance.getName(), taskInstance.getState().toString())); - return true; - } - // task cannot be submitted because its execution state is RUNNING or DELAY. - if (taskInstance.getState() == ExecutionStatus.RUNNING_EXECUTION - || taskInstance.getState() == ExecutionStatus.DELAY_EXECUTION) { - logger.info("submit task, but the status of the task {} is already running or delayed.", taskInstance.getName()); - return true; - } - logger.info("task ready to submit: {}", taskInstance); - - /** - * taskPriority - */ - TaskPriority taskPriority = buildTaskPriority(processInstance.getProcessInstancePriority().getCode(), - processInstance.getId(), - taskInstance.getProcessInstancePriority().getCode(), - taskInstance.getId(), - org.apache.dolphinscheduler.common.Constants.DEFAULT_WORKER_GROUP); - taskUpdateQueue.put(taskPriority); - logger.info(String.format("master submit success, task : %s", taskInstance.getName())); - return true; - } catch (Exception e) { - logger.error("submit task Exception: ", e); - logger.error("task error : %s", JSONUtils.toJsonString(taskInstance)); - return false; - } - } - - /** - * buildTaskPriority - * - * @param processInstancePriority processInstancePriority - * @param processInstanceId processInstanceId - * @param taskInstancePriority taskInstancePriority - * @param taskInstanceId taskInstanceId - * @param workerGroup workerGroup - * @return TaskPriority - */ - private TaskPriority buildTaskPriority(int processInstancePriority, - int processInstanceId, - int taskInstancePriority, - int taskInstanceId, - String workerGroup) { - return new TaskPriority(processInstancePriority, processInstanceId, - taskInstancePriority, taskInstanceId, workerGroup); - } - - /** - * submit wait complete - * - * @return true - */ - protected Boolean submitWaitComplete() { - return true; - } - - /** - * call - * - * @return boolean - */ - @Override - public Boolean call() { - this.processInstance = processService.findProcessInstanceById(taskInstance.getProcessInstanceId()); - return submitWaitComplete(); - } - - /** - * alert time out - */ - protected boolean alertTimeout() { - if (TaskTimeoutStrategy.FAILED == this.taskTimeoutParameter.getStrategy()) { - return true; - } - logger.warn("process id:{} process name:{} task id: {},name:{} execution time out", - processInstance.getId(), processInstance.getName(), taskInstance.getId(), taskInstance.getName()); - // send warn mail - alertDao.sendTaskTimeoutAlert(processInstance.getWarningGroupId(), processInstance.getId(), processInstance.getName(), - taskInstance.getId(), taskInstance.getName()); - return true; - } - - /** - * handle time out for time out strategy warn&&failed - */ - protected void handleTimeoutFailed() { - if (TaskTimeoutStrategy.WARN == this.taskTimeoutParameter.getStrategy()) { - return; - } - logger.info("process id:{} name:{} task id:{} name:{} cancel because of timeout.", - processInstance.getId(), processInstance.getName(), taskInstance.getId(), taskInstance.getName()); - this.cancel = true; - } - - /** - * check task remain time valid - */ - protected boolean checkTaskTimeout() { - if (!checkTimeoutFlag || taskInstance.getStartTime() == null) { - return false; - } - long remainTime = getRemainTime(taskTimeoutParameter.getInterval() * 60L); - return remainTime <= 0; - } - - /** - * get remain time - * - * @return remain time - */ - protected long getRemainTime(long timeoutSeconds) { - Date startTime = taskInstance.getStartTime(); - long usedTime = (System.currentTimeMillis() - startTime.getTime()) / 1000; - return timeoutSeconds - usedTime; - } -} diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/MasterTaskExecThread.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/MasterTaskExecThread.java deleted file mode 100644 index 0ac19e0267..0000000000 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/MasterTaskExecThread.java +++ /dev/null @@ -1,231 +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.server.worker.runner; - -import org.apache.dolphinscheduler.common.Constants; -import org.apache.dolphinscheduler.common.enums.ExecutionStatus; -import org.apache.dolphinscheduler.common.thread.Stopper; -import org.apache.dolphinscheduler.common.utils.CollectionUtils; -import org.apache.dolphinscheduler.common.utils.StringUtils; -import org.apache.dolphinscheduler.dao.entity.TaskInstance; -import org.apache.dolphinscheduler.remote.command.TaskKillRequestCommand; -import org.apache.dolphinscheduler.remote.utils.Host; -import org.apache.dolphinscheduler.server.master.cache.TaskInstanceCacheManager; -import org.apache.dolphinscheduler.server.master.cache.impl.TaskInstanceCacheManagerImpl; -import org.apache.dolphinscheduler.server.master.dispatch.context.ExecutionContext; -import org.apache.dolphinscheduler.server.master.dispatch.enums.ExecutorType; -import org.apache.dolphinscheduler.server.master.dispatch.executor.NettyExecutorManager; -import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; -import org.apache.dolphinscheduler.service.registry.RegistryClient; - -import java.util.Date; -import java.util.Set; - -/** - * master task exec thread - */ -public class MasterTaskExecThread extends MasterBaseTaskExecThread { - - /** - * taskInstance state manager - */ - private TaskInstanceCacheManager taskInstanceCacheManager; - - /** - * netty executor manager - */ - private NettyExecutorManager nettyExecutorManager; - - - /** - * zookeeper register center - */ - private RegistryClient registryClient; - - /** - * constructor of MasterTaskExecThread - * - * @param taskInstance task instance - */ - public MasterTaskExecThread(TaskInstance taskInstance) { - super(taskInstance); - this.taskInstanceCacheManager = SpringApplicationContext.getBean(TaskInstanceCacheManagerImpl.class); - this.nettyExecutorManager = SpringApplicationContext.getBean(NettyExecutorManager.class); - this.registryClient = RegistryClient.getInstance(); - } - - /** - * get task instance - * - * @return TaskInstance - */ - @Override - public TaskInstance getTaskInstance() { - return this.taskInstance; - } - - /** - * whether already Killed,default false - */ - private boolean alreadyKilled = false; - - /** - * submit task instance and wait complete - * - * @return true is task quit is true - */ - @Override - public Boolean submitWaitComplete() { - Boolean result = false; - this.taskInstance = submit(); - if (this.taskInstance == null) { - logger.error("submit task instance to mysql and queue failed , please check and fix it"); - return result; - } - if (!this.taskInstance.getState().typeIsFinished()) { - result = waitTaskQuit(); - } - taskInstance.setEndTime(new Date()); - processService.updateTaskInstance(taskInstance); - logger.info("task :{} id:{}, process id:{}, exec thread completed ", - this.taskInstance.getName(), taskInstance.getId(), processInstance.getId()); - return result; - } - - /** - * polling db - *

- * wait task quit - * - * @return true if task quit success - */ - public Boolean waitTaskQuit() { - // query new state - taskInstance = processService.findTaskInstanceById(taskInstance.getId()); - logger.info("wait task: process id: {}, task id:{}, task name:{} complete", - this.taskInstance.getProcessInstanceId(), this.taskInstance.getId(), this.taskInstance.getName()); - - while (Stopper.isRunning()) { - try { - if (this.processInstance == null) { - logger.error("process instance not exists , master task exec thread exit"); - return true; - } - // task instance add queue , waiting worker to kill - if (this.cancel || this.processInstance.getState() == ExecutionStatus.READY_STOP) { - cancelTaskInstance(); - } - if (processInstance.getState() == ExecutionStatus.READY_PAUSE) { - pauseTask(); - } - // task instance finished - if (taskInstance.getState().typeIsFinished()) { - // if task is final result , then remove taskInstance from cache - taskInstanceCacheManager.removeByTaskInstanceId(taskInstance.getId()); - break; - } - if (checkTaskTimeout()) { - this.checkTimeoutFlag = !alertTimeout(); - } - // updateProcessInstance task instance - //issue#5539 Check status of taskInstance from cache - taskInstance = taskInstanceCacheManager.getByTaskInstanceId(taskInstance.getId()); - processInstance = processService.findProcessInstanceById(processInstance.getId()); - Thread.sleep(Constants.SLEEP_TIME_MILLIS); - } catch (Exception e) { - Thread.currentThread().interrupt(); - logger.error("exception", e); - if (processInstance != null) { - logger.error("wait task quit failed, instance id:{}, task id:{}", - processInstance.getId(), taskInstance.getId()); - } - } - } - return true; - } - - /** - * pause task if task have not been dispatched to worker, do not dispatch anymore. - */ - public void pauseTask() { - taskInstance = processService.findTaskInstanceById(taskInstance.getId()); - if (taskInstance == null) { - return; - } - if (StringUtils.isBlank(taskInstance.getHost())) { - taskInstance.setState(ExecutionStatus.PAUSE); - taskInstance.setEndTime(new Date()); - processService.updateTaskInstance(taskInstance); - } - } - - /** - * task instance add queue , waiting worker to kill - */ - private void cancelTaskInstance() throws Exception { - if (alreadyKilled) { - return; - } - alreadyKilled = true; - taskInstance = processService.findTaskInstanceById(taskInstance.getId()); - if (StringUtils.isBlank(taskInstance.getHost())) { - taskInstance.setState(ExecutionStatus.KILL); - taskInstance.setEndTime(new Date()); - processService.updateTaskInstance(taskInstance); - return; - } - - TaskKillRequestCommand killCommand = new TaskKillRequestCommand(); - killCommand.setTaskInstanceId(taskInstance.getId()); - - ExecutionContext executionContext = new ExecutionContext(killCommand.convert2Command(), ExecutorType.WORKER); - - Host host = Host.of(taskInstance.getHost()); - executionContext.setHost(host); - - nettyExecutorManager.executeDirectly(executionContext); - - logger.info("master kill taskInstance name :{} taskInstance id:{}", - taskInstance.getName(), taskInstance.getId()); - } - - /** - * whether exists valid worker group - * - * @param taskInstanceWorkerGroup taskInstanceWorkerGroup - * @return whether exists - */ - public Boolean existsValidWorkerGroup(String taskInstanceWorkerGroup) { - Set workerGroups = registryClient.getWorkerGroupDirectly(); - // not worker group - if (CollectionUtils.isEmpty(workerGroups)) { - return false; - } - - // has worker group , but not taskInstance assigned worker group - if (!workerGroups.contains(taskInstanceWorkerGroup)) { - return false; - } - Set workers = registryClient.getWorkerGroupNodesDirectly(taskInstanceWorkerGroup); - if (CollectionUtils.isEmpty(workers)) { - return false; - } - return true; - } - -} diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/SubProcessTaskExecThread.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/SubProcessTaskExecThread.java deleted file mode 100644 index 4cf95819e9..0000000000 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/SubProcessTaskExecThread.java +++ /dev/null @@ -1,181 +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.server.worker.runner; - -import org.apache.dolphinscheduler.common.Constants; -import org.apache.dolphinscheduler.common.enums.ExecutionStatus; -import org.apache.dolphinscheduler.common.thread.Stopper; -import org.apache.dolphinscheduler.dao.entity.ProcessInstance; -import org.apache.dolphinscheduler.dao.entity.TaskInstance; - -import java.util.Date; - -/** - * subflow task exec thread - */ -public class SubProcessTaskExecThread extends MasterBaseTaskExecThread { - - /** - * sub process instance - */ - private ProcessInstance subProcessInstance; - - /** - * sub process task exec thread - * - * @param taskInstance task instance - */ - public SubProcessTaskExecThread(TaskInstance taskInstance) { - super(taskInstance); - } - - @Override - public Boolean submitWaitComplete() { - - Boolean result = false; - try { - // submit task instance - this.taskInstance = submit(); - - if (taskInstance == null) { - logger.error("sub work flow submit task instance to mysql and queue failed , please check and fix it"); - return result; - } - setTaskInstanceState(); - waitTaskQuit(); - subProcessInstance = processService.findSubProcessInstance(processInstance.getId(), taskInstance.getId()); - - // at the end of the subflow , the task state is changed to the subflow state - if (subProcessInstance != null) { - if (subProcessInstance.getState() == ExecutionStatus.STOP) { - this.taskInstance.setState(ExecutionStatus.KILL); - } else { - this.taskInstance.setState(subProcessInstance.getState()); - } - } - taskInstance.setEndTime(new Date()); - processService.updateTaskInstance(taskInstance); - logger.info("subflow task :{} id:{}, process id:{}, exec thread completed ", - this.taskInstance.getName(), taskInstance.getId(), processInstance.getId()); - result = true; - - } catch (Exception e) { - Thread.currentThread().interrupt(); - logger.error("exception: ", e); - if (null != taskInstance) { - logger.error("wait task quit failed, instance id:{}, task id:{}", - processInstance.getId(), taskInstance.getId()); - } - } - return result; - } - - /** - * set task instance state - */ - private boolean setTaskInstanceState() { - subProcessInstance = processService.findSubProcessInstance(processInstance.getId(), taskInstance.getId()); - if (subProcessInstance == null || taskInstance.getState().typeIsFinished()) { - return false; - } - - taskInstance.setState(ExecutionStatus.RUNNING_EXECUTION); - taskInstance.setStartTime(new Date()); - processService.updateTaskInstance(taskInstance); - return true; - } - - /** - * updateProcessInstance parent state - */ - private void updateParentProcessState() { - ProcessInstance parentProcessInstance = processService.findProcessInstanceById(this.processInstance.getId()); - - if (parentProcessInstance == null) { - logger.error("parent work flow instance is null , please check it! work flow id {}", processInstance.getId()); - return; - } - this.processInstance.setState(parentProcessInstance.getState()); - } - - /** - * wait task quit - */ - private void waitTaskQuit() throws InterruptedException { - - logger.info("wait sub work flow: {} complete", this.taskInstance.getName()); - - if (taskInstance.getState().typeIsFinished()) { - logger.info("sub work flow task {} already complete. task state:{}, parent work flow instance state:{}", - this.taskInstance.getName(), - this.taskInstance.getState(), - this.processInstance.getState()); - return; - } - while (Stopper.isRunning()) { - // waiting for subflow process instance establishment - if (subProcessInstance == null) { - Thread.sleep(Constants.SLEEP_TIME_MILLIS); - if (!setTaskInstanceState()) { - continue; - } - } - subProcessInstance = processService.findProcessInstanceById(subProcessInstance.getId()); - if (checkTaskTimeout()) { - this.checkTimeoutFlag = !alertTimeout(); - handleTimeoutFailed(); - } - updateParentProcessState(); - if (subProcessInstance.getState().typeIsFinished()) { - break; - } - if (this.processInstance.getState() == ExecutionStatus.READY_PAUSE) { - // parent process "ready to pause" , child process "pause" - pauseSubProcess(); - } else if (this.cancel || this.processInstance.getState() == ExecutionStatus.READY_STOP) { - // parent Process "Ready to Cancel" , subflow "Cancel" - stopSubProcess(); - } - Thread.sleep(Constants.SLEEP_TIME_MILLIS); - } - } - - /** - * stop sub process - */ - private void stopSubProcess() { - if (subProcessInstance.getState() == ExecutionStatus.STOP - || subProcessInstance.getState() == ExecutionStatus.READY_STOP) { - return; - } - subProcessInstance.setState(ExecutionStatus.READY_STOP); - processService.updateProcessInstance(subProcessInstance); - } - - /** - * pause sub process - */ - private void pauseSubProcess() { - if (subProcessInstance.getState() == ExecutionStatus.PAUSE - || subProcessInstance.getState() == ExecutionStatus.READY_PAUSE) { - return; - } - subProcessInstance.setState(ExecutionStatus.READY_PAUSE); - processService.updateProcessInstance(subProcessInstance); - } -} diff --git a/dolphinscheduler-server/src/main/resources/config/install_config.conf b/dolphinscheduler-server/src/main/resources/config/install_config.conf index deccd763c1..ab3401c89c 100755 --- a/dolphinscheduler-server/src/main/resources/config/install_config.conf +++ b/dolphinscheduler-server/src/main/resources/config/install_config.conf @@ -34,6 +34,13 @@ password="xx" # database name dbname="dolphinscheduler" + +# zk cluster +zkQuorum="192.168.xx.xx:2181,192.168.xx.xx:2181,192.168.xx.xx:2181" + +# zk root directory +zkRoot="/dolphinscheduler" + # Note: the target installation path for dolphinscheduler, please not config as the same as the current path (pwd) installPath="/data1_1T/dolphinscheduler" @@ -46,13 +53,6 @@ deployUser="dolphinscheduler" # Note: find and load the Alert Plugin Jar from this dir. alertPluginDir="/data1_1T/dolphinscheduler/lib/plugin/alert" -# registry config -# registry plugin dir -# Note: find and load the Registry Plugin Jar from this dir. -registryPluginDir="/data1_1T/dolphinscheduler/lib/plugin/registry" -registryPluginName="zookeeper" -registryServers="192.168.xx.xx:2181,192.168.xx.xx:2181,192.168.xx.xx:2181" - # user data local directory path, please make sure the directory exists and have read write permissions dataBasedirPath="/tmp/dolphinscheduler" diff --git a/dolphinscheduler-server/src/main/resources/logback-master.xml b/dolphinscheduler-server/src/main/resources/logback-master.xml index c46c9fd930..a61d891b10 100644 --- a/dolphinscheduler-server/src/main/resources/logback-master.xml +++ b/dolphinscheduler-server/src/main/resources/logback-master.xml @@ -18,18 +18,19 @@ - - + - [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %message%n + [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %msg%n UTF-8 + - - + - [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %message%n + [%level] %date{yyyy-MM-dd HH:mm:ss.SSS} %logger{96}:[%line] - %msg%n UTF-8 + +

+
+ {{ $t("Connection name") }} +
+
+ +
+
+ + +
+
+ + {{ $t("Cancel") }} + + {{ $t("Confirm add") }} + +
+
+ + + + diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/menuItem.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/menuItem.vue new file mode 100644 index 0000000000..127a025112 --- /dev/null +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/menuItem.vue @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/nodeStatus.js b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/nodeStatus.js new file mode 100644 index 0000000000..0ff7264048 --- /dev/null +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/nodeStatus.js @@ -0,0 +1,52 @@ +/* + * 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. + */ + +import Vue from 'vue' +import './nodeStatus.scss' +import i18n from '@/module/i18n' +import { formatDate } from '@/module/filter/filter' + +const nodeStatus = ({ stateProps, taskInstance }) => { + const Instance = new Vue({ + data: {}, + methods: {}, + render (h) { + return ( + +
+
    +
  • {i18n.$t('Name')}:{taskInstance.name}
  • +
  • {i18n.$t('State')}:{stateProps.desc}
  • +
  • {i18n.$t('type')}:{taskInstance.taskType}
  • +
  • {i18n.$t('host')}:{taskInstance.host || '-'}
  • +
  • {i18n.$t('Retry Count')}:{taskInstance.retryTimes}
  • +
  • {i18n.$t('Submit Time')}:{formatDate(taskInstance.submitTime)}
  • +
  • {i18n.$t('Start Time')}:{formatDate(taskInstance.startTime)}
  • +
  • {i18n.$t('End Time')}:{taskInstance.endTime ? formatDate(taskInstance.endTime) : '-'}
  • +
+
+ +
+ ) + } + }) + return Instance +} + +export default nodeStatus diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/plugIn/dragZoom.js b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/nodeStatus.scss similarity index 60% rename from dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/plugIn/dragZoom.js rename to dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/nodeStatus.scss index 009c82bbab..798f308d64 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/plugIn/dragZoom.js +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/nodeStatus.scss @@ -1,4 +1,3 @@ -import d3 from 'd3' /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -16,23 +15,16 @@ import d3 from 'd3' * limitations under the License. */ -const DragZoom = function () { - this.element = {} - this.zoom = {} - this.scale = 1 +.status-icon { + width: 100%; + height: 100%; + display: block; + font-size: 18px; } -DragZoom.prototype.init = function () { - const $canvas = $('#canvas') - this.element = d3.select('#canvas') - this.zoom = d3.behavior.zoom() - .scaleExtent([0.5, 2]) - .on('zoom', () => { - this.scale = d3.event.scale - $canvas.css('transform', 'scale(' + this.scale + ')') - $canvas.css('transform-origin', '0 0') - }) - this.element.call(this.zoom).on('dblclick.zoom', null) +.status-info { + margin-bottom: 0; + li { + margin-bottom: 5px; + } } - -export default new DragZoom() diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/taskbar.scss b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/taskbar.scss new file mode 100644 index 0000000000..3ad2416ee3 --- /dev/null +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/taskbar.scss @@ -0,0 +1,167 @@ +/* + * 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. + */ +.dag-taskbar { + width: 190px; + height: 100%; + background-color: #fff; + margin-right: 20px; + + .taskbar-title { + display: flex; + border-bottom: dashed 1px #e5e5e5; + height: 42px; + padding: 0 20px; + align-items: center; + + h4 { + color: #666; + font-size: 14px; + } + } + + .tasks { + width: 100%; + padding: 10px 20px; + display: flex; + flex-wrap: wrap; + box-sizing: border-box; + max-height: calc(100% - 42px); + overflow: auto; + + .draggable-box { + cursor: move; + width: 100%; + height: 32px; + margin-bottom: 10px; + + .task-item { + width: 100%; + height: 100%; + display: flex; + align-items: center; + border: 1px dashed #e4e4e4; + padding: 0 10px; + border-radius: 4px; + + em { + margin-right: 10px; + display: block; + width: 18px; + height: 18px; + background-size: 100% 100%; + &.icos-shell { + background-image: url("../images/task-icos/shell.png"); + } + &.icos-sub_process { + background-image: url("../images/task-icos/sub_process.png"); + } + &.icos-procedure { + background-image: url("../images/task-icos/procedure.png"); + } + &.icos-sql { + background-image: url("../images/task-icos/sql.png"); + } + &.icos-flink { + background-image: url("../images/task-icos/flink.png"); + } + &.icos-mr { + background-image: url("../images/task-icos/mr.png"); + } + &.icos-python { + background-image: url("../images/task-icos/python.png"); + } + &.icos-dependent { + background-image: url("../images/task-icos/dependent.png"); + } + &.icos-http { + background-image: url("../images/task-icos/http.png"); + } + &.icos-datax { + background-image: url("../images/task-icos/datax.png"); + } + &.icos-sqoop { + background-image: url("../images/task-icos/sqoop.png"); + } + &.icos-conditions { + background-image: url("../images/task-icos/conditions.png"); + } + &.icos-waterdrop { + background-image: url("../images/task-icos/waterdrop.png"); + } + &.icos-spark { + background-image: url("../images/task-icos/spark.png"); + } + } + + span { + font-size: 12px; + } + + &:hover { + color: #288fff; + border: 1px dashed #288fff; + background-color: rgba(40, 143, 255, 0.1); + + em { + &.icos-shell { + background-image: url("../images/task-icos/shell_hover.png"); + } + &.icos-sub_process { + background-image: url("../images/task-icos/sub_process_hover.png"); + } + &.icos-procedure { + background-image: url("../images/task-icos/procedure_hover.png"); + } + &.icos-sql { + background-image: url("../images/task-icos/sql_hover.png"); + } + &.icos-flink { + background-image: url("../images/task-icos/flink_hover.png"); + } + &.icos-mr { + background-image: url("../images/task-icos/mr_hover.png"); + } + &.icos-python { + background-image: url("../images/task-icos/python_hover.png"); + } + &.icos-dependent { + background-image: url("../images/task-icos/dependent_hover.png"); + } + &.icos-http { + background-image: url("../images/task-icos/http_hover.png"); + } + &.icos-datax { + background-image: url("../images/task-icos/datax_hover.png"); + } + &.icos-sqoop { + background-image: url("../images/task-icos/sqoop_hover.png"); + } + &.icos-conditions { + background-image: url("../images/task-icos/conditions_hover.png"); + } + &.icos-waterdrop { + background-image: url("../images/task-icos/waterdrop_hover.png"); + } + &.icos-spark { + background-image: url("../images/task-icos/spark_hover.png"); + } + } + } + } + } + } +} diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/taskbar.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/taskbar.vue new file mode 100644 index 0000000000..0ffc40c50d --- /dev/null +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/taskbar.vue @@ -0,0 +1,64 @@ +/* + * 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. + */ + + + + + diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/toolbar.scss b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/toolbar.scss new file mode 100644 index 0000000000..03578f32d9 --- /dev/null +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/toolbar.scss @@ -0,0 +1,113 @@ +/* + * 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. + */ +.dag-toolbar { + width: 100%; + height: 50px; + background-color: #fff; + padding: 0 20px; + display: flex; + align-items: center; + box-sizing: border-box; + + h3 { + font-size: 14px; + font-weight: bold; + margin: 0 10px 0 0; + } + + .transparent { + width: 1px; + height: 1px; + opacity: 0; + } + + .toolbar-operation { + font-size: 18px; + cursor: pointer; + margin-left: 20px; + color: #666666; + &:hover { + color: #288fff; + } + &.last{ + margin-right: 10px; + } + } + + .toolbar-btn { + font-size: 16px; + } + + .toolbar-left { + flex: 1; + display: flex; + align-items: center; + } + + .toolbar-right { + justify-self: flex-end; + display: flex; + align-items: center; + } + + .toolbar-el-btn{ + margin-right: 0; + margin-left: 10px; + } + + .custom-ico{ + display: block; + width: 18px; + height: 18px; + background-size: 100% 100%; + + &.view-variables{ + background-image: url('../images/view-variables.png'); + &:hover{ + background-image: url('../images/view-variables_hover.png'); + } + } + + &.startup-parameters{ + background-image: url('../images/startup-params.png'); + &:hover{ + background-image: url('../images/startup-params_hover.png'); + } + } + + &.full-screen-open{ + background-image: url('../images/full-screen-open.png'); + &:hover{ + background-image: url('../images/full-screen-open_hover.png'); + } + } + + &.full-screen-close{ + background-image: url('../images/full-screen-close.png'); + &:hover{ + background-image: url('../images/full-screen-close_hover.png'); + } + } + + &.graph-format{ + background-image: url('../images/graph-format.png'); + &:hover{ + background-image: url('../images/graph-format_hover.png'); + } + } + } +} diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/toolbar.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/toolbar.vue new file mode 100644 index 0000000000..83e6a5366d --- /dev/null +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/toolbar.vue @@ -0,0 +1,218 @@ +/* + * 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. + */ + + + + + diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/x6-helper.js b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/x6-helper.js new file mode 100644 index 0000000000..96a48ebd7f --- /dev/null +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/x6-helper.js @@ -0,0 +1,315 @@ +/* + * 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. + */ +export const X6_NODE_NAME = 'dag-task' +export const X6_EDGE_NAME = 'dag-edge' +export const X6_PORT_OUT_NAME = 'dag-port-out' +export const X6_PORT_IN_NAME = 'dag-port-in' + +const EDGE = '#999999' +const BG_BLUE = 'rgba(40, 143, 255, 0.1)' +const BG_WHITE = '#FFFFFF' +const NODE_BORDER = '#e4e4e4' +const TITLE = '#333' +const STROKE_BLUE = '#288FFF' + +export const PORT_PROPS = { + groups: { + [X6_PORT_OUT_NAME]: { + position: { + name: 'absolute', + args: { + x: 200, + y: 24 + } + }, + markup: [ + { + tagName: 'g', + selector: 'body', + children: [ + { + tagName: 'circle', + selector: 'circle-outer' + }, + { + tagName: 'text', + selector: 'plus-text' + }, + { + tagName: 'circle', + selector: 'circle-inner' + } + ] + } + ], + attrs: { + body: { + magnet: true + }, + 'plus-text': { + fontSize: 12, + fill: EDGE, + text: '+', + textAnchor: 'middle', + x: 0, + y: 3 + }, + 'circle-outer': { + stroke: EDGE, + strokeWidth: 1, + r: 6, + fill: BG_WHITE + }, + 'circle-inner': { + r: 4, + fill: 'transparent' + } + } + }, + [X6_PORT_IN_NAME]: { + position: { + name: 'absolute', + args: { + x: 0, + y: 24 + } + }, + markup: [ + { + tagName: 'g', + selector: 'body', + className: 'in-port-body', + children: [{ + tagName: 'circle', + selector: 'circle', + className: 'circle' + }] + } + ], + attrs: { + body: { + magnet: true + }, + circle: { + r: 4, + strokeWidth: 0, + fill: 'transparent' + } + } + } + } +} + +export const PORT_HIGHLIGHT_PROPS = { + [X6_PORT_OUT_NAME]: { + attrs: { + 'circle-outer': { + stroke: STROKE_BLUE, + fill: BG_BLUE + }, + 'plus-text': { + fill: STROKE_BLUE + }, + 'circle-inner': { + fill: STROKE_BLUE + } + } + }, + [X6_PORT_IN_NAME]: {} +} + +export const NODE_STATUS_MARKUP = [{ + tagName: 'foreignObject', + selector: 'fo', + children: [ + { + tagName: 'body', + selector: 'fo-body', + ns: 'http://www.w3.org/1999/xhtml', + children: [{ + tagName: 'div', + selector: 'status' + }] + } + ] +}] + +export const NODE_PROPS = { + width: 220, + height: 48, + markup: [ + { + tagName: 'rect', + selector: 'body' + }, + { + tagName: 'image', + selector: 'image' + }, + { + tagName: 'text', + selector: 'title' + } + ], + attrs: { + body: { + refWidth: '100%', + refHeight: '100%', + rx: 6, + ry: 6, + pointerEvents: 'visiblePainted', + fill: BG_WHITE, + stroke: NODE_BORDER, + strokeWidth: 1 + }, + image: { + width: 30, + height: 30, + refX: 12, + refY: 9 + }, + title: { + refX: 45, + refY: 18, + fontFamily: 'Microsoft Yahei', + fontSize: 12, + fontWeight: 'bold', + fill: TITLE, + strokeWidth: 0 + }, + fo: { + refX: '46%', + refY: -25, + width: 18, + height: 18 + } + }, + ports: { + ...PORT_PROPS, + items: [ + { + id: X6_PORT_OUT_NAME, + group: X6_PORT_OUT_NAME + }, + { + id: X6_PORT_IN_NAME, + group: X6_PORT_IN_NAME + } + ] + } +} + +export const NODE_HIGHLIGHT_PROPS = { + attrs: { + body: { + fill: BG_BLUE, + stroke: STROKE_BLUE, + strokeDasharray: '5,2' + }, + title: { + fill: STROKE_BLUE + } + } +} + +export const EDGE_PROPS = { + attrs: { + line: { + stroke: EDGE, + strokeWidth: 0.8, + targetMarker: { + tagName: 'path', + fill: EDGE, + strokeWidth: 0, + d: 'M 6 -3 0 0 6 3 Z' + } + } + }, + connector: { + name: 'rounded' + }, + router: { + name: 'er', + args: { + offset: 20, + min: 20, + direction: 'L' + } + }, + defaultLabel: { + markup: [ + { + tagName: 'rect', + selector: 'body' + }, + { + tagName: 'text', + selector: 'label' + } + ], + attrs: { + label: { + fill: EDGE, + fontSize: 14, + textAnchor: 'middle', + textVerticalAnchor: 'middle', + pointerEvents: 'none' + }, + body: { + ref: 'label', + fill: BG_WHITE, + stroke: EDGE, + strokeWidth: 1, + rx: 4, + ry: 4, + refWidth: '140%', + refHeight: '140%', + refX: '-20%', + refY: '-20%' + } + }, + position: { + distance: 0.5, + options: { + absoluteDistance: true, + reverseDistance: true + } + } + } +} + +export const EDGE_HIGHLIGHT_PROPS = { + attrs: { + line: { + stroke: STROKE_BLUE, + targetMarker: { + fill: STROKE_BLUE + } + } + }, + defaultLabel: { + attrs: { + label: { + fill: STROKE_BLUE + }, + body: { + fill: BG_WHITE, + stroke: STROKE_BLUE + } + } + } +} diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/x6-style.scss b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/x6-style.scss new file mode 100644 index 0000000000..b86b51afc6 --- /dev/null +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/canvas/x6-style.scss @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +$STROKE_BLUE: #288FFF; +$BG_WHITE: #FFFFFF; + +.x6-node[data-shape="dag-task"]{ + .in-port-body{ + &.adsorbed,&.available{ + .circle { + stroke: $STROKE_BLUE; + stroke-width: 4; + fill: $BG_WHITE; + } + } + } +} diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.js b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.js deleted file mode 100644 index 66509a65ed..0000000000 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.js +++ /dev/null @@ -1,195 +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. - */ -import Vue from 'vue' -import _ from 'lodash' -import i18n from '@/module/i18n' -import { jsPlumb } from 'jsplumb' -import JSP from './plugIn/jsPlumbHandle' -import DownChart from './plugIn/downChart' -import store from '@/conf/home/store' -import dagre from 'dagre' - -/** - * Prototype method - */ -const Dag = function () { - this.dag = {} - this.instance = {} -} - -/** - * init - * @dag dag vue instance - */ -Dag.prototype.init = function ({ dag, instance }) { - this.dag = dag - this.instance = instance -} - -/** - * set init config - */ -Dag.prototype.setConfig = function (o) { - JSP.setConfig(o) -} - -/** - * create dag - */ -Dag.prototype.create = function () { - const self = this - const plumbIns = jsPlumb.getInstance() - plumbIns.reset() - plumbIns.ready(() => { - JSP.init({ - dag: this.dag, - instance: this.instance, - options: { - onRemoveNodes ($id) { - self.dag.removeEventModelById($id) - } - } - }) - - // init event - JSP.handleEvent() - - // init draggable - JSP.draggable() - }) -} - -/** - * Action event on the right side of the toolbar - */ -Dag.prototype.toolbarEvent = function ({ item, code, is }) { - const self = this - switch (code) { - case 'pointer': - JSP.handleEventPointer(is) - break - case 'line': - JSP.handleEventLine(is) - break - case 'remove': - JSP.handleEventRemove() - break - case 'screen': - JSP.handleEventScreen({ item, is }) - break - case 'download': - Vue.prototype.$confirm(`${i18n.$t('Please confirm whether the workflow has been saved before downloading')}`, `${i18n.$t('Download')}`, { - confirmButtonText: `${i18n.$t('Confirm')}`, - cancelButtonText: `${i18n.$t('Cancel')}`, - type: 'warning' - }).then(() => { - DownChart.download({ - dagThis: self.dag - }) - }).catch(() => { - }) - break - } -} - -/** - * Echo data display - */ -Dag.prototype.backfill = function (arg) { - const that = this - if (arg) { - const marginX = 100 - const g = new dagre.graphlib.Graph() - g.setGraph({}) - g.setDefaultEdgeLabel(function () { return {} }) - - for (const i in store.state.dag.locations) { - const location = store.state.dag.locations[i] - g.setNode(i, { label: i, width: Math.min(location.name.length * 7, 170), height: 150 }) - } - - for (const i in store.state.dag.connects) { - const connect = store.state.dag.connects[i] - g.setEdge(connect.endPointSourceId, connect.endPointTargetId) - } - dagre.layout(g) - - const dataObject = {} - g.nodes().forEach(function (v) { - const node = g.node(v) - const location = store.state.dag.locations[node.label] - const obj = {} - obj.name = location.name - obj.x = node.x + marginX - obj.y = node.y - obj.targetarr = location.targetarr - dataObject[node.label] = obj - }) - jsPlumb.ready(() => { - JSP.init({ - dag: this.dag, - instance: this.instance, - options: { - onRemoveNodes ($id) { - that.dag.removeEventModelById($id) - } - } - }) - // Backfill - JSP.jspBackfill({ - // connects - connects: _.cloneDeep(store.state.dag.connects), - // Node location information - locations: _.cloneDeep(dataObject), - // Node data - largeJson: _.cloneDeep(store.state.dag.tasks) - }) - }) - } else { - const plumbIns = jsPlumb.getInstance() - plumbIns.reset() - plumbIns.ready(() => { - JSP.init({ - dag: this.dag, - instance: this.instance, - options: { - onRemoveNodes ($id) { - that.dag.removeEventModelById($id) - } - } - }) - // Backfill - JSP.jspBackfill({ - // connects - connects: _.cloneDeep(store.state.dag.connects), - // Node location information - locations: _.cloneDeep(store.state.dag.locations), - // Node data - largeJson: _.cloneDeep(store.state.dag.tasks) - }) - }) - } -} - -/** - * Get dag storage format data - */ -Dag.prototype.saveStore = function () { - return JSP.saveStore() -} - -export default new Dag() diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.scss b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.scss old mode 100755 new mode 100644 index ae7bdd8645..12dd8d99b5 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.scss +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.scss @@ -15,563 +15,19 @@ * limitations under the License. */ -.dag-model { - background: url("../img/dag_bg.png"); - height: calc(100vh - 100px); - ::selection { - background:transparent; - } - ::-moz-selection { - background:transparent; - } - ::-webkit-selection { - background:transparent; - } - .jsplumb-connector { - z-index: 1; - } - .endpoint-tasks { - margin-top:22px; - } - .draggable { - > span { - text-align: center; - display: block; - margin-top: -4px; - padding: 0 4px; - width: 200px; - margin-left: -81px; - position: absolute; - left: 0; - bottom: -12px; - } - .fa { - display: inline-block; - position: absolute; - right: -8px; - top: -8px; - z-index: 2; - cursor: pointer; - } - .icos { - display: inline-block; - cursor: pointer; - } - &.active-tasks { - span { - color: #0296DF; - } - } - } - .icos { - width: 32px; - height: 32px; - margin: 2px; - border-radius: 3px; - position: relative; - z-index: 9; - } - .icos-SHELL { - background: url("../img/toolbar_SHELL.png") no-repeat 50% 50%; - } - .icos-WATERDROP { - background: url("../img/toolbar_WATERDROP.png") no-repeat 50% 50%; - } - .icos-SUB_PROCESS { - background: url("../img/toolbar_SUB_PROCESS.png") no-repeat 50% 50%; - } - .icos-PROCEDURE { - background: url("../img/toolbar_PROCEDURE.png") no-repeat 50% 50%; - } - .icos-SQL { - background: url("../img/toolbar_SQL.png") no-repeat 50% 50%; - } - .icos-SPARK { - background: url("../img/toolbar_SPARK.png") no-repeat 50% 50%; - } - .icos-FLINK { - background: url("../img/toolbar_FLINK.png") no-repeat 50% 50%; - } - .icos-MR { - background: url("../img/toolbar_MR.png") no-repeat 50% 50%; - } - .icos-PYTHON { - background: url("../img/toolbar_PYTHON.png") no-repeat 50% 50%; - } - .icos-DEPENDENT { - background: url("../img/toolbar_DEPENDENT.png") no-repeat 50% 50%; - } - .icos-HTTP { - background: url("../img/toolbar_HTTP.png") no-repeat 50% 50%; - } - .icos-DATAX { - background: url("../img/toolbar_DATAX.png") no-repeat 50% 50%; - } - .icos-TIS { - background: url("../img/toolbar_TIS.svg") no-repeat 50% 50%; - } - .icos-SQOOP { - background: url("../img/toolbar_SQOOP.png") no-repeat 50% 50%; - } - .icos-CONDITIONS { - background: url("../img/toolbar_CONDITIONS.png") no-repeat 50% 50%; - } - .icos-SWITCH{ - background: url("../img/toolbar_SWITCH.png") no-repeat 50% 50%; - } - .toolbar { - width: 60px; - height: 100%; - background: #F2F3F7; - float: left; - border-radius: 0 0 0 3px; - .title { - height: 40px; - line-height: 40px; - background: #40434C; - text-align: center; - border-radius: 3px 0 0 0; - span { - font-size: 14px; - color: #fff; - font-weight: bold; - } - } - .toolbar-btn { - overflow: hidden; - padding: 8px 11px 0 11px; - .bar-box { - width: 36px; - height: 36px; - float: left; - margin-bottom: 3px; - border-radius: 3px; - .disabled { - .icos { - opacity: .6; - -webkit-filter: grayscale(100%); - -moz-filter: grayscale(100%); - -ms-filter: grayscale(100%); - -o-filter: grayscale(100%); - filter: grayscale(100%); - filter: gray; - } - } - &:nth-child(odd) { - margin-right: 6px; - } - &.active { - background: #e1e2e3; - } - } - } - } - .dag-contect { - float: left; - width: calc(100% - 60px); - height: 100%; - .dag-toolbar { - height: 40px; - background: #F2F3F7; - position: relative; - border-radius: 0 3px 0 0; - .ans-btn-text { - color: #337ab7; - .ans-icon { - font-size: 16px; - } - } - .assist-btn { - position: absolute; - left: 10px; - top: 7px; - >.name { - padding-left: 6px; - vertical-align: middle; - } - >.copy-name { - cursor: pointer; - padding-left: 4px; - position: relative; - top: -2px; - &:hover { - i { - color: #47c3ff; - } - } - i { - color: #333; - font-size: 18px; - vertical-align: middle; - } - } - } - .save-btn { - position: absolute; - right: 8px; - top: 6px; - .operation { - overflow: hidden; - display: inline-block; - a { - float: left; - width: 28px; - height: 28px; - text-align: center; - line-height: 28px; - margin-left: 6px; - border-radius: 3px; - vertical-align: middle; - i { - color: #333; - } - &.active { - // background: #e1e2e3; - i { - color: #2d8cf0; - } - } - &.disable { - i { - color: #bbb; - } - } - } - } - } - } - .dag-container { - height: calc(100% - 40px); - overflow-x: auto; - &::-webkit-scrollbar{ - width: 9px; - } - } - } - .tools-model { - height: 60px; - background: #F4F5F4; - border-radius: 3px 3px 0px 0px; - } -} -#screen { - margin-right: 5px; -} -.v-modal-custom-log { - z-index: 101; -} - -svg path:hover { - cursor: pointer; -} - -#chart-container .ui-selecting { - span { - color: #0296DF; - } -} -#chart-container .ui-selected { - span { - color: #0296DF; - } -} - -.contextmenu { - position: fixed; - width: 90px; - background: #fff; - border-radius: 3px; - box-shadow: 0 2px 4px 1px rgba(0, 0, 0, 0.1); - padding: 4px 4px; - visibility:hidden; - z-index: 10000; - a { - height: 30px; - line-height: 28px; - display: block; - i { - font-size: 16px; - vertical-align: middle; - margin-left: 10px; - } - span { - vertical-align: middle; - font-size: 12px; - color: #666; - padding-left: 2px; - } - &:hover { - background: #f6faff; - } - &#startRunning { - i { - color: #35cd75; - } - } - &#editNodes { - i { - color: #0097e0; - } - } - &#removeNodes { - i { - color: #f04d4e; - } - } - &#copyNodes { - i { - color: #FABC05; - } - } - &.disbled { - i,span { - color: #aaa !important; - } - } - } -} - -.jtk-demo { - //min-width: calc(100% - 220px); - width: 8000px; - height: 5000px; - svg:not(:root){ - z-index: 11; - } -} - -.jtk-demo-canvas { - position: relative; - height: 100%; - display: flex; -} - -.jtk-bootstrap { - min-height: 100vh; - display: flex; - flex-direction: column; -} - -.jtk-bootstrap .jtk-page-container { - display: flex; - width: 100vw; - justify-content: center; - flex: 1; -} - -.jtk-bootstrap .jtk-container { - width: 60%; - max-width: 800px; -} - -.jtk-bootstrap-wide .jtk-container { - width: 80%; - max-width: 1187px; -} - -.jtk-demo-main { - position: relative; - margin-top: 98px; -} - -.jtk-demo-main .description { - font-size: 13px; - margin-top: 25px; - padding: 13px; - margin-bottom: 22px; - background-color: #f4f5ef; -} - -.jtk-demo-main .description li { - list-style-type: disc !important; -} - -.canvas-wide { - padding-top: 10px; - margin-left: 0; - -ms-transition: all .1s ease-out; - -moz-transition: all .1s ease-out; - -webkit-transition: all .1s ease-out; - -o-transition: all .1s ease-out; -} - -.jtk-demo-dataset { - text-align: left; - max-height: 600px; - overflow: auto; -} - -.demo-title { - float: left; - font-size: 18px; -} - -.controls { - top: 25px; - color: #FFF; - margin-right: 10px; - position: absolute; - left: 25px; - z-index: 1; -} - -.controls i { - background-color: #3E7E9C; - border-radius: 4px; - cursor: pointer; - margin-right: 0; - padding: 4px; -} -.w { - position: absolute; - z-index: 4; - font-size: 11px; - -webkit-transition: background-color 0.25s ease-in; - -moz-transition: background-color 0.25s ease-in; - transition: background-color 0.25s ease-in; - border: 7px solid transparent; - border-bottom: 30px solid transparent; - .icos { - width: 50px; - height: 50px; - box-shadow: 2px 2px 19px #e0e0e0; - -o-box-shadow: 2px 2px 19px #e0e0e0; - -webkit-box-shadow: 2px 2px 19px #e0e0e0; - -moz-box-shadow: 2px 2px 19px #e0e0e0; - -moz-border-radius: 8px; - border-radius: 8px; - opacity: 0.8; - cursor: move; - background-color: #fff; - } - .name-p { - position: absolute; - left: 50%; - top: 58px; - width: 200px; - text-align: center; - margin-left: -100px; - word-break:break-all; - } - .ban-p { - position: absolute; - left: -4px; - top: 36px; - z-index: 21; - i { - font-size: 18px; - color: #ff0000; - cursor: pointer; - } - } - .state-p { - width: 20px; - height: 20px; - position: absolute; - top: -20px; - left: 18px; - text-align: center; - cursor: pointer; - b { - font-weight: normal; - } - } -} - -.aLabel { - -webkit-transition: background-color 0.25s ease-in; - -moz-transition: background-color 0.25s ease-in; - transition: background-color 0.25s ease-in; - background-color: white; - opacity: 0.8; - padding: 0.3em; - border-radius: 0.5em; - border: 1px solid #346789; - cursor: pointer; -} - -.aLabel.jtk-hover, -.jtk-source-hover, -.jtk-target-hover { - .icos { - background-color: #333; - color: #333; - -ms-transition: all 0.6s ease-out; - -moz-transition: all 0.6s ease-out; - -webkit-transition: all 0.6s ease-out; - -o-transition: all 0.6s ease-out; - } -} - -.jtk-tasks-active { - .icos { - background-color: #2db7f5; - color: #0097e0; - -ms-transition: all 0.6s ease-out; - -moz-transition: all 0.6s ease-out; - -webkit-transition: all 0.6s ease-out; - -o-transition: all 0.6s ease-out; - } -} - - -.jtk-ep { - .ep { - display: block; - } -} - -.ep { - position: absolute; - top: -4%; - right: -1px; - width: 1em; - height: 1em; - z-index: 12; - background-color: orange; - cursor: pointer; - box-shadow: 0 0 2px black; - -webkit-transition: -webkit-box-shadow 0.25s ease-in; - -moz-transition: -moz-box-shadow 0.25s ease-in; - transition: box-shadow 0.25s ease-in; - border-radius:100%; - display: none; -} - -.ep:hover { - box-shadow: 0 0 6px black; -} - -.statemachine-demo .jtk-endpoint { - z-index: 3; -} - -#canvas { - .dot-style { - opacity: 0; - } -} - -.form-mirror { +.dag-chart { width: 100%; - position: relative; - z-index: 0; - .CodeMirror { - height:auto; - min-height: 72px; - } + height: calc(100vh - 100px); + padding: 10px; + background: #f2f3f7; - .CodeMirror-scroll { - height:auto; - min-height: 72px; - overflow-y: hidden; - overflow-x: auto; + &.full-screen { + position: fixed; + width: 100%; + height: 100%; + top: 0; + left: 0; + z-index: 1000; } } -.ans-modal-box.ans-drawer.ans-drawer-right.dagMask.mask { - width: 628px; - left: auto; -} - - diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.vue old mode 100755 new mode 100644 index df8bf33955..a81037294a --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.vue @@ -15,226 +15,114 @@ * limitations under the License. */ - - + + diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/formModel.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/formModel.vue index 17a67b2383..b69d7dc95f 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/formModel.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/formModel.vue @@ -20,7 +20,7 @@ {{$t('Current node settings')}} - + @@ -50,8 +50,8 @@
{{$t('Run flag')}}
- {{$t('Normal')}} - {{$t('Prohibition execution')}} + {{$t('Normal')}} + {{$t('Prohibition execution')}}
@@ -253,13 +253,6 @@ ref="DATAX" :backfill-item="backfillItem"> - - - +
@@ -300,7 +294,7 @@ diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/log.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/log.vue index 81d59d8b95..b022dfd421 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/log.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/log.vue @@ -16,7 +16,7 @@ */