From 4769bce0d7529cf990b7fb397f0c5a61138b236b Mon Sep 17 00:00:00 2001 From: Han Gao Date: Fri, 17 Apr 2020 11:49:43 +0800 Subject: [PATCH] update controllers with ApiException annotation (#2401) Co-authored-by: dailidong Co-authored-by: qiaozhanwei --- .../api/controller/AlertGroupController.java | 165 ++-- .../controller/DataAnalysisController.java | 140 ++-- .../api/controller/DataSourceController.java | 340 ++++----- .../api/controller/ExecutorController.java | 157 ++-- .../api/controller/LoggerController.java | 52 +- .../api/controller/LoginController.java | 91 +-- .../api/controller/MonitorController.java | 63 +- .../ProcessDefinitionController.java | 460 +++++------ .../controller/ProcessInstanceController.java | 357 ++++----- .../api/controller/ProjectController.java | 176 ++--- .../api/controller/QueueController.java | 137 ++-- .../api/controller/ResourcesController.java | 715 ++++++++---------- .../api/controller/SchedulerController.java | 238 +++--- .../controller/TaskInstanceController.java | 65 +- .../api/controller/TaskRecordController.java | 90 +-- .../api/controller/TenantController.java | 174 ++--- .../api/controller/UsersController.java | 359 ++++----- .../api/controller/WorkerGroupController.java | 100 +-- .../api/exceptions/ApiExceptionHandler.java | 3 +- .../exceptions/ApiExceptionHandlerTest.java | 12 + 20 files changed, 1700 insertions(+), 2194 deletions(-) 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 140434ee43..35bbc2af2f 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 @@ -16,6 +16,7 @@ */ package org.apache.dolphinscheduler.api.controller; +import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.AlertGroupService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; @@ -37,13 +38,15 @@ import springfox.documentation.annotations.ApiIgnore; import java.util.HashMap; import java.util.Map; +import static org.apache.dolphinscheduler.api.enums.Status.*; + /** * alert group controller */ @Api(tags = "ALERT_GROUP_TAG", position = 1) @RestController @RequestMapping("alert-group") -public class AlertGroupController extends BaseController{ +public class AlertGroupController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(AlertGroupController.class); @@ -53,171 +56,154 @@ public class AlertGroupController extends BaseController{ /** * create alert group - * @param loginUser login user - * @param groupName group name - * @param groupType group type + * + * @param loginUser login user + * @param groupName group name + * @param groupType group type * @param description description * @return create result code */ - @ApiOperation(value = "createAlertgroup", notes= "CREATE_ALERT_GROUP_NOTES") + @ApiOperation(value = "createAlertgroup", notes = "CREATE_ALERT_GROUP_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "groupType", value = "GROUP_TYPE", required = true, dataType ="AlertType"), - @ApiImplicitParam(name = "description", value = "DESC", dataType ="String") + @ApiImplicitParam(name = "groupType", value = "GROUP_TYPE", required = true, dataType = "AlertType"), + @ApiImplicitParam(name = "description", value = "DESC", dataType = "String") }) @PostMapping(value = "/create") @ResponseStatus(HttpStatus.CREATED) + @ApiException(CREATE_ALERT_GROUP_ERROR) public Result createAlertgroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "groupName") String groupName, - @RequestParam(value = "groupType") AlertType groupType, - @RequestParam(value = "description",required = false) String description) { + @RequestParam(value = "groupName") String groupName, + @RequestParam(value = "groupType") AlertType groupType, + @RequestParam(value = "description", required = false) String description) { logger.info("loginUser user {}, create alertgroup, groupName: {}, groupType: {}, desc: {}", - loginUser.getUserName(), groupName, groupType,description); - try { - Map result = alertGroupService.createAlertgroup(loginUser, groupName, groupType,description); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.CREATE_ALERT_GROUP_ERROR.getMsg(),e); - return error(Status.CREATE_ALERT_GROUP_ERROR.getCode(), Status.CREATE_ALERT_GROUP_ERROR.getMsg()); - } + loginUser.getUserName(), groupName, groupType, description); + Map result = alertGroupService.createAlertgroup(loginUser, groupName, groupType, description); + return returnDataList(result); } /** * alert group list + * * @param loginUser login user * @return alert group list */ - @ApiOperation(value = "list", notes= "QUERY_ALERT_GROUP_LIST_NOTES") + @ApiOperation(value = "list", notes = "QUERY_ALERT_GROUP_LIST_NOTES") @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_ALL_ALERTGROUP_ERROR) public Result list(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { logger.info("login user {}, query all alertGroup", loginUser.getUserName()); - try { - HashMap result = alertGroupService.queryAlertgroup(); - return returnDataList(result); - } catch (Exception e) { - logger.error(Status.QUERY_ALL_ALERTGROUP_ERROR.getMsg(), e); - return error(Status.QUERY_ALL_ALERTGROUP_ERROR.getCode(), Status.QUERY_ALL_ALERTGROUP_ERROR.getMsg()); - } + HashMap result = alertGroupService.queryAlertgroup(); + return returnDataList(result); } /** * paging query alarm group list * * @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 alert group list page */ - @ApiOperation(value = "queryAlertGroupListPaging", notes= "QUERY_ALERT_GROUP_LIST_PAGING_NOTES") + @ApiOperation(value = "queryAlertGroupListPaging", notes = "QUERY_ALERT_GROUP_LIST_PAGING_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type ="String"), + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"), @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"), @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20") }) - @GetMapping(value="/list-paging") + @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) + @ApiException(LIST_PAGING_ALERT_GROUP_ERROR) public Result listPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("pageNo") Integer pageNo, @RequestParam(value = "searchVal", required = false) String searchVal, - @RequestParam("pageSize") Integer pageSize){ + @RequestParam("pageSize") Integer pageSize) { logger.info("login user {}, list paging, pageNo: {}, searchVal: {}, pageSize: {}", - loginUser.getUserName(),pageNo,searchVal,pageSize); - try{ - Map result = checkPageParams(pageNo, pageSize); - if(result.get(Constants.STATUS) != Status.SUCCESS){ - return returnDataListPaging(result); - } - - searchVal = ParameterUtils.handleEscapes(searchVal); - result = alertGroupService.listPaging(loginUser, searchVal, pageNo, pageSize); + loginUser.getUserName(), pageNo, searchVal, pageSize); + Map result = checkPageParams(pageNo, pageSize); + if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); - }catch (Exception e){ - logger.error(Status.LIST_PAGING_ALERT_GROUP_ERROR.getMsg(),e); - return error(Status.LIST_PAGING_ALERT_GROUP_ERROR.getCode(), Status.LIST_PAGING_ALERT_GROUP_ERROR.getMsg()); } + + searchVal = ParameterUtils.handleEscapes(searchVal); + result = alertGroupService.listPaging(loginUser, searchVal, pageNo, pageSize); + return returnDataListPaging(result); } /** * updateProcessInstance alert group - * @param loginUser login user - * @param id alert group id - * @param groupName group name - * @param groupType group type + * + * @param loginUser login user + * @param id alert group id + * @param groupName group name + * @param groupType group type * @param description description * @return update result code */ - @ApiOperation(value = "updateAlertgroup", notes= "UPDATE_ALERT_GROUP_NOTES") + @ApiOperation(value = "updateAlertgroup", notes = "UPDATE_ALERT_GROUP_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"), @ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "groupType", value = "GROUP_TYPE", required = true, dataType ="AlertType"), - @ApiImplicitParam(name = "description", value = "DESC", dataType ="String") + @ApiImplicitParam(name = "groupType", value = "GROUP_TYPE", required = true, dataType = "AlertType"), + @ApiImplicitParam(name = "description", value = "DESC", dataType = "String") }) @PostMapping(value = "/update") @ResponseStatus(HttpStatus.OK) + @ApiException(UPDATE_ALERT_GROUP_ERROR) public Result updateAlertgroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int id, @RequestParam(value = "groupName") String groupName, @RequestParam(value = "groupType") AlertType groupType, - @RequestParam(value = "description",required = false) String description) { + @RequestParam(value = "description", required = false) String description) { logger.info("login user {}, updateProcessInstance alertgroup, groupName: {}, groupType: {}, desc: {}", - loginUser.getUserName(), groupName, groupType,description); - try { - Map result = alertGroupService.updateAlertgroup(loginUser, id, groupName, groupType, description); - return returnDataList(result); - - }catch (Exception e){ - logger.error(Status.UPDATE_ALERT_GROUP_ERROR.getMsg(),e); - return error(Status.UPDATE_ALERT_GROUP_ERROR.getCode(), Status.UPDATE_ALERT_GROUP_ERROR.getMsg()); - } + loginUser.getUserName(), groupName, groupType, description); + Map result = alertGroupService.updateAlertgroup(loginUser, id, groupName, groupType, description); + return returnDataList(result); } /** * delete alert group by id + * * @param loginUser login user - * @param id alert group id + * @param id alert group id * @return delete result code */ - @ApiOperation(value = "delAlertgroupById", notes= "DELETE_ALERT_GROUP_BY_ID_NOTES") + @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") @ResponseStatus(HttpStatus.OK) + @ApiException(DELETE_ALERT_GROUP_ERROR) public Result delAlertgroupById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int id) { + @RequestParam(value = "id") int id) { logger.info("login user {}, delete AlertGroup, id: {},", loginUser.getUserName(), id); - try { - Map result = alertGroupService.delAlertgroupById(loginUser, id); - return returnDataList(result); - - }catch (Exception e){ - logger.error(Status.DELETE_ALERT_GROUP_ERROR.getMsg(),e); - return error(Status.DELETE_ALERT_GROUP_ERROR.getCode(), Status.DELETE_ALERT_GROUP_ERROR.getMsg()); - } + Map result = alertGroupService.delAlertgroupById(loginUser, id); + return returnDataList(result); } /** * check alert group exist + * * @param loginUser login user * @param groupName group name * @return check result code */ - @ApiOperation(value = "verifyGroupName", notes= "VERIFY_ALERT_GROUP_NAME_NOTES") + @ApiOperation(value = "verifyGroupName", notes = "VERIFY_ALERT_GROUP_NAME_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"), }) @GetMapping(value = "/verify-group-name") @ResponseStatus(HttpStatus.OK) public Result verifyGroupName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value ="groupName") String groupName) { + @RequestParam(value = "groupName") String groupName) { logger.info("login user {}, verify group name: {}", loginUser.getUserName(), groupName); - boolean exist= alertGroupService.existGroupName(groupName); + boolean exist = alertGroupService.existGroupName(groupName); Result result = new Result(); if (exist) { logger.error("group {} has exist, can't create again.", groupName); @@ -233,29 +219,24 @@ public class AlertGroupController extends BaseController{ /** * grant user * - * @param loginUser login user - * @param userIds user ids in the group + * @param loginUser login user + * @param userIds user ids in the group * @param alertgroupId alert group id * @return grant result code */ - @ApiOperation(value = "grantUser", notes= "GRANT_ALERT_GROUP_NOTES") + @ApiOperation(value = "grantUser", notes = "GRANT_ALERT_GROUP_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"), @ApiImplicitParam(name = "userIds", value = "USER_IDS", required = true, dataType = "String") }) @PostMapping(value = "/grant-user") @ResponseStatus(HttpStatus.OK) + @ApiException(ALERT_GROUP_GRANT_USER_ERROR) public Result grantUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "alertgroupId") int alertgroupId, - @RequestParam(value = "userIds") String userIds) { - logger.info("login user {}, grant user, alertGroupId: {},userIds : {}", loginUser.getUserName(), alertgroupId,userIds); - try { - Map result = alertGroupService.grantUser(loginUser, alertgroupId, userIds); - return returnDataList(result); - - }catch (Exception e){ - logger.error(Status.ALERT_GROUP_GRANT_USER_ERROR.getMsg(),e); - return error(Status.ALERT_GROUP_GRANT_USER_ERROR.getCode(), Status.ALERT_GROUP_GRANT_USER_ERROR.getMsg()); - } + @RequestParam(value = "alertgroupId") int alertgroupId, + @RequestParam(value = "userIds") String userIds) { + logger.info("login user {}, grant user, alertGroupId: {},userIds : {}", loginUser.getUserName(), alertgroupId, userIds); + Map result = alertGroupService.grantUser(loginUser, alertgroupId, userIds); + return returnDataList(result); } } 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 f93e7d6944..f53391f203 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 @@ -17,6 +17,7 @@ package org.apache.dolphinscheduler.api.controller; +import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.DataAnalysisService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; @@ -25,7 +26,6 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; -import org.apache.dolphinscheduler.api.enums.Status; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -35,13 +35,15 @@ import springfox.documentation.annotations.ApiIgnore; import java.util.Map; +import static org.apache.dolphinscheduler.api.enums.Status.*; + /** * data analysis controller */ @Api(tags = "DATA_ANALYSIS_TAG", position = 1) @RestController @RequestMapping("projects/analysis") -public class DataAnalysisController extends BaseController{ +public class DataAnalysisController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(DataAnalysisController.class); @@ -54,31 +56,27 @@ public class DataAnalysisController extends BaseController{ * * @param loginUser login user * @param startDate count start date - * @param endDate count end date + * @param endDate count end date * @param projectId project id * @return task instance count data */ - @ApiOperation(value = "countTaskState", notes= "COUNT_TASK_STATE_NOTES") + @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 = "endDate", value = "END_DATE", dataType = "String"), + @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100") }) - @GetMapping(value="/task-state-count") + @GetMapping(value = "/task-state-count") @ResponseStatus(HttpStatus.OK) + @ApiException(TASK_INSTANCE_STATE_COUNT_ERROR) 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){ - try{ - logger.info("count task state, user:{}, start date: {}, end date:{}, project id {}", - loginUser.getUserName(), startDate, endDate, projectId); - Map result = dataAnalysisService.countTaskStateByProject(loginUser,projectId, startDate, endDate); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.TASK_INSTANCE_STATE_COUNT_ERROR.getMsg(),e); - return error(Status.TASK_INSTANCE_STATE_COUNT_ERROR.getCode(), Status.TASK_INSTANCE_STATE_COUNT_ERROR.getMsg()); - } + @RequestParam(value = "startDate", required = false) String startDate, + @RequestParam(value = "endDate", required = false) String endDate, + @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) { + logger.info("count task state, user:{}, start date: {}, end date:{}, project id {}", + loginUser.getUserName(), startDate, endDate, projectId); + Map result = dataAnalysisService.countTaskStateByProject(loginUser, projectId, startDate, endDate); + return returnDataList(result); } /** @@ -86,31 +84,27 @@ public class DataAnalysisController extends BaseController{ * * @param loginUser login user * @param startDate start date - * @param endDate end date + * @param endDate end date * @param projectId project id * @return process instance data */ - @ApiOperation(value = "countProcessInstanceState", notes= "COUNT_PROCESS_INSTANCE_NOTES") + @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 = "endDate", value = "END_DATE", dataType = "String"), + @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100") }) - @GetMapping(value="/process-state-count") + @GetMapping(value = "/process-state-count") @ResponseStatus(HttpStatus.OK) + @ApiException(COUNT_PROCESS_INSTANCE_STATE_ERROR) 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){ - try{ - logger.info("count process instance state, user:{}, start date: {}, end date:{}, project id:{}", - loginUser.getUserName(), startDate, endDate, projectId); - Map result = dataAnalysisService.countProcessInstanceStateByProject(loginUser, projectId, startDate, endDate); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.COUNT_PROCESS_INSTANCE_STATE_ERROR.getMsg(),e); - return error(Status.COUNT_PROCESS_INSTANCE_STATE_ERROR.getCode(), Status.COUNT_PROCESS_INSTANCE_STATE_ERROR.getMsg()); - } + @RequestParam(value = "startDate", required = false) String startDate, + @RequestParam(value = "endDate", required = false) String endDate, + @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) { + logger.info("count process instance state, user:{}, start date: {}, end date:{}, project id:{}", + loginUser.getUserName(), startDate, endDate, projectId); + Map result = dataAnalysisService.countProcessInstanceStateByProject(loginUser, projectId, startDate, endDate); + return returnDataList(result); } /** @@ -120,23 +114,19 @@ public class DataAnalysisController extends BaseController{ * @param projectId project id * @return definition count in project id */ - @ApiOperation(value = "countDefinitionByUser", notes= "COUNT_PROCESS_DEFINITION_BY_USER_NOTES") + @ApiOperation(value = "countDefinitionByUser", notes = "COUNT_PROCESS_DEFINITION_BY_USER_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType ="Int", example = "100") + @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100") }) - @GetMapping(value="/define-user-count") + @GetMapping(value = "/define-user-count") @ResponseStatus(HttpStatus.OK) + @ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR) public Result countDefinitionByUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value="projectId", required=false, defaultValue = "0") int projectId){ - try{ - logger.info("count process definition , user:{}, project id:{}", - loginUser.getUserName(), projectId); - Map result = dataAnalysisService.countDefinitionByUser(loginUser, projectId); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.COUNT_PROCESS_DEFINITION_USER_ERROR.getMsg(),e); - return error(Status.COUNT_PROCESS_DEFINITION_USER_ERROR.getCode(), Status.COUNT_PROCESS_DEFINITION_USER_ERROR.getMsg()); - } + @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) { + logger.info("count process definition , user:{}, project id:{}", + loginUser.getUserName(), projectId); + Map result = dataAnalysisService.countDefinitionByUser(loginUser, projectId); + return returnDataList(result); } @@ -145,31 +135,27 @@ public class DataAnalysisController extends BaseController{ * * @param loginUser login user * @param startDate start date - * @param endDate end date + * @param endDate end date * @param projectId project id * @return command state in project id */ - @ApiOperation(value = "countCommandState", notes= "COUNT_COMMAND_STATE_NOTES") + @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") + @ApiImplicitParam(name = "endDate", value = "END_DATE", dataType = "String"), + @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100") }) - @GetMapping(value="/command-state-count") + @GetMapping(value = "/command-state-count") @ResponseStatus(HttpStatus.OK) + @ApiException(COMMAND_STATE_COUNT_ERROR) 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){ - try{ - logger.info("count command state, user:{}, start date: {}, end date:{}, project id {}", - loginUser.getUserName(), startDate, endDate, projectId); - Map result = dataAnalysisService.countCommandState(loginUser, projectId, startDate, endDate); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.COMMAND_STATE_COUNT_ERROR.getMsg(),e); - return error(Status.COMMAND_STATE_COUNT_ERROR.getCode(), Status.COMMAND_STATE_COUNT_ERROR.getMsg()); - } + @RequestParam(value = "startDate", required = false) String startDate, + @RequestParam(value = "endDate", required = false) String endDate, + @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) { + logger.info("count command state, user:{}, start date: {}, end date:{}, project id {}", + loginUser.getUserName(), startDate, endDate, projectId); + Map result = dataAnalysisService.countCommandState(loginUser, projectId, startDate, endDate); + return returnDataList(result); } /** @@ -179,23 +165,19 @@ public class DataAnalysisController extends BaseController{ * @param projectId project id * @return queue state count */ - @ApiOperation(value = "countQueueState", notes= "COUNT_QUEUE_STATE_NOTES") + @ApiOperation(value = "countQueueState", notes = "COUNT_QUEUE_STATE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType ="Int", example = "100") + @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100") }) - @GetMapping(value="/queue-count") + @GetMapping(value = "/queue-count") @ResponseStatus(HttpStatus.OK) + @ApiException(QUEUE_COUNT_ERROR) public Result countQueueState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value="projectId", required=false, defaultValue = "0") int projectId){ - try{ - logger.info("count command state, user:{}, project id {}", - loginUser.getUserName(), projectId); - Map result = dataAnalysisService.countQueueState(loginUser, projectId); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.QUEUE_COUNT_ERROR.getMsg(),e); - return error(Status.QUEUE_COUNT_ERROR.getCode(), Status.QUEUE_COUNT_ERROR.getMsg()); - } + @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) { + logger.info("count command state, user:{}, project id {}", + loginUser.getUserName(), projectId); + Map result = dataAnalysisService.countQueueState(loginUser, projectId); + 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 89e6134609..7f35ac0d70 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 @@ -21,6 +21,7 @@ import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.DataSourceService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; @@ -39,6 +40,7 @@ import springfox.documentation.annotations.ApiIgnore; import java.util.Map; import static org.apache.dolphinscheduler.api.enums.Status.*; + /** * data source controller */ @@ -54,34 +56,36 @@ public class DataSourceController extends BaseController { /** * create data source + * * @param loginUser login user - * @param name data source name - * @param note data source description - * @param type data source type - * @param host host - * @param port port - * @param database data base + * @param name data source name + * @param note data source description + * @param type data source type + * @param host host + * @param port port + * @param database data base * @param principal principal - * @param userName user name - * @param password password - * @param other other arguments + * @param userName user name + * @param password password + * @param other other arguments * @return create result code */ - @ApiOperation(value = "createDataSource", notes= "CREATE_DATA_SOURCE_NOTES") + @ApiOperation(value = "createDataSource", notes = "CREATE_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"), @ApiImplicitParam(name = "note", value = "DATA_SOURCE_NOTE", dataType = "String"), - @ApiImplicitParam(name = "type", value = "DB_TYPE", required = true,dataType ="DbType"), - @ApiImplicitParam(name = "host", value = "DATA_SOURCE_HOST",required = true, dataType ="String"), - @ApiImplicitParam(name = "port", value = "DATA_SOURCE_PORT",required = true, dataType ="String"), - @ApiImplicitParam(name = "database", value = "DATABASE_NAME",required = true, dataType ="String"), - @ApiImplicitParam(name = "userName", value = "USER_NAME",required = true, dataType ="String"), - @ApiImplicitParam(name = "password", value = "PASSWORD", dataType ="String"), + @ApiImplicitParam(name = "type", value = "DB_TYPE", required = true, dataType = "DbType"), + @ApiImplicitParam(name = "host", value = "DATA_SOURCE_HOST", required = true, dataType = "String"), + @ApiImplicitParam(name = "port", value = "DATA_SOURCE_PORT", required = true, dataType = "String"), + @ApiImplicitParam(name = "database", value = "DATABASE_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "userName", value = "USER_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "password", value = "PASSWORD", dataType = "String"), @ApiImplicitParam(name = "connectType", value = "CONNECT_TYPE", dataType = "DbConnectType"), - @ApiImplicitParam(name = "other", value = "DATA_SOURCE_OTHER", dataType ="String") + @ApiImplicitParam(name = "other", value = "DATA_SOURCE_OTHER", dataType = "String") }) @PostMapping(value = "/create") @ResponseStatus(HttpStatus.CREATED) + @ApiException(CREATE_DATASOURCE_ERROR) public Result createDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("name") String name, @RequestParam(value = "note", required = false) String note, @@ -96,15 +100,9 @@ public class DataSourceController extends BaseController { @RequestParam(value = "other") String other) { logger.info("login user {} create datasource name: {}, note: {}, type: {}, host: {}, port: {}, database : {}, principal: {}, userName : {}, connectType: {}, other: {}", loginUser.getUserName(), name, note, type, host, port, database, principal, userName, connectType, other); - try { - String parameter = dataSourceService.buildParameter(name, note, type, host, port, database, principal, userName, password, connectType, other); - Map result = dataSourceService.createDataSource(loginUser, name, note, type, parameter); - return returnDataList(result); - - } catch (Exception e) { - logger.error(CREATE_DATASOURCE_ERROR.getMsg(),e); - return error(Status.CREATE_DATASOURCE_ERROR.getCode(), Status.CREATE_DATASOURCE_ERROR.getMsg()); - } + String parameter = dataSourceService.buildParameter(name, note, type, host, port, database, principal, userName, password, connectType, other); + Map result = dataSourceService.createDataSource(loginUser, name, note, type, parameter); + return returnDataList(result); } @@ -112,35 +110,36 @@ public class DataSourceController extends BaseController { * updateProcessInstance data source * * @param loginUser login user - * @param name data source name - * @param note description - * @param type data source type - * @param other other arguments - * @param id data source di - * @param host host - * @param port port - * @param database database + * @param name data source name + * @param note description + * @param type data source type + * @param other other arguments + * @param id data source di + * @param host host + * @param port port + * @param database database * @param principal principal - * @param userName user name - * @param password password + * @param userName user name + * @param password password * @return update result code */ - @ApiOperation(value = "updateDataSource", notes= "UPDATE_DATA_SOURCE_NOTES") + @ApiOperation(value = "updateDataSource", notes = "UPDATE_DATA_SOURCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "DATA_SOURCE_ID", required = true, dataType ="Int", example = "100"), - @ApiImplicitParam(name = "name", value = "DATA_SOURCE_NAME", required = true, dataType ="String"), + @ApiImplicitParam(name = "id", value = "DATA_SOURCE_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "name", value = "DATA_SOURCE_NAME", required = true, dataType = "String"), @ApiImplicitParam(name = "note", value = "DATA_SOURCE_NOTE", dataType = "String"), - @ApiImplicitParam(name = "type", value = "DB_TYPE", required = true,dataType ="DbType"), - @ApiImplicitParam(name = "host", value = "DATA_SOURCE_HOST",required = true, dataType ="String"), - @ApiImplicitParam(name = "port", value = "DATA_SOURCE_PORT",required = true, dataType ="String"), - @ApiImplicitParam(name = "database", value = "DATABASE_NAME",required = true, dataType ="String"), - @ApiImplicitParam(name = "userName", value = "USER_NAME",required = true, dataType ="String"), - @ApiImplicitParam(name = "password", value = "PASSWORD", dataType ="String"), + @ApiImplicitParam(name = "type", value = "DB_TYPE", required = true, dataType = "DbType"), + @ApiImplicitParam(name = "host", value = "DATA_SOURCE_HOST", required = true, dataType = "String"), + @ApiImplicitParam(name = "port", value = "DATA_SOURCE_PORT", required = true, dataType = "String"), + @ApiImplicitParam(name = "database", value = "DATABASE_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "userName", value = "USER_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "password", value = "PASSWORD", dataType = "String"), @ApiImplicitParam(name = "connectType", value = "CONNECT_TYPE", dataType = "DbConnectType"), - @ApiImplicitParam(name = "other", value = "DATA_SOURCE_OTHER", dataType ="String") + @ApiImplicitParam(name = "other", value = "DATA_SOURCE_OTHER", dataType = "String") }) @PostMapping(value = "/update") @ResponseStatus(HttpStatus.OK) + @ApiException(UPDATE_DATASOURCE_ERROR) public Result updateDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("id") int id, @RequestParam("name") String name, @@ -156,69 +155,52 @@ public class DataSourceController extends BaseController { @RequestParam(value = "other") String other) { logger.info("login user {} updateProcessInstance datasource name: {}, note: {}, type: {}, connectType: {}, other: {}", loginUser.getUserName(), name, note, type, connectType, other); - try { - String parameter = dataSourceService.buildParameter(name, note, type, host, port, database,principal, userName, password, connectType, other); - Map dataSource = dataSourceService.updateDataSource(id, loginUser, name, note, type, parameter); - return returnDataList(dataSource); - } catch (Exception e) { - logger.error(UPDATE_DATASOURCE_ERROR.getMsg(),e); - return error(UPDATE_DATASOURCE_ERROR.getCode(), UPDATE_DATASOURCE_ERROR.getMsg()); - } - - + String parameter = dataSourceService.buildParameter(name, note, type, host, port, database, principal, userName, password, connectType, other); + Map dataSource = dataSourceService.updateDataSource(id, loginUser, name, note, type, parameter); + return returnDataList(dataSource); } /** * 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") + @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") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_DATASOURCE_ERROR) public Result queryDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("id") int id) { logger.info("login user {}, query datasource: {}", loginUser.getUserName(), id); - try { - Map result = dataSourceService.queryDataSource(id); - return returnDataList(result); - } catch (Exception e) { - logger.error(QUERY_DATASOURCE_ERROR.getMsg(),e); - return error(Status.QUERY_DATASOURCE_ERROR.getCode(), Status.QUERY_DATASOURCE_ERROR.getMsg()); - } - - + Map result = dataSourceService.queryDataSource(id); + return returnDataList(result); } /** * query datasouce 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") + @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) + @ApiException(QUERY_DATASOURCE_ERROR) public Result queryDataSourceList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("type") DbType type) { - try { - Map result = dataSourceService.queryDataSourceList(loginUser, type.ordinal()); - return returnDataList(result); - } catch (Exception e) { - logger.error(QUERY_DATASOURCE_ERROR.getMsg(),e); - return error(Status.QUERY_DATASOURCE_ERROR.getCode(), Status.QUERY_DATASOURCE_ERROR.getMsg()); - } + Map result = dataSourceService.queryDataSourceList(loginUser, type.ordinal()); + return returnDataList(result); } /** @@ -226,67 +208,64 @@ 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") + @ApiOperation(value = "queryDataSourceListPaging", notes = "QUERY_DATA_SOURCE_LIST_PAGING_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType ="String"), + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType ="Int",example = "20") + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20") }) @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_DATASOURCE_ERROR) public Result queryDataSourceListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) { - try { - Map result = checkPageParams(pageNo, pageSize); - if (result.get(Constants.STATUS) != Status.SUCCESS) { - return returnDataListPaging(result); - } - searchVal = ParameterUtils.handleEscapes(searchVal); - result = dataSourceService.queryDataSourceListPaging(loginUser, searchVal, pageNo, pageSize); + Map result = checkPageParams(pageNo, pageSize); + if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); - } catch (Exception e) { - logger.error(QUERY_DATASOURCE_ERROR.getMsg(),e); - return error(QUERY_DATASOURCE_ERROR.getCode(), QUERY_DATASOURCE_ERROR.getMsg()); } + searchVal = ParameterUtils.handleEscapes(searchVal); + result = dataSourceService.queryDataSourceListPaging(loginUser, searchVal, pageNo, pageSize); + return returnDataListPaging(result); } /** * connect datasource * * @param loginUser login user - * @param name data source name - * @param note data soruce description - * @param type data source type - * @param other other parameters - * @param host host - * @param port port - * @param database data base + * @param name data source name + * @param note data soruce description + * @param type data source type + * @param other other parameters + * @param host host + * @param port port + * @param database data base * @param principal principal - * @param userName user name - * @param password password + * @param userName user name + * @param password password * @return connect result code */ - @ApiOperation(value = "connectDataSource", notes= "CONNECT_DATA_SOURCE_NOTES") + @ApiOperation(value = "connectDataSource", notes = "CONNECT_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"), @ApiImplicitParam(name = "note", value = "DATA_SOURCE_NOTE", dataType = "String"), - @ApiImplicitParam(name = "type", value = "DB_TYPE", required = true,dataType ="DbType"), - @ApiImplicitParam(name = "host", value = "DATA_SOURCE_HOST",required = true, dataType ="String"), - @ApiImplicitParam(name = "port", value = "DATA_SOURCE_PORT",required = true, dataType ="String"), - @ApiImplicitParam(name = "database", value = "DATABASE_NAME",required = true, dataType ="String"), - @ApiImplicitParam(name = "userName", value = "USER_NAME",required = true, dataType ="String"), - @ApiImplicitParam(name = "password", value = "PASSWORD", dataType ="String"), + @ApiImplicitParam(name = "type", value = "DB_TYPE", required = true, dataType = "DbType"), + @ApiImplicitParam(name = "host", value = "DATA_SOURCE_HOST", required = true, dataType = "String"), + @ApiImplicitParam(name = "port", value = "DATA_SOURCE_PORT", required = true, dataType = "String"), + @ApiImplicitParam(name = "database", value = "DATABASE_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "userName", value = "USER_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "password", value = "PASSWORD", dataType = "String"), @ApiImplicitParam(name = "connectType", value = "CONNECT_TYPE", dataType = "DbConnectType"), - @ApiImplicitParam(name = "other", value = "DATA_SOURCE_OTHER", dataType ="String") + @ApiImplicitParam(name = "other", value = "DATA_SOURCE_OTHER", dataType = "String") }) @PostMapping(value = "/connect") @ResponseStatus(HttpStatus.OK) + @ApiException(CONNECT_DATASOURCE_FAILURE) public Result connectDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("name") String name, @RequestParam(value = "note", required = false) String note, @@ -301,134 +280,111 @@ public class DataSourceController extends BaseController { @RequestParam(value = "other") String other) { logger.info("login user {}, connect datasource: {} failure, note: {}, type: {}, connectType: {}, other: {}", loginUser.getUserName(), name, note, type, connectType, other); - try { - String parameter = dataSourceService.buildParameter(name, note, type, host, port, database, principal, userName, password, connectType, other); - Boolean isConnection = dataSourceService.checkConnection(type, parameter); - Result result = new Result(); - - if (isConnection) { - putMsg(result, SUCCESS); - } else { - putMsg(result, CONNECT_DATASOURCE_FAILURE); - } - return result; - } catch (Exception e) { - logger.error(CONNECT_DATASOURCE_FAILURE.getMsg(),e); - return error(CONNECT_DATASOURCE_FAILURE.getCode(), CONNECT_DATASOURCE_FAILURE.getMsg()); + String parameter = dataSourceService.buildParameter(name, note, type, host, port, database, principal, userName, password, connectType, other); + Boolean isConnection = dataSourceService.checkConnection(type, parameter); + Result result = new Result(); + + if (isConnection) { + putMsg(result, SUCCESS); + } else { + putMsg(result, CONNECT_DATASOURCE_FAILURE); } + return result; } /** * 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") + @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") @ResponseStatus(HttpStatus.OK) + @ApiException(CONNECTION_TEST_FAILURE) public Result connectionTest(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("id") int id) { logger.info("connection test, login user:{}, id:{}", loginUser.getUserName(), id); - try { - Boolean isConnection = dataSourceService.connectionTest(loginUser, id); - Result result = new Result(); + Boolean isConnection = dataSourceService.connectionTest(loginUser, id); + Result result = new Result(); - if (isConnection) { - putMsg(result, SUCCESS); - } else { - putMsg(result, CONNECTION_TEST_FAILURE); - } - return result; - } catch (Exception e) { - logger.error(CONNECTION_TEST_FAILURE.getMsg(),e); - return error(CONNECTION_TEST_FAILURE.getCode(), CONNECTION_TEST_FAILURE.getMsg()); + if (isConnection) { + putMsg(result, SUCCESS); + } else { + putMsg(result, CONNECTION_TEST_FAILURE); } - + return result; } /** * delete datasource by id * * @param loginUser login user - * @param id datasource id + * @param id datasource id * @return delete result */ - @ApiOperation(value = "delete", notes= "DELETE_DATA_SOURCE_NOTES") + @ApiOperation(value = "delete", 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") @ResponseStatus(HttpStatus.OK) + @ApiException(DELETE_DATA_SOURCE_FAILURE) public Result delete(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("id") int id) { - try { - logger.info("delete datasource,login user:{}, id:{}", loginUser.getUserName(), id); - return dataSourceService.delete(loginUser, id); - } catch (Exception e) { - logger.error(DELETE_DATA_SOURCE_FAILURE.getMsg(),e); - return error(DELETE_DATA_SOURCE_FAILURE.getCode(), DELETE_DATA_SOURCE_FAILURE.getMsg()); - } + logger.info("delete datasource,login user:{}, id:{}", loginUser.getUserName(), id); + return dataSourceService.delete(loginUser, id); } /** * 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") + @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) + @ApiException(VERIFY_DATASOURCE_NAME_FAILURE) public Result verifyDataSourceName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "name") String name ) { logger.info("login user {}, verfiy datasource name: {}", loginUser.getUserName(), name); - try { - return dataSourceService.verifyDataSourceName(loginUser, name); - } catch (Exception e) { - logger.error(VERIFY_DATASOURCE_NAME_FAILURE.getMsg(), e); - return error(VERIFY_DATASOURCE_NAME_FAILURE.getCode(), VERIFY_DATASOURCE_NAME_FAILURE.getMsg()); - } + return dataSourceService.verifyDataSourceName(loginUser, name); } - /** * 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") + @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") @ResponseStatus(HttpStatus.OK) + @ApiException(UNAUTHORIZED_DATASOURCE) public Result unauthDatasource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("userId") Integer userId) { - try { - logger.info("unauthorized datasource, login user:{}, unauthorized userId:{}", - loginUser.getUserName(), userId); - Map result = dataSourceService.unauthDatasource(loginUser, userId); - return returnDataList(result); - } catch (Exception e) { - logger.error(UNAUTHORIZED_DATASOURCE.getMsg(),e); - return error(UNAUTHORIZED_DATASOURCE.getCode(), UNAUTHORIZED_DATASOURCE.getMsg()); - } + logger.info("unauthorized datasource, login user:{}, unauthorized userId:{}", + loginUser.getUserName(), userId); + Map result = dataSourceService.unauthDatasource(loginUser, userId); + return returnDataList(result); } @@ -436,26 +392,22 @@ 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") + @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") @ResponseStatus(HttpStatus.OK) + @ApiException(AUTHORIZED_DATA_SOURCE) public Result authedDatasource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("userId") Integer userId) { - try { - logger.info("authorized data source, login user:{}, authorized useId:{}", - loginUser.getUserName(), userId); - Map result = dataSourceService.authedDatasource(loginUser, userId); - return returnDataList(result); - } catch (Exception e) { - logger.error(AUTHORIZED_DATA_SOURCE.getMsg(),e); - return error(AUTHORIZED_DATA_SOURCE.getCode(), AUTHORIZED_DATA_SOURCE.getMsg()); - } + logger.info("authorized data source, login user:{}, authorized useId:{}", + loginUser.getUserName(), userId); + Map result = dataSourceService.authedDatasource(loginUser, userId); + return returnDataList(result); } /** @@ -464,17 +416,13 @@ public class DataSourceController extends BaseController { * @param loginUser login user * @return user info data */ - @ApiOperation(value = "getKerberosStartupState", notes= "GET_USER_INFO_NOTES") - @GetMapping(value="/kerberos-startup-state") + @ApiOperation(value = "getKerberosStartupState", notes = "GET_USER_INFO_NOTES") + @GetMapping(value = "/kerberos-startup-state") @ResponseStatus(HttpStatus.OK) - public Result getKerberosStartupState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser){ + @ApiException(KERBEROS_STARTUP_STATE) + public Result getKerberosStartupState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { logger.info("login user {}", loginUser.getUserName()); - try{ - // if upload resource is HDFS and kerberos startup is true , else false - return success(Status.SUCCESS.getMsg(), CommonUtils.getKerberosStartupState()); - }catch (Exception e){ - logger.error(KERBEROS_STARTUP_STATE.getMsg(),e); - return error(Status.KERBEROS_STARTUP_STATE.getCode(), Status.KERBEROS_STARTUP_STATE.getMsg()); - } + // if upload resource is HDFS and kerberos startup is true , else false + return success(Status.SUCCESS.getMsg(), CommonUtils.getKerberosStartupState()); } } 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 046479d4cb..20f4285ffa 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 @@ -18,7 +18,7 @@ package org.apache.dolphinscheduler.api.controller; import org.apache.dolphinscheduler.api.enums.ExecuteType; -import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.ExecutorService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; @@ -32,8 +32,11 @@ import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; +import java.text.ParseException; import java.util.Map; +import static org.apache.dolphinscheduler.api.enums.Status.*; + /** * execute process controller @@ -50,43 +53,45 @@ public class ExecutorController extends BaseController { /** * execute process instance - * @param loginUser login user - * @param projectName project name - * @param processDefinitionId process definition id - * @param scheduleTime schedule time - * @param failureStrategy failure strategy - * @param startNodeList start nodes list - * @param taskDependType task depend type - * @param execType execute type - * @param warningType warning type - * @param warningGroupId warning group id - * @param receivers receivers - * @param receiversCc receivers cc - * @param runMode run mode + * + * @param loginUser login user + * @param projectName project name + * @param processDefinitionId process definition id + * @param scheduleTime schedule time + * @param failureStrategy failure strategy + * @param startNodeList start nodes list + * @param taskDependType task depend type + * @param execType execute type + * @param warningType warning type + * @param warningGroupId warning group id + * @param receivers receivers + * @param receiversCc receivers cc + * @param runMode run mode * @param processInstancePriority process instance priority - * @param workerGroup worker group - * @param timeout timeout + * @param workerGroup worker group + * @param timeout timeout * @return start process result code */ - @ApiOperation(value = "startProcessInstance", notes= "RUN_PROCESS_INSTANCE_NOTES") + @ApiOperation(value = "startProcessInstance", notes = "RUN_PROCESS_INSTANCE_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "scheduleTime", value = "SCHEDULE_TIME", required = true, dataType = "String"), - @ApiImplicitParam(name = "failureStrategy", value = "FAILURE_STRATEGY", required = true, dataType ="FailureStrategy"), - @ApiImplicitParam(name = "startNodeList", value = "START_NODE_LIST", dataType ="String"), - @ApiImplicitParam(name = "taskDependType", value = "TASK_DEPEND_TYPE", dataType ="TaskDependType"), - @ApiImplicitParam(name = "execType", value = "COMMAND_TYPE", dataType ="CommandType"), - @ApiImplicitParam(name = "warningType", value = "WARNING_TYPE",required = true, dataType ="WarningType"), - @ApiImplicitParam(name = "warningGroupId", value = "WARNING_GROUP_ID",required = true, dataType ="Int", example = "100"), - @ApiImplicitParam(name = "receivers", value = "RECEIVERS",dataType ="String" ), - @ApiImplicitParam(name = "receiversCc", value = "RECEIVERS_CC",dataType ="String" ), - @ApiImplicitParam(name = "runMode", value = "RUN_MODE",dataType ="RunMode" ), - @ApiImplicitParam(name = "processInstancePriority", value = "PROCESS_INSTANCE_PRIORITY", required = true, dataType = "Priority" ), - @ApiImplicitParam(name = "workerGroup", value = "WORKER_GROUP", dataType = "String",example = "default"), - @ApiImplicitParam(name = "timeout", value = "TIMEOUT", dataType = "Int",example = "100"), + @ApiImplicitParam(name = "failureStrategy", value = "FAILURE_STRATEGY", required = true, dataType = "FailureStrategy"), + @ApiImplicitParam(name = "startNodeList", value = "START_NODE_LIST", dataType = "String"), + @ApiImplicitParam(name = "taskDependType", value = "TASK_DEPEND_TYPE", dataType = "TaskDependType"), + @ApiImplicitParam(name = "execType", value = "COMMAND_TYPE", dataType = "CommandType"), + @ApiImplicitParam(name = "warningType", value = "WARNING_TYPE", required = true, dataType = "WarningType"), + @ApiImplicitParam(name = "warningGroupId", value = "WARNING_GROUP_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "receivers", value = "RECEIVERS", dataType = "String"), + @ApiImplicitParam(name = "receiversCc", value = "RECEIVERS_CC", dataType = "String"), + @ApiImplicitParam(name = "runMode", value = "RUN_MODE", dataType = "RunMode"), + @ApiImplicitParam(name = "processInstancePriority", value = "PROCESS_INSTANCE_PRIORITY", required = true, dataType = "Priority"), + @ApiImplicitParam(name = "workerGroup", value = "WORKER_GROUP", dataType = "String", example = "default"), + @ApiImplicitParam(name = "timeout", value = "TIMEOUT", dataType = "Int", example = "100"), }) @PostMapping(value = "start-process-instance") @ResponseStatus(HttpStatus.OK) + @ApiException(START_PROCESS_INSTANCE_ERROR) 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, @@ -102,98 +107,84 @@ public class ExecutorController extends BaseController { @RequestParam(value = "runMode", required = false) RunMode runMode, @RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority, @RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, - @RequestParam(value = "timeout", required = false) Integer timeout) { - try { - logger.info("login user {}, start process instance, project name: {}, process definition id: {}, schedule time: {}, " - + "failure policy: {}, node name: {}, node dep: {}, notify type: {}, " - + "notify group id: {},receivers:{},receiversCc:{}, run mode: {},process instance priority:{}, workerGroup: {}, timeout: {}", - loginUser.getUserName(), projectName, processDefinitionId, scheduleTime, - failureStrategy, startNodeList, taskDependType, warningType, workerGroup,receivers,receiversCc,runMode,processInstancePriority, - workerGroup, timeout); - - if (timeout == null) { - timeout = Constants.MAX_TASK_TIMEOUT; - } - - Map result = execService.execProcessInstance(loginUser, projectName, processDefinitionId, scheduleTime, execType, failureStrategy, - startNodeList, taskDependType, warningType, - warningGroupId,receivers,receiversCc, runMode,processInstancePriority, workerGroup, timeout); - return returnDataList(result); - } catch (Exception e) { - logger.error(Status.START_PROCESS_INSTANCE_ERROR.getMsg(),e); - return error(Status.START_PROCESS_INSTANCE_ERROR.getCode(), Status.START_PROCESS_INSTANCE_ERROR.getMsg()); + @RequestParam(value = "timeout", required = false) Integer timeout) throws ParseException { + logger.info("login user {}, start process instance, project name: {}, process definition id: {}, schedule time: {}, " + + "failure policy: {}, node name: {}, node dep: {}, notify type: {}, " + + "notify group id: {},receivers:{},receiversCc:{}, run mode: {},process instance priority:{}, workerGroup: {}, timeout: {}", + loginUser.getUserName(), projectName, processDefinitionId, scheduleTime, + failureStrategy, startNodeList, taskDependType, warningType, workerGroup, receivers, receiversCc, runMode, processInstancePriority, + workerGroup, timeout); + + if (timeout == null) { + timeout = Constants.MAX_TASK_TIMEOUT; } + + Map result = execService.execProcessInstance(loginUser, projectName, processDefinitionId, scheduleTime, execType, failureStrategy, + startNodeList, taskDependType, warningType, + warningGroupId, receivers, receiversCc, runMode, processInstancePriority, workerGroup, timeout); + 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 loginUser login user + * @param projectName project name * @param processInstanceId process instance id - * @param executeType execute type + * @param executeType execute type * @return execute result code */ - @ApiOperation(value = "execute", notes= "EXECUTE_ACTION_TO_PROCESS_INSTANCE_NOTES") + @ApiOperation(value = "execute", notes = "EXECUTE_ACTION_TO_PROCESS_INSTANCE_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "executeType", value = "EXECUTE_TYPE", required = true, dataType = "ExecuteType") }) @PostMapping(value = "/execute") @ResponseStatus(HttpStatus.OK) + @ApiException(EXECUTE_PROCESS_INSTANCE_ERROR) public Result execute(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("processInstanceId") Integer processInstanceId, @RequestParam("executeType") ExecuteType executeType ) { - try { - logger.info("execute command, login user: {}, project:{}, process instance id:{}, execute type:{}", - loginUser.getUserName(), projectName, processInstanceId, executeType); - Map result = execService.execute(loginUser, projectName, processInstanceId, executeType); - return returnDataList(result); - } catch (Exception e) { - logger.error(Status.EXECUTE_PROCESS_INSTANCE_ERROR.getMsg(),e); - return error(Status.EXECUTE_PROCESS_INSTANCE_ERROR.getCode(), Status.EXECUTE_PROCESS_INSTANCE_ERROR.getMsg()); - } + logger.info("execute command, login user: {}, project:{}, process instance id:{}, execute type:{}", + loginUser.getUserName(), projectName, processInstanceId, executeType); + Map result = execService.execute(loginUser, projectName, processInstanceId, executeType); + return returnDataList(result); } /** * check process definition and all of the son process definitions is on line. * - * @param loginUser login user + * @param loginUser login user * @param processDefinitionId process definition id * @return check result code */ - @ApiOperation(value = "startCheckProcessDefinition", notes= "START_CHECK_PROCESS_DEFINITION_NOTES") + @ApiOperation(value = "startCheckProcessDefinition", notes = "START_CHECK_PROCESS_DEFINITION_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100") }) @PostMapping(value = "/start-check") @ResponseStatus(HttpStatus.OK) + @ApiException(CHECK_PROCESS_DEFINITION_ERROR) public Result startCheckProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "processDefinitionId") int processDefinitionId) { + @RequestParam(value = "processDefinitionId") int processDefinitionId) { logger.info("login user {}, check process definition {}", loginUser.getUserName(), processDefinitionId); - try { - Map result = execService.startCheckByProcessDefinedId(processDefinitionId); - return returnDataList(result); - - } catch (Exception e) { - logger.error(Status.CHECK_PROCESS_DEFINITION_ERROR.getMsg(),e); - return error(Status.CHECK_PROCESS_DEFINITION_ERROR.getCode(), Status.CHECK_PROCESS_DEFINITION_ERROR.getMsg()); - } + Map result = execService.startCheckByProcessDefinedId(processDefinitionId); + return returnDataList(result); } /** * query recipients and copyers by process definition ID * - * @param loginUser login user + * @param loginUser login user * @param processDefinitionId process definition id - * @param processInstanceId process instance id + * @param processInstanceId process instance id * @return receivers cc list */ @ApiIgnore - @ApiOperation(value = "getReceiverCc", notes= "GET_RECEIVER_CC_NOTES") + @ApiOperation(value = "getReceiverCc", notes = "GET_RECEIVER_CC_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100") @@ -201,17 +192,13 @@ public class ExecutorController extends BaseController { }) @GetMapping(value = "/get-receiver-cc") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_RECIPIENTS_AND_COPYERS_BY_PROCESS_DEFINITION_ERROR) public Result getReceiverCc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "processDefinitionId",required = false) Integer processDefinitionId, - @RequestParam(value = "processInstanceId",required = false) Integer processInstanceId) { + @RequestParam(value = "processDefinitionId", required = false) Integer processDefinitionId, + @RequestParam(value = "processInstanceId", required = false) Integer processInstanceId) { logger.info("login user {}, get process definition receiver and cc", loginUser.getUserName()); - try { - Map result = execService.getReceiverCc(processDefinitionId,processInstanceId); - return returnDataList(result); - } catch (Exception e) { - logger.error(Status.QUERY_RECIPIENTS_AND_COPYERS_BY_PROCESS_DEFINITION_ERROR.getMsg(),e); - return error(Status.QUERY_RECIPIENTS_AND_COPYERS_BY_PROCESS_DEFINITION_ERROR.getCode(), Status.QUERY_RECIPIENTS_AND_COPYERS_BY_PROCESS_DEFINITION_ERROR.getMsg()); - } + Map result = execService.getReceiverCc(processDefinitionId, processInstanceId); + 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 eefd6baa67..a5b8176a48 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 @@ -17,6 +17,7 @@ package org.apache.dolphinscheduler.api.controller; +import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.LoggerService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; @@ -25,7 +26,6 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; -import org.apache.dolphinscheduler.api.enums.Status; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -35,6 +35,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; +import static org.apache.dolphinscheduler.api.enums.Status.*; + /** * log controller @@ -52,61 +54,53 @@ 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") + @ApiOperation(value = "queryLog", notes = "QUERY_TASK_INSTANCE_LOG_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "taskInstanceId", value = "TASK_ID", dataType = "Int", example = "100"), - @ApiImplicitParam(name = "skipLineNum", value = "SKIP_LINE_NUM", dataType ="Int", example = "100"), - @ApiImplicitParam(name = "limit", value = "LIMIT", dataType ="Int", example = "100") + @ApiImplicitParam(name = "skipLineNum", value = "SKIP_LINE_NUM", dataType = "Int", example = "100"), + @ApiImplicitParam(name = "limit", value = "LIMIT", dataType = "Int", example = "100") }) @GetMapping(value = "/detail") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_TASK_INSTANCE_LOG_ERROR) 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) { - try { - - logger.info( - "login user {}, view {} task instance log ,skipLineNum {} , limit {}", loginUser.getUserName(), taskInstanceId, skipNum, limit); - return loggerService.queryLog(taskInstanceId, skipNum, limit); - } catch (Exception e) { - logger.error(Status.QUERY_TASK_INSTANCE_LOG_ERROR.getMsg(), e); - return error(Status.QUERY_TASK_INSTANCE_LOG_ERROR.getCode(), Status.QUERY_TASK_INSTANCE_LOG_ERROR.getMsg()); - } + logger.info( + "login user {}, view {} task instance log ,skipLineNum {} , limit {}", loginUser.getUserName(), taskInstanceId, skipNum, limit); + return loggerService.queryLog(taskInstanceId, skipNum, limit); } /** * 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") + @ApiOperation(value = "downloadTaskLog", notes = "DOWNLOAD_TASK_INSTANCE_LOG_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "taskInstanceId", value = "TASK_ID",dataType = "Int", example = "100") + @ApiImplicitParam(name = "taskInstanceId", value = "TASK_ID", dataType = "Int", example = "100") }) @GetMapping(value = "/download-log") @ResponseBody + @ApiException(DOWNLOAD_TASK_INSTANCE_LOG_FILE_ERROR) public ResponseEntity downloadTaskLog(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "taskInstanceId") int taskInstanceId) { - try { - byte[] logBytes = loggerService.getLogBytes(taskInstanceId); - return ResponseEntity - .ok() - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + System.currentTimeMillis() + ".log" + "\"") - .body(logBytes); - } catch (Exception e) { - logger.error(Status.DOWNLOAD_TASK_INSTANCE_LOG_FILE_ERROR.getMsg(), e); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(Status.DOWNLOAD_TASK_INSTANCE_LOG_FILE_ERROR.getMsg()); - } + byte[] logBytes = loggerService.getLogBytes(taskInstanceId); + return ResponseEntity + .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 e3a862d376..ce21425605 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 @@ -18,6 +18,7 @@ package org.apache.dolphinscheduler.api.controller; import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.security.Authenticator; import org.apache.dolphinscheduler.api.service.SessionService; import org.apache.dolphinscheduler.api.utils.Result; @@ -42,7 +43,7 @@ import static org.apache.dolphinscheduler.api.enums.Status.*; /** * user login controller - * + *

* swagger bootstrap ui docs refer : https://doc.xiaominfo.com/guide/enh-func.html */ @Api(tags = "LOGIN_TAG", position = 1) @@ -63,81 +64,71 @@ 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") + @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 = "userPassword", value = "USER_PASSWORD", required = true, dataType = "String") }) @PostMapping(value = "/login") + @ApiException(USER_LOGIN_FAILURE) public Result login(@RequestParam(value = "userName") String userName, @RequestParam(value = "userPassword") String userPassword, HttpServletRequest request, HttpServletResponse response) { + logger.info("login user name: {} ", userName); - try { - logger.info("login user name: {} ", userName); - - //user name check - if (StringUtils.isEmpty(userName)) { - return error(Status.USER_NAME_NULL.getCode(), - Status.USER_NAME_NULL.getMsg()); - } - - // user ip check - String ip = getClientIpAddress(request); - if (StringUtils.isEmpty(ip)) { - return error(IP_IS_EMPTY.getCode(), IP_IS_EMPTY.getMsg()); - } - - // verify username and password - Result> result = authenticator.authenticate(userName, userPassword, ip); - if (result.getCode() != Status.SUCCESS.getCode()) { - return result; - } - - response.setStatus(HttpStatus.SC_OK); - Map cookieMap = result.getData(); - for (Map.Entry cookieEntry : cookieMap.entrySet()) { - Cookie cookie = new Cookie(cookieEntry.getKey(), cookieEntry.getValue()); - cookie.setHttpOnly(true); - response.addCookie(cookie); - } + //user name check + if (StringUtils.isEmpty(userName)) { + return error(Status.USER_NAME_NULL.getCode(), + Status.USER_NAME_NULL.getMsg()); + } + // user ip check + String ip = getClientIpAddress(request); + if (StringUtils.isEmpty(ip)) { + return error(IP_IS_EMPTY.getCode(), IP_IS_EMPTY.getMsg()); + } + + // verify username and password + Result> result = authenticator.authenticate(userName, userPassword, ip); + if (result.getCode() != Status.SUCCESS.getCode()) { return result; - } catch (Exception e) { - logger.error(USER_LOGIN_FAILURE.getMsg(),e); - return error(USER_LOGIN_FAILURE.getCode(), USER_LOGIN_FAILURE.getMsg()); } + + response.setStatus(HttpStatus.SC_OK); + Map cookieMap = result.getData(); + for (Map.Entry cookieEntry : cookieMap.entrySet()) { + Cookie cookie = new Cookie(cookieEntry.getKey(), cookieEntry.getValue()); + cookie.setHttpOnly(true); + response.addCookie(cookie); + } + + return result; } /** * sign out * * @param loginUser login user - * @param request request + * @param request request * @return sign out result */ @ApiOperation(value = "signOut", notes = "SIGNOUT_NOTES") @PostMapping(value = "/signOut") + @ApiException(SIGN_OUT_ERROR) public Result signOut(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, HttpServletRequest request) { - - try { - logger.info("login user:{} sign out", loginUser.getUserName()); - String ip = getClientIpAddress(request); - sessionService.signOut(ip, loginUser); - //clear session - request.removeAttribute(Constants.SESSION_USER); - return success(); - } catch (Exception e) { - logger.error(SIGN_OUT_ERROR.getMsg(),e); - return error(SIGN_OUT_ERROR.getCode(), SIGN_OUT_ERROR.getMsg()); - } + logger.info("login user:{} sign out", loginUser.getUserName()); + String ip = getClientIpAddress(request); + sessionService.signOut(ip, loginUser); + //clear session + request.removeAttribute(Constants.SESSION_USER); + return success(); } } 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 74a5d91a6c..308a6d33d5 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 @@ -17,6 +17,7 @@ package org.apache.dolphinscheduler.api.controller; +import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.MonitorService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; @@ -33,13 +34,14 @@ import springfox.documentation.annotations.ApiIgnore; import java.util.Map; import static org.apache.dolphinscheduler.api.enums.Status.*; + /** * monitor controller */ @Api(tags = "MONITOR_TAG", position = 1) @RestController @RequestMapping("/monitor") -public class MonitorController extends BaseController{ +public class MonitorController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(MonitorController.class); @@ -48,84 +50,67 @@ public class MonitorController extends BaseController{ /** * master list + * * @param loginUser login user * @return master list */ - @ApiOperation(value = "listMaster", notes= "MASTER_LIST_NOTES") + @ApiOperation(value = "listMaster", notes = "MASTER_LIST_NOTES") @GetMapping(value = "/master/list") @ResponseStatus(HttpStatus.OK) + @ApiException(LIST_MASTERS_ERROR) public Result listMaster(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { logger.info("login user: {}, query all master", loginUser.getUserName()); - try{ - logger.info("list master, user:{}", loginUser.getUserName()); - Map result = monitorService.queryMaster(loginUser); - return returnDataList(result); - }catch (Exception e){ - logger.error(LIST_MASTERS_ERROR.getMsg(),e); - return error(LIST_MASTERS_ERROR.getCode(), - LIST_MASTERS_ERROR.getMsg()); - } + logger.info("list master, user:{}", loginUser.getUserName()); + Map result = monitorService.queryMaster(loginUser); + return returnDataList(result); } /** * worker list + * * @param loginUser login user * @return worker information list */ - @ApiOperation(value = "listWorker", notes= "WORKER_LIST_NOTES") + @ApiOperation(value = "listWorker", notes = "WORKER_LIST_NOTES") @GetMapping(value = "/worker/list") @ResponseStatus(HttpStatus.OK) + @ApiException(LIST_WORKERS_ERROR) public Result listWorker(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { logger.info("login user: {}, query all workers", loginUser.getUserName()); - try{ - Map result = monitorService.queryWorker(loginUser); - return returnDataList(result); - }catch (Exception e){ - logger.error(LIST_WORKERS_ERROR.getMsg(),e); - return error(LIST_WORKERS_ERROR.getCode(), - LIST_WORKERS_ERROR.getMsg()); - } + Map result = monitorService.queryWorker(loginUser); + return returnDataList(result); } /** * query database state + * * @param loginUser login user * @return data base state */ - @ApiOperation(value = "queryDatabaseState", notes= "QUERY_DATABASE_STATE_NOTES") + @ApiOperation(value = "queryDatabaseState", notes = "QUERY_DATABASE_STATE_NOTES") @GetMapping(value = "/database") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_DATABASE_STATE_ERROR) public Result queryDatabaseState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { logger.info("login user: {}, query database state", loginUser.getUserName()); - try{ - - Map result = monitorService.queryDatabaseState(loginUser); - return returnDataList(result); - }catch (Exception e){ - logger.error(QUERY_DATABASE_STATE_ERROR.getMsg(),e); - return error(QUERY_DATABASE_STATE_ERROR.getCode(), - QUERY_DATABASE_STATE_ERROR.getMsg()); - } + Map result = monitorService.queryDatabaseState(loginUser); + return returnDataList(result); } /** * query zookeeper state + * * @param loginUser login user * @return zookeeper information list */ - @ApiOperation(value = "queryZookeeperState", notes= "QUERY_ZOOKEEPER_STATE_NOTES") + @ApiOperation(value = "queryZookeeperState", notes = "QUERY_ZOOKEEPER_STATE_NOTES") @GetMapping(value = "/zookeeper/list") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_ZOOKEEPER_STATE_ERROR) public Result queryZookeeperState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { logger.info("login user: {}, query zookeeper state", loginUser.getUserName()); - try{ - Map result = monitorService.queryZookeeperState(loginUser); - return returnDataList(result); - }catch (Exception e){ - logger.error(QUERY_ZOOKEEPER_STATE_ERROR.getMsg(),e); - return error(QUERY_ZOOKEEPER_STATE_ERROR.getCode(), - QUERY_ZOOKEEPER_STATE_ERROR.getMsg()); - } + Map result = monitorService.queryZookeeperState(loginUser); + return returnDataList(result); } } 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 c07ecf9ca7..b043da2613 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 @@ -16,7 +16,9 @@ */ package org.apache.dolphinscheduler.api.controller; +import com.fasterxml.jackson.core.JsonProcessingException; import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.ProcessDefinitionService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; @@ -37,6 +39,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.apache.dolphinscheduler.api.enums.Status.*; + /** * process definition controller @@ -44,7 +48,7 @@ import java.util.Map; @Api(tags = "PROCESS_DEFINITION_TAG", position = 2) @RestController @RequestMapping("projects/{projectName}/process") -public class ProcessDefinitionController extends BaseController{ +public class ProcessDefinitionController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(ProcessDefinitionController.class); @@ -54,52 +58,48 @@ public class ProcessDefinitionController extends BaseController{ /** * create process definition * - * @param loginUser login user + * @param loginUser login user * @param projectName project name - * @param name process definition name - * @param json process definition json + * @param name process definition name + * @param json process definition json * @param description description - * @param locations locations for nodes - * @param connects connects for nodes + * @param locations locations for nodes + * @param connects connects for nodes * @return create result code */ - @ApiOperation(value = "save", notes= "CREATE_PROCESS_DEFINITION_NOTES") + @ApiOperation(value = "save", 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 = "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"), }) @PostMapping(value = "/save") @ResponseStatus(HttpStatus.CREATED) + @ApiException(CREATE_PROCESS_DEFINITION) public Result createProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @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) { - - try { - logger.info("login user {}, create process definition, project name: {}, process definition name: {}, " + - "process_definition_json: {}, desc: {} locations:{}, connects:{}", - loginUser.getUserName(), projectName, name, json, description, locations, connects); - Map result = processDefinitionService.createProcessDefinition(loginUser, projectName, name, json, - description, locations, connects); - return returnDataList(result); - } catch (Exception e) { - logger.error(Status.CREATE_PROCESS_DEFINITION.getMsg(), e); - return error(Status.CREATE_PROCESS_DEFINITION.getCode(), Status.CREATE_PROCESS_DEFINITION.getMsg()); - } + @RequestParam(value = "description", required = false) String description) throws JsonProcessingException { + + logger.info("login user {}, create process definition, project name: {}, process definition name: {}, " + + "process_definition_json: {}, desc: {} locations:{}, connects:{}", + loginUser.getUserName(), projectName, name, json, description, locations, connects); + Map result = processDefinitionService.createProcessDefinition(loginUser, projectName, name, json, + description, locations, connects); + return returnDataList(result); } /** * verify process definition name unique * - * @param loginUser login user + * @param loginUser login user * @param projectName project name - * @param name name + * @param name name * @return true if process definition name not exists, otherwise false */ @ApiOperation(value = "verify-name", notes = "VERIFY_PROCCESS_DEFINITION_NAME_NOTES") @@ -108,76 +108,68 @@ public class ProcessDefinitionController extends BaseController{ }) @GetMapping(value = "/verify-name") @ResponseStatus(HttpStatus.OK) + @ApiException(VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR) public Result verifyProccessDefinitionName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME",required = true) @PathVariable String projectName, - @RequestParam(value = "name", required = true) String name){ - try { - logger.info("verify process definition name unique, user:{}, project name:{}, process definition name:{}", - loginUser.getUserName(), projectName, name); - Map result = processDefinitionService.verifyProccessDefinitionName(loginUser, projectName, name); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR.getMsg(),e); - return error(Status.VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR.getCode(), Status.VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR.getMsg()); - } + @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, + @RequestParam(value = "name", required = true) String name) { + logger.info("verify process definition name unique, user:{}, project name:{}, process definition name:{}", + loginUser.getUserName(), projectName, name); + Map result = processDefinitionService.verifyProccessDefinitionName(loginUser, projectName, name); + return returnDataList(result); } /** * update process definition * - * @param loginUser login user - * @param projectName project name - * @param name process definition name - * @param id process definition id + * @param loginUser login user + * @param projectName project name + * @param name process definition name + * @param id process definition id * @param processDefinitionJson process definition json - * @param description description - * @param locations locations for nodes - * @param connects connects for nodes + * @param description description + * @param locations locations for nodes + * @param connects connects for nodes * @return update result code */ - @ApiOperation(value = "updateProccessDefinition", notes= "UPDATE_PROCCESS_DEFINITION_NOTES") + @ApiOperation(value = "updateProccessDefinition", notes = "UPDATE_PROCCESS_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 = "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"), }) @PostMapping(value = "/update") @ResponseStatus(HttpStatus.OK) + @ApiException(UPDATE_PROCESS_DEFINITION_ERROR) public Result updateProccessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME",required = true) @PathVariable String projectName, - @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, - @RequestParam(value = "description", required = false) String description) { - - try { - logger.info("login user {}, update process define, project name: {}, process define name: {}, " + - "process_definition_json: {}, desc: {}, locations:{}, connects:{}", - loginUser.getUserName(), projectName, name, processDefinitionJson,description, locations, connects); - Map result = processDefinitionService.updateProcessDefinition(loginUser, projectName, id, name, - processDefinitionJson, description, locations, connects); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.UPDATE_PROCESS_DEFINITION_ERROR.getMsg(),e); - return error(Status.UPDATE_PROCESS_DEFINITION_ERROR.getCode(), Status.UPDATE_PROCESS_DEFINITION_ERROR.getMsg()); - } + @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, + @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, + @RequestParam(value = "description", required = false) String description) { + + logger.info("login user {}, update process define, project name: {}, process define name: {}, " + + "process_definition_json: {}, desc: {}, locations:{}, connects:{}", + loginUser.getUserName(), projectName, name, processDefinitionJson, description, locations, connects); + Map result = processDefinitionService.updateProcessDefinition(loginUser, projectName, id, name, + processDefinitionJson, description, locations, connects); + return returnDataList(result); } /** * release process definition * - * @param loginUser login user - * @param projectName project name - * @param processId process definition id + * @param loginUser login user + * @param projectName project name + * @param processId process definition id * @param releaseState release state * @return release result code */ - @ApiOperation(value = "releaseProccessDefinition", notes= "RELEASE_PROCCESS_DEFINITION_NOTES") + @ApiOperation(value = "releaseProccessDefinition", notes = "RELEASE_PROCCESS_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"), @@ -185,344 +177,300 @@ public class ProcessDefinitionController extends BaseController{ }) @PostMapping(value = "/release") @ResponseStatus(HttpStatus.OK) + @ApiException(RELEASE_PROCESS_DEFINITION_ERROR) public Result releaseProccessDefinition(@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, - @RequestParam(value = "releaseState", required = true) int releaseState) { - - try { - logger.info("login user {}, release process definition, project name: {}, release state: {}", - loginUser.getUserName(), projectName, releaseState); - Map result = processDefinitionService.releaseProcessDefinition(loginUser, projectName, processId, releaseState); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.RELEASE_PROCESS_DEFINITION_ERROR.getMsg(),e); - return error(Status.RELEASE_PROCESS_DEFINITION_ERROR.getCode(), Status.RELEASE_PROCESS_DEFINITION_ERROR.getMsg()); - } + @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, + @RequestParam(value = "processId", required = true) int processId, + @RequestParam(value = "releaseState", required = true) int releaseState) { + + logger.info("login user {}, release process definition, project name: {}, release state: {}", + loginUser.getUserName(), projectName, releaseState); + Map result = processDefinitionService.releaseProcessDefinition(loginUser, projectName, processId, releaseState); + return returnDataList(result); } /** * query datail of process definition * - * @param loginUser login user + * @param loginUser login user * @param projectName project name - * @param processId process definition id + * @param processId process definition id * @return process definition detail */ - @ApiOperation(value = "queryProccessDefinitionById", notes= "QUERY_PROCCESS_DEFINITION_BY_ID_NOTES") + @ApiOperation(value = "queryProccessDefinitionById", notes = "QUERY_PROCCESS_DEFINITION_BY_ID_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "processId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value="/select-by-id") + @GetMapping(value = "/select-by-id") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR) public Result queryProccessDefinitionById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME",required = true) @PathVariable String projectName, + @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("processId") Integer processId - ){ - try{ - logger.info("query datail of process definition, login user:{}, project name:{}, process definition id:{}", - loginUser.getUserName(), projectName, processId); - Map result = processDefinitionService.queryProccessDefinitionById(loginUser, projectName, processId); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR.getMsg(),e); - return error(Status.QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR.getCode(), Status.QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR.getMsg()); - } + ) { + logger.info("query datail of process definition, login user:{}, project name:{}, process definition id:{}", + loginUser.getUserName(), projectName, processId); + Map result = processDefinitionService.queryProccessDefinitionById(loginUser, projectName, processId); + return returnDataList(result); } /** * query proccess definition list * - * @param loginUser login user + * @param loginUser login user * @param projectName project name * @return process definition list */ - @ApiOperation(value = "queryProccessDefinitionList", notes= "QUERY_PROCCESS_DEFINITION_LIST_NOTES") - @GetMapping(value="/list") + @ApiOperation(value = "queryProccessDefinitionList", notes = "QUERY_PROCCESS_DEFINITION_LIST_NOTES") + @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_PROCCESS_DEFINITION_LIST) public Result queryProccessDefinitionList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME",required = true) @PathVariable String projectName - ){ - try{ - logger.info("query proccess definition list, login user:{}, project name:{}", - loginUser.getUserName(), projectName); - Map result = processDefinitionService.queryProccessDefinitionList(loginUser, projectName); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.QUERY_PROCCESS_DEFINITION_LIST.getMsg(),e); - return error(Status.QUERY_PROCCESS_DEFINITION_LIST.getCode(), Status.QUERY_PROCCESS_DEFINITION_LIST.getMsg()); - } + @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName + ) { + logger.info("query proccess definition list, login user:{}, project name:{}", + loginUser.getUserName(), projectName); + Map result = processDefinitionService.queryProccessDefinitionList(loginUser, projectName); + return returnDataList(result); } /** * query proccess definition list paging - * @param loginUser login user + * + * @param loginUser login user * @param projectName project name - * @param searchVal search value - * @param pageNo page number - * @param pageSize page size - * @param userId user id + * @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_PROCCESS_DEFINITION_LIST_PAGING_NOTES") + @ApiOperation(value = "queryProcessDefinitionListPaging", notes = "QUERY_PROCCESS_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") }) - @GetMapping(value="/list-paging") + @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_PROCCESS_DEFINITION_LIST_PAGING_ERROR) public Result queryProcessDefinitionListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME",required = true) @PathVariable String projectName, + @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam("pageNo") Integer pageNo, @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam(value = "userId", required = false, defaultValue = "0") Integer userId, - @RequestParam("pageSize") Integer pageSize){ - try{ - logger.info("query proccess definition list paging, login user:{}, project name:{}", loginUser.getUserName(), projectName); - Map result = checkPageParams(pageNo, pageSize); - if(result.get(Constants.STATUS) != Status.SUCCESS){ - return returnDataListPaging(result); - } - searchVal = ParameterUtils.handleEscapes(searchVal); - result = processDefinitionService.queryProcessDefinitionListPaging(loginUser, projectName, searchVal, pageNo, pageSize, userId); + @RequestParam("pageSize") Integer pageSize) { + logger.info("query proccess definition list paging, login user:{}, project name:{}", loginUser.getUserName(), projectName); + Map result = checkPageParams(pageNo, pageSize); + if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); - }catch (Exception e){ - logger.error(Status.QUERY_PROCCESS_DEFINITION_LIST_PAGING_ERROR.getMsg(),e); - return error(Status.QUERY_PROCCESS_DEFINITION_LIST_PAGING_ERROR.getCode(), Status.QUERY_PROCCESS_DEFINITION_LIST_PAGING_ERROR.getMsg()); } + searchVal = ParameterUtils.handleEscapes(searchVal); + result = processDefinitionService.queryProcessDefinitionListPaging(loginUser, projectName, searchVal, pageNo, pageSize, userId); + return returnDataListPaging(result); } /** * encapsulation treeview structure * - * @param loginUser login user + * @param loginUser login user * @param projectName project name - * @param id process definition id - * @param limit limit + * @param id process definition id + * @param limit limit * @return tree view json data */ - @ApiOperation(value = "viewTree", notes= "VIEW_TREE_NOTES") + @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") }) - @GetMapping(value="/view-tree") + @GetMapping(value = "/view-tree") @ResponseStatus(HttpStatus.OK) + @ApiException(ENCAPSULATION_TREEVIEW_STRUCTURE_ERROR) 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){ - try{ - Map result = processDefinitionService.viewTree(id, limit); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.ENCAPSULATION_TREEVIEW_STRUCTURE_ERROR.getMsg(),e); - return error(Status.ENCAPSULATION_TREEVIEW_STRUCTURE_ERROR.getCode(), Status.ENCAPSULATION_TREEVIEW_STRUCTURE_ERROR.getMsg()); - } + @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); + return returnDataList(result); } /** - * * get tasks list by process definition id * - * - * @param loginUser login user - * @param projectName project name + * @param loginUser login user + * @param projectName project name * @param processDefinitionId process definition id * @return task list */ - @ApiOperation(value = "getNodeListByDefinitionId", notes= "GET_NODE_LIST_BY_DEFINITION_ID_NOTES") + @ApiOperation(value = "getNodeListByDefinitionId", notes = "GET_NODE_LIST_BY_DEFINITION_ID_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value="gen-task-list") + @GetMapping(value = "gen-task-list") @ResponseStatus(HttpStatus.OK) + @ApiException(GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR) public Result getNodeListByDefinitionId( @ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME",required = true) @PathVariable String projectName, - @RequestParam("processDefinitionId") Integer processDefinitionId){ - try { - logger.info("query task node name list by definitionId, login user:{}, project name:{}, id : {}", - loginUser.getUserName(), projectName, processDefinitionId); - Map result = processDefinitionService.getTaskNodeListByDefinitionId(processDefinitionId); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR.getMsg(), e); - return error(Status.GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR.getCode(), Status.GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR.getMsg()); - } + @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, + @RequestParam("processDefinitionId") Integer processDefinitionId) throws Exception { + logger.info("query task node name list by definitionId, login user:{}, project name:{}, id : {}", + loginUser.getUserName(), projectName, processDefinitionId); + Map result = processDefinitionService.getTaskNodeListByDefinitionId(processDefinitionId); + return returnDataList(result); } /** - * * get tasks list by process definition id * - * - * @param loginUser login user - * @param projectName project name + * @param loginUser login user + * @param projectName project name * @param processDefinitionIdList process definition id list * @return node list data */ - @ApiOperation(value = "getNodeListByDefinitionIdList", notes= "GET_NODE_LIST_BY_DEFINITION_ID_NOTES") + @ApiOperation(value = "getNodeListByDefinitionIdList", notes = "GET_NODE_LIST_BY_DEFINITION_ID_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "processDefinitionIdList", value = "PROCESS_DEFINITION_ID_LIST", required = true, type = "String") }) - @GetMapping(value="get-task-list") + @GetMapping(value = "get-task-list") @ResponseStatus(HttpStatus.OK) + @ApiException(GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR) public Result getNodeListByDefinitionIdList( @ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME",required = true) @PathVariable String projectName, - @RequestParam("processDefinitionIdList") String processDefinitionIdList){ + @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, + @RequestParam("processDefinitionIdList") String processDefinitionIdList) throws Exception { - try { - logger.info("query task node name list by definitionId list, login user:{}, project name:{}, id list: {}", - loginUser.getUserName(), projectName, processDefinitionIdList); - Map result = processDefinitionService.getTaskNodeListByDefinitionIdList(processDefinitionIdList); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR.getMsg(), e); - return error(Status.GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR.getCode(), Status.GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR.getMsg()); - } + logger.info("query task node name list by definitionId list, login user:{}, project name:{}, id list: {}", + loginUser.getUserName(), projectName, processDefinitionIdList); + Map result = processDefinitionService.getTaskNodeListByDefinitionIdList(processDefinitionIdList); + return returnDataList(result); } /** * delete process definition by id * - * @param loginUser login user - * @param projectName project name + * @param loginUser login user + * @param projectName project name * @param processDefinitionId process definition id * @return delete result code */ - @ApiOperation(value = "deleteProcessDefinitionById", notes= "DELETE_PROCESS_DEFINITION_BY_ID_NOTES") + @ApiOperation(value = "deleteProcessDefinitionById", notes = "DELETE_PROCESS_DEFINITION_BY_ID_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", dataType = "Int", example = "100") }) - @GetMapping(value="/delete") + @GetMapping(value = "/delete") @ResponseStatus(HttpStatus.OK) + @ApiException(DELETE_PROCESS_DEFINE_BY_ID_ERROR) 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 - ){ - try{ - logger.info("delete process definition by id, login user:{}, project name:{}, process definition id:{}", - loginUser.getUserName(), projectName, processDefinitionId); - Map result = processDefinitionService.deleteProcessDefinitionById(loginUser, projectName, processDefinitionId); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR.getMsg(),e); - return error(Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR.getCode(), Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR.getMsg()); - } + @RequestParam("processDefinitionId") Integer processDefinitionId + ) { + logger.info("delete process definition by id, login user:{}, project name:{}, process definition id:{}", + loginUser.getUserName(), projectName, processDefinitionId); + Map result = processDefinitionService.deleteProcessDefinitionById(loginUser, projectName, processDefinitionId); + return returnDataList(result); } /** * batch delete process definition by ids * - * @param loginUser login user - * @param projectName project name + * @param loginUser login user + * @param projectName project name * @param processDefinitionIds process definition id list * @return delete result code */ - @ApiOperation(value = "batchDeleteProcessDefinitionByIds", notes= "BATCH_DELETE_PROCESS_DEFINITION_BY_IDS_NOTES") + @ApiOperation(value = "batchDeleteProcessDefinitionByIds", notes = "BATCH_DELETE_PROCESS_DEFINITION_BY_IDS_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "processDefinitionIds", value = "PROCESS_DEFINITION_IDS", type = "String") }) - @GetMapping(value="/batch-delete") + @GetMapping(value = "/batch-delete") @ResponseStatus(HttpStatus.OK) + @ApiException(BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR) 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 - ){ - try{ - logger.info("delete process definition by ids, login user:{}, project name:{}, process definition ids:{}", - loginUser.getUserName(), projectName, processDefinitionIds); - - Map result = new HashMap<>(5); - List deleteFailedIdList = new ArrayList<>(); - if(StringUtils.isNotEmpty(processDefinitionIds)){ - String[] processDefinitionIdArray = processDefinitionIds.split(","); - - for (String strProcessDefinitionId:processDefinitionIdArray) { - int processDefinitionId = Integer.parseInt(strProcessDefinitionId); - try { - Map deleteResult = processDefinitionService.deleteProcessDefinitionById(loginUser, projectName, processDefinitionId); - if(!Status.SUCCESS.equals(deleteResult.get(Constants.STATUS))){ - deleteFailedIdList.add(strProcessDefinitionId); - logger.error((String)deleteResult.get(Constants.MSG)); - } - } catch (Exception e) { + @RequestParam("processDefinitionIds") String processDefinitionIds + ) { + logger.info("delete process definition by ids, login user:{}, project name:{}, process definition ids:{}", + loginUser.getUserName(), projectName, processDefinitionIds); + + Map result = new HashMap<>(5); + List deleteFailedIdList = new ArrayList<>(); + if (StringUtils.isNotEmpty(processDefinitionIds)) { + String[] processDefinitionIdArray = processDefinitionIds.split(","); + + for (String strProcessDefinitionId : processDefinitionIdArray) { + int processDefinitionId = Integer.parseInt(strProcessDefinitionId); + try { + Map deleteResult = processDefinitionService.deleteProcessDefinitionById(loginUser, projectName, processDefinitionId); + if (!Status.SUCCESS.equals(deleteResult.get(Constants.STATUS))) { deleteFailedIdList.add(strProcessDefinitionId); + logger.error((String) deleteResult.get(Constants.MSG)); } + } catch (Exception e) { + deleteFailedIdList.add(strProcessDefinitionId); } } + } - if(!deleteFailedIdList.isEmpty()){ - putMsg(result, Status.BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR, String.join(",", deleteFailedIdList)); - }else{ - putMsg(result, Status.SUCCESS); - } - - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR.getMsg(),e); - return error(Status.BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR.getCode(), Status.BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR.getMsg()); + if (!deleteFailedIdList.isEmpty()) { + putMsg(result, Status.BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR, String.join(",", deleteFailedIdList)); + } else { + putMsg(result, Status.SUCCESS); } + + return returnDataList(result); } /** * export process definition by id * - * @param loginUser login user - * @param projectName project name + * @param loginUser login user + * @param projectName project name * @param processDefinitionId process definition id - * @param response response + * @param response response */ - @ApiOperation(value = "exportProcessDefinitionById", notes= "EXPORT_PROCCESS_DEFINITION_BY_ID_NOTES") + @ApiOperation(value = "exportProcessDefinitionById", notes = "EXPORT_PROCCESS_DEFINITION_BY_ID_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value="/export") + @GetMapping(value = "/export") @ResponseBody public void exportProcessDefinitionById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @PathVariable String projectName, @RequestParam("processDefinitionId") Integer processDefinitionId, - HttpServletResponse response){ - try{ + HttpServletResponse response) { + try { logger.info("export process definition by id, login user:{}, project name:{}, process definition id:{}", loginUser.getUserName(), projectName, processDefinitionId); - processDefinitionService.exportProcessDefinitionById(loginUser, projectName, processDefinitionId,response); - }catch (Exception e){ - logger.error(Status.EXPORT_PROCESS_DEFINE_BY_ID_ERROR.getMsg(),e); + processDefinitionService.exportProcessDefinitionById(loginUser, projectName, processDefinitionId, response); + } catch (Exception e) { + logger.error(Status.EXPORT_PROCESS_DEFINE_BY_ID_ERROR.getMsg(), e); } } - /** * query proccess definition all by project id * * @param loginUser login user - * @param projectId project id + * @param projectId project id * @return process definition list */ - @ApiOperation(value = "queryProccessDefinitionAllByProjectId", notes= "QUERY_PROCCESS_DEFINITION_All_BY_PROJECT_ID_NOTES") - @GetMapping(value="/queryProccessDefinitionAllByProjectId") + @ApiOperation(value = "queryProccessDefinitionAllByProjectId", notes = "QUERY_PROCCESS_DEFINITION_All_BY_PROJECT_ID_NOTES") + @GetMapping(value = "/queryProccessDefinitionAllByProjectId") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_PROCCESS_DEFINITION_LIST) public Result queryProccessDefinitionAllByProjectId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("projectId") Integer projectId){ - try{ - logger.info("query proccess definition list, login user:{}, project id:{}", - loginUser.getUserName(),projectId); - Map result = processDefinitionService.queryProccessDefinitionAllByProjectId(projectId); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.QUERY_PROCCESS_DEFINITION_LIST.getMsg(),e); - return error(Status.QUERY_PROCCESS_DEFINITION_LIST.getCode(), Status.QUERY_PROCCESS_DEFINITION_LIST.getMsg()); - } + @RequestParam("projectId") Integer projectId) { + logger.info("query proccess definition list, login user:{}, project id:{}", + loginUser.getUserName(), projectId); + Map result = processDefinitionService.queryProccessDefinitionAllByProjectId(projectId); + 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 9b47cb54e4..10dc8e4ce5 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 @@ -17,6 +17,7 @@ package org.apache.dolphinscheduler.api.controller; import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.ProcessInstanceService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; @@ -33,6 +34,8 @@ import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; +import java.io.IOException; +import java.text.ParseException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -46,7 +49,7 @@ import static org.apache.dolphinscheduler.api.enums.Status.*; @Api(tags = "PROCESS_INSTANCE_TAG", position = 10) @RestController @RequestMapping("projects/{projectName}/instance") -public class ProcessInstanceController extends BaseController{ +public class ProcessInstanceController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(ProcessInstanceController.class); @@ -57,102 +60,94 @@ public class ProcessInstanceController extends BaseController{ /** * query process instance list paging * - * @param loginUser login user - * @param projectName project name - * @param pageNo page number - * @param pageSize page size + * @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 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 = "queryProcessInstanceList", 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 = "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", dataType = "Int", example = "100"), @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "100") }) - @GetMapping(value="list-paging") + @GetMapping(value = "list-paging") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_PROCESS_INSTANCE_LIST_PAGING_ERROR) 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, - @RequestParam(value = "searchVal", required = false) String searchVal, - @RequestParam(value = "executorName", required = false) String executorName, - @RequestParam(value = "stateType", required = false) ExecutionStatus stateType, - @RequestParam(value = "host", required = false) String host, - @RequestParam(value = "startDate", required = false) String startTime, - @RequestParam(value = "endDate", required = false) String endTime, - @RequestParam("pageNo") Integer pageNo, - @RequestParam("pageSize") Integer pageSize){ - try{ - logger.info("query all process instance list, login user:{},project name:{}, define id:{}," + - "search value:{},executor name:{},state type:{},host:{},start time:{}, end time:{},page number:{}, page size:{}", - loginUser.getUserName(), projectName, processDefinitionId, searchVal, executorName,stateType,host, - startTime, endTime, pageNo, pageSize); - searchVal = ParameterUtils.handleEscapes(searchVal); - Map result = processInstanceService.queryProcessInstanceList( - loginUser, projectName, processDefinitionId, startTime, endTime, searchVal, executorName, stateType, host, pageNo, pageSize); - return returnDataListPaging(result); - }catch (Exception e){ - logger.error(QUERY_PROCESS_INSTANCE_LIST_PAGING_ERROR.getMsg(),e); - return error(Status.QUERY_PROCESS_INSTANCE_LIST_PAGING_ERROR.getCode(), Status.QUERY_PROCESS_INSTANCE_LIST_PAGING_ERROR.getMsg()); - } + @RequestParam(value = "processDefinitionId", required = false, defaultValue = "0") Integer processDefinitionId, + @RequestParam(value = "searchVal", required = false) String searchVal, + @RequestParam(value = "executorName", required = false) String executorName, + @RequestParam(value = "stateType", required = false) ExecutionStatus stateType, + @RequestParam(value = "host", required = false) String host, + @RequestParam(value = "startDate", required = false) String startTime, + @RequestParam(value = "endDate", required = false) String endTime, + @RequestParam("pageNo") Integer pageNo, + @RequestParam("pageSize") Integer pageSize) { + logger.info("query all process instance list, login user:{},project name:{}, define id:{}," + + "search value:{},executor name:{},state type:{},host:{},start time:{}, end time:{},page number:{}, page size:{}", + loginUser.getUserName(), projectName, processDefinitionId, searchVal, executorName, stateType, host, + startTime, endTime, pageNo, pageSize); + searchVal = ParameterUtils.handleEscapes(searchVal); + Map result = processInstanceService.queryProcessInstanceList( + loginUser, projectName, processDefinitionId, startTime, endTime, searchVal, executorName, stateType, host, pageNo, pageSize); + return returnDataListPaging(result); } /** * query task list by process instance id * - * @param loginUser login user - * @param projectName project name + * @param loginUser login user + * @param projectName project name * @param processInstanceId process instance id * @return task list for the process instance */ - @ApiOperation(value = "queryTaskListByProcessId", notes= "QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_NOTES") + @ApiOperation(value = "queryTaskListByProcessId", notes = "QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", dataType = "Int", example = "100") }) - @GetMapping(value="/task-list-by-process-id") + @GetMapping(value = "/task-list-by-process-id") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_ERROR) 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 - ) { - try{ - logger.info("query task instance list by process instance id, login user:{}, project name:{}, process instance id:{}", - loginUser.getUserName(), projectName, processInstanceId); - Map result = processInstanceService.queryTaskListByProcessId(loginUser, projectName, processInstanceId); - return returnDataList(result); - }catch (Exception e){ - logger.error(QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_ERROR.getMsg(),e); - return error(QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_ERROR.getCode(), QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_ERROR.getMsg()); - } + ) throws IOException { + logger.info("query task instance list by process instance id, login user:{}, project name:{}, process instance id:{}", + loginUser.getUserName(), projectName, processInstanceId); + Map result = processInstanceService.queryTaskListByProcessId(loginUser, projectName, processInstanceId); + return returnDataList(result); } /** * update process instance * - * @param loginUser login user - * @param projectName project name + * @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 processInstanceId process instance id + * @param scheduleTime schedule time + * @param syncDefine sync define + * @param flag flag + * @param locations locations + * @param connects connects * @return update result code */ - @ApiOperation(value = "updateProcessInstance", notes= "UPDATE_PROCESS_INSTANCE_NOTES") + @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", dataType = "Int", example = "100"), @@ -162,241 +157,209 @@ public class ProcessInstanceController extends BaseController{ @ApiImplicitParam(name = "connects", value = "PROCESS_INSTANCE_CONNECTS", type = "String"), @ApiImplicitParam(name = "flag", value = "RECOVERY_PROCESS_INSTANCE_FLAG", type = "Flag"), }) - @PostMapping(value="/update") + @PostMapping(value = "/update") @ResponseStatus(HttpStatus.OK) + @ApiException(UPDATE_PROCESS_INSTANCE_ERROR) 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, - @RequestParam( value = "scheduleTime", required = false) String scheduleTime, - @RequestParam( value = "syncDefine", required = true) Boolean syncDefine, + @RequestParam(value = "processInstanceJson", required = false) String processInstanceJson, + @RequestParam(value = "processInstanceId") Integer processInstanceId, + @RequestParam(value = "scheduleTime", required = false) String scheduleTime, + @RequestParam(value = "syncDefine", required = true) Boolean syncDefine, @RequestParam(value = "locations", required = false) String locations, @RequestParam(value = "connects", required = false) String connects, - @RequestParam( value = "flag", required = false) Flag flag - ){ - try{ - logger.info("updateProcessInstance process instance, login user:{}, project name:{}, process instance json:{}," + - "process instance id:{}, schedule time:{}, sync define:{}, flag:{}, locations:{}, connects:{}", - loginUser.getUserName(), projectName, processInstanceJson, processInstanceId, scheduleTime, - syncDefine, flag, locations, connects); - Map result = processInstanceService.updateProcessInstance(loginUser, projectName, - processInstanceId, processInstanceJson, scheduleTime, syncDefine, flag, locations, connects); - return returnDataList(result); - }catch (Exception e){ - logger.error(UPDATE_PROCESS_INSTANCE_ERROR.getMsg(),e); - return error(Status.UPDATE_PROCESS_INSTANCE_ERROR.getCode(), Status.UPDATE_PROCESS_INSTANCE_ERROR.getMsg()); - } + @RequestParam(value = "flag", required = false) Flag flag + ) throws ParseException { + logger.info("updateProcessInstance process instance, login user:{}, project name:{}, process instance json:{}," + + "process instance id:{}, schedule time:{}, sync define:{}, flag:{}, locations:{}, connects:{}", + loginUser.getUserName(), projectName, processInstanceJson, processInstanceId, scheduleTime, + syncDefine, flag, locations, connects); + Map result = processInstanceService.updateProcessInstance(loginUser, projectName, + processInstanceId, processInstanceJson, scheduleTime, syncDefine, flag, locations, connects); + return returnDataList(result); } /** * query process instance by id * - * @param loginUser login user - * @param projectName project name + * @param loginUser login user + * @param projectName project name * @param processInstanceId process instance id * @return process instance detail */ - @ApiOperation(value = "queryProcessInstanceById", notes= "QUERY_PROCESS_INSTANCE_BY_ID_NOTES") + @ApiOperation(value = "queryProcessInstanceById", notes = "QUERY_PROCESS_INSTANCE_BY_ID_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", dataType = "Int", example = "100") }) - @GetMapping(value="/select-by-id") + @GetMapping(value = "/select-by-id") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_PROCESS_INSTANCE_BY_ID_ERROR) 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 - ){ - try{ - logger.info("query process instance detail by id, login user:{},project name:{}, process instance id:{}", - loginUser.getUserName(), projectName, processInstanceId); - Map result = processInstanceService.queryProcessInstanceById(loginUser, projectName, processInstanceId); - return returnDataList(result); - }catch (Exception e){ - logger.error(QUERY_PROCESS_INSTANCE_BY_ID_ERROR.getMsg(),e); - return error(Status.QUERY_PROCESS_INSTANCE_BY_ID_ERROR.getCode(), Status.QUERY_PROCESS_INSTANCE_BY_ID_ERROR.getMsg()); - } + @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, + @RequestParam("processInstanceId") Integer processInstanceId + ) { + logger.info("query process instance detail by id, login user:{},project name:{}, process instance id:{}", + loginUser.getUserName(), projectName, processInstanceId); + Map result = processInstanceService.queryProcessInstanceById(loginUser, projectName, processInstanceId); + return returnDataList(result); } /** * 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 loginUser login user + * @param projectName project name * @param processInstanceId process instance id * @return delete result code */ - @ApiOperation(value = "deleteProcessInstanceById", notes= "DELETE_PROCESS_INSTANCE_BY_ID_NOTES") + @ApiOperation(value = "deleteProcessInstanceById", notes = "DELETE_PROCESS_INSTANCE_BY_ID_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", dataType = "Int", example = "100") }) - @GetMapping(value="/delete") + @GetMapping(value = "/delete") @ResponseStatus(HttpStatus.OK) + @ApiException(DELETE_PROCESS_INSTANCE_BY_ID_ERROR) 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 - ){ - try{ - logger.info("delete process instance by id, login user:{}, project name:{}, process instance id:{}", - loginUser.getUserName(), projectName, processInstanceId); - // task queue - Map result = processInstanceService.deleteProcessInstanceById(loginUser, projectName, processInstanceId); - return returnDataList(result); - }catch (Exception e){ - logger.error(DELETE_PROCESS_INSTANCE_BY_ID_ERROR.getMsg(),e); - return error(Status.DELETE_PROCESS_INSTANCE_BY_ID_ERROR.getCode(), Status.DELETE_PROCESS_INSTANCE_BY_ID_ERROR.getMsg()); - } + @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, + @RequestParam("processInstanceId") Integer processInstanceId + ) { + logger.info("delete process instance by id, login user:{}, project name:{}, process instance id:{}", + loginUser.getUserName(), projectName, processInstanceId); + // task queue + Map result = processInstanceService.deleteProcessInstanceById(loginUser, projectName, processInstanceId); + return returnDataList(result); } /** * query sub process instance detail info by task id * - * @param loginUser login user + * @param loginUser login user * @param projectName project name - * @param taskId task id + * @param taskId task id * @return sub process instance detail */ - @ApiOperation(value = "querySubProcessInstanceByTaskId", notes= "QUERY_SUBPROCESS_INSTANCE_BY_TASK_ID_NOTES") + @ApiOperation(value = "querySubProcessInstanceByTaskId", notes = "QUERY_SUBPROCESS_INSTANCE_BY_TASK_ID_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "taskId", value = "TASK_ID", dataType = "Int", example = "100") }) - @GetMapping(value="/select-sub-process") + @GetMapping(value = "/select-sub-process") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_SUB_PROCESS_INSTANCE_DETAIL_INFO_BY_TASK_ID_ERROR) public Result querySubProcessInstanceByTaskId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("taskId") Integer taskId){ - try{ - Map result = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectName, taskId); - return returnDataList(result); - }catch (Exception e){ - logger.error(QUERY_SUB_PROCESS_INSTANCE_DETAIL_INFO_BY_TASK_ID_ERROR.getMsg(),e); - return error(Status.QUERY_SUB_PROCESS_INSTANCE_DETAIL_INFO_BY_TASK_ID_ERROR.getCode(), Status.QUERY_SUB_PROCESS_INSTANCE_DETAIL_INFO_BY_TASK_ID_ERROR.getMsg()); - } + @RequestParam("taskId") Integer taskId) { + Map result = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectName, taskId); + return returnDataList(result); } /** * query parent process instance detail info by sub process instance id * - * @param loginUser login user + * @param loginUser login user * @param projectName project name - * @param subId sub process id + * @param subId sub process id * @return parent instance detail */ - @ApiOperation(value = "queryParentInstanceBySubId", notes= "QUERY_PARENT_PROCESS_INSTANCE_BY_SUB_PROCESS_INSTANCE_ID_NOTES") + @ApiOperation(value = "queryParentInstanceBySubId", notes = "QUERY_PARENT_PROCESS_INSTANCE_BY_SUB_PROCESS_INSTANCE_ID_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "subId", value = "SUB_PROCESS_INSTANCE_ID", dataType = "Int", example = "100") }) - @GetMapping(value="/select-parent-process") + @GetMapping(value = "/select-parent-process") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_PARENT_PROCESS_INSTANCE_DETAIL_INFO_BY_SUB_PROCESS_INSTANCE_ID_ERROR) public Result queryParentInstanceBySubId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("subId") Integer subId){ - try{ - Map result = processInstanceService.queryParentInstanceBySubId(loginUser, projectName, subId); - return returnDataList(result); - }catch (Exception e){ - logger.error(QUERY_PARENT_PROCESS_INSTANCE_DETAIL_INFO_BY_SUB_PROCESS_INSTANCE_ID_ERROR.getMsg(),e); - return error(Status.QUERY_PARENT_PROCESS_INSTANCE_DETAIL_INFO_BY_SUB_PROCESS_INSTANCE_ID_ERROR.getCode(), Status.QUERY_PARENT_PROCESS_INSTANCE_DETAIL_INFO_BY_SUB_PROCESS_INSTANCE_ID_ERROR.getMsg()); - } + @RequestParam("subId") Integer subId) { + Map result = processInstanceService.queryParentInstanceBySubId(loginUser, projectName, subId); + return returnDataList(result); } /** * query process instance global variables and local variables * - * @param loginUser login user + * @param loginUser login user * @param processInstanceId process instance id * @return variables data */ - @ApiOperation(value = "viewVariables", notes= "QUERY_PROCESS_INSTANCE_GLOBAL_VARIABLES_AND_LOCAL_VARIABLES_NOTES") + @ApiOperation(value = "viewVariables", notes = "QUERY_PROCESS_INSTANCE_GLOBAL_VARIABLES_AND_LOCAL_VARIABLES_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", dataType = "Int", example = "100") }) - @GetMapping(value="/view-variables") + @GetMapping(value = "/view-variables") @ResponseStatus(HttpStatus.OK) - public Result viewVariables(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser - , @RequestParam("processInstanceId") Integer processInstanceId){ - try{ - Map result = processInstanceService.viewVariables(processInstanceId); - return returnDataList(result); - }catch (Exception e){ - logger.error(QUERY_PROCESS_INSTANCE_ALL_VARIABLES_ERROR.getMsg(),e); - return error(Status.QUERY_PROCESS_INSTANCE_ALL_VARIABLES_ERROR.getCode(), Status.QUERY_PROCESS_INSTANCE_ALL_VARIABLES_ERROR.getMsg()); - } + @ApiException(QUERY_PROCESS_INSTANCE_ALL_VARIABLES_ERROR) + public Result viewVariables(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @RequestParam("processInstanceId") Integer processInstanceId) throws Exception { + Map result = processInstanceService.viewVariables(processInstanceId); + return returnDataList(result); } /** * encapsulation gantt structure * - * @param loginUser login user - * @param projectName project name + * @param loginUser login user + * @param projectName project name * @param processInstanceId process instance id * @return gantt tree data */ - @ApiOperation(value = "vieGanttTree", notes= "VIEW_GANTT_NOTES") + @ApiOperation(value = "vieGanttTree", notes = "VIEW_GANTT_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", dataType = "Int", example = "100") }) - @GetMapping(value="/view-gantt") + @GetMapping(value = "/view-gantt") @ResponseStatus(HttpStatus.OK) + @ApiException(ENCAPSULATION_PROCESS_INSTANCE_GANTT_STRUCTURE_ERROR) 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){ - try{ - Map result = processInstanceService.viewGantt(processInstanceId); - return returnDataList(result); - }catch (Exception e){ - logger.error(ENCAPSULATION_PROCESS_INSTANCE_GANTT_STRUCTURE_ERROR.getMsg(),e); - return error(Status.ENCAPSULATION_PROCESS_INSTANCE_GANTT_STRUCTURE_ERROR.getCode(),ENCAPSULATION_PROCESS_INSTANCE_GANTT_STRUCTURE_ERROR.getMsg()); - } + @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, + @RequestParam("processInstanceId") Integer processInstanceId) throws Exception { + Map result = processInstanceService.viewGantt(processInstanceId); + return returnDataList(result); } /** * 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 projectName project name * @param processInstanceIds process instance id * @return delete result code */ - @GetMapping(value="/batch-delete") + @GetMapping(value = "/batch-delete") @ResponseStatus(HttpStatus.OK) + @ApiException(BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR) public Result batchDeleteProcessInstanceByIds(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @PathVariable String projectName, - @RequestParam("processInstanceIds") String processInstanceIds - ){ - try{ - logger.info("delete process instance by ids, login user:{}, project name:{}, process instance ids :{}", - loginUser.getUserName(), projectName, processInstanceIds); - // task queue - Map result = new HashMap<>(5); - List deleteFailedIdList = new ArrayList<>(); - if(StringUtils.isNotEmpty(processInstanceIds)){ - String[] processInstanceIdArray = processInstanceIds.split(","); + @PathVariable String projectName, + @RequestParam("processInstanceIds") String processInstanceIds + ) { + logger.info("delete process instance by ids, login user:{}, project name:{}, process instance ids :{}", + loginUser.getUserName(), projectName, processInstanceIds); + // task queue + Map result = new HashMap<>(5); + List deleteFailedIdList = new ArrayList<>(); + if (StringUtils.isNotEmpty(processInstanceIds)) { + String[] processInstanceIdArray = processInstanceIds.split(","); - for (String strProcessInstanceId:processInstanceIdArray) { - int processInstanceId = Integer.parseInt(strProcessInstanceId); - try { - Map deleteResult = processInstanceService.deleteProcessInstanceById(loginUser, projectName, processInstanceId); - if(!Status.SUCCESS.equals(deleteResult.get(Constants.STATUS))){ - deleteFailedIdList.add(strProcessInstanceId); - logger.error((String)deleteResult.get(Constants.MSG)); - } - } catch (Exception e) { + for (String strProcessInstanceId : processInstanceIdArray) { + int processInstanceId = Integer.parseInt(strProcessInstanceId); + try { + Map deleteResult = processInstanceService.deleteProcessInstanceById(loginUser, projectName, processInstanceId); + if (!Status.SUCCESS.equals(deleteResult.get(Constants.STATUS))) { deleteFailedIdList.add(strProcessInstanceId); + logger.error((String) deleteResult.get(Constants.MSG)); } + } catch (Exception e) { + deleteFailedIdList.add(strProcessInstanceId); } } - if(!deleteFailedIdList.isEmpty()){ - putMsg(result, Status.BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR, String.join(",", deleteFailedIdList)); - }else{ - putMsg(result, Status.SUCCESS); - } - - return returnDataList(result); - }catch (Exception e){ - logger.error(BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR.getMsg(),e); - return error(Status.BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR.getCode(), Status.BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR.getMsg()); } + if (!deleteFailedIdList.isEmpty()) { + putMsg(result, Status.BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR, String.join(",", deleteFailedIdList)); + } 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 571b2ea469..90364f09fb 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 @@ -17,7 +17,7 @@ package org.apache.dolphinscheduler.api.controller; -import org.apache.dolphinscheduler.api.enums.Status; +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; @@ -59,61 +59,53 @@ public class ProjectController extends BaseController { /** * 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 = "createProject", notes = "CREATE_PROJECT_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "projectName", value = "PROJECT_NAME", dataType ="String"), + @ApiImplicitParam(name = "projectName", value = "PROJECT_NAME", dataType = "String"), @ApiImplicitParam(name = "description", value = "PROJECT_DESC", dataType = "String") }) @PostMapping(value = "/create") @ResponseStatus(HttpStatus.CREATED) + @ApiException(CREATE_PROJECT_ERROR) public Result createProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("projectName") String projectName, @RequestParam(value = "description", required = false) String description) { - try { - logger.info("login user {}, create project name: {}, desc: {}", loginUser.getUserName(), projectName, description); - Map result = projectService.createProject(loginUser, projectName, description); - return returnDataList(result); - } catch (Exception e) { - logger.error(CREATE_PROJECT_ERROR.getMsg(), e); - return error(CREATE_PROJECT_ERROR.getCode(), CREATE_PROJECT_ERROR.getMsg()); - } + logger.info("login user {}, create project name: {}, desc: {}", loginUser.getUserName(), projectName, description); + Map result = projectService.createProject(loginUser, projectName, description); + return returnDataList(result); } /** * updateProcessInstance project * - * @param loginUser login user - * @param projectId project id + * @param loginUser login user + * @param projectId project id * @param projectName project name * @param description description * @return update result code */ - @ApiOperation(value = "updateProject", notes= "UPDATE_PROJECT_NOTES") + @ApiOperation(value = "updateProject", notes = "UPDATE_PROJECT_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType ="Int", example = "100"), - @ApiImplicitParam(name = "projectName",value = "PROJECT_NAME",dataType = "String"), + @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100"), + @ApiImplicitParam(name = "projectName", value = "PROJECT_NAME", dataType = "String"), @ApiImplicitParam(name = "description", value = "PROJECT_DESC", dataType = "String") }) @PostMapping(value = "/update") @ResponseStatus(HttpStatus.OK) + @ApiException(UPDATE_PROJECT_ERROR) public Result updateProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("projectId") Integer projectId, @RequestParam("projectName") String projectName, @RequestParam(value = "description", required = false) String description) { - try { - logger.info("login user {} , updateProcessInstance project name: {}, desc: {}", loginUser.getUserName(), projectName, description); - Map result = projectService.update(loginUser, projectId, projectName, description); - return returnDataList(result); - } catch (Exception e) { - logger.error(UPDATE_PROJECT_ERROR.getMsg(), e); - return error(UPDATE_PROJECT_ERROR.getCode(), UPDATE_PROJECT_ERROR.getMsg()); - } + logger.info("login user {} , updateProcessInstance project name: {}, desc: {}", loginUser.getUserName(), projectName, description); + Map result = projectService.update(loginUser, projectId, projectName, description); + return returnDataList(result); } /** @@ -123,23 +115,19 @@ public class ProjectController extends BaseController { * @param projectId project id * @return project detail information */ - @ApiOperation(value = "queryProjectById", notes= "QUERY_PROJECT_BY_ID_NOTES") + @ApiOperation(value = "queryProjectById", notes = "QUERY_PROJECT_BY_ID_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType ="Int", example = "100") + @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100") }) @GetMapping(value = "/query-by-id") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_PROJECT_DETAILS_BY_ID_ERROR) public Result queryProjectById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("projectId") Integer projectId) { logger.info("login user {}, query project by id: {}", loginUser.getUserName(), projectId); - try { - Map result = projectService.queryById(projectId); - return returnDataList(result); - } catch (Exception e) { - logger.error(QUERY_PROJECT_DETAILS_BY_ID_ERROR.getMsg(), e); - return error(QUERY_PROJECT_DETAILS_BY_ID_ERROR.getCode(), QUERY_PROJECT_DETAILS_BY_ID_ERROR.getMsg()); - } + Map result = projectService.queryById(projectId); + return returnDataList(result); } /** @@ -147,33 +135,29 @@ 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") + @ApiOperation(value = "queryProjectListPaging", notes = "QUERY_PROJECT_LIST_PAGING_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType ="String"), - @ApiImplicitParam(name = "projectId", value = "PAGE_SIZE", dataType ="Int", example = "20"), - @ApiImplicitParam(name = "projectId", value = "PAGE_NO", dataType ="Int", example = "1") + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), + @ApiImplicitParam(name = "projectId", value = "PAGE_SIZE", dataType = "Int", example = "20"), + @ApiImplicitParam(name = "projectId", value = "PAGE_NO", dataType = "Int", example = "1") }) @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) + @ApiException(LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR) public Result queryProjectListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam("pageSize") Integer pageSize, @RequestParam("pageNo") Integer pageNo ) { - try { - logger.info("login user {}, query project list paging", loginUser.getUserName()); - searchVal = ParameterUtils.handleEscapes(searchVal); - Map result = projectService.queryProjectListPaging(loginUser, pageSize, pageNo, searchVal); - return returnDataListPaging(result); - } catch (Exception e) { - logger.error(LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR.getMsg(), e); - return error(Status.LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR.getCode(), Status.LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR.getMsg()); - } + logger.info("login user {}, query project list paging", loginUser.getUserName()); + searchVal = ParameterUtils.handleEscapes(searchVal); + Map result = projectService.queryProjectListPaging(loginUser, pageSize, pageNo, searchVal); + return returnDataListPaging(result); } /** @@ -183,49 +167,41 @@ public class ProjectController extends BaseController { * @param projectId project id * @return delete result code */ - @ApiOperation(value = "deleteProjectById", notes= "DELETE_PROJECT_BY_ID_NOTES") + @ApiOperation(value = "deleteProjectById", notes = "DELETE_PROJECT_BY_ID_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType ="Int", example = "100") + @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100") }) @GetMapping(value = "/delete") @ResponseStatus(HttpStatus.OK) + @ApiException(DELETE_PROJECT_ERROR) public Result deleteProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("projectId") Integer projectId ) { - try { - logger.info("login user {}, delete project: {}.", loginUser.getUserName(), projectId); - Map result = projectService.deleteProject(loginUser, projectId); - return returnDataList(result); - } catch (Exception e) { - logger.error(DELETE_PROJECT_ERROR.getMsg(), e); - return error(DELETE_PROJECT_ERROR.getCode(), DELETE_PROJECT_ERROR.getMsg()); - } + logger.info("login user {}, delete project: {}.", loginUser.getUserName(), projectId); + Map result = projectService.deleteProject(loginUser, projectId); + return returnDataList(result); } /** * 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") + @ApiOperation(value = "queryUnauthorizedProject", notes = "QUERY_UNAUTHORIZED_PROJECT_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "USER_ID", dataType ="Int", example = "100") + @ApiImplicitParam(name = "userId", value = "USER_ID", dataType = "Int", example = "100") }) @GetMapping(value = "/unauth-project") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_UNAUTHORIZED_PROJECT_ERROR) public Result queryUnauthorizedProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("userId") Integer userId) { - try { - logger.info("login user {}, query unauthorized project by user id: {}.", loginUser.getUserName(), userId); - Map result = projectService.queryUnauthorizedProject(loginUser, userId); - return returnDataList(result); - } catch (Exception e) { - logger.error(QUERY_UNAUTHORIZED_PROJECT_ERROR.getMsg(), e); - return error(QUERY_UNAUTHORIZED_PROJECT_ERROR.getCode(), QUERY_UNAUTHORIZED_PROJECT_ERROR.getMsg()); - } + logger.info("login user {}, query unauthorized project by user id: {}.", loginUser.getUserName(), userId); + Map result = projectService.queryUnauthorizedProject(loginUser, userId); + return returnDataList(result); } @@ -233,73 +209,61 @@ public class ProjectController extends BaseController { * 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") + @ApiOperation(value = "queryAuthorizedProject", notes = "QUERY_AUTHORIZED_PROJECT_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "USER_ID", dataType ="Int", example = "100") + @ApiImplicitParam(name = "userId", value = "USER_ID", dataType = "Int", example = "100") }) @GetMapping(value = "/authed-project") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_AUTHORIZED_PROJECT) public Result queryAuthorizedProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("userId") Integer userId) { - try { - logger.info("login user {}, query authorized project by user id: {}.", loginUser.getUserName(), userId); - Map result = projectService.queryAuthorizedProject(loginUser, userId); - return returnDataList(result); - } catch (Exception e) { - logger.error(QUERY_AUTHORIZED_PROJECT.getMsg(), e); - return error(QUERY_AUTHORIZED_PROJECT.getCode(), QUERY_AUTHORIZED_PROJECT.getMsg()); - } + logger.info("login user {}, query authorized project by user id: {}.", loginUser.getUserName(), userId); + Map result = projectService.queryAuthorizedProject(loginUser, userId); + return returnDataList(result); } /** * import process definition - * @param loginUser login user - * @param file resource file + * + * @param loginUser login user + * @param file resource file * @param projectName project name * @return import result code */ - @ApiOperation(value = "importProcessDefinition", notes= "EXPORT_PROCCESS_DEFINITION_NOTES") + @ApiOperation(value = "importProcessDefinition", notes = "EXPORT_PROCCESS_DEFINITION_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "file", value = "RESOURCE_FILE", required = true, dataType = "MultipartFile") }) - @PostMapping(value="/import-definition") + @PostMapping(value = "/import-definition") + @ApiException(IMPORT_PROCESS_DEFINE_ERROR) public Result importProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("file") MultipartFile file, - @RequestParam("projectName") String projectName){ - try{ - logger.info("import process definition by id, login user:{}, project: {}", - loginUser.getUserName(), projectName); - Map result = processDefinitionService.importProcessDefinition(loginUser, file, projectName); - return returnDataList(result); - }catch (Exception e){ - logger.error(IMPORT_PROCESS_DEFINE_ERROR.getMsg(),e); - return error(IMPORT_PROCESS_DEFINE_ERROR.getCode(), IMPORT_PROCESS_DEFINE_ERROR.getMsg()); - } + @RequestParam("projectName") String projectName) { + logger.info("import process definition by id, login user:{}, project: {}", + loginUser.getUserName(), projectName); + Map result = processDefinitionService.importProcessDefinition(loginUser, file, projectName); + return returnDataList(result); } /** * query all project list + * * @param loginUser login user * @return all project list */ - @ApiOperation(value = "queryAllProjectList", notes= "QUERY_ALL_PROJECT_LIST_NOTES") + @ApiOperation(value = "queryAllProjectList", notes = "QUERY_ALL_PROJECT_LIST_NOTES") @GetMapping(value = "/query-project-list") @ResponseStatus(HttpStatus.OK) + @ApiException(LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR) public Result queryAllProjectList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - - try { - logger.info("login user {}, query all project list", loginUser.getUserName()); - Map result = projectService.queryAllProjectList(); - return returnDataList(result); - } catch (Exception e) { - logger.error(LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR.getMsg(), e); - return error(Status.LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR.getCode(), Status.LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR.getMsg()); - } + logger.info("login user {}, query all project list", loginUser.getUserName()); + Map result = projectService.queryAllProjectList(); + return returnDataList(result); } - } 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 056ca618f5..cf62d1340b 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 @@ -18,6 +18,7 @@ package org.apache.dolphinscheduler.api.controller; import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.QueueService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; @@ -36,6 +37,8 @@ import springfox.documentation.annotations.ApiIgnore; import java.util.Map; +import static org.apache.dolphinscheduler.api.enums.Status.*; + /** * queue controller @@ -43,7 +46,7 @@ import java.util.Map; @Api(tags = "QUEUE_TAG", position = 1) @RestController @RequestMapping("/queue") -public class QueueController extends BaseController{ +public class QueueController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(QueueController.class); @@ -53,151 +56,131 @@ public class QueueController extends BaseController{ /** * query queue list + * * @param loginUser login user * @return queue list */ - @ApiOperation(value = "queryList", notes= "QUERY_QUEUE_LIST_NOTES") - @GetMapping(value="/list") + @ApiOperation(value = "queryList", notes = "QUERY_QUEUE_LIST_NOTES") + @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) - public Result queryList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser){ - try{ - logger.info("login user {}, query queue list", loginUser.getUserName()); - Map result = queueService.queryList(loginUser); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.QUERY_QUEUE_LIST_ERROR.getMsg(),e); - return error(Status.QUERY_QUEUE_LIST_ERROR.getCode(), Status.QUERY_QUEUE_LIST_ERROR.getMsg()); - } + @ApiException(QUERY_QUEUE_LIST_ERROR) + public Result queryList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { + logger.info("login user {}, query queue list", loginUser.getUserName()); + Map result = queueService.queryList(loginUser); + return returnDataList(result); } /** * 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") + @ApiOperation(value = "queryQueueListPaging", notes = "QUERY_QUEUE_LIST_PAGING_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType ="String"), + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType ="Int",example = "20") + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20") }) - @GetMapping(value="/list-paging") + @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_QUEUE_LIST_ERROR) public Result queryQueueListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("pageNo") Integer pageNo, - @RequestParam(value = "searchVal", required = false) String searchVal, - @RequestParam("pageSize") Integer pageSize){ - try{ - logger.info("login user {}, query queue list,search value:{}", loginUser.getUserName(),searchVal); - Map result = checkPageParams(pageNo, pageSize); - if(result.get(Constants.STATUS) != Status.SUCCESS){ - return returnDataListPaging(result); - } - - searchVal = ParameterUtils.handleEscapes(searchVal); - result = queueService.queryList(loginUser,searchVal,pageNo,pageSize); + @RequestParam("pageNo") Integer pageNo, + @RequestParam(value = "searchVal", required = false) String searchVal, + @RequestParam("pageSize") Integer pageSize) { + logger.info("login user {}, query queue list,search value:{}", loginUser.getUserName(), searchVal); + Map result = checkPageParams(pageNo, pageSize); + if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); - }catch (Exception e){ - logger.error(Status.QUERY_QUEUE_LIST_ERROR.getMsg(),e); - return error(Status.QUERY_QUEUE_LIST_ERROR.getCode(), Status.QUERY_QUEUE_LIST_ERROR.getMsg()); } + + searchVal = ParameterUtils.handleEscapes(searchVal); + result = queueService.queryList(loginUser, searchVal, pageNo, pageSize); + return returnDataListPaging(result); } /** * 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") + @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") @ResponseStatus(HttpStatus.CREATED) + @ApiException(CREATE_QUEUE_ERROR) public Result createQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "queue") String queue, - @RequestParam(value = "queueName") String queueName) { + @RequestParam(value = "queue") String queue, + @RequestParam(value = "queueName") String queueName) { logger.info("login user {}, create queue, queue: {}, queueName: {}", loginUser.getUserName(), queue, queueName); - try { - Map result = queueService.createQueue(loginUser,queue,queueName); - return returnDataList(result); - - }catch (Exception e){ - logger.error(Status.CREATE_QUEUE_ERROR.getMsg(),e); - return error(Status.CREATE_QUEUE_ERROR.getCode(), Status.CREATE_QUEUE_ERROR.getMsg()); - } + Map result = queueService.createQueue(loginUser, queue, queueName); + return returnDataList(result); } /** * 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") + @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") @ResponseStatus(HttpStatus.CREATED) + @ApiException(UPDATE_QUEUE_ERROR) public Result updateQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int id, @RequestParam(value = "queue") String queue, @RequestParam(value = "queueName") String queueName) { logger.info("login user {}, update queue, id: {}, queue: {}, queueName: {}", - loginUser.getUserName(), id,queue, queueName); - try { - Map result = queueService.updateQueue(loginUser,id,queue,queueName); - return returnDataList(result); - - }catch (Exception e){ - logger.error(Status.UPDATE_QUEUE_ERROR.getMsg(),e); - return error(Status.UPDATE_QUEUE_ERROR.getCode(), Status.UPDATE_QUEUE_ERROR.getMsg()); - } + loginUser.getUserName(), id, queue, queueName); + Map result = queueService.updateQueue(loginUser, id, queue, queueName); + return returnDataList(result); } /** * 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") + @ApiOperation(value = "verifyQueue", notes = "VERIFY_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 = "/verify-queue") @ResponseStatus(HttpStatus.OK) + @ApiException(VERIFY_QUEUE_ERROR) public Result verifyQueue(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value ="queue") String queue, - @RequestParam(value ="queueName") String queueName + @RequestParam(value = "queue") String queue, + @RequestParam(value = "queueName") String queueName ) { - try{ - logger.info("login user {}, verfiy queue: {} queue name: {}", - loginUser.getUserName(),queue,queueName); - return queueService.verifyQueue(queue,queueName); - }catch (Exception e){ - logger.error(Status.VERIFY_QUEUE_ERROR.getMsg(),e); - return error(Status.VERIFY_QUEUE_ERROR.getCode(), Status.VERIFY_QUEUE_ERROR.getMsg()); - } + logger.info("login user {}, verfiy queue: {} queue name: {}", + loginUser.getUserName(), queue, queueName); + return queueService.verifyQueue(queue, queueName); } 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 1d83fcea2b..cc09b2d650 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 @@ -17,6 +17,7 @@ package org.apache.dolphinscheduler.api.controller; import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.ResourcesService; import org.apache.dolphinscheduler.api.service.UdfFuncService; import org.apache.dolphinscheduler.api.utils.Result; @@ -44,13 +45,14 @@ import springfox.documentation.annotations.ApiIgnore; import java.util.Map; import static org.apache.dolphinscheduler.api.enums.Status.*; + /** * resources controller */ @Api(tags = "RESOURCES_TAG", position = 1) @RestController @RequestMapping("resources") -public class ResourcesController extends BaseController{ +public class ResourcesController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(ResourcesController.class); @@ -71,202 +73,177 @@ public class ResourcesController extends BaseController{ */ /** - * - * @param loginUser login user - * @param type type - * @param alias alias - * @param description description - * @param pid parent id - * @param currentDir current directory + * @param loginUser login user + * @param type type + * @param alias alias + * @param description description + * @param pid parent id + * @param currentDir current directory * @return */ - @ApiOperation(value = "createDirctory", notes= "CREATE_RESOURCE_NOTES") + @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 = "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 = "/directory/create") + @ApiException(CREATE_RESOURCE_ERROR) public Result createDirectory(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "type") ResourceType type, - @RequestParam(value ="name") String alias, - @RequestParam(value = "description", required = false) String description, - @RequestParam(value ="pid") int pid, - @RequestParam(value ="currentDir") String currentDir) { - try { - logger.info("login user {}, create resource, type: {}, resource alias: {}, desc: {}, file: {},{}", - loginUser.getUserName(),type, alias, description,pid,currentDir); - return resourceService.createDirectory(loginUser,alias, description,type ,pid,currentDir); - } catch (Exception e) { - logger.error(CREATE_RESOURCE_ERROR.getMsg(),e); - return error(CREATE_RESOURCE_ERROR.getCode(), CREATE_RESOURCE_ERROR.getMsg()); - } + @RequestParam(value = "type") ResourceType type, + @RequestParam(value = "name") String alias, + @RequestParam(value = "description", required = false) String description, + @RequestParam(value = "pid") int pid, + @RequestParam(value = "currentDir") String currentDir) { + logger.info("login user {}, create resource, type: {}, resource alias: {}, desc: {}, file: {},{}", + loginUser.getUserName(), type, alias, description, pid, currentDir); + return resourceService.createDirectory(loginUser, alias, description, type, pid, currentDir); } /** * create resource * - * @param loginUser login user - * @param alias alias + * @param loginUser login user + * @param alias alias * @param description description - * @param type type - * @param file file + * @param type type + * @param file file * @return create result code */ - @ApiOperation(value = "createResource", notes= "CREATE_RESOURCE_NOTES") + @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 = "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 = "/create") + @ApiException(CREATE_RESOURCE_ERROR) public Result createResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "type") ResourceType type, - @RequestParam(value ="name") String alias, + @RequestParam(value = "name") String alias, @RequestParam(value = "description", required = false) String description, @RequestParam("file") MultipartFile file, - @RequestParam(value ="pid") int pid, - @RequestParam(value ="currentDir") String currentDir) { - try { - logger.info("login user {}, create resource, type: {}, resource alias: {}, desc: {}, file: {},{}", - loginUser.getUserName(),type, alias, description, file.getName(), file.getOriginalFilename()); - return resourceService.createResource(loginUser,alias, description,type ,file,pid,currentDir); - } catch (Exception e) { - logger.error(CREATE_RESOURCE_ERROR.getMsg(),e); - return error(CREATE_RESOURCE_ERROR.getCode(), CREATE_RESOURCE_ERROR.getMsg()); - } + @RequestParam(value = "pid") int pid, + @RequestParam(value = "currentDir") String currentDir) { + logger.info("login user {}, create resource, type: {}, resource alias: {}, desc: {}, file: {},{}", + loginUser.getUserName(), type, alias, description, file.getName(), file.getOriginalFilename()); + return resourceService.createResource(loginUser, alias, description, type, file, pid, currentDir); } /** * update resource * - * @param loginUser login user - * @param alias alias - * @param resourceId resource id - * @param type resource type + * @param loginUser login user + * @param alias alias + * @param resourceId resource id + * @param type resource type * @param description description * @return update result code */ - @ApiOperation(value = "updateResource", notes= "UPDATE_RESOURCE_NOTES") + @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 = "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") }) @PostMapping(value = "/update") + @ApiException(UPDATE_RESOURCE_ERROR) public Result updateResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value ="id") int resourceId, + @RequestParam(value = "id") int resourceId, @RequestParam(value = "type") ResourceType type, - @RequestParam(value ="name")String alias, + @RequestParam(value = "name") String alias, @RequestParam(value = "description", required = false) String description) { - try { - logger.info("login user {}, update resource, type: {}, resource alias: {}, desc: {}", - loginUser.getUserName(),type, alias, description); - return resourceService.updateResource(loginUser,resourceId,alias,description,type); - } catch (Exception e) { - logger.error(UPDATE_RESOURCE_ERROR.getMsg(),e); - return error(Status.UPDATE_RESOURCE_ERROR.getCode(), Status.UPDATE_RESOURCE_ERROR.getMsg()); - } + logger.info("login user {}, update resource, type: {}, resource alias: {}, desc: {}", + loginUser.getUserName(), type, alias, description); + return resourceService.updateResource(loginUser, resourceId, alias, description, type); } /** * query resources list * * @param loginUser login user - * @param type resource type + * @param type resource type * @return resource list */ - @ApiOperation(value = "queryResourceList", notes= "QUERY_RESOURCE_LIST_NOTES") + @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") + @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_RESOURCES_LIST_ERROR) public Result queryResourceList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value ="type") ResourceType type - ){ - try{ - logger.info("query resource list, login user:{}, resource type:{}", loginUser.getUserName(), type); - Map result = resourceService.queryResourceList(loginUser, type); - return returnDataList(result); - }catch (Exception e){ - logger.error(QUERY_RESOURCES_LIST_ERROR.getMsg(),e); - return error(Status.QUERY_RESOURCES_LIST_ERROR.getCode(), Status.QUERY_RESOURCES_LIST_ERROR.getMsg()); - } + @RequestParam(value = "type") ResourceType type + ) { + logger.info("query resource list, login user:{}, resource type:{}", loginUser.getUserName(), type); + Map result = resourceService.queryResourceList(loginUser, type); + return returnDataList(result); } /** * query resources list paging * * @param loginUser login user - * @param type resource type + * @param type resource type * @param searchVal search value - * @param pageNo page number - * @param pageSize page size + * @param pageNo page number + * @param pageSize page size * @return resource list page */ - @ApiOperation(value = "queryResourceListPaging", notes= "QUERY_RESOURCE_LIST_PAGING_NOTES") + @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"), - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType ="String"), + @ApiImplicitParam(name = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"), + @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "int"), + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType ="Int",example = "20") + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20") }) - @GetMapping(value="/list-paging") + @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_RESOURCES_LIST_PAGING) public Result queryResourceListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value ="type") ResourceType type, - @RequestParam(value ="id") int id, - @RequestParam("pageNo") Integer pageNo, - @RequestParam(value = "searchVal", required = false) String searchVal, - @RequestParam("pageSize") Integer pageSize - ){ - try{ - logger.info("query resource list, login user:{}, resource type:{}, search value:{}", - loginUser.getUserName(), type, searchVal); - Map result = checkPageParams(pageNo, pageSize); - if(result.get(Constants.STATUS) != Status.SUCCESS){ - return returnDataListPaging(result); - } - - searchVal = ParameterUtils.handleEscapes(searchVal); - result = resourceService.queryResourceListPaging(loginUser,id,type,searchVal,pageNo, pageSize); + @RequestParam(value = "type") ResourceType type, + @RequestParam(value = "id") int id, + @RequestParam("pageNo") Integer pageNo, + @RequestParam(value = "searchVal", required = false) String searchVal, + @RequestParam("pageSize") Integer pageSize + ) { + logger.info("query resource list, login user:{}, resource type:{}, search value:{}", + loginUser.getUserName(), type, searchVal); + Map result = checkPageParams(pageNo, pageSize); + if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); - }catch (Exception e){ - logger.error(QUERY_RESOURCES_LIST_PAGING.getMsg(),e); - return error(Status.QUERY_RESOURCES_LIST_PAGING.getCode(), Status.QUERY_RESOURCES_LIST_PAGING.getMsg()); } + + searchVal = ParameterUtils.handleEscapes(searchVal); + result = resourceService.queryResourceListPaging(loginUser, id, type, searchVal, pageNo, pageSize); + return returnDataListPaging(result); } /** * delete resource * - * @param loginUser login user + * @param loginUser login user * @param resourceId resource id * @return delete result code */ - @ApiOperation(value = "deleteResource", notes= "DELETE_RESOURCE_BY_ID_NOTES") + @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") @ResponseStatus(HttpStatus.OK) + @ApiException(DELETE_RESOURCE_ERROR) public Result deleteResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value ="id") int resourceId - ) { - try{ - logger.info("login user {}, delete resource id: {}", - loginUser.getUserName(),resourceId); - return resourceService.delete(loginUser,resourceId); - }catch (Exception e){ - logger.error(DELETE_RESOURCE_ERROR.getMsg(),e); - return error(Status.DELETE_RESOURCE_ERROR.getCode(), Status.DELETE_RESOURCE_ERROR.getMsg()); - } + @RequestParam(value = "id") int resourceId + ) throws Exception { + logger.info("login user {}, delete resource id: {}", + loginUser.getUserName(), resourceId); + return resourceService.delete(loginUser, resourceId); } @@ -278,52 +255,44 @@ public class ResourcesController extends BaseController{ * @param type resource type * @return true if the resource name not exists, otherwise return false */ - @ApiOperation(value = "verifyResourceName", notes= "VERIFY_RESOURCE_NAME_NOTES") + @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) + @ApiException(VERIFY_RESOURCE_BY_NAME_AND_TYPE_ERROR) public Result verifyResourceName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value ="fullName") String fullName, - @RequestParam(value ="type") ResourceType type + @RequestParam(value = "fullName") String fullName, + @RequestParam(value = "type") ResourceType type ) { - try { - logger.info("login user {}, verfiy resource alias: {},resource type: {}", - loginUser.getUserName(), fullName,type); - - return resourceService.verifyResourceName(fullName,type,loginUser); - } catch (Exception e) { - logger.error(VERIFY_RESOURCE_BY_NAME_AND_TYPE_ERROR.getMsg(), e); - return error(Status.VERIFY_RESOURCE_BY_NAME_AND_TYPE_ERROR.getCode(), Status.VERIFY_RESOURCE_BY_NAME_AND_TYPE_ERROR.getMsg()); - } + logger.info("login user {}, verfiy resource alias: {},resource type: {}", + loginUser.getUserName(), fullName, type); + + return resourceService.verifyResourceName(fullName, type, loginUser); } /** * query resources jar list * * @param loginUser login user - * @param type resource type + * @param type resource type * @return resource list */ - @ApiOperation(value = "queryResourceJarList", notes= "QUERY_RESOURCE_LIST_NOTES") + @ApiOperation(value = "queryResourceJarList", 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 = "/list/jar") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_RESOURCES_LIST_ERROR) public Result queryResourceJarList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value ="type") ResourceType type - ){ - try{ - logger.info("query resource list, login user:{}, resource type:{}", loginUser.getUserName(), type.toString()); - Map result = resourceService.queryResourceJarList(loginUser, type); - return returnDataList(result); - }catch (Exception e){ - logger.error(QUERY_RESOURCES_LIST_ERROR.getMsg(),e); - return error(Status.QUERY_RESOURCES_LIST_ERROR.getCode(), Status.QUERY_RESOURCES_LIST_ERROR.getMsg()); - } + @RequestParam(value = "type") ResourceType type + ) { + logger.info("query resource list, login user:{}, resource type:{}", loginUser.getUserName(), type.toString()); + Map result = resourceService.queryResourceJarList(loginUser, type); + return returnDataList(result); } /** @@ -334,286 +303,252 @@ public class ResourcesController extends BaseController{ * @param type resource type * @return true if the resource name not exists, otherwise return false */ - @ApiOperation(value = "queryResource", notes= "QUERY_BY_RESOURCE_NAME") + @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 = "type", value = "RESOURCE_TYPE", required = true, dataType = "ResourceType"), + @ApiImplicitParam(name = "fullName", value = "RESOURCE_FULL_NAME", required = true, dataType = "String") }) @GetMapping(value = "/queryResource") @ResponseStatus(HttpStatus.OK) + @ApiException(RESOURCE_NOT_EXIST) 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, - @RequestParam(value ="type") ResourceType type + @RequestParam(value = "fullName", required = false) String fullName, + @RequestParam(value = "id", required = false) Integer id, + @RequestParam(value = "type") ResourceType type ) { - try { - logger.info("login user {}, query resource by full name: {} or id: {},resource type: {}", - loginUser.getUserName(), fullName,id,type); - - return resourceService.queryResource(fullName,id,type); - } catch (Exception e) { - logger.error(RESOURCE_NOT_EXIST.getMsg(), e); - return error(Status.RESOURCE_NOT_EXIST.getCode(), Status.RESOURCE_NOT_EXIST.getMsg()); - } + logger.info("login user {}, query resource by full name: {} or id: {},resource type: {}", + loginUser.getUserName(), fullName, id, type); + + return resourceService.queryResource(fullName, id, type); } /** * view resource file online * - * @param loginUser login user - * @param resourceId resource id + * @param loginUser login user + * @param resourceId resource id * @param skipLineNum skip line number - * @param limit limit + * @param limit limit * @return resource content */ - @ApiOperation(value = "viewResource", notes= "VIEW_RESOURCE_BY_ID_NOTES") + @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") + @ApiException(VIEW_RESOURCE_FILE_ON_LINE_ERROR) public Result viewResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int resourceId, @RequestParam(value = "skipLineNum") int skipLineNum, @RequestParam(value = "limit") int limit ) { - try{ - logger.info("login user {}, view resource : {}, skipLineNum {} , limit {}", - loginUser.getUserName(),resourceId,skipLineNum,limit); - - return resourceService.readResource(resourceId,skipLineNum,limit); - }catch (Exception e){ - logger.error(VIEW_RESOURCE_FILE_ON_LINE_ERROR.getMsg(),e); - return error(Status.VIEW_RESOURCE_FILE_ON_LINE_ERROR.getCode(), Status.VIEW_RESOURCE_FILE_ON_LINE_ERROR.getMsg()); - } + logger.info("login user {}, view resource : {}, skipLineNum {} , limit {}", + loginUser.getUserName(), resourceId, skipLineNum, limit); + + return resourceService.readResource(resourceId, skipLineNum, limit); } /** * create resource file online * - * @param loginUser login user - * @param type resource type - * @param fileName file name - * @param fileSuffix file suffix + * @param loginUser login user + * @param type resource type + * @param fileName file name + * @param fileSuffix file suffix * @param description description - * @param content content + * @param content content * @return create result code */ - @ApiOperation(value = "onlineCreateResource", notes= "ONLINE_CREATE_RESOURCE_NOTES") + @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 = "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") }) @PostMapping(value = "/online-create") + @ApiException(CREATE_RESOURCE_FILE_ON_LINE_ERROR) public Result onlineCreateResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "type") ResourceType type, - @RequestParam(value ="fileName")String fileName, - @RequestParam(value ="suffix")String fileSuffix, + @RequestParam(value = "fileName") String fileName, + @RequestParam(value = "suffix") String fileSuffix, @RequestParam(value = "description", required = false) String description, @RequestParam(value = "content") String content, - @RequestParam(value ="pid") int pid, - @RequestParam(value ="currentDir") String currentDir + @RequestParam(value = "pid") int pid, + @RequestParam(value = "currentDir") String currentDir ) { - try{ - logger.info("login user {}, online create resource! fileName : {}, type : {}, suffix : {},desc : {},content : {}", - loginUser.getUserName(),fileName,type,fileSuffix,description,content,pid,currentDir); - if(StringUtils.isEmpty(content)){ - logger.error("resource file contents are not allowed to be empty"); - return error(Status.RESOURCE_FILE_IS_EMPTY.getCode(), RESOURCE_FILE_IS_EMPTY.getMsg()); - } - return resourceService.onlineCreateResource(loginUser,type,fileName,fileSuffix,description,content,pid,currentDir); - }catch (Exception e){ - logger.error(CREATE_RESOURCE_FILE_ON_LINE_ERROR.getMsg(),e); - return error(Status.CREATE_RESOURCE_FILE_ON_LINE_ERROR.getCode(), Status.CREATE_RESOURCE_FILE_ON_LINE_ERROR.getMsg()); + logger.info("login user {}, online create resource! fileName : {}, type : {}, suffix : {},desc : {},content : {}", + loginUser.getUserName(), fileName, type, fileSuffix, description, content, pid, currentDir); + if (StringUtils.isEmpty(content)) { + logger.error("resource file contents are not allowed to be empty"); + return error(Status.RESOURCE_FILE_IS_EMPTY.getCode(), RESOURCE_FILE_IS_EMPTY.getMsg()); } + return resourceService.onlineCreateResource(loginUser, type, fileName, fileSuffix, description, content, pid, currentDir); } /** * edit resource file online * - * @param loginUser login user + * @param loginUser login user * @param resourceId resource id - * @param content content + * @param content content * @return update result code */ - @ApiOperation(value = "updateResourceContent", notes= "UPDATE_RESOURCE_NOTES") + @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") + @ApiException(EDIT_RESOURCE_FILE_ON_LINE_ERROR) public Result updateResourceContent(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "id") int resourceId, @RequestParam(value = "content") String content ) { - try{ - logger.info("login user {}, updateProcessInstance resource : {}", - loginUser.getUserName(),resourceId); - if(StringUtils.isEmpty(content)){ - logger.error("The resource file contents are not allowed to be empty"); - return error(Status.RESOURCE_FILE_IS_EMPTY.getCode(), RESOURCE_FILE_IS_EMPTY.getMsg()); - } - return resourceService.updateResourceContent(resourceId,content); - }catch (Exception e){ - logger.error(EDIT_RESOURCE_FILE_ON_LINE_ERROR.getMsg(),e); - return error(Status.EDIT_RESOURCE_FILE_ON_LINE_ERROR.getCode(), Status.EDIT_RESOURCE_FILE_ON_LINE_ERROR.getMsg()); + logger.info("login user {}, updateProcessInstance resource : {}", + loginUser.getUserName(), resourceId); + if (StringUtils.isEmpty(content)) { + logger.error("The resource file contents are not allowed to be empty"); + return error(Status.RESOURCE_FILE_IS_EMPTY.getCode(), RESOURCE_FILE_IS_EMPTY.getMsg()); } + return resourceService.updateResourceContent(resourceId, content); } /** * download resource file * - * @param loginUser login user + * @param loginUser login user * @param resourceId resource id * @return resource content */ - @ApiOperation(value = "downloadResource", notes= "DOWNLOAD_RESOURCE_NOTES") + @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") @ResponseBody + @ApiException(DOWNLOAD_RESOURCE_FILE_ERROR) public ResponseEntity downloadResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int resourceId) { - try{ - logger.info("login user {}, download resource : {}", - loginUser.getUserName(), resourceId); - 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); - }catch (RuntimeException e){ - logger.error(e.getMessage(),e); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage()); - }catch (Exception e){ - logger.error(DOWNLOAD_RESOURCE_FILE_ERROR.getMsg(),e); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(Status.DOWNLOAD_RESOURCE_FILE_ERROR.getMsg()); + @RequestParam(value = "id") int resourceId) throws Exception { + logger.info("login user {}, download resource : {}", + loginUser.getUserName(), resourceId); + 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); } /** * create udf function - * @param loginUser login user - * @param type udf type - * @param funcName function name - * @param argTypes argument types - * @param database database + * + * @param loginUser login user + * @param type udf type + * @param funcName function name + * @param argTypes argument types + * @param database database * @param description description - * @param className class name - * @param resourceId resource id + * @param className class name + * @param resourceId resource id * @return create result code */ - @ApiOperation(value = "createUdfFunc", notes= "CREATE_UDF_FUNCTION_NOTES") + @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 = "suffix", 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 = "suffix", 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") @ResponseStatus(HttpStatus.CREATED) + @ApiException(CREATE_UDF_FUNCTION_ERROR) public Result createUdfFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @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 = "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) { logger.info("login user {}, create udf function, type: {}, funcName: {},argTypes: {} ,database: {},desc: {},resourceId: {}", - loginUser.getUserName(),type, funcName, argTypes,database,description, resourceId); - try { - return udfFuncService.createUdfFunction(loginUser,funcName,className,argTypes,database,description,type,resourceId); - } catch (Exception e) { - logger.error(CREATE_UDF_FUNCTION_ERROR.getMsg(),e); - return error(Status.CREATE_UDF_FUNCTION_ERROR.getCode(), Status.CREATE_UDF_FUNCTION_ERROR.getMsg()); - } + loginUser.getUserName(), type, funcName, argTypes, database, description, resourceId); + return udfFuncService.createUdfFunction(loginUser, funcName, className, argTypes, database, description, type, resourceId); } /** * view udf function * * @param loginUser login user - * @param id resource id + * @param id resource id * @return udf function detail */ - @ApiOperation(value = "viewUIUdfFunction", notes= "VIEW_UDF_FUNCTION_NOTES") + @ApiOperation(value = "viewUIUdfFunction", notes = "VIEW_UDF_FUNCTION_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "resourceId", value = "RESOURCE_ID", required = true, dataType ="Int", example = "100") + @ApiImplicitParam(name = "resourceId", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100") }) @GetMapping(value = "/udf-func/update-ui") @ResponseStatus(HttpStatus.OK) + @ApiException(VIEW_UDF_FUNCTION_ERROR) public Result viewUIUdfFunction(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("id") int id) { + @RequestParam("id") int id) { logger.info("login user {}, query udf{}", loginUser.getUserName(), id); - try { - Map map = udfFuncService.queryUdfFuncDetail(id); - return returnDataList(map); - } catch (Exception e) { - logger.error(VIEW_UDF_FUNCTION_ERROR.getMsg(),e); - return error(Status.VIEW_UDF_FUNCTION_ERROR.getCode(), Status.VIEW_UDF_FUNCTION_ERROR.getMsg()); - } + Map map = udfFuncService.queryUdfFuncDetail(id); + return returnDataList(map); } /** * update udf function * - * @param loginUser login user - * @param type resource type - * @param funcName function name - * @param argTypes argument types - * @param database data base + * @param loginUser login user + * @param type resource type + * @param funcName function name + * @param argTypes argument types + * @param database data base * @param description description - * @param resourceId resource id - * @param className class name - * @param udfFuncId udf function id + * @param resourceId resource id + * @param className class name + * @param udfFuncId udf function id * @return update result code */ - @ApiOperation(value = "updateUdfFunc", notes= "UPDATE_UDF_FUNCTION_NOTES") + @ApiOperation(value = "updateUdfFunc", notes = "UPDATE_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 = "suffix", 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 = "id", 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 = "suffix", 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 = "id", value = "RESOURCE_ID", required = true, dataType = "Int", example = "100") }) @PostMapping(value = "/udf-func/update") + @ApiException(UPDATE_UDF_FUNCTION_ERROR) public Result updateUdfFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(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 = "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) { - try { - logger.info("login user {}, updateProcessInstance udf function id: {},type: {}, funcName: {},argTypes: {} ,database: {},desc: {},resourceId: {}", - loginUser.getUserName(),udfFuncId,type, funcName, argTypes,database,description, resourceId); - Map result = udfFuncService.updateUdfFunc(udfFuncId,funcName,className,argTypes,database,description,type,resourceId); - return returnDataList(result); - } catch (Exception e) { - logger.error(UPDATE_UDF_FUNCTION_ERROR.getMsg(),e); - return error(Status.UPDATE_UDF_FUNCTION_ERROR.getCode(), Status.UPDATE_UDF_FUNCTION_ERROR.getMsg()); - } + logger.info("login user {}, updateProcessInstance udf function id: {},type: {}, funcName: {},argTypes: {} ,database: {},desc: {},resourceId: {}", + loginUser.getUserName(), udfFuncId, type, funcName, argTypes, database, description, resourceId); + Map result = udfFuncService.updateUdfFunc(udfFuncId, funcName, className, argTypes, database, description, type, resourceId); + return returnDataList(result); } /** @@ -621,91 +556,78 @@ public class ResourcesController 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 udf function list page */ - @ApiOperation(value = "queryUdfFuncListPaging", notes= "QUERY_UDF_FUNCTION_LIST_PAGING_NOTES") + @ApiOperation(value = "queryUdfFuncListPaging", notes = "QUERY_UDF_FUNCTION_LIST_PAGING_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType ="String"), + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType ="Int",example = "20") + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20") }) - @GetMapping(value="/udf-func/list-paging") + @GetMapping(value = "/udf-func/list-paging") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_UDF_FUNCTION_LIST_PAGING_ERROR) public Result queryUdfFuncList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("pageNo") Integer pageNo, @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam("pageSize") Integer pageSize - ){ - try{ - logger.info("query udf functions list, login user:{},search value:{}", - loginUser.getUserName(), searchVal); - Map result = checkPageParams(pageNo, pageSize); - if(result.get(Constants.STATUS) != Status.SUCCESS){ - return returnDataListPaging(result); - } - - result = udfFuncService.queryUdfFuncListPaging(loginUser,searchVal,pageNo, pageSize); + ) { + logger.info("query udf functions list, login user:{},search value:{}", + loginUser.getUserName(), searchVal); + Map result = checkPageParams(pageNo, pageSize); + if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); - }catch (Exception e){ - logger.error(QUERY_UDF_FUNCTION_LIST_PAGING_ERROR.getMsg(),e); - return error(Status.QUERY_UDF_FUNCTION_LIST_PAGING_ERROR.getCode(), Status.QUERY_UDF_FUNCTION_LIST_PAGING_ERROR.getMsg()); } + + result = udfFuncService.queryUdfFuncListPaging(loginUser, searchVal, pageNo, pageSize); + return returnDataListPaging(result); } /** * query resource list by type * * @param loginUser login user - * @param type resource type + * @param type resource type * @return resource list */ - @ApiOperation(value = "queryResourceList", notes= "QUERY_RESOURCE_LIST_NOTES") + @ApiOperation(value = "queryResourceList", notes = "QUERY_RESOURCE_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") + @GetMapping(value = "/udf-func/list") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_DATASOURCE_BY_TYPE_ERROR) public Result queryResourceList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("type") UdfType type){ - try{ - logger.info("query datasource list, user:{}, type:{}", loginUser.getUserName(), type); - Map result = udfFuncService.queryResourceList(loginUser,type.ordinal()); - return returnDataList(result); - }catch (Exception e){ - logger.error(QUERY_DATASOURCE_BY_TYPE_ERROR.getMsg(),e); - return error(Status.QUERY_DATASOURCE_BY_TYPE_ERROR.getCode(),QUERY_DATASOURCE_BY_TYPE_ERROR.getMsg()); - } + @RequestParam("type") UdfType type) { + logger.info("query datasource list, user:{}, type:{}", loginUser.getUserName(), type); + Map result = udfFuncService.queryResourceList(loginUser, type.ordinal()); + return returnDataList(result); } /** * verify udf function name can use or not * * @param loginUser login user - * @param name name + * @param name name * @return true if the name can user, otherwise return false */ - @ApiOperation(value = "verifyUdfFuncName", notes= "VERIFY_UDF_FUNCTION_NAME_NOTES") + @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") @ResponseStatus(HttpStatus.OK) + @ApiException(VERIFY_UDF_FUNCTION_NAME_ERROR) public Result verifyUdfFuncName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value ="name") String name + @RequestParam(value = "name") String name ) { logger.info("login user {}, verfiy udf function name: {}", - loginUser.getUserName(),name); + loginUser.getUserName(), name); - try{ - - return udfFuncService.verifyUdfFuncByName(name); - }catch (Exception e){ - logger.error(VERIFY_UDF_FUNCTION_NAME_ERROR.getMsg(),e); - return error(Status.VERIFY_UDF_FUNCTION_NAME_ERROR.getCode(), Status.VERIFY_UDF_FUNCTION_NAME_ERROR.getMsg()); - } + return udfFuncService.verifyUdfFuncByName(name); } /** @@ -715,48 +637,39 @@ public class ResourcesController extends BaseController{ * @param udfFuncId udf function id * @return delete result code */ - @ApiOperation(value = "deleteUdfFunc", notes= "DELETE_UDF_FUNCTION_NOTES") + @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 = "RESOURCE_ID", required = true, dataType = "Int", example = "100") }) @GetMapping(value = "/udf-func/delete") @ResponseStatus(HttpStatus.OK) + @ApiException(DELETE_UDF_FUNCTION_ERROR) public Result deleteUdfFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value ="id") int udfFuncId + @RequestParam(value = "id") int udfFuncId ) { - try{ - - logger.info("login user {}, delete udf function id: {}", loginUser.getUserName(),udfFuncId); - return udfFuncService.delete(udfFuncId); - }catch (Exception e){ - logger.error(DELETE_UDF_FUNCTION_ERROR.getMsg(),e); - return error(Status.DELETE_UDF_FUNCTION_ERROR.getCode(), Status.DELETE_UDF_FUNCTION_ERROR.getMsg()); - } + logger.info("login user {}, delete udf function id: {}", loginUser.getUserName(), udfFuncId); + return udfFuncService.delete(udfFuncId); } /** * authorized file resource list * * @param loginUser login user - * @param userId user id + * @param userId user id * @return authorized result */ - @ApiOperation(value = "authorizedFile", notes= "AUTHORIZED_FILE_NOTES") + @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) + @ApiException(AUTHORIZED_FILE_RESOURCE_ERROR) public Result authorizedFile(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("userId") Integer userId) { - try{ - logger.info("authorized file resource, user: {}, user id:{}", loginUser.getUserName(), userId); - Map result = resourceService.authorizedFile(loginUser, userId); - return returnDataList(result); - }catch (Exception e){ - logger.error(AUTHORIZED_FILE_RESOURCE_ERROR.getMsg(),e); - return error(Status.AUTHORIZED_FILE_RESOURCE_ERROR.getCode(), Status.AUTHORIZED_FILE_RESOURCE_ERROR.getMsg()); - } + logger.info("authorized file resource, user: {}, user id:{}", loginUser.getUserName(), userId); + Map result = resourceService.authorizedFile(loginUser, userId); + return returnDataList(result); } @@ -764,25 +677,21 @@ public class ResourcesController extends BaseController{ * unauthorized file resource list * * @param loginUser login user - * @param userId user id + * @param userId user id * @return unauthorized result code */ - @ApiOperation(value = "authorizeResourceTree", notes= "AUTHORIZE_RESOURCE_TREE_NOTES") + @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") @ResponseStatus(HttpStatus.CREATED) + @ApiException(AUTHORIZE_RESOURCE_TREE) public Result authorizeResourceTree(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("userId") Integer userId) { - try{ - logger.info("all resource file, user:{}, user id:{}", loginUser.getUserName(), userId); - Map result = resourceService.authorizeResourceTree(loginUser, userId); - return returnDataList(result); - }catch (Exception e){ - logger.error(AUTHORIZE_RESOURCE_TREE.getMsg(),e); - return error(Status.AUTHORIZE_RESOURCE_TREE.getCode(), Status.AUTHORIZE_RESOURCE_TREE.getMsg()); - } + @RequestParam("userId") Integer userId) { + logger.info("all resource file, user:{}, user id:{}", loginUser.getUserName(), userId); + Map result = resourceService.authorizeResourceTree(loginUser, userId); + return returnDataList(result); } @@ -790,26 +699,22 @@ public class ResourcesController extends BaseController{ * unauthorized udf function * * @param loginUser login user - * @param userId user id + * @param userId user id * @return unauthorized result code */ - @ApiOperation(value = "unauthUDFFunc", notes= "UNAUTHORIZED_UDF_FUNC_NOTES") + @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) + @ApiException(UNAUTHORIZED_UDF_FUNCTION_ERROR) public Result unauthUDFFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("userId") Integer userId) { - try{ - logger.info("unauthorized udf function, login user:{}, unauthorized user id:{}", loginUser.getUserName(), userId); - - Map result = resourceService.unauthorizedUDFFunction(loginUser, userId); - return returnDataList(result); - }catch (Exception e){ - logger.error(UNAUTHORIZED_UDF_FUNCTION_ERROR.getMsg(),e); - return error(Status.UNAUTHORIZED_UDF_FUNCTION_ERROR.getCode(), Status.UNAUTHORIZED_UDF_FUNCTION_ERROR.getMsg()); - } + logger.info("unauthorized udf function, login user:{}, unauthorized user id:{}", loginUser.getUserName(), userId); + + Map result = resourceService.unauthorizedUDFFunction(loginUser, userId); + return returnDataList(result); } @@ -817,24 +722,20 @@ public class ResourcesController extends BaseController{ * authorized udf function * * @param loginUser login user - * @param userId user id + * @param userId user id * @return authorized result code */ - @ApiOperation(value = "authUDFFunc", notes= "AUTHORIZED_UDF_FUNC_NOTES") + @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) + @ApiException(AUTHORIZED_UDF_FUNCTION_ERROR) public Result authorizedUDFFunction(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("userId") Integer userId) { - try{ - logger.info("auth udf function, login user:{}, auth user id:{}", loginUser.getUserName(), userId); - Map result = resourceService.authorizedUDFFunction(loginUser, userId); - return returnDataList(result); - }catch (Exception e){ - logger.error(AUTHORIZED_UDF_FUNCTION_ERROR.getMsg(),e); - return error(Status.AUTHORIZED_UDF_FUNCTION_ERROR.getCode(), Status.AUTHORIZED_UDF_FUNCTION_ERROR.getMsg()); - } + logger.info("auth udf function, login user:{}, auth user id:{}", loginUser.getUserName(), userId); + Map result = resourceService.authorizedUDFFunction(loginUser, userId); + return returnDataList(result); } } \ No newline at end of file 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 90b4bca81b..a9a5514027 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 @@ -17,7 +17,7 @@ package org.apache.dolphinscheduler.api.controller; -import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.SchedulerService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.enums.FailureStrategy; @@ -34,6 +34,7 @@ import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; +import java.io.IOException; import java.util.Map; import static org.apache.dolphinscheduler.api.enums.Status.*; @@ -60,33 +61,34 @@ public class SchedulerController extends BaseController { /** * create schedule * - * @param loginUser login user - * @param projectName project name - * @param processDefinitionId process definition id - * @param schedule scheduler - * @param warningType warning type - * @param warningGroupId warning group id - * @param failureStrategy failure strategy + * @param loginUser login user + * @param projectName project name + * @param processDefinitionId process definition id + * @param schedule scheduler + * @param warningType warning type + * @param warningGroupId warning group id + * @param failureStrategy failure strategy * @param processInstancePriority process instance priority - * @param receivers receivers - * @param receiversCc receivers cc - * @param workerGroup worker group + * @param receivers receivers + * @param receiversCc receivers cc + * @param workerGroup worker group * @return create result code */ - @ApiOperation(value = "createSchedule", notes= "CREATE_SCHEDULE_NOTES") + @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", 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 = "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 = "receivers", value = "RECEIVERS", type ="String"), - @ApiImplicitParam(name = "receiversCc", value = "RECEIVERS_CC", type ="String"), + @ApiImplicitParam(name = "failureStrategy", value = "FAILURE_STRATEGY", type = "FailureStrategy"), + @ApiImplicitParam(name = "receivers", value = "RECEIVERS", type = "String"), + @ApiImplicitParam(name = "receiversCc", value = "RECEIVERS_CC", type = "String"), @ApiImplicitParam(name = "workerGroupId", value = "WORKER_GROUP_ID", dataType = "Int", example = "100"), - @ApiImplicitParam(name = "processInstancePriority", value = "PROCESS_INSTANCE_PRIORITY", type ="Priority"), + @ApiImplicitParam(name = "processInstancePriority", value = "PROCESS_INSTANCE_PRIORITY", type = "Priority"), }) @PostMapping("/create") @ResponseStatus(HttpStatus.CREATED) + @ApiException(CREATE_SCHEDULE_ERROR) 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, @@ -97,51 +99,47 @@ public class SchedulerController extends BaseController { @RequestParam(value = "receivers", required = false) String receivers, @RequestParam(value = "receiversCc", required = false) String receiversCc, @RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, - @RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority) { + @RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority) throws IOException { logger.info("login user {}, project name: {}, process name: {}, create schedule: {}, warning type: {}, warning group id: {}," + "failure policy: {},receivers : {},receiversCc : {},processInstancePriority : {}, workGroupId:{}", loginUser.getUserName(), projectName, processDefinitionId, schedule, warningType, warningGroupId, failureStrategy, receivers, receiversCc, processInstancePriority, workerGroup); - try { - Map result = schedulerService.insertSchedule(loginUser, projectName, processDefinitionId, schedule, - warningType, warningGroupId, failureStrategy, receivers, receiversCc, processInstancePriority, workerGroup); + Map result = schedulerService.insertSchedule(loginUser, projectName, processDefinitionId, schedule, + warningType, warningGroupId, failureStrategy, receivers, receiversCc, processInstancePriority, workerGroup); - return returnDataList(result); - } catch (Exception e) { - logger.error(CREATE_SCHEDULE_ERROR.getMsg(), e); - return error(CREATE_SCHEDULE_ERROR.getCode(), CREATE_SCHEDULE_ERROR.getMsg()); - } + return returnDataList(result); } /** * updateProcessInstance schedule * - * @param loginUser login user - * @param projectName project name - * @param id scheduler id - * @param schedule scheduler - * @param warningType warning type - * @param warningGroupId warning group id - * @param failureStrategy failure strategy - * @param receivers receivers - * @param workerGroup worker group + * @param loginUser login user + * @param projectName project name + * @param id scheduler id + * @param schedule scheduler + * @param warningType warning type + * @param warningGroupId warning group id + * @param failureStrategy failure strategy + * @param receivers receivers + * @param workerGroup worker group * @param processInstancePriority process instance priority - * @param receiversCc receivers cc + * @param receiversCc receivers cc * @return update result code */ - @ApiOperation(value = "updateSchedule", notes= "UPDATE_SCHEDULE_NOTES") + @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", 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 = "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 = "receivers", value = "RECEIVERS", type ="String"), - @ApiImplicitParam(name = "receiversCc", value = "RECEIVERS_CC", type ="String"), + @ApiImplicitParam(name = "failureStrategy", value = "FAILURE_STRATEGY", type = "FailureStrategy"), + @ApiImplicitParam(name = "receivers", value = "RECEIVERS", type = "String"), + @ApiImplicitParam(name = "receiversCc", value = "RECEIVERS_CC", type = "String"), @ApiImplicitParam(name = "workerGroupId", value = "WORKER_GROUP_ID", dataType = "Int", example = "100"), - @ApiImplicitParam(name = "processInstancePriority", value = "PROCESS_INSTANCE_PRIORITY", type ="Priority"), + @ApiImplicitParam(name = "processInstancePriority", value = "PROCESS_INSTANCE_PRIORITY", type = "Priority"), }) @PostMapping("/update") + @ApiException(UPDATE_SCHEDULE_ERROR) 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, @@ -152,195 +150,163 @@ public class SchedulerController extends BaseController { @RequestParam(value = "receivers", required = false) String receivers, @RequestParam(value = "receiversCc", required = false) String receiversCc, @RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, - @RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority) { + @RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority) throws IOException { logger.info("login user {}, project name: {},id: {}, updateProcessInstance schedule: {}, notify type: {}, notify mails: {}, " + "failure policy: {},receivers : {},receiversCc : {},processInstancePriority : {},workerGroupId:{}", loginUser.getUserName(), projectName, id, schedule, warningType, warningGroupId, failureStrategy, receivers, receiversCc, processInstancePriority, workerGroup); - try { - Map result = schedulerService.updateSchedule(loginUser, projectName, id, schedule, - warningType, warningGroupId, failureStrategy, receivers, receiversCc, null, processInstancePriority, workerGroup); - return returnDataList(result); - - } catch (Exception e) { - logger.error(UPDATE_SCHEDULE_ERROR.getMsg(), e); - return error(Status.UPDATE_SCHEDULE_ERROR.getCode(), Status.UPDATE_SCHEDULE_ERROR.getMsg()); - } + Map result = schedulerService.updateSchedule(loginUser, projectName, id, schedule, + warningType, warningGroupId, failureStrategy, receivers, receiversCc, null, processInstancePriority, workerGroup); + return returnDataList(result); } /** * publish schedule setScheduleState * - * @param loginUser login user + * @param loginUser login user * @param projectName project name - * @param id scheduler id + * @param id scheduler id * @return publish result code */ - @ApiOperation(value = "online", notes= "ONLINE_SCHEDULE_NOTES") + @ApiOperation(value = "online", notes = "ONLINE_SCHEDULE_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "SCHEDULE_ID", required = true, dataType = "Int", example = "100") }) @PostMapping("/online") + @ApiException(PUBLISH_SCHEDULE_ONLINE_ERROR) public Result online(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable("projectName") String projectName, @RequestParam("id") Integer id) { logger.info("login user {}, schedule setScheduleState, project name: {}, id: {}", loginUser.getUserName(), projectName, id); - try { - Map result = schedulerService.setScheduleState(loginUser, projectName, id, ReleaseState.ONLINE); - return returnDataList(result); - - } catch (Exception e) { - logger.error(PUBLISH_SCHEDULE_ONLINE_ERROR.getMsg(), e); - return error(Status.PUBLISH_SCHEDULE_ONLINE_ERROR.getCode(), Status.PUBLISH_SCHEDULE_ONLINE_ERROR.getMsg()); - } + Map result = schedulerService.setScheduleState(loginUser, projectName, id, ReleaseState.ONLINE); + return returnDataList(result); } /** * offline schedule * - * @param loginUser login user + * @param loginUser login user * @param projectName project name - * @param id schedule id + * @param id schedule id * @return operation result code */ - @ApiOperation(value = "offline", notes= "OFFLINE_SCHEDULE_NOTES") + @ApiOperation(value = "offline", notes = "OFFLINE_SCHEDULE_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "SCHEDULE_ID", required = true, dataType = "Int", example = "100") }) @PostMapping("/offline") + @ApiException(OFFLINE_SCHEDULE_ERROR) public Result offline(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable("projectName") String projectName, @RequestParam("id") Integer id) { logger.info("login user {}, schedule offline, project name: {}, process definition id: {}", loginUser.getUserName(), projectName, id); - try { - Map result = schedulerService.setScheduleState(loginUser, projectName, id, ReleaseState.OFFLINE); - return returnDataList(result); - - } catch (Exception e) { - logger.error(OFFLINE_SCHEDULE_ERROR.getMsg(), e); - return error(Status.OFFLINE_SCHEDULE_ERROR.getCode(), Status.OFFLINE_SCHEDULE_ERROR.getMsg()); - } + Map result = schedulerService.setScheduleState(loginUser, projectName, id, ReleaseState.OFFLINE); + return returnDataList(result); } /** * query schedule list paging * - * @param loginUser login user - * @param projectName project name + * @param loginUser login user + * @param projectName project name * @param processDefinitionId process definition id - * @param pageNo page number - * @param pageSize page size - * @param searchVal search value + * @param pageNo page number + * @param pageSize page size + * @param searchVal search value * @return schedule list page */ - @ApiOperation(value = "queryScheduleListPaging", notes= "QUERY_SCHEDULE_LIST_PAGING_NOTES") + @ApiOperation(value = "queryScheduleListPaging", notes = "QUERY_SCHEDULE_LIST_PAGING_NOTES") @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", dataType = "Int", example = "100"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "100") + @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", dataType = "Int", example = "100"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "100") }) - @GetMapping("/list-paging") + @GetMapping("/list-paging") + @ApiException(QUERY_SCHEDULE_LIST_PAGING_ERROR) public Result queryScheduleListPaging(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam Integer processDefinitionId, @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) { - logger.info("login user {}, query schedule, project name: {}, process definition id: {}", - loginUser.getUserName(), projectName, processDefinitionId); - try { - searchVal = ParameterUtils.handleEscapes(searchVal); - Map result = schedulerService.querySchedule(loginUser, projectName, processDefinitionId, searchVal, pageNo, pageSize); - return returnDataListPaging(result); - }catch (Exception e){ - logger.error(QUERY_SCHEDULE_LIST_PAGING_ERROR.getMsg(),e); - return error(Status.QUERY_SCHEDULE_LIST_PAGING_ERROR.getCode(), Status.QUERY_SCHEDULE_LIST_PAGING_ERROR.getMsg()); - } - + logger.info("login user {}, query schedule, project name: {}, process definition id: {}", + loginUser.getUserName(), projectName, processDefinitionId); + searchVal = ParameterUtils.handleEscapes(searchVal); + Map result = schedulerService.querySchedule(loginUser, projectName, processDefinitionId, searchVal, pageNo, pageSize); + return returnDataListPaging(result); } /** * delete schedule by id * - * @param loginUser login user + * @param loginUser login user * @param projectName project name - * @param scheduleId scheule id + * @param scheduleId scheule id * @return delete result code */ - @ApiOperation(value = "deleteScheduleById", notes= "OFFLINE_SCHEDULE_NOTES") + @ApiOperation(value = "deleteScheduleById", notes = "OFFLINE_SCHEDULE_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "scheduleId", value = "SCHEDULE_ID", required = true, dataType = "Int", example = "100") }) - @GetMapping(value="/delete") + @GetMapping(value = "/delete") @ResponseStatus(HttpStatus.OK) + @ApiException(DELETE_SCHEDULE_CRON_BY_ID_ERROR) public Result deleteScheduleById(@RequestAttribute(value = SESSION_USER) User loginUser, - @PathVariable String projectName, - @RequestParam("scheduleId") Integer scheduleId - ){ - try{ - logger.info("delete schedule by id, login user:{}, project name:{}, schedule id:{}", - loginUser.getUserName(), projectName, scheduleId); - Map result = schedulerService.deleteScheduleById(loginUser, projectName, scheduleId); - return returnDataList(result); - }catch (Exception e){ - logger.error(DELETE_SCHEDULE_CRON_BY_ID_ERROR.getMsg(),e); - return error(Status.DELETE_SCHEDULE_CRON_BY_ID_ERROR.getCode(), Status.DELETE_SCHEDULE_CRON_BY_ID_ERROR.getMsg()); - } + @PathVariable String projectName, + @RequestParam("scheduleId") Integer scheduleId + ) { + logger.info("delete schedule by id, login user:{}, project name:{}, schedule id:{}", + loginUser.getUserName(), projectName, scheduleId); + Map result = schedulerService.deleteScheduleById(loginUser, projectName, scheduleId); + return returnDataList(result); } + /** * query schedule list * - * @param loginUser login user + * @param loginUser login user * @param projectName project name * @return schedule list */ - @ApiOperation(value = "queryScheduleList", notes= "QUERY_SCHEDULE_LIST_NOTES") + @ApiOperation(value = "queryScheduleList", notes = "QUERY_SCHEDULE_LIST_NOTES") @PostMapping("/list") + @ApiException(QUERY_SCHEDULE_LIST_ERROR) public Result queryScheduleList(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName) { - try { - logger.info("login user {}, query schedule list, project name: {}", - loginUser.getUserName(), projectName); - Map result = schedulerService.queryScheduleList(loginUser, projectName); - return returnDataList(result); - } catch (Exception e) { - logger.error(QUERY_SCHEDULE_LIST_ERROR.getMsg(), e); - return error(Status.QUERY_SCHEDULE_LIST_ERROR.getCode(), Status.QUERY_SCHEDULE_LIST_ERROR.getMsg()); - } + logger.info("login user {}, query schedule list, project name: {}", + loginUser.getUserName(), projectName); + Map result = schedulerService.queryScheduleList(loginUser, projectName); + return returnDataList(result); } /** * preview schedule * - * @param loginUser login user + * @param loginUser login user * @param projectName project name - * @param schedule schedule expression + * @param schedule schedule expression * @return the next five fire time */ - @ApiOperation(value = "previewSchedule", notes= "PREVIEW_SCHEDULE_NOTES") + @ApiOperation(value = "previewSchedule", notes = "PREVIEW_SCHEDULE_NOTES") @ApiImplicitParams({ @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) 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 - ){ + @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, + @RequestParam(value = "schedule") String schedule + ) { logger.info("login user {}, project name: {}, preview schedule: {}", loginUser.getUserName(), projectName, schedule); - try { - Map result = schedulerService.previewSchedule(loginUser, projectName, schedule); - return returnDataList(result); - } catch (Exception e) { - logger.error(PREVIEW_SCHEDULE_ERROR.getMsg(), e); - return error(PREVIEW_SCHEDULE_ERROR.getCode(), PREVIEW_SCHEDULE_ERROR.getMsg()); - } + Map result = schedulerService.previewSchedule(loginUser, projectName, schedule); + 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 276d2ff7da..c0ad88f481 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 @@ -17,6 +17,7 @@ package org.apache.dolphinscheduler.api.controller; +import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.TaskInstanceService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; @@ -24,7 +25,6 @@ import org.apache.dolphinscheduler.common.enums.ExecutionStatus; import org.apache.dolphinscheduler.common.utils.ParameterUtils; import org.apache.dolphinscheduler.dao.entity.User; import io.swagger.annotations.*; -import org.apache.dolphinscheduler.api.enums.Status; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -34,13 +34,15 @@ import springfox.documentation.annotations.ApiIgnore; import java.util.Map; +import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_LIST_PAGING_ERROR; + /** * task instance controller */ @Api(tags = "TASK_INSTANCE_TAG", position = 11) @RestController @RequestMapping("/projects/{projectName}/task-instance") -public class TaskInstanceController extends BaseController{ +public class TaskInstanceController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(TaskInstanceController.class); @@ -51,34 +53,35 @@ public class TaskInstanceController extends BaseController{ /** * query task list paging * - * @param loginUser login user - * @param projectName project name + * @param loginUser login user + * @param projectName project name * @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") + @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 = "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 = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = false, dataType = "Int", example = "100"), + @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", dataType = "Int", example = "1"), @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20") }) @GetMapping("/list-paging") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_TASK_LIST_PAGING_ERROR) public Result queryTaskListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "processInstanceId", required = false, defaultValue = "0") Integer processInstanceId, @@ -90,20 +93,14 @@ public class TaskInstanceController extends BaseController{ @RequestParam(value = "startDate", required = false) String startTime, @RequestParam(value = "endDate", required = false) String endTime, @RequestParam("pageNo") Integer pageNo, - @RequestParam("pageSize") Integer pageSize){ - - try{ - logger.info("query task instance list, project name:{},process instance:{}, search value:{},task name:{}, executor name: {},state type:{}, host:{}, start:{}, end:{}", - projectName, processInstanceId, searchVal, taskName, executorName, stateType, host, startTime, endTime); - searchVal = ParameterUtils.handleEscapes(searchVal); - Map result = taskInstanceService.queryTaskListPaging( - loginUser, projectName, processInstanceId, taskName, executorName, startTime, endTime, searchVal, stateType, host, pageNo, pageSize); - return returnDataListPaging(result); - }catch (Exception e){ - logger.error(Status.QUERY_TASK_LIST_PAGING_ERROR.getMsg(),e); - return error(Status.QUERY_TASK_LIST_PAGING_ERROR.getCode(), Status.QUERY_TASK_LIST_PAGING_ERROR.getMsg()); - } + @RequestParam("pageSize") Integer pageSize) { + logger.info("query task instance list, project name:{},process instance:{}, search value:{},task name:{}, executor name: {},state type:{}, host:{}, start:{}, end:{}", + projectName, processInstanceId, searchVal, taskName, executorName, stateType, host, startTime, endTime); + searchVal = ParameterUtils.handleEscapes(searchVal); + Map result = taskInstanceService.queryTaskListPaging( + loginUser, projectName, processInstanceId, taskName, executorName, startTime, endTime, searchVal, stateType, host, pageNo, pageSize); + return returnDataListPaging(result); } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskRecordController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskRecordController.java index 64121c26dd..e20c845d42 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskRecordController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskRecordController.java @@ -17,11 +17,11 @@ package org.apache.dolphinscheduler.api.controller; +import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.TaskRecordService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.dolphinscheduler.api.enums.Status; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -31,13 +31,15 @@ import springfox.documentation.annotations.ApiIgnore; import java.util.Map; +import static org.apache.dolphinscheduler.api.enums.Status.*; + /** * data quality controller */ @ApiIgnore @RestController @RequestMapping("/projects/task-record") -public class TaskRecordController extends BaseController{ +public class TaskRecordController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(TaskRecordController.class); @@ -49,20 +51,21 @@ public class TaskRecordController extends BaseController{ /** * query task record list page * - * @param loginUser login user - * @param taskName task name - * @param state state + * @param loginUser login user + * @param taskName task name + * @param state state * @param sourceTable source table - * @param destTable destination table - * @param taskDate task date - * @param startTime start time - * @param endTime end time - * @param pageNo page numbere - * @param pageSize page size + * @param destTable destination table + * @param taskDate task date + * @param startTime start time + * @param endTime end time + * @param pageNo page numbere + * @param pageSize page size * @return task record list */ @GetMapping("/list-paging") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_TASK_RECORD_LIST_PAGING_ERROR) public Result queryTaskRecordListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(value = "taskName", required = false) String taskName, @RequestParam(value = "state", required = false) String state, @@ -73,59 +76,48 @@ public class TaskRecordController extends BaseController{ @RequestParam(value = "endDate", required = false) String endTime, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize - ){ + ) { - try{ logger.info("query task record list, task name:{}, state :{}, taskDate: {}, start:{}, end:{}", - taskName, state, taskDate, startTime, endTime); - Map result = taskRecordService.queryTaskRecordListPaging(false, taskName, startTime, taskDate, sourceTable, destTable, endTime,state, pageNo, pageSize); + taskName, state, taskDate, startTime, endTime); + Map result = taskRecordService.queryTaskRecordListPaging(false, taskName, startTime, taskDate, sourceTable, destTable, endTime, state, pageNo, pageSize); return returnDataListPaging(result); - }catch (Exception e){ - logger.error(Status.QUERY_TASK_RECORD_LIST_PAGING_ERROR.getMsg(),e); - return error(Status.QUERY_TASK_RECORD_LIST_PAGING_ERROR.getCode(), Status.QUERY_TASK_RECORD_LIST_PAGING_ERROR.getMsg()); - } - } /** * query history task record list paging * - * @param loginUser login user - * @param taskName task name - * @param state state + * @param loginUser login user + * @param taskName task name + * @param state state * @param sourceTable source table - * @param destTable destination table - * @param taskDate task date - * @param startTime start time - * @param endTime end time - * @param pageNo page number - * @param pageSize page size + * @param destTable destination table + * @param taskDate task date + * @param startTime start time + * @param endTime end time + * @param pageNo page number + * @param pageSize page size * @return history task record list */ @GetMapping("/history-list-paging") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_TASK_RECORD_LIST_PAGING_ERROR) public Result queryHistoryTaskRecordListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "taskName", required = false) String taskName, - @RequestParam(value = "state", required = false) String state, - @RequestParam(value = "sourceTable", required = false) String sourceTable, - @RequestParam(value = "destTable", required = false) String destTable, - @RequestParam(value = "taskDate", required = false) String taskDate, - @RequestParam(value = "startDate", required = false) String startTime, - @RequestParam(value = "endDate", required = false) String endTime, - @RequestParam("pageNo") Integer pageNo, - @RequestParam("pageSize") Integer pageSize - ){ - - try{ - logger.info("query hisotry task record list, task name:{}, state :{}, taskDate: {}, start:{}, end:{}", - taskName, state, taskDate, startTime, endTime); - Map result = taskRecordService.queryTaskRecordListPaging(true, taskName, startTime, taskDate, sourceTable, destTable, endTime,state, pageNo, pageSize); - return returnDataListPaging(result); - }catch (Exception e){ - logger.error(Status.QUERY_TASK_RECORD_LIST_PAGING_ERROR.getMsg(),e); - return error(Status.QUERY_TASK_RECORD_LIST_PAGING_ERROR.getCode(), Status.QUERY_TASK_RECORD_LIST_PAGING_ERROR.getMsg()); - } + @RequestParam(value = "taskName", required = false) String taskName, + @RequestParam(value = "state", required = false) String state, + @RequestParam(value = "sourceTable", required = false) String sourceTable, + @RequestParam(value = "destTable", required = false) String destTable, + @RequestParam(value = "taskDate", required = false) String taskDate, + @RequestParam(value = "startDate", required = false) String startTime, + @RequestParam(value = "endDate", required = false) String endTime, + @RequestParam("pageNo") Integer pageNo, + @RequestParam("pageSize") Integer pageSize + ) { + logger.info("query hisotry task record list, task name:{}, state :{}, taskDate: {}, start:{}, end:{}", + taskName, state, taskDate, startTime, endTime); + Map result = taskRecordService.queryTaskRecordListPaging(true, taskName, startTime, taskDate, sourceTable, destTable, endTime, state, pageNo, pageSize); + return returnDataListPaging(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 afdb80bd2c..a603ac050c 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 @@ -18,6 +18,7 @@ package org.apache.dolphinscheduler.api.controller; import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.TenantService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; @@ -36,6 +37,8 @@ import springfox.documentation.annotations.ApiIgnore; import java.util.Map; +import static org.apache.dolphinscheduler.api.enums.Status.*; + /** * tenant controller @@ -43,7 +46,7 @@ import java.util.Map; @Api(tags = "TENANT_TAG", position = 1) @RestController @RequestMapping("/tenant") -public class TenantController extends BaseController{ +public class TenantController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(TenantController.class); @@ -54,38 +57,33 @@ public class TenantController extends BaseController{ /** * create tenant * - * @param loginUser login user - * @param tenantCode tenant code - * @param tenantName tenant name - * @param queueId queue id + * @param loginUser login user + * @param tenantCode tenant code + * @param tenantName tenant name + * @param queueId queue id * @param description description * @return create result code */ - @ApiOperation(value = "createTenant", notes= "CREATE_TENANT_NOTES") + @ApiOperation(value = "createTenant", notes = "CREATE_TENANT_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "tenantCode", value = "TENANT_CODE", required = true, dataType = "String"), - @ApiImplicitParam(name = "tenantName", value = "TENANT_NAME", 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 = "tenantName", value = "TENANT_NAME", 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") @ResponseStatus(HttpStatus.CREATED) + @ApiException(CREATE_TENANT_ERROR) public Result createTenant(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "tenantCode") String tenantCode, - @RequestParam(value = "tenantName") String tenantName, - @RequestParam(value = "queueId") int queueId, - @RequestParam(value = "description",required = false) String description) { + @RequestParam(value = "tenantCode") String tenantCode, + @RequestParam(value = "tenantName") String tenantName, + @RequestParam(value = "queueId") int queueId, + @RequestParam(value = "description", required = false) String description) throws Exception { logger.info("login user {}, create tenant, tenantCode: {}, tenantName: {}, queueId: {}, desc: {}", - loginUser.getUserName(), tenantCode, tenantName, queueId,description); - try { - Map result = tenantService.createTenant(loginUser,tenantCode,tenantName,queueId,description); - return returnDataList(result); - - }catch (Exception e){ - logger.error(Status.CREATE_TENANT_ERROR.getMsg(),e); - return error(Status.CREATE_TENANT_ERROR.getCode(), Status.CREATE_TENANT_ERROR.getMsg()); - } + loginUser.getUserName(), tenantCode, tenantName, queueId, description); + Map result = tenantService.createTenant(loginUser, tenantCode, tenantName, queueId, description); + return returnDataList(result); } @@ -94,36 +92,32 @@ public class TenantController 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 tenant list page */ - @ApiOperation(value = "queryTenantlistPaging", notes= "QUERY_TENANT_LIST_PAGING_NOTES") + @ApiOperation(value = "queryTenantlistPaging", notes = "QUERY_TENANT_LIST_PAGING_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType ="String"), + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", dataType = "String"), @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType ="Int",example = "20") + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20") }) - @GetMapping(value="/list-paging") + @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_TENANT_LIST_PAGING_ERROR) public Result queryTenantlistPaging(@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) { logger.info("login user {}, list paging, pageNo: {}, searchVal: {}, pageSize: {}", - loginUser.getUserName(),pageNo,searchVal,pageSize); - try{ - Map result = checkPageParams(pageNo, pageSize); - if(result.get(Constants.STATUS) != Status.SUCCESS){ - return returnDataListPaging(result); - } - searchVal = ParameterUtils.handleEscapes(searchVal); - result = tenantService.queryTenantList(loginUser, searchVal, pageNo, pageSize); + loginUser.getUserName(), pageNo, searchVal, pageSize); + Map result = checkPageParams(pageNo, pageSize); + if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); - }catch (Exception e){ - logger.error(Status.QUERY_TENANT_LIST_PAGING_ERROR.getMsg(),e); - return error(Status.QUERY_TENANT_LIST_PAGING_ERROR.getCode(), Status.QUERY_TENANT_LIST_PAGING_ERROR.getMsg()); } + searchVal = ParameterUtils.handleEscapes(searchVal); + result = tenantService.queryTenantList(loginUser, searchVal, pageNo, pageSize); + return returnDataListPaging(result); } @@ -133,113 +127,95 @@ public class TenantController extends BaseController{ * @param loginUser login user * @return tenant list */ - @ApiOperation(value = "queryTenantlist", notes= "QUERY_TENANT_LIST_NOTES") - @GetMapping(value="/list") + @ApiOperation(value = "queryTenantlist", notes = "QUERY_TENANT_LIST_NOTES") + @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) - public Result queryTenantlist(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser){ + @ApiException(QUERY_TENANT_LIST_ERROR) + public Result queryTenantlist(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { logger.info("login user {}, query tenant list", loginUser.getUserName()); - try{ - Map result = tenantService.queryTenantList(loginUser); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.QUERY_TENANT_LIST_ERROR.getMsg(),e); - return error(Status.QUERY_TENANT_LIST_ERROR.getCode(), Status.QUERY_TENANT_LIST_ERROR.getMsg()); - } + Map result = tenantService.queryTenantList(loginUser); + return returnDataList(result); } - /** * udpate tenant * - * @param loginUser login user - * @param id tennat id - * @param tenantCode tennat code - * @param tenantName tennat name - * @param queueId queue id + * @param loginUser login user + * @param id tennat id + * @param tenantCode tennat code + * @param tenantName tennat name + * @param queueId queue id * @param description description * @return update result code */ - @ApiOperation(value = "updateTenant", notes= "UPDATE_TENANT_NOTES") + @ApiOperation(value = "updateTenant", notes = "UPDATE_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"), @ApiImplicitParam(name = "tenantCode", value = "TENANT_CODE", required = true, dataType = "String"), - @ApiImplicitParam(name = "tenantName", value = "TENANT_NAME", 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 = "tenantName", value = "TENANT_NAME", 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") @ResponseStatus(HttpStatus.OK) + @ApiException(UPDATE_TENANT_ERROR) public Result updateTenant(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int id, - @RequestParam(value = "tenantCode") String tenantCode, - @RequestParam(value = "tenantName") String tenantName, - @RequestParam(value = "queueId") int queueId, - @RequestParam(value = "description",required = false) String description) { + @RequestParam(value = "id") int id, + @RequestParam(value = "tenantCode") String tenantCode, + @RequestParam(value = "tenantName") String tenantName, + @RequestParam(value = "queueId") int queueId, + @RequestParam(value = "description", required = false) String description) throws Exception { logger.info("login user {}, updateProcessInstance tenant, tenantCode: {}, tenantName: {}, queueId: {}, description: {}", - loginUser.getUserName(), tenantCode, tenantName, queueId,description); - try { - Map result = tenantService.updateTenant(loginUser,id,tenantCode, tenantName, queueId, description); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.UPDATE_TENANT_ERROR.getMsg(),e); - return error(Status.UPDATE_TENANT_ERROR.getCode(), Status.UPDATE_TENANT_ERROR.getMsg()); - } + loginUser.getUserName(), tenantCode, tenantName, queueId, description); + Map result = tenantService.updateTenant(loginUser, id, tenantCode, tenantName, queueId, description); + return returnDataList(result); } /** * delete tenant by id * * @param loginUser login user - * @param id tenant id + * @param id tenant id * @return delete result code */ - @ApiOperation(value = "deleteTenantById", notes= "DELETE_TENANT_NOTES") + @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") @ResponseStatus(HttpStatus.OK) + @ApiException(DELETE_TENANT_BY_ID_ERROR) public Result deleteTenantById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int id) { + @RequestParam(value = "id") int id) throws Exception { logger.info("login user {}, delete tenant, tenantId: {},", loginUser.getUserName(), id); - try { - Map result = tenantService.deleteTenantById(loginUser,id); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.DELETE_TENANT_BY_ID_ERROR.getMsg(),e); - return error(Status.DELETE_TENANT_BY_ID_ERROR.getCode(), Status.DELETE_TENANT_BY_ID_ERROR.getMsg()); - } + Map result = tenantService.deleteTenantById(loginUser, id); + return returnDataList(result); } /** * verify tenant code * - * @param loginUser login user + * @param loginUser login user * @param tenantCode tenant code * @return true if tenant code can user, otherwise return false */ - @ApiOperation(value = "verifyTenantCode", notes= "VERIFY_TENANT_CODE_NOTES") + @ApiOperation(value = "verifyTenantCode", notes = "VERIFY_TENANT_CODE_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "tenantCode", value = "TENANT_CODE", required = true, dataType = "String") }) @GetMapping(value = "/verify-tenant-code") @ResponseStatus(HttpStatus.OK) + @ApiException(VERIFY_TENANT_CODE_ERROR) public Result verifyTenantCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value ="tenantCode") String tenantCode + @RequestParam(value = "tenantCode") String tenantCode ) { - - try{ - logger.info("login user {}, verfiy tenant code: {}", - loginUser.getUserName(),tenantCode); - return tenantService.verifyTenantCode(tenantCode); - }catch (Exception e){ - logger.error(Status.VERIFY_TENANT_CODE_ERROR.getMsg(),e); - return error(Status.VERIFY_TENANT_CODE_ERROR.getCode(), Status.VERIFY_TENANT_CODE_ERROR.getMsg()); - } + logger.info("login user {}, verfiy tenant code: {}", + loginUser.getUserName(), tenantCode); + return tenantService.verifyTenantCode(tenantCode); } 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 42f89237ab..08d862e032 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 @@ -18,6 +18,7 @@ package org.apache.dolphinscheduler.api.controller; import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.UsersService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; @@ -36,14 +37,16 @@ import springfox.documentation.annotations.ApiIgnore; import java.util.Map; +import static org.apache.dolphinscheduler.api.enums.Status.*; + /** * user controller */ -@Api(tags = "USERS_TAG" , position = 14) +@Api(tags = "USERS_TAG", position = 14) @RestController @RequestMapping("/users") -public class UsersController extends BaseController{ +public class UsersController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(UsersController.class); @@ -52,20 +55,20 @@ 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") + @ApiOperation(value = "createUser", notes = "CREATE_USER_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userName", value = "USER_NAME",type = "String"), - @ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", type ="String"), + @ApiImplicitParam(name = "userName", value = "USER_NAME", type = "String"), + @ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", type = "String"), @ApiImplicitParam(name = "tenantId", value = "TENANT_ID", dataType = "Int", example = "100"), @ApiImplicitParam(name = "queue", value = "QUEUE", dataType = "Int", example = "100"), @ApiImplicitParam(name = "email", value = "EMAIL", dataType = "Int", example = "100"), @@ -73,81 +76,73 @@ public class UsersController extends BaseController{ }) @PostMapping(value = "/create") @ResponseStatus(HttpStatus.CREATED) + @ApiException(CREATE_USER_ERROR) public Result createUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "userName") String userName, - @RequestParam(value = "userPassword") String userPassword, - @RequestParam(value = "tenantId") int tenantId, - @RequestParam(value = "queue",required = false,defaultValue = "") String queue, - @RequestParam(value = "email") String email, - @RequestParam(value = "phone", required = false) String phone) { + @RequestParam(value = "userName") String userName, + @RequestParam(value = "userPassword") String userPassword, + @RequestParam(value = "tenantId") int tenantId, + @RequestParam(value = "queue", required = false, defaultValue = "") String queue, + @RequestParam(value = "email") String email, + @RequestParam(value = "phone", required = false) String phone) throws Exception { logger.info("login user {}, create user, userName: {}, email: {}, tenantId: {}, userPassword: {}, phone: {}, user queue: {}", - loginUser.getUserName(), userName, email, tenantId, Constants.PASSWORD_DEFAULT, phone,queue); + loginUser.getUserName(), userName, email, tenantId, Constants.PASSWORD_DEFAULT, phone, queue); - try { - Map result = usersService.createUser(loginUser, userName, userPassword,email,tenantId, phone,queue); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.CREATE_USER_ERROR.getMsg(),e); - return error(Status.CREATE_USER_ERROR.getCode(), Status.CREATE_USER_ERROR.getMsg()); - } + Map result = usersService.createUser(loginUser, userName, userPassword, email, tenantId, phone, queue); + return returnDataList(result); } /** * query user list paging * * @param loginUser login user - * @param pageNo page number + * @param pageNo page number * @param searchVal search avlue - * @param pageSize page size + * @param pageSize page size * @return user list page */ - @ApiOperation(value = "queryUserList", notes= "QUERY_USER_LIST_NOTES") + @ApiOperation(value = "queryUserList", notes = "QUERY_USER_LIST_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "pageNo", value = "PAGE_NO",dataType = "Int", example = "100"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", type ="String"), - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type ="String") + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "100"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", type = "String"), + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String") }) - @GetMapping(value="/list-paging") + @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_USER_LIST_PAGING_ERROR) public Result queryUserList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("pageNo") Integer pageNo, @RequestParam(value = "searchVal", required = false) String searchVal, - @RequestParam("pageSize") Integer pageSize){ + @RequestParam("pageSize") Integer pageSize) { logger.info("login user {}, list user paging, pageNo: {}, searchVal: {}, pageSize: {}", - loginUser.getUserName(),pageNo,searchVal,pageSize); - try{ - Map result = checkPageParams(pageNo, pageSize); - if(result.get(Constants.STATUS) != Status.SUCCESS){ - return returnDataListPaging(result); - } - searchVal = ParameterUtils.handleEscapes(searchVal); - result = usersService.queryUserList(loginUser, searchVal, pageNo, pageSize); + loginUser.getUserName(), pageNo, searchVal, pageSize); + Map result = checkPageParams(pageNo, pageSize); + if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); - }catch (Exception e){ - logger.error(Status.QUERY_USER_LIST_PAGING_ERROR.getMsg(),e); - return error(Status.QUERY_USER_LIST_PAGING_ERROR.getCode(), Status.QUERY_USER_LIST_PAGING_ERROR.getMsg()); } + searchVal = ParameterUtils.handleEscapes(searchVal); + result = usersService.queryUserList(loginUser, searchVal, pageNo, pageSize); + return returnDataListPaging(result); } /** * 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 tennat 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") + @ApiOperation(value = "updateUser", notes = "UPDATE_USER_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "USER_ID",dataType = "Int", example = "100"), - @ApiImplicitParam(name = "userName", value = "USER_NAME",type = "String"), - @ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", type ="String"), + @ApiImplicitParam(name = "id", value = "USER_ID", dataType = "Int", example = "100"), + @ApiImplicitParam(name = "userName", value = "USER_NAME", type = "String"), + @ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", type = "String"), @ApiImplicitParam(name = "tenantId", value = "TENANT_ID", dataType = "Int", example = "100"), @ApiImplicitParam(name = "queue", value = "QUEUE", dataType = "Int", example = "100"), @ApiImplicitParam(name = "email", value = "EMAIL", dataType = "Int", example = "100"), @@ -155,103 +150,88 @@ public class UsersController extends BaseController{ }) @PostMapping(value = "/update") @ResponseStatus(HttpStatus.OK) + @ApiException(UPDATE_USER_ERROR) public Result updateUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int id, - @RequestParam(value = "userName") String userName, - @RequestParam(value = "userPassword") String userPassword, - @RequestParam(value = "queue",required = false,defaultValue = "") String queue, - @RequestParam(value = "email") String email, - @RequestParam(value = "tenantId") int tenantId, - @RequestParam(value = "phone", required = false) String phone) { + @RequestParam(value = "id") int id, + @RequestParam(value = "userName") String userName, + @RequestParam(value = "userPassword") String userPassword, + @RequestParam(value = "queue", required = false, defaultValue = "") String queue, + @RequestParam(value = "email") String email, + @RequestParam(value = "tenantId") int tenantId, + @RequestParam(value = "phone", required = false) String phone) throws Exception { logger.info("login user {}, updateProcessInstance user, userName: {}, email: {}, tenantId: {}, userPassword: {}, phone: {}, user queue: {}", - loginUser.getUserName(), userName, email, tenantId, Constants.PASSWORD_DEFAULT, phone,queue); - try { - Map result = usersService.updateUser(id, userName, userPassword, email, tenantId, phone, queue); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.UPDATE_USER_ERROR.getMsg(),e); - return error(Status.UPDATE_USER_ERROR.getCode(), Status.UPDATE_USER_ERROR.getMsg()); - } + loginUser.getUserName(), userName, email, tenantId, Constants.PASSWORD_DEFAULT, phone, queue); + Map result = usersService.updateUser(id, userName, userPassword, email, tenantId, phone, queue); + return returnDataList(result); } /** * 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") + @ApiOperation(value = "delUserById", notes = "DELETE_USER_BY_ID_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "USER_ID",dataType = "Int", example = "100") + @ApiImplicitParam(name = "id", value = "USER_ID", dataType = "Int", example = "100") }) @PostMapping(value = "/delete") @ResponseStatus(HttpStatus.OK) + @ApiException(DELETE_USER_BY_ID_ERROR) public Result delUserById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id") int id) { + @RequestParam(value = "id") int id) throws Exception { logger.info("login user {}, delete user, userId: {},", loginUser.getUserName(), id); - try { - Map result = usersService.deleteUserById(loginUser, id); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.DELETE_USER_BY_ID_ERROR.getMsg(),e); - return error(Status.DELETE_USER_BY_ID_ERROR.getCode(), Status.DELETE_USER_BY_ID_ERROR.getMsg()); - } + Map result = usersService.deleteUserById(loginUser, id); + return returnDataList(result); } /** * 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") + @ApiOperation(value = "grantProject", notes = "GRANT_PROJECT_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "USER_ID",dataType = "Int", example = "100"), - @ApiImplicitParam(name = "projectIds", value = "PROJECT_IDS",type = "String") + @ApiImplicitParam(name = "userId", value = "USER_ID", dataType = "Int", example = "100"), + @ApiImplicitParam(name = "projectIds", value = "PROJECT_IDS", type = "String") }) @PostMapping(value = "/grant-project") @ResponseStatus(HttpStatus.OK) + @ApiException(GRANT_PROJECT_ERROR) public Result grantProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "userId") int userId, - @RequestParam(value = "projectIds") String projectIds) { - logger.info("login user {}, grant project, userId: {},projectIds : {}", loginUser.getUserName(), userId,projectIds); - try { - Map result = usersService.grantProject(loginUser, userId, projectIds); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.GRANT_PROJECT_ERROR.getMsg(),e); - return error(Status.GRANT_PROJECT_ERROR.getCode(), Status.GRANT_PROJECT_ERROR.getMsg()); - } + @RequestParam(value = "userId") int userId, + @RequestParam(value = "projectIds") String projectIds) { + logger.info("login user {}, grant project, userId: {},projectIds : {}", loginUser.getUserName(), userId, projectIds); + Map result = usersService.grantProject(loginUser, userId, projectIds); + return returnDataList(result); } /** * 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") + @ApiOperation(value = "grantResource", notes = "GRANT_RESOURCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "USER_ID",dataType = "Int", example = "100"), - @ApiImplicitParam(name = "resourceIds", value = "RESOURCE_IDS",type = "String") + @ApiImplicitParam(name = "userId", value = "USER_ID", dataType = "Int", example = "100"), + @ApiImplicitParam(name = "resourceIds", value = "RESOURCE_IDS", type = "String") }) @PostMapping(value = "/grant-file") @ResponseStatus(HttpStatus.OK) + @ApiException(GRANT_RESOURCE_ERROR) public Result grantResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "userId") int userId, - @RequestParam(value = "resourceIds") String resourceIds) { - logger.info("login user {}, grant project, userId: {},resourceIds : {}", loginUser.getUserName(), userId,resourceIds); - try { - Map result = usersService.grantResources(loginUser, userId, resourceIds); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.GRANT_RESOURCE_ERROR.getMsg(),e); - return error(Status.GRANT_RESOURCE_ERROR.getCode(), Status.GRANT_RESOURCE_ERROR.getMsg()); - } + @RequestParam(value = "userId") int userId, + @RequestParam(value = "resourceIds") String resourceIds) { + logger.info("login user {}, grant project, userId: {},resourceIds : {}", loginUser.getUserName(), userId, resourceIds); + Map result = usersService.grantResources(loginUser, userId, resourceIds); + return returnDataList(result); } @@ -259,58 +239,49 @@ 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") + @ApiOperation(value = "grantUDFFunc", notes = "GRANT_UDF_FUNC_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "USER_ID",dataType = "Int", example = "100"), - @ApiImplicitParam(name = "udfIds", value = "UDF_IDS",type = "String") + @ApiImplicitParam(name = "userId", value = "USER_ID", dataType = "Int", example = "100"), + @ApiImplicitParam(name = "udfIds", value = "UDF_IDS", type = "String") }) @PostMapping(value = "/grant-udf-func") @ResponseStatus(HttpStatus.OK) + @ApiException(GRANT_UDF_FUNCTION_ERROR) public Result grantUDFFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "userId") int userId, - @RequestParam(value = "udfIds") String udfIds) { - logger.info("login user {}, grant project, userId: {},resourceIds : {}", loginUser.getUserName(), userId,udfIds); - try { - Map result = usersService.grantUDFFunction(loginUser, userId, udfIds); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.GRANT_UDF_FUNCTION_ERROR.getMsg(),e); - return error(Status.GRANT_UDF_FUNCTION_ERROR.getCode(), Status.GRANT_UDF_FUNCTION_ERROR.getMsg()); - } + @RequestParam(value = "userId") int userId, + @RequestParam(value = "udfIds") String udfIds) { + logger.info("login user {}, grant project, userId: {},resourceIds : {}", loginUser.getUserName(), userId, udfIds); + Map result = usersService.grantUDFFunction(loginUser, userId, udfIds); + return returnDataList(result); } - /** * grant datasource * - * @param loginUser login user - * @param userId user id - * @param datasourceIds data source id array + * @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") + @ApiOperation(value = "grantDataSource", notes = "GRANT_DATASOURCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "USER_ID",dataType = "Int", example = "100"), - @ApiImplicitParam(name = "datasourceIds", value = "DATASOURCE_IDS",type = "String") + @ApiImplicitParam(name = "userId", value = "USER_ID", dataType = "Int", example = "100"), + @ApiImplicitParam(name = "datasourceIds", value = "DATASOURCE_IDS", type = "String") }) @PostMapping(value = "/grant-datasource") @ResponseStatus(HttpStatus.OK) + @ApiException(GRANT_DATASOURCE_ERROR) public Result grantDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "userId") int userId, - @RequestParam(value = "datasourceIds") String datasourceIds) { - logger.info("login user {}, grant project, userId: {},projectIds : {}", loginUser.getUserName(),userId,datasourceIds); - try { - Map result = usersService.grantDataSource(loginUser, userId, datasourceIds); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.GRANT_DATASOURCE_ERROR.getMsg(),e); - return error(Status.GRANT_DATASOURCE_ERROR.getCode(), Status.GRANT_DATASOURCE_ERROR.getMsg()); - } + @RequestParam(value = "userId") int userId, + @RequestParam(value = "datasourceIds") String datasourceIds) { + logger.info("login user {}, grant project, userId: {},projectIds : {}", loginUser.getUserName(), userId, datasourceIds); + Map result = usersService.grantDataSource(loginUser, userId, datasourceIds); + return returnDataList(result); } @@ -320,18 +291,14 @@ public class UsersController extends BaseController{ * @param loginUser login user * @return user info */ - @ApiOperation(value = "getUserInfo", notes= "GET_USER_INFO_NOTES") - @GetMapping(value="/get-user-info") + @ApiOperation(value = "getUserInfo", notes = "GET_USER_INFO_NOTES") + @GetMapping(value = "/get-user-info") @ResponseStatus(HttpStatus.OK) - public Result getUserInfo(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser){ + @ApiException(GET_USER_INFO_ERROR) + public Result getUserInfo(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { logger.info("login user {},get user info", loginUser.getUserName()); - try{ - Map result = usersService.getUserInfo(loginUser); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.GET_USER_INFO_ERROR.getMsg(),e); - return error(Status.GET_USER_INFO_ERROR.getCode(), Status.GET_USER_INFO_ERROR.getMsg()); - } + Map result = usersService.getUserInfo(loginUser); + return returnDataList(result); } /** @@ -340,18 +307,14 @@ public class UsersController extends BaseController{ * @param loginUser login user * @return user list */ - @ApiOperation(value = "listUser", notes= "LIST_USER_NOTES") - @GetMapping(value="/list") + @ApiOperation(value = "listUser", notes = "LIST_USER_NOTES") + @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) - public Result listUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser){ + @ApiException(USER_LIST_ERROR) + public Result listUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { logger.info("login user {}, user list", loginUser.getUserName()); - try{ - Map result = usersService.queryAllGeneralUsers(loginUser); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.USER_LIST_ERROR.getMsg(),e); - return error(Status.USER_LIST_ERROR.getCode(), Status.USER_LIST_ERROR.getMsg()); - } + Map result = usersService.queryAllGeneralUsers(loginUser); + return returnDataList(result); } @@ -361,17 +324,13 @@ public class UsersController extends BaseController{ * @param loginUser login user * @return user list */ - @GetMapping(value="/list-all") + @GetMapping(value = "/list-all") @ResponseStatus(HttpStatus.OK) - public Result listAll(@RequestAttribute(value = Constants.SESSION_USER) User loginUser){ + @ApiException(USER_LIST_ERROR) + public Result listAll(@RequestAttribute(value = Constants.SESSION_USER) User loginUser) { logger.info("login user {}, user list", loginUser.getUserName()); - try{ - Map result = usersService.queryUserList(loginUser); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.USER_LIST_ERROR.getMsg(),e); - return error(Status.USER_LIST_ERROR.getCode(), Status.USER_LIST_ERROR.getMsg()); - } + Map result = usersService.queryUserList(loginUser); + return returnDataList(result); } @@ -379,79 +338,71 @@ 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") + @ApiOperation(value = "verifyUserName", notes = "VERIFY_USER_NAME_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "userName", value = "USER_NAME",type = "String") + @ApiImplicitParam(name = "userName", value = "USER_NAME", type = "String") }) @GetMapping(value = "/verify-user-name") @ResponseStatus(HttpStatus.OK) + @ApiException(VERIFY_USERNAME_ERROR) public Result verifyUserName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value ="userName") String userName + @RequestParam(value = "userName") String userName ) { - try{ - - logger.info("login user {}, verfiy user name: {}", - loginUser.getUserName(),userName); - return usersService.verifyUserName(userName); - }catch (Exception e){ - logger.error(Status.VERIFY_USERNAME_ERROR.getMsg(),e); - return error(Status.VERIFY_USERNAME_ERROR.getCode(), Status.VERIFY_USERNAME_ERROR.getMsg()); - } + logger.info("login user {}, verfiy user name: {}", + loginUser.getUserName(), userName); + return usersService.verifyUserName(userName); } /** * 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") + @ApiOperation(value = "unauthorizedUser", notes = "UNAUTHORIZED_USER_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "alertgroupId", value = "ALERT_GROUP_ID",type = "String") + @ApiImplicitParam(name = "alertgroupId", value = "ALERT_GROUP_ID", type = "String") }) @GetMapping(value = "/unauth-user") @ResponseStatus(HttpStatus.OK) + @ApiException(UNAUTHORIZED_USER_ERROR) public Result unauthorizedUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("alertgroupId") Integer alertgroupId) { - try{ - logger.info("unauthorized user, login user:{}, alert group id:{}", - loginUser.getUserName(), alertgroupId); - Map result = usersService.unauthorizedUser(loginUser, alertgroupId); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.UNAUTHORIZED_USER_ERROR.getMsg(),e); - return error(Status.UNAUTHORIZED_USER_ERROR.getCode(), Status.UNAUTHORIZED_USER_ERROR.getMsg()); - } + logger.info("unauthorized user, login user:{}, alert group id:{}", + loginUser.getUserName(), alertgroupId); + Map result = usersService.unauthorizedUser(loginUser, alertgroupId); + return returnDataList(result); } /** * 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") + @ApiOperation(value = "authorizedUser", notes = "AUTHORIZED_USER_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "alertgroupId", value = "ALERT_GROUP_ID",type = "String") + @ApiImplicitParam(name = "alertgroupId", value = "ALERT_GROUP_ID", type = "String") }) @GetMapping(value = "/authed-user") @ResponseStatus(HttpStatus.OK) + @ApiException(AUTHORIZED_USER_ERROR) public Result authorizedUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("alertgroupId") Integer alertgroupId) { - try{ + try { logger.info("authorized user , login user:{}, alert group id:{}", loginUser.getUserName(), alertgroupId); Map result = usersService.authorizedUser(loginUser, alertgroupId); return returnDataList(result); - }catch (Exception e){ - logger.error(Status.AUTHORIZED_USER_ERROR.getMsg(),e); + } catch (Exception e) { + logger.error(Status.AUTHORIZED_USER_ERROR.getMsg(), e); return error(Status.AUTHORIZED_USER_ERROR.getCode(), Status.AUTHORIZED_USER_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 d7c898a29f..429553f4f1 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 @@ -17,7 +17,7 @@ package org.apache.dolphinscheduler.api.controller; -import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.WorkerGroupService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; @@ -27,7 +27,6 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; -import org.apache.dolphinscheduler.service.zk.ZookeeperCachedOperator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -35,16 +34,17 @@ import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; -import java.util.List; import java.util.Map; +import static org.apache.dolphinscheduler.api.enums.Status.*; + /** * worker group controller */ @Api(tags = "WORKER_GROUP_TAG", position = 1) @RestController @RequestMapping("/worker-group") -public class WorkerGroupController extends BaseController{ +public class WorkerGroupController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(WorkerGroupController.class); @@ -56,69 +56,61 @@ 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 ipList ip list + * @param id worker group id + * @param name worker group name + * @param ipList ip list * @return create or update result code */ - @ApiOperation(value = "saveWorkerGroup", notes= "CREATE_WORKER_GROUP_NOTES") + @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 = "ipList", value = "WORKER_IP_LIST", required = true, dataType ="String") + @ApiImplicitParam(name = "name", value = "WORKER_GROUP_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "ipList", value = "WORKER_IP_LIST", required = true, dataType = "String") }) @PostMapping(value = "/save") @ResponseStatus(HttpStatus.OK) + @ApiException(SAVE_ERROR) public Result saveWorkerGroup(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "id", required = false, defaultValue = "0") int id, - @RequestParam(value = "name") String name, - @RequestParam(value = "ipList") String ipList - ) { + @RequestParam(value = "id", required = false, defaultValue = "0") int id, + @RequestParam(value = "name") String name, + @RequestParam(value = "ipList") String ipList + ) { logger.info("save worker group: login user {}, id:{}, name: {}, ipList: {} ", loginUser.getUserName(), id, name, ipList); - try { - Map result = workerGroupService.saveWorkerGroup(loginUser,id, name, ipList); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.SAVE_ERROR.getMsg(),e); - return error(Status.SAVE_ERROR.getCode(), Status.SAVE_ERROR.getMsg()); - } + Map result = workerGroupService.saveWorkerGroup(loginUser, id, name, ipList); + return returnDataList(result); } /** * 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") + @ApiOperation(value = "queryAllWorkerGroupsPaging", notes = "QUERY_WORKER_GROUP_PAGING_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 = "ipList", value = "WORKER_IP_LIST", required = true, dataType ="String") + @ApiImplicitParam(name = "name", value = "WORKER_GROUP_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "ipList", value = "WORKER_IP_LIST", required = true, dataType = "String") }) @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_WORKER_GROUP_FAIL) public Result queryAllWorkerGroupsPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam("pageNo") Integer pageNo, @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam("pageSize") Integer pageSize ) { logger.info("query all worker group paging: login user {}, pageNo:{}, pageSize:{}, searchVal:{}", - loginUser.getUserName() , pageNo, pageSize, searchVal); - - try { - searchVal = ParameterUtils.handleEscapes(searchVal); - Map result = workerGroupService.queryAllGroupPaging(loginUser,pageNo, pageSize, searchVal); - return returnDataListPaging(result); - }catch (Exception e){ - logger.error(Status.QUERY_WORKER_GROUP_FAIL.getMsg(),e); - return error(Status.QUERY_WORKER_GROUP_FAIL.getCode(), Status.QUERY_WORKER_GROUP_FAIL.getMsg()); - } + loginUser.getUserName(), pageNo, pageSize, searchVal); + + searchVal = ParameterUtils.handleEscapes(searchVal); + Map result = workerGroupService.queryAllGroupPaging(loginUser, pageNo, pageSize, searchVal); + return returnDataListPaging(result); } /** @@ -127,49 +119,41 @@ public class WorkerGroupController extends BaseController{ * @param loginUser login user * @return all worker group list */ - @ApiOperation(value = "queryAllWorkerGroups", notes= "QUERY_WORKER_GROUP_LIST_NOTES") + @ApiOperation(value = "queryAllWorkerGroups", notes = "QUERY_WORKER_GROUP_LIST_NOTES") @GetMapping(value = "/all-groups") @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_WORKER_GROUP_FAIL) public Result queryAllWorkerGroups(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser ) { logger.info("query all worker group: login user {}", - loginUser.getUserName() ); + loginUser.getUserName()); - try { - - Map result = workerGroupService.queryAllGroup(); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.QUERY_WORKER_GROUP_FAIL.getMsg(),e); - return error(Status.QUERY_WORKER_GROUP_FAIL.getCode(), Status.QUERY_WORKER_GROUP_FAIL.getMsg()); - } + Map result = workerGroupService.queryAllGroup(); + return returnDataList(result); } /** * 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") + @ApiOperation(value = "deleteById", notes = "DELETE_WORKER_GROUP_BY_ID_NOTES") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "WORKER_GROUP_ID", required = true, dataType = "Int", example = "10"), }) @GetMapping(value = "/delete-by-id") @ResponseStatus(HttpStatus.OK) + @ApiException(DELETE_WORKER_GROUP_FAIL) public Result deleteById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("id") Integer id + @RequestParam("id") Integer id ) { logger.info("delete worker group: login user {}, id:{} ", - loginUser.getUserName() , id); - - try { - Map result = workerGroupService.deleteWorkerGroupById(id); - return returnDataList(result); - }catch (Exception e){ - logger.error(Status.DELETE_WORKER_GROUP_FAIL.getMsg(),e); - return error(Status.DELETE_WORKER_GROUP_FAIL.getCode(), Status.DELETE_WORKER_GROUP_FAIL.getMsg()); - } + loginUser.getUserName(), id); + + Map result = workerGroupService.deleteWorkerGroupById(id); + return returnDataList(result); } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandler.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandler.java index c00c443bf9..90d1afea49 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandler.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandler.java @@ -36,12 +36,13 @@ public class ApiExceptionHandler { @ExceptionHandler(Exception.class) public Result exceptionHandler(Exception e, HandlerMethod hm) { - logger.error(e.getMessage(), e); ApiException ce = hm.getMethodAnnotation(ApiException.class); if (ce == null) { + logger.error(e.getMessage(), e); return Result.errorWithArgs(Status.INTERNAL_SERVER_ERROR_ARGS, e.getMessage()); } Status st = ce.value(); + logger.error(st.getMsg(), e); return Result.error(st); } 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 c0f1b3fd25..95cd96d08e 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 @@ -17,6 +17,7 @@ package org.apache.dolphinscheduler.api.exceptions; import org.apache.dolphinscheduler.api.controller.AccessTokenController; +import org.apache.dolphinscheduler.api.controller.ProcessDefinitionController; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.dao.entity.User; @@ -24,6 +25,7 @@ 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.*; @@ -39,4 +41,14 @@ public class ApiExceptionHandlerTest { Result result = handler.exceptionHandler(new RuntimeException("test exception"), hm); 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("exportProcessDefinitionById", User.class, String.class, Integer.class, HttpServletResponse.class); + HandlerMethod hm = new HandlerMethod(controller, method); + Result result = handler.exceptionHandler(new RuntimeException("test exception"), hm); + Assert.assertEquals(Status.INTERNAL_SERVER_ERROR_ARGS.getCode(),result.getCode().intValue()); + } } \ No newline at end of file